Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2004:
[Freeciv-Dev] (PR#8921) specialist names in the ruleset
Home

[Freeciv-Dev] (PR#8921) specialist names in the ruleset

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8921) specialist names in the ruleset
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 6 Jun 2004 00:12:11 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8921 >

This patch puts the specialist names ("elvis", "scientist", "taxman") 
into the ruleset.  This is straightforward and another step toward 
generalizing specialists.

As you might expect changing the names will break savegame 
compatability.  In fact since most code elsewhere hard-codes the 
specialist types, changing the order will also break things badly.  I 
added a comment about this.  Of course this should not always be the 
case, but we have to start somewhere.

jason

? error.gz
? orig
? test.gz
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.375
diff -u -r1.375 packhand.c
--- client/packhand.c   2 Jun 2004 19:47:41 -0000       1.375
+++ client/packhand.c   6 Jun 2004 07:08:33 -0000
@@ -2674,6 +2674,7 @@
   int i;
 
   for (i = 0; i < SP_COUNT; i++) {
+    sz_strlcpy(game.rgame.specialists[i].name, packet->specialist_name[i]);
     game.rgame.specialists[i].min_size = packet->specialist_min_size[i];
     game.rgame.specialists[i].bonus = packet->specialist_bonus[i];
   }
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.141
diff -u -r1.141 game.h
--- common/game.h       31 May 2004 16:38:54 -0000      1.141
+++ common/game.h       6 Jun 2004 07:08:33 -0000
@@ -187,6 +187,7 @@
   /* values from game.ruleset */
   struct {
     struct {
+      char name[MAX_LEN_NAME];
       int min_size, bonus;
     } specialists[SP_COUNT];
     bool changable_tax;
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.26
diff -u -r1.26 packets.def
--- common/packets.def  2 Jun 2004 19:47:41 -0000       1.26
+++ common/packets.def  6 Jun 2004 07:08:33 -0000
@@ -956,6 +956,7 @@
 end
 
 PACKET_RULESET_GAME=97;sc,lsend
+  STRING specialist_name[SP_COUNT][MAX_LEN_NAME];
   UINT8 specialist_min_size[SP_COUNT];
   UINT8 specialist_bonus[SP_COUNT];
   BOOL changable_tax; add-cap(spec)
Index: data/default/cities.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/cities.ruleset,v
retrieving revision 1.10
diff -u -r1.10 cities.ruleset
--- data/default/cities.ruleset 21 May 2004 19:03:44 -0000      1.10
+++ data/default/cities.ruleset 6 Jun 2004 07:08:33 -0000
@@ -20,16 +20,20 @@
 ; fields restrict setting specialists to this type before the
 ; the city is of a certain size.
 [specialist]
-base_elvis = 2
-base_scientist = 3
-base_taxman = 3
+
+; Changing any of these values is likely to break things
+types = "elvis", "scientist", "taxman"
+elvis_min_size = 0
+elvis_base_bonus = 2
+scientist_min_size = 5
+scientist_base_bonus = 3
+taxman_min_size = 5
+taxman_base_bonus = 3
+
 changable_tax = 1
 ;forced_science = 0
 ;forced_luxury = 100
 ;forced_gold = 0
-min_size_elvis = 0
-min_size_taxman = 5
-min_size_scientist = 5
 
 [parameters]
 add_to_size_limit  = 8         ; cities >= this cannot be added to.
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.174
diff -u -r1.174 ruleset.c
--- server/ruleset.c    31 May 2004 16:38:55 -0000      1.174
+++ server/ruleset.c    6 Jun 2004 07:08:34 -0000
@@ -2490,23 +2490,29 @@
   char **styles, *replacement;
   int i, nval;
   const char *filename = secfile_filename(file);
+  char **specialist_names;
 
   (void) check_ruleset_capabilities(file, "+1.9", filename);
 
   /* Specialist options */
+  specialist_names = secfile_lookup_str_vec(file, &nval, "specialist.types");
+  if (nval != SP_COUNT) {
+    freelog(LOG_FATAL, "There must be exactly %d types of specialist.",
+           SP_COUNT);
+    exit(EXIT_FAILURE);
+  }
+
+  for (i = 0; i < nval; i++) {
+    const char *name = specialist_names[i];
+
+    sz_strlcpy(game.rgame.specialists[i].name, name);
+    game.rgame.specialists[i].min_size
+      = secfile_lookup_int(file, "specialist.%s_min_size", name);
+    game.rgame.specialists[i].bonus
+      = secfile_lookup_int(file, "specialist.%s_base_bonus", name);
+    
+  }
 
-  game.rgame.specialists[SP_ELVIS].min_size =
-    secfile_lookup_int_default(file, 0, "specialist.min_size_elvis");
-  game.rgame.specialists[SP_SCIENTIST].min_size =
-    secfile_lookup_int_default(file, 5, "specialist.min_size_scientist");
-  game.rgame.specialists[SP_TAXMAN].min_size =
-    secfile_lookup_int_default(file, 5, "specialist.min_size_taxman");
-  game.rgame.specialists[SP_ELVIS].bonus =
-    secfile_lookup_int_default(file, 2, "specialist.base_elvis");
-  game.rgame.specialists[SP_SCIENTIST].bonus =
-    secfile_lookup_int_default(file, 3, "specialist.base_scientist");
-  game.rgame.specialists[SP_TAXMAN].bonus =
-    secfile_lookup_int_default(file, 3, "specialist.base_taxman");
   game.rgame.changable_tax = 
     secfile_lookup_bool_default(file, TRUE, "specialist.changable_tax");
   game.rgame.forced_science = 
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.157
diff -u -r1.157 savegame.c
--- server/savegame.c   31 May 2004 06:41:11 -0000      1.157
+++ server/savegame.c   6 Jun 2004 07:08:35 -0000
@@ -943,12 +943,11 @@
 
     pcity->steal=secfile_lookup_int(file, "player%d.c%d.steal", plrno, i);
 
-    pcity->specialists[SP_ELVIS]
-      = secfile_lookup_int(file, "player%d.c%d.nelvis", plrno, i);
-    pcity->specialists[SP_SCIENTIST]
-      = secfile_lookup_int(file, "player%d.c%d.nscientist", plrno, i);
-    pcity->specialists[SP_TAXMAN]
-      = secfile_lookup_int(file, "player%d.c%d.ntaxman", plrno, i);
+    for (j = 0; j < SP_COUNT; j++) {
+      pcity->specialists[j]
+       = secfile_lookup_int(file, "player%d.c%d.n%s", plrno, i,
+                            game.rgame.specialists[j].name);
+    }
 
     for (j = 0; j < NUM_TRADEROUTES; j++)
       pcity->trade[j]=secfile_lookup_int(file, "player%d.c%d.traderoute%d",
@@ -1710,12 +1709,11 @@
                       plrno, i);
     secfile_insert_int(file, pcity->size, "player%d.c%d.size", plrno, i);
     secfile_insert_int(file, pcity->steal, "player%d.c%d.steal", plrno, i);
-    secfile_insert_int(file, pcity->specialists[SP_ELVIS],
-                      "player%d.c%d.nelvis", plrno, i);
-    secfile_insert_int(file, pcity->specialists[SP_SCIENTIST],
-                      "player%d.c%d.nscientist", plrno, i);
-    secfile_insert_int(file, pcity->specialists[SP_TAXMAN],
-                      "player%d.c%d.ntaxman", plrno, i);
+    for (j = 0; j < SP_COUNT; j++) {
+      secfile_insert_int(file, pcity->specialists[j],
+                        "player%d.c%d.n%s", plrno, i,
+                        game.rgame.specialists[j].name);
+    }
 
     for (j = 0; j < NUM_TRADEROUTES; j++)
       secfile_insert_int(file, pcity->trade[j], "player%d.c%d.traderoute%d", 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8921) specialist names in the ruleset, Jason Short <=