Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] Re: (PR#6330) terrain flags: TER_NO_BARBS
Home

[Freeciv-Dev] Re: (PR#6330) terrain flags: TER_NO_BARBS

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#6330) terrain flags: TER_NO_BARBS
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 30 Sep 2003 07:48:53 -0700
Reply-to: rt@xxxxxxxxxxxxxx

Per I. Mathisen wrote:
> On Mon, 29 Sep 2003, Jason Short wrote:
> 
>>This patch introduces terrain flags, read from the ruleset and sent to
>>the client.One simple terrain flag NO_BARBS (no barbarian summoning on
>>this terrain) is added (this also addresses PR#6183).
> 
> 
> +flags                = "no_barbs"
> 
> It seems custom to name flags with capital letters. See eg units.ruleset.

Done.  Now it's

   flags = "NoBarbs"

which is how units.ruleset handles multiple words.

I also added support to the history ruleset (all rulesets have NoBarbs 
for actic/glacier and tundra) and added a few comments.

jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.332
diff -u -r1.332 packhand.c
--- client/packhand.c   2003/09/23 22:01:41     1.332
+++ client/packhand.c   2003/09/30 15:38:31
@@ -2388,6 +2388,8 @@
   t->transform_result = p->transform_result;
   t->transform_time = p->transform_time;
   
+  t->flags = p->flags;
+
   t->helptext = p->helptext;   /* pointer assignment */
   
   tilespec_setup_tile_type(p->id);
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.144
diff -u -r1.144 capstr.c
--- common/capstr.c     2003/09/22 16:54:09     1.144
+++ common/capstr.c     2003/09/30 15:38:31
@@ -80,7 +80,7 @@
                    "+no_nation_selected +diplomacy +no_extra_tiles " \
                    "+diplomacy2 +citizens_style +root_tech auth " \
                    "+nat_ulimit +retake +goto_pack borders dip " \
-                   "+packet_short_unit +unit_occupied"
+                   "+packet_short_unit +unit_occupied +terr_flags"
 
 /* "+1.14.0" is protocol for 1.14.0 release.
  *
@@ -152,6 +152,9 @@
  *
  * "unit_occupied" means units occupying transporters are not sent to enemies.
  * instead an 'occupied' flag is set for the transporter.
+ *
+ * "terr_flags" means terrain flags (with the TER_NO_BARBS flag) have been
+ * added.
  */
 
 void init_our_capability(void)
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.146
diff -u -r1.146 map.c
--- common/map.c        2003/09/29 02:42:15     1.146
+++ common/map.c        2003/09/30 15:38:31
@@ -408,6 +408,29 @@
   return count;
 }
 
+/****************************************************************************
+  Return the terrain flag matching the given string, or TER_LAST if there's
+  no match.
+****************************************************************************/
+enum terrain_flag_id terrain_flag_from_str(const char *s)
+{
+  enum terrain_flag_id flag;
+  const char *flag_names[] = {
+    /* Must match terrain flags in terrain.h. */
+    "NoBarbs"
+  };
+
+  assert(ARRAY_SIZE(flag_names) == TER_COUNT);
+
+  for (flag = TER_FIRST; flag < TER_LAST; flag++) {
+    if (mystrcasecmp(flag_names[flag], s) == 0) {
+      return flag;
+    }
+  }
+
+  return TER_LAST;
+}
+
 /***************************************************************
   determines if any tile close to x,y has special spe
 ***************************************************************/
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.156
diff -u -r1.156 map.h
--- common/map.h        2003/09/29 17:42:37     1.156
+++ common/map.h        2003/09/30 15:38:31
@@ -100,7 +100,7 @@
 tile_type for each terrain type
 expand with government bonuses??
 *****************************************************************/
-
+BV_DEFINE(bv_terrain_flags, TER_MAX);
 struct tile_type {
   char terrain_name[MAX_LEN_NAME];     /* "" if unused */
   char terrain_name_orig[MAX_LEN_NAME];        /* untranslated copy */
@@ -149,6 +149,8 @@
   enum tile_terrain_type transform_result;
   int transform_time;
 
+  bv_terrain_flags flags;
+
   char *helptext;
 };
 
@@ -348,6 +350,7 @@
 const char *get_special_name(enum tile_special_type type);
 bool is_terrain_near_tile(int x, int y, enum tile_terrain_type t);
 int count_terrain_near_tile(int x, int y, enum tile_terrain_type t);
+enum terrain_flag_id terrain_flag_from_str(const char *s);
 bool is_special_near_tile(int x, int y, enum tile_special_type spe);
 int count_special_near_tile(int x, int y, enum tile_special_type spe);
 bool is_coastline(int x,int y);
Index: common/packets.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v
retrieving revision 1.257
diff -u -r1.257 packets.c
--- common/packets.c    2003/09/22 16:54:09     1.257
+++ common/packets.c    2003/09/30 15:38:31
@@ -2443,6 +2443,8 @@
     dio_put_string(&dout, packet->special[i].graphic_alt);
   }
 
+  DIO_BV_PUT(&dout, packet->flags);
+
   /* This must be last, so client can determine length: */
   if(packet->helptext) {
     dio_put_string(&dout, packet->helptext);
@@ -2494,6 +2496,8 @@
     dio_get_string(&din, packet->special[i].graphic_alt,
                sizeof(packet->special[i].graphic_alt));
   }
+
+  DIO_BV_GET(&din, packet->flags);
 
   len = dio_input_remaining(&din);
   if (len > 0) {
Index: common/packets.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v
retrieving revision 1.154
diff -u -r1.154 packets.h
--- common/packets.h    2003/09/22 16:54:09     1.154
+++ common/packets.h    2003/09/30 15:38:31
@@ -761,6 +761,8 @@
 
   enum tile_terrain_type transform_result;
   int transform_time;
+
+  bv_terrain_flags flags;
   
   char *helptext;              /* same as for packet_ruleset_unit, above */
 };
Index: common/terrain.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.h,v
retrieving revision 1.5
diff -u -r1.5 terrain.h
--- common/terrain.h    2003/01/09 02:36:37     1.5
+++ common/terrain.h    2003/09/30 15:38:31
@@ -71,6 +71,14 @@
 #define T_FIRST (T_ARCTIC)
 #define T_COUNT (T_UNKNOWN)
 
+enum terrain_flag_id {
+  TER_NO_BARBS, /* No barbarians summoned on this terrain. */
+  TER_LAST
+};
+#define TER_FIRST (TER_NO_BARBS)
+#define TER_COUNT (TER_LAST)
+#define TER_MAX 64 /* Changing this breaks network compatability. */
+
 enum known_type {
  TILE_UNKNOWN, TILE_KNOWN_FOGGED, TILE_KNOWN
 };
@@ -82,5 +90,7 @@
 #define is_ocean_near_tile(x, y) is_terrain_near_tile(x, y, T_OCEAN)
 #define adjacent_ocean_tiles4(x, y) adjacent_terrain_tiles4(x, y, T_OCEAN)
 #define count_ocean_near_tile(x,y) count_terrain_near_tile(x,y, T_OCEAN)
+
+#define terrain_has_flag(terr, flag) BV_ISSET(tile_types[(terr)].flags, flag)
 
 #endif  /* FC__TERRAIN_H */
Index: data/civ1/terrain.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ1/terrain.ruleset,v
retrieving revision 1.14
diff -u -r1.14 terrain.ruleset
--- data/civ1/terrain.ruleset   2002/03/30 02:43:52     1.14
+++ data/civ1/terrain.ruleset   2003/09/30 15:38:31
@@ -171,6 +171,7 @@
 mining_time          = 0
 transform_result     = "no"
 transform_time       = 0
+flags                = "NoBarbs"
 helptext            = _("\
 Arctic squares are found only in the most northerly or southerly\
  reaches of the world.  They are very cold, and hence difficult to\
@@ -572,6 +573,7 @@
 mining_time          = 0
 transform_result     = "no"
 transform_time       = 0
+flags                = "NoBarbs"
 helptext            = _("\
 Tundra are broad, cold regions, fit for some agriculture and little\
  else.\
Index: data/civ2/terrain.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ2/terrain.ruleset,v
retrieving revision 1.16
diff -u -r1.16 terrain.ruleset
--- data/civ2/terrain.ruleset   2002/03/30 02:43:53     1.16
+++ data/civ2/terrain.ruleset   2003/09/30 15:38:31
@@ -179,6 +179,7 @@
 mining_time          = 10
 transform_result     = "Tundra"
 transform_time       = 24
+flags                = "NoBarbs"
 helptext            = _("\
 Glaciers are found only in the most northerly or southerly\
  reaches of the world.  They are very cold, and hence difficult to\
@@ -573,6 +574,7 @@
 mining_time          = 0
 transform_result     = "Desert"
 transform_time       = 24
+flags                = "NoBarbs"
 helptext            = _("\
 Tundra are broad, cold regions, fit for some agriculture and little\
  else.\
Index: data/default/terrain.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/terrain.ruleset,v
retrieving revision 1.17
diff -u -r1.17 terrain.ruleset
--- data/default/terrain.ruleset        2002/03/30 02:43:54     1.17
+++ data/default/terrain.ruleset        2003/09/30 15:38:31
@@ -179,6 +179,7 @@
 mining_time          = 10
 transform_result     = "Tundra"
 transform_time       = 24
+flags                = "NoBarbs"
 helptext            = _("\
 Glaciers are found only in the most northerly or southerly\
  reaches of the world.  They are very cold, and hence difficult to\
@@ -573,6 +574,7 @@
 mining_time          = 0
 transform_result     = "Desert"
 transform_time       = 24
+flags                = "NoBarbs"
 helptext            = _("\
 Tundra are broad, cold regions, fit for some agriculture and little\
  else.\
Index: data/history/terrain.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/history/terrain.ruleset,v
retrieving revision 1.1
diff -u -r1.1 terrain.ruleset
--- data/history/terrain.ruleset        2002/08/12 20:03:12     1.1
+++ data/history/terrain.ruleset        2003/09/30 15:38:31
@@ -179,6 +179,7 @@
 mining_time          = 10
 transform_result     = "Tundra"
 transform_time       = 24
+flags                = "NoBarbs"
 helptext            = _("\
 Glaciers are found only in the most northerly or southerly\
  reaches of the world.  They are very cold, and hence difficult to\
@@ -573,6 +574,7 @@
 mining_time          = 0
 transform_result     = "Desert"
 transform_time       = 24
+flags                = "NoBarbs"
 helptext            = _("\
 Tundra are broad, cold regions, fit for some agriculture and little\
  else.\
Index: server/barbarian.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/barbarian.c,v
retrieving revision 1.68
diff -u -r1.68 barbarian.c
--- server/barbarian.c  2003/09/19 14:14:45     1.68
+++ server/barbarian.c  2003/09/30 15:38:31
@@ -35,6 +35,7 @@
 #include "rand.h"
 #include "support.h"
 #include "tech.h"
+#include "terrain.h"
 
 #include "gamehand.h"
 #include "maphand.h"
@@ -331,7 +332,7 @@
   /* No uprising on North or South Pole */
   do {
     rand_map_pos(&x, &y);
-  } while (y == 0 || y == map.ysize - 1);
+  } while (terrain_has_flag(map_get_terrain(x, y), TER_NO_BARBS));
 
   if (!(pc = dist_nearest_city(NULL, x, y, TRUE, FALSE))) {
     /* any city */
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.154
diff -u -r1.154 ruleset.c
--- server/ruleset.c    2003/09/21 14:02:15     1.154
+++ server/ruleset.c    2003/09/30 15:38:31
@@ -1431,8 +1431,7 @@
 
   for (i = T_FIRST; i < T_COUNT; i++)
     {
-      char *s1_name;
-      char *s2_name;
+      char *s1_name, *s2_name, **slist;
       t = &(tile_types[i]);
 
       sz_strlcpy(t->graphic_str,
@@ -1488,6 +1487,22 @@
       t->transform_result =
        lookup_terrain(secfile_lookup_str(file, "%s.transform_result", sec[i]), 
i);
       t->transform_time = secfile_lookup_int(file, "%s.transform_time", 
sec[i]);
+
+      slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec[i]);
+      BV_CLR_ALL(t->flags);
+      for (j = 0; j < nval; j++) {
+       const char *sval = slist[j];
+       enum terrain_flag_id flag = terrain_flag_from_str(sval);
+
+       if (flag == TER_LAST) {
+         /* TRANS: Rare error message. */
+         freelog(LOG_FATAL, _("Terrain %s has unknown flag %s"),
+                 t->terrain_name, sval);
+         exit(EXIT_FAILURE);
+       } else {
+         BV_SET(t->flags, flag);
+       }
+      }
       
       t->helptext = lookup_helptext(file, sec[i]);
     }
@@ -2655,6 +2670,8 @@
 
       packet.transform_result = t->transform_result;
       packet.transform_time = t->transform_time;
+
+      packet.flags = t->flags;
 
       packet.helptext = t->helptext;   /* pointer assignment */
       

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