From d046aaa262dfb3a83743d1d18407520b949647e6 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 15 Sep 2023 15:40:00 +0300 Subject: [PATCH 17/17] Add support for ZoC imposing extras See osdn #47701 Signed-off-by: Marko Lindqvist --- client/packhand.c | 3 +++ common/extras.c | 12 ++++++++++++ common/extras.h | 26 +++++++++++++++----------- common/unit.c | 20 ++++++++++++++++++++ server/ruleset.c | 4 ++++ 5 files changed, 54 insertions(+), 11 deletions(-) diff --git a/client/packhand.c b/client/packhand.c index e1be57905c..9d6cd04e72 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -4258,6 +4258,9 @@ void handle_ruleset_extra(const struct packet_ruleset_extra *p) if (pextra->no_aggr_near_city >= 0) { extra_to_caused_by_list(pextra, EC_NOT_AGGRESSIVE); } + if (extra_has_flag(pextra, EF_CAUSE_ZOC)) { + extra_type_list_append(extra_type_list_of_zoccers(), pextra); + } pextra->hidden_by = p->hidden_by; pextra->bridged_over = p->bridged_over; pextra->conflicts = p->conflicts; diff --git a/common/extras.c b/common/extras.c index 96463e8f37..0814a137f6 100644 --- a/common/extras.c +++ b/common/extras.c @@ -36,6 +36,7 @@ static struct extra_type_list *caused_by[EC_LAST]; static struct extra_type_list *removed_by[ERM_COUNT]; static struct extra_type_list *cleanable; static struct extra_type_list *unit_hidden; +static struct extra_type_list *zoccers; /************************************************************************//** Initialize extras structures. @@ -52,6 +53,7 @@ void extras_init(void) } cleanable = extra_type_list_new(); unit_hidden = extra_type_list_new(); + zoccers = extra_type_list_new(); for (i = 0; i < MAX_EXTRA_TYPES; i++) { requirement_vector_init(&(extras[i].reqs)); @@ -114,6 +116,8 @@ void extras_free(void) cleanable = NULL; extra_type_list_destroy(unit_hidden); unit_hidden = NULL; + extra_type_list_destroy(zoccers); + zoccers = NULL; for (i = 0; i < MAX_EXTRA_TYPES; i++) { requirement_vector_free(&(extras[i].reqs)); @@ -253,6 +257,14 @@ struct extra_type_list *extra_type_list_of_unit_hiders(void) return unit_hidden; } +/************************************************************************//** + Returns extra types that cauze ZoC by themselves. +****************************************************************************/ +struct extra_type_list *extra_type_list_of_zoccers(void) +{ + return zoccers; +} + /************************************************************************//** Return random extra type for given cause that is native to the tile. ****************************************************************************/ diff --git a/common/extras.h b/common/extras.h index 0b70457009..7e03434832 100644 --- a/common/extras.h +++ b/common/extras.h @@ -59,17 +59,20 @@ struct road_type; /* Units inside will not die all at once */ #define SPECENUM_VALUE10 EF_NO_STACK_DEATH #define SPECENUM_VALUE10NAME N_("NoStackDeath") - -#define SPECENUM_VALUE11 EF_USER_FLAG_1 -#define SPECENUM_VALUE12 EF_USER_FLAG_2 -#define SPECENUM_VALUE13 EF_USER_FLAG_3 -#define SPECENUM_VALUE14 EF_USER_FLAG_4 -#define SPECENUM_VALUE15 EF_USER_FLAG_5 -#define SPECENUM_VALUE16 EF_USER_FLAG_6 -#define SPECENUM_VALUE17 EF_USER_FLAG_7 -#define SPECENUM_VALUE18 EF_USER_FLAG_8 -#define SPECENUM_VALUE19 EF_USER_FLAG_9 -#define SPECENUM_VALUE20 EF_USER_FLAG_10 +/* Extra itself makes tile to be considered extra owners ZoC */ +#define SPECENUM_VALUE11 EF_CAUSE_ZOC +#define SPECENUM_VALUE11NAME N_("CauseZoC") + +#define SPECENUM_VALUE12 EF_USER_FLAG_1 +#define SPECENUM_VALUE13 EF_USER_FLAG_2 +#define SPECENUM_VALUE14 EF_USER_FLAG_3 +#define SPECENUM_VALUE15 EF_USER_FLAG_4 +#define SPECENUM_VALUE16 EF_USER_FLAG_5 +#define SPECENUM_VALUE17 EF_USER_FLAG_6 +#define SPECENUM_VALUE18 EF_USER_FLAG_7 +#define SPECENUM_VALUE19 EF_USER_FLAG_8 +#define SPECENUM_VALUE20 EF_USER_FLAG_9 +#define SPECENUM_VALUE21 EF_USER_FLAG_10 #define SPECENUM_COUNT EF_COUNT #define SPECENUM_NAMEOVERRIDE @@ -194,6 +197,7 @@ struct extra_type *rand_extra_for_tile(struct tile *ptile, enum extra_cause caus bool generated); struct extra_type_list *extra_type_list_of_unit_hiders(void); +struct extra_type_list *extra_type_list_of_zoccers(void); #define is_extra_caused_by(e, c) (e->causes & (1 << c)) bool is_extra_caused_by_worker_action(const struct extra_type *pextra); diff --git a/common/unit.c b/common/unit.c index 99ab82421f..416ec27bfe 100644 --- a/common/unit.c +++ b/common/unit.c @@ -1375,6 +1375,8 @@ struct unit *unit_occupies_tile(const struct tile *ptile, bool is_plr_zoc_srv(const struct player *pplayer, const struct tile *ptile0, const struct civ_map *zmap) { + struct extra_type_list *zoccers = extra_type_list_of_zoccers(); + square_iterate(zmap, ptile0, 1, ptile) { struct terrain *pterrain; struct city *pcity; @@ -1392,6 +1394,14 @@ bool is_plr_zoc_srv(const struct player *pplayer, const struct tile *ptile0, return FALSE; } } else { + if (!pplayers_allied(extra_owner(ptile), pplayer)) { + extra_type_list_iterate(zoccers, pextra) { + if (tile_has_extra(ptile, pextra)) { + return FALSE; + } + } extra_type_list_iterate_end; + } + unit_list_iterate(ptile->units, punit) { if (!pplayers_allied(unit_owner(punit), pplayer) && !unit_has_type_flag(punit, UTYF_NOZOC) @@ -1434,6 +1444,8 @@ bool is_plr_zoc_srv(const struct player *pplayer, const struct tile *ptile0, bool is_plr_zoc_client(const struct player *pplayer, const struct tile *ptile0, const struct civ_map *zmap) { + struct extra_type_list *zoccers = extra_type_list_of_zoccers(); + square_iterate(zmap, ptile0, 1, ptile) { struct terrain *pterrain; struct city *pcity; @@ -1453,6 +1465,14 @@ bool is_plr_zoc_client(const struct player *pplayer, const struct tile *ptile0, return FALSE; } } else { + if (!pplayers_allied(extra_owner(ptile), pplayer)) { + extra_type_list_iterate(zoccers, pextra) { + if (tile_has_extra(ptile, pextra)) { + return FALSE; + } + } extra_type_list_iterate_end; + } + unit_list_iterate(ptile->units, punit) { if (!unit_transported_client(punit) && !pplayers_allied(unit_owner(punit), pplayer) diff --git a/server/ruleset.c b/server/ruleset.c index ff91834534..09f4254b54 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -3764,6 +3764,10 @@ static bool load_ruleset_terrain(struct section_file *file, extra_to_caused_by_list(pextra, EC_NOT_AGGRESSIVE); } + if (extra_has_flag(pextra, EF_CAUSE_ZOC)) { + extra_type_list_append(extra_type_list_of_zoccers(), pextra); + } + if (!ok) { break; } -- 2.40.1