Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2003:
[Freeciv-Dev] (PR#3627) Use of MAX_NUM_NATIONS
Home

[Freeciv-Dev] (PR#3627) Use of MAX_NUM_NATIONS

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: rf13@xxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#3627) Use of MAX_NUM_NATIONS
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 28 Mar 2003 15:50:18 -0800
Reply-to: rt@xxxxxxxxxxxxxx

[jdorje - Wed Mar 26 06:33:54 2003]:

> [rfalke - Thu Mar  6 10:32:42 2003]:
> 
> > 
> > MAX_NUM_NATIONS it is used as a flag value to indicate "no nation
> > choosen yet". This is bad since it requires to do capability code
> > every time we change it. Better to use value outside of the normal
> > range. Either very large (65000) or a very small (-1).
> 
> See attached patch.  This introduces a NO_NATION_SELECTED==-1 macro
> variable to do this.
> 
> I'm not sure if a new capability is needed for this or not.  Probably
> one is, but I haven't added it yet.

Same patch, capability added.

jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.297
diff -u -r1.297 packhand.c
--- client/packhand.c   2003/03/24 22:29:31     1.297
+++ client/packhand.c   2003/03/28 23:47:22
@@ -278,9 +278,9 @@
 **************************************************************************/
 void handle_game_state(struct packet_generic_integer *packet)
 {
-  if (get_client_state() == CLIENT_SELECT_RACE_STATE && 
-     packet->value==CLIENT_GAME_RUNNING_STATE &&
-     game.player_ptr->nation == MAX_NUM_NATIONS) {
+  if (get_client_state() == CLIENT_SELECT_RACE_STATE
+      && packet->value == CLIENT_GAME_RUNNING_STATE
+      && game.player_ptr->nation == NO_NATION_SELECTED) {
     popdown_races_dialog();
   }
   
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.128
diff -u -r1.128 capstr.c
--- common/capstr.c     2003/03/28 22:08:12     1.128
+++ common/capstr.c     2003/03/28 23:47:22
@@ -76,8 +76,8 @@
 
 #define CAPABILITY "+1.14.0 conn_info +occupied team tech_impr_gfx " \
                    "city_struct_minor_cleanup obsolete_last class_legend " \
-                   "+impr_req +waste +fastfocus +continent +small_dipl"
-  
+                   "+impr_req +waste +fastfocus +continent +small_dipl " \
+                   "+no_nation_selected"
 /* "+1.14.0" is protocol for 1.14.0 release.
  *
  * "conn_info" is sending the conn_id field. To preserve compatability
@@ -112,6 +112,9 @@
  *
  * "small_dipl" makes the player diplomacy data in the player packet
  * smaller, by sending 8-bit instead of 32-bit values.
+ *
+ * "no_nation_selected" means that -1 (NO_NATION_SELECTED) is used for
+ * players who have no assigned nation (rather than MAX_NUM_NATIONS).
  */
 
 void init_our_capability(void)
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.141
diff -u -r1.141 map.h
--- common/map.h        2003/03/11 17:59:26     1.141
+++ common/map.h        2003/03/28 23:47:24
@@ -177,6 +177,8 @@
   bool have_rivers_overlay;    /* only applies if !have_specials */
   int num_continents;
   struct tile *tiles;
+
+  /* Only used by server. */
   struct map_position start_positions[MAX_NUM_NATIONS];
 };
 
Index: common/nation.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.h,v
retrieving revision 1.22
diff -u -r1.22 nation.h
--- common/nation.h     2003/01/31 08:39:00     1.22
+++ common/nation.h     2003/03/28 23:47:24
@@ -17,7 +17,10 @@
 #include "terrain.h"           /* T_COUNT */
 
 #define MAX_NUM_TECH_GOALS 10
+
+/* Changing either of these values will break network compatibility. */
 #define MAX_NUM_NATIONS  63
+#define NO_NATION_SELECTED (Nation_Type_id)(-1)
 
 /* 
  * Purpose of this constant is to catch invalid ruleset and network
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.113
diff -u -r1.113 player.c
--- common/player.c     2003/03/07 05:08:42     1.113
+++ common/player.c     2003/03/28 23:47:24
@@ -70,7 +70,7 @@
   sz_strlcpy(plr->username, "UserName");
   plr->is_male = TRUE;
   plr->government=game.default_government;
-  plr->nation=MAX_NUM_NATIONS;
+  plr->nation = NO_NATION_SELECTED;
   plr->team = TEAM_NONE;
   plr->capital = FALSE;
   unit_list_init(&plr->units);
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.117
diff -u -r1.117 srv_main.c
--- server/srv_main.c   2003/03/26 22:37:50     1.117
+++ server/srv_main.c   2003/03/28 23:47:25
@@ -1057,7 +1057,7 @@
   nation_used_count = 0;
 
   players_iterate(other_player) {
-    if (other_player->nation == MAX_NUM_NATIONS) {
+    if (other_player->nation == NO_NATION_SELECTED) {
       send_select_nation(other_player);
     } else {
       nation_used_count++;     /* count used nations */
@@ -1069,7 +1069,7 @@
   /* if there's no nation left, reject remaining players, sorry */
   if( nation_used_count == game.playable_nation_count ) {   /* barb */
     players_iterate(other_player) {
-      if (other_player->nation == MAX_NUM_NATIONS) {
+      if (other_player->nation == NO_NATION_SELECTED) {
        freelog(LOG_NORMAL, _("No nations left: Removing player %s."),
                other_player->name);
        notify_player(other_player,
@@ -1090,7 +1090,7 @@
   packet.num_nations_used = 0;
 
   players_iterate(other_player) {
-    if (other_player->nation == MAX_NUM_NATIONS) {
+    if (other_player->nation == NO_NATION_SELECTED) {
       continue;
     }
     packet.nations_used[packet.num_nations_used] = other_player->nation;
@@ -1200,8 +1200,9 @@
   for (i=0; i<game.nplayers; i++) {
     pplayer = &game.players[i];
     
-    if (pplayer->nation != MAX_NUM_NATIONS)
+    if (pplayer->nation != NO_NATION_SELECTED) {
       continue;
+    }
 
     if (num_nations_avail == 0) {
       freelog(LOG_NORMAL,
@@ -1630,7 +1631,7 @@
    */
   server_state = RUN_GAME_STATE;
   players_iterate(pplayer) {
-    if (pplayer->nation == MAX_NUM_NATIONS && !pplayer->ai.control) {
+    if (pplayer->nation == NO_NATION_SELECTED && !pplayer->ai.control) {
       send_select_nation(pplayer);
       server_state = SELECT_RACES_STATE;
     }
@@ -1642,7 +1643,7 @@
     sniff_packets();
 
     players_iterate(pplayer) {
-      if (pplayer->nation == MAX_NUM_NATIONS && !pplayer->ai.control) {
+      if (pplayer->nation == NO_NATION_SELECTED && !pplayer->ai.control) {
        flag = TRUE;
        break;
       }

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