Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2004:
[Freeciv-Dev] (PR#9787) RFC: generalized terrain
Home

[Freeciv-Dev] (PR#9787) RFC: generalized terrain

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: mburda@xxxxxxxxx
Subject: [Freeciv-Dev] (PR#9787) RFC: generalized terrain
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 31 Aug 2004 16:09:56 -0700
Reply-to: rt@xxxxxxxxxxx

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

> [jdorje - Tue Aug 31 23:09:31 2004]:
> 
> Here's an update of the patch.  It is now quite small.
> 
> It still cheats by putting the enumeration values in mapgen.


Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.400
diff -u -r1.400 packhand.c
--- client/packhand.c   31 Aug 2004 04:40:48 -0000      1.400
+++ client/packhand.c   31 Aug 2004 23:07:12 -0000
@@ -2190,6 +2190,8 @@
   city_styles_alloc(packet->style_count);
   tilespec_alloc_city_tiles(game.styles_count);
 
+  game.terrain_count = packet->terrain_count;
+
   for(i = 0; i < MAX_NUM_TEAMS; i++) {
     mystrlcpy(team_get_by_id(i)->name, packet->team_name[i],
               MAX_LEN_NAME);
Index: common/dataio.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/dataio.c,v
retrieving revision 1.11
diff -u -r1.11 dataio.c
--- common/dataio.c     2 Jun 2004 19:47:41 -0000       1.11
+++ common/dataio.c     31 Aug 2004 23:07:12 -0000
@@ -723,7 +723,7 @@
   dio_get_uint8(din, &peffect->cond_adv);
   dio_get_uint8(din, (int *) &(peffect->cond_eff));
   dio_get_uint8(din, (int *) &(peffect->aff_unit));
-  dio_get_uint8(din, (int *) &(peffect->aff_terr));
+  dio_get_sint16(din, (int *) &(peffect->aff_terr));
   dio_get_uint16(din, (int *) &(peffect->aff_spec));
 }
 
@@ -738,6 +738,6 @@
   dio_put_uint8(dout, peffect->cond_adv);
   dio_put_uint8(dout, peffect->cond_eff);
   dio_put_uint8(dout, peffect->aff_unit);
-  dio_put_uint8(dout, peffect->aff_terr);
+  dio_put_sint16(dout, peffect->aff_terr);
   dio_put_uint16(dout, peffect->aff_spec);
 }
Index: common/fc_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/fc_types.h,v
retrieving revision 1.3
diff -u -r1.3 fc_types.h
--- common/fc_types.h   28 Aug 2004 19:15:39 -0000      1.3
+++ common/fc_types.h   31 Aug 2004 23:07:12 -0000
@@ -19,7 +19,7 @@
  * definition in another file */
 
 typedef signed short Continent_id;
-typedef enum tile_terrain_type Terrain_type_id;
+typedef int Terrain_type_id;
 
 struct city;
 
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.148
diff -u -r1.148 game.h
--- common/game.h       16 Aug 2004 15:42:59 -0000      1.148
+++ common/game.h       31 Aug 2004 23:07:12 -0000
@@ -157,6 +157,8 @@
   int playable_nation_count;
   int styles_count;
 
+  int terrain_count;
+
   int watchtower_extra_vision;
   int watchtower_vision;
   int allowed_city_names;
Index: common/nation.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.h,v
retrieving revision 1.29
diff -u -r1.29 nation.h
--- common/nation.h     29 Aug 2004 19:03:31 -0000      1.29
+++ common/nation.h     31 Aug 2004 23:07:13 -0000
@@ -56,7 +56,7 @@
 struct city_name {
   char* name;
   ternary river;
-  ternary terrain[T_COUNT];    
+  ternary terrain[MAX_NUM_TERRAINS];
 };
 
 struct leader {
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.43
diff -u -r1.43 packets.def
--- common/packets.def  27 Aug 2004 17:36:53 -0000      1.43
+++ common/packets.def  31 Aug 2004 23:07:13 -0000
@@ -163,7 +163,7 @@
 type CLAUSE            = uint8(enum clause_type)
 type ACTIVITY          = uint8(enum unit_activity)
 type EVENT             = sint16(enum event_type)
-type TERRAIN           = uint8(Terrain_type_id)
+type TERRAIN           = sint16(Terrain_type_id)
 type SPECIAL           = uint16(enum tile_special_type)
 type SPECIALIST                = uint8(enum specialist_type)
 type DIPLOMAT_ACTION   = uint8(enum diplomat_actions)
@@ -1242,6 +1242,7 @@
   UINT8 nation_count;
   UINT8 playable_nation_count;
   UINT8 style_count;
+  UINT8 terrain_count;
   UINT8 borders;
   BOOL happyborders;
   BOOL slow_invasions; add-cap(slow_invasions)
Index: common/terrain.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.h,v
retrieving revision 1.21
diff -u -r1.21 terrain.h
--- common/terrain.h    31 Aug 2004 04:40:50 -0000      1.21
+++ common/terrain.h    31 Aug 2004 23:07:13 -0000
@@ -62,22 +62,17 @@
    | S_FORTRESS             \
    | S_AIRBASE)
 
-/* Changing this breaks savegame and network compatability. */
-enum tile_terrain_type {
-  T_ARCTIC, T_DESERT, T_FOREST, T_GRASSLAND, T_HILLS, T_JUNGLE, 
-  T_MOUNTAINS, T_OCEAN, T_PLAINS, T_UNUSED, T_SWAMP, T_TUNDRA,
-  T_UNKNOWN, /* A special flag meaning unknown terrain. */
-  T_NONE, /* A special flag meaning no terrain. */
-  T_ANY   /* A special flag that matches "any" terrain type. */
-};
+#define T_NONE (-3) /* A special flag meaning no terrain type. */
+#define T_ANY (-2) /* A special flag that matches "any" terrain type. */
+#define T_UNKNOWN (-1) /* An unknown terrain. */
 
 /* The first terrain value and number of base terrains.  This is used in
  * loops.  T_COUNT may eventually be turned into a variable. */
-#define T_FIRST (T_ARCTIC)
-#define T_COUNT (T_TUNDRA + 1)
+#define T_FIRST (0)
+#define T_COUNT (game.terrain_count)
 
 /* A hard limit on the number of terrains; useful for static arrays. */
-#define MAX_NUM_TERRAINS (T_COUNT)
+#define MAX_NUM_TERRAINS (MAX_NUM_ITEMS)
 
 /* Must match with terrain_flag_from_str in terrain.c. */
 enum terrain_flag_id {
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.149
diff -u -r1.149 mapgen.c
--- server/mapgen.c     28 Aug 2004 16:50:49 -0000      1.149
+++ server/mapgen.c     31 Aug 2004 23:07:13 -0000
@@ -33,6 +33,12 @@
 
 #include "mapgen.h"
 
+/* Old-style terrain enumeration: deprecated. */
+enum {
+  T_ARCTIC, T_DESERT, T_FOREST, T_GRASSLAND, T_HILLS, T_JUNGLE,
+  T_MOUNTAINS, T_OCEAN, T_PLAINS, T_UNUSED, T_SWAMP, T_TUNDRA,
+};
+
 /* Provide a block to convert from native to map coordinates.  For instance
  *   do_in_map_pos(mx, my, xn, yn) {
  *     map_set_terrain(mx, my, T_OCEAN);
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.192
diff -u -r1.192 ruleset.c
--- server/ruleset.c    31 Aug 2004 04:40:50 -0000      1.192
+++ server/ruleset.c    31 Aug 2004 23:07:14 -0000
@@ -1508,12 +1508,13 @@
   /* terrain names */
 
   sec = secfile_get_secnames_prefix(file, "terrain_", &nval);
-  if (nval != (T_COUNT - T_FIRST))
-    {
-      /* sometime this restriction should be removed */
-      freelog(LOG_FATAL, "Bad number of terrains %d (%s)", nval, filename);
-      exit(EXIT_FAILURE);
-    }
+  game.terrain_count = nval;
+  if (nval == 0) {
+    /* TRANS: "%s" is filename */
+    freelog(LOG_FATAL, _("Ruleset doesn't have any terrains (%s)"),
+           filename);
+    exit(EXIT_FAILURE);
+  }
 
   terrain_type_iterate(i) {
     char *name = secfile_lookup_str(file, "%s.terrain_name", sec[i]);
@@ -1999,6 +2000,7 @@
   packet.nation_count = game.nation_count;
   packet.playable_nation_count = game.playable_nation_count;
   packet.style_count = game.styles_count;
+  packet.terrain_count = game.terrain_count;
 
   for(i = 0; i < MAX_NUM_TEAMS; i++) {
     sz_strlcpy(packet.team_name[i], team_get_by_id(i)->name);

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