Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11374) merge utype_xxx_cost
Home

[Freeciv-Dev] (PR#11374) merge utype_xxx_cost

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11374) merge utype_xxx_cost
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 6 Dec 2004 10:15:58 -0800
Reply-to: rt@xxxxxxxxxxx

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

This patch merges utype_food_cost, utype_shield_cost, and 
utype_gold_cost into a single function.  It takes the output type 
(O_SHIELD, O_FOOD, O_GOLD) as an additional parameter.

There is a change to behavior: fanatics under fundamentalism no longer 
have gold or food upkeep.  This is probably a bugfix.

-jason

Index: ai/advdomestic.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdomestic.c,v
retrieving revision 1.122
diff -u -r1.122 advdomestic.c
--- ai/advdomestic.c    30 Nov 2004 08:37:01 -0000      1.122
+++ ai/advdomestic.c    6 Dec 2004 18:12:36 -0000
@@ -159,7 +159,8 @@
   unit_type = best_role_unit(pcity, F_SETTLERS);
 
   if (unit_type != U_LAST
-      && est_food > utype_food_cost(get_unit_type(unit_type), gov)) {
+      && est_food > utype_upkeep_cost(get_unit_type(unit_type),
+                                     gov, O_FOOD)) {
     /* settler_want calculated in settlers.c called from ai_manage_cities() */
     int want = pcity->ai.settler_want;
 
@@ -181,7 +182,8 @@
   unit_type = best_role_unit(pcity, F_CITIES);
 
   if (unit_type != U_LAST
-      && est_food >= utype_food_cost(get_unit_type(unit_type), gov)) {
+      && est_food >= utype_upkeep_cost(get_unit_type(unit_type),
+                                      gov, O_FOOD)) {
     /* founder_want calculated in settlers.c, called from ai_manage_cities(). 
*/
     int want = pcity->ai.founder_want;
 
Index: client/repodlgs_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/repodlgs_common.c,v
retrieving revision 1.18
diff -u -r1.18 repodlgs_common.c
--- client/repodlgs_common.c    6 Dec 2004 18:01:14 -0000       1.18
+++ client/repodlgs_common.c    6 Dec 2004 18:12:36 -0000
@@ -99,9 +99,11 @@
 
   unit_type_iterate(utype) {
     unittype = get_unit_type(utype);
-    cost = utype_gold_cost(unittype, get_gov_pplayer(game.player_ptr));
+    cost = utype_upkeep_cost(unittype, get_gov_pplayer(game.player_ptr),
+                            O_GOLD);
 
     if (cost == 0) {
+      /* Short-circuit all of the following checks. */
       continue;
     }
 
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.272
diff -u -r1.272 city.c
--- common/city.c       6 Dec 2004 18:01:14 -0000       1.272
+++ common/city.c       6 Dec 2004 18:12:37 -0000
@@ -2080,10 +2080,10 @@
    * gold etc -- SKi */
   unit_list_iterate(pcity->units_supported, this_unit) {
     struct unit_type *ut = unit_type(this_unit);
-    int shield_cost = utype_shield_cost(ut, g);
+    int shield_cost = utype_upkeep_cost(ut, g, O_SHIELD);
     int happy_cost = utype_happy_cost(ut, g);
-    int food_cost = utype_food_cost(ut, g);
-    int gold_cost = utype_gold_cost(ut, g);
+    int food_cost = utype_upkeep_cost(ut, g, O_FOOD);
+    int gold_cost = utype_upkeep_cost(ut, g, O_GOLD);
 
     /* Save old values so we can decide if the unit info should be resent */
     int old_unhappiness = this_unit->unhappiness;
Index: common/unittype.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.c,v
retrieving revision 1.44
diff -u -r1.44 unittype.c
--- common/unittype.c   6 Dec 2004 17:54:40 -0000       1.44
+++ common/unittype.c   6 Dec 2004 18:12:37 -0000
@@ -116,23 +116,17 @@
 }
 
 /**************************************************************************
-...
+  Returns the upkeep of a unit of this type under the given government.
 **************************************************************************/
-int utype_shield_cost(struct unit_type *ut, struct government *g)
+int utype_upkeep_cost(const struct unit_type *ut,
+                     const struct government *g, Output_type_id otype)
 {
   if (government_has_flag(g, G_FANATIC_TROOPS) &&
       BV_ISSET(ut->flags, F_FANATIC)) {
+    /* Special case: fanatics have no upkeep under fanaticism. */
     return 0;
   }
-  return ut->upkeep[O_SHIELD] * g->unit_upkeep_factor[O_SHIELD];
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-int utype_food_cost(struct unit_type *ut, struct government *g)
-{
-  return ut->upkeep[O_FOOD] * g->unit_upkeep_factor[O_FOOD];
+  return ut->upkeep[otype] * g->unit_upkeep_factor[otype];
 }
 
 /**************************************************************************
@@ -146,14 +140,6 @@
 /**************************************************************************
 ...
 **************************************************************************/
-int utype_gold_cost(struct unit_type *ut, struct government *g)
-{
-  return ut->upkeep[O_GOLD] * g->unit_upkeep_factor[O_GOLD];
-}
-
-/**************************************************************************
-...
-**************************************************************************/
 bool unit_type_flag(Unit_Type_id id, int flag)
 {
   assert(flag>=0 && flag<F_LAST);
Index: common/unittype.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.h,v
retrieving revision 1.35
diff -u -r1.35 unittype.h
--- common/unittype.h   5 Dec 2004 09:08:19 -0000       1.35
+++ common/unittype.h   6 Dec 2004 18:12:37 -0000
@@ -246,10 +246,9 @@
 const char *get_unit_name(Unit_Type_id id);
 const char *get_units_with_flag_string(int flag);
 
-int utype_shield_cost(struct unit_type *ut, struct government *g);
-int utype_food_cost(struct unit_type *ut, struct government *g);
+int utype_upkeep_cost(const struct unit_type *ut,
+                     const struct government *gov, Output_type_id otype);
 int utype_happy_cost(struct unit_type *ut, struct government *g);
-int utype_gold_cost(struct unit_type *ut, struct government *g);
 
 int can_upgrade_unittype(struct player *pplayer, Unit_Type_id id);
 int unit_upgrade_price(const struct player * const pplayer,
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.279
diff -u -r1.279 cityturn.c
--- server/cityturn.c   5 Dec 2004 09:08:19 -0000       1.279
+++ server/cityturn.c   6 Dec 2004 18:12:38 -0000
@@ -835,7 +835,7 @@
 
   if (pcity->surplus[O_SHIELD] < 0) {
     unit_list_iterate_safe(pcity->units_supported, punit) {
-      if (utype_shield_cost(unit_type(punit), g) > 0
+      if (utype_upkeep_cost(unit_type(punit), g, O_SHIELD) > 0
          && pcity->surplus[O_SHIELD] < 0
           && !unit_flag(punit, F_UNDISBANDABLE)) {
        notify_player_ex(pplayer, pcity->tile, E_UNIT_LOST,
@@ -853,7 +853,7 @@
      * it! If we make it here all normal units are already disbanded, so only
      * undisbandable ones remain. */
     unit_list_iterate_safe(pcity->units_supported, punit) {
-      int upkeep = utype_shield_cost(unit_type(punit), g);
+      int upkeep = utype_upkeep_cost(unit_type(punit), g, O_SHIELD);
 
       if (upkeep > 0 && pcity->surplus[O_SHIELD] < 0) {
        assert(unit_flag(punit, F_UNDISBANDABLE));
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.213
diff -u -r1.213 settlers.c
--- server/settlers.c   3 Dec 2004 23:00:02 -0000       1.213
+++ server/settlers.c   6 Dec 2004 18:12:38 -0000
@@ -892,8 +892,8 @@
 static int unit_food_upkeep(struct unit *punit)
 {
   struct player *pplayer = unit_owner(punit);
-  int upkeep = utype_food_cost(unit_type(punit),
-                              get_gov_pplayer(pplayer));
+  int upkeep = utype_upkeep_cost(unit_type(punit),
+                                get_gov_pplayer(pplayer), O_FOOD);
   if (punit->id != 0 && punit->homecity == 0)
     upkeep = 0; /* thanks, Peter */
 

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