From f9356094c6aae60dee29d8baf682c71be26db63f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 3 Oct 2023 00:28:52 +0300 Subject: [PATCH 50/50] Cache territory claiming base types See osdn #47345 Signed-off-by: Marko Lindqvist --- client/packhand.c | 4 ++++ common/actions.c | 9 +++------ common/borders.c | 28 +++++++++++++++------------- common/extras.c | 12 ++++++++++++ common/extras.h | 1 + server/ruleset.c | 5 +++++ 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/client/packhand.c b/client/packhand.c index 08b237874a..783063484c 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -4283,6 +4283,10 @@ void handle_ruleset_extra(const struct packet_ruleset_extra *p) if (extra_has_flag(pextra, EF_CAUSE_ZOC)) { extra_type_list_append(extra_type_list_of_zoccers(), pextra); } + 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->bridged_over = p->bridged_over; pextra->conflicts = p->conflicts; diff --git a/common/actions.c b/common/actions.c index 01ca7884e8..79abe2962b 100644 --- a/common/actions.c +++ b/common/actions.c @@ -2419,12 +2419,9 @@ action_actor_utype_hard_reqs_ok_full(const struct action *paction, break; } extra_type_list_iterate_end; } else { - extra_type_by_cause_iterate(EC_BASE, pextra) { - if (!territory_claiming_base(pextra->data.base)) { - /* Hard requirement */ - continue; - } + struct extra_type_list *terr_claimers = extra_type_list_of_terr_claimers(); + extra_type_list_iterate(terr_claimers, pextra) { if (!is_native_extra_to_uclass(pextra, pclass)) { /* Hard requirement */ continue; @@ -2432,7 +2429,7 @@ action_actor_utype_hard_reqs_ok_full(const struct action *paction, has_target = TRUE; break; - } extra_type_by_cause_iterate_end; + } extra_type_list_iterate_end; } if (!has_target) { diff --git a/common/borders.c b/common/borders.c index 1603e9e40b..aefedd5490 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; @@ -79,15 +81,15 @@ int tile_border_source_strength(struct tile *ptile) strength = (city_size_get(pcity) + 2) * (100 + get_city_bonus(pcity, EFT_BORDER_STRENGTH_PCT)) / 100; } 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)) { - /* Base strength 100/100 = 1 */ + extra_type_list_iterate(terr_claimers, pextra) { + if (tile_has_extra(ptile, pextra)) { + /* Base strength 100 / 100 = 1 */ strength = (100 + get_tile_bonus(ptile, EFT_BORDER_STRENGTH_PCT)) / 100; break; } - } extra_type_by_cause_iterate_end; + } extra_type_list_iterate_end; } return strength; @@ -118,13 +120,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 0814a137f6..56d5e6e3fa 100644 --- a/common/extras.c +++ b/common/extras.c @@ -37,6 +37,7 @@ 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; +static struct extra_type_list *terr_claimer; /************************************************************************//** Initialize extras structures. @@ -54,6 +55,7 @@ void extras_init(void) cleanable = extra_type_list_new(); unit_hidden = extra_type_list_new(); zoccers = extra_type_list_new(); + terr_claimer = extra_type_list_new(); for (i = 0; i < MAX_EXTRA_TYPES; i++) { requirement_vector_init(&(extras[i].reqs)); @@ -118,6 +120,8 @@ void extras_free(void) unit_hidden = NULL; extra_type_list_destroy(zoccers); zoccers = NULL; + extra_type_list_destroy(terr_claimer); + terr_claimer = NULL; for (i = 0; i < MAX_EXTRA_TYPES; i++) { requirement_vector_free(&(extras[i].reqs)); @@ -265,6 +269,14 @@ struct extra_type_list *extra_type_list_of_zoccers(void) return zoccers; } +/************************************************************************//** + 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 7e03434832..7d189fecd2 100644 --- a/common/extras.h +++ b/common/extras.h @@ -198,6 +198,7 @@ struct extra_type *rand_extra_for_tile(struct tile *ptile, enum extra_cause caus struct extra_type_list *extra_type_list_of_unit_hiders(void); struct extra_type_list *extra_type_list_of_zoccers(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 46331c5363..1cd054cf73 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -3773,6 +3773,11 @@ static bool load_ruleset_terrain(struct section_file *file, extra_type_list_append(extra_type_list_of_zoccers(), pextra); } + 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