From 8dc63a7c757fb78cf06bbed84f568b74e670d6a4 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 13 Feb 2023 02:25:04 +0200 Subject: [PATCH 17/17] Add unit class native_bases cache See osdn #46417 Signed-off-by: Marko Lindqvist --- client/helpdata.c | 3 ++- common/tile.c | 18 ++++++++---------- common/unittype.c | 9 +++++++++ common/unittype.h | 1 + 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/client/helpdata.c b/client/helpdata.c index f7e9454c14..2824807eea 100644 --- a/client/helpdata.c +++ b/client/helpdata.c @@ -3446,7 +3446,8 @@ void helptext_extra(char *buf, size_t bufsz, struct player *pplayer, _("Build by issuing a \"road\" order.\n")); } if (is_extra_caused_by(pextra, EC_BASE)) { - fc_assert(pbase); + fc_assert(pbase != NULL); + if (pbase->gui_type == BASE_GUI_OTHER) { cat_snprintf(buf, bufsz, _("Build by issuing a \"build base\" order.\n")); diff --git a/common/tile.c b/common/tile.c index 5f28eb6a2f..b0b67aa3b3 100644 --- a/common/tile.c +++ b/common/tile.c @@ -233,20 +233,19 @@ bool tile_has_base_flag_for_unit(const struct tile *ptile, } /**************************************************************************** - Check if tile contains base providing effect for unit + Check if tile contains base providing effect for unit. ****************************************************************************/ bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype) { - extra_type_by_cause_iterate(EC_BASE, pextra) { + extra_type_list_iterate(utype_class(punittype)->cache.native_bases, pextra) { struct base_type *pbase = extra_base_get(pextra); if (tile_has_extra(ptile, pextra) - && territory_claiming_base(pbase) - && is_native_extra_to_uclass(pextra, utype_class(punittype))) { + && territory_claiming_base(pbase)) { return TRUE; } - } extra_type_by_cause_iterate_end; + } extra_type_list_iterate_end; return FALSE; } @@ -343,17 +342,16 @@ bool tile_has_refuel_extra(const struct tile *ptile, } /**************************************************************************** - Check if tile contains base native for unit + Check if tile contains base native for unit. ****************************************************************************/ bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype) { - extra_type_by_cause_iterate(EC_BASE, pextra) { - if (tile_has_extra(ptile, pextra) - && is_native_extra_to_utype(pextra, punittype)) { + extra_type_list_iterate(utype_class(punittype)->cache.native_bases, 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/unittype.c b/common/unittype.c index 96874c187e..65bf509455 100644 --- a/common/unittype.c +++ b/common/unittype.c @@ -1871,6 +1871,7 @@ void unit_classes_init(void) unit_classes[i].item_number = i; unit_classes[i].cache.refuel_extras = NULL; unit_classes[i].cache.native_tile_extras = NULL; + unit_classes[i].cache.native_bases = NULL; unit_classes[i].cache.bonus_roads = NULL; unit_classes[i].cache.subset_movers = NULL; unit_classes[i].helptext = NULL; @@ -1894,6 +1895,10 @@ void unit_classes_free(void) extra_type_list_destroy(unit_classes[i].cache.native_tile_extras); unit_classes[i].cache.native_tile_extras = NULL; } + if (unit_classes[i].cache.native_bases != NULL) { + extra_type_list_destroy(unit_classes[i].cache.native_bases); + unit_classes[i].cache.native_bases = NULL; + } if (unit_classes[i].cache.bonus_roads != NULL) { extra_type_list_destroy(unit_classes[i].cache.bonus_roads); unit_classes[i].cache.bonus_roads = NULL; @@ -2059,6 +2064,7 @@ void set_unit_class_caches(struct unit_class *pclass) { pclass->cache.refuel_extras = extra_type_list_new(); pclass->cache.native_tile_extras = extra_type_list_new(); + pclass->cache.native_bases = extra_type_list_new(); pclass->cache.bonus_roads = extra_type_list_new(); pclass->cache.subset_movers = unit_class_list_new(); @@ -2072,6 +2078,9 @@ void set_unit_class_caches(struct unit_class *pclass) if (extra_has_flag(pextra, EF_NATIVE_TILE)) { extra_type_list_append(pclass->cache.native_tile_extras, pextra); } + if (is_extra_caused_by(pextra, EC_BASE)) { + extra_type_list_append(pclass->cache.native_bases, pextra); + } if (proad != NULL && road_provides_move_bonus(proad)) { extra_type_list_append(pclass->cache.bonus_roads, pextra); } diff --git a/common/unittype.h b/common/unittype.h index 6915516c00..234572e77b 100644 --- a/common/unittype.h +++ b/common/unittype.h @@ -150,6 +150,7 @@ struct unit_class { struct { struct extra_type_list *refuel_extras; struct extra_type_list *native_tile_extras; + struct extra_type_list *native_bases; struct extra_type_list *bonus_roads; struct unit_class_list *subset_movers; } cache; -- 2.39.1