Re: [Freeciv-Dev] (PR#20672) Settler ferry assert

2007-08-03 Thread Marko Lindqvist

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.0 +0300
+++ freeciv/ai/aiferry.c	2007-08-04 03:09:50.0 +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.0 +0300
+++ freeciv/ai/aisettler.c	2007-08-04 03:10:17.0 +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(¶meter, 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.0 +0300
+++ freeciv/ai/aiferry.c	2007-08-04 03:12:25.0 +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.0 +0300
+++ freeciv/ai/aisettler.c	2007-08-04 03:11:45.0 +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(¶meter, ferry);
 parameter.get_TB = no_fights_or_unknown;
 
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Fwd: [Freeciv-Dev] (PR#20672) Settler ferry assert

2007-03-19 Thread Marko Lindqvist

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

Forwarding to RT where this was meant in the first place. Gmail not
handling reply-to headers correctly...


-- Forwarded message --
From: Marko Lindqvist <[EMAIL PROTECTED]>
Date: Mar 19, 2007 11:04 AM
Subject: Re: [Freeciv-Dev] (PR#20672) Settler ferry assert
To: [EMAIL PROTECTED]


On 3/19/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>  S2_1 fix (attached patch): Change assert to check only that move_type
> is not LAND_MOVING (we need to get over sea, and land units cannot
> help) and add checks to is_boat_free() to make sure that it does not
> select land units. Also added checks that ferry is not using fuel, or
> losing hitpoints over time.
>
>  Trunk will need modified version of this patch. I'll make it later.

 Trunk version


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/aiferry.c freeciv/ai/aiferry.c
--- freeciv/ai/aiferry.c	2007-03-05 21:11:52.0 +0200
+++ freeciv/ai/aiferry.c	2007-03-19 11:02:23.0 +0200
@@ -324,7 +324,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)
 {
@@ -335,14 +335,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 = get_unit_class(unit_type(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-03-05 21:11:52.0 +0200
+++ freeciv/ai/aisettler.c	2007-03-19 11:00:06.0 +0200
@@ -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: */
@@ -605,7 +606,9 @@
   ferry->tile = punit->tile;
 }
 
-assert(SEA_MOVING == get_unit_move_type(unit_type(ferry)));
+ferry_class = get_unit_class(unit_type(ferry));
+
+assert(ferry_class->ai.sea_move != MOVE_NONE);
 pft_fill_unit_overlap_param(¶meter, ferry);
 parameter.get_TB = no_fights_or_unknown;
 
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] (PR#20672) Settler ferry assert

2007-03-18 Thread Marko Lindqvist

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

 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.

 S2_1 fix (attached patch): Change assert to check only that move_type
is not LAND_MOVING (we need to get over sea, and land units cannot
help) and add checks to is_boat_free() to make sure that it does not
select land units. Also added checks that ferry is not using fuel, or
losing hitpoints over time.

 Trunk will need modified version of this patch. I'll make it later.


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/aiferry.c freeciv/ai/aiferry.c
--- freeciv/ai/aiferry.c	2007-03-05 19:14:29.0 +0200
+++ freeciv/ai/aiferry.c	2007-03-19 03:32:59.0 +0200
@@ -276,7 +276,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)
 {
@@ -287,14 +287,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
+  && get_unit_class(unit_type(boat))->hp_loss_pct <= 0);
 }
 
 /
diff -Nurd -X.diff_ignore freeciv/ai/aisettler.c freeciv/ai/aisettler.c
--- freeciv/ai/aisettler.c	2007-03-05 19:14:29.0 +0200
+++ freeciv/ai/aisettler.c	2007-03-19 03:33:19.0 +0200
@@ -605,7 +605,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(¶meter, ferry);
 parameter.get_TB = no_fights_or_unknown;
 
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev