Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11737) new function base_city_get_output_tile
Home

[Freeciv-Dev] (PR#11737) new function base_city_get_output_tile

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11737) new function base_city_get_output_tile
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 30 Dec 2004 14:13:49 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch merges base_city_get_food_tile, base_city_get_shields_tile, 
and base_city_get_trade_tile into a single function 
base_city_get_output_tile.

The merge itself is quite straightforward.  Some of the callers have 
been simplified however to use an output_type_iterate.

-jason

? gmon.out
Index: ai/aisettler.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aisettler.c,v
retrieving revision 1.14
diff -u -r1.14 aisettler.c
--- ai/aisettler.c      9 Dec 2004 21:27:48 -0000       1.14
+++ ai/aisettler.c      30 Dec 2004 22:10:02 -0000
@@ -150,13 +150,16 @@
       /* We cannot read city center from cache */
 
       /* Food */
-      result->citymap[i][j].food = base_city_get_food_tile(i, j, pcity, FALSE);
+      result->citymap[i][j].food
+       = base_city_get_output_tile(i, j, pcity, FALSE, O_FOOD);
 
       /* Shields */
-      result->citymap[i][j].shield =base_city_get_shields_tile(i, j, pcity, 
FALSE);
+      result->citymap[i][j].shield
+       = base_city_get_output_tile(i, j, pcity, FALSE, O_SHIELD);
 
       /* Trade */
-      result->citymap[i][j].trade = base_city_get_trade_tile(i, j, pcity, 
FALSE);
+      result->citymap[i][j].trade
+       = base_city_get_output_tile(i, j, pcity, FALSE, O_TRADE);
 
       sum = result->citymap[i][j].food * ai->food_priority
             + result->citymap[i][j].trade * ai->science_priority
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.298
diff -u -r1.298 city.c
--- common/city.c       30 Dec 2004 21:56:35 -0000      1.298
+++ common/city.c       30 Dec 2004 22:10:04 -0000
@@ -823,8 +823,8 @@
 **************************************************************************/
 int city_get_shields_tile(int city_x, int city_y, const struct city *pcity)
 {
-  return base_city_get_shields_tile(city_x, city_y, pcity,
-                                   city_celebrating(pcity));
+  return base_city_get_output_tile(city_x, city_y, pcity,
+                                  city_celebrating(pcity), O_SHIELD);
 }
 
 /**************************************************************************
@@ -833,9 +833,9 @@
 
   This can be used to calculate the benefits celebration would give.
 **************************************************************************/
-int base_city_get_shields_tile(int city_x, int city_y,
-                              const struct city *pcity,
-                              bool is_celebrating)
+int base_city_get_output_tile(int city_x, int city_y,
+                             const struct city *pcity, bool is_celebrating,
+                             Output_type_id otype)
 {
   struct tile *ptile;
 
@@ -845,7 +845,7 @@
   }
 
   return base_get_output_tile(ptile, pcity,
-                             city_x, city_y, is_celebrating, O_SHIELD);
+                             city_x, city_y, is_celebrating, otype);
 }
 /**************************************************************************
   Calculate the trade the given tile is capable of producing for the
@@ -853,28 +853,8 @@
 **************************************************************************/
 int city_get_trade_tile(int city_x, int city_y, const struct city *pcity)
 {
-  return base_city_get_trade_tile(city_x, city_y,
-                                 pcity, city_celebrating(pcity));
-}
-
-/**************************************************************************
-  Calculate the trade the given tile would be capable of producing for
-  the city if the city's celebration status were as given.
-
-  This can be used to calculate the benefits celebration would give.
-**************************************************************************/
-int base_city_get_trade_tile(int city_x, int city_y,
-                            const struct city *pcity, bool is_celebrating)
-{
-  struct tile *ptile;
-
-  if (!(ptile = city_map_to_map(pcity, city_x, city_y))) {
-    assert(0);
-    return 0;
-  }
-
-  return base_get_output_tile(ptile, pcity, city_x, city_y, is_celebrating,
-                             O_TRADE);
+  return base_city_get_output_tile(city_x, city_y,
+                                  pcity, city_celebrating(pcity), O_TRADE);
 }
 
 /**************************************************************************
@@ -883,28 +863,8 @@
 **************************************************************************/
 int city_get_food_tile(int city_x, int city_y, const struct city *pcity)
 {
-  return base_city_get_food_tile(city_x, city_y, pcity,
-                                city_celebrating(pcity));
-}
-
-/**************************************************************************
-  Calculate the food the given tile would be capable of producing for
-  the city if the city's celebration status were as given.
-
-  This can be used to calculate the benefits celebration would give.
-**************************************************************************/
-int base_city_get_food_tile(int city_x, int city_y, const struct city *pcity,
-                           bool is_celebrating)
-{
-  struct tile *ptile;
-
-  if (!(ptile = city_map_to_map(pcity, city_x, city_y))) {
-    assert(0);
-    return 0;
-  }
-
-  return base_get_output_tile(ptile, pcity, city_x, city_y, is_celebrating,
-                             O_FOOD);
+  return base_city_get_output_tile(city_x, city_y, pcity,
+                                  city_celebrating(pcity), O_FOOD);
 }
 
 /**************************************************************************
@@ -1704,11 +1664,10 @@
   
   city_map_iterate(x, y) {
     if (get_worker_city(pcity, x, y) == C_TILE_WORKER) {
-      output[O_FOOD] += base_city_get_food_tile(x, y, pcity, is_celebrating);
-      output[O_SHIELD] += base_city_get_shields_tile(x, y, pcity,
-                                                    is_celebrating);
-      output[O_TRADE] += base_city_get_trade_tile(x, y, pcity,
-                                                 is_celebrating);
+      output_type_iterate(o) {
+       output[o] += base_city_get_output_tile(x, y, pcity,
+                                              is_celebrating, o);
+      } output_type_iterate_end;
     }
   } city_map_iterate_end;
 }
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.189
diff -u -r1.189 city.h
--- common/city.h       30 Dec 2004 21:45:25 -0000      1.189
+++ common/city.h       30 Dec 2004 22:10:04 -0000
@@ -404,8 +404,6 @@
 
 const char *get_impr_name_ex(const struct city *pcity, Impr_Type_id id);
 
-int get_output_tile(const struct tile *ptile, Output_type_id otype);
-
 /* city map functions */
 
 bool is_valid_city_coords(const int city_x, const int city_y);
@@ -422,18 +420,14 @@
 int compare_iter_index(const void *a, const void *b);
 void generate_city_map_indices(void);
 
-/* shield on spot */
+/* output on spot */
+int get_output_tile(const struct tile *ptile, Output_type_id otype);
 int city_get_shields_tile(int city_x, int city_y, const struct city *pcity);
-int base_city_get_shields_tile(int city_x, int city_y,
-                              const struct city *pcity, bool is_celebrating);
-/* trade  on spot */
 int city_get_trade_tile(int city_x, int city_y, const struct city *pcity);
-int base_city_get_trade_tile(int city_x, int city_y,
-                            const struct city *pcity, bool is_celebrating);
-/* food   on spot */
 int city_get_food_tile(int city_x, int city_y, const struct city *pcity);
-int base_city_get_food_tile(int city_x, int city_y,
-                           const struct city *pcity, bool is_celebrating);
+int base_city_get_output_tile(int city_x, int city_y,
+                             const struct city *pcity, bool is_celebrating,
+                             Output_type_id otype);
 
 void set_worker_city(struct city *pcity, int city_x, int city_y,
                     enum city_tile_type type); 
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.55
diff -u -r1.55 cm.c
--- common/aicore/cm.c  15 Dec 2004 00:15:12 -0000      1.55
+++ common/aicore/cm.c  30 Dec 2004 22:10:04 -0000
@@ -847,14 +847,10 @@
 {
   bool is_celebrating = base_city_celebrating(pcity);
 
-  out->production[O_FOOD]
-    = base_city_get_food_tile(x, y, pcity, is_celebrating);
-  out->production[O_SHIELD]
-    = base_city_get_shields_tile(x, y, pcity, is_celebrating);
-  out->production[O_TRADE]
-    = base_city_get_trade_tile(x, y, pcity, is_celebrating);
-  out->production[O_GOLD] = out->production[O_SCIENCE]
-    = out->production[O_LUXURY] = 0;
+  output_type_iterate(o) {
+    out->production[o] = base_city_get_output_tile(x, y, pcity,
+                                                  is_celebrating, o);
+  } output_type_iterate_end;
 }
 
 /****************************************************************************
@@ -1536,7 +1532,7 @@
   }
   state->min_production[O_FOOD] = usage[O_FOOD]
     + state->parameter.minimal_surplus[O_FOOD]
-    - base_city_get_food_tile(x, y, pcity, is_celebrating);
+    - base_city_get_output_tile(x, y, pcity, is_celebrating, O_FOOD);
 
   /* surplus = (factories-waste) * production - shield_usage, so:
    *   production = (surplus + shield_usage)/(factories-waste)
@@ -1561,7 +1557,7 @@
       = ((usage[O_SHIELD] + state->parameter.minimal_surplus[O_SHIELD])
         / sbonus);
     state->min_production[O_SHIELD]
-      -= base_city_get_shields_tile(x, y, pcity, is_celebrating);
+      -= base_city_get_output_tile(x, y, pcity, is_celebrating, O_SHIELD);
   } else {
     /* Dunno what the usage is, so it's pointless to set the
      * min_production */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11737) new function base_city_get_output_tile, Jason Short <=