From 414e58a53383dbc62c505bb47c1665892c3b3608 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 4 Dec 2022 15:33:46 +0200 Subject: [PATCH 36/36] Make movement.[ch] functions to respect their nmap parameter They had main map usage hardcoded for some subroutine calls. See osdn #46122 Signed-off-by: Marko Lindqvist --- common/aicore/pf_tools.c | 8 ++++---- common/movement.c | 25 ++++++++++++++----------- common/movement.h | 8 +++++--- server/citytools.c | 4 ++-- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/common/aicore/pf_tools.c b/common/aicore/pf_tools.c index 0078d45dc6..809c488ad6 100644 --- a/common/aicore/pf_tools.c +++ b/common/aicore/pf_tools.c @@ -248,7 +248,7 @@ pf_get_move_scope(const struct tile *ptile, || uclass_has_flag(uclass, UCF_BUILD_ANYWHERE) || is_native_near_tile(param->map, uclass, ptile) || (1 == game.info.citymindist - && is_city_channel_tile(uclass, ptile, NULL)))) { + && is_city_channel_tile(param->map, uclass, ptile, NULL)))) { scope |= PF_MS_CITY; } @@ -347,7 +347,7 @@ static inline bool pf_move_possible(const struct tile *src, if (PF_MS_NATIVE == dst_scope && (PF_MS_NATIVE & src_scope) - && !is_native_move(utype_class(param->utype), src, dst)) { + && !is_native_move(param->map, utype_class(param->utype), src, dst)) { return FALSE; } @@ -829,7 +829,7 @@ void pft_fill_utype_parameter(struct pf_parameter *parameter, Fill classic parameters for an unit. ****************************************************************************/ void pft_fill_unit_parameter(struct pf_parameter *parameter, - const struct unit *punit) + const struct unit *punit) { pft_fill_unit_default_parameter(parameter, punit); pft_fill_parameter(parameter, unit_type_get(punit)); @@ -878,7 +878,7 @@ void pft_fill_utype_overlap_param(struct pf_parameter *parameter, For sea/land bombardment and for ferries. ****************************************************************************/ void pft_fill_unit_overlap_param(struct pf_parameter *parameter, - const struct unit *punit) + const struct unit *punit) { pft_fill_unit_default_parameter(parameter, punit); pft_fill_overlap_param(parameter, unit_type_get(punit)); diff --git a/common/movement.c b/common/movement.c index e8abdaac3c..b7bef4d2ac 100644 --- a/common/movement.c +++ b/common/movement.c @@ -239,7 +239,8 @@ bool can_attack_from_non_native(const struct unit_type *utype) /************************************************************************//** Check for a city channel. ****************************************************************************/ -bool is_city_channel_tile(const struct unit_class *punitclass, +bool is_city_channel_tile(const struct civ_map *nmap, + const struct unit_class *punitclass, const struct tile *ptile, const struct tile *pexclude) { @@ -250,7 +251,7 @@ bool is_city_channel_tile(const struct unit_class *punitclass, dbv_init(&tile_processed, map_num_tiles()); for (;;) { dbv_set(&tile_processed, tile_index(ptile)); - adjc_iterate(&(wld.map), ptile, piter) { + adjc_iterate(nmap, ptile, piter) { if (dbv_isset(&tile_processed, tile_index(piter))) { continue; } else if (piter != pexclude @@ -276,6 +277,7 @@ bool is_city_channel_tile(const struct unit_class *punitclass, dbv_free(&tile_processed); tile_list_destroy(process_queue); + return found; } @@ -295,7 +297,7 @@ bool can_exist_at_tile(const struct civ_map *nmap, && (uclass_has_flag(utype_class(utype), UCF_BUILD_ANYWHERE) || is_native_near_tile(nmap, utype_class(utype), ptile) || (1 == game.info.citymindist - && is_city_channel_tile(utype_class(utype), ptile, NULL)))) { + && is_city_channel_tile(nmap, utype_class(utype), ptile, NULL)))) { return TRUE; } @@ -367,7 +369,8 @@ bool is_native_to_class(const struct unit_class *punitclass, moves, so that callers are responsible for checking for other sources of legal moves (e.g. cities, transports, etc.). ****************************************************************************/ -bool is_native_move(const struct unit_class *punitclass, +bool is_native_move(const struct civ_map *nmap, + const struct unit_class *punitclass, const struct tile *src_tile, const struct tile *dst_tile) { @@ -429,16 +432,16 @@ bool is_native_move(const struct unit_class *punitclass, return TRUE; case RMM_CARDINAL: /* Road connects source and destination if cardinal move. */ - if (is_move_cardinal(&(wld.map), src_tile, dst_tile)) { + if (is_move_cardinal(nmap, src_tile, dst_tile)) { return TRUE; } break; case RMM_RELAXED: - if (is_move_cardinal(&(wld.map), src_tile, dst_tile)) { + if (is_move_cardinal(nmap, src_tile, dst_tile)) { /* Cardinal moves have no between tiles, so connected. */ return TRUE; } - cardinal_between_iterate(&(wld.map), src_tile, dst_tile, between) { + cardinal_between_iterate(nmap, src_tile, dst_tile, between) { if (tile_has_extra(between, iextra) || (pextra != iextra && tile_has_extra(between, pextra))) { /* We have a link for the connection. @@ -553,7 +556,7 @@ bool can_step_taken_wrt_to_zoc(const struct unit_type *punittype, } return (is_my_zoc(unit_owner, src_tile, zmap) - || is_my_zoc(unit_owner, dst_tile, zmap)); + || is_my_zoc(unit_owner, dst_tile, zmap)); } /************************************************************************//** @@ -699,7 +702,7 @@ unit_move_to_tile_test(const struct civ_map *nmap, /* 11) */ if (utype_has_flag(punittype, UTYF_COAST_STRICT) - && !pcity && !is_safe_ocean(&(wld.map), dst_tile)) { + && !pcity && !is_safe_ocean(nmap, dst_tile)) { return MR_TRIREME; } @@ -716,7 +719,7 @@ unit_move_to_tile_test(const struct civ_map *nmap, } /* 14) */ - if (!(is_native_move(utype_class(punittype), src_tile, dst_tile) + if (!(is_native_move(nmap, utype_class(punittype), src_tile, dst_tile) /* Allow non-native moves into cities or boarding transport. */ || pcity || unit_could_load_at(punit, dst_tile))) { @@ -809,7 +812,7 @@ unit_teleport_to_tile_test(const struct civ_map *nmap, /* 6) */ if (utype_has_flag(punittype, UTYF_COAST_STRICT) - && !pcity && !is_safe_ocean(&(wld.map), dst_tile)) { + && !pcity && !is_safe_ocean(nmap, dst_tile)) { return MR_TRIREME; } diff --git a/common/movement.h b/common/movement.h index 6aae1bafe3..c1bd1fe584 100644 --- a/common/movement.h +++ b/common/movement.h @@ -64,7 +64,8 @@ bool can_attack_non_native_hard_reqs(const struct unit_type *utype); bool can_attack_non_native(const struct unit_type *utype); bool can_attack_from_non_native(const struct unit_type *utype); -bool is_city_channel_tile(const struct unit_class *punitclass, +bool is_city_channel_tile(const struct civ_map *nmap, + const struct unit_class *punitclass, const struct tile *ptile, const struct tile *pexclude); @@ -87,7 +88,8 @@ static inline bool is_native_tile_to_class(const struct unit_class *punitclass, tile_extras(ptile)); } -bool is_native_move(const struct unit_class *punitclass, +bool is_native_move(const struct civ_map *nmap, + const struct unit_class *punitclass, const struct tile *src_tile, const struct tile *dst_tile); bool is_native_near_tile(const struct civ_map *nmap, @@ -145,4 +147,4 @@ const char *move_points_text(int mp, bool reduce); } #endif /* __cplusplus */ -#endif /* FC__MOVEMENT_H */ +#endif /* FC__MOVEMENT_H */ diff --git a/server/citytools.c b/server/citytools.c index fff72c22d8..163baae1c0 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -1715,7 +1715,7 @@ void remove_city(struct city *pcity) } } unit_list_iterate_safe_end; - /* make sure ships are not left on land when city is removed. */ + /* Make sure ships are not left on land when city is removed. */ unit_list_iterate_safe(pcenter->units, punit) { bool moved; const struct unit_type *punittype = unit_type_get(punit); @@ -1789,7 +1789,7 @@ void remove_city(struct city *pcity) if (!uclass_has_flag(pclass, UCF_BUILD_ANYWHERE) && !is_native_tile(punit->utype, piter) - && !is_city_channel_tile(pclass, piter, pcenter)) { + && !is_city_channel_tile(&(wld.map), pclass, piter, pcenter)) { notify_player(unit_owner(punit), unit_tile(punit), E_UNIT_LOST_MISC, ftc_server, _("When %s was disbanded your %s in %s was trapped, " -- 2.35.1