Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] (PR#2957) is ocean as a function with oceanness read from
Home

[Freeciv-Dev] (PR#2957) is ocean as a function with oceanness read from

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: kayeats@xxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#2957) is ocean as a function with oceanness read from ruleset
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 18 Jan 2004 09:23:10 -0800
Reply-to: rt@xxxxxxxxxxx

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

> [jdorje - Sat Jan 17 17:40:43 2004]:
> 
> Here is a patch that does the exact same thing, but uses a terrain flag
> instead of adding a new boolean terrain value.

Here's the same patch, but with documentation.

jason

Index: common/terrain.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.c,v
retrieving revision 1.1
diff -u -r1.1 terrain.c
--- common/terrain.c    2004/01/17 17:21:20     1.1
+++ common/terrain.c    2004/01/18 17:21:49
@@ -62,7 +62,8 @@
   enum terrain_flag_id flag;
   const char *flag_names[] = {
     /* Must match terrain flags in terrain.h. */
-    "NoBarbs"
+    "NoBarbs",
+    "Oceanic"
   };
 
   assert(ARRAY_SIZE(flag_names) == TER_COUNT);
@@ -128,6 +129,56 @@
 
   cartesian_adjacent_iterate(map_x, map_y, adjc_x, adjc_y) {
     if (map_get_terrain(adjc_x, adjc_y) == t) {
+      num_adjacent++;
+    }
+  } cartesian_adjacent_iterate_end;
+
+  return num_adjacent;
+}
+
+/****************************************************************************
+  Returns TRUE iff any adjacent tile contains terrain with the given flag.
+****************************************************************************/
+bool is_terrain_flag_near_tile(int map_x, int map_y,
+                              enum terrain_flag_id flag)
+{
+  adjc_iterate(map_x, map_y, adjc_x, adjc_y) {
+    if (terrain_has_flag(map_get_terrain(adjc_x, adjc_y), flag)) {
+      return TRUE;
+    }
+  } adjc_iterate_end;
+
+  return FALSE;
+}
+
+/****************************************************************************
+  Return the number of adjacent tiles that have terrain with the given flag.
+****************************************************************************/
+int count_terrain_flag_near_tile(int map_x, int map_y,
+                                enum terrain_flag_id flag)
+{
+  int count = 0;
+
+  adjc_iterate(map_x, map_y, adjc_x, adjc_y) {
+    if (terrain_has_flag(map_get_terrain(adjc_x, adjc_y), flag)) {
+      count++;
+    }
+  } adjc_iterate_end;
+
+  return count;
+}
+
+/****************************************************************************
+  Return the number of cardinally adjacent tiles that have terrain with
+  the given flag.
+****************************************************************************/
+int adjacent_terrain_flag_tiles4(int map_x, int map_y,
+                                enum terrain_flag_id flag)
+{
+  int num_adjacent = 0;
+
+  cartesian_adjacent_iterate(map_x, map_y, adjc_x, adjc_y) {
+    if (terrain_has_flag(map_get_terrain(adjc_x, adjc_y), flag)) {
       num_adjacent++;
     }
   } cartesian_adjacent_iterate_end;
Index: common/terrain.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.h,v
retrieving revision 1.8
diff -u -r1.8 terrain.h
--- common/terrain.h    2004/01/17 17:21:20     1.8
+++ common/terrain.h    2004/01/18 17:21:49
@@ -73,6 +73,7 @@
 
 enum terrain_flag_id {
   TER_NO_BARBS, /* No barbarians summoned on this terrain. */
+  TER_OCEANIC, /* This is an ocean terrain. */
   TER_LAST
 };
 #define TER_FIRST (TER_NO_BARBS)
@@ -100,9 +101,14 @@
 int count_terrain_near_tile(int map_x, int map_y, enum tile_terrain_type t);
 int adjacent_terrain_tiles4(int map_x, int map_y, enum tile_terrain_type t);
 
+/* Functions to operate on a terrain flag. */
+bool is_terrain_flag_near_tile(int x, int y, enum terrain_flag_id flag);
+int count_terrain_flag_near_tile(int x, int y, enum terrain_flag_id flag);
+int adjacent_terrain_flag_tiles4(int x, int y, enum terrain_flag_id flag);
+
 /* Terrain-specific functions. */
-#define is_ocean(x) ((x) == T_OCEAN)
-#define is_ocean_near_tile(x, y) is_terrain_near_tile(x, y, T_OCEAN)
+#define is_ocean(x) (terrain_has_flag((x), TER_OCEANIC))
+#define is_ocean_near_tile(x, y) is_terrain_flag_near_tile(x, y, TER_OCEANIC)
 #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)
 
Index: data/civ1/terrain.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ1/terrain.ruleset,v
retrieving revision 1.15
diff -u -r1.15 terrain.ruleset
--- data/civ1/terrain.ruleset   2003/10/02 17:54:57     1.15
+++ data/civ1/terrain.ruleset   2004/01/18 17:21:49
@@ -137,6 +137,16 @@
 ;                        "no"  -- cannot transform
 ;                        terrain name -- transformation changes to that terrain
 ; transform_time       = time to transform; if 0, cannot transform
+; flags                = General flags for this terrain:
+;   - NoBarbs          = Barbarians will not be spawned here.
+;   - Oceanic          = This is an "ocean" terrain.  This has a big effect
+                         on gameplay.  Naval units can move on oceanic terrain,
+                         while land units cannot.  Oceanic tiles can be used
+                         as a water source for irrigation.  Cities built next
+                         to oceanic terrain can build naval improvements and
+                         units.  Most terrain improvements can only be built
+                         on land.  Oceanic terrain has no zones of control.
+                         The list goes on.
 ; helptext            = optional help text string; should escape all raw 
 ;                       newlines so that xgettext parsing works
 
@@ -424,6 +434,7 @@
 mining_time          = 0
 transform_result     = "no"
 transform_time       = 0
+flags                = "Oceanic"
 helptext            = _("\
 Oceans cover much of the world, and only sea units (Triremes and\
  other boats) can travel on them.\
Index: data/civ2/terrain.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ2/terrain.ruleset,v
retrieving revision 1.17
diff -u -r1.17 terrain.ruleset
--- data/civ2/terrain.ruleset   2003/10/02 17:54:57     1.17
+++ data/civ2/terrain.ruleset   2004/01/18 17:21:49
@@ -145,6 +145,16 @@
 ;                        "no"  -- cannot transform
 ;                        terrain name -- transformation changes to that terrain
 ; transform_time       = time to transform; if 0, cannot transform
+; flags                = General flags for this terrain:
+;   - NoBarbs          = Barbarians will not be spawned here.
+;   - Oceanic          = This is an "ocean" terrain.  This has a big effect
+                         on gameplay.  Naval units can move on oceanic terrain,
+                         while land units cannot.  Oceanic tiles can be used
+                         as a water source for irrigation.  Cities built next
+                         to oceanic terrain can build naval improvements and
+                         units.  Most terrain improvements can only be built
+                         on land.  Oceanic terrain has no zones of control.
+                         The list goes on.
 ; helptext            = optional help text string; should escape all raw 
 ;                       newlines so that xgettext parsing works
 
@@ -432,6 +442,7 @@
 mining_time          = 0
 transform_result     = "no"
 transform_time       = 0
+flags                = "Oceanic"
 helptext            = _("\
 Oceans cover much of the world, and only sea units (Triremes and\
  other boats) can travel on them.\
Index: data/default/terrain.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/terrain.ruleset,v
retrieving revision 1.18
diff -u -r1.18 terrain.ruleset
--- data/default/terrain.ruleset        2003/10/02 17:54:57     1.18
+++ data/default/terrain.ruleset        2004/01/18 17:21:49
@@ -145,6 +145,16 @@
 ;                        "no"  -- cannot transform
 ;                        terrain name -- transformation changes to that terrain
 ; transform_time       = time to transform; if 0, cannot transform
+; flags                = General flags for this terrain:
+;   - NoBarbs          = Barbarians will not be spawned here.
+;   - Oceanic          = This is an "ocean" terrain.  This has a big effect
+                         on gameplay.  Naval units can move on oceanic terrain,
+                         while land units cannot.  Oceanic tiles can be used
+                         as a water source for irrigation.  Cities built next
+                         to oceanic terrain can build naval improvements and
+                         units.  Most terrain improvements can only be built
+                         on land.  Oceanic terrain has no zones of control.
+                         The list goes on.
 ; helptext            = optional help text string; should escape all raw 
 ;                       newlines so that xgettext parsing works
 
@@ -432,6 +442,7 @@
 mining_time          = 0
 transform_result     = "Swamp"
 transform_time       = 36
+flags                = "Oceanic"
 helptext            = _("\
 Oceans cover much of the world, and only sea units (Triremes and\
  other boats) can travel on them.\
Index: data/history/terrain.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/history/terrain.ruleset,v
retrieving revision 1.2
diff -u -r1.2 terrain.ruleset
--- data/history/terrain.ruleset        2003/10/02 17:54:58     1.2
+++ data/history/terrain.ruleset        2004/01/18 17:21:50
@@ -145,6 +145,16 @@
 ;                        "no"  -- cannot transform
 ;                        terrain name -- transformation changes to that terrain
 ; transform_time       = time to transform; if 0, cannot transform
+; flags                = General flags for this terrain:
+;   - NoBarbs          = Barbarians will not be spawned here.
+;   - Oceanic          = This is an "ocean" terrain.  This has a big effect
+                         on gameplay.  Naval units can move on oceanic terrain,
+                         while land units cannot.  Oceanic tiles can be used
+                         as a water source for irrigation.  Cities built next
+                         to oceanic terrain can build naval improvements and
+                         units.  Most terrain improvements can only be built
+                         on land.  Oceanic terrain has no zones of control.
+                         The list goes on.
 ; helptext            = optional help text string; should escape all raw 
 ;                       newlines so that xgettext parsing works
 
@@ -432,6 +442,7 @@
 mining_time          = 0
 transform_result     = "Swamp"
 transform_time       = 36
+flags                = "Oceanic"
 helptext            = _("\
 Oceans cover much of the world, and only sea units (Triremes and\
  other boats) can travel on them.\
Index: doc/README.rulesets
===================================================================
RCS file: /home/freeciv/CVS/freeciv/doc/README.rulesets,v
retrieving revision 1.6
diff -u -r1.6 README.rulesets
--- doc/README.rulesets 2002/11/02 13:33:54     1.6
+++ doc/README.rulesets 2004/01/18 17:21:50
@@ -168,6 +168,12 @@
 The civstyle option will be removed in the near future.
 
 ----------------------------------------------------------------------
+terrain.ruleset:
+----------------
+
+
+
+----------------------------------------------------------------------
 The AI:
 -------
 

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