Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2004:
[Freeciv-Dev] (PR#9143) new function end_phase
Home

[Freeciv-Dev] (PR#9143) new function end_phase

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9143) new function end_phase
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 28 Jun 2004 11:32:55 -0700
Reply-to: rt@xxxxxxxxxxx

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

This patch introduces a new function end_phase and moves some code from 
the main loop into end_turn and end_phase.  Generally, end_phase marks 
all player end-of-phase actions, while end_turn does end-of-year 
actions.  Some of the moved code does change the order of actions but 
this shouldn't have a big impact on behavior.

This is a step toward PR#576.  It is generally consistent with the 
target action ordering outlined in PR#725.

jason

? core-load
? core-save
? diff
? orig
? data/trident/stack
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.170
diff -u -r1.170 srv_main.c
--- server/srv_main.c   17 Jun 2004 19:50:41 -0000      1.170
+++ server/srv_main.c   28 Jun 2004 18:28:22 -0000
@@ -101,6 +101,7 @@
 #include "srv_main.h"
 
 
+static void after_game_advance_year(void);
 static void before_end_year(void);
 static void end_turn(void);
 static void ai_start_turn(void);
@@ -507,10 +508,22 @@
 }
 
 /**************************************************************************
-...
+  End a phase of movement.  This handles all end-of-phase actions
+  for one or more players.
 **************************************************************************/
-static void end_turn(void)
+static void end_phase(void)
 {
+  freelog(LOG_DEBUG, "Endphase");
+ 
+  /* 
+   * This empties the client Messages window; put this before
+   * everything else below, since otherwise any messages from the
+   * following parts get wiped out before the user gets a chance to
+   * see them.  --dwp
+   */
+  before_end_year();
+
+  /* Freeze sending of cities. */
   nocity_send = TRUE;
 
   /* AI end of turn activities */
@@ -532,6 +545,7 @@
 
   kill_dying_players();
 
+  /* Unfreeze sending of cities. */
   nocity_send = FALSE;
   players_iterate(pplayer) {
     send_player_cities(pplayer);
@@ -539,6 +553,28 @@
   } players_iterate_end;
   flush_packets();  /* to curb major city spam */
 
+  do_apollo_program();
+  marco_polo_make_contact();
+
+  /* Moved this to after the human turn for efficiency -- Syela */
+  freelog(LOG_DEBUG, "Autosettlers");
+  auto_settlers();
+
+  freelog(LOG_DEBUG, "Auto-Attack phase");
+  auto_attack();
+}
+
+/**************************************************************************
+  Handle the end of each turn.
+**************************************************************************/
+static void end_turn(void)
+{
+  freelog(LOG_DEBUG, "Endturn");
+
+  freelog(LOG_DEBUG, "Season of native unrests");
+  summon_barbarians(); /* wild guess really, no idea where to put it, but
+                         I want to give them chance to move their units */
+
   update_environmental_upset(S_POLLUTION, &game.heating,
                             &game.globalwarming, &game.warminglevel,
                             global_warming);
@@ -546,8 +582,6 @@
                             &game.nuclearwinter, &game.coolinglevel,
                             nuclear_winter);
   update_diplomatics();
-  do_apollo_program();
-  marco_polo_make_contact();
   make_history_report();
   stdinhand_turn();
   send_player_turn_notifications(NULL);
@@ -578,6 +612,24 @@
 
   freelog(LOG_DEBUG, "Turn ended.");
   game.turn_start = time(NULL);
+
+  freelog(LOG_DEBUG, "Gamenextyear");
+  game_advance_year();
+  after_game_advance_year();
+
+  freelog(LOG_DEBUG, "Updatetimeout");
+  update_timeout();
+
+  check_spaceship_arrivals();
+
+  freelog(LOG_DEBUG, "Sendplayerinfo");
+  send_player_info(NULL, NULL);
+
+  freelog(LOG_DEBUG, "Sendgameinfo");
+  send_game_info(NULL);
+
+  freelog(LOG_DEBUG, "Sendyeartoclients");
+  send_year_to_clients(game.year);
 }
 
 /**************************************************************************
@@ -1409,40 +1461,12 @@
     sanity_check();
 
     /* 
-     * This empties the client Messages window; put this before
-     * everything else below, since otherwise any messages from the
-     * following parts get wiped out before the user gets a chance to
-     * see them.  --dwp
-    */
-    before_end_year();
-
-    /* 
      * This will freeze the reports and agents at the client.
      */
     lsend_packet_freeze_hint(&game.game_connections);
 
-    freelog(LOG_DEBUG, "Season of native unrests");
-    summon_barbarians(); /* wild guess really, no idea where to put it, but
-                            I want to give them chance to move their units */
-    /* Moved this to after the human turn for efficiency -- Syela */
-    freelog(LOG_DEBUG, "Autosettlers");
-    auto_settlers();
-    freelog(LOG_DEBUG, "Auto-Attack phase");
-    auto_attack();
-    freelog(LOG_DEBUG, "Endturn");
+    end_phase();
     end_turn();
-    freelog(LOG_DEBUG, "Gamenextyear");
-    game_advance_year();
-    after_game_advance_year();
-    freelog(LOG_DEBUG, "Updatetimeout");
-    update_timeout();
-    check_spaceship_arrivals();
-    freelog(LOG_DEBUG, "Sendplayerinfo");
-    send_player_info(NULL, NULL);
-    freelog(LOG_DEBUG, "Sendgameinfo");
-    send_game_info(NULL);
-    freelog(LOG_DEBUG, "Sendyeartoclients");
-    send_year_to_clients(game.year);
     freelog(LOG_DEBUG, "Sendinfotometaserver");
     (void) send_server_info_to_metaserver(FALSE, FALSE);
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9143) new function end_phase, Jason Short <=