[Freeciv-Dev] (PR#11324) merge get_city_xxx_bonus into a single function
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=11324 >
We have
get_city_shield_bonus
get_city_science_bonus
get_city_luxury_bonus
get_city_gold_bonus
this patch merges them all into a single function
get_city_output_bonus(). The function takes the output type. One of
the callers (in aicity) is just a search-and-replace update. The other
caller is changed to use an iteration.
This simplifies logic and potentially paves the way for food or trade
bonuses (which are commented out in effects.h).
-jason
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.178
diff -u -r1.178 aicity.c
--- ai/aicity.c 30 Nov 2004 08:37:02 -0000 1.178
+++ ai/aicity.c 3 Dec 2004 23:46:00 -0000
@@ -119,20 +119,20 @@
want += food * ai->food_priority;
if (shields != 0) {
- want += ((shields * get_city_shield_bonus(acity)) / 100)
+ want += ((shields * get_city_output_bonus(acity, O_SHIELD)) / 100)
* ai->shield_priority;
want -= city_pollution(acity, shields) * ai->pollution_priority;
}
if (lux > 0) {
- want += ((lux * get_city_luxury_bonus(acity)) / 100)
+ want += ((lux * get_city_output_bonus(acity, O_LUXURY)) / 100)
* ai->luxury_priority;
}
if (sci > 0) {
- want += ((sci * get_city_science_bonus(acity)) / 100)
+ want += ((sci * get_city_output_bonus(acity, O_SCIENCE)) / 100)
* ai->science_priority;
}
if (tax > 0) {
- tax *= get_city_tax_bonus(acity) / 100;
+ tax *= get_city_output_bonus(acity, O_GOLD) / 100;
}
want += tax * ai->gold_priority;
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.267
diff -u -r1.267 city.c
--- common/city.c 3 Dec 2004 23:30:27 -0000 1.267
+++ common/city.c 3 Dec 2004 23:46:01 -0000
@@ -1603,27 +1603,25 @@
}
/**************************************************************************
- Return the factor (in %) by which the shield should be multiplied.
+ Return the factor (in %) by which the city's output should be multiplied.
**************************************************************************/
-int get_city_shield_bonus(const struct city *pcity)
+int get_city_output_bonus(const struct city *pcity, Output_type_id otype)
{
- return (100 + get_city_bonus(pcity, EFT_PROD_BONUS));
-}
+ enum effect_type eft[] = {EFT_LAST, EFT_PROD_BONUS, EFT_LAST,
+ EFT_TAX_BONUS, EFT_LUXURY_BONUS,
+ EFT_SCIENCE_BONUS};
+ int bonus = 100;
-/**************************************************************************
- Return the factor (in %) by which the tax should be multiplied.
-**************************************************************************/
-int get_city_tax_bonus(const struct city *pcity)
-{
- return (100 + get_city_bonus(pcity, EFT_TAX_BONUS));
-}
+ if (eft[otype] != EFT_LAST) {
+ bonus += get_city_bonus(pcity, eft[otype]);
+ }
-/**************************************************************************
- Return the factor (in %) by which the luxury should be multiplied.
-**************************************************************************/
-int get_city_luxury_bonus(const struct city *pcity)
-{
- return (100 + get_city_bonus(pcity, EFT_LUXURY_BONUS));
+ if (otype == O_SCIENCE
+ && government_has_flag(get_gov_pcity(pcity), G_REDUCED_RESEARCH)) {
+ bonus /= 2;
+ }
+
+ return bonus;
}
/**************************************************************************
@@ -1646,22 +1644,6 @@
}
/**************************************************************************
- Return the factor (in %) by which the science should be multiplied.
-**************************************************************************/
-int get_city_science_bonus(const struct city *pcity)
-{
- int science_bonus;
-
- science_bonus = 100 + get_city_bonus(pcity, EFT_SCIENCE_BONUS);
-
- if (government_has_flag(get_gov_pcity(pcity), G_REDUCED_RESEARCH)) {
- science_bonus /= 2;
- }
-
- return science_bonus;
-}
-
-/**************************************************************************
Get the incomes of a city according to the taxrates (ignore # of
specialists). trade should usually be pcity->surplus[O_TRADE].
**************************************************************************/
@@ -1734,10 +1716,9 @@
static void add_buildings_effect(struct city *pcity)
{
/* this is the place to set them */
- pcity->bonus[O_GOLD] = get_city_tax_bonus(pcity);
- pcity->bonus[O_LUXURY] = get_city_luxury_bonus(pcity);
- pcity->bonus[O_SCIENCE] = get_city_science_bonus(pcity);
- pcity->bonus[O_SHIELD] = get_city_shield_bonus(pcity);
+ output_type_iterate(o) {
+ pcity->bonus[o] = get_city_output_bonus(pcity, o);
+ } output_type_iterate_end;
pcity->shield_prod = (pcity->shield_prod * pcity->bonus[O_SHIELD]) / 100;
pcity->luxury_total = (pcity->luxury_total * pcity->bonus[O_LUXURY]) / 100;
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.174
diff -u -r1.174 city.h
--- common/city.h 3 Dec 2004 09:39:40 -0000 1.174
+++ common/city.h 3 Dec 2004 23:46:01 -0000
@@ -507,10 +507,7 @@
int city_waste(const struct city *pcity, int shields);
int city_specialists(const struct city *pcity); /*
elv+tax+scie */
const char *specialists_string(const int *specialists);
-int get_city_tax_bonus(const struct city *pcity);
-int get_city_luxury_bonus(const struct city *pcity);
-int get_city_shield_bonus(const struct city *pcity);
-int get_city_science_bonus(const struct city *pcity);
+int get_city_output_bonus(const struct city *pcity, Output_type_id otype);
bool city_built_last_turn(const struct city *pcity);
/* city creation / destruction */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#11324) merge get_city_xxx_bonus into a single function,
Jason Short <=
|
|