Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2005:
[Freeciv-Dev] (PR#13264) send is_new_game to the client
Home

[Freeciv-Dev] (PR#13264) send is_new_game to the client

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13264) send is_new_game to the client
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 13 Jun 2005 20:01:42 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch sends the game.is_new_game value to the client.

At first I wanted to make this part of the client-state packet.  However
this doesn't work at all since there is no client-state packet sent to
the client when it joins the server!!!  So instead I made it part of the
game-info packet.

This patch is required for PR#13246 to work properly.  However it also
conflicts with that patch a bit.  This can be avoided by applying just
the packets.def and game.h parts, then running

  replace "game.is_new_game" "game.info.is_new_game"

-jason

? client/gui-win32/optiondlg.c.2456
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.218
diff -u -r1.218 game.c
--- common/game.c       4 Jun 2005 22:57:24 -0000       1.218
+++ common/game.c       14 Jun 2005 02:58:29 -0000
@@ -241,7 +241,7 @@
 #endif
   game.info.government_when_anarchy = G_MAGIC;   /* flag */
 
-  game.is_new_game   = TRUE;
+  game.info.is_new_game   = TRUE;
   game.simultaneous_phases_stored = GAME_DEFAULT_SIMULTANEOUS_PHASES;
   game.timeoutint    = GAME_DEFAULT_TIMEOUTINT;
   game.timeoutintinc = GAME_DEFAULT_TIMEOUTINTINC;
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.193
diff -u -r1.193 game.h
--- common/game.h       10 Jun 2005 02:20:05 -0000      1.193
+++ common/game.h       14 Jun 2005 02:58:29 -0000
@@ -53,7 +53,6 @@
 struct civ_game {
   struct packet_game_info info;
   struct packet_ruleset_control control;
-  bool is_new_game;            /* 1 for games never started */
   int version;
   char id[MAX_ID_LEN];         /* server only */
   int timeoutint;     /* increase timeout every N turns... */
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.135
diff -u -r1.135 packets.def
--- common/packets.def  10 Jun 2005 02:20:05 -0000      1.135
+++ common/packets.def  14 Jun 2005 02:58:29 -0000
@@ -343,6 +343,7 @@
   UINT32 tech;
   UINT32 skill_level;
 
+  BOOL is_new_game;   # TRUE only in pregame for "new" (not loaded) games
   FLOAT seconds_to_phasedone;
   UINT32 timeout;
   TURN turn;
Index: server/connecthand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/connecthand.c,v
retrieving revision 1.51
diff -u -r1.51 connecthand.c
--- server/connecthand.c        9 Jun 2005 18:24:48 -0000       1.51
+++ server/connecthand.c        14 Jun 2005 02:58:29 -0000
@@ -140,7 +140,7 @@
 
     gamelog(GAMELOG_PLAYER, pplayer);
 
-  } else if (server_state == PRE_GAME_STATE && game.is_new_game) {
+  } else if (server_state == PRE_GAME_STATE && game.info.is_new_game) {
     if (!attach_connection_to_player(pconn, NULL)) {
       notify_conn(dest, _("Couldn't attach your connection to new player."));
       freelog(LOG_VERBOSE, "%s is not attached to a player", pconn->username);
@@ -579,7 +579,7 @@
     } players_iterate_end;
   }
 
-  if (game.is_new_game
+  if (game.info.is_new_game
       && !pplayer->is_connected /* eg multiple controllers */
       && !pplayer->ai.control    /* eg created AI player */
       && server_state == PRE_GAME_STATE) {
Index: server/meta.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/meta.c,v
retrieving revision 1.68
diff -u -r1.68 meta.c
--- server/meta.c       5 May 2005 19:22:25 -0000       1.68
+++ server/meta.c       14 Jun 2005 02:58:29 -0000
@@ -298,10 +298,10 @@
         } else if (!plr->is_alive && !strchr(game.allow_take, 'd')) {
           is_player_available = FALSE;
         } else if (plr->ai.control
-            && !strchr(game.allow_take, (game.is_new_game ? 'A' : 'a'))) {
+            && !strchr(game.allow_take, (game.info.is_new_game ? 'A' : 'a'))) {
           is_player_available = FALSE;
         } else if (!plr->ai.control
-            && !strchr(game.allow_take, (game.is_new_game ? 'H' : 'h'))) {
+            && !strchr(game.allow_take, (game.info.is_new_game ? 'H' : 'h'))) {
           is_player_available = FALSE;
         }
 
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.387
diff -u -r1.387 plrhand.c
--- server/plrhand.c    8 Jun 2005 18:26:05 -0000       1.387
+++ server/plrhand.c    14 Jun 2005 02:58:30 -0000
@@ -1693,7 +1693,7 @@
 void server_remove_player(struct player *pplayer)
 {
   /* Not allowed after a game has started */
-  if (!(game.is_new_game && server_state == PRE_GAME_STATE)) {
+  if (!(game.info.is_new_game && server_state == PRE_GAME_STATE)) {
     die("You can't remove players after the game has started!");
   }
 
@@ -1966,7 +1966,7 @@
    *
    * FIXME: could we use map_is_empty here? */
   server_player_init(pplayer,
-                     (server_state == RUN_GAME_STATE || !game.is_new_game),
+                     (server_state == RUN_GAME_STATE || 
!game.info.is_new_game),
                     TRUE);
 
   sz_strlcpy(pplayer->name, OBSERVER_NAME);
@@ -1983,7 +1983,7 @@
    * not have been created.
    *
    * FIXME: could we use map_is_empty here? */
-  if (server_state == RUN_GAME_STATE || !game.is_new_game) {
+  if (server_state == RUN_GAME_STATE || !game.info.is_new_game) {
     pplayer->nation = OBSERVER_NATION;
     init_tech(pplayer, 0);
     map_know_and_see_all(pplayer);
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.254
diff -u -r1.254 savegame.c
--- server/savegame.c   10 Jun 2005 02:20:09 -0000      1.254
+++ server/savegame.c   14 Jun 2005 02:58:31 -0000
@@ -3658,12 +3658,12 @@
   }
 
 
-  game.is_new_game = !secfile_lookup_bool_default(file, TRUE,
+  game.info.is_new_game = !secfile_lookup_bool_default(file, TRUE,
                                                  "game.save_players");
 
   map_load(file);
 
-  if (!game.is_new_game) {
+  if (!game.info.is_new_game) {
     /* destroyed wonders: */
     string = secfile_lookup_str_default(file, NULL,
                                         "game.destroyed_wonders_new");
@@ -3836,7 +3836,7 @@
    * started the first time), it should always be considered a running
    * game for savegame purposes:
    */
-  secfile_insert_int(file, (int) (game.is_new_game ? server_state :
+  secfile_insert_int(file, (int) (game.info.is_new_game ? server_state :
                                  RUN_GAME_STATE), "game.server_state");
   
   secfile_insert_str(file, get_meta_patches_string(), "game.metapatches");
@@ -3845,7 +3845,7 @@
   secfile_insert_str(file, meta_addr_port(), "game.metaserver");
   
   sz_strlcpy(options, SAVEFILE_OPTIONS);
-  if (game.is_new_game) {
+  if (game.info.is_new_game) {
     if (map.num_start_positions>0) {
       sz_strlcat(options, " startpos");
     }
@@ -4036,7 +4036,7 @@
     map_save(file);
   }
   
-  if ((server_state == PRE_GAME_STATE) && game.is_new_game) {
+  if ((server_state == PRE_GAME_STATE) && game.info.is_new_game) {
     return; /* want to save scenarios as well */
   }
 
Index: server/settings.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settings.c,v
retrieving revision 1.26
diff -u -r1.26 settings.c
--- server/settings.c   9 Jun 2005 18:24:48 -0000       1.26
+++ server/settings.c   14 Jun 2005 02:58:31 -0000
@@ -1033,7 +1033,7 @@
      * or if we do have a map but its a scenario one (ie, the game has
      * never actually been started).
      */
-    return (map_is_empty() || game.is_new_game);
+    return (map_is_empty() || game.info.is_new_game);
   case SSET_RULES_FLEXIBLE:
   case SSET_META:
     /* These can always be changed: */
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.269
diff -u -r1.269 srv_main.c
--- server/srv_main.c   9 Jun 2005 18:30:13 -0000       1.269
+++ server/srv_main.c   14 Jun 2005 02:58:31 -0000
@@ -1617,10 +1617,10 @@
 {
   struct timer *eot_timer;     /* time server processing at end-of-turn */
   int save_counter = 0;
-  bool is_new_turn = game.is_new_game;
+  bool is_new_turn = game.info.is_new_game;
 
   /* We may as well reset is_new_game now. */
-  game.is_new_game = FALSE;
+  game.info.is_new_game = FALSE;
 
   eot_timer = new_timer_start(TIMER_CPU, TIMER_ACTIVE);
 
@@ -1792,7 +1792,7 @@
     /* Reset server */
     server_game_free();
     server_game_init();
-    game.is_new_game = TRUE;
+    game.info.is_new_game = TRUE;
     server_state = PRE_GAME_STATE;
   }
 
@@ -1850,14 +1850,14 @@
   test_random1(200000);
 #endif
 
-  if (game.is_new_game) {
+  if (game.info.is_new_game) {
     generate_players();
     final_ruleset_adjustments();
   }
    
   /* If we have a tile map, and map.generator==0, call map_fractal_generate
    * anyway to make the specials, huts and continent numbers. */
-  if (map_is_empty() || (map.generator == 0 && game.is_new_game)) {
+  if (map_is_empty() || (map.generator == 0 && game.info.is_new_game)) {
     map_fractal_generate(TRUE);
   }
 
@@ -1867,7 +1867,7 @@
   server_state = RUN_GAME_STATE;
   (void) send_server_info_to_metaserver(META_INFO);
 
-  if(game.is_new_game) {
+  if(game.info.is_new_game) {
     /* Before the player map is allocated (and initiailized)! */
     game.fogofwar_old = game.info.fogofwar;
 
@@ -1877,7 +1877,7 @@
       player_limit_to_government_rates(pplayer);
       pplayer->economic.gold = game.info.gold;
     } players_iterate_end;
-    if(game.is_new_game) {
+    if(game.info.is_new_game) {
       /* If we're starting a new game, reset the rules.max_players to be the
        * number of players currently in the game.  But when loading a game
        * we don't want to change it. */
@@ -1886,7 +1886,7 @@
   }
 
   /* Set up alliances based on team selections */
-  if (game.is_new_game) {
+  if (game.info.is_new_game) {
    players_iterate(pplayer) {
      players_iterate(pdest) {
       if (players_on_same_team(pplayer, pdest)
@@ -1919,7 +1919,7 @@
 
   ai_data_movemap_init();
 
-  if (!game.is_new_game) {
+  if (!game.info.is_new_game) {
     players_iterate(pplayer) {
       if (pplayer->ai.control) {
        set_ai_level_direct(pplayer, pplayer->ai.skill_level);
@@ -1935,7 +1935,7 @@
   send_all_info(game.game_connections);
   lsend_packet_thaw_hint(game.game_connections);
   
-  if(game.is_new_game) {
+  if(game.info.is_new_game) {
     init_new_game();
 
     /* give global observers the entire map */
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.419
diff -u -r1.419 stdinhand.c
--- server/stdinhand.c  9 Jun 2005 18:24:48 -0000       1.419
+++ server/stdinhand.c  14 Jun 2005 02:58:32 -0000
@@ -795,7 +795,7 @@
              _("%s is now under human control."), pplayer->name);
 
     /* because the hard AI `cheats' with government rates but humans shouldn't 
*/
-    if (!game.is_new_game) {
+    if (!game.info.is_new_game) {
       check_player_government_rates(pplayer);
     }
     /* Remove hidden dialogs from clients. This way the player can initiate
@@ -949,7 +949,7 @@
     return FALSE;
   }
 
-  if (!(game.is_new_game && server_state == PRE_GAME_STATE)) {
+  if (!(game.info.is_new_game && server_state == PRE_GAME_STATE)) {
     cmd_reply(CMD_REMOVE, caller, C_FAIL,
              _("Players cannot be removed once the game has started."));
     return FALSE;
@@ -2563,7 +2563,7 @@
   const char *allow;
 
   if (pplayer->is_observer) {
-    if (!(allow = strchr(game.allow_take, (game.is_new_game ? 'O' : 'o')))) {
+    if (!(allow = strchr(game.allow_take, (game.info.is_new_game ? 'O' : 
'o')))) {
       if (will_obs) {
         mystrlcpy(msg, _("Sorry, one can't observe globally in this game."),
                   MAX_LEN_MSG);
@@ -2597,7 +2597,7 @@
       return FALSE;
     }
   } else if (pplayer->ai.control) {
-    if (!(allow = strchr(game.allow_take, (game.is_new_game ? 'A' : 'a')))) {
+    if (!(allow = strchr(game.allow_take, (game.info.is_new_game ? 'A' : 
'a')))) {
       if (will_obs) {
         mystrlcpy(msg, _("Sorry, one can't observe AI players in this game."),
                   MAX_LEN_MSG);
@@ -2608,7 +2608,7 @@
       return FALSE;
     }
   } else { 
-    if (!(allow = strchr(game.allow_take, (game.is_new_game ? 'H' : 'h')))) {
+    if (!(allow = strchr(game.allow_take, (game.info.is_new_game ? 'H' : 
'h')))) {
       if (will_obs) {
         mystrlcpy(msg, 
                   _("Sorry, one can't observe human players in this game."),
@@ -2652,7 +2652,7 @@
 {
   int i = 0, ntokens = 0;
   char buf[MAX_LEN_CONSOLE_LINE], *arg[2], msg[MAX_LEN_MSG];  
-  bool is_newgame = server_state == PRE_GAME_STATE && game.is_new_game;
+  bool is_newgame = server_state == PRE_GAME_STATE && game.info.is_new_game;
   enum m_pre_result result;
   struct connection *pconn = NULL;
   struct player *pplayer = NULL;
@@ -2802,7 +2802,7 @@
 {
   int i = 0, ntokens = 0;
   char buf[MAX_LEN_CONSOLE_LINE], *arg[2], msg[MAX_LEN_MSG];
-  bool is_newgame = server_state == PRE_GAME_STATE && game.is_new_game;
+  bool is_newgame = server_state == PRE_GAME_STATE && game.info.is_new_game;
   enum m_pre_result match_result;
   struct connection *pconn = NULL;
   struct player *pplayer = NULL;
@@ -2974,7 +2974,7 @@
   enum m_pre_result match_result;
   struct connection *pconn = NULL;
   struct player *pplayer = NULL;
-  bool is_newgame = server_state == PRE_GAME_STATE && game.is_new_game;
+  bool is_newgame = server_state == PRE_GAME_STATE && game.info.is_new_game;
   bool one_obs_among_many = FALSE, res = FALSE;
 
   sz_strlcpy(buf, str);
@@ -3570,7 +3570,7 @@
   switch (server_state) {
   case PRE_GAME_STATE:
     /* Sanity check scenario */
-    if (game.is_new_game && !check) {
+    if (game.info.is_new_game && !check) {
       if (map.num_start_positions > 0
          && game.info.max_players > map.num_start_positions) {
        /* If we load a pre-generated map (i.e., a scenario) it is possible
@@ -3972,7 +3972,7 @@
        cat_snprintf(buf2, sizeof(buf2), _(", difficulty level %s"),
                     name_of_skill_level(pplayer->ai.skill_level));
       }
-      if (!game.is_new_game) {
+      if (!game.info.is_new_game) {
        cat_snprintf(buf2, sizeof(buf2), _(", nation %s"),
                     get_nation_name_plural(pplayer->nation));
       }
#!/bin/bash

files=`find . -name "*.[ch]"`
#files=pango.diff
#files=`find . -type f -name "Makefile.am"`
#files=`find . -type f| grep -v CVS`
#files=`find . -name "*.ruleset"`

echo Replacing \"$1\" with \"$2\".

for file in $files; do
    cat $file \
        | sed "s/$1/$2/g" \
        > $file.$$

    cmp $file $file.$$ >/dev/null \
        || (mv $file.$$ $file && echo "  $file")
    rm -f $file.$$
done

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13264) send is_new_game to the client, Jason Short <=