Author: jtn
Date: Tue Jun 17 00:00:03 2014
New Revision: 25165

URL: http://svn.gna.org/viewcvs/freeciv?rev=25165&view=rev
Log:
When choosing a transporter for a unit, prefer less deeply nested ones,
then ones with more move points.

See gna bug #22189.

Modified:
    branches/S2_5/client/control.c
    branches/S2_5/common/unit.c

Modified: branches/S2_5/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/control.c?rev=25165&r1=25164&r2=25165&view=diff
==============================================================================
--- branches/S2_5/client/control.c      (original)
+++ branches/S2_5/client/control.c      Tue Jun 17 00:00:03 2014
@@ -1648,7 +1648,7 @@
 /****************************************************************************
   Send a request to the server that the cargo be loaded into the transporter.
 
-  If ptransporter is NULL a transporter will be picked at random.
+  If ptransporter is NULL a suitable transporter will be chosen.
 ****************************************************************************/
 void request_unit_load(struct unit *pcargo, struct unit *ptrans)
 {

Modified: branches/S2_5/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/unit.c?rev=25165&r1=25164&r2=25165&view=diff
==============================================================================
--- branches/S2_5/common/unit.c (original)
+++ branches/S2_5/common/unit.c Tue Jun 17 00:00:03 2014
@@ -1999,15 +1999,24 @@
 ****************************************************************************/
 struct unit *transporter_for_unit(const struct unit *pcargo)
 {
-  struct tile *ptile = unit_tile(pcargo);
-
-  unit_list_iterate(ptile->units, ptrans) {
+  struct unit_list *tile_units = unit_tile(pcargo)->units;
+  struct unit *best = NULL;
+  int bestdepth = 0; /* initialiser doesn't matter */
+
+  unit_list_iterate(tile_units, ptrans) {
     if (can_unit_load(pcargo, ptrans)) {
-      return ptrans;
+      int depth = unit_transport_depth(ptrans);
+      if (!best || depth < bestdepth) {
+        best = ptrans;
+        bestdepth = depth;
+      } else if (depth == bestdepth
+                 && ptrans->moves_left > best->moves_left) {
+        best = ptrans;
+      }
     }
   } unit_list_iterate_end;
 
-  return NULL;
+  return best;
 }
 
 /****************************************************************************


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to