Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2004:
[Freeciv-Dev] Re: (PR#8584) remove dio_[put|get]_city_map
Home

[Freeciv-Dev] Re: (PR#8584) remove dio_[put|get]_city_map

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#8584) remove dio_[put|get]_city_map
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 24 Apr 2004 16:15:48 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8584 >

Jason Short wrote:
> This patch removes dio_put_citY_map and dio_get_city_map, along with the 
> hard-coding of the city map indices in dataio.c.

Same patch, with the client and server parts.

jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.362
diff -u -r1.362 packhand.c
--- client/packhand.c   14 Apr 2004 17:18:36 -0000      1.362
+++ client/packhand.c   24 Apr 2004 23:14:24 -0000
@@ -380,7 +380,7 @@
 **************************************************************************/
 void handle_city_info(struct packet_city_info *packet)
 {
-  int i, x, y;
+  int i;
   bool city_is_new, city_has_changed_owner = FALSE, need_effect_update = FALSE;
   struct city *pcity;
   bool popup, update_descriptions = FALSE;
@@ -494,18 +494,16 @@
   pcity->caravan_shields=packet->caravan_shields;
   pcity->last_turns_shield_surplus = packet->last_turns_shield_surplus;
 
-  i=0;
-  for(y=0; y<CITY_MAP_SIZE; y++) {
-    for(x=0; x<CITY_MAP_SIZE; x++) {
-      if (city_is_new) {
-       /* Need to pre-initialize before set_worker_city()  -- dwp */
-       pcity->city_map[x][y] =
-           is_valid_city_coords(x, y) ? C_TILE_EMPTY : C_TILE_UNAVAILABLE;
-      }
-      if (is_valid_city_coords(x, y)) {
-       set_worker_city(pcity, x, y, packet->city_map[i] - '0');
-      }
-      i++;
+  for (i = 0; i < CITY_MAP_SIZE * CITY_MAP_SIZE; i++) {
+    const int x = i % CITY_MAP_SIZE, y = i / CITY_MAP_SIZE;
+
+    if (city_is_new) {
+      /* Need to pre-initialize before set_worker_city()  -- dwp */
+      pcity->city_map[x][y] =
+       is_valid_city_coords(x, y) ? C_TILE_EMPTY : C_TILE_UNAVAILABLE;
+    }
+    if (is_valid_city_coords(x, y)) {
+      set_worker_city(pcity, x, y, packet->city_map[i]);
     }
   }
   
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.164
diff -u -r1.164 capstr.c
--- common/capstr.c     14 Apr 2004 11:19:44 -0000      1.164
+++ common/capstr.c     24 Apr 2004 23:14:24 -0000
@@ -77,7 +77,7 @@
 #define CAPABILITY "+1.14.delta +last_turns_shield_surplus veteran +orders " \
                    "+starter +union +iso_maps +orders2client " \
                    "+change_production +tilespec1 +no_earth +trans " \
-                   "+want_hack invasions killstack bombard"
+                   "+want_hack invasions killstack bombard +city_map"
 
 /* "+1.14.delta" is the new delta protocol for 1.14.0-dev.
  *
@@ -114,6 +114,8 @@
  * "killstack" means ruleset option to ignore unit killstack effect
  *
  * "bombard" means units support the bombard ability.
+ *
+ * "city_map" means the city_map is sent as an array instead of a bitfield.
  */
 
 void init_our_capability(void)
Index: common/dataio.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/dataio.c,v
retrieving revision 1.10
diff -u -r1.10 dataio.c
--- common/dataio.c     14 Feb 2004 02:21:25 -0000      1.10
+++ common/dataio.c     24 Apr 2004 23:14:25 -0000
@@ -53,10 +53,6 @@
 
 #include "dataio.h"
 
-static const int city_map_index[20] = {
-  1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23
-};
-
 /**************************************************************************
 ...
 **************************************************************************/
@@ -403,22 +399,6 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void dio_put_city_map(struct data_out *dout, const char *value)
-{
-  int i;
-
-  for (i = 0; i < 20; i += 5) {
-    dio_put_uint8(dout, (value[city_map_index[i]] - '0') * 81 +
-                 (value[city_map_index[i + 1]] - '0') * 27 +
-                 (value[city_map_index[i + 2]] - '0') * 9 +
-                 (value[city_map_index[i + 3]] - '0') * 3 +
-                 (value[city_map_index[i + 4]] - '0') * 1);
-  }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
 void dio_get_uint8(struct data_in *din, int *dest)
 {
   if (enough_data(din, 1)) {
@@ -625,55 +605,6 @@
 
   if (din->too_short) {
     din->bad_bit_string = TRUE;
-  }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void dio_get_city_map(struct data_in *din, char *dest, size_t max_dest_size)
-{
-  int i;
-
-  if (dest) {
-    assert(max_dest_size >= 26);
-    dest[0] = '2';
-    dest[4] = '2';
-    dest[12] = '1';
-    dest[20] = '2';
-    dest[24] = '2';
-    dest[25] = '\0';
-  }
-
-  if (!enough_data(din, 4)) {
-    if (dest) {
-      for (i = 0; i < 20;) {
-       int j;
-
-       for (j = 0; j < 5; j++) {
-         dest[city_map_index[i++]] = '0';
-       }
-      }
-    }
-    return;
-  }
-
-  for (i = 0; i < 20;) {
-    int j;
-
-    dio_get_uint8(din, &j);
-
-    if (dest) {
-      dest[city_map_index[i++]] = '0' + j / 81;
-      j %= 81;
-      dest[city_map_index[i++]] = '0' + j / 27;
-      j %= 27;
-      dest[city_map_index[i++]] = '0' + j / 9;
-      j %= 9;
-      dest[city_map_index[i++]] = '0' + j / 3;
-      j %= 3;
-      dest[city_map_index[i++]] = '0' + j;
-    }
   }
 }
 
Index: common/dataio.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/dataio.h,v
retrieving revision 1.5
diff -u -r1.5 dataio.h
--- common/dataio.h     10 Apr 2004 03:47:49 -0000      1.5
+++ common/dataio.h     24 Apr 2004 23:14:25 -0000
@@ -68,7 +68,6 @@
 void dio_get_string(struct data_in *din, char *dest, size_t max_dest_size);
 void dio_get_bit_string(struct data_in *din, char *dest,
                        size_t max_dest_size);
-void dio_get_city_map(struct data_in *din, char *dest, size_t max_dest_size);
 void dio_get_tech_list(struct data_in *din, int *dest);
 void dio_get_worklist(struct data_in *din, struct worklist *pwl);
 void dio_get_diplstate(struct data_in *din, struct player_diplstate *pds);
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.21
diff -u -r1.21 packets.def
--- common/packets.def  24 Apr 2004 17:32:47 -0000      1.21
+++ common/packets.def  24 Apr 2004 23:14:25 -0000
@@ -151,7 +151,6 @@
 type MEMORY            = memory(unsigned char)
 type STRING            = string(char)
 type BIT_STRING                = bit_string(char)
-type CITY_MAP          = city_map(char)
 type WORKLIST          = worklist(struct worklist)
 type TECH_LIST         = tech_list(int)
 type EFFECT            = effect(struct impr_effect)
@@ -169,6 +168,7 @@
 type RIVER_MOVE                = uint8(enum special_river_move)
 type REPORT_TYPE       = uint8(enum report_type)
 type AUTH_TYPE         = uint8(enum authentication_type)
+type CITY_MAP          = uint8(enum city_tile_type)
 type IMPR_RANGE                = uint8(enum impr_range)
 type DIRECTION         = uint8(enum direction8)
 type ORDERS            = uint8(enum unit_orders)
@@ -408,7 +408,7 @@
   WORKLIST worklist;
 
   BIT_STRING improvements[B_LAST+1];
-  CITY_MAP city_map[CITY_MAP_SIZE*CITY_MAP_SIZE+1];
+  CITY_MAP city_map[CITY_MAP_SIZE * CITY_MAP_SIZE];
 
   BOOL did_buy, did_sell, was_happy, airlift, diplomat_investigate;
 
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.257
diff -u -r1.257 citytools.c
--- server/citytools.c  22 Mar 2004 20:58:13 -0000      1.257
+++ server/citytools.c  24 Apr 2004 23:14:26 -0000
@@ -1733,11 +1733,9 @@
   packet->did_buy=pcity->did_buy;
   packet->did_sell=pcity->did_sell;
   packet->was_happy=pcity->was_happy;
-  p=packet->city_map;
   for(y=0; y<CITY_MAP_SIZE; y++)
     for(x=0; x<CITY_MAP_SIZE; x++)
-      *p++=get_worker_city(pcity, x, y)+'0';
-  *p='\0';
+      packet->city_map[x + y * CITY_MAP_SIZE] = get_worker_city(pcity, x, y);
 
   p=packet->improvements;
 

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