Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11305) government waste values in an array
Home

[Freeciv-Dev] (PR#11305) government waste values in an array

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11305) government waste values in an array
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 2 Dec 2004 11:04:56 -0800
Reply-to: rt@xxxxxxxxxxx

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

This patch takes the gov->corruption_xxx and gov->waste_xxx values and 
puts them into an array, gov->waste[].xxx.  This standardizes the names, 
making future extensions easier.  It's almost all just search-and-replace.

-jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.429
diff -u -r1.429 packhand.c
--- client/packhand.c   2 Dec 2004 10:14:53 -0000       1.429
+++ client/packhand.c   2 Dec 2004 19:02:47 -0000
@@ -2436,17 +2436,17 @@
   gov->celeb_shield_bonus  = p->celeb_shield_bonus;
   gov->celeb_food_bonus    = p->celeb_food_bonus;
 
-  gov->corruption_level    = p->corruption_level;
-  gov->fixed_corruption_distance = p->fixed_corruption_distance;
-  gov->corruption_distance_factor = p->corruption_distance_factor;
-  gov->extra_corruption_distance = p->extra_corruption_distance;
-  gov->corruption_max_distance_cap = p->corruption_max_distance_cap;
+  gov->waste[O_TRADE].level = p->corruption_level;
+  gov->waste[O_TRADE].fixed_distance = p->fixed_corruption_distance;
+  gov->waste[O_TRADE].distance_factor = p->corruption_distance_factor;
+  gov->waste[O_TRADE].extra_distance = p->extra_corruption_distance;
+  gov->waste[O_TRADE].max_distance_cap = p->corruption_max_distance_cap;
   
-  gov->waste_level           = p->waste_level;
-  gov->fixed_waste_distance  = p->fixed_waste_distance;
-  gov->waste_distance_factor = p->waste_distance_factor;
-  gov->extra_waste_distance  = p->extra_waste_distance;
-  gov->waste_max_distance_cap = p->waste_max_distance_cap;
+  gov->waste[O_SHIELD].level = p->waste_level;
+  gov->waste[O_SHIELD].fixed_distance = p->fixed_waste_distance;
+  gov->waste[O_SHIELD].distance_factor = p->waste_distance_factor;
+  gov->waste[O_SHIELD].extra_distance = p->extra_waste_distance;
+  gov->waste[O_SHIELD].max_distance_cap = p->waste_max_distance_cap;
   
   gov->flags               = p->flags;
   gov->num_ruler_titles    = p->num_ruler_titles;
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.265
diff -u -r1.265 city.c
--- common/city.c       2 Dec 2004 10:20:30 -0000       1.265
+++ common/city.c       2 Dec 2004 19:02:47 -0000
@@ -2239,6 +2239,7 @@
   int dist;
   unsigned int val;
   int trade_penalty;
+  struct gov_waste *corruption = &g->waste[O_TRADE];
 
   assert(game.notradesize < game.fulltradesize);
   if (pcity->size <= game.notradesize) {
@@ -2250,26 +2251,25 @@
        (game.fulltradesize - game.notradesize);
   }
 
-  if (g->corruption_level == 0) {
+  if (corruption->level == 0) {
     return trade_penalty;
   }
-  if (g->fixed_corruption_distance != 0) {
-    dist = g->fixed_corruption_distance;
+  if (corruption->fixed_distance != 0) {
+    dist = corruption->fixed_distance;
   } else {
     capital = find_palace(city_owner(pcity));
     if (!capital)
-      dist = g->corruption_max_distance_cap;
+      dist = corruption->max_distance_cap;
     else {
       int tmp = real_map_distance(capital->tile, pcity->tile);
-      dist = MIN(g->corruption_max_distance_cap, tmp);
+      dist = MIN(corruption->max_distance_cap, tmp);
     }
   }
-  dist =
-      dist * g->corruption_distance_factor + g->extra_corruption_distance;
+  dist = dist * corruption->distance_factor + corruption->extra_distance;
 
   /* Now calculate the final corruption.  Ordered to reduce integer
    * roundoff errors. */
-  val = trade * MAX(dist, 1) * g->corruption_level;
+  val = trade * MAX(dist, 1) * corruption->level;
   val -= (val * get_city_bonus(pcity, EFT_CORRUPT_PCT)) / 100;
   val /= 100 * 100; /* Level is a % multiplied by 100 */
   val = CLIP(trade_penalty, val, trade);
@@ -2286,24 +2286,25 @@
   int dist;
   int shield_penalty = 0;
   unsigned int val;
+  struct gov_waste *waste = &g->waste[O_SHIELD];
 
-  if (g->waste_level == 0) {
+  if (waste->level == 0) {
     return shield_penalty;
   }
-  if (g->fixed_waste_distance != 0) {
-    dist = g->fixed_waste_distance;
+  if (waste->fixed_distance != 0) {
+    dist = waste->fixed_distance;
   } else {
     capital = find_palace(city_owner(pcity));
     if (!capital) {
-      dist = g->waste_max_distance_cap;
+      dist = waste->max_distance_cap;
     } else {
       int tmp = real_map_distance(capital->tile, pcity->tile);
-      dist = MIN(g->waste_max_distance_cap, tmp);
+      dist = MIN(waste->max_distance_cap, tmp);
     }
   }
-  dist = dist * g->waste_distance_factor + g->extra_waste_distance;
+  dist = dist * waste->distance_factor + waste->extra_distance;
   /* Ordered to reduce integer roundoff errors */
-  val = shields * MAX(dist, 1) * g->waste_level;
+  val = shields * MAX(dist, 1) * waste->level;
   val /= 100 * 100; /* Level is a % multiplied by 100 */
 
   val -= (val * get_city_bonus(pcity, EFT_WASTE_PCT)) / 100;
Index: common/government.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.h,v
retrieving revision 1.33
diff -u -r1.33 government.h
--- common/government.h 2 Dec 2004 10:14:53 -0000       1.33
+++ common/government.h 2 Dec 2004 19:02:47 -0000
@@ -121,22 +121,16 @@
   int   celeb_shield_bonus;
   int   celeb_food_bonus;
 
-  /* corruption modifiers -- SKi */
-  int   corruption_level;
-  int   corruption_modifier;
-  int   fixed_corruption_distance;
-  int   corruption_distance_factor;
-  int   extra_corruption_distance;
-  int   corruption_max_distance_cap;
-  
-  /* waste modifiers, see governments.ruleset for more detail */
-  int   waste_level;
-  int   waste_modifier;
-  int   fixed_waste_distance;
-  int   waste_distance_factor;
-  int   extra_waste_distance;
-  int   waste_max_distance_cap;
-    
+  /* waste/corruption modifiers - see governments.ruleset for more detail */
+  struct gov_waste {
+    int level;
+    int modifier;
+    int fixed_distance;
+    int distance_factor;
+    int extra_distance;
+    int max_distance_cap;
+  } waste[O_MAX];
+
   /* other flags: bits in enum government_flag_id order,
      use government_has_flag() to access */
   int   flags;
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.276
diff -u -r1.276 cityturn.c
--- server/cityturn.c   30 Nov 2004 08:37:03 -0000      1.276
+++ server/cityturn.c   2 Dec 2004 19:02:48 -0000
@@ -1237,8 +1237,8 @@
     dist = 32;
   }
   dist -= (dist * get_city_bonus(pcity, EFT_INCITE_DIST_PCT)) / 100;
-  if (g->fixed_corruption_distance != 0) {
-    dist = MIN(g->fixed_corruption_distance, dist);
+  if (g->waste[O_TRADE].fixed_distance != 0) {
+    dist = MIN(g->waste[O_TRADE].fixed_distance, dist);
   }
 
   size = MAX(1, pcity->size
Index: server/diplomats.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplomats.c,v
retrieving revision 1.63
diff -u -r1.63 diplomats.c
--- server/diplomats.c  19 Nov 2004 02:30:42 -0000      1.63
+++ server/diplomats.c  2 Dec 2004 19:02:48 -0000
@@ -1427,8 +1427,8 @@
   }
   else
     dist=32;
-  if (g->fixed_corruption_distance != 0)
-    dist = MIN(g->fixed_corruption_distance, dist);
+  if (g->waste[O_TRADE].fixed_distance != 0)
+    dist = MIN(g->waste[O_TRADE].fixed_distance, dist);
   cost /= dist + 2;
 
   cost *= unit_build_shield_cost(punit->type) / 10;
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.206
diff -u -r1.206 ruleset.c
--- server/ruleset.c    2 Dec 2004 10:14:54 -0000       1.206
+++ server/ruleset.c    2 Dec 2004 19:02:48 -0000
@@ -1789,6 +1789,8 @@
   /* easy ones: */
   government_iterate(g) {
     int i = g->index;
+    const char *waste_name[] = {NULL, "waste", "corruption",
+                               NULL, NULL, NULL};
     
     g->required_tech
       = lookup_tech(file, sec[i], "tech_req", FALSE, filename, g->name);
@@ -1825,28 +1827,26 @@
     g->unit_gold_cost_factor
       = secfile_lookup_int(file, "%s.unit_gold_factor", sec[i]);
 
-    g->corruption_level
-      = secfile_lookup_int(file, "%s.corruption_level", sec[i]);
-    g->fixed_corruption_distance
-      = secfile_lookup_int(file, "%s.corruption_fixed_distance", sec[i]);
-    g->corruption_distance_factor
-      = secfile_lookup_int(file, "%s.corruption_distance_factor", sec[i]);
-    g->extra_corruption_distance
-      = secfile_lookup_int(file, "%s.corruption_extra_distance", sec[i]);
-    g->corruption_max_distance_cap
-      = secfile_lookup_int_default(file, 36, 
-        "%s.corruption_max_distance_cap", sec[i]); 
-
-    g->waste_level
-      = secfile_lookup_int(file, "%s.waste_level", sec[i]);
-    g->fixed_waste_distance
-      = secfile_lookup_int(file, "%s.waste_fixed_distance", sec[i]);
-    g->waste_distance_factor
-      = secfile_lookup_int(file, "%s.waste_distance_factor", sec[i]);
-    g->extra_waste_distance
-      = secfile_lookup_int(file, "%s.waste_extra_distance", sec[i]);
-    g->waste_max_distance_cap
-      = secfile_lookup_int_default(file, 36, "%s.waste_max_distance_cap", 
sec[i]); 
+    output_type_iterate(o) {
+      if (waste_name[o]) {
+       g->waste[o].level = secfile_lookup_int(file, "%s.%s_level",
+                                              sec[i], waste_name[o]);
+       g->waste[o].fixed_distance
+         = secfile_lookup_int(file, "%s.%s_fixed_distance",
+                              sec[i], waste_name[o]);
+       g->waste[o].distance_factor
+         = secfile_lookup_int(file, "%s.%s_distance_factor",
+                              sec[i], waste_name[o]);
+       g->waste[o].extra_distance
+         = secfile_lookup_int(file, "%s.%s_extra_distance",
+                              sec[i], waste_name[o]);
+       g->waste[o].max_distance_cap
+         = secfile_lookup_int_default(file, 36, "%s.%s_max_distance_cap",
+                                      sec[i], waste_name[o]); 
+      } else {
+       memset(&g->waste[o], 0, sizeof(g->waste[o]));
+      }
+    } output_type_iterate_end;
 
     g->trade_bonus
       = secfile_lookup_int(file, "%s.production_trade_bonus", sec[i]);
@@ -3043,17 +3043,17 @@
     gov.celeb_shield_bonus = g->celeb_shield_bonus;
     gov.celeb_food_bonus = g->celeb_food_bonus;
 
-    gov.corruption_level = g->corruption_level;
-    gov.fixed_corruption_distance = g->fixed_corruption_distance;
-    gov.corruption_distance_factor = g->corruption_distance_factor;
-    gov.extra_corruption_distance = g->extra_corruption_distance;
-    gov.corruption_max_distance_cap = g->corruption_max_distance_cap;
+    gov.corruption_level = g->waste[O_TRADE].level;
+    gov.fixed_corruption_distance = g->waste[O_TRADE].fixed_distance;
+    gov.corruption_distance_factor = g->waste[O_TRADE].distance_factor;
+    gov.extra_corruption_distance = g->waste[O_TRADE].extra_distance;
+    gov.corruption_max_distance_cap = g->waste[O_TRADE].max_distance_cap;
     
-    gov.waste_level = g->waste_level;
-    gov.fixed_waste_distance = g->fixed_waste_distance;
-    gov.waste_distance_factor = g->waste_distance_factor;
-    gov.extra_waste_distance = g->extra_waste_distance;
-    gov.waste_max_distance_cap = g->waste_max_distance_cap;
+    gov.waste_level = g->waste[O_SHIELD].level;
+    gov.fixed_waste_distance = g->waste[O_SHIELD].fixed_distance;
+    gov.waste_distance_factor = g->waste[O_SHIELD].distance_factor;
+    gov.extra_waste_distance = g->waste[O_SHIELD].extra_distance;
+    gov.waste_max_distance_cap = g->waste[O_SHIELD].max_distance_cap;
         
     gov.flags = g->flags;
     gov.num_ruler_titles = g->num_ruler_titles;

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