Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] (PR#13046) clean up specialists in the ruleset
Home

[Freeciv-Dev] (PR#13046) clean up specialists in the ruleset

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13046) clean up specialists in the ruleset
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 11 May 2005 13:53:17 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch cleans up the specialists in the cities.ruleset to use a
grid, like every other type of element does.  This makes the ruleset
more readible and the loading code shorter.

The non-specialist-related parameters that were in the [specialist]
section I moved into the [parameters] section.

(Note, this patch is a few days old.  I don't know if it still applies.)

-jason

Index: data/default/cities.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/cities.ruleset,v
retrieving revision 1.16
diff -u -r1.16 cities.ruleset
--- data/default/cities.ruleset 21 Apr 2005 00:28:27 -0000      1.16
+++ data/default/cities.ruleset 21 Apr 2005 00:58:20 -0000
@@ -11,45 +11,69 @@
 description="Cities data for Freeciv"
 options="1.9"
 
-; Configure the effect of specialists. Each specialist contributes
-; the given amount of its special kind of value (luxury for elvis,
-; research for scientist and gold for taxman). You can set
-; changable_tax to zero to disallow players setting the taxrate
-; for themselves. In this case, the values in the forced_ fields
-; apply instead, modified by government restrictions. The min_size
-; fields restrict setting specialists to this type before the
-; the city is of a certain size.
-[specialist]
-
-types = _("elvis"), _("scientist"), _("taxman")
-elvis_short_name = _("?Elvis:E")
-elvis_req      =
+
+; A specialist is a city citizen who is not a tile worker.  Usually the
+; player can control what specialist each citizen is, so long as the
+; requirements for that specialist are met.
+;
+; Below are the entries for the specialists, one per specialist type.
+; The tag name (in [specialist_*]) doesn't matter so long as it's unique.
+; For each specialist the following fields may be set:
+;
+; 
+; name         = name as seen by user 
+; short_name    = one-character "short name" used (for instance) in cityrep
+; reqs         = requirements to build the building (see effects.ruleset
+;                and README.effects for help on requirements)
+; bonus_food    = Food given by this specialist
+; bonus_shield
+; bonus_trade
+; bonus_gold
+; bonus_luxury
+; bonus_science
+
+[specialist_elvis]
+name = _("elvis")
+short_name = _("?Elvis:E")
+reqs   =
     { "type", "name", "range"
 ; Nothing
     }
-elvis_bonus_luxury = 2
-scientist_short_name = _("?Scientist:S")
-scientist_req  =
+bonus_luxury = 2
+
+[specialist_scientist]
+name = _("scientist")
+short_name = _("?Scientist:S")
+reqs   =
     { "type", "name", "range"
       "MinSize", "5", "City"
     }
-scientist_bonus_science = 3
-taxman_short_name = _("?Taxman:T")
-taxman_req     =
+bonus_science = 3
+
+[specialist_taxman]
+name = _("taxman")
+short_name = _("?Taxman:T")
+eqs    =
     { "type", "name", "range"
       "MinSize", "5", "City"
     }
-taxman_bonus_gold = 3
+bonus_gold = 3
 
-changable_tax = 1
-;forced_science = 0
-;forced_luxury = 100
-;forced_gold = 0
 
 [parameters]
 add_to_size_limit  = 8         ; cities >= this cannot be added to.
 angry_citizens = 1              ; set to zero to disable angry citizens
 
+; Set this to 0 to disallow changing of tax rates
+changeable_tax = 1
+
+; Set these fields when changeable_tax is turned off
+;forced_science = 0
+;forced_luxury = 100
+;forced_gold = 0
+
+
+
 ;
 ; City styles define the way cities are drawn
 ;
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.245
diff -u -r1.245 ruleset.c
--- server/ruleset.c    21 Apr 2005 00:28:28 -0000      1.245
+++ server/ruleset.c    21 Apr 2005 00:58:20 -0000
@@ -2278,57 +2278,39 @@
 **************************************************************************/
 static void load_ruleset_cities(struct section_file *file)
 {
-  char **styles, *replacement;
+  char **styles, **sec, *replacement;
   int i, nval, j;
   const char *filename = secfile_filename(file);
-  char **specialist_names;
+  char *item;
 
   (void) check_ruleset_capabilities(file, "+1.9", filename);
 
   /* Specialist options */
-  specialist_names = secfile_lookup_str_vec(file, &nval, "specialist.types");
+  sec = secfile_get_secnames_prefix(file, "specialist_", &nval);
 
   for (i = 0; i < nval; i++) {
-    const char *name = specialist_names[i], *short_name;
-    int *bonus = game.rgame.specialists[i].bonus;
-    int j;
+    struct specialist *s = &game.rgame.specialists[i];
+    struct requirement_vector *reqs = lookup_req_list(file, sec[i], "reqs");
+
+    item = secfile_lookup_str(file, "%s.name", sec[i]);
+    sz_strlcpy(s->name, item);
 
-    sz_strlcpy(game.rgame.specialists[i].name, name);
-    short_name
-      = secfile_lookup_str_default(file, name,
-                                  "specialist.%s_short_name", name);
-    sz_strlcpy(game.rgame.specialists[i].short_name, short_name);
+    item = secfile_lookup_str_default(file, s->name, "%s.short_name", sec[i]);
+    sz_strlcpy(s->short_name, item);
 
     output_type_iterate(o) {
-      bonus[o] = secfile_lookup_int_default(file, 0,
-                                           "specialist.%s_bonus_%s",
-                                           name, get_output_identifier(o));
+      s->bonus[o]
+       = secfile_lookup_int_default(file, 0, "%s.bonus_%s",
+                                    sec[i], get_output_identifier(o));
     } output_type_iterate_end;
 
     for (j = 0; j < MAX_NUM_REQS; j++) {
-      const char *type
-       = secfile_lookup_str_default(file, NULL, "specialist.%s_req%d.type",
-                                    name, j);
-      const char *range
-       = secfile_lookup_str_default(file, "", "specialist.%s_req%d.range",
-                                    name, j);
-      bool survives
-       = secfile_lookup_bool_default(file, FALSE,
-                                     "specialist.%s_req%d.survives",
-                                     name, j);
-      const char *value
-       = secfile_lookup_str_default(file, "", "specialist.%s_req%d.name",
-                                    name, j);
-      struct requirement req = req_from_str(type, range, survives, value); 
-
-      if (req.source.type == REQ_LAST) {
-       freelog(LOG_ERROR,
-               "Specialist %s has unknown req: \"%s\" \"%s\" \"%s\" %d (%s)",
-               name, type, range, value, survives, filename);
-       req.source.type = REQ_NONE;
+      if (reqs->size > j) {
+       s->req[j] = reqs->p[j];
+      } else {
+       memset(&s->req[j], 0, sizeof(s->req[j]));
+       s->req[j].source.type = REQ_NONE;
       }
-
-      game.rgame.specialists[i].req[j] = req;
     }
 
     if (game.rgame.specialists[i].req[0].source.type == REQ_NONE
@@ -2342,32 +2324,29 @@
     exit(EXIT_FAILURE);
   }
   game.rgame.num_specialist_types = nval;
-  free(specialist_names);
+  free(sec);
 
+  /* City Parameters */
+
+  game.add_to_size_limit =
+    secfile_lookup_int_default(file, 9, "parameters.add_to_size_limit");
+  game.angrycitizen =
+    secfile_lookup_bool_default(file, GAME_DEFAULT_ANGRYCITIZEN,
+                                "parameters.angry_citizens");
   game.rgame.changable_tax = 
-    secfile_lookup_bool_default(file, TRUE, "specialist.changable_tax");
+    secfile_lookup_bool_default(file, TRUE, "parameters.changable_tax");
   game.rgame.forced_science = 
-    secfile_lookup_int_default(file, 0, "specialist.forced_science");
+    secfile_lookup_int_default(file, 0, "parameters.forced_science");
   game.rgame.forced_luxury = 
-    secfile_lookup_int_default(file, 100, "specialist.forced_luxury");
+    secfile_lookup_int_default(file, 100, "parameters.forced_luxury");
   game.rgame.forced_gold = 
-    secfile_lookup_int_default(file, 0, "specialist.forced_gold");
+    secfile_lookup_int_default(file, 0, "parameters.forced_gold");
   if (game.rgame.forced_science + game.rgame.forced_luxury
       + game.rgame.forced_gold != 100) {
     freelog(LOG_FATAL, "Forced taxes do not add up in ruleset!");
     exit(EXIT_FAILURE);
   }
 
-  /* City Parameters */
-
-  game.add_to_size_limit =
-    secfile_lookup_int_default(file, 9, "parameters.add_to_size_limit");
-
-  /* Angry citizens */
-
-  game.angrycitizen =
-    secfile_lookup_bool_default(file, GAME_DEFAULT_ANGRYCITIZEN,
-                                "parameters.angry_citizens");
 
   /* City Styles ... */
 

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