Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11440) error in unhappy_city_check
Home

[Freeciv-Dev] (PR#11440) error in unhappy_city_check

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11440) error in unhappy_city_check
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 9 Dec 2004 12:51:03 -0800
Reply-to: bugs@xxxxxxxxxxx

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

static inline void unhappy_city_check(struct city *pcity)
{
   if (city_unhappy(pcity)) {
     pcity->surplus[O_FOOD] = MIN(0, pcity->surplus[O_FOOD]);
     pcity->surplus[O_SHIELD] = MIN(0, pcity->surplus[O_SHIELD]);
     pcity->surplus[O_GOLD] = MIN(0, pcity->surplus[O_GOLD]);
     pcity->surplus[O_SCIENCE] = MIN(0, pcity->surplus[O_SCIENCE]);

     pcity->tax_total = 0;
     pcity->science_total = 0;
   }
}

surplus[O_GOLD] is a new field and is not yet used by anyone.  But it is 
set incorrectly here.  It should be made negative if appropriate.  This 
patch makes this fix.

Looking at this code in 2.0:

   if (city_unhappy(pcity)) {
     pcity->food_surplus = MIN(0, pcity->food_surplus);
     pcity->tax_total = 0;
     pcity->science_total = 0;
     pcity->shield_surplus = MIN(0, pcity->shield_surplus);
   }

we see that tax_total is set to 0.  Since "surplus" is calculated on 
demand by city_gold_surplus it will thus become negative.

-jason

Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.277
diff -u -r1.277 city.c
--- common/city.c       9 Dec 2004 20:17:46 -0000       1.277
+++ common/city.c       9 Dec 2004 20:49:12 -0000
@@ -1986,8 +1986,8 @@
   if (city_unhappy(pcity)) {
     pcity->surplus[O_FOOD] = MIN(0, pcity->surplus[O_FOOD]);
     pcity->surplus[O_SHIELD] = MIN(0, pcity->surplus[O_SHIELD]);
-    pcity->surplus[O_GOLD] = MIN(0, pcity->surplus[O_GOLD]);
-    pcity->surplus[O_SCIENCE] = MIN(0, pcity->surplus[O_SCIENCE]);
+    pcity->surplus[O_GOLD] -= pcity->tax_total;
+    pcity->surplus[O_SCIENCE] -= pcity->science_total;
 
     /* FIXME: These are special cases because many parts of the code still
      * check tax_total and science_total instead of the surplus[] array. */

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