Complete.Org: Mailing Lists: Archives: freeciv-ai: October 2004:
[freeciv-ai] (PR#10216) AI Builds Too Many Transports
Home

[freeciv-ai] (PR#10216) AI Builds Too Many Transports

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: badamson@xxxxxxxxxxx
Subject: [freeciv-ai] (PR#10216) AI Builds Too Many Transports
From: "Gregory Berkolaiko" <Gregory.Berkolaiko@xxxxxxxxxxxxx>
Date: Sun, 3 Oct 2004 21:19:04 -0700
Reply-to: rt@xxxxxxxxxxx

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

> [badamson@xxxxxxxxxxx - Mon Oct 04 01:19:11 2004]:
> 
> 3) That code (kill_something_with)) then checks whether there is a path 
> from the city (were the attacker will begin) and the target (the enemy 
> land unit to be bombarded), using function goto_is_sane. That call is 
> used to decide whether a land attacker needs a ferry; a land attacker 
> will need a ferry if there is no valid (land) path from the city to the 
> target. However, the function is also used for sea attackers. For those 
> units, the kill_something_with function incorrectly concludes that the 
> (naval!) attack unit will need a ferry (go_by_boat becomes TRUE). I 
> guess it is not handling the 'overlap' needed for shore bombardment 
> properly.

Actually, goto_is_sane is innocent, the culprit is WARMAP_COST which for
sea units should be WARMAP_SEACOST.

Two fixes attached.  A short (but equally effective) one is just making
sure that sea attackers don't try to go by boat.  A long one move some
code around so it doesn't get called neelessly.

The reason I bothered about short fix is to try to avoid conflicts with
other patches I was making.  But by the time I get round to finishing
them, there would be conflicts anyway...


? core.10423
? core.10618
Index: ai/advmilitary.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v
retrieving revision 1.174
diff -u -r1.174 advmilitary.c
--- ai/advmilitary.c    29 Sep 2004 02:24:18 -0000      1.174
+++ ai/advmilitary.c    4 Oct 2004 04:13:23 -0000
@@ -1055,8 +1055,10 @@
       return;
     }
 
-    go_by_boat = !(goto_is_sane(myunit, acity->tile, TRUE) 
-                  && WARMAP_COST(ptile) <= (MIN(6, move_rate) * THRESHOLD));
+    go_by_boat = (is_ground_unit(myunit)
+                  && !(WARMAP_COST(ptile) <= (MIN(6, move_rate) * THRESHOLD)
+                       && goto_is_sane(myunit, acity->tile, TRUE)));
+
     move_time = turns_to_enemy_city(myunit->type, acity, move_rate, 
                                     go_by_boat, ferryboat, boattype);
 
? core.10423
? core.10618
Index: ai/advmilitary.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v
retrieving revision 1.174
diff -u -r1.174 advmilitary.c
--- ai/advmilitary.c    29 Sep 2004 02:24:18 -0000      1.174
+++ ai/advmilitary.c    4 Oct 2004 04:08:51 -0000
@@ -984,7 +984,7 @@
   struct tile *boat_tile = NULL;
   /* Type of the boat (real or a future one) */
   Unit_Type_id boattype = U_LAST;
-  bool go_by_boat;
+  bool go_by_boat = FALSE;
   /* Is the defender veteran? */
   int def_vet;
   struct ai_choice best_choice;
@@ -1007,21 +1007,6 @@
     return;
   }
 
-  if (is_ground_unit(myunit)) {
-    int boatid = find_boat(pplayer, &boat_tile, 2);
-    ferryboat = player_find_unit_by_id(pplayer, boatid);
-  }
-
-  if (ferryboat) {
-    boattype = ferryboat->type;
-  } else {
-    boattype = best_role_unit_for_player(pplayer, L_FERRYBOAT);
-    if (boattype == U_LAST) {
-      /* We pretend that we can have the simplest boat -- to stimulate tech */
-      boattype = get_role_unit(L_FERRYBOAT, 0);
-    }
-  }
-
   best_choice.want = find_something_to_kill(pplayer, myunit, &ptile);
 
   acity = map_get_city(ptile);
@@ -1055,8 +1040,24 @@
       return;
     }
 
-    go_by_boat = !(goto_is_sane(myunit, acity->tile, TRUE) 
-                  && WARMAP_COST(ptile) <= (MIN(6, move_rate) * THRESHOLD));
+    if (is_ground_unit(myunit)) {
+      int boatid = find_boat(pplayer, &boat_tile, 2);
+
+      ferryboat = player_find_unit_by_id(pplayer, boatid);
+      if (ferryboat) {
+        boattype = ferryboat->type;
+      } else {
+        boattype = best_role_unit_for_player(pplayer, L_FERRYBOAT);
+        if (boattype == U_LAST) {
+          /* Pretend that we can have the simplest boat 
+           * so that we stimulate tech */
+          boattype = get_role_unit(L_FERRYBOAT, 0);
+        }
+      }
+      go_by_boat = !(WARMAP_COST(ptile) <= (MIN(6, move_rate) * THRESHOLD)
+                     && goto_is_sane(myunit, acity->tile, TRUE));
+    }
+
     move_time = turns_to_enemy_city(myunit->type, acity, move_rate, 
                                     go_by_boat, ferryboat, boattype);
 
@@ -1110,6 +1111,7 @@
                           &best_choice, NULL, U_LAST);
   } else { 
     /* Attract a boat to our city or retain the one that's already here */
+    assert(is_ground_unit(myunit));
     best_choice.need_boat = TRUE;
     process_attacker_want(pcity, benefit, def_type, def_vet, ptile, 
                           &best_choice, ferryboat, boattype);

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