Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] (PR#4676) clean up pcity->occupied usage
Home

[Freeciv-Dev] (PR#4676) clean up pcity->occupied usage

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4676) clean up pcity->occupied usage
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 24 Jul 2003 19:34:42 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch cleans this usage up in two ways:

1.  Instead of pcity->occupied it's now pcity->client.occupied.  This 
makes it harder to accidentally use it at the server (which was one of 
the original bugs with this code), and is a prelude for more 
client-side-only fields (see PR#3771).  Of course this means all users 
have to be changed.

2.  Lots of comments added about the client-side usage of this field. 
I've satisfied myself that the client side of the code is correct, and 
put this explanation into the comments.

jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.320
diff -u -r1.320 packhand.c
--- client/packhand.c   2003/07/23 13:46:01     1.320
+++ client/packhand.c   2003/07/25 02:31:16
@@ -457,7 +457,9 @@
                                    &need_effect_update);
   } impr_type_iterate_end;
 
-  pcity->occupied =
+  /* Since we can see inside the city, just determine the occupied status
+   * from the units present. */
+  pcity->client.occupied =
       (unit_list_size(&(map_get_tile(pcity->x, pcity->y)->units)) > 0);
 
   popup = (city_is_new && can_client_change_view() && 
@@ -591,8 +593,11 @@
   
   pcity->size=packet->size;
   pcity->tile_trade = packet->tile_trade;
-  pcity->occupied = packet->occupied;
 
+  /* We can't actually see the internals of the city, but the server tells
+   * us this much. */
+  pcity->client.occupied = packet->occupied;
+
   if (packet->happy) {
     pcity->ppl_happy[4]   = pcity->size;
     pcity->ppl_unhappy[4] = 0;
@@ -993,7 +998,11 @@
         return;
       }
       if(pcity)  {
-       pcity->occupied =
+       /* Unit moved out of a city - update the occupied status.  The
+        * logic is a little shaky since it's not clear whether we can
+        * see the internals of the city or not; however, the server should
+        * send us a city update to clear things up. */
+       pcity->client.occupied =
            (unit_list_size(&(map_get_tile(pcity->x, pcity->y)->units)) > 0);
 
         if(pcity->id==punit->homecity)
@@ -1003,7 +1012,9 @@
       }
       
       if((pcity=map_get_city(punit->x, punit->y)))  {
-       pcity->occupied = TRUE;
+       /* Unit moved into a city - obviously it's occupied. */
+       pcity->client.occupied = TRUE;
+
         if(pcity->id == punit->homecity)
          repaint_city = TRUE;
        else
@@ -1086,7 +1097,8 @@
     agents_unit_new(punit);
 
     if ((pcity = map_get_city(punit->x, punit->y))) {
-      pcity->occupied = TRUE;
+      /* The unit is in a city - obviously it's occupied. */
+      pcity->client.occupied = TRUE;
     }
   }
 
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.124
diff -u -r1.124 tilespec.c
--- client/tilespec.c   2003/07/24 16:17:21     1.124
+++ client/tilespec.c   2003/07/25 02:31:16
@@ -1269,7 +1269,7 @@
     }
   }
 
-  if (pcity->occupied) {
+  if (pcity->client.occupied) {
     *sprs++ = get_city_occupied_sprite(pcity);
   }
 
@@ -1312,7 +1312,7 @@
     *sprs++ = get_city_nation_flag_sprite(pcity);
   }
 
-  if (pcity->occupied) {
+  if (pcity->client.occupied) {
     *sprs++ = get_city_occupied_sprite(pcity);
   }
 
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.132
diff -u -r1.132 city.h
--- common/city.h       2003/07/23 13:46:03     1.132
+++ common/city.h       2003/07/25 02:31:16
@@ -255,8 +255,10 @@
 
   struct unit_list units_supported;
 
-  /* TRUE iff there units in the town. Only set at the client. */
-  bool occupied;             
+  struct {
+    /* Only used at the client (the serer is omniscient). */
+    bool occupied;     
+  } client;      
 
   int steal;                 /* diplomats steal once; for spies, gets harder */
   /* turn states */
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.180
diff -u -r1.180 unit.c
--- common/unit.c       2003/07/21 01:19:36     1.180
+++ common/unit.c       2003/07/25 02:31:16
@@ -1173,7 +1173,7 @@
       struct city *pcity = is_non_allied_city_tile(ptile, pplayer);
 
       if (pcity 
-          && (pcity->occupied 
+          && (pcity->client.occupied 
               || map_get_known2(x1, y1, pplayer) == TILE_KNOWN_FOGGED)) {
         /* If the city is fogged, we assume it's occupied */
         return FALSE;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#4676) clean up pcity->occupied usage, Jason Short <=