Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] (PR#3565) Patch: rage agianst end of turn moves
Home

[Freeciv-Dev] (PR#3565) Patch: rage agianst 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] (PR#3565) Patch: rage agianst end of turn moves
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 2 May 2005 20:19:43 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Here's the version of the patch I'm committing to 2.0.

-jason

? diff
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.187.2.2
diff -u -r1.187.2.2 game.c
--- common/game.c       25 Nov 2004 23:22:34 -0000      1.187.2.2
+++ common/game.c       3 May 2005 03:17:09 -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.152.2.4
diff -u -r1.152.2.4 game.h
--- common/game.h       25 Nov 2004 23:22:34 -0000      1.152.2.4
+++ common/game.h       3 May 2005 03:17:09 -0000
@@ -71,6 +71,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; /* increase to, when enemy move seen */
   int tcptimeout;
   int netwait;
   time_t last_ping;
@@ -424,6 +425,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.55.2.3
diff -u -r1.55.2.3 packets.def
--- common/packets.def  16 Nov 2004 18:13:59 -0000      1.55.2.3
+++ common/packets.def  3 May 2005 03:17:09 -0000
@@ -327,7 +327,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.143.2.2
diff -u -r1.143.2.2 gamehand.c
--- server/gamehand.c   16 Nov 2004 18:14:00 -0000      1.143.2.2
+++ server/gamehand.c   3 May 2005 03:17:09 -0000
@@ -407,6 +407,23 @@
   return game.timeout;
 }
 
+/**************************************************************************
+  adjusts game.turn_start when enemy moves an unit, we see it and the 
+  remaining timeout is smaller than the option
+  It's possible to use a simular function to do that per player.
+**************************************************************************/
+void increase_timeout_because_unit_moved(void)
+{
+  if (game.timeout != 0){
+    int seconds_to_turndone = game.turn_start + game.timeout - time(NULL);
+
+    if (seconds_to_turndone < game.timeoutaddenemymove){
+      game.turn_start = time(NULL) - 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.11.2.1
diff -u -r1.11.2.1 gamehand.h
--- server/gamehand.h   16 Nov 2004 18:14:00 -0000      1.11.2.1
+++ server/gamehand.h   3 May 2005 03:17:09 -0000
@@ -24,6 +24,7 @@
 void send_start_turn_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.197.2.13
diff -u -r1.197.2.13 savegame.c
--- server/savegame.c   26 Feb 2005 00:33:23 -0000      1.197.2.13
+++ server/savegame.c   3 May 2005 03:17:10 -0000
@@ -3084,6 +3084,10 @@
     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)
@@ -3635,6 +3639,8 @@
   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.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.5.2.8
diff -u -r1.5.2.8 settings.c
--- server/settings.c   29 Apr 2005 17:49:27 -0000      1.5.2.8
+++ server/settings.c   3 May 2005 03:17:10 -0000
@@ -877,6 +877,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)
+  
   GEN_INT("nettimeout", game.tcptimeout,
          SSET_META, SSET_NETWORK, SSET_RARE, SSET_TO_CLIENT,
          N_("Seconds to let a client's network connection block"),
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.306.2.11
diff -u -r1.306.2.11 unittools.c
--- server/unittools.c  1 Apr 2005 00:42:29 -0000       1.306.2.11
+++ server/unittools.c  3 May 2005 03:17:11 -0000
@@ -48,6 +48,7 @@
 #include "settlers.h"
 #include "srv_main.h"
 #include "unithand.h"
+#include "gamehand.h"
 
 #include "aiexplorer.h"
 #include "aitools.h"
@@ -1940,11 +1941,15 @@
 {
   struct packet_unit_info info;
   struct packet_unit_short_info sinfo;
-  
+  bool new_information_for_enemy = FALSE;
+
   if (!dest) {
     dest = &game.game_connections;
   }
 
+/* maybe the wrong position for that, but this is the lowlevel function
+ * where we check if we have to increase timeout, or remove_turn_done */
+  
   package_unit(punit, &info);
   package_short_unit(punit, &sinfo, UNIT_INFO_IDENTITY, FALSE, FALSE);
             
@@ -1958,6 +1963,11 @@
       if (can_player_see_unit_at(pplayer, punit, punit->tile)
          || can_player_see_unit_at(pplayer, punit, ptile)) {
        send_packet_unit_short_info(pconn, &sinfo);
+       if (pplayers_at_war(pplayer,unit_owner(punit))
+           && !pplayer->ai.control) {
+         /* increase_timeout_because_unit_moved(pplayer) possible here */
+          new_information_for_enemy = TRUE;
+       }
       } else {
        if (remove_unseen) {
          dsend_packet_unit_remove(pconn, punit->id);
@@ -1965,6 +1975,11 @@
       }
     }
   } conn_list_iterate_end;
+  
+  if (game.timeout != 0 && new_information_for_enemy){
+    increase_timeout_because_unit_moved();
+  }
+
 }
 
 /**************************************************************************

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