From 60b86bbf67653df8e48f3138ccc88a378c498d58 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 2 Sep 2023 23:01:43 +0300 Subject: [PATCH 18/18] Stop units hidden by extras imposing ZoC Requested by bard See osdn #47700 Signed-off-by: Marko Lindqvist --- common/unit.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/common/unit.c b/common/unit.c index 81d7e25b07..99ab82421f 100644 --- a/common/unit.c +++ b/common/unit.c @@ -1388,15 +1388,30 @@ bool is_plr_zoc_srv(const struct player *pplayer, const struct tile *ptile0, if (pcity != NULL) { if (unit_list_size(ptile->units) > 0) { /* Occupied enemy city, it doesn't matter if units inside have - * UTYF_NOZOC or not. Fogged city is assumed to be occupied. */ + * UTYF_NOZOC or not. */ return FALSE; } } else { unit_list_iterate(ptile->units, punit) { - if (!unit_transported_server(punit) - && !pplayers_allied(unit_owner(punit), pplayer) - && !unit_has_type_flag(punit, UTYF_NOZOC)) { - return FALSE; + if (!pplayers_allied(unit_owner(punit), pplayer) + && !unit_has_type_flag(punit, UTYF_NOZOC) + && !unit_transported_server(punit)) { + bool hidden = FALSE; + + /* We do NOT check the possibility that player is allied with an extra owner, + * and should thus see inside the extra. + * This is to avoid the situation where having an alliance with third player + * suddenly causes ZoC from a unit that would not cause it without the alliance. */ + extra_type_list_iterate(unit_class_get(punit)->cache.hiding_extras, pextra) { + if (tile_has_extra(ptile, pextra)) { + hidden = TRUE; + break; + } + } extra_type_list_iterate_end; + + if (!hidden) { + return FALSE; + } } } unit_list_iterate_end; } -- 2.40.1