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

Currently, the worked tile fields are not sent.  Instead, the worked pointers
are set using the city_info packet city_map[].

This patch merely passes the worked city id value.  A future patch will
change the client to use the field.

Also, this adjusts the terrain and resource number size to match reality, as
neither can ever be more than 96 (a limitation of using a printable ASCII
character in the map data).  The sizes are now 96 and 48 respectively (was
200 and 100), and the packet data is uint8.

Instead of passing -1 as a special case out-of-range value to indicate none,
just pass the *_count() -- guaranteed to generate NULL on receipt, and easy
to grep in the code.


Index: server/ruleset.c
===================================================================
--- server/ruleset.c    (revision 14418)
+++ server/ruleset.c    (working copy)
@@ -3277,19 +3277,19 @@
 
     packet.irrigation_result = (pterrain->irrigation_result
                                ? terrain_number(pterrain->irrigation_result)
-                               : -1);
+                               : terrain_count());
     packet.irrigation_food_incr = pterrain->irrigation_food_incr;
     packet.irrigation_time = pterrain->irrigation_time;
 
     packet.mining_result = (pterrain->mining_result
                            ? terrain_number(pterrain->mining_result)
-                           : -1);
+                           : terrain_count());
     packet.mining_shield_incr = pterrain->mining_shield_incr;
     packet.mining_time = pterrain->mining_time;
 
     packet.transform_result = (pterrain->transform_result
                               ? terrain_number(pterrain->transform_result)
-                              : -1);
+                              : terrain_count());
     packet.transform_time = pterrain->transform_time;
     packet.rail_time = pterrain->rail_time;
     packet.clean_pollution_time = pterrain->clean_pollution_time;
Index: server/maphand.c
===================================================================
--- server/maphand.c    (revision 14418)
+++ server/maphand.c    (working copy)
@@ -639,7 +639,7 @@
 
   info.x = ptile->x;
   info.y = ptile->y;
-  info.owner = tile_owner(ptile) ? player_number(tile_owner(ptile)) : 
MAP_TILE_OWNER_NULL;
+
   if (ptile->spec_sprite) {
     sz_strlcpy(info.spec_sprite, ptile->spec_sprite);
   } else {
@@ -652,41 +652,65 @@
     if (!pplayer && !pconn->observer) {
       continue;
     }
+
     if (!pplayer || map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
       info.known = TILE_KNOWN;
-      info.type = tile_terrain(ptile) ? terrain_number(tile_terrain(ptile)) : 
-1;
+      info.continent = tile_continent(ptile);
+      info.owner = (NULL != tile_owner(ptile))
+                    ? player_number(tile_owner(ptile))
+                    : MAP_TILE_OWNER_NULL;
+      info.worked = (NULL != tile_worked(ptile))
+                     ? tile_worked(ptile)->id
+                     : IDENTITY_NUMBER_ZERO;
 
+      info.terrain = (NULL != tile_terrain(ptile))
+                      ? terrain_number(tile_terrain(ptile))
+                      : terrain_count();
+      info.resource = (NULL != tile_resource(ptile))
+                       ? resource_number(tile_resource(ptile))
+                       : resource_count();
+
       tile_special_type_iterate(spe) {
        info.special[spe] = BV_ISSET(ptile->special, spe);
       } tile_special_type_iterate_end;
 
-      info.resource = tile_resource(ptile) ? 
resource_number(tile_resource(ptile)) : -1;
-      info.continent = tile_continent(ptile);
       send_packet_tile_info(pconn, &info);
     } else if (pplayer && map_is_known(ptile, pplayer)
               && map_get_seen(ptile, pplayer, V_MAIN) == 0) {
       struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
 
       info.known = TILE_KNOWN_FOGGED;
-      info.type = plrtile->terrain ? terrain_number(plrtile->terrain) : -1;
+      info.continent = tile_continent(ptile);
+      info.owner = (NULL != tile_owner(ptile))
+                   ? player_number(tile_owner(ptile))
+                   : MAP_TILE_OWNER_NULL;
+      info.worked = IDENTITY_NUMBER_ZERO;
 
+      info.terrain = (NULL != plrtile->terrain)
+                      ? terrain_number(plrtile->terrain)
+                      : terrain_count();
+      info.resource = (NULL != plrtile->resource)
+                       ? resource_number(plrtile->resource)
+                       : resource_count();
+
       tile_special_type_iterate(spe) {
        info.special[spe] = BV_ISSET(plrtile->special, spe);
       } tile_special_type_iterate_end;
 
-      info.resource = plrtile->resource ? resource_number(plrtile->resource) : 
-1;
-      info.continent = tile_continent(ptile);
       send_packet_tile_info(pconn, &info);
     } else if (send_unknown) {
       info.known = TILE_UNKNOWN;
-      info.type  = -1;
+      info.continent = 0;
+      info.owner = MAP_TILE_OWNER_NULL;
+      info.worked = IDENTITY_NUMBER_ZERO;
 
+      info.terrain = terrain_count();
+      info.resource = resource_count();
+
       tile_special_type_iterate(spe) {
         info.special[spe] = FALSE;
       } tile_special_type_iterate_end;
 
-      info.resource  = -1;
-      info.continent = 0;
       send_packet_tile_info(pconn, &info);
     }
   }
Index: server/edithand.c
===================================================================
--- server/edithand.c   (revision 14418)
+++ server/edithand.c   (working copy)
@@ -70,9 +70,10 @@
                       Terrain_type_id terrain, Resource_type_id resource,
                      bv_special special)
 {
+  struct terrain *old_terrain;
+  struct terrain *pterrain = terrain_by_number(terrain);
+  struct resource *presource = resource_by_number(resource);
   struct tile *ptile = map_pos_to_tile(x, y);
-  struct terrain *pterrain = terrain_by_number(terrain), *old_terrain;
-  struct resource *presource = resource_by_number(resource);
 
   if (!can_conn_edit(pc) || !ptile || !pterrain) {
     return;
Index: common/packets.def
===================================================================
--- common/packets.def  (revision 14418)
+++ common/packets.def  (working copy)
@@ -174,10 +174,8 @@
 type CLAUSE            = uint8(enum clause_type)
 type ACTIVITY          = uint8(enum unit_activity)
 type EVENT             = sint16(enum event_type)
-type TERRAIN           = sint16(Terrain_type_id)
+type KNOWN             = uint8(enum known_type)
 type SPECIAL           = uint16(enum tile_special_type)
-type RESOURCE           = sint8(Resource_type_id)
-type SPECIALIST                = uint8(Specialist_type_id)
 type DIPLOMAT_ACTION   = uint8(enum diplomat_actions)
 type CMDLEVEL          = uint8(enum cmdlevel_id)
 type PLACE_TYPE                = uint8(enum spaceship_place_type)
@@ -222,6 +220,9 @@
 type TEAM              = UINT8
 type CONTINENT          = sint16(Continent_id)
 type IMPROVEMENT       = uint8(Impr_type_id)
+type RESOURCE           = uint8(Resource_type_id)
+type SPECIALIST         = uint8(Specialist_type_id)
+type TERRAIN            = uint8(Terrain_type_id)
 type EDIT_TECH_MODE     = uint8(enum editor_tech_mode)
 
 # other typedefs
@@ -344,12 +345,14 @@
 PACKET_TILE_INFO=14; sc,lsend,is-info
   COORD x, y; key
 
-  TERRAIN type;
-  UINT8 known;
+  CONTINENT continent;
+  KNOWN known;
+  PLAYER owner;
+  CITY worked;
+
+  TERRAIN terrain;
+  RESOURCE resource;
   BOOL special[S_LAST];
-  RESOURCE resource;
-  PLAYER owner;
-  CONTINENT continent;
   STRING spec_sprite[MAX_LEN_NAME];
 end
 
Index: common/terrain.h
===================================================================
--- common/terrain.h    (revision 14418)
+++ common/terrain.h    (working copy)
@@ -88,8 +88,9 @@
 #define T_FIRST 0
 
 /* A hard limit on the number of terrains; useful for static arrays. */
-#define MAX_NUM_TERRAINS  MAX_NUM_ITEMS
-#define MAX_NUM_RESOURCES 100 /* Limited to half a byte in the net code. */
+#define MAX_NUM_TERRAINS (96)
+/* Reflect reality; but theoretically could be larger than terrains! */
+#define MAX_NUM_RESOURCES (MAX_NUM_TERRAINS/2)
 
 enum terrain_class {
   TC_LAND,
Index: client/packhand.c
===================================================================
--- client/packhand.c   (revision 14418)
+++ client/packhand.c   (working copy)
@@ -2111,7 +2111,8 @@
   bool known_changed = FALSE;
   bool tile_changed = FALSE;
   struct player *powner = valid_player_by_number(packet->owner);
-  struct terrain *pterrain = terrain_by_number(packet->type);
+  struct resource *presource = resource_by_number(packet->resource);
+  struct terrain *pterrain = terrain_by_number(packet->terrain);
   struct tile *ptile = map_pos_to_tile(packet->x, packet->y);
   
   if (NULL == ptile) {
@@ -2141,6 +2142,7 @@
       break;
     };
   }
+
   tile_special_type_iterate(spe) {
     if (packet->special[spe]) {
       if (!tile_has_special(ptile, spe)) {
@@ -2155,22 +2157,20 @@
     }
   } tile_special_type_iterate_end;
 
-  if (NULL != tile_resource(ptile)) {
-    tile_changed = (resource_number(tile_resource(ptile)) != packet->resource);
-  } else {
-    tile_changed = (-1 != packet->resource);
-  }
+  tile_changed = tile_changed || (tile_resource(ptile) != presource);
 
   /* always called after setting terrain */
-  tile_set_resource(ptile, resource_by_number(packet->resource));
+  tile_set_resource(ptile, presource);
 
   if (tile_owner(ptile) != powner) {
     tile_set_owner(ptile, powner);
     tile_changed = TRUE;
   }
+
   if (old_known != packet->known) {
     known_changed = TRUE;
   }
+
   if (NULL != client.playing) {
     BV_CLR(ptile->tile_known, player_index(client.playing));
     vision_layer_iterate(v) {
Index: client/editor.c
===================================================================
--- client/editor.c     (revision 14418)
+++ client/editor.c     (working copy)
@@ -280,7 +280,9 @@
     /* FIXME: No way to change resources. */
     dsend_packet_edit_tile(&aconnection, ptile->x, ptile->y,
                           terrain_number(tile.terrain),
-                          tile.resource ? resource_number(tile.resource) : -1,
+                          (NULL != tile.resource)
+                           ? resource_number(tile.resource)
+                           : resource_count(),
                           tile.special);
   }
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to