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: Tue, 25 Mar 2003 22:33:55 -0800
Reply-to: rt@xxxxxxxxxxxxxx

[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.

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/26 06:22:45
@@ -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/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/26 06:22:45
@@ -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/26 06:22:45
@@ -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/26 06:22:45
@@ -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.116
diff -u -r1.116 srv_main.c
--- server/srv_main.c   2003/03/24 22:29:32     1.116
+++ server/srv_main.c   2003/03/26 06:22:47
@@ -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;
@@ -1131,8 +1131,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,
@@ -1554,7 +1555,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;
     }
@@ -1566,7 +1567,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]