From 0d508d4fc0f8604f3ed1e263038e5667aae70c88 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 6 Jan 2023 11:23:15 +0200 Subject: [PATCH 15/15] tile_has_refuel_extra(): Use unit class refuel_extras cache - Cache renamed from 'refuel_bases' as 'refuel_extras' See osdn #46416 Signed-off-by: Marko Lindqvist --- common/aicore/pf_tools.c | 2 +- common/movement.c | 15 +++++++++------ common/tile.c | 12 +++++------- common/tile.h | 2 +- common/unittype.c | 12 ++++++------ common/unittype.h | 2 +- server/unittools.c | 12 +++++++----- 7 files changed, 30 insertions(+), 27 deletions(-) diff --git a/common/aicore/pf_tools.c b/common/aicore/pf_tools.c index 406dc223ef..324f5c3a80 100644 --- a/common/aicore/pf_tools.c +++ b/common/aicore/pf_tools.c @@ -557,7 +557,7 @@ static bool is_possible_base_fuel(const struct tile *ptile, } uclass = utype_class(param->utype); - extra_type_list_iterate(uclass->cache.refuel_bases, pextra) { + extra_type_list_iterate(uclass->cache.refuel_extras, pextra) { /* All airbases are considered possible, simply attack enemies. */ if (tile_has_extra(ptile, pextra)) { return TRUE; diff --git a/common/movement.c b/common/movement.c index f136b9740b..694822c054 100644 --- a/common/movement.c +++ b/common/movement.c @@ -418,17 +418,19 @@ bool is_native_near_tile(const struct unit_class *uclass, const struct tile *pti } /**************************************************************************** - Return TRUE iff the unit can "survive" at this location. This means it can + Return TRUE iff the unit can "survive" at this location. This means it can not only be physically present at the tile but will be able to survive indefinitely on its own (without a transporter). Units that require fuel - or have a danger of drowning are examples of non-survivable units. See - also can_unit_exist_at_tile(). + or have a danger of drowning are examples of non-survivable units. + See also can_unit_exist_at_tile(). (This function could be renamed as unit_wants_transporter().) ****************************************************************************/ bool can_unit_survive_at_tile(const struct unit *punit, const struct tile *ptile) { + const struct unit_type *utype; + if (!can_unit_exist_at_tile(punit, ptile)) { return FALSE; } @@ -437,17 +439,18 @@ bool can_unit_survive_at_tile(const struct unit *punit, return TRUE; } - if (tile_has_refuel_extra(ptile, unit_type_get(punit))) { + utype = unit_type_get(punit); + if (tile_has_refuel_extra(ptile, utype_class(utype))) { /* Unit can always survive at refueling base */ return TRUE; } - if (unit_has_type_flag(punit, UTYF_COAST) && is_safe_ocean(ptile)) { + if (utype_has_flag(utype, UTYF_COAST) && is_safe_ocean(ptile)) { /* Refueling coast */ return TRUE; } - if (utype_fuel(unit_type_get(punit))) { + if (utype_fuel(utype)) { /* Unit requires fuel and this is not refueling tile */ return FALSE; } diff --git a/common/tile.c b/common/tile.c index 29f9331f1e..5f28eb6a2f 100644 --- a/common/tile.c +++ b/common/tile.c @@ -328,18 +328,16 @@ int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o) } /**************************************************************************** - Check if tile contains refuel extra native for unit + Check if tile contains refuel extra native for unit class ****************************************************************************/ bool tile_has_refuel_extra(const struct tile *ptile, - const struct unit_type *punittype) + const struct unit_class *uclass) { - extra_type_iterate(pextra) { - if (tile_has_extra(ptile, pextra) - && extra_has_flag(pextra, EF_REFUEL) - && is_native_extra_to_utype(pextra, punittype)) { + extra_type_list_iterate(uclass->cache.refuel_extras, pextra) { + if (tile_has_extra(ptile, pextra)) { return TRUE; } - } extra_type_iterate_end; + } extra_type_list_iterate_end; return FALSE; } diff --git a/common/tile.h b/common/tile.h index 1711a45635..34156d0b7c 100644 --- a/common/tile.h +++ b/common/tile.h @@ -128,7 +128,7 @@ bool tile_has_base_flag_for_unit(const struct tile *ptile, const struct unit_type *punittype, enum base_flag_id flag); bool tile_has_refuel_extra(const struct tile *ptile, - const struct unit_type *punittype); + const struct unit_class *uclass); bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype); bool tile_has_claimable_base(const struct tile *ptile, diff --git a/common/unittype.c b/common/unittype.c index c09ea56f9f..96874c187e 100644 --- a/common/unittype.c +++ b/common/unittype.c @@ -1869,7 +1869,7 @@ void unit_classes_init(void) * num_unit_classes isn't known yet. */ for (i = 0; i < ARRAY_SIZE(unit_classes); i++) { unit_classes[i].item_number = i; - unit_classes[i].cache.refuel_bases = NULL; + unit_classes[i].cache.refuel_extras = NULL; unit_classes[i].cache.native_tile_extras = NULL; unit_classes[i].cache.bonus_roads = NULL; unit_classes[i].cache.subset_movers = NULL; @@ -1886,9 +1886,9 @@ void unit_classes_free(void) int i; for (i = 0; i < ARRAY_SIZE(unit_classes); i++) { - if (unit_classes[i].cache.refuel_bases != NULL) { - extra_type_list_destroy(unit_classes[i].cache.refuel_bases); - unit_classes[i].cache.refuel_bases = NULL; + if (unit_classes[i].cache.refuel_extras != NULL) { + extra_type_list_destroy(unit_classes[i].cache.refuel_extras); + unit_classes[i].cache.refuel_extras = NULL; } if (unit_classes[i].cache.native_tile_extras != NULL) { extra_type_list_destroy(unit_classes[i].cache.native_tile_extras); @@ -2057,7 +2057,7 @@ void utype_set_ai_data(struct unit_type *ptype, const struct ai_type *ai, ****************************************************************************/ void set_unit_class_caches(struct unit_class *pclass) { - pclass->cache.refuel_bases = extra_type_list_new(); + pclass->cache.refuel_extras = extra_type_list_new(); pclass->cache.native_tile_extras = extra_type_list_new(); pclass->cache.bonus_roads = extra_type_list_new(); pclass->cache.subset_movers = unit_class_list_new(); @@ -2067,7 +2067,7 @@ void set_unit_class_caches(struct unit_class *pclass) struct road_type *proad = extra_road_get(pextra); if (extra_has_flag(pextra, EF_REFUEL)) { - extra_type_list_append(pclass->cache.refuel_bases, pextra); + extra_type_list_append(pclass->cache.refuel_extras, pextra); } if (extra_has_flag(pextra, EF_NATIVE_TILE)) { extra_type_list_append(pclass->cache.native_tile_extras, pextra); diff --git a/common/unittype.h b/common/unittype.h index 421b279e8a..6915516c00 100644 --- a/common/unittype.h +++ b/common/unittype.h @@ -148,7 +148,7 @@ struct unit_class { } adv; struct { - struct extra_type_list *refuel_bases; + struct extra_type_list *refuel_extras; struct extra_type_list *native_tile_extras; struct extra_type_list *bonus_roads; struct unit_class_list *subset_movers; diff --git a/server/unittools.c b/server/unittools.c index 42b3c65550..69fd5de157 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -1458,21 +1458,23 @@ static bool is_refuel_tile(const struct tile *ptile, const struct player *pplayer, const struct unit *punit) { + const struct unit_type *utype; const struct unit_class *pclass; if (is_allied_city_tile(ptile, pplayer)) { return TRUE; } - if (unit_has_type_flag(punit, UTYF_COAST) && is_safe_ocean(ptile)) { + utype = unit_type_get(punit); + if (utype_has_flag(utype, UTYF_COAST) && is_safe_ocean(ptile)) { return TRUE; } - pclass = unit_class_get(punit); - if (NULL != pclass->cache.refuel_bases) { + pclass = utype_class(utype); + if (NULL != pclass->cache.refuel_extras) { const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer); - extra_type_list_iterate(pclass->cache.refuel_bases, pextra) { + extra_type_list_iterate(pclass->cache.refuel_extras, pextra) { if (BV_ISSET(plrtile->extras, extra_index(pextra))) { return TRUE; } @@ -1493,7 +1495,7 @@ void unit_tc_effect_refresh(struct player *pplayer) } /**********************************************************************//** - Is unit being refueled in its current position + Is unit being refueled in its current position? **************************************************************************/ bool is_unit_being_refueled(const struct unit *punit) { -- 2.39.0