Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#10217) More aicity.c changes
Home

[Freeciv-Dev] (PR#10217) More aicity.c changes

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#10217) More aicity.c changes
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Mon, 20 Sep 2004 14:29:08 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10217 >

CHANGES:
 - make one run only to set comparison values for city worth (thanks
to jason for pointing out the obvious); should make code _much_ faster
 - faster upkeep calculation (one less function call, ignore units)
 - fix major bug with wonder evaluation
 - readd corruption and waste that mysteriously disappeared from the code
at one point

  - Per

Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.166
diff -u -r1.166 aicity.c
--- ai/aicity.c 20 Sep 2004 13:27:08 -0000      1.166
+++ ai/aicity.c 20 Sep 2004 21:24:06 -0000
@@ -108,23 +108,28 @@
 {
   int want = 0;
 
+  built_impr_iterate(acity, i) {
+    tax -= improvement_upkeep(acity, i);
+  } built_impr_iterate_end;
+
   want += food * ai->food_priority;
   if (shields != 0) {
     want += ((shields * get_city_shield_bonus(acity)) / 100)
             * ai->shield_priority;
     want -= city_pollution(acity, shields) * ai->pollution_priority;
   }
-  if (lux != 0) {
+  if (lux > 0) {
     want += ((lux * get_city_luxury_bonus(acity)) / 100)
             * ai->luxury_priority;
   }
-  if (sci != 0) {
+  if (sci > 0) {
     want += ((sci * get_city_science_bonus(acity)) / 100)
             * ai->science_priority;
   }
-  want += ((city_gold_surplus(acity, tax) 
-          * get_city_tax_bonus(acity)) / 100)
-          * ai->gold_priority;
+  if (tax > 0) {
+    tax *= get_city_tax_bonus(acity) / 100;
+  }
+  want += tax * ai->gold_priority;
 
   return want;
 }
@@ -144,23 +149,19 @@
     return 0; /* Nothing to calculate here. */
   }
 
-  /* First calculate current worth */
-  city_range_iterate(pcity, pplayer->cities, ai->impr_range[id], acity) {
-    int food, trade, shields, lux, sci, tax;
-
-    get_food_trade_shields(acity, &food, &trade, &shields);
-    get_tax_income(pplayer, trade, &sci, &lux, &tax);
-    acity->ai.worth = city_want(acity, ai, food, shields, sci, lux, tax);
-  } city_range_iterate_end;
-
   /* Add the improvement */
   city_add_improvement(pcity, id);
+  if (is_wonder(id)) {
+    game.global_wonders[id] = pcity->id;
+  }
 
   /* Stir, then compare notes */
   city_range_iterate(pcity, pplayer->cities, ai->impr_range[id], acity) {
     int food, trade, shields, lux, sci, tax;
 
     get_food_trade_shields(acity, &food, &trade, &shields);
+    trade -= city_corruption(acity, trade);
+    shields -= city_waste(acity, shields);
     get_tax_income(pplayer, trade, &sci, &lux, &tax);
     final_want += city_want(acity, ai, food, shields, sci, lux, tax)
                   - acity->ai.worth;
@@ -168,6 +169,9 @@
 
   /* Restore */
   city_remove_improvement(pcity, id);
+  if (is_wonder(id)) {
+    game.global_wonders[id] = 0;
+  }
 
   /* Ensure that we didn't inadvertantly move our palace */
   if (find_palace(pplayer) != capital) {
@@ -486,6 +490,20 @@
 /* TODO:  RECALC_SPEED should be configurable to ai difficulty. -kauf  */
 #define RECALC_SPEED 5
 {
+  struct ai_data *ai = ai_data_get(pplayer);
+
+  /* First find current worth of cities and cache this. Note, this
+   * must be done in exactly the same way as in city_want(). */
+  city_list_iterate(pplayer->cities, acity) {
+    int food, trade, shields, lux, sci, tax;
+
+    get_food_trade_shields(acity, &food, &trade, &shields);
+    trade -= city_corruption(acity, trade);
+    shields -= city_waste(acity, shields);
+    get_tax_income(pplayer, trade, &sci, &lux, &tax);
+    acity->ai.worth = city_want(acity, ai, food, shields, sci, lux, tax);
+  } city_list_iterate_end;
+
   impr_type_iterate(id) {
     if (!can_player_build_improvement(pplayer, id)
         || improvement_obsolete(pplayer, id)) {

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#10217) More aicity.c changes, Per I. Mathisen <=