Complete.Org: Mailing Lists: Archives: freeciv-dev: March 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: Thu, 17 Mar 2005 20:52:02 -0800
Reply-to: bugs@xxxxxxxxxxx

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

Here is an updated patch for adjacent reqs.  I believe this is ready to
be committed.

-jason

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       18 Mar 2005 04:51:37 -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",
@@ -220,6 +221,7 @@
                                const char *value)
 {
   struct requirement req;
+  bool invalid = TRUE;
 
   req.source = req_source_from_str(type, value);
 
@@ -234,7 +236,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:
@@ -244,6 +246,31 @@
   }
 
   req.survives = survives;
+
+  switch (req.source.type) {
+  case REQ_SPECIAL:
+  case REQ_TERRAIN:
+    invalid = (req.range != REQ_RANGE_LOCAL
+              && req.range != REQ_RANGE_ADJACENT);
+    break;
+  case REQ_TECH:
+  case REQ_GOV:
+  case REQ_BUILDING:
+    /* FIXME: sanity checking */
+    invalid = FALSE;
+    break;
+  case REQ_NONE:
+    invalid = FALSE;
+    break;
+  case REQ_LAST:
+    break;
+  }
+  if (invalid) {
+    freelog(LOG_ERROR, "Invalid requirement %s | %s | %s | %s",
+           type, range, survives ? "survives" : "", value);
+    exit(EXIT_FAILURE);
+  }
+
   return req;
 }
 
@@ -462,6 +489,7 @@
       return 0;
     }
   case REQ_RANGE_LAST:
+  case REQ_RANGE_ADJACENT:
     break;
   }
   assert(0);
@@ -469,6 +497,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 +600,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       18 Mar 2005 04:51:37 -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.2
diff -u -r1.2 effects.ruleset
--- data/civ2/effects.ruleset   1 Mar 2005 22:40:28 -0000       1.2
+++ data/civ2/effects.ruleset   18 Mar 2005 04:51:37 -0000
@@ -263,7 +263,7 @@
 value  = 1
 reqs   =
     { "type", "name", "range"
-      "Terrain", "Ocean", "City"
+      "Terrain", "Ocean", "Local"
       "Building", "Harbour", "City"
     }
 
@@ -394,7 +394,7 @@
 value  = 1
 reqs   =
     { "type", "name", "range"
-      "Terrain", "Ocean", "City"
+      "Terrain", "Ocean", "Local"
       "Building", "Offshore Platform", "City"
     }
 
@@ -611,7 +611,7 @@
 value  = 50
 reqs   =
     { "type", "name", "range"
-      "Special", "Road", "City"
+      "Special", "Road", "Local"
       "Building", "Super Highways", "City"
     }
 
@@ -620,7 +620,7 @@
 value  = 50
 reqs   =
     { "type", "name", "range"
-      "Special", "Farmland", "City"
+      "Special", "Farmland", "Local"
       "Building", "Supermarket", "City"
     }
 
Index: data/default/effects.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/effects.ruleset,v
retrieving revision 1.2
diff -u -r1.2 effects.ruleset
--- data/default/effects.ruleset        1 Mar 2005 22:40:28 -0000       1.2
+++ data/default/effects.ruleset        18 Mar 2005 04:51:37 -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"
     }
 
@@ -643,7 +643,7 @@
 value  = 50
 reqs   =
     { "type", "name", "range"
-      "Special", "Road", "City"
+      "Special", "Road", "Local"
       "Building", "Super Highways", "City"
     }
 
@@ -652,7 +652,7 @@
 value  = 50
 reqs   =
     { "type", "name", "range"
-      "Special", "Farmland", "City"
+      "Special", "Farmland", "Local"
       "Building", "Supermarket", "City"
     }
 
Index: data/history/effects.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/history/effects.ruleset,v
retrieving revision 1.2
diff -u -r1.2 effects.ruleset
--- data/history/effects.ruleset        1 Mar 2005 22:40:28 -0000       1.2
+++ data/history/effects.ruleset        18 Mar 2005 04:51:37 -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"
     }
 
@@ -607,7 +607,7 @@
 value  = 50
 reqs   =
     { "type", "name", "range"
-      "Special", "Road", "City"
+      "Special", "Road", "Local"
       "Building", "Super Highways", "City"
     }
 
@@ -616,7 +616,7 @@
 value  = 50
 reqs   =
     { "type", "name", "range"
-      "Special", "Farmland", "City"
+      "Special", "Farmland", "Local"
       "Building", "Supermarket", "City"
     }
 

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