Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2005:
[Freeciv-Dev] (PR#11761) new function city_get_output_tile
Home

[Freeciv-Dev] (PR#11761) new function city_get_output_tile

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11761) new function city_get_output_tile
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 1 Jan 2005 15:19:58 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch merges city_get_food_tile, city_get_shields_tile, and 
city_get_trade_tile into a single function city_get_output_tile.  It's 
rather straightforward.

(Not to be confused with the previous patch that created 
BASE_city_get_output_tile.)

-jason

? gmon.out
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.168
diff -u -r1.168 mapview_common.c
--- client/mapview_common.c     25 Dec 2004 20:38:14 -0000      1.168
+++ client/mapview_common.c     1 Jan 2005 23:18:35 -0000
@@ -935,9 +935,9 @@
                          struct canvas *pcanvas,
                          int canvas_x, int canvas_y)
 {
-  int food = city_get_food_tile(city_x, city_y, pcity);
-  int shields = city_get_shields_tile(city_x, city_y, pcity);
-  int trade = city_get_trade_tile(city_x, city_y, pcity);
+  int food = city_get_output_tile(city_x, city_y, pcity, O_FOOD);
+  int shields = city_get_output_tile(city_x, city_y, pcity, O_SHIELD);
+  int trade = city_get_output_tile(city_x, city_y, pcity, O_TRADE);
 
   food = CLIP(0, food, NUM_TILES_DIGITS - 1);
   shields = CLIP(0, shields, NUM_TILES_DIGITS - 1);
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.299
diff -u -r1.299 city.c
--- common/city.c       1 Jan 2005 22:47:14 -0000       1.299
+++ common/city.c       1 Jan 2005 23:18:35 -0000
@@ -818,13 +818,15 @@
 }
 
 /**************************************************************************
-  Calculate the shields the given tile is capable of producing for the
-  city.
+  Calculate the production output the given tile is capable of producing
+  for the city.  The output type is given by 'otype' (generally O_FOOD,
+  O_SHIELD, or O_TRADE).
 **************************************************************************/
-int city_get_shields_tile(int city_x, int city_y, const struct city *pcity)
+int city_get_output_tile(int city_x, int city_y, const struct city *pcity,
+                        Output_type_id otype)
 {
   return base_city_get_output_tile(city_x, city_y, pcity,
-                                  city_celebrating(pcity), O_SHIELD);
+                                  city_celebrating(pcity), otype);
 }
 
 /**************************************************************************
@@ -847,25 +849,6 @@
   return base_get_output_tile(ptile, pcity,
                              city_x, city_y, is_celebrating, otype);
 }
-/**************************************************************************
-  Calculate the trade the given tile is capable of producing for the
-  city.
-**************************************************************************/
-int city_get_trade_tile(int city_x, int city_y, const struct city *pcity)
-{
-  return base_city_get_output_tile(city_x, city_y,
-                                  pcity, city_celebrating(pcity), O_TRADE);
-}
-
-/**************************************************************************
-  Calculate the food the given tile is capable of producing for the
-  city.
-**************************************************************************/
-int city_get_food_tile(int city_x, int city_y, const struct city *pcity)
-{
-  return base_city_get_output_tile(city_x, city_y, pcity,
-                                  city_celebrating(pcity), O_FOOD);
-}
 
 /**************************************************************************
   Returns TRUE if the given unit can build a city at the given map
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.190
diff -u -r1.190 city.h
--- common/city.h       1 Jan 2005 22:47:14 -0000       1.190
+++ common/city.h       1 Jan 2005 23:18:35 -0000
@@ -422,9 +422,8 @@
 
 /* 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 city_get_trade_tile(int city_x, int city_y, const struct city *pcity);
-int city_get_food_tile(int city_x, int city_y, const struct city *pcity);
+int city_get_output_tile(int city_x, int city_y, const struct city *pcity,
+                        Output_type_id otype);
 int base_city_get_output_tile(int city_x, int city_y,
                              const struct city *pcity, bool is_celebrating,
                              Output_type_id otype);
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.216
diff -u -r1.216 settlers.c
--- server/settlers.c   19 Dec 2004 19:44:40 -0000      1.216
+++ server/settlers.c   1 Jan 2005 23:18:36 -0000
@@ -233,26 +233,28 @@
 
   plr = city_owner(pcity);
 
-  food_value = city_get_food_tile(x, y, pcity);
+  food_value = city_get_output_tile(x, y, pcity, O_FOOD);
   if (foodneed > 0) {
     food_value += 9 * MIN(food_value, foodneed);
   }
   food_value *= food_weighting(MAX(2, pcity->size));
   
-  shield_value = city_get_shields_tile(x, y, pcity);
+  shield_value = city_get_output_tile(x, y, pcity, O_SHIELD);
   if (prodneed > 0) {
     shield_value += 9 * (MIN(shield_value, prodneed));
   }
   shield_value *= SHIELD_WEIGHTING * pcity->bonus[O_SHIELD];
   shield_value /= 100;
 
-  trade_value = (city_get_trade_tile(x, y, pcity) * pcity->ai.trade_want
-       * (pcity->bonus[O_GOLD] * plr->economic.tax
-         + pcity->bonus[O_LUXURY] * plr->economic.luxury
-         + pcity->bonus[O_SCIENCE] * plr->economic.science)) / 10000;
+  trade_value = city_get_output_tile(x, y, pcity, O_TRADE);
+  trade_value *= pcity->ai.trade_want;
+  trade_value *= (pcity->bonus[O_GOLD] * plr->economic.tax
+                 + pcity->bonus[O_LUXURY] * plr->economic.luxury
+                 + pcity->bonus[O_SCIENCE] * plr->economic.science);
+  trade_value /= 10000;
 
   return food_value + shield_value + trade_value;
-}  
+}
 
 /**************************************************************************
   Calculates the value of removing pollution at the given tile.

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