Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2005:
[Freeciv-Dev] (PR#13327) Scenario and nation selection
Home

[Freeciv-Dev] (PR#13327) Scenario and nation selection

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13327) Scenario and nation selection
From: "Mateusz Stefek" <mstefek@xxxxxxxxx>
Date: Fri, 23 Sep 2005 10:07:24 -0700
Reply-to: bugs@xxxxxxxxxxx

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

> [mstefek - Tue Sep 20 19:01:40 2005]:

> Anyway, there's another problem with my patch: There's a race between
> the aifill spin button and loading a savegame with aifill != 5. This
> problem deserves a separate ticket. Generally aifill should be
> synchronized with the aifill spin button, but in practice there are so
> many scenarious when it isn't.

I decided to do this in a single patch. Here it is.
--
mateusz

Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.239
diff -u -r1.239 game.c
--- common/game.c       17 Sep 2005 15:50:10 -0000      1.239
+++ common/game.c       23 Sep 2005 17:02:58 -0000
@@ -251,7 +251,7 @@
   game.timeoutcounter= 1;
   game.timeoutaddenemymove = GAME_DEFAULT_TIMEOUTADDEMOVE; 
   game.last_ping     = 0;
-  game.aifill      = GAME_DEFAULT_AIFILL;
+  game.info.aifill      = GAME_DEFAULT_AIFILL;
   sz_strlcpy(game.info.start_units, GAME_DEFAULT_START_UNITS);
 
   game.seed = GAME_DEFAULT_SEED;
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.199
diff -u -r1.199 game.h
--- common/game.h       5 Sep 2005 15:55:46 -0000       1.199
+++ common/game.h       23 Sep 2005 17:03:02 -0000
@@ -69,7 +69,6 @@
    * use.  The "stored" value is a value the player can change; it won't
    * take effect until the next turn. */
   bool simultaneous_phases_stored;
-  int aifill;
   char *startmessage;
   struct player *player_ptr;
   struct player players[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.157
diff -u -r1.157 packets.def
--- common/packets.def  17 Sep 2005 08:52:22 -0000      1.157
+++ common/packets.def  23 Sep 2005 17:03:02 -0000
@@ -348,6 +348,8 @@
   GOLD gold;
   UINT32 tech;
   UINT32 skill_level;
+  
+  UINT8 aifill;
 
   BOOL is_new_game;   # TRUE only in pregame for "new" (not loaded) games
   FLOAT seconds_to_phasedone;
Index: server/connecthand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/connecthand.c,v
retrieving revision 1.55
diff -u -r1.55 connecthand.c
--- server/connecthand.c        5 Sep 2005 15:55:46 -0000       1.55
+++ server/connecthand.c        23 Sep 2005 17:03:18 -0000
@@ -705,7 +705,7 @@
   send_game_info(NULL);
   send_player_info(pplayer, NULL);
 
-  aifill(game.aifill);
+  aifill(game.info.aifill);
 
   return TRUE;
 }
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.277
diff -u -r1.277 savegame.c
--- server/savegame.c   18 Sep 2005 07:26:02 -0000      1.277
+++ server/savegame.c   23 Sep 2005 17:03:30 -0000
@@ -3322,7 +3322,7 @@
               secfile_lookup_str_default(file, GAME_DEFAULT_SAVE_NAME,
                                          "game.save_name"));
 
-    game.aifill = secfile_lookup_int_default(file, 0, "game.aifill");
+    game.info.aifill = secfile_lookup_int_default(file, 0, "game.aifill");
 
     game.scorelog = secfile_lookup_bool_default(file, FALSE, "game.scorelog");
     sz_strlcpy(game.id, secfile_lookup_str_default(file, "", "game.id"));
@@ -3846,7 +3846,7 @@
   secfile_insert_int(file, 2, "game.civstyle");
   secfile_insert_int(file, game.info.save_nturns, "game.save_nturns");
   secfile_insert_str(file, game.save_name, "game.save_name");
-  secfile_insert_int(file, game.aifill, "game.aifill");
+  secfile_insert_int(file, game.info.aifill, "game.aifill");
   secfile_insert_bool(file, game.scorelog, "game.scorelog");
   secfile_insert_str(file, game.id, "game.id");
   secfile_insert_bool(file, game.info.fogofwar, "game.fogofwar");
Index: server/settings.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settings.c,v
retrieving revision 1.32
diff -u -r1.32 settings.c
--- server/settings.c   11 Aug 2005 02:39:03 -0000      1.32
+++ server/settings.c   23 Sep 2005 17:03:30 -0000
@@ -406,7 +406,7 @@
              "will be rejected."), maxplayers_callback,
          GAME_MIN_MAX_PLAYERS, GAME_MAX_MAX_PLAYERS, GAME_DEFAULT_MAX_PLAYERS)
 
-  GEN_INT("aifill", game.aifill,
+  GEN_INT("aifill", game.info.aifill,
          SSET_PLAYERS, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
          N_("Total number of players (including AI players)"),
          N_("If set to a positive value, then AI players will be "
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.437
diff -u -r1.437 stdinhand.c
--- server/stdinhand.c  20 Sep 2005 12:48:35 -0000      1.437
+++ server/stdinhand.c  23 Sep 2005 17:03:40 -0000
@@ -930,9 +930,9 @@
 
   pplayer->ai.control = TRUE;
   set_ai_level_directer(pplayer, game.info.skill_level);
+  aifill(game.info.aifill);
   send_game_info(NULL);
   send_player_info(pplayer, NULL);
-  aifill(game.aifill);
   reset_all_start_commands();
   (void) send_server_info_to_metaserver(META_INFO);
   return TRUE;
@@ -970,7 +970,7 @@
     cmd_reply(CMD_REMOVE, caller, C_OK,
              _("Removed player %s from the game."), name);
   }
-  aifill(game.aifill);
+  aifill(game.info.aifill);
   return TRUE;
 }
 
@@ -2524,6 +2524,7 @@
 
   if (!check && do_update) {
     send_server_setting(NULL, cmd);
+    send_game_info(NULL);
     reset_all_start_commands();
     send_server_info_to_metaserver(META_INFO);
     /* 
@@ -3046,7 +3047,7 @@
 
     /* actually do the removal */
     server_remove_player(pplayer);
-    aifill(game.aifill);
+    aifill(game.info.aifill);
     reset_all_start_commands();
   }
 
@@ -3175,6 +3176,9 @@
           read_timer_seconds_free(uloadtimer));
 
   sanity_check();
+  
+  send_game_info(game.est_connections);
+  send_rulesets(game.est_connections);
 
   /* Everything seemed to load ok; spread the good news. */
   send_load_game_info(TRUE);
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.548
diff -u -r1.548 packhand.c
--- client/packhand.c   5 Sep 2005 15:55:45 -0000       1.548
+++ client/packhand.c   23 Sep 2005 17:03:47 -0000
@@ -180,7 +180,11 @@
     aconnection.id = conn_id;
     agents_game_joined();
     update_menus();
-    set_client_page(PAGE_START);
+    
+    
+    if (get_client_page() == PAGE_MAIN || get_client_page() == PAGE_NETWORK) {
+      set_client_page(PAGE_START);
+    }
 
     /* we could always use hack, verify we're local */ 
     send_client_wants_hack(challenge_file);
@@ -1340,7 +1344,13 @@
 void handle_game_info(struct packet_game_info *pinfo)
 {
   bool boot_help;
+  bool update_aifill_button = FALSE;
+
 
+  if (game.info.aifill != pinfo->aifill) {
+    update_aifill_button = TRUE;
+  }
+  
   game.info = *pinfo;
 
   game.government_when_anarchy
@@ -1358,6 +1368,9 @@
     boot_help_texts();         /* reboot, after setting game.spacerace */
   }
   update_unit_focus();
+  if (update_aifill_button) {
+    update_start_page();
+  }
 }
 
 /**************************************************************************
Index: client/gui-gtk-2.0/pages.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/pages.c,v
retrieving revision 1.40
diff -u -r1.40 pages.c
--- client/gui-gtk-2.0/pages.c  5 Sep 2005 15:55:45 -0000       1.40
+++ client/gui-gtk-2.0/pages.c  23 Sep 2005 17:03:47 -0000
@@ -98,8 +98,7 @@
 static void start_scenario_callback(GtkWidget *w, gpointer data)
 {
   set_client_page(PAGE_SCENARIO);
-
-  start_new_game_callback(NULL, NULL);
+  client_start_server();
 }
 
 /**************************************************************************
@@ -108,8 +107,7 @@
 static void load_saved_game_callback(GtkWidget *w, gpointer data)
 {
   set_client_page(PAGE_LOAD);
-
-  start_new_game_callback(NULL, NULL);
+  client_start_server();
 }
 
 /**************************************************************************
@@ -916,13 +914,16 @@
 /**************************************************************************
   AI fill setting callback.
 **************************************************************************/
+static bool send_new_aifill_to_server = TRUE;
 static void ai_fill_callback(GtkWidget *w, gpointer data)
 {
   char buf[512];
 
-  my_snprintf(buf, sizeof(buf), "/set aifill %d",
+  if (send_new_aifill_to_server) {
+    my_snprintf(buf, sizeof(buf), "/set aifill %d",
       gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w)));
-  send_chat(buf);
+    send_chat(buf);
+  }
 }
 
 /**************************************************************************
@@ -947,10 +948,14 @@
 /**************************************************************************
   update the start page.
 **************************************************************************/
-static void update_start_page(void)
+void update_start_page(void)
 {
+  bool old = send_new_aifill_to_server;
+  send_new_aifill_to_server = FALSE;
   /* Default to aifill 5. */
-  gtk_spin_button_set_value(GTK_SPIN_BUTTON(start_aifill_spin), 5);
+  gtk_spin_button_set_value(GTK_SPIN_BUTTON(start_aifill_spin),
+                            game.info.aifill);
+  send_new_aifill_to_server = old;
 }
 
 static struct player *team_menu_player;
@@ -1274,9 +1279,23 @@
 {
   if (!packet->load_successful) {
   } else {
-    update_nation_page(packet);
+    if (game.info.is_new_game) {
+      char message[MAX_LEN_MSG];
+
+      set_client_page(PAGE_START);
+      
+      /* It's pregame. Create a player and connect to him */
+      my_snprintf(message, sizeof(message), "/create %s", user_name);
+      send_chat(message);
+      my_snprintf(message, sizeof(message), "/ai %s", user_name);
+      send_chat(message);
+      my_snprintf(message, sizeof(message), "/take \"%s\"", user_name);
+      send_chat(message);
 
-    set_client_page(PAGE_NATION);
+    } else {
+      update_nation_page(packet);
+      set_client_page(PAGE_NATION);
+    }
   }
 }
 
@@ -1736,6 +1755,13 @@
   return box;
 }
 
+/**************************************************************************
+  Returns current client page
+**************************************************************************/
+enum client_pages get_client_page(void)
+{
+  return old_page;
+}
 
 /**************************************************************************
   changes the current page.
@@ -1746,6 +1772,7 @@
   enum client_pages new_page;
 
   new_page = page;
+  
 
   /* If the page remains the same, don't do anything. */
   if (old_page == new_page) {
@@ -1753,12 +1780,8 @@
   }
 
   switch (old_page) {
-  /* We aren't interested in showing a start page on game load or scenario. */
   case PAGE_SCENARIO:
   case PAGE_LOAD:
-    if (new_page == PAGE_START) {
-      return;
-    }
     break;
   case PAGE_NETWORK:
     if (lan_timer != 0) {
Index: client/include/pages_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/pages_g.h,v
retrieving revision 1.2
diff -u -r1.2 pages_g.h
--- client/include/pages_g.h    28 Mar 2005 17:19:27 -0000      1.2
+++ client/include/pages_g.h    23 Sep 2005 17:03:47 -0000
@@ -27,5 +27,7 @@
 };
 
 void set_client_page(enum client_pages page);
+enum client_pages get_client_page(void);
+void update_start_page(void);
 
 #endif  /* FC__PAGES_G_H */

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