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

Here's my proposed patch to rid us of this troublesome beast....

Index: ai/advdomestic.c
===================================================================
--- ai/advdomestic.c    (revision 14391)
+++ ai/advdomestic.c    (working copy)
@@ -336,17 +336,23 @@
     init_choice(&cur);
     /* Consider building caravan-type units to aid wonder construction */  
     ai_choose_help_wonder(pcity, &cur, ai);
-    copy_if_better_choice(&cur, choice);
+    if (choice->want < cur.want) {
+      *choice = cur;
+    }
 
     init_choice(&cur);
     /* Consider city improvements */
     ai_advisor_choose_building(pcity, &cur);
-    copy_if_better_choice(&cur, choice);
+    if (choice->want < cur.want) {
+      *choice = cur;
+    }
 
     init_choice(&cur);
     /* Consider building caravan-type units for trade route */
     ai_choose_trade_route(pcity, &cur, ai);
-    copy_if_better_choice(&cur, choice);
+    if (choice->want < cur.want) {
+      *choice = cur;
+    }
   }
 
   if (choice->want >= 200) {
Index: ai/aitools.c
===================================================================
--- ai/aitools.c        (revision 14391)
+++ ai/aitools.c        (working copy)
@@ -1163,16 +1163,6 @@
 }
 
 /**************************************************************************
-...
-**************************************************************************/
-void copy_if_better_choice(struct ai_choice *cur, struct ai_choice *best)
-{
-  if (best->want < cur->want) {
-    best = cur;
-  }
-}
-
-/**************************************************************************
   ...
 **************************************************************************/
 bool is_unit_choice_type(enum choice_type type)
Index: ai/aitools.h
===================================================================
--- ai/aitools.h        (revision 14391)
+++ ai/aitools.h        (working copy)
@@ -92,7 +92,6 @@
 
 void init_choice(struct ai_choice *choice);
 void adjust_choice(int value, struct ai_choice *choice);
-void copy_if_better_choice(struct ai_choice *cur, struct ai_choice *best);
 
 bool is_unit_choice_type(enum choice_type type);
 
Index: ai/aicity.c
===================================================================
--- ai/aicity.c (revision 14391)
+++ ai/aicity.c (working copy)
@@ -1365,7 +1365,9 @@
         && !(ai_on_war_footing(pplayer) && pcity->ai.choice.want > 0
              && pcity->id != ai->wonder_city)) {
       domestic_advisor_choose_build(pplayer, pcity, &newchoice);
-      copy_if_better_choice(&newchoice, &(pcity->ai.choice));
+      if (pcity->ai.choice.want < newchoice.want) {
+        pcity->ai.choice = newchoice;
+      }
     }
   }
 
Index: ai/advmilitary.c
===================================================================
--- ai/advmilitary.c    (revision 14391)
+++ ai/advmilitary.c    (working copy)
@@ -1218,9 +1218,10 @@
                           &best_choice, ferryboat, boattype);
   }
 
-  if (best_choice.want > choice->want) {
+  if (choice->want < best_choice.want) {
     /* We want attacker more than what we have selected before */
-    copy_if_better_choice(&best_choice, choice);
+    *choice = best_choice;
+
     CITY_LOG(LOG_DEBUG, pcity, "kill_something_with()"
             " %s has chosen attacker, %s, want=%d",
             city_name(pcity),
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to