Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#11270) rewrite output_before_penalty as an array
Home

[Freeciv-Dev] (PR#11270) rewrite output_before_penalty as an array

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11270) rewrite output_before_penalty as an array
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 30 Nov 2004 11:50:21 -0800
Reply-to: rt@xxxxxxxxxxx

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

This patch changes gov->output_before_penalty and 
gov->celeb_output_before_penalty to be an array, indexed by output type. 
  This is a straightforward cleanup; the goal is just to make future 
changes easier.

There are no network changes.  This means there's a little bit of extra 
code in the packet packing and unpacking.  Eventually the network 
packets should be changed to match (once we break network compatibility).

jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.428
diff -u -r1.428 packhand.c
--- client/packhand.c   30 Nov 2004 08:37:02 -0000      1.428
+++ client/packhand.c   30 Nov 2004 19:47:22 -0000
@@ -2414,13 +2414,19 @@
   gov->free_food           = p->free_food;
   gov->free_gold           = p->free_gold;
 
-  gov->trade_before_penalty   = p->trade_before_penalty;
-  gov->shields_before_penalty = p->shields_before_penalty;
-  gov->food_before_penalty    = p->food_before_penalty;
-
-  gov->celeb_trade_before_penalty   = p->celeb_trade_before_penalty;
-  gov->celeb_shields_before_penalty = p->celeb_shields_before_penalty;
-  gov->celeb_food_before_penalty    = p->celeb_food_before_penalty;
+  output_type_iterate(o) {
+    gov->output_before_penalty[o] = FC_INFINITY;
+    gov->celeb_output_before_penalty[o] = FC_INFINITY;
+  } output_type_iterate_end;
+
+  gov->output_before_penalty[O_TRADE] = p->trade_before_penalty;
+  gov->output_before_penalty[O_SHIELD] = p->shields_before_penalty;
+  gov->output_before_penalty[O_FOOD] = p->food_before_penalty;
+
+  gov->celeb_output_before_penalty[O_TRADE] = p->celeb_trade_before_penalty;
+  gov->celeb_output_before_penalty[O_SHIELD]
+    = p->celeb_shields_before_penalty;
+  gov->celeb_output_before_penalty[O_FOOD] = p->celeb_food_before_penalty;
 
   gov->trade_bonus         = p->trade_bonus;
   gov->shield_bonus        = p->shield_bonus;
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.263
diff -u -r1.263 city.c
--- common/city.c       30 Nov 2004 08:37:03 -0000      1.263
+++ common/city.c       30 Nov 2004 19:47:23 -0000
@@ -594,8 +594,9 @@
 
   if (pcity) {
     struct government *g = get_gov_pcity(pcity);
-    int before_penalty = (is_celebrating ? g->celeb_shields_before_penalty
-                         : g->shields_before_penalty);
+    int before_penalty = (is_celebrating
+                         ? g->celeb_output_before_penalty[O_SHIELD]
+                         : g->output_before_penalty[O_SHIELD]);
 
     s += get_city_tile_bonus(pcity, ptile, EFT_PROD_ADD_TILE);
 
@@ -697,8 +698,9 @@
    * Democracy/Republic [government in general now -- SKi] bonus  -AJS */
   if (pcity) {
     struct government *g = get_gov_pcity(pcity);
-    int before_penalty = (is_celebrating ? g->celeb_trade_before_penalty
-                         : g->trade_before_penalty);
+    int before_penalty = (is_celebrating
+                         ? g->celeb_output_before_penalty[O_TRADE]
+                         : g->output_before_penalty[O_TRADE]);
 
     t += get_city_tile_bonus(pcity, ptile, EFT_TRADE_ADD_TILE);
 
@@ -810,8 +812,9 @@
 
   if (pcity) {
     struct government *g = get_gov_pcity(pcity);
-    int before_penalty = (is_celebrating ? g->celeb_food_before_penalty
-                         : g->food_before_penalty);
+    int before_penalty = (is_celebrating
+                         ? g->celeb_output_before_penalty[O_FOOD]
+                         : g->output_before_penalty[O_FOOD]);
 
     f += get_city_tile_bonus(pcity, &tile, EFT_FOOD_ADD_TILE);
 
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.171
diff -u -r1.171 city.h
--- common/city.h       30 Nov 2004 08:37:03 -0000      1.171
+++ common/city.h       30 Nov 2004 19:47:23 -0000
@@ -32,12 +32,6 @@
   C_TILE_EMPTY, C_TILE_WORKER, C_TILE_UNAVAILABLE
 };
 
-enum output_type {
-  O_FOOD, O_SHIELD, O_TRADE, O_GOLD, O_LUXURY, O_SCIENCE, O_LAST
-};
-#define O_COUNT num_output_types
-#define O_MAX O_LAST
-
 enum city_options {
   /* The first 4 are whether to auto-attack versus each unit move_type
    * from with auto-attack units within this city.  Note that these
Index: common/fc_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/fc_types.h,v
retrieving revision 1.9
diff -u -r1.9 fc_types.h
--- common/fc_types.h   24 Nov 2004 03:34:57 -0000      1.9
+++ common/fc_types.h   30 Nov 2004 19:47:23 -0000
@@ -30,4 +30,10 @@
 struct tile;
 struct unit;
 
+enum output_type {
+  O_FOOD, O_SHIELD, O_TRADE, O_GOLD, O_LUXURY, O_SCIENCE, O_LAST
+};
+#define O_COUNT num_output_types
+#define O_MAX O_LAST
+
 #endif /* FC__FC_TYPES_H */
Index: common/government.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.h,v
retrieving revision 1.32
diff -u -r1.32 government.h
--- common/government.h 10 Nov 2004 17:01:59 -0000      1.32
+++ common/government.h 30 Nov 2004 19:47:23 -0000
@@ -107,15 +107,9 @@
   int   free_food;
   int   free_gold;
   
-  /* government production penalties -- SKi */
-  int   trade_before_penalty;
-  int   shields_before_penalty;
-  int   food_before_penalty;
-
-  /* government production penalties when celebrating */
-  int   celeb_trade_before_penalty;
-  int   celeb_shields_before_penalty;
-  int   celeb_food_before_penalty;
+  /* government production penalties (when celebrating and when not) */
+  int output_before_penalty[O_MAX];
+  int celeb_output_before_penalty[O_MAX];
 
   /* government production bonuses -- SKi */
   int   trade_bonus;
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.205
diff -u -r1.205 ruleset.c
--- server/ruleset.c    30 Nov 2004 06:54:07 -0000      1.205
+++ server/ruleset.c    30 Nov 2004 19:47:24 -0000
@@ -1862,19 +1862,16 @@
     g->celeb_food_bonus
       = secfile_lookup_int(file, "%s.production_food_bonus,1", sec[i]);
 
-    g->trade_before_penalty
-      = secfile_lookup_int(file, "%s.production_trade_penalty", sec[i]);
-    g->shields_before_penalty
-      = secfile_lookup_int(file, "%s.production_shield_penalty", sec[i]);
-    g->food_before_penalty
-      = secfile_lookup_int(file, "%s.production_food_penalty", sec[i]);
-
-    g->celeb_trade_before_penalty
-      = secfile_lookup_int(file, "%s.production_trade_penalty,1", sec[i]);
-    g->celeb_shields_before_penalty
-      = secfile_lookup_int(file, "%s.production_shield_penalty,1", sec[i]);
-    g->celeb_food_before_penalty
-      = secfile_lookup_int(file, "%s.production_food_penalty,1", sec[i]);
+    output_type_iterate(o) {
+      g->output_before_penalty[o]
+       = secfile_lookup_int_default(file, FC_INFINITY,
+                                    "%s.production_%s_penalty", sec[i],
+                                    get_output_identifier(o));
+      g->celeb_output_before_penalty[o]
+       = secfile_lookup_int_default(file, FC_INFINITY,
+                                    "%s.production_%s_penalty,1", sec[i],
+                                    get_output_identifier(o));
+    } output_type_iterate_end;
     
     g->helptext = lookup_helptext(file, sec[i]);
   } government_iterate_end;
@@ -3029,13 +3026,14 @@
     gov.free_food   = g->free_food;
     gov.free_gold   = g->free_gold;
 
-    gov.trade_before_penalty = g->trade_before_penalty;
-    gov.shields_before_penalty = g->shields_before_penalty;
-    gov.food_before_penalty = g->food_before_penalty;
-
-    gov.celeb_trade_before_penalty = g->celeb_trade_before_penalty;
-    gov.celeb_shields_before_penalty = g->celeb_shields_before_penalty;
-    gov.celeb_food_before_penalty = g->celeb_food_before_penalty;
+    gov.trade_before_penalty = g->output_before_penalty[O_TRADE];
+    gov.shields_before_penalty = g->output_before_penalty[O_SHIELD];
+    gov.food_before_penalty = g->output_before_penalty[O_FOOD];
+
+    gov.celeb_trade_before_penalty = g->celeb_output_before_penalty[O_TRADE];
+    gov.celeb_shields_before_penalty
+      = g->celeb_output_before_penalty[O_SHIELD];
+    gov.celeb_food_before_penalty = g->celeb_output_before_penalty[O_FOOD];
 
     gov.trade_bonus = g->trade_bonus;
     gov.shield_bonus = g->shield_bonus;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11270) rewrite output_before_penalty as an array, Jason Short <=