Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#11142) allow specialists to provide science, gold, or
Home

[Freeciv-Dev] (PR#11142) allow specialists to provide science, gold, or

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11142) allow specialists to provide science, gold, or luxury
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 21 Nov 2004 17:59:16 -0800
Reply-to: rt@xxxxxxxxxxx

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

This patch allows specialists to provide any or all of science, gold, or 
luxury.

Instead of a "bonus" value, there is a bonus_sci, bonus_tax, bonus_lux. 
  Simple enough.  A new non-manditory capability is added.

Warning: don't actually use these features in your ruleset unless you're 
debugging.  The AI is still hard-coded and will not be able to deal with 
it.  The non-manditory capability allows compatibility with older 
freecivs but will still break if specialists don't have the output types 
expected by older freecivs.  Finally there's a problem that all rulesets 
use the cities.ruleset from the default ruleset, so any changes here 
will break civ1/civ2 rulesets.

jason

? diff
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.421
diff -u -r1.421 packhand.c
--- client/packhand.c   20 Nov 2004 17:27:43 -0000      1.421
+++ client/packhand.c   22 Nov 2004 01:48:41 -0000
@@ -2636,7 +2636,31 @@
   specialist_type_iterate(sp) {
     sz_strlcpy(game.rgame.specialists[sp].name, packet->specialist_name[sp]);
     game.rgame.specialists[sp].min_size = packet->specialist_min_size[sp];
-    game.rgame.specialists[sp].bonus = packet->specialist_bonus[sp];
+    if (has_capability("spec_multi", aconnection.capability)) {
+      game.rgame.specialists[sp].bonus_sci
+       = packet->specialist_bonus_sci[sp];
+      game.rgame.specialists[sp].bonus_tax
+       = packet->specialist_bonus_tax[sp];
+      game.rgame.specialists[sp].bonus_lux
+       = packet->specialist_bonus_lux[sp];
+    } else {
+      int bonus = packet->specialist_bonus[sp];
+
+      game.rgame.specialists[sp].bonus_sci = 0;
+      game.rgame.specialists[sp].bonus_tax = 0;
+      game.rgame.specialists[sp].bonus_lux = 0;
+      switch (sp) {
+      case SP_ELVIS:
+       game.rgame.specialists[sp].bonus_lux = bonus;
+       break;
+      case SP_SCIENTIST:
+       game.rgame.specialists[sp].bonus_sci = bonus;
+       break;
+      case SP_TAXMAN:
+       game.rgame.specialists[sp].bonus_tax = bonus;
+       break;
+      }
+    }
   } specialist_type_iterate_end;
   tilespec_setup_specialist_types();
 
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.195
diff -u -r1.195 capstr.c
--- common/capstr.c     16 Nov 2004 18:09:46 -0000      1.195
+++ common/capstr.c     22 Nov 2004 01:48:41 -0000
@@ -83,6 +83,12 @@
  *
  * "username_info" means that the username is sent in the player_info packet
  *
+ * "new_hack" means a new-style hack-request method
+ *
+ * "spec_multi" means specialists may provide more than one type of output.
+ * Note that actually using this feature with an unsupported client will
+ * break it.
+ *
  *   - No new manditory capabilities can be added to the release branch; doing
  *     so would break network capability of supposedly "compatible" releases.
  *
@@ -90,7 +96,8 @@
  *     as long as possible.  We want to maintain network compatibility with
  *     the stable branch for as long as possible.
  */
-#define CAPABILITY "+2.0 connecting conn_ping_info username_info new_hack"
+#define CAPABILITY "+2.0 connecting conn_ping_info username_info new_hack " \
+                   "spec_multi"
 
 void init_our_capability(void)
 {
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.255
diff -u -r1.255 city.c
--- common/city.c       17 Nov 2004 19:21:14 -0000      1.255
+++ common/city.c       22 Nov 2004 01:48:42 -0000
@@ -1676,12 +1676,15 @@
   get_tax_income(city_owner(pcity), pcity->trade_prod, &pcity->science_total, 
                  &pcity->luxury_total, &pcity->tax_total);
 
-  pcity->luxury_total += (pcity->specialists[SP_ELVIS]
-                         * game.rgame.specialists[SP_ELVIS].bonus);
-  pcity->science_total += (pcity->specialists[SP_SCIENTIST]
-                          * game.rgame.specialists[SP_SCIENTIST].bonus);
-  pcity->tax_total += (pcity->specialists[SP_TAXMAN]
-                       * game.rgame.specialists[SP_TAXMAN].bonus);
+  specialist_type_iterate(sp) {
+    pcity->luxury_total
+      += pcity->specialists[sp] * game.rgame.specialists[sp].bonus_lux;
+    pcity->science_total
+      += pcity->specialists[sp] * game.rgame.specialists[sp].bonus_sci;
+    pcity->tax_total
+      += pcity->specialists[sp] * game.rgame.specialists[sp].bonus_tax;
+  } specialist_type_iterate_end;
+
   pcity->tax_total += get_city_tithes_bonus(pcity);
 }
 
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.157
diff -u -r1.157 game.h
--- common/game.h       22 Nov 2004 00:51:18 -0000      1.157
+++ common/game.h       22 Nov 2004 01:48:42 -0000
@@ -195,7 +195,8 @@
   struct {
     struct {
       char name[MAX_LEN_NAME];
-      int min_size, bonus;
+      int min_size;
+      int bonus_sci, bonus_tax, bonus_lux;
     } specialists[SP_COUNT];
 #define DEFAULT_SPECIALIST SP_ELVIS
     bool changable_tax;
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.59
diff -u -r1.59 packets.def
--- common/packets.def  16 Nov 2004 18:09:46 -0000      1.59
+++ common/packets.def  22 Nov 2004 01:48:42 -0000
@@ -973,7 +973,10 @@
 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];
+  UINT8 specialist_bonus[SP_COUNT]; remove-cap(spec_multi)
+  UINT8 specialist_bonus_sci[SP_COUNT]; add-cap(spec_multi)
+  UINT8 specialist_bonus_tax[SP_COUNT]; add-cap(spec_multi)
+  UINT8 specialist_bonus_lux[SP_COUNT]; add-cap(spec_multi)
   BOOL changable_tax;
   UINT8 forced_science;
   UINT8 forced_luxury;
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.44
diff -u -r1.44 cm.c
--- common/aicore/cm.c  19 Nov 2004 02:31:35 -0000      1.44
+++ common/aicore/cm.c  22 Nov 2004 01:48:42 -0000
@@ -174,7 +174,7 @@
   int production[NUM_STATS];
   double estimated_fitness; /* weighted sum of production */
   bool is_specialist;
-  enum specialist_type spec; /* valid only if is_specialist */
+  Specialist_type_id spec; /* valid only if is_specialist */
   struct tile_vector tiles;  /* valid only if !is_specialist */
   struct tile_type_vector better_types;
   struct tile_type_vector worse_types;
@@ -918,19 +918,7 @@
 
 /*
  * Add the specialist types to the lattice.
- * This structure is necessary for now because each specialist
- * creates only one type of production and we need to map
- * indices from specialist_type to cm_stat.
  */
-struct spec_stat_pair {
-  enum specialist_type spec;
-  enum cm_stat stat;
-};
-const static struct spec_stat_pair pairs[SP_COUNT] =  {
-  { SP_ELVIS, LUXURY },
-  { SP_SCIENTIST, SCIENCE },
-  { SP_TAXMAN, GOLD }
-};
 
 /****************************************************************************
   Create lattice nodes for each type of specialist.  This adds a new
@@ -947,14 +935,15 @@
   /* for each specialist type, create a tile_type that has as production
    * the bonus for the specialist (if the city is allowed to use it) */
   specialist_type_iterate(i) {
-    if (city_can_use_specialist(pcity, pairs[i].spec)) {
-      type.spec = pairs[i].spec;
-      type.production[pairs[i].stat]
-        = game.rgame.specialists[pairs[i].spec].bonus;
+    if (city_can_use_specialist(pcity, i)) {
+      type.spec = i;
+      type.production[SCIENCE] = game.rgame.specialists[i].bonus_sci;
+      type.production[GOLD] = game.rgame.specialists[i].bonus_tax;
+      type.production[LUXURY] = game.rgame.specialists[i].bonus_lux;
 
       tile_type_lattice_add(lattice, &type, 0, 0);
 
-      type.production[pairs[i].stat] = 0;
+
     }
   } specialist_type_iterate_end;
 }
Index: data/default/cities.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/cities.ruleset,v
retrieving revision 1.11
diff -u -r1.11 cities.ruleset
--- data/default/cities.ruleset 9 Jun 2004 04:39:13 -0000       1.11
+++ data/default/cities.ruleset 22 Nov 2004 01:48:42 -0000
@@ -21,14 +21,13 @@
 ; the city is of a certain size.
 [specialist]
 
-; Changing the order or names of specialists will break things
 types = "elvis", "scientist", "taxman"
 elvis_min_size = 0
-elvis_base_bonus = 2
+elvis_bonus_lux = 2
 scientist_min_size = 5
-scientist_base_bonus = 3
+scientist_bonus_sci = 3
 taxman_min_size = 5
-taxman_base_bonus = 3
+taxman_bonus_tax = 3
 
 changable_tax = 1
 ;forced_science = 0
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.200
diff -u -r1.200 ruleset.c
--- server/ruleset.c    17 Nov 2004 19:21:14 -0000      1.200
+++ server/ruleset.c    22 Nov 2004 01:48:43 -0000
@@ -2558,9 +2558,13 @@
     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[i].bonus_sci
+      = secfile_lookup_int_default(file, 0, "specialist.%s_bonus_sci", name);
+    game.rgame.specialists[i].bonus_tax
+      = secfile_lookup_int_default(file, 0, "specialist.%s_bonus_tax", name);
+    game.rgame.specialists[i].bonus_lux
+      = secfile_lookup_int_default(file, 0, "specialist.%s_bonus_lux", name);
   }
   free(specialist_names);
 
@@ -3149,9 +3153,17 @@
   struct packet_ruleset_game misc_p;
 
   specialist_type_iterate(sp) {
+    int sci = game.rgame.specialists[sp].bonus_sci;
+    int tax = game.rgame.specialists[sp].bonus_tax;
+    int lux = game.rgame.specialists[sp].bonus_lux;
+
     sz_strlcpy(misc_p.specialist_name[sp], game.rgame.specialists[sp].name);
     misc_p.specialist_min_size[sp] = game.rgame.specialists[sp].min_size;
-    misc_p.specialist_bonus[sp] = game.rgame.specialists[sp].bonus;
+
+    misc_p.specialist_bonus_sci[sp] = sci;
+    misc_p.specialist_bonus_tax[sp] = tax;
+    misc_p.specialist_bonus_lux[sp] = lux;
+    misc_p.specialist_bonus[sp] = MAX(MAX(sci, tax), lux);
   } specialist_type_iterate_end;
   misc_p.changable_tax = game.rgame.changable_tax;
   misc_p.forced_science = game.rgame.forced_science;

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