Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2005:
[Freeciv-Dev] (PR#13391) make 'owner' fields into pointers
Home

[Freeciv-Dev] (PR#13391) make 'owner' fields into pointers

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13391) make 'owner' fields into pointers
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 1 Jul 2005 23:00:25 -0700
Reply-to: bugs@xxxxxxxxxxx

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

In most places we use player pointers statically.  See ptile->owner,
pconn->player, etc.  However a few places use a player index and then
require a lookup with get_player.  The biggest users are punit->owner
and pcity->owner but also pcity->original, pdcity->owner, and several
fields in the city claims map use the integer value.

Using a pointer here is more consistent and convenient.  It's typesafe
and in most cases makes for slightly shorter code.  This patch changes
these integers to be struct player * fields.  This makes a noticable
difference in the server and common code, see for instance:

-    if ((pcity->original != pplayer->player_no)
-        && (get_player(pcity->original)->is_alive)) {
+    if (pcity->original != pplayer && pcity->original->is_alive) {

in the client the difference is smaller since the biggest user is simply
comparison to game.player_ptr.  Overall the number of SLOC is reduced by
about 10% for these operations (according to diffstat).

-jason

Index: ai/advdiplomacy.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdiplomacy.c,v
retrieving revision 1.81
diff -u -r1.81 advdiplomacy.c
--- ai/advdiplomacy.c   27 Jun 2005 18:06:08 -0000      1.81
+++ ai/advdiplomacy.c   2 Jul 2005 05:54:14 -0000
@@ -264,7 +264,7 @@
 {
   int worth = 0; /* worth for pplayer of what aplayer gives */
   bool give = (pplayer == pclause->from);
-  int giver;
+  struct player *giver;
   struct ai_dip_intel *adip = &ai->diplomacy.player_intel[aplayer->player_no];
   bool is_dangerous;
 
@@ -272,7 +272,7 @@
   
   diplomacy_verbose = verbose;
 
-  giver = pclause->from->player_no;
+  giver = pclause->from;
 
   switch (pclause->type) {
   case CLAUSE_ADVANCE:
@@ -459,7 +459,7 @@
       } else {
         worth *= 15;
       }
-      if (aplayer->player_no == offer->original) {
+      if (aplayer == offer->original) {
         /* Let them buy back their own city cheaper. */
         worth /= 2;
       }
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.229
diff -u -r1.229 aicity.c
--- ai/aicity.c 27 Jun 2005 14:30:16 -0000      1.229
+++ ai/aicity.c 2 Jul 2005 05:54:14 -0000
@@ -707,7 +707,7 @@
   if (wonder_city == NULL) {
     return;
   }
-  if (wonder_city->owner != pplayer->player_no) {
+  if (wonder_city->owner != pplayer) {
     ai->wonder_city = 0;
     return;
   }
@@ -750,7 +750,7 @@
   struct ai_data *ai = ai_data_get(pplayer);
   struct city *wonder_city = find_city_by_id(ai->wonder_city);
 
-  if (wonder_city && wonder_city->owner != pplayer->player_no) {
+  if (wonder_city && wonder_city->owner != pplayer) {
     /* We lost it to the enemy! */
     ai->wonder_city = 0;
     wonder_city = NULL;
Index: ai/aihunt.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aihunt.c,v
retrieving revision 1.18
diff -u -r1.18 aihunt.c
--- ai/aihunt.c 30 Apr 2005 17:09:25 -0000      1.18
+++ ai/aihunt.c 2 Jul 2005 05:54:14 -0000
@@ -239,8 +239,7 @@
 **************************************************************************/
 bool ai_hunter_qualify(struct player *pplayer, struct unit *punit)
 {
-  if (is_barbarian(pplayer)
-      || punit->owner != pplayer->player_no) {
+  if (is_barbarian(pplayer) || punit->owner != pplayer) {
     return FALSE;
   }
   if (unit_has_role(punit->type, L_HUNTER)) {
@@ -265,8 +264,7 @@
   unit_list_iterate(punit->tile->units, missile) {
     struct unit *sucker = NULL;
 
-    if (missile->owner == pplayer->player_no
-        && unit_flag(missile, F_MISSILE)) {
+    if (missile->owner == pplayer && unit_flag(missile, F_MISSILE)) {
       UNIT_LOG(LOGLEVEL_HUNT, missile, "checking for hunt targets");
       pft_fill_unit_parameter(&parameter, punit);
       map = pf_create_map(&parameter);
Index: ai/aisettler.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aisettler.c,v
retrieving revision 1.21
diff -u -r1.21 aisettler.c
--- ai/aisettler.c      5 May 2005 18:32:46 -0000       1.21
+++ ai/aisettler.c      2 Jul 2005 05:54:14 -0000
@@ -419,7 +419,7 @@
   }
 
   /* If (x, y) is an existing city, consider immigration */
-  if (pcity && pcity->owner == pplayer->player_no) {
+  if (pcity && pcity->owner == pplayer) {
     return;
   }
 
Index: ai/aitools.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.h,v
retrieving revision 1.54
diff -u -r1.54 aitools.h
--- ai/aitools.h        7 May 2005 13:35:25 -0000       1.54
+++ ai/aitools.h        2 Jul 2005 05:54:15 -0000
@@ -31,11 +31,12 @@
 #define NORMAL_STACKING_FEARFULNESS ((double)PF_TURN_FACTOR / 36.0)
 
 #ifdef DEBUG
-#define CHECK_UNIT(punit)                                        \
- (assert(punit != NULL),                                         \
-  assert(punit->type < U_LAST),                                  \
-  assert(punit->owner < MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS),   \
-  assert(find_unit_by_id(punit->id) != NULL))
+#define CHECK_UNIT(punit)                                                   \
+  (assert(punit != NULL),                                                  \
+   assert(punit->type < U_LAST),                                           \
+   assert(punit->owner != NULL),                                           \
+   assert(&game.players[punit->owner->player_no] == punit->owner),         \
+   assert(find_unit_by_id(punit->id) != NULL))
 #else
 #define CHECK_UNIT(punit) assert(TRUE)
 #endif
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.360
diff -u -r1.360 aiunit.c
--- ai/aiunit.c 31 May 2005 03:15:58 -0000      1.360
+++ ai/aiunit.c 2 Jul 2005 05:54:15 -0000
@@ -1019,7 +1019,7 @@
 
   CHECK_UNIT(punit);
 
-  if (!pcity || pcity->owner != pplayer->player_no) {
+  if (!pcity || pcity->owner != pplayer) {
     pcity = punit->tile->city;
     /* Do not stay defending an allied city forever */
     aiguard_clear_charge(punit);
@@ -1818,9 +1818,9 @@
   const struct unit *caravan = data;
 
   freelog(LOG_CARAVAN2, "%s caravan %d(%s): %s %s worth %g",
-      get_player(caravan->owner)->name, caravan->id, result->src->name,
-      result->help_wonder ? "wonder in" : "trade to",
-      result->dest->name, result->value);
+         caravan->owner->name, caravan->id, result->src->name,
+         result->help_wonder ? "wonder in" : "trade to",
+         result->dest->name, result->value);
 }
 
 /*************************************************************************
@@ -2184,7 +2184,7 @@
       unit_list_iterate(pcity->tile->units, punit) {
        if ((punit->ai.ai_role == AIUNIT_NONE || emergency)
            && punit->ai.ai_role != AIUNIT_DEFEND_HOME
-           && punit->owner == pplayer->player_no) {
+           && punit->owner == pplayer) {
           int want = assess_defense_unit(pcity, punit, FALSE);
 
           if (want > best_want) {
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.80
diff -u -r1.80 citydlg_common.c
--- client/citydlg_common.c     22 May 2005 18:12:52 -0000      1.80
+++ client/citydlg_common.c     2 Jul 2005 05:54:16 -0000
@@ -583,7 +583,7 @@
   struct unit *pmyunit = NULL;
 
   unit_list_iterate(punit_list, punit) {
-    if (game.info.player_idx == punit->owner) {
+    if (game.player_ptr == punit->owner) {
       /* Activate this unit. */
       pmyunit = punit;
       request_new_unit_activity(punit, ACTIVITY_IDLE);
@@ -806,7 +806,7 @@
    * buying; that's handled separately (and with an error message). */
   return (can_client_issue_orders()
          && pcity
-         && pcity->owner == game.info.player_idx
+         && pcity->owner == game.player_ptr
          && pcity->turn_founded != game.info.turn
          && !pcity->did_buy
          && get_current_construction_bonus(pcity, EFT_PROD_TO_GOLD) <= 0
Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.168
diff -u -r1.168 climisc.c
--- client/climisc.c    30 Jun 2005 20:18:37 -0000      1.168
+++ client/climisc.c    2 Jul 2005 05:54:16 -0000
@@ -888,7 +888,7 @@
 {
   struct unit_list *plist;
 
-  if (pcity->owner != game.info.player_idx) {
+  if (pcity->owner != game.player_ptr) {
     plist = pcity->info_units_supported;
   } else {
     plist = pcity->units_supported;
@@ -904,7 +904,7 @@
 {
   struct unit_list *plist;
 
-  if (pcity->owner != game.info.player_idx) {
+  if (pcity->owner != game.player_ptr) {
     plist = pcity->info_units_present;
   } else {
     plist = pcity->tile->units;
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.179
diff -u -r1.179 control.c
--- client/control.c    7 Jun 2005 06:17:08 -0000       1.179
+++ client/control.c    2 Jul 2005 05:54:16 -0000
@@ -145,7 +145,7 @@
 {
   struct unit *punit_old_focus = punit_focus;
 
-  if (punit && punit->owner != game.info.player_idx) {
+  if (punit && punit->owner != game.player_ptr) {
     /* Callers should make sure this never happens. */
     freelog(LOG_ERROR, "Trying to focus on another player's unit!");
     assert(0);
@@ -781,7 +781,7 @@
        request_new_unit_activity(pcargo, ACTIVITY_IDLE);
       }
 
-      if (pcargo->owner == game.info.player_idx) {
+      if (pcargo->owner == game.player_ptr) {
        plast = pcargo;
       }
     }
@@ -855,7 +855,8 @@
 void wakeup_sentried_units(struct tile *ptile)
 {
   unit_list_iterate(ptile->units, punit) {
-    if(punit->activity==ACTIVITY_SENTRY && game.info.player_idx==punit->owner) 
{
+    if (punit->activity == ACTIVITY_SENTRY
+       && game.player_ptr == punit->owner) {
       request_new_unit_activity(punit, ACTIVITY_IDLE);
     }
   }
@@ -1432,7 +1433,7 @@
 
   unit_list_unlink(src_tile->units, punit);
 
-  if (game.info.player_idx == punit->owner
+  if (game.player_ptr == punit->owner
       && auto_center_on_unit
       && !unit_has_orders(punit)
       && punit->activity != ACTIVITY_GOTO
@@ -1537,7 +1538,8 @@
   else if (unit_list_size(ptile->units) == 1
       && !unit_list_get(ptile->units, 0)->occupy) {
     struct unit *punit=unit_list_get(ptile->units, 0);
-    if(game.info.player_idx==punit->owner) {
+
+    if (game.player_ptr == punit->owner) {
       if(can_unit_do_activity(punit, ACTIVITY_IDLE)) {
         maybe_goto = keyboardless_goto;
        set_unit_focus_and_select(punit);
@@ -1583,7 +1585,7 @@
     return NULL;
   } else if (listsize == 1) {
     struct unit *punit = unit_list_get(ptile->units, 0);
-    return (game.info.player_idx == punit->owner) ? punit : NULL;
+    return (game.player_ptr == punit->owner) ? punit : NULL;
   }
 
   /*  Quickselect priorities. Units with moves left
@@ -1600,7 +1602,7 @@
    */
 
     unit_list_iterate(ptile->units, punit)  {
-  if(game.info.player_idx != punit->owner || punit == punit_focus) {
+  if (game.player_ptr != punit->owner || punit == punit_focus) {
     continue;
   }
   if (qtype == SELECT_SEA) {
Index: client/mapctrl_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.c,v
retrieving revision 1.55
diff -u -r1.55 mapctrl_common.c
--- client/mapctrl_common.c     1 Jun 2005 00:32:31 -0000       1.55
+++ client/mapctrl_common.c     2 Jul 2005 05:54:17 -0000
@@ -144,7 +144,7 @@
 
       /*  Tile passed all tests; process it.
        */
-      if (ptile->city && ptile->city->owner == game.info.player_idx) {
+      if (ptile->city && ptile->city->owner == game.player_ptr) {
         map_deco[ptile->index].hilite = HILITE_CITY;
         tiles_hilited_cities = TRUE;
       }
@@ -286,7 +286,7 @@
       toggle_city_hilite(pcity, FALSE); /* cityrep.c */
     }
   }
-  else if (pcity && pcity->owner == game.info.player_idx) {
+  else if (pcity && pcity->owner == game.player_ptr) {
     map_deco[ptile->index].hilite = HILITE_CITY;
     tiles_hilited_cities = TRUE;
     toggle_city_hilite(pcity, TRUE);
@@ -327,7 +327,7 @@
   struct city *pcity = ptile->city;
 
   if (pcity) {
-    if (pcity->owner != game.info.player_idx)  {
+    if (pcity->owner != game.player_ptr)  {
       return;
     }
     clipboard = pcity->currently_building;
@@ -370,7 +370,7 @@
     return;
   }
   if (!tiles_hilited_cities) {
-    if (pcity && pcity->owner == game.info.player_idx) {
+    if (pcity && pcity->owner == game.player_ptr) {
       clipboard_send_production_packet(pcity);
     }
     return;
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.239
diff -u -r1.239 mapview_common.c
--- client/mapview_common.c     22 May 2005 18:12:52 -0000      1.239
+++ client/mapview_common.c     2 Jul 2005 05:54:17 -0000
@@ -1217,7 +1217,7 @@
   const struct citybar_sprites *citybar = get_citybar_sprites(tileset);
   const bool line1 = draw_city_names;
   const bool line2 = ((draw_city_productions || draw_city_growth)
-                     && pcity->owner == game.info.player_idx);
+                     && pcity->owner == game.player_ptr);
   static char name[512], growth[32], prod[512], size[32];
   enum color_std growth_color;
   struct color *owner_color;
@@ -1432,7 +1432,7 @@
     *width = MAX(*width, total_width);
     *height += total_height + 3;
   }
-  if (draw_city_productions && pcity->owner == game.info.player_idx) {
+  if (draw_city_productions && pcity->owner == game.player_ptr) {
     get_city_mapview_production(pcity, prod, sizeof(prod));
     get_text_size(&prod_rect.w, &prod_rect.h, FONT_CITY_PROD, prod);
 
@@ -1803,7 +1803,7 @@
   }
 
   if (pcity) {
-    if (pcity->owner == game.info.player_idx) {
+    if (pcity->owner == game.player_ptr) {
       /* rule a */
       return pcity;
     } else {
@@ -1817,7 +1817,7 @@
 
   city_map_checked_iterate(ptile, city_x, city_y, tile1) {
     pcity = tile_get_city(tile1);
-    if (pcity && pcity->owner == game.info.player_idx
+    if (pcity && pcity->owner == game.player_ptr
        && get_worker_city(pcity, CITY_MAP_SIZE - 1 - city_x,
                           CITY_MAP_SIZE - 1 - city_y) == C_TILE_EMPTY) {
       /*
@@ -1847,7 +1847,7 @@
 
     if (tile1) {
       unit_list_iterate(tile1->units, psettler) {
-       if (psettler->owner == game.info.player_idx
+       if (psettler->owner == game.player_ptr
            && unit_flag(psettler, F_CITIES)
            && city_can_be_built_here(psettler->tile, psettler)) {
          if (!closest_settler) {
@@ -2100,7 +2100,7 @@
 {
   my_snprintf(name_buffer, name_buffer_len, pcity->name);
 
-  if (pcity->owner == game.info.player_idx) {
+  if (pcity->owner == game.player_ptr) {
     int turns = city_turns_to_grow(pcity);
 
     if (turns == 0) {
Index: client/overview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/overview_common.c,v
retrieving revision 1.12
diff -u -r1.12 overview_common.c
--- client/overview_common.c    8 Jun 2005 21:11:29 -0000       1.12
+++ client/overview_common.c    2 Jul 2005 05:54:17 -0000
@@ -108,7 +108,7 @@
   if (client_tile_get_known(ptile) == TILE_UNKNOWN) {
     return get_color(tileset, COLOR_OVERVIEW_UNKNOWN);
   } else if ((pcity = tile_get_city(ptile))) {
-    if (pcity->owner == game.info.player_idx) {
+    if (pcity->owner == game.player_ptr) {
       return get_color(tileset, COLOR_OVERVIEW_MY_CITY);
     } else if (pplayers_allied(city_owner(pcity), game.player_ptr)) {
       /* Includes teams. */
@@ -117,7 +117,7 @@
       return get_color(tileset, COLOR_OVERVIEW_ENEMY_CITY);
     }
   } else if ((punit = find_visible_unit(ptile))) {
-    if (punit->owner == game.info.player_idx) {
+    if (punit->owner == game.player_ptr) {
       return get_color(tileset, COLOR_OVERVIEW_MY_UNIT);
     } else if (pplayers_allied(unit_owner(punit), game.player_ptr)) {
       /* Includes teams. */
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.525
diff -u -r1.525 packhand.c
--- client/packhand.c   21 Jun 2005 16:21:00 -0000      1.525
+++ client/packhand.c   2 Jul 2005 05:54:18 -0000
@@ -273,7 +273,7 @@
        tile_visible_mapcanvas(punit1->tile)) {
       show_combat = TRUE;
     } else if (auto_center_on_combat) {
-      if (punit0->owner == game.info.player_idx)
+      if (punit0->owner == game.player_ptr)
        center_tile_mapcanvas(punit0->tile);
       else
        center_tile_mapcanvas(punit1->tile);
@@ -383,7 +383,7 @@
 
   pcity=find_city_by_id(packet->id);
 
-  if (pcity && (pcity->owner != packet->owner)) {
+  if (pcity && (pcity->owner->player_no != packet->owner)) {
     client_remove_city(pcity);
     pcity = NULL;
     city_has_changed_owner = TRUE;
@@ -422,7 +422,7 @@
     assert(pcity->id == packet->id);
   }
   
-  pcity->owner=packet->owner;
+  pcity->owner = get_player(packet->owner);
   pcity->tile = map_pos_to_tile(packet->x, packet->y);
   sz_strlcpy(pcity->name, packet->name);
   
@@ -523,7 +523,7 @@
   pcity->client.unhappy = city_unhappy(pcity);
 
   popup = (city_is_new && can_client_change_view()
-           && pcity->owner == game.info.player_idx && popup_new_cities)
+           && pcity->owner == game.player_ptr && popup_new_cities)
           || packet->diplomat_investigate;
 
   if (city_is_new && !city_has_changed_owner) {
@@ -568,8 +568,9 @@
     pcity->info_units_present = unit_list_new();
     city_list_prepend(city_owner(pcity)->cities, pcity);
     tile_set_city(pcity->tile, pcity);
-    if(pcity->owner==game.info.player_idx)
+    if (pcity->owner == game.player_ptr) {
       city_report_dialog_update();
+    }
 
     for(i=0; i<game.info.nplayers; i++) {
       unit_list_iterate(game.players[i].units, punit) 
@@ -578,7 +579,7 @@
       unit_list_iterate_end;
     }
   } else {
-    if(pcity->owner == game.info.player_idx) {
+    if (pcity->owner == game.player_ptr) {
       city_report_dialog_update_city(pcity);
     }
   }
@@ -600,8 +601,7 @@
     }
   }
 
-  if (!is_new && (pcity->owner==game.info.player_idx
-                 || popup)) {
+  if (!is_new && (pcity->owner==game.player_ptr || popup)) {
     refresh_city_dialog(pcity);
   }
 
@@ -631,7 +631,7 @@
 
   pcity=find_city_by_id(packet->id);
 
-  if (pcity && (pcity->owner != packet->owner)) {
+  if (pcity && (pcity->owner->player_no != packet->owner)) {
     client_remove_city(pcity);
     pcity = NULL;
     city_has_changed_owner = TRUE;
@@ -653,7 +653,7 @@
       update_descriptions = TRUE;
     }
 
-    pcity->owner=packet->owner;
+    pcity->owner = get_player(packet->owner);
     sz_strlcpy(pcity->name, packet->name);
     
     assert(pcity->id == packet->id);
@@ -904,7 +904,7 @@
 {
   struct unit *punit;
 
-  if (packet->owner != game.info.player_idx ) {
+  if (packet->owner != game.info.player_idx) {
     freelog(LOG_ERROR, "Got packet_unit_info for unit of %s.",
             game.players[packet->owner].name);
   }
@@ -949,8 +949,7 @@
   bool ret = FALSE;
   struct unit *focus_unit = get_unit_in_focus();
   
-  punit = player_find_unit_by_id(get_player(packet_unit->owner),
-                                 packet_unit->id);
+  punit = player_find_unit_by_id(packet_unit->owner, packet_unit->id);
   if (!punit && find_unit_by_id(packet_unit->id)) {
     /* This means unit has changed owner. We deal with this here
      * by simply deleting the old one and creating a new one. */
@@ -995,7 +994,7 @@
       /* Wakeup Focus */
       if (wakeup_focus 
           && !game.player_ptr->ai.control
-          && punit->owner == game.info.player_idx
+          && punit->owner == game.player_ptr
           && punit->activity == ACTIVITY_SENTRY
           && packet_unit->activity == ACTIVITY_IDLE
          && is_player_phase(game.player_ptr, game.info.phase)
@@ -1038,7 +1037,7 @@
       punit->orders.list = packet_unit->orders.list;
       packet_unit->orders.list = NULL;
 
-      if (punit->owner == game.info.player_idx) {
+      if (punit->owner == game.player_ptr) {
         refresh_unit_city_dialogs(punit);
       }
     } /*** End of Change in activity or activity's target. ***/
@@ -1143,7 +1142,7 @@
        
         if((unit_flag(punit, F_TRADE_ROUTE) || unit_flag(punit, F_HELP_WONDER))
           && (!game.player_ptr->ai.control)
-          && punit->owner==game.info.player_idx
+          && punit->owner == game.player_ptr
           && !unit_has_orders(punit)
           && can_client_issue_orders()
           && (unit_can_help_build_wonder_here(punit)
@@ -1194,7 +1193,7 @@
     punit = packet_unit;
     idex_register_unit(punit);
 
-    unit_list_prepend(get_player(punit->owner)->units, punit);
+    unit_list_prepend(punit->owner->units, punit);
     unit_list_prepend(punit->tile->units, punit);
 
     if((pcity=find_city_by_id(punit->homecity))) {
@@ -1299,7 +1298,7 @@
     return;
   }
 
-  if (packet->owner == game.info.player_idx ) {
+  if (packet->owner == game.info.player_idx) {
     freelog(LOG_ERROR, "Got packet_short_unit for own unit.");
   }
 
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.311
diff -u -r1.311 tilespec.c
--- client/tilespec.c   9 Jun 2005 18:34:45 -0000       1.311
+++ client/tilespec.c   2 Jul 2005 05:54:18 -0000
@@ -4217,7 +4217,7 @@
   if (!punit)
     return NULL;
 
-  if (citymode && punit->owner == game.info.player_idx)
+  if (citymode && punit->owner == game.player_ptr)
     return NULL;
 
   if (punit != pfocus
Index: client/agents/sha.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/sha.c,v
retrieving revision 1.5
diff -u -r1.5 sha.c
--- client/agents/sha.c 5 May 2005 18:32:47 -0000       1.5
+++ client/agents/sha.c 2 Jul 2005 05:54:19 -0000
@@ -68,8 +68,7 @@
 static void sha_unit_new(int id)
 {
   struct unit *punit = find_unit_by_id(id);
-  struct unit *pold_unit = create_unit_virtual(get_player(punit->owner),
-                                              NULL, 0, 0);
+  struct unit *pold_unit = create_unit_virtual(punit->owner, NULL, 0, 0);
 
   freelog(LOG_DEBUG, "sha got unit: %d", id);
 
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/citydlg.c,v
retrieving revision 1.129
diff -u -r1.129 citydlg.c
--- client/gui-gtk-2.0/citydlg.c        5 May 2005 18:32:47 -0000       1.129
+++ client/gui-gtk-2.0/citydlg.c        2 Jul 2005 05:54:19 -0000
@@ -865,7 +865,7 @@
   GtkTreeModel *model;
   GtkTreePath *path;
 
-  if (pdialog->pcity->owner != game.info.player_idx) {
+  if (pdialog->pcity->owner != game.player_ptr) {
     gtk_drag_finish(context, FALSE, FALSE, time);
   }
     
@@ -1240,13 +1240,12 @@
   create_and_append_worklist_page(pdialog);
 
   /* only create these tabs if not a spy */
-  if (pcity->owner == game.info.player_idx) {
-
+  if (pcity->owner == game.player_ptr) {
     create_and_append_happiness_page(pdialog);
     create_and_append_cma_page(pdialog);
   }
 
-  if (pcity->owner == game.info.player_idx) {
+  if (pcity->owner == game.player_ptr) {
     create_and_append_settings_page(pdialog);
   } else {
     gtk_notebook_set_current_page(GTK_NOTEBOOK(pdialog->notebook),
@@ -1280,7 +1279,7 @@
   gtk_dialog_add_action_widget(GTK_DIALOG(pdialog->shell),
                               pdialog->next_command, 2);
   
-  if (pcity->owner != game.info.player_idx) {
+  if (pcity->owner != game.player_ptr) {
     gtk_widget_set_sensitive(pdialog->prev_command, FALSE);
     gtk_widget_set_sensitive(pdialog->next_command, FALSE);
   }
@@ -1630,7 +1629,7 @@
   int n, m, i;
   char buf[30];
 
-  if (pdialog->pcity->owner != game.info.player_idx) {
+  if (pdialog->pcity->owner != game.player_ptr) {
     units = pdialog->pcity->info_units_supported;
   } else {
     units = pdialog->pcity->units_supported;
@@ -1716,7 +1715,7 @@
          G_CALLBACK(supported_unit_middle_callback),
          GINT_TO_POINTER(punit->id));
 
-      if (pdialog->pcity->owner != game.info.player_idx) {
+      if (pdialog->pcity->owner != game.player_ptr) {
        gtk_widget_set_sensitive(cmd, FALSE);
       } else {
        gtk_widget_set_sensitive(cmd, TRUE);
@@ -1745,7 +1744,7 @@
   int n, m, i;
   char buf[30];
 
-  if (pdialog->pcity->owner != game.info.player_idx) {
+  if (pdialog->pcity->owner != game.player_ptr) {
     units = pdialog->pcity->info_units_present;
   } else {
     units = pdialog->pcity->tile->units;
@@ -1826,7 +1825,7 @@
          G_CALLBACK(present_unit_middle_callback),
          GINT_TO_POINTER(punit->id));
 
-      if (pdialog->pcity->owner != game.info.player_idx) {
+      if (pdialog->pcity->owner != game.player_ptr) {
        gtk_widget_set_sensitive(cmd, FALSE);
       } else {
        gtk_widget_set_sensitive(cmd, TRUE);
@@ -1860,7 +1859,7 @@
   /* the first time, we see if all the city dialogs are open */
 
   dialog_list_iterate(dialog_list, pdialog) {
-    if (pdialog->pcity->owner == game.info.player_idx)
+    if (pdialog->pcity->owner == game.player_ptr)
       count++;
   }
   dialog_list_iterate_end;
@@ -1873,7 +1872,7 @@
     dialog_list_iterate_end;
   } else {
     dialog_list_iterate(dialog_list, pdialog) {
-      if (pdialog->pcity->owner == game.info.player_idx) {
+      if (pdialog->pcity->owner == game.player_ptr) {
        gtk_widget_set_sensitive(pdialog->prev_command, TRUE);
        gtk_widget_set_sensitive(pdialog->next_command, TRUE);
       }
@@ -2491,8 +2490,8 @@
     return;
   }
 
-  if (pdialog->pcity->did_buy || pdialog->pcity->did_sell ||
-      pdialog->pcity->owner != game.info.player_idx) {
+  if (pdialog->pcity->did_buy || pdialog->pcity->did_sell
+      || pdialog->pcity->owner != game.player_ptr) {
     return;
   }
   
@@ -2728,7 +2727,7 @@
 
   gtk_widget_hide(pdialog->shell);
 
-  if (pdialog->pcity->owner == game.info.player_idx) {
+  if (pdialog->pcity->owner == game.player_ptr) {
     close_happiness_dialog(pdialog->pcity);
     close_cma_dialog(pdialog->pcity);
   }
@@ -2802,7 +2801,7 @@
 
   assert(city_dialogs_have_been_initialised);
   assert(size >= 1);
-  assert(pdialog->pcity->owner == game.info.player_idx);
+  assert(pdialog->pcity->owner == game.player_ptr);
 
   if (size == 1) {
     return;
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/dialogs.c,v
retrieving revision 1.107
diff -u -r1.107 dialogs.c
--- client/gui-gtk-2.0/dialogs.c        23 Jun 2005 07:24:38 -0000      1.107
+++ client/gui-gtk-2.0/dialogs.c        2 Jul 2005 05:54:20 -0000
@@ -1388,7 +1388,7 @@
       struct unit *pmyunit = NULL;
 
       unit_list_iterate(ptile->units, punit) {
-        if (game.info.player_idx == punit->owner) {
+        if (game.player_ptr == punit->owner) {
           pmyunit = punit;
 
           /* Activate this unit. */
@@ -1413,7 +1413,7 @@
   case SELECT_UNIT_SENTRY:
     {
       unit_list_iterate(ptile->units, punit) {
-        if (game.info.player_idx == punit->owner) {
+        if (game.player_ptr == punit->owner) {
           if ((punit->activity == ACTIVITY_IDLE) &&
               !punit->ai.control &&
               can_unit_do_activity(punit, ACTIVITY_SENTRY)) {
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.131
diff -u -r1.131 gui_main.c
--- client/gui-gtk-2.0/gui_main.c       30 Jun 2005 20:29:23 -0000      1.131
+++ client/gui-gtk-2.0/gui_main.c       2 Jul 2005 05:54:20 -0000
@@ -1454,10 +1454,9 @@
     return TRUE;
 
   punit = find_unit_by_id(unit_ids[i]);
-  if(punit) { /* should always be true at this point */
-    if (punit->owner == game.info.player_idx) {  /* may be non-true if 
alliance */
-      set_unit_focus(punit);
-    }
+  if (punit && punit->owner == game.player_ptr) {
+    /* Unit shouldn't be NULL but may be owned by an ally. */
+    set_unit_focus(punit);
   }
 
   return TRUE;
Index: client/gui-gtk-2.0/happiness.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/happiness.c,v
retrieving revision 1.22
diff -u -r1.22 happiness.c
--- client/gui-gtk-2.0/happiness.c      5 May 2005 18:32:47 -0000       1.22
+++ client/gui-gtk-2.0/happiness.c      2 Jul 2005 05:54:20 -0000
@@ -220,7 +220,7 @@
   int nleft = sizeof(buf);
 
   struct city *pcity = pdialog->pcity;
-  struct player *pplayer = &game.players[pcity->owner];
+  struct player *pplayer = pcity->owner;
   int cities = city_list_size(pplayer->cities);
   int content = game.info.unhappysize;
   int basis = game.info.cityfactor 
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.351
diff -u -r1.351 city.c
--- common/city.c       27 Jun 2005 14:30:17 -0000      1.351
+++ common/city.c       2 Jul 2005 05:54:21 -0000
@@ -384,7 +384,7 @@
 **************************************************************************/
 struct player *city_owner(const struct city *pcity)
 {
-  return (&game.players[pcity->owner]);
+  return pcity->owner;
 }
 
 /**************************************************************************
@@ -2356,7 +2356,7 @@
   Create virtual skeleton for a city.  It does not register the city so 
   the id is set to 0.  All other values are more or less sane defaults.
 **************************************************************************/
-struct city *create_city_virtual(const struct player *pplayer,
+struct city *create_city_virtual(struct player *pplayer,
                                 struct tile *ptile, const char *name)
 {
   int i;
@@ -2365,7 +2365,8 @@
   pcity = fc_malloc(sizeof(struct city));
 
   pcity->id = 0;
-  pcity->owner = pplayer->player_no;
+  assert(pplayer != NULL); /* No unowned cities! */
+  pcity->owner = pplayer;
   pcity->tile = ptile;
   sz_strlcpy(pcity->name, name);
   pcity->size = 1;
@@ -2385,7 +2386,7 @@
   }
   pcity->food_stock = 0;
   pcity->shield_stock = 0;
-  pcity->original = pplayer->player_no;
+  pcity->original = pplayer;
 
   /* Initialise improvements list */
   for (i = 0; i < ARRAY_SIZE(pcity->improvements); i++) {
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.215
diff -u -r1.215 city.h
--- common/city.h       27 Jun 2005 14:30:17 -0000      1.215
+++ common/city.h       2 Jul 2005 05:54:21 -0000
@@ -209,7 +209,7 @@
 
 struct city {
   int id;
-  int owner;
+  struct player *owner; /* Cannot be NULL. */
   struct tile *tile;
   char name[MAX_LEN_NAME];
 
@@ -290,7 +290,7 @@
   int rapture;                /* rapture rounds count */ 
   bool was_happy;
   bool airlift;
-  int original;                        /* original owner */
+  struct player *original;     /* original owner - cannot be NULL */
   int city_options;            /* bitfield; positions as enum city_options */
 
   /* server variable. indicates if the city map is synced with the client. */
@@ -511,7 +511,7 @@
 bool city_built_last_turn(const struct city *pcity);
 
 /* city creation / destruction */
-struct city *create_city_virtual(const struct player *pplayer,
+struct city *create_city_virtual(struct player *pplayer,
                                 struct tile *ptile, const char *name);
 void remove_city_virtual(struct city *pcity);
 
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.186
diff -u -r1.186 player.c
--- common/player.c     21 Jun 2005 16:21:01 -0000      1.186
+++ common/player.c     2 Jul 2005 05:54:21 -0000
@@ -75,11 +75,7 @@
 ****************************************************************************/
 bool player_owns_city(const struct player *pplayer, const struct city *pcity)
 {
-  if (!pcity || !pplayer) {
-    /* better safe than sorry */
-    return FALSE;
-  }
-  return (pcity->owner==pplayer->player_no);
+  return (pcity && pplayer && pcity->owner == pplayer);
 }
 
 /***************************************************************
@@ -335,12 +331,8 @@
                                    int city_id)
 {
   struct city *pcity = idex_lookup_city(city_id);
-  
-  if(pcity && (pcity->owner==pplayer->player_no)) {
-    return pcity;
-  } else {
-    return NULL;
-  }
+
+  return (pcity && pcity->owner == pplayer) ? pcity : NULL;
 }
 
 /***************************************************************
@@ -352,12 +344,8 @@
                                    int unit_id)
 {
   struct unit *punit = idex_lookup_unit(unit_id);
-  
-  if(punit && (punit->owner==pplayer->player_no)) {
-    return punit;
-  } else {
-    return NULL;
-  }
+
+  return (punit && punit->owner == pplayer) ? punit : NULL;
 }
 
 /*************************************************************************
@@ -366,11 +354,12 @@
 bool player_in_city_radius(const struct player *pplayer,
                           const struct tile *ptile)
 {
-  struct city *pcity;
   map_city_radius_iterate(ptile, ptile1) {
-    pcity = tile_get_city(ptile1);
-    if (pcity && (pcity->owner == pplayer->player_no))
+    struct city *pcity = tile_get_city(ptile1);
+
+    if (pcity && pcity->owner == pplayer) {
       return TRUE;
+    }
   } map_city_radius_iterate_end;
   return FALSE;
 }
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.242
diff -u -r1.242 unit.c
--- common/unit.c       17 Jun 2005 23:03:35 -0000      1.242
+++ common/unit.c       2 Jul 2005 05:54:22 -0000
@@ -1121,9 +1121,7 @@
 **************************************************************************/
 struct player *unit_owner(const struct unit *punit)
 {
-  /* FIXME: if punit->owner were a player pointer then this function couldn't
-   * have a const parameter. */
-  return (&game.players[punit->owner]);
+  return punit->owner;
 }
 
 /****************************************************************************
@@ -1437,7 +1435,8 @@
   struct unit *punit = fc_calloc(1, sizeof(struct unit));
 
   punit->type = type;
-  punit->owner = pplayer->player_no;
+  assert(pplayer != NULL); /* No unowned units! */
+  punit->owner = pplayer;
   if (pcity) {
     punit->tile = pcity->tile;
     punit->homecity = pcity->id;
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.144
diff -u -r1.144 unit.h
--- common/unit.h       7 Jun 2005 06:17:13 -0000       1.144
+++ common/unit.h       2 Jul 2005 05:54:22 -0000
@@ -126,7 +126,7 @@
 struct unit {
   Unit_type_id type;
   int id;
-  int owner;
+  struct player *owner; /* Cannot be NULL. */
   struct tile *tile;
   int homecity;
   int moves_left;
Index: common/aicore/caravan.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/caravan.c,v
retrieving revision 1.1
diff -u -r1.1 caravan.c
--- common/aicore/caravan.c     31 May 2005 03:10:33 -0000      1.1
+++ common/aicore/caravan.c     2 Jul 2005 05:54:22 -0000
@@ -243,13 +243,14 @@
   How much does the city benefit from the new trade route?
   How much does the former partner lose?
  ***************************************************************************/
-static int one_city_trade_benefit(const struct city *pcity, int playerid,
+static int one_city_trade_benefit(const struct city *pcity,
+                                 const struct player *pplayer,
                                   bool countloser, int newtrade) {
   int losttrade = 0;
 
   /* if the city is owned by someone else, we don't benefit from the
      new trade (but we might still lose from a broken trade route) */
-  if (pcity->owner != playerid) {
+  if (pcity->owner != pplayer) {
     newtrade = 0;
   }
 
@@ -263,13 +264,13 @@
 
     /* if we own the city, the trade benefit is only by how much
        better we are than the old trade route */
-    if (pcity->owner == playerid) {
+    if (pcity->owner == pplayer) {
       newtrade -= oldtrade;
     }
 
     /* if the city that lost a trade route is one of ours, and if we
        care about accounting for the lost trade, count it. */
-    if (countloser && losercity->owner == playerid) {
+    if (countloser && losercity->owner == pplayer) {
       losttrade = oldtrade;
     }
   }
@@ -283,7 +284,7 @@
   This yields the total benefit in terms of trade per turn of establishing
   a route from src to dest.
  ***************************************************************************/
-static double trade_benefit(int caravan_owner,
+static double trade_benefit(const struct player *caravan_owner,
                             const struct city *src,
                             const struct city *dest,
                             const struct caravan_parameter *param) {
@@ -603,12 +604,11 @@
                                        const struct caravan_parameter *param,
                                        struct caravan_result *best)
 {
-  struct player *player;
+  struct player *player = caravan->owner;
 
   /* Iterate over all cities we own (since the caravan could change its
    * home city); iterate over all cities we know about (places the caravan
    * can go to); pick out the best trade route. */
-  player = get_player(caravan->owner);
   city_list_iterate(player->cities, src) {
     cities_iterate(dest) {
       struct caravan_result current;
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.66
diff -u -r1.66 cm.c
--- common/aicore/cm.c  10 May 2005 19:08:55 -0000      1.66
+++ common/aicore/cm.c  2 Jul 2005 05:54:24 -0000
@@ -1570,7 +1570,7 @@
 static double estimate_fitness(const struct cm_state *state,
                               const int production[]) {
   const struct city *pcity = state->pcity;
-  const struct player *pplayer = get_player(pcity->owner);
+  const struct player *pplayer = pcity->owner;
   double estimates[O_COUNT];
   double sum = 0;
 
Index: server/barbarian.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/barbarian.c,v
retrieving revision 1.93
diff -u -r1.93 barbarian.c
--- server/barbarian.c  23 Jun 2005 21:58:23 -0000      1.93
+++ server/barbarian.c  2 Jul 2005 05:54:24 -0000
@@ -200,7 +200,7 @@
   struct player *barbarians;
   int unit, unit_cnt, land_cnt = 0, sea_cnt = 0;
   int boat;
-  int i, me;
+  int i;
   struct tile *utile = NULL;
   bool alive = TRUE;     /* explorer survived */
 
@@ -216,7 +216,6 @@
   unit_cnt = 3 + myrand(4);
 
   barbarians = create_barbarian_player(TRUE);
-  me = barbarians->player_no;
 
   for (i = 0; i < unit_cnt; i++) {
     unit = find_a_unit_type(L_BARBARIAN, L_BARBARIAN_TECH);
@@ -231,7 +230,7 @@
 
   if (land_cnt >= 3) {           /* enough land, scatter guys around */
     unit_list_iterate((ptile)->units, punit2) {
-      if (punit2->owner == me) {
+      if (punit2->owner == barbarians) {
         send_unit_info(NULL, punit2);
        do {
          do {
@@ -249,7 +248,7 @@
       /* FIXME: If anyone knows what this code is supposed to do, rewrite
        * this comment to explain it. */
       unit_list_iterate((ptile)->units, punit2) {
-        if (punit2->owner == me) {
+        if (punit2->owner == barbarians) {
           send_unit_info(NULL, punit2);
           while(TRUE) {
            utile = rand_neighbour(ptile);
@@ -272,7 +271,7 @@
       } unit_list_iterate_end;
     } else {             /* The village is surrounded! Kill the explorer. */
       unit_list_iterate_safe((ptile)->units, punit2) {
-        if (punit2->owner != me) {
+        if (punit2->owner != barbarians) {
           wipe_unit(punit2);
           alive = FALSE;
         } else {
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.330
diff -u -r1.330 citytools.c
--- server/citytools.c  29 Jun 2005 02:17:53 -0000      1.330
+++ server/citytools.c  2 Jul 2005 05:54:24 -0000
@@ -800,7 +800,7 @@
 
   /* Has to follow the unfog call above. */
   city_list_unlink(pgiver->cities, pcity);
-  pcity->owner = ptaker->player_no;
+  pcity->owner = ptaker;
   city_list_prepend(ptaker->cities, pcity);
 
   /* Update the national borders. */
@@ -1223,7 +1223,7 @@
   pplayer->economic.gold += coins;
   cplayer->economic.gold -= coins;
   send_player_info(cplayer, cplayer);
-  if (pcity->original != pplayer->player_no) {
+  if (pcity->original != pplayer) {
     notify_player_ex(pplayer, pcity->tile, E_UNIT_WIN_ATT, 
                     _("You conquer %s, your lootings accumulate"
                       " to %d gold!"), 
@@ -1289,7 +1289,7 @@
   struct city *pcity = tile_get_city(ptile);
 
   packet->id = pdcity->id;
-  packet->owner = pdcity->owner;
+  packet->owner = pdcity->owner->player_no;
   packet->x = ptile->x;
   packet->y = ptile->y;
   sz_strlcpy(packet->name, pdcity->name);
@@ -1521,7 +1521,7 @@
   int x, y, i;
 
   packet->id=pcity->id;
-  packet->owner=pcity->owner;
+  packet->owner = pcity->owner->player_no;
   packet->x = pcity->tile->x;
   packet->y = pcity->tile->y;
   sz_strlcpy(packet->name, pcity->name);
@@ -1878,7 +1878,7 @@
     return FALSE;
   }
 
-  if (ptile->owner && ptile->owner->player_no != pcity->owner) {
+  if (ptile->owner && ptile->owner != pcity->owner) {
     return FALSE;
   }
 
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.322
diff -u -r1.322 cityturn.c
--- server/cityturn.c   28 Jun 2005 17:32:53 -0000      1.322
+++ server/cityturn.c   2 Jul 2005 05:54:25 -0000
@@ -1363,7 +1363,7 @@
 
   /* Buy back is cheap, conquered cities are also cheap */
   if (pcity->owner != pcity->original) {
-    if (pplayer->player_no == pcity->original) {
+    if (pplayer == pcity->original) {
       cost /= 2;            /* buy back: 50% price reduction */
     } else {
       cost = cost * 2 / 3;  /* buy conquered: 33% price reduction */
Index: server/diplhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplhand.c,v
retrieving revision 1.97
diff -u -r1.97 diplhand.c
--- server/diplhand.c   1 Jul 2005 08:25:34 -0000       1.97
+++ server/diplhand.c   2 Jul 2005 05:54:25 -0000
@@ -167,7 +167,7 @@
                            "you can't accept treaty."));
            return;
          }
-         if (pcity->owner != pplayer->player_no) {
+         if (pcity->owner != pplayer) {
            notify_player(pplayer,
                          _("You are not owner of %s, you can't accept 
treaty."),
                          pcity->name);
@@ -262,7 +262,7 @@
                          get_nation_name_plural(pother->nation));
            goto cleanup;
          }
-         if (pcity->owner != pother->player_no) {
+         if (pcity->owner != pother) {
            notify_player(pplayer,
                          _("The %s no longer control %s! "
                            "Treaty canceled!"),
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.167
diff -u -r1.167 maphand.c
--- server/maphand.c    30 Jun 2005 19:12:57 -0000      1.167
+++ server/maphand.c    2 Jul 2005 05:54:25 -0000
@@ -1680,7 +1680,7 @@
   if (game.info.borders > 0) {
     iterate_outward(ptile, game.info.borders, tile1) {
       struct city *pccity = map_get_closest_city(tile1);
-      struct player *new_owner = pccity ? get_player(pccity->owner) : NULL;
+      struct player *new_owner = pccity ? pccity->owner : NULL;
 
       if (new_owner != tile_get_owner(tile1)) {
        tile_set_owner(tile1, new_owner);
@@ -1780,7 +1780,7 @@
        struct city *pccity = map_get_closest_city(ptile);
 
        if (pccity) {
-         tile_set_owner(ptile, get_player(pccity->owner));
+         tile_set_owner(ptile, pccity->owner);
        }
       } iterate_outward_end;
     } cities_iterate_end;
Index: server/maphand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.h,v
retrieving revision 1.57
diff -u -r1.57 maphand.h
--- server/maphand.h    30 Jun 2005 19:12:57 -0000      1.57
+++ server/maphand.h    2 Jul 2005 05:54:25 -0000
@@ -33,7 +33,7 @@
   bool happy, unhappy;
   char name[MAX_LEN_NAME];
   unsigned short size;
-  unsigned char owner;
+  struct player *owner; /* City owner - cannot be NULL. */
 
   bv_imprs improvements;
 };
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.394
diff -u -r1.394 plrhand.c
--- server/plrhand.c    29 Jun 2005 08:53:17 -0000      1.394
+++ server/plrhand.c    2 Jul 2005 05:54:26 -0000
@@ -157,12 +157,11 @@
   palace = game.info.savepalace;
   game.info.savepalace = FALSE; /* moving it around is dumb */
   city_list_iterate(pplayer->cities, pcity) {
-    if ((pcity->original != pplayer->player_no)
-        && (get_player(pcity->original)->is_alive)) {
+    if (pcity->original != pplayer && pcity->original->is_alive) {
       /* Transfer city to original owner, kill all its units outside of
          a radius of 3, give verbose messages of every unit transferred,
          and raze buildings according to raze chance (also removes palace) */
-      transfer_city(get_player(pcity->original), pcity, 3, TRUE, TRUE, TRUE);
+      transfer_city(pcity->original, pcity, 3, TRUE, TRUE, TRUE);
     }
   } city_list_iterate_end;
 
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.67
diff -u -r1.67 sanitycheck.c
--- server/sanitycheck.c        7 Jun 2005 06:17:14 -0000       1.67
+++ server/sanitycheck.c        2 Jul 2005 05:54:26 -0000
@@ -208,8 +208,7 @@
                  "empty but occupied by an enemy unit!",
                  pcity->name, TILE_XY(ptile));
        }
-       if (game.info.borders > 0
-           && owner && owner->player_no != pcity->owner) {
+       if (game.info.borders > 0 && owner && owner != pcity->owner) {
          freelog(LOG_ERROR, "Tile at %s->%d,%d marked as "
                  "empty but in enemy territory!",
                  pcity->name, TILE_XY(ptile));
@@ -232,8 +231,7 @@
                  "worked but occupied by an enemy unit!",
                  pcity->name, TILE_XY(ptile));
        }
-       if (game.info.borders > 0
-           && owner && owner->player_no != pcity->owner) {
+       if (game.info.borders > 0 && owner && owner != pcity->owner) {
          freelog(LOG_ERROR, "Tile at %s->%d,%d marked as "
                  "worked but in enemy territory!",
                  pcity->name, TILE_XY(ptile));
@@ -372,7 +370,7 @@
        SANITY_CHECK(transporter2 != NULL);
 
         /* Also in the list of owner? */
-        SANITY_CHECK(player_find_unit_by_id(get_player(transporter->owner),
+        SANITY_CHECK(player_find_unit_by_id(transporter->owner,
                                      punit->transported_by) != NULL);
         SANITY_CHECK(same_pos(ptile, transporter->tile));
 
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.258
diff -u -r1.258 savegame.c
--- server/savegame.c   30 Jun 2005 19:12:57 -0000      1.258
+++ server/savegame.c   2 Jul 2005 05:54:27 -0000
@@ -2111,12 +2111,15 @@
     pcity->id=secfile_lookup_int(file, "player%d.c%d.id", plrno, i);
     alloc_id(pcity->id);
     idex_register_city(pcity);
-    
-    if (section_file_lookup(file, "player%d.c%d.original", plrno, i))
-      pcity->original = secfile_lookup_int(file, "player%d.c%d.original", 
-                                          plrno,i);
-    else 
-      pcity->original = plrno;
+
+    id = secfile_lookup_int_default(file, -1,
+                                   "player%d.c%d.original", plrno, i);
+    if (id >= 0 && id < game.info.nplayers) {
+      pcity->original = get_player(id);
+    } else {
+      pcity->original = get_player(plrno);
+    }
+
     pcity->size=secfile_lookup_int(file, "player%d.c%d.size", plrno, i);
 
     pcity->steal=secfile_lookup_int(file, "player%d.c%d.steal", plrno, i);
@@ -2506,7 +2509,8 @@
                                        "player%d.dc%d.happy", plrno, j);
        pdcity->unhappy = secfile_lookup_bool_default(file, FALSE,
                                        "player%d.dc%d.unhappy", plrno, j);
-       pdcity->owner = secfile_lookup_int(file, "player%d.dc%d.owner", plrno, 
j);
+       id = secfile_lookup_int(file, "player%d.dc%d.owner", plrno, j);
+       pdcity->owner = get_player(id);
 
        /* Initialise list of improvements */
        BV_CLR_ALL(pdcity->improvements);
@@ -2934,8 +2938,8 @@
     secfile_insert_int(file, pcity->tile->nat_x, "player%d.c%d.x", plrno, i);
     secfile_insert_int(file, pcity->tile->nat_y, "player%d.c%d.y", plrno, i);
     secfile_insert_str(file, pcity->name, "player%d.c%d.name", plrno, i);
-    secfile_insert_int(file, pcity->original, "player%d.c%d.original", 
-                      plrno, i);
+    secfile_insert_int(file, pcity->original->player_no,
+                      "player%d.c%d.original", plrno, i);
     secfile_insert_int(file, pcity->size, "player%d.c%d.size", plrno, i);
     secfile_insert_int(file, pcity->steal, "player%d.c%d.steal", plrno, i);
     specialist_type_iterate(sp) {
@@ -3133,8 +3137,8 @@
                              "player%d.dc%d.happy", plrno, i);
          secfile_insert_bool(file, pdcity->unhappy,
                              "player%d.dc%d.unhappy", plrno, i);
-         secfile_insert_int(file, pdcity->owner, "player%d.dc%d.owner",
-                            plrno, i);
+         secfile_insert_int(file, pdcity->owner->player_no,
+                            "player%d.dc%d.owner", plrno, i);
 
          /* Save improvement list as bitvector. Note that improvement order
           * is saved in savefile.improvement_order.
Index: server/score.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/score.c,v
retrieving revision 1.23
diff -u -r1.23 score.c
--- server/score.c      21 Jun 2005 16:21:02 -0000      1.23
+++ server/score.c      2 Jul 2005 05:54:27 -0000
@@ -37,7 +37,7 @@
 
 struct claim_cell {
   int when;
-  int whom;
+  const struct player *whom;
   bv_player know;
   int cities;
 };
@@ -138,8 +138,6 @@
 
 #endif
 
-static int no_owner = MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS;
-
 /**************************************************************************
   allocate and clear claim map; determine city radii
 **************************************************************************/
@@ -163,7 +161,7 @@
   players_iterate(pplayer) {
     city_list_iterate(pplayer->cities, pcity) {
       map_city_radius_iterate(pcity->tile, tile1) {
-       pcmap->claims[tile1->index].cities |= (1u << pcity->owner);
+       pcmap->claims[tile1->index].cities |= (1u << pcity->owner->player_no);
       } map_city_radius_iterate_end;
     } city_list_iterate_end;
   } players_iterate_end;
@@ -174,9 +172,10 @@
 **************************************************************************/
 static void build_landarea_map_turn_0(struct claim_map *pcmap)
 {
-  int turn, owner;
+  int turn;
   struct tile **nextedge;
   struct claim_cell *pclaim;
+  struct player *owner;
 
   turn = 0;
   nextedge = pcmap->edges;
@@ -189,7 +188,7 @@
 
     if (is_ocean(ptile->terrain)) {
       /* pclaim->when = 0; */
-      pclaim->whom = no_owner;
+      pclaim->whom = NULL;
       /* pclaim->know = 0; */
     } else if (ptile->city) {
       owner = ptile->city->owner;
@@ -197,8 +196,8 @@
       pclaim->whom = owner;
       *nextedge = ptile;
       nextedge++;
-      pcmap->player_landarea[owner]++;
-      pcmap->player_owndarea[owner]++;
+      pcmap->player_landarea[owner->player_no]++;
+      pcmap->player_owndarea[owner->player_no]++;
       pclaim->know = ptile->tile_known;
     } else if (ptile->worked) {
       owner = ptile->worked->owner;
@@ -206,8 +205,8 @@
       pclaim->whom = owner;
       *nextedge = ptile;
       nextedge++;
-      pcmap->player_landarea[owner]++;
-      pcmap->player_owndarea[owner]++;
+      pcmap->player_landarea[owner->player_no]++;
+      pcmap->player_owndarea[owner->player_no]++;
       pclaim->know = ptile->tile_known;
     } else if (unit_list_size(ptile->units) > 0) {
       owner = (unit_list_get(ptile->units, 0))->owner;
@@ -215,14 +214,14 @@
       pclaim->whom = owner;
       *nextedge = ptile;
       nextedge++;
-      pcmap->player_landarea[owner]++;
-      if (TEST_BIT(pclaim->cities, owner)) {
-       pcmap->player_owndarea[owner]++;
+      pcmap->player_landarea[owner->player_no]++;
+      if (TEST_BIT(pclaim->cities, owner->player_no)) {
+       pcmap->player_owndarea[owner->player_no]++;
       }
       pclaim->know = ptile->tile_known;
     } else {
       /* pclaim->when = 0; */
-      pclaim->whom = no_owner;
+      pclaim->whom = NULL;
       pclaim->know = ptile->tile_known;
     }
   } whole_map_iterate_end;
@@ -240,7 +239,7 @@
 static void build_landarea_map_expand(struct claim_map *pcmap)
 {
   struct tile **midedge;
-  int turn, accum, other;
+  int turn, accum;
   struct tile **thisedge;
   struct tile **nextedge;
 
@@ -253,33 +252,33 @@
     for (accum = 0; *thisedge; thisedge++) {
       struct tile *ptile = *thisedge;
       int i = ptile->index;
-      int owner = pcmap->claims[i].whom;
+      const struct player *owner = pcmap->claims[i].whom, *other;
 
-      if (owner != no_owner) {
+      if (owner) {
        adjc_iterate(ptile, tile1) {
          int j = tile1->index;
          struct claim_cell *pclaim = &pcmap->claims[j];
 
-         if (BV_ISSET(pclaim->know, owner)) {
+         if (BV_ISSET(pclaim->know, owner->player_no)) {
            if (pclaim->when == 0) {
              pclaim->when = turn + 1;
              pclaim->whom = owner;
              *nextedge = tile1;
              nextedge++;
-             pcmap->player_landarea[owner]++;
-             if (TEST_BIT(pclaim->cities, owner)) {
-               pcmap->player_owndarea[owner]++;
+             pcmap->player_landarea[owner->player_no]++;
+             if (TEST_BIT(pclaim->cities, owner->player_no)) {
+               pcmap->player_owndarea[owner->player_no]++;
              }
              accum++;
            } else if (pclaim->when == turn + 1
-                      && pclaim->whom != no_owner
+                      && pclaim->whom
                       && pclaim->whom != owner) {
              other = pclaim->whom;
-             if (TEST_BIT(pclaim->cities, other)) {
-               pcmap->player_owndarea[other]--;
+             if (TEST_BIT(pclaim->cities, other->player_no)) {
+               pcmap->player_owndarea[other->player_no]--;
              }
-             pcmap->player_landarea[other]--;
-             pclaim->whom = no_owner;
+             pcmap->player_landarea[other->player_no]--;
+             pclaim->whom = NULL;
              accum--;
            }
          }
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.241
diff -u -r1.241 settlers.c
--- server/settlers.c   26 Jun 2005 09:30:11 -0000      1.241
+++ server/settlers.c   2 Jul 2005 05:54:27 -0000
@@ -858,7 +858,7 @@
 
       /* do not go to tiles that already have workers there */
       unit_list_iterate(ptile->units, aunit) {
-       if (aunit->owner == pplayer->player_no
+       if (aunit->owner == pplayer
            && aunit->id != punit->id
            && unit_flag(aunit, F_SETTLERS)) {
          consider = FALSE;
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.341
diff -u -r1.341 unithand.c
--- server/unithand.c   27 Jun 2005 08:30:34 -0000      1.341
+++ server/unithand.c   2 Jul 2005 05:54:27 -0000
@@ -284,7 +284,7 @@
 
     unit_list_unlink(old_owner->units, punit);
     unit_list_prepend(new_owner->units, punit);
-    punit->owner = new_owner->player_no;
+    punit->owner = new_owner;
 
     if (tile_has_special(punit->tile, S_FORTRESS)
         && unit_profits_of_watchtower(punit)) {
@@ -621,13 +621,13 @@
     if (map_is_known_and_seen(pattacker->tile, other_player)
        || map_is_known_and_seen(pdefender->tile, other_player)) {
       if (!can_player_see_unit(other_player, pattacker)) {
-       assert(other_player->player_no != pattacker->owner);
+       assert(other_player != pattacker->owner);
        lsend_packet_unit_short_info(other_player->connections,
                                     &unit_att_short_packet);
       }
 
       if (!can_player_see_unit(other_player, pdefender)) {
-       assert(other_player->player_no != pdefender->owner);
+       assert(other_player != pdefender->owner);
        lsend_packet_unit_short_info(other_player->connections,
                                     &unit_def_short_packet);
       }
@@ -1565,8 +1565,7 @@
 
   /* You are allowed to unload a unit if it is yours or if the transporter
    * is yours. */
-  if (pcargo->owner != pplayer->player_no
-      && ptrans->owner != pplayer->player_no) {
+  if (pcargo->owner != pplayer && ptrans->owner != pplayer) {
     return;
   }
 
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.366
diff -u -r1.366 unittools.c
--- server/unittools.c  28 Jun 2005 22:38:09 -0000      1.366
+++ server/unittools.c  2 Jul 2005 05:54:28 -0000
@@ -1798,10 +1798,11 @@
     }
 
     /* count killed units */
-    unit_list_iterate(punit->tile->units, vunit)
-      if (pplayers_at_war(unit_owner(pkiller), unit_owner(vunit)))
-       num_killed[vunit->owner]++;
-    unit_list_iterate_end;
+    unit_list_iterate(punit->tile->units, vunit) {
+      if (pplayers_at_war(unit_owner(pkiller), unit_owner(vunit))) {
+       num_killed[vunit->owner->player_no]++;
+      }
+    } unit_list_iterate_end;
 
     /* inform the owners */
     for (i = 0; i<MAX_NUM_PLAYERS+MAX_NUM_BARBARIANS; i++) {
@@ -1842,7 +1843,7 @@
 void package_unit(struct unit *punit, struct packet_unit_info *packet)
 {
   packet->id = punit->id;
-  packet->owner = punit->owner;
+  packet->owner = punit->owner->player_no;
   packet->x = punit->tile->x;
   packet->y = punit->tile->y;
   packet->homecity = punit->homecity;
@@ -1921,7 +1922,7 @@
   packet->info_city_id = info_city_id;
 
   packet->id = punit->id;
-  packet->owner = punit->owner;
+  packet->owner = punit->owner->player_no;
   packet->x = punit->tile->x;
   packet->y = punit->tile->y;
   packet->veteran = punit->veteran;
@@ -1992,8 +1993,7 @@
   conn_list_iterate(dest, pconn) {
     struct player *pplayer = pconn->player;
     
-    if ((!pplayer && pconn->observer) 
-       || pplayer->player_no == punit->owner) {
+    if ((!pplayer && pconn->observer) || pplayer == punit->owner) {
       send_packet_unit_info(pconn, &info);
     } else {
       if (can_player_see_unit_at(pplayer, punit, punit->tile)
@@ -3022,7 +3022,7 @@
     struct dumb_city *pdcity = map_get_player_tile(ptile, pplayer)->city;
 
     if ((penemy && can_player_see_unit(pplayer, penemy))
-       || (pdcity && !pplayers_allied(pplayer, get_player(pdcity->owner))
+       || (pdcity && !pplayers_allied(pplayer, pdcity->owner)
            && pdcity->occupied)) {
       cancel = TRUE;
       break;
Index: server/scripting/api.pkg
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api.pkg,v
retrieving revision 1.9
diff -u -r1.9 api.pkg
--- server/scripting/api.pkg    11 May 2005 00:53:22 -0000      1.9
+++ server/scripting/api.pkg    2 Jul 2005 05:54:28 -0000
@@ -40,7 +40,7 @@
 
 struct City {
   const char *name;
-  int owner @ owner_id;
+  Player *owner;
   Tile *tile;
 
   const int id;
@@ -48,7 +48,7 @@
 
 struct Unit {
   int type @ type_id;
-  int owner @ owner_id;
+  Player *owner;
   int homecity @ homecity_id;
   Tile *tile;
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13391) make 'owner' fields into pointers, Jason Short <=