From b429443e0567134f153a6af1d9a7e1a6977b55f6 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 3 Oct 2023 00:38:04 +0300 Subject: [PATCH 24/24] Cache territory claiming base types See osdn #47345 Signed-off-by: Marko Lindqvist --- client/packhand.c | 5 +++++ common/borders.c | 26 ++++++++++++++------------ common/extras.c | 12 ++++++++++++ common/extras.h | 1 + server/ruleset.c | 5 +++++ 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/client/packhand.c b/client/packhand.c index 5c4222a431..d4d273a5b3 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -4096,6 +4096,11 @@ void handle_ruleset_extra(const struct packet_ruleset_extra *p) pextra->native_to = p->native_to; pextra->flags = p->flags; + + if (is_extra_caused_by(pextra, EC_BASE) + && territory_claiming_base(extra_base_get(pextra))) { + extra_type_list_append(extra_type_list_of_terr_claimers(), pextra); + } pextra->hidden_by = p->hidden_by; pextra->conflicts = p->conflicts; diff --git a/common/borders.c b/common/borders.c index 8987b0b961..600f67380c 100644 --- a/common/borders.c +++ b/common/borders.c @@ -48,14 +48,16 @@ int tile_border_source_radius_sq(struct tile *ptile) radius_sq += MIN(city_size_get(pcity), CITY_MAP_MAX_RADIUS_SQ) * game.info.border_size_effect; } else { - extra_type_by_cause_iterate(EC_BASE, pextra) { - struct base_type *pbase = extra_base_get(pextra); + struct extra_type_list *terr_claimers = extra_type_list_of_terr_claimers(); + + extra_type_list_iterate(terr_claimers, pextra) { + if (tile_has_extra(ptile, pextra)) { + struct base_type *pbase = extra_base_get(pextra); - if (tile_has_extra(ptile, pextra) && territory_claiming_base(pbase)) { radius_sq = pbase->border_sq; break; } - } extra_type_by_cause_iterate_end; + } extra_type_list_iterate_end; } return radius_sq; @@ -78,14 +80,14 @@ int tile_border_source_strength(struct tile *ptile) if (pcity) { strength = city_size_get(pcity) + 2; } else { - extra_type_by_cause_iterate(EC_BASE, pextra) { - struct base_type *pbase = extra_base_get(pextra); + struct extra_type_list *terr_claimers = extra_type_list_of_terr_claimers(); - if (tile_has_extra(ptile, pextra) && territory_claiming_base(pbase)) { + extra_type_list_iterate(terr_claimers, pextra) { + if (tile_has_extra(ptile, pextra)) { strength = 1; break; } - } extra_type_by_cause_iterate_end; + } extra_type_list_iterate_end; } return strength; @@ -116,13 +118,13 @@ bool is_border_source(struct tile *ptile) } if (extra_owner(ptile) != NULL) { - extra_type_by_cause_iterate(EC_BASE, pextra) { - struct base_type *pbase = extra_base_get(pextra); + struct extra_type_list *terr_claimers = extra_type_list_of_terr_claimers(); - if (tile_has_extra(ptile, pextra) && territory_claiming_base(pbase)) { + extra_type_list_iterate(terr_claimers, pextra) { + if (tile_has_extra(ptile, pextra)) { return TRUE; } - } extra_type_by_cause_iterate_end; + } extra_type_list_iterate_end; } return FALSE; diff --git a/common/extras.c b/common/extras.c index a8bae36b8e..3c730f7af9 100644 --- a/common/extras.c +++ b/common/extras.c @@ -35,6 +35,7 @@ static struct user_flag user_extra_flags[MAX_NUM_USER_EXTRA_FLAGS]; static struct extra_type_list *caused_by[EC_LAST]; static struct extra_type_list *removed_by[ERM_COUNT]; static struct extra_type_list *unit_hidden; +static struct extra_type_list *terr_claimer; /**************************************************************************** Initialize extras structures. @@ -50,6 +51,7 @@ void extras_init(void) removed_by[i] = extra_type_list_new(); } unit_hidden = extra_type_list_new(); + terr_claimer = extra_type_list_new(); for (i = 0; i < MAX_EXTRA_TYPES; i++) { requirement_vector_init(&(extras[i].reqs)); @@ -109,6 +111,8 @@ void extras_free(void) extra_type_list_destroy(unit_hidden); unit_hidden = NULL; + extra_type_list_destroy(terr_claimer); + terr_claimer = NULL; for (i = 0; i < MAX_EXTRA_TYPES; i++) { requirement_vector_free(&(extras[i].reqs)); @@ -244,6 +248,14 @@ struct extra_type_list *extra_type_list_of_unit_hiders(void) return unit_hidden; } +/************************************************************************** + Returns extra types that claim terrain +**************************************************************************/ +struct extra_type_list *extra_type_list_of_terr_claimers(void) +{ + return terr_claimer; +} + /************************************************************************** Return random extra type for given cause that is native to the tile. **************************************************************************/ diff --git a/common/extras.h b/common/extras.h index b70b930ef7..374ec006f5 100644 --- a/common/extras.h +++ b/common/extras.h @@ -183,6 +183,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_terr_claimers(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/server/ruleset.c b/server/ruleset.c index 2437f88485..d99c1fb627 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -3651,6 +3651,11 @@ static bool load_ruleset_terrain(struct section_file *file, ok = FALSE; } + if (is_extra_caused_by(pextra, EC_BASE) + && territory_claiming_base(extra_base_get(pextra))) { + extra_type_list_append(extra_type_list_of_terr_claimers(), pextra); + } + if (!ok) { break; } -- 2.40.1