<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39413 >
This is a small implementation of the startyear server command, that
sets the year the game starts.
Some abstraction done in game.h:
Added GAME_MIN_YEAR and GAME_MAX_YEAR, and use them to define
GAME_MAX_/GAME_MIN_ for end year and start year.
Two places in the code still referred to GAME_START_YEAR (that now is
removed). In server/report.c a test for the first turn was wanted so I
used 'game.info.turn == 0', in server/maphand.c, tiles are initialized
with last_seen=GAME_START_YEAR, now they are inited with GAME_MIN_YEAR
which should be safe in the same way ( <= all years)
I coded the patch against S2_1 (sorry), but it applies to trunk with
some offsets.
This patch is to help generalize freeciv rules and calender. Further
down this path MIN and MAX_YEAR could be altered, but I keep it at the
old value to avoid introducing unknown bugs.
Index: server/settings.c
===================================================================
--- server/settings.c (revision 13006)
+++ server/settings.c (arbetskopia)
@@ -161,6 +161,19 @@
}
/*************************************************************************
+ Verify that a given startyear is valid.
+*************************************************************************/
+static bool startyear_callback(int value, const char **error_string)
+{
+ if (value > game.info.end_year) {
+ /* Tried to set startyear later than endyear */
+ *error_string = _("Cannot set startyear later than endyear.");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/*************************************************************************
Verify that a given maxplayers string is valid.
*************************************************************************/
static bool maxplayers_callback(int value, const char **error_string)
@@ -875,6 +888,13 @@
N_("The game will end at the end of the given year."),
endyear_callback,
GAME_MIN_END_YEAR, GAME_MAX_END_YEAR, GAME_DEFAULT_END_YEAR)
+
+ GEN_INT("startyear", game.info.year,
+ SSET_RULES, SSET_SOCIOLOGY, SSET_VITAL, SSET_TO_CLIENT,
+ N_("Year the game begins"),
+ N_("The game will begin at the given year."),
+ startyear_callback,
+ GAME_MIN_START_YEAR, GAME_MAX_START_YEAR, GAME_DEFAULT_START_YEAR)
GEN_INT("timeout", game.info.timeout,
SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
Index: server/report.c
===================================================================
--- server/report.c (revision 13006)
+++ server/report.c (arbetskopia)
@@ -935,7 +935,7 @@
}
if (!fp) {
- if (game.info.year == GAME_START_YEAR) {
+ if (game.info.turn == 0) {
oper = SL_CREATE;
} else {
fp = fopen(logname, "r");
Index: server/maphand.c
===================================================================
--- server/maphand.c (revision 13006)
+++ server/maphand.c (arbetskopia)
@@ -980,7 +980,7 @@
}
}
- plrtile->last_updated = GAME_START_YEAR;
+ plrtile->last_updated = GAME_MIN_YEAR;
vision_layer_iterate(v) {
plrtile->own_seen[v] = plrtile->seen_count[v];
} vision_layer_iterate_end;
Index: common/game.c
===================================================================
--- common/game.c (revision 13006)
+++ common/game.c (arbetskopia)
@@ -193,7 +193,7 @@
game.info.tcptimeout = GAME_DEFAULT_TCPTIMEOUT;
game.info.netwait = GAME_DEFAULT_NETWAIT;
game.info.end_year = GAME_DEFAULT_END_YEAR;
- game.info.year = GAME_START_YEAR;
+ game.info.year = GAME_DEFAULT_START_YEAR;
game.info.turn = 0;
game.info.min_players = GAME_DEFAULT_MIN_PLAYERS;
game.info.max_players = GAME_DEFAULT_MAX_PLAYERS;
Index: common/game.h
===================================================================
--- common/game.h (revision 13006)
+++ common/game.h (arbetskopia)
@@ -175,9 +175,9 @@
#define GAME_DEFAULT_ANGRYCITIZEN TRUE
-#define GAME_DEFAULT_END_YEAR 5000
-#define GAME_MIN_END_YEAR GAME_START_YEAR
-#define GAME_MAX_END_YEAR 5000
+#define GAME_DEFAULT_END_YEAR GAME_MAX_YEAR
+#define GAME_MIN_END_YEAR GAME_MIN_YEAR
+#define GAME_MAX_END_YEAR GAME_MAX_YEAR
#define GAME_DEFAULT_MIN_PLAYERS 1
#define GAME_MIN_MIN_PLAYERS 1
@@ -328,10 +328,10 @@
#define GAME_MIN_BARBARIANRATE 0
#define GAME_MAX_BARBARIANRATE 4
-#define GAME_DEFAULT_ONSETBARBARIAN (GAME_START_YEAR+ \
- ((GAME_DEFAULT_END_YEAR-(GAME_START_YEAR))/3))
-#define GAME_MIN_ONSETBARBARIAN GAME_START_YEAR
-#define GAME_MAX_ONSETBARBARIAN GAME_MAX_END_YEAR
+#define GAME_DEFAULT_ONSETBARBARIAN (GAME_DEFAULT_START_YEAR+ \
+ ((GAME_DEFAULT_END_YEAR-(GAME_DEFAULT_START_YEAR))/3))
+#define GAME_MIN_ONSETBARBARIAN GAME_MIN_YEAR
+#define GAME_MAX_ONSETBARBARIAN GAME_MAX_YEAR
#define GAME_DEFAULT_OCCUPYCHANCE 0
#define GAME_MIN_OCCUPYCHANCE 0
@@ -363,6 +363,11 @@
#define GAME_MIN_REVOLUTION_LENGTH 0
#define GAME_MAX_REVOLUTION_LENGTH 10
-#define GAME_START_YEAR -4000
+#define GAME_DEFAULT_START_YEAR GAME_MIN_YEAR
+#define GAME_MIN_START_YEAR GAME_MIN_YEAR
+#define GAME_MAX_START_YEAR GAME_MAX_YEAR
+#define GAME_MIN_YEAR -4000
+#define GAME_MAX_YEAR 5000
+
#endif /* FC__GAME_H */
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev