From 2fce4b90af0eaef7def5e2b136615efe12d5fe40 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 6 Jan 2023 10:56:23 +0200 Subject: [PATCH 38/38] 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 f31cfe508b..33624aac12 100644 --- a/common/aicore/pf_tools.c +++ b/common/aicore/pf_tools.c @@ -567,7 +567,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 b7bef4d2ac..af2ef74711 100644 --- a/common/movement.c +++ b/common/movement.c @@ -479,11 +479,11 @@ bool is_native_near_tile(const struct civ_map *nmap, } /************************************************************************//** - 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().) ****************************************************************************/ @@ -491,6 +491,8 @@ bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile) { + const struct unit_type *utype; + if (!can_unit_exist_at_tile(nmap, punit, ptile)) { return FALSE; } @@ -499,17 +501,18 @@ bool can_unit_survive_at_tile(const struct civ_map *nmap, 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(nmap, ptile)) { + if (utype_has_flag(utype, UTYF_COAST) && is_safe_ocean(nmap, 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 fb9079f02d..9eecb44fe8 100644 --- a/common/tile.c +++ b/common/tile.c @@ -300,18 +300,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 86aac2fa05..2725d76e51 100644 --- a/common/tile.h +++ b/common/tile.h @@ -127,7 +127,7 @@ bool tile_has_base(const struct tile *ptile, const struct base_type *pbase); int tile_has_not_aggressive_extra_for_unit(const struct tile *ptile, const struct unit_type *punittype); 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 7282d462e0..213a675344 100644 --- a/common/unittype.c +++ b/common/unittype.c @@ -2572,7 +2572,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; @@ -2589,9 +2589,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); @@ -2792,7 +2792,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(); @@ -2802,7 +2802,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 51340d344f..493eea3d35 100644 --- a/common/unittype.h +++ b/common/unittype.h @@ -154,7 +154,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 6525726f0f..bb27bbd44f 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -1542,21 +1542,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(&(wld.map), ptile)) { + utype = unit_type_get(punit); + if (utype_has_flag(utype, UTYF_COAST) && is_safe_ocean(&(wld.map), 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; } @@ -1567,7 +1569,7 @@ static bool is_refuel_tile(const struct tile *ptile, } /**********************************************************************//** - 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