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

On 2/10/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>  I think you cannot check for is_native_tile() in could_unit_load()
> (this was probably bug already in find_transport_from_tile()) It means
> that you cannot load to boat in coastal city.

Fixed. New patch attached. I have tested boarding transports in
cities. It works now, at least.

>  You could check that transport can_unit_exist_at_tile(), but I don't
> think that is necessary. can_unit_exist_at_tile() would return FALSE
> only if we attempt recursive transportation, which is prohibited by
> other means already. Assert, maybe?

I think you got some functions mixed up above.

  - Per

Index: server/unittools.c
===================================================================
--- server/unittools.c	(revision 12614)
+++ server/unittools.c	(working copy)
@@ -2844,7 +2844,7 @@
     
   /* Special checks for ground units in the ocean. */
   if (!can_unit_survive_at_tile(punit, pdesttile)) {
-    ptransporter = find_transporter_for_unit(punit, pdesttile);
+    ptransporter = find_transporter_for_unit(punit);
     if (ptransporter) {
       put_unit_onto_transporter(punit, ptransporter);
     }
Index: common/unit.c
===================================================================
--- common/unit.c	(revision 12614)
+++ common/unit.c	(working copy)
@@ -543,22 +543,15 @@
 }
 
 /****************************************************************************
-  Return TRUE iff the given unit can be loaded into the transporter.
+  Return TRUE iff the given unit could be loaded into the transporter
+  if we moved there.
 ****************************************************************************/
-bool can_unit_load(const struct unit *pcargo, const struct unit *ptrans)
+bool could_unit_load(const struct unit *pcargo, const struct unit *ptrans)
 {
-  /* This function needs to check EVERYTHING. */
-
   if (!pcargo || !ptrans) {
     return FALSE;
   }
 
-  /* Check positions of the units.  Of course you can't load a unit onto
-   * a transporter on a different tile... */
-  if (!same_pos(pcargo->tile, ptrans->tile)) {
-    return FALSE;
-  }
-
   /* Double-check ownership of the units: you can load into an allied unit
    * (of course only allied units can be on the same tile). */
   if (!pplayers_allied(unit_owner(pcargo), unit_owner(ptrans))) {
@@ -576,16 +569,37 @@
   }
 
   /* Make sure this transporter can carry this type of unit. */
-  if(!can_unit_transport(ptrans, pcargo)) {
+  if (!can_unit_transport(ptrans, pcargo)) {
     return FALSE;
   }
 
+  /* Transporter must be native to the tile it is on. */
+  if (!can_unit_exist_at_tile(ptrans, ptrans->tile)) {
+    return FALSE;
+  }
+
   /* Make sure there's room in the transporter. */
   return (get_transporter_occupancy(ptrans)
 	  < get_transporter_capacity(ptrans));
 }
 
 /****************************************************************************
+  Return TRUE iff the given unit can be loaded into the transporter.
+****************************************************************************/
+bool can_unit_load(const struct unit *pcargo, const struct unit *ptrans)
+{
+  /* This function needs to check EVERYTHING. */
+
+  /* Check positions of the units.  Of course you can't load a unit onto
+   * a transporter on a different tile... */
+  if (!same_pos(pcargo->tile, ptrans->tile)) {
+    return FALSE;
+  }
+
+  return could_unit_load(pcargo, ptrans);
+}
+
+/****************************************************************************
   Return TRUE iff the given unit can be unloaded from its current
   transporter.
 
@@ -1392,9 +1406,10 @@
 /****************************************************************************
   Find a transporter at the given location for the unit.
 ****************************************************************************/
-struct unit *find_transporter_for_unit(const struct unit *pcargo,
-				       const struct tile *ptile)
-{ 
+struct unit *find_transporter_for_unit(const struct unit *pcargo)
+{
+  struct tile *ptile = pcargo->tile;
+
   unit_list_iterate(ptile->units, ptrans) {
     if (can_unit_load(pcargo, ptrans)) {
       return ptrans;
Index: common/unit.h
===================================================================
--- common/unit.h	(revision 12614)
+++ common/unit.h	(working copy)
@@ -216,6 +216,7 @@
 bool unit_can_airlift_to(const struct unit *punit, const struct city *pcity);
 bool unit_has_orders(const struct unit *punit);
 
+bool could_unit_load(const struct unit *pcargo, const struct unit *ptrans);
 bool can_unit_load(const struct unit *punit, const struct unit *ptrans);
 bool can_unit_unload(const struct unit *punit, const struct unit *ptrans);
 bool can_unit_paradrop(const struct unit *punit);
@@ -297,8 +298,7 @@
 void free_unit_orders(struct unit *punit);
 
 int get_transporter_occupancy(const struct unit *ptrans);
-struct unit *find_transporter_for_unit(const struct unit *pcargo,
-				       const struct tile *ptile);
+struct unit *find_transporter_for_unit(const struct unit *pcargo);
 
 enum unit_upgrade_result test_unit_upgrade(const struct unit *punit,
 					   bool is_free);
Index: common/movement.c
===================================================================
--- common/movement.c	(revision 12614)
+++ common/movement.c	(working copy)
@@ -500,9 +500,7 @@
 struct unit *find_transport_from_tile(struct unit *punit, struct tile *ptile)
 {
   unit_list_iterate(ptile->units, ptransport) {
-    if (get_transporter_capacity(ptransport) > get_transporter_occupancy(ptransport)
-        && can_unit_transport(ptransport, punit)
-        && is_native_tile(unit_type(ptransport), ptile)) {
+    if (could_unit_load(ptransport, punit)) {
       return ptransport;
     }
   } unit_list_iterate_end;
Index: common/unitlist.c
===================================================================
--- common/unitlist.c	(revision 12614)
+++ common/unitlist.c	(working copy)
@@ -160,8 +160,7 @@
 bool units_can_load(const struct unit_list *punits)
 {
   unit_list_iterate(punits, punit) {
-    if (can_unit_load(punit,
-		      find_transporter_for_unit(punit, punit->tile))) {
+    if (find_transporter_for_unit(punit)) {
       return TRUE;
     }
   } unit_list_iterate_end;
Index: client/control.c
===================================================================
--- client/control.c	(revision 12614)
+++ client/control.c	(working copy)
@@ -1305,7 +1305,7 @@
 void request_unit_load(struct unit *pcargo, struct unit *ptrans)
 {
   if (!ptrans) {
-    ptrans = find_transporter_for_unit(pcargo, pcargo->tile);
+    ptrans = find_transporter_for_unit(pcargo);
   }
 
   if (can_client_issue_orders()
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
--- client/gui-gtk-2.0/citydlg.c	(revision 12614)
+++ client/gui-gtk-2.0/citydlg.c	(working copy)
@@ -2063,7 +2063,7 @@
       GINT_TO_POINTER(punit->id));
     gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
-    if (!can_unit_load(punit, find_transporter_for_unit(punit, punit->tile))) {
+    if (!find_transporter_for_unit(punit)) {
       gtk_widget_set_sensitive(item, FALSE);
     }
 
Index: client/gui-win32/menu.c
===================================================================
--- client/gui-win32/menu.c	(revision 12614)
+++ client/gui-win32/menu.c	(working copy)
@@ -1155,9 +1155,7 @@
 		     !unit_flag(punit, F_UNDISBANDABLE));
       my_enable_menu(menu, IDM_ORDERS_HOMECITY,
 		     can_unit_change_homecity(punit));
-      my_enable_menu(menu, IDM_ORDERS_LOAD,
-	can_unit_load(punit, find_transporter_for_unit(punit,
-						       punit->tile)));
+      my_enable_menu(menu, IDM_ORDERS_LOAD, find_transporter_for_unit(punit));
       my_enable_menu(menu, IDM_ORDERS_UNLOAD,
 	(can_unit_unload(punit, find_unit_by_id(punit->transported_by))
 	 && can_unit_exist_at_tile(punit, punit->tile)) 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to