From 6ca00f328016c5a517c923338d53ed09a09ea767 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 7 Apr 2023 22:19:22 +0300 Subject: [PATCH 28/28] Stop transported units from causing ZoC Reported by bard See osdn #47656 Signed-off-by: Marko Lindqvist --- common/unit.c | 24 ++++++++++++++++-------- common/unit.h | 8 ++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/common/unit.c b/common/unit.c index 84265807a6..28a8421b39 100644 --- a/common/unit.c +++ b/common/unit.c @@ -1421,9 +1421,18 @@ bool is_my_zoc(const struct player *pplayer, const struct tile *ptile0, } } else { unit_list_iterate(ptile->units, punit) { - if (!pplayers_allied(unit_owner(punit), pplayer) - && !unit_has_type_flag(punit, UTYF_NOZOC)) { - return FALSE; + if (srv) { + if (!unit_transported_server(punit) + && !pplayers_allied(unit_owner(punit), pplayer) + && !unit_has_type_flag(punit, UTYF_NOZOC)) { + return FALSE; + } + } else { + if (!unit_transported_client(punit) + && !pplayers_allied(unit_owner(punit), pplayer) + && !unit_has_type_flag(punit, UTYF_NOZOC)) { + return FALSE; + } } } unit_list_iterate_end; } @@ -2315,12 +2324,11 @@ bool unit_transported(const struct unit *pcargo) /* The unit is transported if a transporter unit is set or, (for the client) * if the transported_by field is set. */ - if (pcargo->transporter != NULL - || (!is_server() && pcargo->client.transported_by != -1)) { - return TRUE; + if (is_server()) { + return unit_transported_server(pcargo); + } else { + return unit_transported_client(pcargo); } - - return FALSE; } /**********************************************************************//** diff --git a/common/unit.h b/common/unit.h index 8033391c12..84013cbe15 100644 --- a/common/unit.h +++ b/common/unit.h @@ -499,6 +499,14 @@ bool unit_transport_load(struct unit *pcargo, struct unit *ptrans, bool force); bool unit_transport_unload(struct unit *pcargo); struct unit *unit_transport_get(const struct unit *pcargo); + +#define unit_transported_server(_pcargo_) ((_pcargo_)->transporter != NULL) + +/* Evaluates parameter twice! */ +#define unit_transported_client(_pcargo_) \ + ((_pcargo_)->client.transported_by != -1 \ + || (_pcargo_)->transporter != NULL) + bool unit_transported(const struct unit *pcargo); struct unit_list *unit_transport_cargo(const struct unit *ptrans); bool unit_transport_check(const struct unit *pcargo, -- 2.39.2