From 01901d1defb22340b81758d3841b4abddd132eda Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 5 Nov 2023 18:32:45 +0200 Subject: [PATCH 33/33] Unhardcode extras.[ch] wld.map references See osdn #48943 Signed-off-by: Marko Lindqvist --- common/extras.c | 20 ++++++++++++-------- common/extras.h | 12 ++++++++---- common/requirements.c | 10 ++++++---- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/common/extras.c b/common/extras.c index 56d5e6e3fa..0d682d8e6e 100644 --- a/common/extras.c +++ b/common/extras.c @@ -360,9 +360,10 @@ bool is_extra_removed_by(const struct extra_type *pextra, Is there extra of the given type cardinally near tile? (Does not check ptile itself.) ****************************************************************************/ -bool is_extra_card_near(const struct tile *ptile, const struct extra_type *pextra) +bool is_extra_card_near(const struct civ_map *nmap, const struct tile *ptile, + const struct extra_type *pextra) { - cardinal_adjc_iterate(&(wld.map), ptile, adjc_tile) { + cardinal_adjc_iterate(nmap, ptile, adjc_tile) { if (tile_has_extra(adjc_tile, pextra)) { return TRUE; } @@ -375,9 +376,10 @@ bool is_extra_card_near(const struct tile *ptile, const struct extra_type *pextr Is there extra of the given type near tile? (Does not check ptile itself.) ****************************************************************************/ -bool is_extra_near_tile(const struct tile *ptile, const struct extra_type *pextra) +bool is_extra_near_tile(const struct civ_map *nmap, const struct tile *ptile, + const struct extra_type *pextra) { - adjc_iterate(&(wld.map), ptile, adjc_tile) { + adjc_iterate(nmap, ptile, adjc_tile) { if (tile_has_extra(adjc_tile, pextra)) { return TRUE; } @@ -865,11 +867,12 @@ bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag) Returns TRUE iff any cardinally adjacent tile contains an extra with the given flag (does not check ptile itself). ****************************************************************************/ -bool is_extra_flag_card_near(const struct tile *ptile, enum extra_flag_id flag) +bool is_extra_flag_card_near(const struct civ_map *nmap, const struct tile *ptile, + enum extra_flag_id flag) { extra_type_iterate(pextra) { if (extra_has_flag(pextra, flag)) { - cardinal_adjc_iterate(&(wld.map), ptile, adjc_tile) { + cardinal_adjc_iterate(nmap, ptile, adjc_tile) { if (tile_has_extra(adjc_tile, pextra)) { return TRUE; } @@ -884,11 +887,12 @@ bool is_extra_flag_card_near(const struct tile *ptile, enum extra_flag_id flag) Returns TRUE iff any adjacent tile contains an extra with the given flag (does not check ptile itself). ****************************************************************************/ -bool is_extra_flag_near_tile(const struct tile *ptile, enum extra_flag_id flag) +bool is_extra_flag_near_tile(const struct civ_map *nmap, const struct tile *ptile, + enum extra_flag_id flag) { extra_type_iterate(pextra) { if (extra_has_flag(pextra, flag)) { - adjc_iterate(&(wld.map), ptile, adjc_tile) { + adjc_iterate(nmap, ptile, adjc_tile) { if (tile_has_extra(adjc_tile, pextra)) { return TRUE; } diff --git a/common/extras.h b/common/extras.h index 7d189fecd2..c49e3e19b7 100644 --- a/common/extras.h +++ b/common/extras.h @@ -227,8 +227,10 @@ bool is_extra_removed_by_worker_action(const struct extra_type *pextra); bool is_extra_removed_by_action(const struct extra_type *pextra, const struct action *paction); -bool is_extra_card_near(const struct tile *ptile, const struct extra_type *pextra); -bool is_extra_near_tile(const struct tile *ptile, const struct extra_type *pextra); +bool is_extra_card_near(const struct civ_map *nmap, const struct tile *ptile, + const struct extra_type *pextra); +bool is_extra_near_tile(const struct civ_map *nmap, const struct tile *ptile, + const struct extra_type *pextra); bool extra_can_be_built(const struct extra_type *pextra, const struct tile *ptile); bool can_build_extra(const struct extra_type *pextra, @@ -267,9 +269,11 @@ bool unit_can_displace_hut(const struct unit *punit, const struct tile *ptile); bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag); -bool is_extra_flag_card_near(const struct tile *ptile, +bool is_extra_flag_card_near(const struct civ_map *nmap, + const struct tile *ptile, enum extra_flag_id flag); -bool is_extra_flag_near_tile(const struct tile *ptile, +bool is_extra_flag_near_tile(const struct civ_map *nmap, + const struct tile *ptile, enum extra_flag_id flag); void user_extra_flags_init(void); diff --git a/common/requirements.c b/common/requirements.c index 4f4f0011fa..ec7063c81c 100644 --- a/common/requirements.c +++ b/common/requirements.c @@ -2704,6 +2704,7 @@ is_extra_req_active(const struct req_context *context, { const struct extra_type *pextra; enum fc_tristate ret; + const struct civ_map *nmap = &(wld.map); IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_EXTRA); @@ -2726,13 +2727,13 @@ is_extra_req_active(const struct req_context *context, return TRI_MAYBE; } return BOOL_TO_TRISTATE(tile_has_extra(context->tile, pextra) - || is_extra_card_near(context->tile, pextra)); + || is_extra_card_near(nmap, context->tile, pextra)); case REQ_RANGE_ADJACENT: if (!context->tile) { return TRI_MAYBE; } return BOOL_TO_TRISTATE(tile_has_extra(context->tile, pextra) - || is_extra_near_tile(context->tile, pextra)); + || is_extra_near_tile(nmap, context->tile, pextra)); case REQ_RANGE_CITY: if (!context->city) { return TRI_MAYBE; @@ -3312,6 +3313,7 @@ is_extraflag_req_active(const struct req_context *context, { enum extra_flag_id extraflag; enum fc_tristate ret; + const struct civ_map *nmap = &(wld.map); IS_REQ_ACTIVE_VARIANT_ASSERT(VUT_EXTRAFLAG); @@ -3334,13 +3336,13 @@ is_extraflag_req_active(const struct req_context *context, return TRI_MAYBE; } return BOOL_TO_TRISTATE(tile_has_extra_flag(context->tile, extraflag) - || is_extra_flag_card_near(context->tile, extraflag)); + || is_extra_flag_card_near(nmap, context->tile, extraflag)); case REQ_RANGE_ADJACENT: if (!context->tile) { return TRI_MAYBE; } return BOOL_TO_TRISTATE(tile_has_extra_flag(context->tile, extraflag) - || is_extra_flag_near_tile(context->tile, extraflag)); + || is_extra_flag_near_tile(nmap, context->tile, extraflag)); case REQ_RANGE_CITY: if (!context->city) { return TRI_MAYBE; -- 2.42.0