Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] Re: (PR#3565) End of turn moves
Home

[Freeciv-Dev] Re: (PR#3565) End of turn moves

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: ue80@xxxxxxxxxxxxxxxxxxxxx
Cc: jdwheeler42@xxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#3565) End of turn moves
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 2 Mar 2005 20:01:51 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=3565 >

ue80@xxxxxxxxxxxxxxxxxxxxx wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=3565 >
> 
> Hi,
> 
> i've reduced the patch, that only the timeout is changed.
> Can be applied to pubserver without changing the clients.
> 
> Better patch only possible with manipulating turn-done-button.
> But that would need a new capability.

There are several bugs.

* You put the timeout-increase check in send_unit_info_to_onlookers. 
This is very bad because this function can pretty much be called anytime 
by anyone.  I moved it into move_unit() where it "should" be.

* Multiple consecutive increases didn't work.  Turns out this was 
because the game_info packet has is-info set.  This means the second 
packet that sent the exact same values (the same seconds_to_turndone, 
even though 20 seconds passed in between) would be discarded.  This is 
obviously a bug (should probably be fixed in 2.0 as well).

* Calling time() twice in a row and expecting the value to be the same 
is a bad idea.  I got rid of the extra time() call.

-jason

? patch.diff
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.197
diff -u -r1.197 game.c
--- common/game.c       23 Feb 2005 03:34:05 -0000      1.197
+++ common/game.c       3 Mar 2005 03:23:12 -0000
@@ -189,6 +189,7 @@
   game.timeoutinc    = GAME_DEFAULT_TIMEOUTINC;
   game.timeoutincmult= GAME_DEFAULT_TIMEOUTINCMULT;
   game.timeoutcounter= 1;
+  game.timeoutaddenemymove = GAME_DEFAULT_TIMEOUTADDEMOVE; 
   game.tcptimeout    = GAME_DEFAULT_TCPTIMEOUT;
   game.netwait       = GAME_DEFAULT_NETWAIT;
   game.last_ping     = 0;
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.173
diff -u -r1.173 game.h
--- common/game.h       23 Feb 2005 03:34:05 -0000      1.173
+++ common/game.h       3 Mar 2005 03:23:12 -0000
@@ -70,6 +70,7 @@
   int timeoutincmult; /* ... and multiply timeoutinc by this amount ... */
   int timeoutintinc;  /* ... and increase timeoutint by this amount */
   int timeoutcounter; /* timeoutcounter - timeoutint = turns to next inc. */
+  int timeoutaddenemymove; /* minimum timeout after an enemy move is seen */
   int tcptimeout;
   int netwait;
   time_t last_ping;
@@ -436,6 +437,7 @@
 #define GAME_DEFAULT_TIMEOUTINTINC   0
 #define GAME_DEFAULT_TIMEOUTINC      0
 #define GAME_DEFAULT_TIMEOUTINCMULT  1
+#define GAME_DEFAULT_TIMEOUTADDEMOVE 0
 
 #ifndef NDEBUG
 #define GAME_MIN_TIMEOUT             -1
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.95
diff -u -r1.95 packets.def
--- common/packets.def  23 Feb 2005 03:34:05 -0000      1.95
+++ common/packets.def  3 Mar 2005 03:23:13 -0000
@@ -333,7 +333,10 @@
   STRING spec_sprite[MAX_LEN_NAME];
 end
 
-PACKET_GAME_INFO=15; is-info,sc
+# This packet used to have is_info set but that doesn't work with the
+# seconds_to_phasedone field: sending the same value a second time after a
+# while has passed means a completely reset timeout.
+PACKET_GAME_INFO=15; sc
   GOLD gold;
   UINT32 tech;
   UINT8 researchcost;
Index: server/gamehand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gamehand.c,v
retrieving revision 1.152
diff -u -r1.152 gamehand.c
--- server/gamehand.c   23 Feb 2005 03:34:06 -0000      1.152
+++ server/gamehand.c   3 Mar 2005 03:23:13 -0000
@@ -413,6 +413,28 @@
   return game.timeout;
 }
 
+/**************************************************************************
+  adjusts game.phase_start when enemy moves a unit, we see it and the 
+  remaining timeout is smaller than the timeoutaddenemymove option.
+
+  It's possible to use a similar function to do that per-player.  In
+  theory there should be a separate timeout for each player and the
+  added time should only go onto the victim's timer.
+**************************************************************************/
+void increase_timeout_because_unit_moved(void)
+{
+  if (game.timeout != 0 && game.timeoutaddenemymove > 0) {
+    int seconds_to_turndone;
+    time_t now = time(NULL); /* Only call this once */
+
+    seconds_to_turndone = game.phase_start + game.timeout - now;
+    if (seconds_to_turndone < game.timeoutaddenemymove){
+      game.phase_start = now - game.timeout + game.timeoutaddenemymove;
+      send_game_info(NULL);
+    }  
+  }
+}
+
 /************************************************************************** 
   generate challenge filename for this connection, cannot fail.
 **************************************************************************/
Index: server/gamehand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gamehand.h,v
retrieving revision 1.13
diff -u -r1.13 gamehand.h
--- server/gamehand.h   23 Feb 2005 03:34:06 -0000      1.13
+++ server/gamehand.h   3 Mar 2005 03:23:13 -0000
@@ -24,6 +24,7 @@
 void send_start_phase_to_clients(void);
 
 int update_timeout(void);
+void increase_timeout_because_unit_moved(void);
 
 const char *new_challenge_filename(struct connection *pc);
 
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.223
diff -u -r1.223 savegame.c
--- server/savegame.c   26 Feb 2005 00:33:21 -0000      1.223
+++ server/savegame.c   3 Mar 2005 03:23:14 -0000
@@ -3112,6 +3112,11 @@
     game.timeoutcounter =
        secfile_lookup_int_default(file, 1, "game.timeoutcounter");
 
+    game.timeoutaddenemymove
+      = secfile_lookup_int_default(file, game.timeoutaddenemymove,
+                                  "game.timeoutaddenemymove");
+
+    
     game.end_year      = secfile_lookup_int(file, "game.end_year");
     game.researchcost  = secfile_lookup_int_default(file, 0, 
"game.researchcost");
     if (game.researchcost == 0)
@@ -3658,7 +3663,9 @@
   secfile_insert_int(file, game.timeoutintinc, "game.timeoutintinc");
   secfile_insert_int(file, game.timeoutinc, "game.timeoutinc");
   secfile_insert_int(file, game.timeoutincmult, "game.timeoutincmult"); 
-  secfile_insert_int(file, game.timeoutcounter, "game.timeoutcounter"); 
+  secfile_insert_int(file, game.timeoutcounter, "game.timeoutcounter");
+  secfile_insert_int(file, game.timeoutaddenemymove,
+                    "game.timeoutaddenemymove");
   secfile_insert_int(file, game.end_year, "game.end_year");
   secfile_insert_int(file, game.year, "game.year");
   secfile_insert_int(file, game.turn, "game.turn");
Index: server/settings.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settings.c,v
retrieving revision 1.18
diff -u -r1.18 settings.c
--- server/settings.c   26 Feb 2005 01:05:55 -0000      1.18
+++ server/settings.c   3 Mar 2005 03:23:15 -0000
@@ -873,6 +873,13 @@
             "\"timeoutincrease\" to have a dynamic timer."), NULL, 
           GAME_MIN_TIMEOUT, GAME_MAX_TIMEOUT, GAME_DEFAULT_TIMEOUT)
 
+  GEN_INT("timeaddenemymove", game.timeoutaddenemymove,
+         SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
+         N_("Timeout at least n seconds when enemy moved"),
+         N_("Any time a unit moves when in sight of an enemy player, "
+            "the remaining timeout is set to this value if it was lower."),
+         NULL, 0, GAME_MAX_TIMEOUT, GAME_DEFAULT_TIMEOUTADDEMOVE)
+  
   /* This setting points to the "stored" value; changing it won't have
    * an effect until the next synchronization point (i.e., the start of
    * the next turn). */
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.323
diff -u -r1.323 unittools.c
--- server/unittools.c  2 Mar 2005 19:17:51 -0000       1.323
+++ server/unittools.c  3 Mar 2005 03:23:15 -0000
@@ -48,6 +48,7 @@
 #include "settlers.h"
 #include "srv_main.h"
 #include "unithand.h"
+#include "gamehand.h"
 
 #include "aiexplorer.h"
 #include "aitools.h"
@@ -2919,6 +2920,26 @@
 
   conn_list_do_unbuffer(pplayer->connections);
 
+  if (game.timeout != 0 && game.timeoutaddenemymove > 0) {
+    bool new_information_for_enemy = FALSE;
+
+    phase_players_iterate(penemy) {
+      /* Increase the timeout if an enemy unit moves and the
+       * timeoutaddenemymove setting is in use. */
+      if (penemy->is_connected
+         && pplayer != penemy
+         && pplayers_at_war(penemy, pplayer)
+         && can_player_see_unit(penemy, punit)) {
+       new_information_for_enemy = TRUE;
+       break;
+      }
+    } phase_players_iterate_end;
+
+    if (game.timeout != 0 && new_information_for_enemy) {
+      increase_timeout_because_unit_moved();
+    }
+  }
+
   /* Note, an individual call to move_unit may leave things in an unstable
    * state (e.g., negative transporter capacity) if more than one unit is
    * being moved at a time (e.g., bounce unit) and they are not done in the

[Prev in Thread] Current Thread [Next in Thread]