Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11710) city output effect values
Home

[Freeciv-Dev] (PR#11710) city output effect values

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11710) city output effect values
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 27 Dec 2004 12:51:20 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11710 >

This patch takes the city output effect values - currently in an array - 
and puts them into a switch in a separate function.

The advantage of putting them in a switch is that if we change the 
output types (O_POLLUTION) we'll get a compiler warning/error.  It 
encapsulates the ugliness of this conversion.

The same should be done with the ADD_TILE, INC_TILE, and PER_TILE effects.

-jason

? gmon.out
? new
? orig
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.295
diff -u -r1.295 city.c
--- common/city.c       25 Dec 2004 20:13:05 -0000      1.295
+++ common/city.c       27 Dec 2004 20:37:17 -0000
@@ -262,6 +262,54 @@
 }
 
 /**************************************************************************
+  Return the effect for the production bonus for this output type.
+**************************************************************************/
+static inline enum effect_type get_output_bonus_effect(Output_type_id otype)
+{
+  switch (otype) {
+  case O_SHIELD:
+    return EFT_PROD_BONUS;
+  case O_GOLD:
+    return EFT_TAX_BONUS;
+  case O_LUXURY:
+    return EFT_LUXURY_BONUS;
+  case O_SCIENCE:
+    return EFT_SCIENCE_BONUS;
+  case O_FOOD:
+  case O_TRADE:
+    return EFT_LAST;
+  case O_LAST:
+    break;
+  }
+
+  assert(0);
+  return EFT_LAST;
+}
+
+/**************************************************************************
+  Return the effect for waste reduction for this output type.
+**************************************************************************/
+static inline enum effect_type get_output_waste_effect(Output_type_id otype)
+{
+  switch (otype) {
+  case O_SHIELD:
+    return EFT_WASTE_PCT;
+  case O_TRADE:
+    return EFT_CORRUPT_PCT;
+  case O_FOOD:
+  case O_GOLD:
+  case O_LUXURY:
+  case O_SCIENCE:
+    return EFT_LAST;
+  case O_LAST:
+    break;
+  }
+
+  assert(0);
+  return EFT_LAST;
+}
+
+/**************************************************************************
   Set the worker on the citymap.  Also sets the worked field in the map.
 **************************************************************************/
 void set_worker_city(struct city *pcity, int city_x, int city_y,
@@ -1598,13 +1646,11 @@
 **************************************************************************/
 int get_city_output_bonus(const struct city *pcity, Output_type_id otype)
 {
-  enum effect_type eft[] = {EFT_LAST, EFT_PROD_BONUS, EFT_LAST,
-                           EFT_TAX_BONUS, EFT_LUXURY_BONUS,
-                           EFT_SCIENCE_BONUS};
+  enum effect_type eft = get_output_bonus_effect(otype);
   int bonus = 100;
 
-  if (eft[otype] != EFT_LAST) {
-    bonus += get_city_bonus(pcity, eft[otype]);
+  if (eft != EFT_LAST) {
+    bonus += get_city_bonus(pcity, eft);
   }
 
   if (otype == O_SCIENCE
@@ -2246,8 +2292,7 @@
   unsigned int val;
   int penalty = 0;
   struct gov_waste *waste = &g->waste[otype];
-  enum effect_type eft[] = {EFT_LAST, EFT_WASTE_PCT, EFT_CORRUPT_PCT,
-                           EFT_LAST, EFT_LAST, EFT_LAST};
+  enum effect_type eft = get_output_waste_effect(otype);
 
   if (otype == O_TRADE) {
     /* FIXME: special case for trade: it is affected by notradesize and
@@ -2284,8 +2329,8 @@
   /* Now calculate the final waste.  Ordered to reduce integer
    * roundoff errors. */
   val = total * MAX(dist, 1) * waste->level;
-  if (eft[otype] != EFT_LAST) {
-    val -= (val * get_city_bonus(pcity, eft[otype])) / 100;
+  if (eft != EFT_LAST) {
+    val -= (val * get_city_bonus(pcity, eft)) / 100;
   }
   val /= 100 * 100; /* Level is a % multiplied by 100 */
   val = CLIP(penalty, val, total);

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