Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12154) "adjacent" range for reqs
Home

[Freeciv-Dev] (PR#12154) "adjacent" range for reqs

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12154) "adjacent" range for reqs
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 7 Feb 2005 09:27:24 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch implements "adjacent" as a new range for reqs.  It is used 
for terrains and specials; adjacent means any adjacent tile may have 
this terrain/special.  This basically replaces terr_gate/spec_gate, and 
it's prettier since all the list stuff is taken care of along with other 
reqs.

However I didn't remove the terr_gate/spec_gate code.  This will take 
more work since buildings don't have reqs yet.

-jason

? fog
? fog.c
? fog.png
? foo
? data/isotrident/grid.png
? data/isotrident/grid.xcf
Index: common/requirements.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.c,v
retrieving revision 1.5
diff -u -r1.5 requirements.c
--- common/requirements.c       2 Feb 2005 02:44:31 -0000       1.5
+++ common/requirements.c       7 Feb 2005 17:25:27 -0000
@@ -40,6 +40,7 @@
  * requirements.h.  Do not change these unless you know what you're doing! */
 static const char *req_range_names[REQ_RANGE_LAST] = {
   "Local",
+  "Adjacent",
   "City",
   "Continent",
   "Player",
@@ -234,7 +235,7 @@
     case REQ_BUILDING:
     case REQ_SPECIAL:
     case REQ_TERRAIN:
-      req.range = REQ_RANGE_CITY;
+      req.range = REQ_RANGE_LOCAL;
       break;
     case REQ_GOV:
     case REQ_TECH:
@@ -462,6 +463,7 @@
       return 0;
     }
   case REQ_RANGE_LAST:
+  case REQ_RANGE_ADJACENT:
     break;
   }
   assert(0);
@@ -469,6 +471,67 @@
 }
 
 /****************************************************************************
+  Is there a source special within range of the target?
+****************************************************************************/
+static bool is_special_in_range(enum target_type target,
+                               const struct tile *target_tile,
+                               enum req_range range, bool survives,
+                               enum tile_special_type special)
+
+{
+    /* The requirement is filled if the tile has the special. */
+  if (!target_tile) {
+    return FALSE;
+  }
+
+  switch (range) {
+  case REQ_RANGE_LOCAL:
+    return tile_has_special(target_tile, special);
+  case REQ_RANGE_ADJACENT:
+    return is_special_near_tile(target_tile, special);
+  case REQ_RANGE_CITY:
+  case REQ_RANGE_CONTINENT:
+  case REQ_RANGE_PLAYER:
+  case REQ_RANGE_WORLD:
+  case REQ_RANGE_LAST:
+    break;
+  }
+
+  assert(0);
+  return FALSE;
+}
+
+/****************************************************************************
+  Is there a source tile within range of the target?
+****************************************************************************/
+static bool is_terrain_in_range(enum target_type target,
+                               const struct tile *target_tile,
+                               enum req_range range, bool survives,
+                               Terrain_type_id terrain)
+{
+  if (!target_tile) {
+    return FALSE;
+  }
+
+  switch (range) {
+  case REQ_RANGE_LOCAL:
+    /* The requirement is filled if the tile has the terrain. */
+    return target_tile->terrain  == terrain;
+  case REQ_RANGE_ADJACENT:
+    return is_terrain_near_tile(target_tile, terrain);
+  case REQ_RANGE_CITY:
+  case REQ_RANGE_CONTINENT:
+  case REQ_RANGE_PLAYER:
+  case REQ_RANGE_WORLD:
+  case REQ_RANGE_LAST:
+    break;
+  }
+
+  assert(0);
+  return FALSE;
+}
+
+/****************************************************************************
   Checks the requirement to see if it is active on the given target.
 
   target gives the type of the target
@@ -511,13 +574,13 @@
                                     req->range, req->survives,
                                     req->source.value.building) > 0);
   case REQ_SPECIAL:
-    /* The requirement is filled if the tile has the special. */
-    return (target_tile
-           && tile_has_special(target_tile, req->source.value.special));
+    return is_special_in_range(target, target_tile,
+                              req->range, req->survives,
+                              req->source.value.special);
   case REQ_TERRAIN:
-    /* The requirement is filled if the tile has the terrain. */
-    return (target_tile
-           && (target_tile->terrain  == req->source.value.terrain));
+    return is_terrain_in_range(target, target_tile,
+                              req->range, req->survives,
+                              req->source.value.terrain);
   case REQ_LAST:
     break;
   }
Index: common/requirements.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.h,v
retrieving revision 1.3
diff -u -r1.3 requirements.h
--- common/requirements.h       2 Feb 2005 02:44:31 -0000       1.3
+++ common/requirements.h       7 Feb 2005 17:25:27 -0000
@@ -33,6 +33,7 @@
  * in requirements.c. */
 enum req_range {
   REQ_RANGE_LOCAL,
+  REQ_RANGE_ADJACENT,
   REQ_RANGE_CITY,
   REQ_RANGE_CONTINENT,
   REQ_RANGE_PLAYER,
Index: data/civ2/effects.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ2/effects.ruleset,v
retrieving revision 1.1
diff -u -r1.1 effects.ruleset
--- data/civ2/effects.ruleset   2 Feb 2005 02:44:32 -0000       1.1
+++ data/civ2/effects.ruleset   7 Feb 2005 17:25:27 -0000
@@ -259,7 +259,7 @@
 value  = 1
 reqs   =
     { "type", "name", "range"
-      "Terrain", "Ocean", "City"
+      "Terrain", "Ocean", "Local"
       "Building", "Harbour", "City"
     }
 
@@ -390,7 +390,7 @@
 value  = 1
 reqs   =
     { "type", "name", "range"
-      "Terrain", "Ocean", "City"
+      "Terrain", "Ocean", "Local"
       "Building", "Offshore Platform", "City"
     }
 
Index: data/default/effects.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/effects.ruleset,v
retrieving revision 1.1
diff -u -r1.1 effects.ruleset
--- data/default/effects.ruleset        2 Feb 2005 02:44:32 -0000       1.1
+++ data/default/effects.ruleset        7 Feb 2005 17:25:27 -0000
@@ -259,7 +259,7 @@
 value  = 1
 reqs   =
     { "type", "name", "range"
-      "Terrain", "Ocean", "City"
+      "Terrain", "Ocean", "Local"
       "Building", "Harbour", "City"
     }
 
@@ -421,7 +421,7 @@
 value  = 1
 reqs   =
     { "type", "name", "range"
-      "Terrain", "Ocean", "City"
+      "Terrain", "Ocean", "Local"
       "Building", "Offshore Platform", "City"
     }
 
Index: data/history/effects.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/history/effects.ruleset,v
retrieving revision 1.1
diff -u -r1.1 effects.ruleset
--- data/history/effects.ruleset        2 Feb 2005 02:44:32 -0000       1.1
+++ data/history/effects.ruleset        7 Feb 2005 17:25:27 -0000
@@ -259,7 +259,7 @@
 value  = 1
 reqs   =
     { "type", "name", "range"
-      "Terrain", "Ocean", "City"
+      "Terrain", "Ocean", "Local"
       "Building", "Harbour", "City"
     }
 
@@ -390,7 +390,7 @@
 value  = 1
 reqs   =
     { "type", "name", "range"
-      "Terrain", "Ocean", "City"
+      "Terrain", "Ocean", "Local"
       "Building", "Offshore Platform", "City"
     }
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12154) "adjacent" range for reqs, Jason Short <=