Complete.Org: Mailing Lists: Archives: freeciv-ai: September 2004:
[freeciv-ai] (PR#10061) assertion "punit->transported_by > 0" failed
Home

[freeciv-ai] (PR#10061) assertion "punit->transported_by > 0" failed

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: marko.lindqvist@xxxxxxxxxxx
Subject: [freeciv-ai] (PR#10061) assertion "punit->transported_by > 0" failed
From: "Gregory Berkolaiko" <Gregory.Berkolaiko@xxxxxxxxxxxxx>
Date: Thu, 16 Sep 2004 22:57:19 -0700
Reply-to: rt@xxxxxxxxxxx

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

Here is a patch.

Thanks to Jordi for providing a savegame.

G.
? 0
? core.9199
? freeciv.spec
Index: ai/aiferry.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiferry.c,v
retrieving revision 1.4
diff -u -r1.4 aiferry.c
--- ai/aiferry.c        26 Aug 2004 22:08:42 -0000      1.4
+++ ai/aiferry.c        17 Sep 2004 05:54:58 -0000
@@ -266,6 +266,20 @@
 }
 
 /****************************************************************************
+  Runs a few checks to determine if "boat" is a free boat that can carry
+  "cap" units of the same type as "punit" (the last one isn't implemented).
+****************************************************************************/
+static bool is_boat_free(struct unit *boat, struct unit *punit, int cap)
+{
+  return (is_ground_units_transport(boat)
+         && boat->owner == punit->owner
+         && (boat->ai.passenger == FERRY_AVAILABLE
+             || boat->ai.passenger == punit->id)
+         && (get_transporter_capacity(boat) 
+             - get_transporter_occupancy(boat) >= cap));
+}
+
+/****************************************************************************
   Proper and real PF function for finding a boat.  If you don't require
   the path to the ferry, pass path=NULL.
 
@@ -312,10 +326,7 @@
       struct tile *ptile = map_get_tile(x, y);
       
       unit_list_iterate(ptile->units, aunit) {
-        if (is_ground_units_transport(aunit)
-            && aunit->owner == punit->owner
-            && (aunit->ai.passenger == FERRY_AVAILABLE
-                || aunit->ai.passenger == punit->id)) {
+        if (is_boat_free(aunit, punit, cap)) {
           /* Turns for the unit to get to rendezvous pnt */
           int u_turns = pos.turn;
           /* Turns for the boat to get to the rendezvous pnt */
@@ -354,12 +365,9 @@
 
   square_iterate(punit->x, punit->y, 1, x, y) {
     unit_list_iterate(map_get_tile(x, y)->units, aunit) {
-      if (is_ground_units_transport(aunit)
-         && aunit->owner == punit->owner
-          && (aunit->ai.passenger == FERRY_AVAILABLE
-              || aunit->ai.passenger == punit->id)) {
-         return aunit->id;
-       }
+      if (is_boat_free(aunit, punit, cap)) {
+        return aunit->id;
+      }
     } unit_list_iterate_end;
   } square_iterate_end;
 
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.202
diff -u -r1.202 settlers.c
--- server/settlers.c   15 Sep 2004 11:37:40 -0000      1.202
+++ server/settlers.c   17 Sep 2004 05:55:05 -0000
@@ -769,6 +769,8 @@
   The "virtual boats" code is not used. It is probably too unreliable, 
   since the AI switches its production back and forth continously.
 
+  FIXME: if there is a (free) boat in a city filled with units, 
+  ground_unit_transporter_capacity will return negative.
   TODO: Kill me.  There is a reliable version of this, find_ferry.
 **************************************************************************/
 Unit_Type_id find_boat(struct player *pplayer, int *x, int *y, int cap)

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