Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#11254) get_tile_output_base
Home

[Freeciv-Dev] (PR#11254) get_tile_output_base

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11254) get_tile_output_base
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 29 Nov 2004 13:20:01 -0800
Reply-to: rt@xxxxxxxxxxx

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

This patch merges get_tile_food_base, get_tile_shield_base, and 
get_tile_trade_base into a single function get_tile_output_base.  This 
cuts out some duplicated code and someday will allow callers to do the same.

jason

Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.261
diff -u -r1.261 city.c
--- common/city.c       29 Nov 2004 20:21:11 -0000      1.261
+++ common/city.c       29 Nov 2004 21:06:18 -0000
@@ -582,7 +582,7 @@
 {
   enum tile_special_type spec_t = map_get_special(ptile);
   Terrain_type_id tile_t = ptile->terrain;
-  int s = get_tile_shield_base(ptile);
+  int s = get_tile_output_base(ptile, O_SHIELD);
 
   if (contains_special(spec_t, S_MINE)) {
     s += get_tile_type(tile_t)->mining_shield_incr;
@@ -679,7 +679,7 @@
 {
   enum tile_special_type spec_t = map_get_special(ptile);
   Terrain_type_id tile_t = ptile->terrain;
-  int t = get_tile_trade_base(ptile);
+  int t = get_tile_output_base(ptile, O_TRADE);
 
   if (contains_special(spec_t, S_RIVER) && !is_ocean(tile_t)) {
     t += terrain_control.river_trade_incr;
@@ -782,7 +782,7 @@
   const Terrain_type_id tile_t = ptile->terrain;
   struct tile_type *type = get_tile_type(tile_t);
   struct tile tile;
-  int f = get_tile_food_base(ptile);
+  int f = get_tile_output_base(ptile, O_FOOD);
   const bool auto_water = (pcity && is_city_center(city_x, city_y)
                           && tile_t == type->irrigation_result
                           && terrain_control.may_irrigate);
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.207
diff -u -r1.207 map.c
--- common/map.c        29 Nov 2004 20:56:51 -0000      1.207
+++ common/map.c        29 Nov 2004 21:06:18 -0000
@@ -723,43 +723,19 @@
   return FALSE;
 }
 
-/***************************************************************
-...
-***************************************************************/
-int get_tile_food_base(const struct tile *ptile)
+/****************************************************************************
+  Return the output of this type provided by the tile.  This includes base
+  terrain plus S_SPECIAL_1 and S_SPECIAL_2, but not any other specials
+  (river/road/irrigation/etc).
+****************************************************************************/
+int get_tile_output_base(const struct tile *ptile, Output_type_id output)
 {
   if (tile_has_special(ptile, S_SPECIAL_1)) 
-    return tile_types[ptile->terrain].special[0].output[O_FOOD];
-  else if (tile_has_special(ptile, S_SPECIAL_2))
-    return tile_types[ptile->terrain].special[1].output[O_FOOD];
-  else
-    return tile_types[ptile->terrain].output[O_FOOD];
-}
-
-/***************************************************************
-...
-***************************************************************/
-int get_tile_shield_base(const struct tile *ptile)
-{
-  if (tile_has_special(ptile, S_SPECIAL_1))
-    return tile_types[ptile->terrain].special[0].output[O_SHIELD];
-  else if(tile_has_special(ptile, S_SPECIAL_2))
-    return tile_types[ptile->terrain].special[1].output[O_SHIELD];
-  else
-    return tile_types[ptile->terrain].output[O_SHIELD];
-}
-
-/***************************************************************
-...
-***************************************************************/
-int get_tile_trade_base(const struct tile *ptile)
-{
-  if (tile_has_special(ptile, S_SPECIAL_1))
-    return tile_types[ptile->terrain].special[0].output[O_TRADE];
+    return tile_types[ptile->terrain].special[0].output[output];
   else if (tile_has_special(ptile, S_SPECIAL_2))
-    return tile_types[ptile->terrain].special[1].output[O_TRADE];
+    return tile_types[ptile->terrain].special[1].output[output];
   else
-    return tile_types[ptile->terrain].output[O_TRADE];
+    return tile_types[ptile->terrain].output[output];
 }
 
 /***************************************************************
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.228
diff -u -r1.228 map.h
--- common/map.h        29 Nov 2004 20:56:51 -0000      1.228
+++ common/map.h        29 Nov 2004 21:06:19 -0000
@@ -386,9 +386,7 @@
 bool is_safe_ocean(const struct tile *ptile);
 bool is_cardinally_adj_to_ocean(const struct tile *ptile);
 bool is_sea_usable(const struct tile *ptile);
-int get_tile_food_base(const struct tile *ptile);
-int get_tile_shield_base(const struct tile *ptile);
-int get_tile_trade_base(const struct tile *ptile);
+int get_tile_output_base(const struct tile *ptile, Output_type_id output);
 enum tile_special_type get_tile_infrastructure_set(const struct tile *ptile);
 const char *map_get_infrastructure_text(enum tile_special_type spe);
 enum tile_special_type map_get_infrastructure_prerequisite(enum 
tile_special_type spe);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11254) get_tile_output_base, Jason Short <=