Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11346) put government upkeep values into an array
Home

[Freeciv-Dev] (PR#11346) put government upkeep values into an array

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11346) put government upkeep values into an array
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 5 Dec 2004 01:37:16 -0800
Reply-to: rt@xxxxxxxxxxx

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

This patch puts the government upkeep values (upkeep_cost and 
upkeep_factor, each for food, shields, and gold) into an array indexed 
by output type.

jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.435
diff -u -r1.435 packhand.c
--- client/packhand.c   5 Dec 2004 09:21:27 -0000       1.435
+++ client/packhand.c   5 Dec 2004 09:35:39 -0000
@@ -2405,16 +2405,12 @@
   gov->rapture_size      = p->rapture_size;
   
   gov->unit_happy_cost_factor  = p->unit_happy_cost_factor;
-  gov->unit_shield_cost_factor = p->unit_shield_cost_factor;
-  gov->unit_food_cost_factor   = p->unit_food_cost_factor;
-  gov->unit_gold_cost_factor   = p->unit_gold_cost_factor;
-  
   gov->free_happy          = p->free_happy;
-  gov->free_shield         = p->free_shield;
-  gov->free_food           = p->free_food;
-  gov->free_gold           = p->free_gold;
 
   output_type_iterate(o) {
+    gov->free_upkeep[o] = p->free_upkeep[o];
+    gov->unit_upkeep_factor[o] = p->unit_upkeep_factor[o];
+
     gov->output_before_penalty[o] = p->output_before_penalty[o];
     gov->celeb_output_before_penalty[o] = p->celeb_output_before_penalty[o];
     gov->output_inc_tile[o] = p->output_inc_tile[o];
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.201
diff -u -r1.201 capstr.c
--- common/capstr.c     5 Dec 2004 09:21:27 -0000       1.201
+++ common/capstr.c     5 Dec 2004 09:35:39 -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.Dec.5b"
+#define CAPABILITY "+Freeciv.Devel.2004.Dec.5c"
 
 void init_our_capability(void)
 {
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.270
diff -u -r1.270 city.c
--- common/city.c       5 Dec 2004 09:01:00 -0000       1.270
+++ common/city.c       5 Dec 2004 09:35:39 -0000
@@ -1214,10 +1214,10 @@
 **************************************************************************/
 int citygov_free_shield(const struct city *pcity, struct government *gov)
 {
-  if (gov->free_shield == G_CITY_SIZE_FREE) {
+  if (gov->free_upkeep[O_SHIELD] == G_CITY_SIZE_FREE) {
     return pcity->size;
   } else {
-    return gov->free_shield;
+    return gov->free_upkeep[O_SHIELD];
   }
 }
 
@@ -1238,10 +1238,10 @@
 **************************************************************************/
 int citygov_free_food(const struct city *pcity, struct government *gov)
 {
-  if (gov->free_food == G_CITY_SIZE_FREE) {
+  if (gov->free_upkeep[O_FOOD] == G_CITY_SIZE_FREE) {
     return pcity->size;
   } else {
-    return gov->free_food;
+    return gov->free_upkeep[O_FOOD];
   }
 }
 
@@ -1251,10 +1251,10 @@
 static int citygov_free_gold(const struct city *pcity, 
                              struct government *gov)
 {
-  if (gov->free_gold == G_CITY_SIZE_FREE) {
+  if (gov->free_upkeep[O_GOLD] == G_CITY_SIZE_FREE) {
     return pcity->size;
   } else {
-    return gov->free_gold;
+    return gov->free_upkeep[O_GOLD];
   }
 }
 
Index: common/government.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.h,v
retrieving revision 1.35
diff -u -r1.35 government.h
--- common/government.h 4 Dec 2004 10:09:29 -0000       1.35
+++ common/government.h 5 Dec 2004 09:35:39 -0000
@@ -96,16 +96,12 @@
                                   rapture is (practically) impossible */
 
   /* unit cost modifiers */
-  int   unit_happy_cost_factor;
-  int   unit_shield_cost_factor;
-  int   unit_food_cost_factor;
-  int   unit_gold_cost_factor;
+  int unit_happy_cost_factor;
+  int unit_upkeep_factor[O_MAX];
   
   /* base cost that a city does not have to "pay" for */
-  int   free_happy;
-  int   free_shield;
-  int   free_food;
-  int   free_gold;
+  int free_happy;
+  int free_upkeep[O_MAX];
   
   /* government production penalties (when celebrating and when not) */
   int output_before_penalty[O_MAX];
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.67
diff -u -r1.67 packets.def
--- common/packets.def  5 Dec 2004 09:21:27 -0000       1.67
+++ common/packets.def  5 Dec 2004 09:35:39 -0000
@@ -1029,14 +1029,10 @@
   UINT8 rapture_size;
       
   UINT8 unit_happy_cost_factor;
-  UINT8 unit_shield_cost_factor;
-  UINT8 unit_food_cost_factor;
-  UINT8 unit_gold_cost_factor;
+  UINT8 unit_upkeep_factor[O_MAX];
       
   UINT8 free_happy;
-  UINT8 free_shield;
-  UINT8 free_food;
-  UINT8 free_gold;
+  UINT8 free_upkeep[O_MAX];
 
   UINT8 output_before_penalty[O_MAX];
   UINT8 celeb_output_before_penalty[O_MAX];
Index: common/unittype.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.c,v
retrieving revision 1.43
diff -u -r1.43 unittype.c
--- common/unittype.c   5 Dec 2004 09:08:19 -0000       1.43
+++ common/unittype.c   5 Dec 2004 09:35:39 -0000
@@ -124,7 +124,7 @@
       BV_ISSET(ut->flags, F_FANATIC)) {
     return 0;
   }
-  return ut->upkeep[O_SHIELD] * g->unit_shield_cost_factor;
+  return ut->upkeep[O_SHIELD] * g->unit_upkeep_factor[O_SHIELD];
 }
 
 /**************************************************************************
@@ -132,7 +132,7 @@
 **************************************************************************/
 int utype_food_cost(struct unit_type *ut, struct government *g)
 {
-  return ut->upkeep[O_FOOD] * g->unit_food_cost_factor;
+  return ut->upkeep[O_FOOD] * g->unit_upkeep_factor[O_FOOD];
 }
 
 /**************************************************************************
@@ -148,7 +148,7 @@
 **************************************************************************/
 int utype_gold_cost(struct unit_type *ut, struct government *g)
 {
-  return ut->upkeep[O_GOLD] * g->unit_gold_cost_factor;
+  return ut->upkeep[O_GOLD] * g->unit_upkeep_factor[O_GOLD];
 }
 
 /**************************************************************************
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.212
diff -u -r1.212 ruleset.c
--- server/ruleset.c    5 Dec 2004 09:21:27 -0000       1.212
+++ server/ruleset.c    5 Dec 2004 09:35:40 -0000
@@ -429,12 +429,19 @@
   Lookup entry in the file and return the corresponding city cost:
   value if int, or G_CITY_SIZE_FREE is entry is "City_Size".
   Dies if gets some other string.  filename is for error message.
+
+  Returns 0 if no value is given in the ruleset.
 **************************************************************************/
 static int lookup_city_cost(struct section_file *file, const char *prefix,
                            const char *entry, const char *filename)
 {
   char *sval;
   int ival = 0;
+
+  if (!section_file_lookup(file, "%s.%s", prefix, entry)) {
+    /* Default to 0. */
+    return 0;
+  }
   
   sval = secfile_lookup_str_int(file, &ival, "%s.%s", prefix, entry);
   if (sval) {
@@ -1812,23 +1819,21 @@
     
     g->free_happy
       = lookup_city_cost(file, sec[i], "unit_free_unhappy", filename);
-    g->free_shield
-      = lookup_city_cost(file, sec[i], "unit_free_shield", filename);
-    g->free_food
-      = lookup_city_cost(file, sec[i], "unit_free_food", filename);
-    g->free_gold
-      = lookup_city_cost(file, sec[i], "unit_free_gold", filename);
 
     g->unit_happy_cost_factor
       = secfile_lookup_int(file, "%s.unit_unhappy_factor", sec[i]);
-    g->unit_shield_cost_factor
-      = secfile_lookup_int(file, "%s.unit_shield_factor", sec[i]);
-    g->unit_food_cost_factor
-      = secfile_lookup_int(file, "%s.unit_food_factor", sec[i]);
-    g->unit_gold_cost_factor
-      = secfile_lookup_int(file, "%s.unit_gold_factor", sec[i]);
 
     output_type_iterate(o) {
+      char buf[128];
+
+      my_snprintf(buf, sizeof(buf), "unit_free_%s",
+                 get_output_identifier(o));
+      g->free_upkeep[o] = lookup_city_cost(file, sec[i], buf, filename);
+
+      g->unit_upkeep_factor[o]
+       = secfile_lookup_int_default(file, 0, "%s.unit_%s_factor", sec[i],
+                                    get_output_identifier(o));
+
       if (waste_name[o]) {
        g->waste[o].level = secfile_lookup_int(file, "%s.%s_level",
                                               sec[i], waste_name[o]);
@@ -3006,23 +3011,17 @@
     gov.rapture_size     = g->rapture_size;
     
     gov.unit_happy_cost_factor  = g->unit_happy_cost_factor;
-    gov.unit_shield_cost_factor = g->unit_shield_cost_factor;
-    gov.unit_food_cost_factor   = g->unit_food_cost_factor;
-    gov.unit_gold_cost_factor   = g->unit_gold_cost_factor;
-    
     gov.free_happy  = g->free_happy;
-    gov.free_shield = g->free_shield;
-    gov.free_food   = g->free_food;
-    gov.free_gold   = g->free_gold;
 
     output_type_iterate(o) {
+      gov.free_upkeep[o] = g->free_upkeep[o];
+      gov.unit_upkeep_factor[o] = g->unit_upkeep_factor[o];
+
       gov.output_before_penalty[o] = g->output_before_penalty[o];
       gov.celeb_output_before_penalty[o] = g->celeb_output_before_penalty[o];
       gov.output_inc_tile[o] = g->output_inc_tile[o];
       gov.celeb_output_inc_tile[o] = g->celeb_output_inc_tile[o];
-    } output_type_iterate_end;
 
-    output_type_iterate(o) {
       gov.waste_level[o] = g->waste[o].level;
       gov.fixed_waste_distance[o] = g->waste[o].fixed_distance;
       gov.waste_distance_factor[o] = g->waste[o].distance_factor;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11346) put government upkeep values into an array, Jason Short <=