Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] (PR#12793) a minimum-size requirement
Home

[Freeciv-Dev] (PR#12793) a minimum-size requirement

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12793) a minimum-size requirement
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 14 Apr 2005 00:13:17 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch adds a minimum size requirement.  When applied at city range, 
it is met if the city has at least the size given in the requirement.

This is useful at the moment for specialists, which hard-code this 
requirement.  This patch also removes the specialist min_size entry and 
updates the rulesets to use the new requirement form.

No behavior should be changed.

-jason

Index: client/helpdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/helpdata.c,v
retrieving revision 1.101
diff -u -r1.101 helpdata.c
--- client/helpdata.c   14 Apr 2005 04:49:12 -0000      1.101
+++ client/helpdata.c   14 Apr 2005 07:12:51 -0000
@@ -186,6 +186,10 @@
     cat_snprintf(buf, bufsz, _("Requires the %s nation.\n\n"),
                 get_nation_name(req->source.value.nation));
     return;
+  case REQ_MINSIZE:
+    cat_snprintf(buf, bufsz, _("Requires a minimum size of %d.\n\n"),
+                req->source.value.minsize);
+    return;
   }
   assert(0);
 }
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.490
diff -u -r1.490 packhand.c
--- client/packhand.c   14 Apr 2005 04:49:12 -0000      1.490
+++ client/packhand.c   14 Apr 2005 07:12:52 -0000
@@ -2543,7 +2543,6 @@
     sz_strlcpy(game.rgame.specialists[sp].name, packet->specialist_name[sp]);
     sz_strlcpy(game.rgame.specialists[sp].short_name,
               packet->specialist_short_name[sp]);
-    game.rgame.specialists[sp].min_size = packet->specialist_min_size[sp];
     output_type_iterate(o) {
       bonus[o] = packet->specialist_bonus[sp * O_COUNT + o];
     } output_type_iterate_end;
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.327
diff -u -r1.327 city.c
--- common/city.c       14 Apr 2005 04:49:13 -0000      1.327
+++ common/city.c       14 Apr 2005 07:12:52 -0000
@@ -669,10 +669,6 @@
 bool city_can_use_specialist(const struct city *pcity,
                             Specialist_type_id type)
 {
-  if (pcity->size < game.rgame.specialists[type].min_size) {
-    return FALSE;
-  }
-
   return are_reqs_active(city_owner(pcity), pcity, B_LAST, NULL,
                         game.rgame.specialists[type].req, MAX_NUM_REQS);
 }
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.180
diff -u -r1.180 game.h
--- common/game.h       10 Apr 2005 23:55:24 -0000      1.180
+++ common/game.h       14 Apr 2005 07:12:53 -0000
@@ -196,7 +196,6 @@
       char name[MAX_LEN_NAME];
       char short_name[MAX_LEN_NAME];
       int bonus[O_MAX];
-      int min_size;
       struct requirement req[MAX_NUM_REQS];
     } specialists[SP_MAX];
 #define SP_COUNT game.rgame.num_specialist_types
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.105
diff -u -r1.105 packets.def
--- common/packets.def  14 Apr 2005 04:49:13 -0000      1.105
+++ common/packets.def  14 Apr 2005 07:12:53 -0000
@@ -991,7 +991,6 @@
   UINT8 req_array_size; # Another hack to get around limitations of packgen
   STRING specialist_name[SP_MAX:num_specialist_types][MAX_LEN_NAME];
   STRING specialist_short_name[SP_MAX:num_specialist_types][MAX_LEN_NAME];
-  UINT8 specialist_min_size[SP_MAX:num_specialist_types];
   UINT8 specialist_bonus[SP_MAX * O_MAX:bonus_array_size];
   UINT8 specialist_req_type[SP_MAX * MAX_NUM_REQS:req_array_size];
   UINT8 specialist_req_range[SP_MAX * MAX_NUM_REQS:req_array_size];
Index: common/requirements.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.c,v
retrieving revision 1.12
diff -u -r1.12 requirements.c
--- common/requirements.c       14 Apr 2005 04:49:13 -0000      1.12
+++ common/requirements.c       14 Apr 2005 07:12:53 -0000
@@ -34,7 +34,8 @@
   "Building",
   "Special",
   "Terrain",
-  "Nation"
+  "Nation",
+  "MinSize"
 };
 
 /* Names of requirement ranges. These must correspond to enum req_range in
@@ -134,6 +135,12 @@
       return source;
     }
     break;
+  case REQ_MINSIZE:
+    source.value.minsize = atoi(value);
+    if (source.value.minsize > 0) {
+      return source;
+    }
+    break;
   case REQ_LAST:
     break;
   }
@@ -174,6 +181,9 @@
   case REQ_NATION:
     source.value.nation = value;
     return source;
+  case REQ_MINSIZE:
+    source.value.minsize = value;
+    return source;
   case REQ_LAST:
     return source;
   }
@@ -214,6 +224,9 @@
   case REQ_NATION:
     *value = source->value.nation;
     return;
+  case REQ_MINSIZE:
+    *value = source->value.minsize;
+    return;
   case REQ_LAST:
     break;
   }
@@ -251,6 +264,9 @@
     case REQ_TERRAIN:
       req.range = REQ_RANGE_LOCAL;
       break;
+    case REQ_MINSIZE:
+      req.range = REQ_RANGE_CITY;
+      break;
     case REQ_GOV:
     case REQ_TECH:
     case REQ_NATION:
@@ -273,6 +289,9 @@
     /* FIXME: sanity checking */
     invalid = FALSE;
     break;
+  case REQ_MINSIZE:
+    invalid = (req.range != REQ_RANGE_CITY);
+    break;
   case REQ_NATION:
     invalid = (req.range != REQ_RANGE_PLAYER
               && req.range != REQ_RANGE_WORLD);
@@ -657,6 +676,8 @@
   case REQ_NATION:
     return is_nation_in_range(target_player, req->range, req->survives,
                              req->source.value.nation);
+  case REQ_MINSIZE:
+    return target_city && target_city->size >= req->source.value.minsize;
   case REQ_LAST:
     break;
   }
@@ -726,6 +747,8 @@
     return psource1->value.terrain == psource2->value.terrain;
   case REQ_NATION:
     return psource1->value.nation == psource2->value.nation;
+  case REQ_MINSIZE:
+    return psource1->value.minsize == psource2->value.minsize;
   case REQ_LAST:
     break;
   }
@@ -763,6 +786,9 @@
   case REQ_NATION:
     mystrlcat(buf, get_nation_name(psource->value.nation), bufsz);
     break;
+  case REQ_MINSIZE:
+    cat_snprintf(buf, bufsz, "Size %d", psource->value.minsize);
+    break;
   case REQ_LAST:
     assert(0);
     break;
Index: common/requirements.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.h,v
retrieving revision 1.9
diff -u -r1.9 requirements.h
--- common/requirements.h       14 Apr 2005 04:49:14 -0000      1.9
+++ common/requirements.h       14 Apr 2005 07:12:53 -0000
@@ -27,6 +27,7 @@
   REQ_SPECIAL,
   REQ_TERRAIN,
   REQ_NATION,
+  REQ_MINSIZE, /* Minimum size: at city range means city size */
   REQ_LAST
 };
 
@@ -53,6 +54,7 @@
     enum tile_special_type special;     /* source special */
     Terrain_type_id terrain;            /* source terrain type */
     Nation_Type_id nation;              /* source nation type */
+    int minsize;                        /* source minsize type */
   } value;                              /* source value */
 };
 
Index: data/default/cities.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/cities.ruleset,v
retrieving revision 1.15
diff -u -r1.15 cities.ruleset
--- data/default/cities.ruleset 26 Mar 2005 05:59:15 -0000      1.15
+++ data/default/cities.ruleset 14 Apr 2005 07:12:53 -0000
@@ -23,13 +23,21 @@
 
 types = _("elvis"), _("scientist"), _("taxman")
 elvis_short_name = _("?Elvis:E")
-elvis_min_size = 0
+elvis_req      =
+    { "type", "name", "range"
+    }
 elvis_bonus_luxury = 2
 scientist_short_name = _("?Scientist:S")
-scientist_min_size = 5
+scientist_req  =
+    { "type", "name", "range"
+      "MinSize", "5", "City"
+    }
 scientist_bonus_science = 3
 taxman_short_name = _("?Taxman:T")
-taxman_min_size = 5
+taxman_req     =
+    { "type", "name", "range"
+      "MinSize", "5", "City"
+    }
 taxman_bonus_gold = 3
 
 changable_tax = 1
Index: doc/README.effects
===================================================================
RCS file: /home/freeciv/CVS/freeciv/doc/README.effects,v
retrieving revision 1.8
diff -u -r1.8 README.effects
--- doc/README.effects  11 Apr 2005 22:42:06 -0000      1.8
+++ doc/README.effects  14 Apr 2005 07:12:53 -0000
@@ -171,11 +171,13 @@
            (if unspecified, 0 (doesn't survive) is assumed)
 .req_type  = The type of the requirement; one of:
              "None" (default), "Tech", "Gov", "Building", "Special",
-             "Terrain", "Nation"
+             "Terrain", "Nation", "MinSize"
 .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, tile
-             terrain, or nation that is required.  The requirement applies
-             to the target of the effect (not the source).
+             terrain, or nation that is required.  For MinSize it is the
+             minimum (city) size at which the requirement is met.  The
+             requirement applies to the target of the effect (not
+             the source).
 
 See data/default/buildings.ruleset for examples.
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.303
diff -u -r1.303 cityturn.c
--- server/cityturn.c   14 Apr 2005 04:49:15 -0000      1.303
+++ server/cityturn.c   14 Apr 2005 07:12:53 -0000
@@ -745,6 +745,13 @@
                               get_impr_name_ex(pcity, target),
                               get_nation_name(req->source.value.nation));
              break;
+           case REQ_MINSIZE:
+             notify_player_ex(pplayer, pcity->tile, E_CITY_CANTBUILD,
+                              _("%s can't build %s from the worklist; "
+                                "city must be of size %d.  Postponing..."),
+                              pcity->name, get_impr_name_ex(pcity, target),
+                              req->source.value.minsize);
+             break;
            case REQ_NONE:
            case REQ_LAST:
              assert(0);
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.243
diff -u -r1.243 ruleset.c
--- server/ruleset.c    14 Apr 2005 04:49:15 -0000      1.243
+++ server/ruleset.c    14 Apr 2005 07:12:54 -0000
@@ -2330,18 +2330,12 @@
       = secfile_lookup_str_default(file, name,
                                   "specialist.%s_short_name", name);
     sz_strlcpy(game.rgame.specialists[i].short_name, short_name);
-    game.rgame.specialists[i].min_size
-      = secfile_lookup_int(file, "specialist.%s_min_size", name);
 
     output_type_iterate(o) {
       bonus[o] = secfile_lookup_int_default(file, 0,
                                            "specialist.%s_bonus_%s",
                                            name, get_output_identifier(o));
     } output_type_iterate_end;
-    if (game.rgame.specialists[i].min_size == 0
-       && game.rgame.default_specialist == -1) {
-      game.rgame.default_specialist = i;
-    }
 
     for (j = 0; j < MAX_NUM_REQS; j++) {
       const char *type
@@ -2355,7 +2349,7 @@
                                      "specialist.%s_req%d.survives",
                                      name, j);
       const char *value
-       = secfile_lookup_str_default(file, "", "specialist.%s_req%d.value",
+       = secfile_lookup_str_default(file, "", "specialist.%s_req%d.name",
                                     name, j);
       struct requirement req = req_from_str(type, range, survives, value); 
 
@@ -2368,6 +2362,11 @@
 
       game.rgame.specialists[i].req[j] = req;
     }
+
+    if (game.rgame.specialists[i].req[0].source.type == REQ_NONE
+       && game.rgame.default_specialist == -1) {
+      game.rgame.default_specialist = i;
+    }
   }
   if (game.rgame.default_specialist == -1) {
     freelog(LOG_FATAL, "You must give a min_size of 0 for at least one "
@@ -3055,7 +3054,6 @@
     sz_strlcpy(misc_p.specialist_name[sp], game.rgame.specialists[sp].name);
     sz_strlcpy(misc_p.specialist_short_name[sp],
               game.rgame.specialists[sp].short_name);
-    misc_p.specialist_min_size[sp] = game.rgame.specialists[sp].min_size;
 
     output_type_iterate(o) {
       misc_p.specialist_bonus[sp * O_COUNT + o] = bonus[o];

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12793) a minimum-size requirement, Jason Short <=