Author: jtn Date: Mon Jun 16 23:57:09 2014 New Revision: 25158 URL: http://svn.gna.org/viewcvs/freeciv?rev=25158&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: trunk/client/control.c trunk/common/unit.c Modified: trunk/client/control.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/control.c?rev=25158&r1=25157&r2=25158&view=diff ============================================================================== --- trunk/client/control.c (original) +++ trunk/client/control.c Mon Jun 16 23:57:09 2014 @@ -1640,7 +1640,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: trunk/common/unit.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=25158&r1=25157&r2=25158&view=diff ============================================================================== --- trunk/common/unit.c (original) +++ trunk/common/unit.c Mon Jun 16 23:57:09 2014 @@ -1972,15 +1972,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