Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] (PR#12937) use bitvectors for embassies
Home

[Freeciv-Dev] (PR#12937) use bitvectors for embassies

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12937) use bitvectors for embassies
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 29 Apr 2005 17:48:06 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch changes the pplayer->embassy to be a bitvector.  A new
player_bitfield BV_DEFINE is added.

Savegames are backwards-compatible.

-jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.495
diff -u -r1.495 packhand.c
--- client/packhand.c   23 Apr 2005 17:40:23 -0000      1.495
+++ client/packhand.c   30 Apr 2005 00:44:31 -0000
@@ -1478,7 +1478,12 @@
   pplayer->economic.luxury=pinfo->luxury;
   pplayer->government=pinfo->government;
   pplayer->target_government = pinfo->target_government;
-  pplayer->embassy=pinfo->embassy;
+  BV_CLR_ALL(pplayer->embassy);
+  players_iterate(pother) {
+    if (pinfo->embassy[pother->player_no]) {
+      BV_SET(pplayer->embassy, pother->player_no);
+    }
+  } players_iterate_end;
   pplayer->gives_shared_vision = pinfo->gives_shared_vision;
   pplayer->city_style=pinfo->city_style;
   for (i = 0; i < MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS; i++) {
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.237
diff -u -r1.237 capstr.c
--- common/capstr.c     29 Apr 2005 17:58:10 -0000      1.237
+++ common/capstr.c     30 Apr 2005 00:44:31 -0000
@@ -82,7 +82,7 @@
  *     as long as possible.  We want to maintain network compatibility with
  *     the stable branch for as long as possible.
  */
-#define CAPABILITY "+Freeciv.Devel.2005.Apr.29"
+#define CAPABILITY "+Freeciv.Devel.2005.Apr.29b"
 
 void init_our_capability(void)
 {
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.108
diff -u -r1.108 packets.def
--- common/packets.def  23 Apr 2005 04:26:57 -0000      1.108
+++ common/packets.def  30 Apr 2005 00:44:31 -0000
@@ -555,7 +555,7 @@
   BOOL is_male;
   GOVERNMENT government;
   GOVERNMENT target_government;
-  UINT32 embassy;
+  BOOL embassy[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
   UINT8 city_style;
   NATION nation;
   TEAM team;
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.174
diff -u -r1.174 player.c
--- common/player.c     23 Apr 2005 17:40:27 -0000      1.174
+++ common/player.c     30 Apr 2005 00:44:35 -0000
@@ -64,7 +64,7 @@
 bool player_has_embassy(const struct player *pplayer,
                        const struct player *pplayer2)
 {
-  return (TEST_BIT(pplayer->embassy, pplayer2->player_no)
+  return (BV_ISSET(pplayer->embassy, pplayer2->player_no)
           || (pplayer == pplayer2)
           || (get_player_bonus(pplayer, EFT_HAVE_EMBASSIES) > 0
               && !is_barbarian(pplayer2)));
@@ -121,7 +121,7 @@
   plr->was_created = FALSE;
   plr->is_alive=TRUE;
   plr->is_dying = FALSE;
-  plr->embassy=0;
+  BV_CLR_ALL(plr->embassy);
   plr->reputation=GAME_DEFAULT_REPUTATION;
   for(i = 0; i < MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS; i++) {
     plr->diplstates[i].type = DS_NO_CONTACT;
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.145
diff -u -r1.145 player.h
--- common/player.h     19 Apr 2005 22:05:58 -0000      1.145
+++ common/player.h     30 Apr 2005 00:44:35 -0000
@@ -173,6 +173,8 @@
   int contact_turns_left;      /* until contact ends */
 };
 
+BV_DEFINE(player_bitfield, MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS);
+
 /***************************************************************************
   On the distinction between nations(formerly races), players, and users,
   see doc/HACKING
@@ -203,7 +205,7 @@
   int revolution_finishes;
 
   bool capital; /* used to give player init_buildings in first city. */
-  int embassy;
+  player_bitfield embassy;
   int reputation;
   struct player_diplstate diplstates[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
   int city_style;
Index: server/diplhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplhand.c,v
retrieving revision 1.92
diff -u -r1.92 diplhand.c
--- server/diplhand.c   14 Feb 2005 22:52:41 -0000      1.92
+++ server/diplhand.c   30 Apr 2005 00:44:36 -0000
@@ -479,7 +479,7 @@
 void establish_embassy(struct player *pplayer, struct player *aplayer)
 {
   /* Establish the embassy. */
-  pplayer->embassy |= (1 << aplayer->player_no);
+  BV_SET(pplayer->embassy, aplayer->player_no);
   send_player_info(pplayer, pplayer);
   send_player_info(pplayer, aplayer);  /* update player dialog with embassy */
   send_player_info(aplayer, pplayer);  /* INFO_EMBASSY level info */
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.366
diff -u -r1.366 plrhand.c
--- server/plrhand.c    15 Apr 2005 05:22:52 -0000      1.366
+++ server/plrhand.c    30 Apr 2005 00:44:36 -0000
@@ -1503,7 +1503,11 @@
   if (info_level >= INFO_EMBASSY
       || receiver->diplstates[plr->player_no].contact_turns_left > 0) {
     packet->target_government = plr->target_government;
-    packet->embassy = plr->embassy;
+    memset(&packet->embassy, 0, sizeof(packet->embassy));
+    players_iterate(pother) {
+      packet->embassy[pother->player_no]
+       = BV_ISSET(plr->embassy, pother->player_no);
+    } players_iterate_end;
     packet->gives_shared_vision = plr->gives_shared_vision;
     for(i = 0; i < MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS; i++) {
       packet->diplstates[i].type       = plr->diplstates[i].type;
@@ -1514,10 +1518,9 @@
     }
   } else {
     packet->target_government = packet->government;
-    if (!receiver || !player_has_embassy(plr, receiver)) {
-      packet->embassy  = 0;
-    } else {
-      packet->embassy  = 1 << receiver->player_no;
+    memset(&packet->embassy, 0, sizeof(packet->embassy));
+    if (receiver && player_has_embassy(plr, receiver)) {
+      packet->embassy[receiver->player_no] = TRUE;
     }
     if (!receiver || !gives_shared_vision(plr, receiver)) {
       packet->gives_shared_vision = 0;
@@ -1967,7 +1970,7 @@
   } tech_type_iterate_end;
   cplayer->phase_done = TRUE; /* Have other things to think
                                 about - paralysis */
-  cplayer->embassy = 0;   /* all embassies destroyed */
+  BV_CLR_ALL(cplayer->embassy);   /* all embassies destroyed */
 
   /* Do the ai */
 
@@ -1989,7 +1992,7 @@
     pplayer->revolution_finishes = game.turn + 1;
   }
   pplayer->research->bulbs_researched = 0;
-  pplayer->embassy = 0; /* all embassies destroyed */
+  BV_CLR_ALL(pplayer->embassy);   /* all embassies destroyed */
 
   /* give splitted player the embassies to his team mates back, if any */
   if (pplayer->team != TEAM_NONE) {
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.235
diff -u -r1.235 savegame.c
--- server/savegame.c   28 Apr 2005 04:15:42 -0000      1.235
+++ server/savegame.c   30 Apr 2005 00:44:37 -0000
@@ -181,7 +181,7 @@
 #define SAVEFILE_OPTIONS "startoptions spacerace2 rulesets" \
 " diplchance_percent worklists2 map_editor known32fix turn " \
 "attributes watchtower rulesetdir client_worklists orders " \
-"startunits turn_last_built improvement_order technology_order"
+"startunits turn_last_built improvement_order technology_order embassies"
 
 static const char hex_chars[] = "0123456789abcdef";
 
@@ -1730,7 +1730,26 @@
     plr->target_government = plr->government;
   }
 
-  plr->embassy=secfile_lookup_int(file, "player%d.embassy", plrno);
+  BV_CLR_ALL(plr->embassy);
+  if (has_capability("embassies", savefile_options)) {
+    players_iterate(pother) {
+      if (secfile_lookup_bool(file, "player%d.embassy%d",
+                             plrno, pother->player_no)) {
+       BV_SET(plr->embassy, pother->player_no);
+      }
+    } players_iterate_end;
+  } else {
+    /* Required for 2.0 and earlier savegames.  Remove eventually and make
+     * the cap check manditory. */
+    int embassy = secfile_lookup_int(file, "player%d.embassy", plrno);
+
+    players_iterate(pother) {
+      if (embassy & (1 << pother->player_no)) {
+       BV_SET(plr->embassy, pother->player_no);
+      }
+    } players_iterate_end;
+
+  }
 
   p = secfile_lookup_str_default(file, NULL, "player%d.city_style_by_name",
                                  plrno);
@@ -2475,8 +2494,14 @@
   gov = get_government(plr->target_government);
   secfile_insert_str(file, gov->name_orig,
                     "player%d.target_government_name", plrno);
-  
-  secfile_insert_int(file, plr->embassy, "player%d.embassy", plrno);
+
+  players_iterate(pother) {
+    secfile_insert_bool(file, BV_ISSET(plr->embassy, pother->player_no),
+                       "player%d.embassy%d", plrno, pother->player_no);
+  } players_iterate_end;
+
+  /* Required for 2.0 and earlier servers.  Remove eventually. */
+  secfile_insert_int(file, 0, "player%d.embassy", plrno);
 
   /* This field won't be used; it's kept only for forward compatibility. 
    * City styles are specified by name since CVS 12/01-04. */
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.248
diff -u -r1.248 srv_main.c
--- server/srv_main.c   29 Apr 2005 18:14:40 -0000      1.248
+++ server/srv_main.c   30 Apr 2005 00:44:37 -0000
@@ -1879,7 +1879,7 @@
           && pplayer->player_no != pdest->player_no) {
         pplayer->diplstates[pdest->player_no].type = DS_TEAM;
         give_shared_vision(pplayer, pdest);
-        pplayer->embassy |= (1 << pdest->player_no);
+       BV_SET(pplayer->embassy, pdest->player_no);
       }
     } players_iterate_end;
    } players_iterate_end;
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.400
diff -u -r1.400 stdinhand.c
--- server/stdinhand.c  29 Apr 2005 18:14:40 -0000      1.400
+++ server/stdinhand.c  30 Apr 2005 00:44:38 -0000
@@ -2727,7 +2727,7 @@
       pplayer->is_observer = TRUE;
       pplayer->capital = TRUE;
       pplayer->phase_done = TRUE;
-      pplayer->embassy = 0;   /* no embassys */
+      BV_CLR_ALL(pplayer->embassy);   /* no embassys */
       pplayer->is_alive = FALSE;
       pplayer->was_created = FALSE;
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12937) use bitvectors for embassies, Jason Short <=