From 5d46b116bd73c39d171aaa5fd718d17e46e8e502 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 2 Nov 2022 03:23:46 +0200 Subject: [PATCH 52/52] pf_attack_possible(): Consider UTYF_NEVER_PROTECTS Also, no unit is unreachable in a city Patch by lexxie9952 See osdn #46024 Signed-off-by: Marko Lindqvist --- common/aicore/pf_tools.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/common/aicore/pf_tools.c b/common/aicore/pf_tools.c index 1b719f2b8d..0078d45dc6 100644 --- a/common/aicore/pf_tools.c +++ b/common/aicore/pf_tools.c @@ -46,6 +46,7 @@ static inline bool pf_attack_possible(const struct tile *ptile, enum known_type known, const struct pf_parameter *param) { + bool non_allied_city; bool attack_any; if (!can_attack_non_native(param->utype) @@ -58,19 +59,28 @@ static inline bool pf_attack_possible(const struct tile *ptile, return TRUE; } + non_allied_city = is_non_allied_city_tile(ptile, param->owner); attack_any = FALSE; + unit_list_iterate(ptile->units, punit) { + /* Any non-hostile unit will fail the whole stack*/ if (!pplayers_at_war(unit_owner(punit), param->owner)) { return FALSE; } - /* Unit reachability test. */ + /* Hostile unit reachability test. */ if (BV_ISSET(param->utype->targets, uclass_index(unit_class_get(punit))) - || tile_has_native_base(ptile, unit_type_get(punit))) { + || tile_has_native_base(ptile, unit_type_get(punit)) + || non_allied_city) { attack_any = TRUE; } else if (game.info.unreachable_protects) { - /* We would need to be able to attack all, this is not the case. */ - return FALSE; + /* We get here if punit is unreachable to utype */ + if (!utype_has_flag(unit_type_get(punit), UTYF_NEVER_PROTECTS)) { + return FALSE; + } + /* NB: if there are UTYF_NEVER_PROTECTS units on the tile, 'attack_any' + has to get set TRUE at least once to enable an attack to the tile, + which is exactly correct behaviour. */ } } unit_list_iterate_end; -- 2.35.1