From 4756fe731e76c03af07ca40473e78041660b4293 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 3 Oct 2023 00:33:47 +0300 Subject: [PATCH 36/36] Cache territory claiming base types See osdn #47345 Signed-off-by: Marko Lindqvist --- client/packhand.c | 4 ++++ common/actions.c | 9 +++------ common/borders.c | 26 ++++++++++++++------------ common/extras.c | 12 ++++++++++++ common/extras.h | 1 + server/ruleset.c | 5 +++++ 6 files changed, 39 insertions(+), 18 deletions(-) diff --git a/client/packhand.c b/client/packhand.c index b13e4cc3c4..44589395f9 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -4276,6 +4276,10 @@ void handle_ruleset_extra(const struct packet_ruleset_extra *p) if (extra_has_flag(pextra, EF_NOT_AGGRESSIVE)) { extra_to_caused_by_list(pextra, EC_NOT_AGGRESSIVE); } + 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 8c971c3dcc..252bd6924a 100644 --- a/common/actions.c +++ b/common/actions.c @@ -3412,12 +3412,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; @@ -3425,7 +3422,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 9f18350e3c..13e8cba1e8 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 c8271cf639..01c1a4ea06 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)); @@ -110,6 +112,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)); @@ -249,6 +253,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 de9c3bc87b..d7a7980d4b 100644 --- a/common/extras.h +++ b/common/extras.h @@ -191,6 +191,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 7b436b98b3..76272c8f35 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -3836,6 +3836,11 @@ static bool load_ruleset_terrain(struct section_file *file, extra_to_caused_by_list(pextra, EC_NOT_AGGRESSIVE); } + 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