Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2004:
[Freeciv-Dev] Re: (PR#8879) don't do actions on loading
Home

[Freeciv-Dev] Re: (PR#8879) don't do actions on loading

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#8879) don't do actions on loading
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 2 Jun 2004 16:21:48 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8879 >

Jason Short wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=8879 >
> 
> When loading a game (a game that's started, that is - not a scenario), 
> we don't want to do actions at the beginning of the turn.  This is 
> easily avoided by putting in a new variable, is_new_turn.  (This name 
> isn't ideal.  Anyone have a better idea?)
> 
> This includes AI movement, AI diplomacy, etc.  Of course the AI 
> shouldn't want to do any movement or diplomacy anyway.  But they do.
> 
> Also we don't need to toggle fog-of-war in the middle of a turn, since 
> it should already have been dealt with in the load.  However we probably 
> don't *want* to toggle it until the beginning of the next turn (rather 
> than toggling it immediately as is now done, even under this patch). 
> This is a question for later...
> 
> Finally we shouldn't shuffle players when loading a game.  However this 
> requires that the shuffled order be put in the ruleset, which will be 
> the next step.

The original patch didn't work because game.is_new_game is reset to 
FALSE several lines before I access it.  I'm not sure why this is done, 
but I'm not going to change it.  However I've moved it down those 
several lines so that it's now reset right after setting is_new_turn 
from it.

jason

Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.164
diff -u -r1.164 srv_main.c
--- server/srv_main.c   30 May 2004 04:21:00 -0000      1.164
+++ server/srv_main.c   2 Jun 2004 23:19:43 -0000
@@ -101,7 +101,6 @@
 #include "srv_main.h"
 
 
-static void begin_turn(void);
 static void before_end_year(void);
 static void end_turn(void);
 static void ai_start_turn(void);
@@ -443,12 +442,12 @@
 Note: This does not give "time" to any player;
       it is solely for updating turn-dependent data.
 **************************************************************************/
-static void begin_turn(void)
+static void begin_turn(bool is_new_turn)
 {
   freelog(LOG_DEBUG, "Begin turn");
 
   /* See if the value of fog of war has changed */
-  if (game.fogofwar != game.fogofwar_old) {
+  if (is_new_turn && game.fogofwar != game.fogofwar_old) {
     if (game.fogofwar) {
       enable_fog_of_war();
       game.fogofwar_old = TRUE;
@@ -458,6 +457,7 @@
     }
   }
 
+  /* FIXME: player shuffling shouldn't be repeated unless is_new_turn. */
   freelog(LOG_DEBUG, "Shuffleplayers");
   shuffle_players();
 
@@ -468,7 +468,7 @@
   Begin a phase of movement.  This handles all beginning-of-phase actions
   for one or more players.
 **************************************************************************/
-static void begin_phase(void)
+static void begin_phase(bool is_new_phase)
 {
   freelog(LOG_DEBUG, "Begin phase");
 
@@ -488,15 +488,18 @@
   flush_packets();  /* to curb major city spam */
   conn_list_do_unbuffer(&game.game_connections);
 
-  /* Try to avoid hiding events under a diplomacy dialog */
-  players_iterate(pplayer) {
-    if (pplayer->ai.control && !is_barbarian(pplayer)) {
-      ai_diplomacy_actions(pplayer);
-    }
-  } players_iterate_end;
+  if (is_new_phase) {
+    /* Try to avoid hiding events under a diplomacy dialog */
+    players_iterate(pplayer) {
+      if (pplayer->ai.control && !is_barbarian(pplayer)) {
+       ai_diplomacy_actions(pplayer);
+      }
+    } players_iterate_end;
+
+    freelog(LOG_DEBUG, "Aistartturn");
+    ai_start_turn();
+  }
 
-  freelog(LOG_DEBUG, "Aistartturn");
-  ai_start_turn();
   send_start_turn_to_clients();
 
   sanity_check();
@@ -1346,6 +1349,10 @@
 {
   struct timer *eot_timer;     /* time server processing at end-of-turn */
   int save_counter = 0;
+  bool is_new_turn = game.is_new_game;
+
+  /* We may as well reset is_new_game now. */
+  game.is_new_game = FALSE;
 
   eot_timer = new_timer_start(TIMER_CPU, TIMER_ACTIVE);
 
@@ -1358,9 +1365,14 @@
   lsend_packet_freeze_hint(&game.game_connections);
 
   while(server_state==RUN_GAME_STATE) {
-    /* absolute beginning of a turn */
-    begin_turn();
-    begin_phase();
+    /* The beginning of a turn.
+     *
+     * We have to initialize data as well as do some actions.  However when
+     * loading a game we don't want to do these actions (like AI unit
+     * movement and AI diplomacy). */
+    begin_turn(is_new_turn);
+    begin_phase(is_new_turn);
+    is_new_turn = TRUE;
 
     force_end_of_sniff = FALSE;
 
@@ -1725,8 +1737,6 @@
     init_new_game();
   }
 
-  game.is_new_game = FALSE;
-
   send_game_state(&game.game_connections, CLIENT_GAME_RUNNING_STATE);
 
   /*** Where the action is. ***/

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#8879) don't do actions on loading, Jason Short <=