Author: pepeto Date: Sat Jul 19 11:14:15 2014 New Revision: 25619 URL: http://svn.gna.org/viewcvs/freeciv?rev=25619&view=rev Log: Really take in account embark/disembark restriction rules when moving. It was resulting units standing on undesirable tiles. Prefer transport_from_tile() to unit_class_transporter_capacity().
See gna bug #22299 Modified: branches/S2_5/ai/default/aiair.c branches/S2_5/common/movement.c branches/S2_5/common/movement.h branches/S2_5/common/unit.c branches/S2_5/server/unittools.c branches/S2_5/server/unittools.h Modified: branches/S2_5/ai/default/aiair.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/ai/default/aiair.c?rev=25619&r1=25618&r2=25619&view=diff ============================================================================== --- branches/S2_5/ai/default/aiair.c (original) +++ branches/S2_5/ai/default/aiair.c Sat Jul 19 11:14:15 2014 @@ -56,7 +56,6 @@ struct pf_path **path) { struct player *pplayer = unit_owner(punit); - const struct unit_type *punittype = unit_type(punit); struct pf_parameter parameter; struct pf_map *pfm; @@ -69,7 +68,7 @@ break; } - if (is_airunit_refuel_point(ptile, pplayer, punittype, FALSE)) { + if (is_airunit_refuel_point(ptile, pplayer, punit)) { if (path) { *path = pf_map_path(pfm, ptile); } @@ -265,8 +264,7 @@ break; /* Too far! */ } - if (!is_airunit_refuel_point(ptile, pplayer, - unit_type(punit), FALSE)) { + if (!is_airunit_refuel_point(ptile, pplayer, punit)) { continue; /* Cannot refuel here. */ } @@ -338,8 +336,7 @@ /* We are on a GOTO. Check if it will get us anywhere */ && NULL != punit->goto_tile && !same_pos(unit_tile(punit), punit->goto_tile) - && is_airunit_refuel_point(punit->goto_tile, - pplayer, unit_type(punit), FALSE)) { + && is_airunit_refuel_point(punit->goto_tile, pplayer, punit)) { pfm = pf_map_new(¶meter); path = pf_map_path(pfm, punit->goto_tile); if (path) { Modified: branches/S2_5/common/movement.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/movement.c?rev=25619&r1=25618&r2=25619&view=diff ============================================================================== --- branches/S2_5/common/movement.c (original) +++ branches/S2_5/common/movement.c Sat Jul 19 11:14:15 2014 @@ -485,8 +485,7 @@ /* 4) */ if (!(can_exist_at_tile(punittype, dst_tile) - || unit_class_transporter_capacity(dst_tile, puowner, - utype_class(punittype)) > 0)) { + || NULL != transport_from_tile(punit, dst_tile))) { return MR_NO_TRANSPORTER_CAPACITY; } @@ -583,7 +582,8 @@ Search transport suitable for given unit from tile. It has to have free space in it. **************************************************************************/ -struct unit *transport_from_tile(struct unit *punit, struct tile *ptile) +struct unit *transport_from_tile(const struct unit *punit, + const struct tile *ptile) { unit_list_iterate(ptile->units, ptransport) { if (could_unit_load(punit, ptransport)) { Modified: branches/S2_5/common/movement.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/movement.h?rev=25619&r1=25618&r2=25619&view=diff ============================================================================== --- branches/S2_5/common/movement.h (original) +++ branches/S2_5/common/movement.h Sat Jul 19 11:14:15 2014 @@ -95,7 +95,8 @@ int unit_class_transporter_capacity(const struct tile *ptile, const struct player *pplayer, const struct unit_class *pclass); -struct unit *transport_from_tile(struct unit *punit, struct tile *ptile); +struct unit *transport_from_tile(const struct unit *punit, + const struct tile *ptile); void init_move_fragments(void); const char *move_points_text_full(int mp, bool reduce, const char *prefix, Modified: branches/S2_5/common/unit.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/unit.c?rev=25619&r1=25618&r2=25619&view=diff ============================================================================== --- branches/S2_5/common/unit.c (original) +++ branches/S2_5/common/unit.c Sat Jul 19 11:14:15 2014 @@ -2069,9 +2069,8 @@ } if (!can_type_transport_units_cargo(to_unittype, punit)) { - /* TODO: allow transported units to be reassigned. Check for - * unit_class_transporter_capacity() here and make changes to - * upgrade_unit. */ + /* TODO: allow transported units to be reassigned. Check here + * and make changes to upgrade_unit. */ return UU_NOT_ENOUGH_ROOM; } Modified: branches/S2_5/server/unittools.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/unittools.c?rev=25619&r1=25618&r2=25619&view=diff ============================================================================== --- branches/S2_5/server/unittools.c (original) +++ branches/S2_5/server/unittools.c Sat Jul 19 11:14:15 2014 @@ -412,9 +412,7 @@ break; } - if (is_airunit_refuel_point(ptile, pplayer, - unit_type(punit), FALSE)) { - + if (is_airunit_refuel_point(ptile, pplayer, punit)) { struct pf_path *path; int id = punit->id; @@ -1365,36 +1363,32 @@ /************************************************************************** Can unit refuel on tile. Considers also carrier capacity on tile. **************************************************************************/ -bool is_airunit_refuel_point(struct tile *ptile, struct player *pplayer, - const struct unit_type *type, - bool unit_is_on_carrier) -{ - int cap; - struct player_tile *plrtile = map_get_player_tile(ptile, pplayer); - - if (!is_non_allied_unit_tile(ptile, pplayer)) { - struct unit_class *pclass = utype_class(type); - - if (is_allied_city_tile(ptile, pplayer)) { - return TRUE; - } - - if (pclass->cache.refuel_bases != NULL) { - base_type_list_iterate(pclass->cache.refuel_bases, pbase) { - if (BV_ISSET(plrtile->bases, base_index(pbase))) { - return TRUE; - } - } base_type_list_iterate_end; - } - } - - cap = unit_class_transporter_capacity(ptile, pplayer, utype_class(type)); - - if (unit_is_on_carrier) { - cap++; - } - - return cap > 0; +bool is_airunit_refuel_point(const struct tile *ptile, + const struct player *pplayer, + const struct unit *punit) +{ + const struct unit_class *pclass; + + if (NULL != is_non_allied_unit_tile(ptile, pplayer)) { + return FALSE; + } + + if (NULL != is_allied_city_tile(ptile, pplayer)) { + return TRUE; + } + + pclass = unit_class(punit); + if (NULL != pclass->cache.refuel_bases) { + const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer); + + base_type_list_iterate(pclass->cache.refuel_bases, pbase) { + if (BV_ISSET(plrtile->bases, base_index(pbase))) { + return TRUE; + } + } base_type_list_iterate_end; + } + + return (NULL != transport_from_tile(punit, ptile)); } /************************************************************************** Modified: branches/S2_5/server/unittools.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/unittools.h?rev=25619&r1=25618&r2=25619&view=diff ============================================================================== --- branches/S2_5/server/unittools.h (original) +++ branches/S2_5/server/unittools.h Sat Jul 19 11:14:15 2014 @@ -82,9 +82,9 @@ /* move check related */ bool is_unit_being_refueled(const struct unit *punit); -bool is_airunit_refuel_point(struct tile *ptile, struct player *pplayer, - const struct unit_type *punittype, - bool unit_is_on_carrier); +bool is_airunit_refuel_point(const struct tile *ptile, + const struct player *pplayer, + const struct unit *punit); /* turn update related */ void player_restore_units(struct player *pplayer); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits