Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11547) calculate city bonuses at the beginning of the

[Freeciv-Dev] (PR#11547) calculate city bonuses at the beginning of the

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11547) calculate city bonuses at the beginning of the refresh
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 16 Dec 2004 02:57:29 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: >

Currently pcity->bonus[] is calculated around the middle of 
generic_city_refresh, right before it's first used.  I want to 
restructure things a bit.  An easy first step is to move the calculation 
of these values to the beginning and to put them in their own function. 
  This is simple because calculating these values doesn't depend on 
anything else (although a number of things do depend on it).

Note also that these values may not need to be recalculated each time. 
Benoit had a patch that allowed CM to disable these calls.  This is 
really a separate issue, but separating these calculations into their 
own function may make it a bit easier.  The same thing is true of the 
pcity->usage array calculated in city_support, but that's a bit more 


My design for the restructuring is this:

* First we calculate pcity->bonus[] with set_city_bonuses.

* Then we calculate pcity->citizen_base with get_citizen_output.

* Then we calculate pcity->prod and pcity->waste.  This is more 
complicated since it takes into acount added-on stuff (trade and tithes) 
and has some circular dependencies.  These calculations depend on the 
citizen_base[] values as well as the bonus[] values, but nothing else. 
Perhaps this part can be split up by adding in a pcity->total[] array 
(total = prod + waste).  Or maybe prod should be calculated before 
waste; I'm not quite sure about this.

* Then we calculate all the happiness stuff.  city_support falls in here 
somewhere (along with the calculation of pcity->usage[]) but I haven't 
quite figured that out.  Note that happiness checks can not look at the 
surplus[] but only the prod[] values (which is what they do now, and is 
fine since for luxury the two are the same).

* Finally we calculate pcity->surplus[] from the production and usage.


Index: common/city.c
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.286
diff -u -r1.286 city.c
--- common/city.c       16 Dec 2004 10:25:41 -0000      1.286
+++ common/city.c       16 Dec 2004 10:45:22 -0000
@@ -1724,6 +1724,19 @@
   add_specialist_output(pcity, output);
+  This function sets all the values in the pcity->bonus[] array.  This should
+  be called near the beginning of generic_city_refresh.  It doesn't depend on
+  anything else in the refresh and doesn't change when workers are moved
+  around (but does change when buildings are built, etc.).
+static inline void set_city_bonuses(struct city *pcity)
+  output_type_iterate(o) {
+    pcity->bonus[o] = get_city_output_bonus(pcity, o);
+  } output_type_iterate_end;
   Modify the incomes according to the taxrates and # of specialists.
@@ -1756,11 +1769,6 @@
 static void add_buildings_effect(struct city *pcity)
-  /* this is the place to set them */
-  output_type_iterate(o) {
-    pcity->bonus[o] = get_city_output_bonus(pcity, o);
-  } output_type_iterate_end;
   pcity->prod[O_SHIELD] = (pcity->prod[O_SHIELD] * pcity->bonus[O_SHIELD]) / 
   pcity->prod[O_LUXURY] = (pcity->prod[O_LUXURY] * pcity->bonus[O_LUXURY]) / 
   pcity->prod[O_GOLD] = (pcity->prod[O_GOLD] * pcity->bonus[O_GOLD]) / 100;
@@ -2189,6 +2197,7 @@
   int prev_tile_trade = pcity->citizen_base[O_TRADE];
+  set_city_bonuses(pcity);     /* Calculate the bonus[] array values. */
   set_tax_income(pcity);       /* calc base luxury, tax & bulbs */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11547) calculate city bonuses at the beginning of the refresh, Jason Short <=