Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2005:
[Freeciv-Dev] (PR#13539) Fix AI tile effect miscalculation
Home

[Freeciv-Dev] (PR#13539) Fix AI tile effect miscalculation

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13539) Fix AI tile effect miscalculation
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Mon, 25 Jul 2005 07:24:34 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Some city.c speedup work must have screwed up the AI's ability to
calculate the benefit of tile effects. AI has totally stopped building
Harbours, for instance. This patch fixes the problem.

  - Per

Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.231
diff -u -r1.231 aicity.c
--- ai/aicity.c 22 Jul 2005 16:18:04 -0000      1.231
+++ ai/aicity.c 25 Jul 2005 14:20:50 -0000
@@ -140,7 +140,7 @@
   int want = 0, prod[O_COUNT], bonus[O_COUNT], waste[O_COUNT], i;
 
   /* The below calculation mostly duplicates set_city_production(). */
-  get_citizen_output(acity, prod); /* this also clears prod[] */
+  get_citizen_output_uncached(acity, prod); /* this also clears prod */
   for (i = 0; i < NUM_TRADEROUTES; i++) {
     prod[O_TRADE] += acity->trade_value[i];
   }
@@ -261,8 +261,8 @@
   /* Base want is calculated above using a more direct approach. */
   v += base_want(pplayer, pcity, id);
   if (v != 0) {
-    CITY_LOG(LOG_DEBUG, pcity, "%s base_want is %d (range=%d)", 
-             get_improvement_name(id), v, ai->impr_range[id]);
+    CITY_LOG(LOG_DEBUG, pcity, "%s base_want is %d (range=%d, id=%d)", 
+             get_improvement_name(id), v, ai->impr_range[id], id);
   }
 
   /* Find number of cities per range.  */
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.358
diff -u -r1.358 city.c
--- common/city.c       24 Jul 2005 17:01:35 -0000      1.358
+++ common/city.c       25 Jul 2005 14:22:46 -0000
@@ -1562,7 +1562,7 @@
 }
 
 /****************************************************************************
-  Calculate the base output (all types) of all workers and specialists in
+  Return the base output (all types) of all workers and specialists in
   the city.  The output[] array is completely cleared in the process.  This
   does not account for output transformations (like trade->(sci,gold,lux))
   or city bonuses (pcity->bonus[]).
@@ -1574,6 +1574,27 @@
 }
 
 /****************************************************************************
+  Recalculate the base output (all types) of all workers and specialists in
+  the city.  The output[] array is completely cleared in the process.  This
+  does not account for output transformations (like trade->(sci,gold,lux))
+  or city bonuses (pcity->bonus[]).
+****************************************************************************/
+void get_citizen_output_uncached(const struct city *pcity, int *output)
+{
+  bool celebrating = base_city_celebrating(pcity);
+
+  memset(output, 0, O_COUNT * sizeof(*output));
+  city_map_checked_iterate(pcity->tile, x, y, ptile) {
+    if (pcity->city_map[x][y] == C_TILE_WORKER) {
+      output_type_iterate(o) {
+        output[o] += base_city_get_output_tile(x, y, pcity, celebrating, o);
+      } output_type_iterate_end;
+    }
+  } city_map_checked_iterate_end;
+  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
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.218
diff -u -r1.218 city.h
--- common/city.h       22 Jul 2005 16:18:05 -0000      1.218
+++ common/city.h       25 Jul 2005 14:22:50 -0000
@@ -511,6 +511,7 @@
 void city_styles_free(void);
 
 void get_citizen_output(const struct city *pcity, int *output);
+void get_citizen_output_uncached(const struct city *pcity, int *output);
 void add_tax_income(const struct player *pplayer, int trade, int *output);
 int get_city_tithes_bonus(const struct city *pcity);
 int city_pollution_types(const struct city *pcity, int shield_total,

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13539) Fix AI tile effect miscalculation, Per I. Mathisen <=