From a144f970407876f54e5ddda2ea810203c7663a6c Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 8 Jul 2023 20:22:17 +0300 Subject: [PATCH 30/30] test_unit_can_airlift_to(): Take map as parameter See osdn #48365 Signed-off-by: Marko Lindqvist --- client/text.c | 2 +- common/actions.c | 20 ++++++++++---------- common/unit.c | 11 ++++++----- common/unit.h | 3 ++- server/unithand.c | 13 +++++++------ 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/client/text.c b/client/text.c index 4c0392b454..7156d3f017 100644 --- a/client/text.c +++ b/client/text.c @@ -589,7 +589,7 @@ const char *get_airlift_text(const struct unit_list *punits, enum unit_airlift_result result; /* NULL will tell us about the capability of airlifting from source */ - result = test_unit_can_airlift_to(client_player(), punit, pdest); + result = test_unit_can_airlift_to(&(wld.map), client_player(), punit, pdest); switch (result) { case AR_NO_MOVES: diff --git a/common/actions.c b/common/actions.c index 89372773bc..be1532b8db 100644 --- a/common/actions.c +++ b/common/actions.c @@ -3916,7 +3916,7 @@ is_action_possible(const action_id wanted_action, /* No need to check again. */ return TRI_NO; } else { - square_iterate(&(wld.map), target->tile, + square_iterate(nmap, target->tile, game.info.citymindist - 1, otile) { if (tile_city(otile) != NULL && plr_sees_tile(actor->player, otile)) { @@ -3938,7 +3938,7 @@ is_action_possible(const action_id wanted_action, if (!omniscient) { /* The player may not have enough information to find out if * citymindist blocks or not. This doesn't depend on if it blocks. */ - square_iterate(&(wld.map), target->tile, + square_iterate(nmap, target->tile, game.info.citymindist - 1, otile) { if (!plr_sees_tile(actor->player, otile)) { /* Could have a city that blocks via citymindist. Even if this @@ -4077,7 +4077,7 @@ is_action_possible(const action_id wanted_action, case ACTRES_AIRLIFT: /* Reason: Keep the old rules. */ /* Info leak: same as test_unit_can_airlift_to() */ - switch (test_unit_can_airlift_to(omniscient ? NULL : actor->player, + switch (test_unit_can_airlift_to(nmap, omniscient ? NULL : actor->player, actor->unit, target->city)) { case AR_OK: return TRI_YES; @@ -4106,7 +4106,7 @@ is_action_possible(const action_id wanted_action, case ACTRES_CONQUER_CITY: /* Reason: "Conquer City" involves moving into the city. */ - if (!unit_can_move_to_tile(&(wld.map), actor->unit, target->tile, + if (!unit_can_move_to_tile(nmap, actor->unit, target->tile, FALSE, FALSE, TRUE)) { return TRI_NO; } @@ -4115,7 +4115,7 @@ is_action_possible(const action_id wanted_action, case ACTRES_CONQUER_EXTRAS: /* Reason: "Conquer Extras" involves moving to the tile. */ - if (!unit_can_move_to_tile(&(wld.map), actor->unit, target->tile, + if (!unit_can_move_to_tile(nmap, actor->unit, target->tile, FALSE, FALSE, FALSE)) { return TRI_NO; } @@ -4410,7 +4410,7 @@ is_action_possible(const action_id wanted_action, break; case ACTRES_TRANSPORT_DISEMBARK: - if (!unit_can_move_to_tile(&(wld.map), actor->unit, target->tile, + if (!unit_can_move_to_tile(nmap, actor->unit, target->tile, FALSE, FALSE, FALSE)) { /* Reason: involves moving to the tile. */ return TRI_NO; @@ -4441,7 +4441,7 @@ is_action_possible(const action_id wanted_action, /* Keep the old rules. */ return TRI_NO; } - if (!unit_can_move_to_tile(&(wld.map), actor->unit, target->tile, + if (!unit_can_move_to_tile(nmap, actor->unit, target->tile, FALSE, TRUE, FALSE)) { /* Reason: involves moving to the tile. */ return TRI_NO; @@ -4503,7 +4503,7 @@ is_action_possible(const action_id wanted_action, case ACTRES_HUT_ENTER: case ACTRES_HUT_FRIGHTEN: /* Reason: involves moving to the tile. */ - if (!unit_can_move_to_tile(&(wld.map), actor->unit, target->tile, + if (!unit_can_move_to_tile(nmap, actor->unit, target->tile, FALSE, FALSE, FALSE)) { return TRI_NO; } @@ -4515,13 +4515,13 @@ is_action_possible(const action_id wanted_action, case ACTRES_UNIT_MOVE: /* Reason: is moving to the tile. */ - if (!unit_can_move_to_tile(&(wld.map), actor->unit, target->tile, + if (!unit_can_move_to_tile(nmap, actor->unit, target->tile, FALSE, FALSE, FALSE)) { return TRI_NO; } /* Reason: Don't override "Transport Embark" */ - if (!can_unit_exist_at_tile(&(wld.map), actor->unit, target->tile)) { + if (!can_unit_exist_at_tile(nmap, actor->unit, target->tile)) { return TRI_NO; } diff --git a/common/unit.c b/common/unit.c index b8f0254f0f..fc9455448e 100644 --- a/common/unit.c +++ b/common/unit.c @@ -70,17 +70,18 @@ bool are_unit_orders_equal(const struct unit_order *order1, } /**********************************************************************//** - Determines if punit can be airlifted to dest_city now! So punit needs + Determines if punit can be airlifted to dest_city now! So punit needs to be in a city now. If pdest_city is NULL, just indicate whether it's possible for the unit to be airlifted at all from its current position. The 'restriction' parameter specifies which player's knowledge this is based on -- one player can't see whether another's cities are currently - able to airlift. (Clients other than global observers should only call + able to airlift. (Clients other than global observers should only call this with a non-NULL 'restriction'.) **************************************************************************/ enum unit_airlift_result - test_unit_can_airlift_to(const struct player *restriction, + test_unit_can_airlift_to(const struct civ_map *nmap, + const struct player *restriction, const struct unit *punit, const struct city *pdest_city) { @@ -118,7 +119,7 @@ enum unit_airlift_result && (NULL == restriction || (tile_get_known(city_tile(pdest_city), restriction) == TILE_KNOWN_SEEN)) - && !can_unit_exist_at_tile(&(wld.map), punit, city_tile(pdest_city))) { + && !can_unit_exist_at_tile(nmap, punit, city_tile(pdest_city))) { /* Can't exist at the destination tile. */ return AR_BAD_DST_CITY; } @@ -178,7 +179,7 @@ enum unit_airlift_result } /**********************************************************************//** - Determines if punit can be airlifted to dest_city now! So punit needs + Determines if punit can be airlifted to dest_city now! So punit needs to be in a city now. On the server this gives correct information; on the client it errs on the side of saying airlifting is possible even if it's not certain given diff --git a/common/unit.h b/common/unit.h index 6ae7916d8b..aa2a5af2a1 100644 --- a/common/unit.h +++ b/common/unit.h @@ -312,7 +312,8 @@ int unit_shield_value(const struct unit *punit, bool unit_can_help_build_wonder_here(const struct unit *punit); bool unit_can_est_trade_route_here(const struct unit *punit); enum unit_airlift_result - test_unit_can_airlift_to(const struct player *restriction, + test_unit_can_airlift_to(const struct civ_map *nmap, + const struct player *restriction, const struct unit *punit, const struct city *pdest_city); bool unit_can_airlift_to(const struct unit *punit, const struct city *pcity); diff --git a/server/unithand.c b/server/unithand.c index 0c75dd3264..d47bd5df33 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -1310,7 +1310,8 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, const struct unit_type *act_utype = unit_type_get(punit); struct player *tgt_player = NULL; struct ane_expl *explnat = fc_malloc(sizeof(struct ane_expl)); - bool can_exist = can_unit_exist_at_tile(&(wld.map), punit, unit_tile(punit)); + struct civ_map *nmap = &(wld.map); + bool can_exist = can_unit_exist_at_tile(nmap, punit, unit_tile(punit)); bool on_native = is_native_tile(unit_type_get(punit), unit_tile(punit)); int action_custom; @@ -1406,7 +1407,7 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, action_custom = unit_upgrade_test(punit, FALSE); break; case ACTRES_AIRLIFT: - action_custom = test_unit_can_airlift_to(NULL, punit, target_city); + action_custom = test_unit_can_airlift_to(nmap, NULL, punit, target_city); break; case ACTRES_NUKE_UNITS: action_custom = unit_attack_units_at_tile_result(punit, paction, @@ -1418,7 +1419,7 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, break; case ACTRES_CONQUER_CITY: if (target_city) { - action_custom = unit_move_to_tile_test(&(wld.map), punit, + action_custom = unit_move_to_tile_test(nmap, punit, punit->activity, unit_tile(punit), city_tile(target_city), @@ -1429,7 +1430,7 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, break; case ACTRES_TRANSPORT_EMBARK: if (target_unit) { - action_custom = unit_move_to_tile_test(&(wld.map), punit, + action_custom = unit_move_to_tile_test(nmap, punit, punit->activity, unit_tile(punit), unit_tile(target_unit), @@ -1444,7 +1445,7 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, case ACTRES_CONQUER_EXTRAS: case ACTRES_UNIT_MOVE: if (target_tile) { - action_custom = unit_move_to_tile_test(&(wld.map), punit, + action_custom = unit_move_to_tile_test(nmap, punit, punit->activity, unit_tile(punit), target_tile, @@ -1502,7 +1503,7 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, && target_tile != NULL && map_is_known_and_seen(target_tile, act_player, V_MAIN) - && (!can_unit_exist_at_tile(&(wld.map), punit, target_tile) + && (!can_unit_exist_at_tile(nmap, punit, target_tile) && (!BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK) || !unit_could_load_at(punit, target_tile)))) { explnat->kind = ANEK_BAD_TERRAIN_TGT; -- 2.40.1