Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2000:
[Freeciv-Dev] [PATCH] Incorrect 'turns to build' display; fixed.
Home

[Freeciv-Dev] [PATCH] Incorrect 'turns to build' display; fixed.

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] [PATCH] Incorrect 'turns to build' display; fixed.
From: Big Gaute <gs234@xxxxxxxxx>
Date: 02 Jul 2000 22:27:04 +0200

In the client there are a number of places where the player is
presented with an estimate of how long it will take to build a given
unit or improvement.  In the case where the number of surplus shields
is not strictly positive, the game incorrectly reports 999 (that is,
infinity) rather than 1 if there are enough shields stockpiled in the
city.  This bug is most easily seen if you play using the option to
display what cities produce on the main map and buy a unit /
improvement via the cities dialog.

The below patch fixes this.  It's a bit longish, but only because of
reformatting; it's a very simple fix.

As an aside, why is city_turns_to_build() in common?  As far as I can
see, it's only used in the client.

--- city.c.old  Sun Jul  2 21:02:32 2000
+++ city.c      Sun Jul  2 21:48:52 2000
@@ -1336,31 +1336,34 @@
 int city_turns_to_build(struct city *pcity, int id, int id_is_unit)
 {
   int city_shield_surplus = pcity->shield_surplus;
+  int shield_stock = pcity->shield_stock;
+  int cost;
 
+  if (id_is_unit)
+  {
+    if (!pcity->is_building_unit)
+      shield_stock /= 2;
+    cost = get_unit_type(id)->build_cost;
+  }
+  else
+  {
+    if (pcity->is_building_unit ||
+       (is_wonder(pcity->currently_building) != is_wonder(id)))
+      shield_stock /= 2;
+    cost = get_improvement_type(id)->build_cost;
+  }
+  
   if (city_shield_surplus > 0)
   {
-    int rounds, cost;
-    int shield_stock = pcity->shield_stock;
-
-    if (id_is_unit)
-    {
-      if (!pcity->is_building_unit)
-       shield_stock /= 2;
-      cost = get_unit_type(id)->build_cost;
-    }
-    else
-    {
-      if (pcity->is_building_unit ||
-         (is_wonder(pcity->currently_building) != is_wonder(id)))
-       shield_stock /= 2;
-      cost = get_improvement_type(id)->build_cost;
-    }
-
-    rounds = (cost - shield_stock + city_shield_surplus - 1) /
+    int rounds = (cost - shield_stock + city_shield_surplus - 1) /
       city_shield_surplus;
 
     return (rounds > 0) ? rounds : 1;
   }
+  /* Check for the case where city_shield_surplus <= 0 but there are
+     sufficient shields available anyway (eg. buying).  -- GS */
+  else if (cost <= shield_stock)
+    return 1;
 
   return 999;
 }

-- 
Big Gaute (not to be confused with LG)
"There was a time when a guy who died at forty was revered as the toughest
and most doggedly ancient son of a bitch in Cow Ass Clearing, Shitoleshire,
Engalond, back in the year dot." - Spider Jerusalem, Transmetropolitan #25



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