Author: cazfi
Date: Sat Feb  6 21:45:57 2016
New Revision: 31794

URL: http://svn.gna.org/viewcvs/freeciv?rev=31794&view=rev
Log:
First turn is now T1, and T0 is only pre-game.

See patch #6599

Modified:
    trunk/common/game.c
    trunk/common/game.h
    trunk/common/mapimg.c
    trunk/common/scriptcore/api_game_methods.c
    trunk/common/scriptcore/api_game_methods.h
    trunk/common/scriptcore/tolua_game.pkg
    trunk/data/alien/script.lua
    trunk/data/scenarios/tutorial.sav
    trunk/server/cityturn.c
    trunk/server/legacysave.c
    trunk/server/savecompat.c
    trunk/server/scripting/script_server.c
    trunk/server/settings.c
    trunk/server/srv_main.c

Modified: trunk/common/game.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/game.c?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/common/game.c (original)
+++ trunk/common/game.c Sat Feb  6 21:45:57 2016
@@ -811,7 +811,7 @@
 ****************************************************************************/
 int current_turn_timeout(void)
 {
-  if (game.info.turn == 0 && game.info.first_timeout != -1) {
+  if (game.info.turn == 1 && game.info.first_timeout != -1) {
     return game.info.first_timeout;
   } else {
     return game.info.timeout;

Modified: trunk/common/game.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/game.h?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/common/game.h (original)
+++ trunk/common/game.h Sat Feb  6 21:45:57 2016
@@ -566,7 +566,7 @@
 #define GAME_DEFAULT_BARBARIANRATE   BARBS_NORMAL
 
 #define GAME_DEFAULT_ONSETBARBARIAN  60
-#define GAME_MIN_ONSETBARBARIAN      0
+#define GAME_MIN_ONSETBARBARIAN      1
 #define GAME_MAX_ONSETBARBARIAN      GAME_MAX_END_TURN
 
 #define GAME_DEFAULT_OCCUPYCHANCE    0

Modified: trunk/common/mapimg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/mapimg.c?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/common/mapimg.c       (original)
+++ trunk/common/mapimg.c       Sat Feb  6 21:45:57 2016
@@ -1343,7 +1343,7 @@
    * - it is the first turn
    * - turns is set to a value not zero and the current turn can be devided
    *   by this number */
-  if (!force && game.info.turn != 0
+  if (!force && game.info.turn != 1
       && !(pmapdef->turns != 0 && game.info.turn % pmapdef->turns == 0)) {
     return TRUE;
   }

Modified: trunk/common/scriptcore/api_game_methods.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/api_game_methods.c?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/common/scriptcore/api_game_methods.c  (original)
+++ trunk/common/scriptcore/api_game_methods.c  Sat Feb  6 21:45:57 2016
@@ -50,6 +50,20 @@
 }
 
 /*****************************************************************************
+  Return the current turn, as if real turns started from 0.
+*****************************************************************************/
+int api_methods_game_turn_deprecated(lua_State *L)
+{
+  LUASCRIPT_CHECK_STATE(L, FALSE);
+
+  if (game.info.turn > 0) {
+    return game.info.turn - 1;
+  }
+
+  return game.info.turn;
+}
+
+/*****************************************************************************
   Return TRUE if pbuilding is a wonder.
 *****************************************************************************/
 bool api_methods_building_type_is_wonder(lua_State *L,

Modified: trunk/common/scriptcore/api_game_methods.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/api_game_methods.h?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/common/scriptcore/api_game_methods.h  (original)
+++ trunk/common/scriptcore/api_game_methods.h  Sat Feb  6 21:45:57 2016
@@ -25,6 +25,7 @@
 
 /* Game */
 int api_methods_game_turn(lua_State *L);
+int api_methods_game_turn_deprecated(lua_State *L);
 
 /* Building Type */
 bool api_methods_building_type_is_wonder(lua_State *L,

Modified: trunk/common/scriptcore/tolua_game.pkg
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/tolua_game.pkg?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/common/scriptcore/tolua_game.pkg      (original)
+++ trunk/common/scriptcore/tolua_game.pkg      Sat Feb  6 21:45:57 2016
@@ -113,6 +113,10 @@
 /* Module Game */
 module game {
   int api_methods_game_turn
+    @ current_turn (lua_State *L);
+
+  /* Deprecated. Use current_turn() to get the real turn number */
+  int api_methods_game_turn_deprecated
     @ turn (lua_State *L);
 }
 

Modified: trunk/data/alien/script.lua
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/alien/script.lua?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/data/alien/script.lua (original)
+++ trunk/data/alien/script.lua Sat Feb  6 21:45:57 2016
@@ -119,10 +119,10 @@
 
 -- Show a pop up telling the beginning of the story when the game starts.
 function turn_callback(turn, year)
-  if turn == 0 then
+  if turn == 1 then
     notify.event(nil, nil, E.SCRIPT,
 _("Deneb 7 was known to have strange force field surrounding it\nthat made it 
impossible to get near planet with year\n250 Galactic Era Earth technology. 
However, when you were\nflying past, that field suddenly reverted and sucked 
you\nto the planet.\n\nYou find yourself in a strange world, probably 
touched\nby superior technology, where big portion of Earth science\nis 
invalid. You have to learn new rules,\nrules of this world.\n\nThere's deadly 
radiation that no known shielding works against.\nThere's alien life, but more 
surprisingly also some\nedible plants just like on Earth.\n\nRadio doesn't 
work,\nair doesn't allow flying, some basic Physics does\nnot apply 
here.\n\nYou struggle to live on this planet, and read\nRoadside Picnic by 
Strugatsky brothers once more."))
   end
 end
 
-signal.connect('turn_started', 'turn_callback')
+signal.connect('turn_begin', 'turn_callback')

Modified: trunk/data/scenarios/tutorial.sav
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/scenarios/tutorial.sav?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/data/scenarios/tutorial.sav   (original)
+++ trunk/data/scenarios/tutorial.sav   Sat Feb  6 21:45:57 2016
@@ -98,12 +98,12 @@
 -- Hint to build workers?
 
 function turn_callback(turn, year)
-  if turn == 0 then
+  if turn == 1 then
     notify.event(nil, nil, E.SCRIPT,
 _("Welcome to Freeciv.  You lead a civilization.  Your\ntask is to conquer the 
world!  You should start by\nexploring the land around you with your 
explorer,\nand using your settlers to find a good place to build\na city.  Use 
the number pad to move units around."))
   end
 end
-signal.connect('turn_started', 'turn_callback')
+signal.connect('turn_begin', 'turn_callback')
 
 -- Check for and warn about vulnerable stacks.
 function check_stacks(tile, player)

Modified: trunk/server/cityturn.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/cityturn.c?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/server/cityturn.c     (original)
+++ trunk/server/cityturn.c     Sat Feb  6 21:45:57 2016
@@ -3545,7 +3545,7 @@
 
   'game.server.mgr_turninterval' controls the number of turns between
   migration checks for one city (counted from the founding). If this
-  setting is zero, or it is the first turn (T0), migration does no occur.
+  setting is zero, or it is the first turn (T1), migration does no occur.
 
   'game.server.mgr_distance' is the maximal distance for migration.
 

Modified: trunk/server/legacysave.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/legacysave.c?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/server/legacysave.c   (original)
+++ trunk/server/legacysave.c   Sat Feb  6 21:45:57 2016
@@ -1271,7 +1271,7 @@
     }
 
     punit->server.birth_turn = secfile_lookup_int_default(file, game.info.turn,
-                                                   "player%d.u%d.born", plrno, 
i);
+                                                          "player%d.u%d.born", 
plrno, i) + 1;
     base = secfile_lookup_int_default(file, -1,
                                       "player%d.u%d.activity_base", plrno, i);
     if (base >= 0 && base < num_base_types) {
@@ -2391,7 +2391,7 @@
     /* before did_buy for undocumented hack */
     pcity->turn_founded =
       secfile_lookup_int_default(file, -2, "player%d.c%d.turn_founded",
-                                 plrno, i);
+                                 plrno, i) + 1;
     fc_assert_exit_msg(secfile_lookup_int(file, &j, "player%d.c%d.did_buy",
                                           plrno, i),
                        "%s", secfile_error());
@@ -3354,8 +3354,11 @@
       = secfile_lookup_int_default(file, GAME_DEFAULT_UNITWAITTIME,
                                    "game.unitwaittime");
 
-    game.server.end_turn      = secfile_lookup_int_default(file, 5000,
-                                                         "game.end_turn");
+    game.server.end_turn
+      = secfile_lookup_int_default(file, 5000 - 1, "game.end_turn") + 1;
+    if (game.server.end_turn > GAME_MAX_END_TURN) {
+      game.server.end_turn = GAME_MAX_END_TURN;
+    }
     game.info.shieldbox
       = secfile_lookup_int_default(file, GAME_DEFAULT_SHIELDBOX,
                                   "game.box_shield");
@@ -3385,6 +3388,9 @@
          * (I_DESTROYED) are used at turn number for the city improvements,
          * we cannot use that strange hack anymore. */
         game.info.turn = 0;
+      } else if (!game.info.is_new_game) {
+        /* Game start at T1 nowadays */
+        game.info.turn++;
       }
     } else {
       game.info.turn = 0;

Modified: trunk/server/savecompat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savecompat.c?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/server/savecompat.c   (original)
+++ trunk/server/savecompat.c   Sat Feb  6 21:45:57 2016
@@ -1139,6 +1139,24 @@
 }
 
 /****************************************************************************
+  Increase turn value in secfile by one.
+****************************************************************************/
+static int increase_secfile_turn_int(struct loaddata *loading, const char *key,
+                                     int old_def, bool keep_default)
+{
+  int value;
+
+  value = secfile_lookup_int_default(loading->file, old_def, "%s", key);
+
+  if (value != old_def || !keep_default) {
+    value++;
+    secfile_replace_int(loading->file, value, "%s", key);
+  }
+
+  return value;
+}
+
+/****************************************************************************
   Translate savegame secfile data from 2.6.x to 3.0.0 format.
   Note that even after 2.6 savegame has gone through this compatibility
   function, it's still 2.6 savegame in the sense that savegame2.c, and not
@@ -1150,6 +1168,8 @@
   int plrno;
   int nplayers;
   int num_settings;
+  bool started;
+  int old_turn;
 
   /* Check status and return if not OK (sg_success != TRUE). */
   sg_check_ret();
@@ -1163,6 +1183,17 @@
     log_sg("random.save: %s", secfile_error());
   }
 
+  /* Already started games should have their turn counts increased by 1 */
+  if (secfile_lookup_bool_default(loading->file, TRUE, "game.save_players")) {
+    started = TRUE;
+
+    old_turn = increase_secfile_turn_int(loading, "game.turn", 0, FALSE) - 1;
+    increase_secfile_turn_int(loading, "game.scoreturn", old_turn + 
GAME_DEFAULT_SCORETURN, FALSE);
+    increase_secfile_turn_int(loading, "history.turn", -2, TRUE);
+  } else {
+    started = FALSE;
+  }
+
   nplayers = secfile_lookup_int_default(loading->file, 0, "players.nplayers");
 
   for (plrno = 0; plrno < nplayers; plrno++) {
@@ -1174,6 +1205,32 @@
 
       secfile_insert_str_vec(loading->file, flag_names, 1,
                              "player%d.flags", plrno);
+    }
+
+    if (started) {
+      int num = secfile_lookup_int_default(loading->file, 0,
+                                           "player%d.nunits",
+                                           plrno);
+      int i;
+
+      for (i = 0; i < num; i++) {
+        char buf[64];
+
+        fc_snprintf(buf, sizeof(buf), "player%d.u%d.born", plrno, i);
+
+        increase_secfile_turn_int(loading, buf, old_turn, FALSE);
+      }
+
+      num = secfile_lookup_int_default(loading->file, 0,
+                                       "player%d.ncities", plrno);
+
+      for (i = 0; i < num; i++) {
+        char buf[64];
+
+        fc_snprintf(buf, sizeof(buf), "player%d.c%d.turn_founded", plrno, i);
+
+        increase_secfile_turn_int(loading, buf, -2, TRUE);
+      }
     }
   }
 

Modified: trunk/server/scripting/script_server.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/scripting/script_server.c?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/server/scripting/script_server.c      (original)
+++ trunk/server/scripting/script_server.c      Sat Feb  6 21:45:57 2016
@@ -344,8 +344,14 @@
 *****************************************************************************/
 static void script_server_signal_create(void)
 {
+  luascript_signal_create(fcl_main, "turn_begin", 2,
+                          API_TYPE_INT, API_TYPE_INT);
+
+  /* Deprecated form of the 'turn_begin' signal that counts real turns
+   * starting from 0. */
   luascript_signal_create(fcl_main, "turn_started", 2,
                           API_TYPE_INT, API_TYPE_INT);
+
   luascript_signal_create(fcl_main, "unit_moved", 3,
                           API_TYPE_UNIT, API_TYPE_TILE, API_TYPE_TILE);
 

Modified: trunk/server/settings.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/settings.c?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/server/settings.c     (original)
+++ trunk/server/settings.c     Sat Feb  6 21:45:57 2016
@@ -693,7 +693,7 @@
   if (S_S_RUNNING == server_state()) {
     int timeout = *pset->integer.pvalue;
 
-    if (game.info.turn != 0 || game.info.first_timeout == -1) {
+    if (game.info.turn != 1 || game.info.first_timeout == -1) {
       /* This may cause the current turn to end immediately. */
       game.tinfo.seconds_to_phasedone = timeout;
     }
@@ -710,7 +710,7 @@
   if (S_S_RUNNING == server_state()) {
     int timeout = *pset->integer.pvalue;
 
-    if (game.info.turn == 0) {
+    if (game.info.turn == 1) {
       /* This may cause the current turn to end immediately. */
       if (timeout != -1) {
         game.tinfo.seconds_to_phasedone = timeout;
@@ -2512,9 +2512,9 @@
           N_("First turn timeout"),
           /* TRANS: The strings between single quotes are setting names and
            * should not be translated. */
-          N_("If greater than 0, T0 will last for 'first_timeout' seconds.\n"
-             "If set to 0, T0 will not have a timeout.\n"
-             "If set to -1, the special treatment of T0 will be disabled.\n"
+          N_("If greater than 0, T1 will last for 'first_timeout' seconds.\n"
+             "If set to 0, T1 will not have a timeout.\n"
+             "If set to -1, the special treatment of T1 will be disabled.\n"
              "See also 'timeout'."),
           NULL, first_timeout_callback, first_timeout_action,
           GAME_MIN_FIRST_TIMEOUT, GAME_MAX_FIRST_TIMEOUT,

Modified: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=31794&r1=31793&r2=31794&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Sat Feb  6 21:45:57 2016
@@ -973,8 +973,11 @@
   send_game_info(NULL);
 
   if (is_new_turn) {
+    script_server_signal_emit("turn_begin", 2,
+                              API_TYPE_INT, game.info.turn,
+                              API_TYPE_INT, game.info.year);
     script_server_signal_emit("turn_started", 2,
-                              API_TYPE_INT, game.info.turn,
+                              API_TYPE_INT, game.info.turn > 0 ? 
game.info.turn - 1: game.info.turn,
                               API_TYPE_INT, game.info.year);
 
     /* We build scores at the beginning of every turn.  We have to
@@ -2810,6 +2813,8 @@
 #endif
 
   if (game.info.is_new_game) {
+    game.info.turn++; /* pregame T0 -> game T1 */
+    fc_assert(game.info.turn == 1);
     game.info.year = game.server.start_year;
     /* Must come before assign_player_colors() */
     generate_players();


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to