Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] (PR#12750) nation reqs
Home

[Freeciv-Dev] (PR#12750) nation reqs

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12750) nation reqs
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 9 Apr 2005 17:58:50 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch adds reqs for nations.  This is useless to the default 
ruleset (all nations are equal) but should be of great use for modpacks.

The main user of reqs right now is the effects code.  So I attached a 
demo patch for the ruleset.  Play as Mordor and you get +100% production.

-jason

Index: client/helpdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/helpdata.c,v
retrieving revision 1.99
diff -u -r1.99 helpdata.c
--- client/helpdata.c   28 Mar 2005 17:14:57 -0000      1.99
+++ client/helpdata.c   10 Apr 2005 00:55:32 -0000
@@ -182,6 +182,10 @@
     cat_snprintf(buf, bufsz, _("Requires the %s terrain.\n\n"),
                 get_terrain_name(req->source.value.terrain));
     return;
+  case REQ_NATION:
+    cat_snprintf(buf, bufsz, _("Requires the %s nation.\n\n"),
+                get_nation_name(req->source.value.nation));
+    return;
   }
   assert(0);
 }
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.228
diff -u -r1.228 capstr.c
--- common/capstr.c     28 Mar 2005 17:14:57 -0000      1.228
+++ common/capstr.c     10 Apr 2005 00:55:33 -0000
@@ -82,7 +82,7 @@
  *     as long as possible.  We want to maintain network compatibility with
  *     the stable branch for as long as possible.
  */
-#define CAPABILITY "+Freeciv.Devel.2004.Mar.28"
+#define CAPABILITY "+Freeciv.Devel.2004.Apr.9"
 
 void init_our_capability(void)
 {
Index: common/effects.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.c,v
retrieving revision 1.27
diff -u -r1.27 effects.c
--- common/effects.c    10 Apr 2005 00:50:37 -0000      1.27
+++ common/effects.c    10 Apr 2005 00:55:33 -0000
@@ -865,6 +865,9 @@
       case REQ_TERRAIN:
        mystrlcat(buf, get_terrain_name(psource->value.terrain), buf_len);
        break;
+    case REQ_NATION:
+      mystrlcat(buf, get_nation_name(psource->value.nation), buf_len);
+      break;
       case REQ_LAST:
        break;
     }
Index: common/fc_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/fc_types.h,v
retrieving revision 1.17
diff -u -r1.17 fc_types.h
--- common/fc_types.h   29 Mar 2005 12:28:26 -0000      1.17
+++ common/fc_types.h   10 Apr 2005 00:55:33 -0000
@@ -46,6 +46,8 @@
 typedef int Specialist_type_id;
 typedef int Impr_Type_id;
 typedef enum output_type Output_type_id;
+typedef int Nation_Type_id;
+typedef int Team_Type_id;
 
 struct city;
 struct government;
Index: common/nation.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.h,v
retrieving revision 1.39
diff -u -r1.39 nation.h
--- common/nation.h     29 Mar 2005 12:28:26 -0000      1.39
+++ common/nation.h     10 Apr 2005 00:55:33 -0000
@@ -37,9 +37,6 @@
 
 #define MAX_NUM_NATION_GROUPS 128
 
-typedef int Nation_Type_id;
-typedef int Team_Type_id;
-
 struct sprite;                 /* opaque; client-gui specific */
 
 /*
Index: common/requirements.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.c,v
retrieving revision 1.10
diff -u -r1.10 requirements.c
--- common/requirements.c       3 Apr 2005 20:19:52 -0000       1.10
+++ common/requirements.c       10 Apr 2005 00:55:33 -0000
@@ -33,7 +33,8 @@
   "Gov",
   "Building",
   "Special",
-  "Terrain"
+  "Terrain",
+  "Nation"
 };
 
 /* Names of requirement ranges. These must correspond to enum req_range in
@@ -127,6 +128,12 @@
       return source;
     }
     break;
+  case REQ_NATION:
+    source.value.nation = find_nation_by_name(value);
+    if (source.value.nation != NO_NATION_SELECTED) {
+      return source;
+    }
+    break;
   case REQ_LAST:
     break;
   }
@@ -164,6 +171,9 @@
   case REQ_TERRAIN:
     source.value.terrain = value;
     return source;
+  case REQ_NATION:
+    source.value.nation = value;
+    return source;
   case REQ_LAST:
     return source;
   }
@@ -201,6 +211,9 @@
   case REQ_TERRAIN:
     *value = source->value.terrain;
     return;
+  case REQ_NATION:
+    *value = source->value.nation;
+    return;
   case REQ_LAST:
     break;
   }
@@ -240,6 +253,7 @@
       break;
     case REQ_GOV:
     case REQ_TECH:
+    case REQ_NATION:
       req.range = REQ_RANGE_PLAYER;
       break;
     }
@@ -259,6 +273,10 @@
     /* FIXME: sanity checking */
     invalid = FALSE;
     break;
+  case REQ_NATION:
+    invalid = (req.range != REQ_RANGE_PLAYER
+              && req.range != REQ_RANGE_WORLD);
+    break;
   case REQ_NONE:
     invalid = FALSE;
     break;
@@ -559,6 +577,36 @@
 }
 
 /****************************************************************************
+  Is there a nation within range of the target?
+****************************************************************************/
+static bool is_nation_in_range(const struct player *target_player,
+                              enum req_range range, bool survives,
+                              Nation_Type_id nation)
+{
+  switch (range) {
+  case REQ_RANGE_PLAYER:
+    return target_player && target_player->nation == nation;
+  case REQ_RANGE_WORLD:
+    /* FIXME: inefficient */
+    players_iterate(pplayer) {
+      if (pplayer->nation == nation && (pplayer->is_alive || survives)) {
+       return TRUE;
+      }
+    } players_iterate_end;
+    return FALSE;
+  case REQ_RANGE_LOCAL:
+  case REQ_RANGE_ADJACENT:
+  case REQ_RANGE_CITY:
+  case REQ_RANGE_CONTINENT:
+  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
@@ -606,6 +654,9 @@
     return is_terrain_in_range(target_tile,
                               req->range, req->survives,
                               req->source.value.terrain);
+  case REQ_NATION:
+    return is_nation_in_range(target_player, req->range, req->survives,
+                             req->source.value.nation);
   case REQ_LAST:
     break;
   }
Index: common/requirements.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.h,v
retrieving revision 1.7
diff -u -r1.7 requirements.h
--- common/requirements.h       3 Apr 2005 20:19:52 -0000       1.7
+++ common/requirements.h       10 Apr 2005 00:55:33 -0000
@@ -26,6 +26,7 @@
   REQ_BUILDING,
   REQ_SPECIAL,
   REQ_TERRAIN,
+  REQ_NATION,
   REQ_LAST
 };
 
@@ -51,6 +52,7 @@
     Impr_Type_id building;              /* source building */
     enum tile_special_type special;     /* source special */
     Terrain_type_id terrain;            /* source terrain type */
+    Nation_Type_id nation;              /* source nation type */
   } value;                              /* source value */
 };
 
Index: doc/README.effects
===================================================================
RCS file: /home/freeciv/CVS/freeciv/doc/README.effects,v
retrieving revision 1.7
diff -u -r1.7 README.effects
--- doc/README.effects  10 Apr 2005 00:50:37 -0000      1.7
+++ doc/README.effects  10 Apr 2005 00:55:33 -0000
@@ -170,11 +170,12 @@
 .survives  = 1 if effect survives destruction (wonders only)
            (if unspecified, 0 (doesn't survive) is assumed)
 .req_type  = The type of the requirement; one of:
-             "None" (default), "Tech", "Gov", "Building", "Special", "Terrain"
+             "None" (default), "Tech", "Gov", "Building", "Special",
+             "Terrain", "Nation"
 .req       = The requirement.  The effect will not be active unless this
              requirement is met.  This is a string containing the name of
-             the technology, government, building, tile special, or tile
-             terrain that is required.  The requirement applies to the
-             target of the effect (not the source).
+             the technology, government, building, tile special, tile
+             terrain, or nation that is required.  The requirement applies
+             to the target of the effect (not the source).
 
 See data/default/buildings.ruleset for examples.
Index: data/default/effects.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/effects.ruleset,v
retrieving revision 1.5
diff -u -r1.5 effects.ruleset
--- data/default/effects.ruleset        10 Apr 2005 00:50:37 -0000      1.5
+++ data/default/effects.ruleset        10 Apr 2005 00:55:40 -0000
@@ -16,6 +16,14 @@
 ; /* <-- avoid gettext warnings
 ; */ <-- avoid gettext warnings
 
+[effect_sauron_wins]
+name    = "Prod_Bonus"
+value   = 100
+reqs    =
+    { "type", "name", "range"
+      "Nation", "Mordor", "World"
+    }
+
 [effect_airport]
 name   = "Air_Veteran"
 value  = 1

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12750) nation reqs, Jason Short <=