Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2005:
[Freeciv-Dev] Re: (PR#13399) Granary Not Working - FreeCiv 2.02 (Fedora
Home

[Freeciv-Dev] Re: (PR#13399) Granary Not Working - FreeCiv 2.02 (Fedora

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jasoltow@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#13399) Granary Not Working - FreeCiv 2.02 (Fedora Core 4)
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 19 Jul 2005 10:53:38 -0700
Reply-to: bugs@xxxxxxxxxxx

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

I believe Freeciv 2.0 does indeed have a major granary bug in the
default ruleset.

1.  Granary and pyramids are cumulative.
2.  Once you have pyramids you can no longer build granary, so the bug
is hard to see in action.

Also I think there's another bug here, but I'm not sure what it is.

Symptoms:

1.  City has 19/20 food, with +1/turn, with granary and pyramids.  Next
turn it grows and has 20/30 food (should be 10/30).

2.  City has 18/20 food, with +2/turn, with pyramids only.  Next turn it
grows and has 15/30 food (should be 10/30).

3.  City has 18/20 food, with +2/turn, with granary only.  Next turn it
grows and has 15/30 food (should be 10/30).

4.  City has 28/30 food, with +3/turn, with pyramids only.  Next turn it
grows and has 20/40 food (should be 16/30).

The latter three are because of several bugs in the code.

1.  New food was calculated after the city size was increased, so the
foodbox size was wrong.
2.  Food didn't carry over.

The attached patch should fix the code issues.  Now:

1.  City has 18/20 food, with +3/turn, granary only.  Next turn it grows
and has 11/30.

2.  City has 29/30 food, with +3/turn, granary and pyramids.  Next turn
it grows and has 32/40.  (This is because of the ruleset bug which this
patch doesn't fix.)

This patch is for 2.0.  I don't know how much these bugs might apply to
the development version.

-jason


Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.267.2.11
diff -p -u -r1.267.2.11 cityturn.c
--- server/cityturn.c   1 Mar 2005 21:50:12 -0000       1.267.2.11
+++ server/cityturn.c   19 Jul 2005 17:52:44 -0000
@@ -477,10 +477,12 @@ static void city_increase_size(struct ci
 {
   struct player *powner = city_owner(pcity);
   bool have_square;
-  int savings_pct = granary_savings(pcity), new_food;
+  int foodloss_pct = 100 - granary_savings(pcity);
   bool rapture_grow = city_rapture_grow(pcity); /* check before size increase! 
*/
 
   if (!city_can_grow_to(pcity, pcity->size + 1)) { /* need improvement */
+    int new_food;
+
     if (get_current_construction_bonus(pcity, EFT_SIZE_ADJ) > 0
         || get_current_construction_bonus(pcity, EFT_SIZE_UNLIMIT) > 0) {
       notify_player_ex(powner, pcity->tile, E_CITY_AQ_BUILDING,
@@ -494,20 +496,21 @@ static void city_increase_size(struct ci
     }
     /* Granary can only hold so much */
     new_food = (city_granary_size(pcity->size)
-               * (100 * 100 - game.aqueductloss * (100 - savings_pct))
+               * (100 * 100 - game.aqueductloss * foodloss_pct)
                / (100 * 100));
     pcity->food_stock = MIN(pcity->food_stock, new_food);
     return;
   }
 
-  pcity->size++;
-  /* Do not empty food stock if city is growing by celebrating */
-  if (rapture_grow) {
-    new_food = city_granary_size(pcity->size);
-  } else {
-    new_food = city_granary_size(pcity->size) * savings_pct / 100;
+  /* Take away food before increasing the population (which affects foodbox
+   * size).  Don't take away food for rapture growth.  Allow food to
+   * carry over where applicable. */
+  if (!rapture_grow) {
+    pcity->food_stock -= city_granary_size(pcity->size) * foodloss_pct / 100;
   }
-  pcity->food_stock = MIN(pcity->food_stock, new_food);
+
+  /* Increase size *after* growing. */
+  pcity->size++;
 
   /* If there is enough food, and the city is big enough,
    * make new citizens into scientists or taxmen -- Massimo */

[Prev in Thread] Current Thread [Next in Thread]