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

On 19/03/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>  Magic ruleset problem.
>
>  aisettler code asserts that selected ferry is SEA_MOVING. It gets
> ferries from is_boat_free() which does not limit move_type.

 Patches updated against svn


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/aiferry.c freeciv/ai/aiferry.c
--- freeciv/ai/aiferry.c	2007-08-01 17:17:27.000000000 +0300
+++ freeciv/ai/aiferry.c	2007-08-04 03:09:50.000000000 +0300
@@ -327,7 +327,7 @@
 
 /****************************************************************************
   Runs a few checks to determine if "boat" is a free boat that can carry
-  "cap" units of the same type as "punit".
+  "cap" units of the same type as "punit" over sea.
 ****************************************************************************/
 bool is_boat_free(struct unit *boat, struct unit *punit, int cap)
 {
@@ -338,14 +338,21 @@
    * - Only available boats or boats that are already dedicated to this unit
    *   are eligible.
    * - Only boats with enough remaining capacity are eligible.
+   * - Only units that can travel at sea are eligible.
+   * - Units that require fuel are lose hitpoints are not eligible.
    */
+  struct unit_class *ferry_class = unit_class(boat);
+
   return (can_unit_transport(boat, punit)
 	  && !unit_has_orders(boat)
 	  && boat->owner == punit->owner
 	  && (boat->ai.passenger == FERRY_AVAILABLE
 	      || boat->ai.passenger == punit->id)
 	  && (get_transporter_capacity(boat) 
-	      - get_transporter_occupancy(boat) >= cap));
+	      - get_transporter_occupancy(boat) >= cap)
+          && ferry_class->ai.sea_move != MOVE_NONE
+          && !unit_type(boat)->fuel
+          && !is_losing_hp(boat));
 }
 
 /****************************************************************************
diff -Nurd -X.diff_ignore freeciv/ai/aisettler.c freeciv/ai/aisettler.c
--- freeciv/ai/aisettler.c	2007-08-01 17:17:27.000000000 +0300
+++ freeciv/ai/aisettler.c	2007-08-04 03:10:17.000000000 +0300
@@ -552,6 +552,7 @@
   struct player *pplayer = unit_owner(punit);
   struct pf_parameter parameter;
   struct unit *ferry = NULL;
+  struct unit_class *ferry_class = NULL;
 
   assert(pplayer->ai.control);
   /* Only virtual units may use virtual boats: */
@@ -606,7 +607,9 @@
       ferry->tile = punit->tile;
     }
 
-    assert(SEA_MOVING == get_unit_move_type(unit_type(ferry)));
+    ferry_class = unit_class(ferry);
+
+    assert(ferry_class->ai.sea_move != MOVE_NONE);
     pft_fill_unit_overlap_param(&parameter, ferry);
     parameter.get_TB = no_fights_or_unknown;
 
diff -Nurd -X.diff_ignore freeciv/ai/aiferry.c freeciv/ai/aiferry.c
--- freeciv/ai/aiferry.c	2007-07-04 14:04:26.000000000 +0300
+++ freeciv/ai/aiferry.c	2007-08-04 03:12:25.000000000 +0300
@@ -279,7 +279,7 @@
 
 /****************************************************************************
   Runs a few checks to determine if "boat" is a free boat that can carry
-  "cap" units of the same type as "punit".
+  "cap" units of the same type as "punit" over sea.
 ****************************************************************************/
 bool is_boat_free(struct unit *boat, struct unit *punit, int cap)
 {
@@ -290,14 +290,21 @@
    * - Only available boats or boats that are already dedicated to this unit
    *   are eligible.
    * - Only boats with enough remaining capacity are eligible.
+   * - Land moving units cannot transport others over sea
+   * - Units that require fuel are lose hitpoints are not eligible
    */
+  enum unit_move_type boat_move_type = unit_type(boat)->move_type;
+
   return (can_unit_transport(boat, punit)
 	  && !unit_has_orders(boat)
 	  && boat->owner == punit->owner
 	  && (boat->ai.passenger == FERRY_AVAILABLE
 	      || boat->ai.passenger == punit->id)
 	  && (get_transporter_capacity(boat) 
-	      - get_transporter_occupancy(boat) >= cap));
+	      - get_transporter_occupancy(boat) >= cap)
+          && boat_move_type != LAND_MOVING
+          && !unit_type(boat)->fuel
+          && unit_class(boat)->hp_loss_pct <= 0);
 }
 
 /****************************************************************************
diff -Nurd -X.diff_ignore freeciv/ai/aisettler.c freeciv/ai/aisettler.c
--- freeciv/ai/aisettler.c	2007-07-04 14:04:26.000000000 +0300
+++ freeciv/ai/aisettler.c	2007-08-04 03:11:45.000000000 +0300
@@ -606,7 +606,7 @@
       ferry->tile = punit->tile;
     }
 
-    assert(SEA_MOVING == unit_type(ferry)->move_type);
+    assert(LAND_MOVING != unit_type(ferry)->move_type);
     pft_fill_unit_overlap_param(&parameter, ferry);
     parameter.get_TB = no_fights_or_unknown;
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to