From dd643b51a1dcc44f9e1b276fa97f57bf3e5da6b9 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 8 Jul 2023 20:15:33 +0300 Subject: [PATCH 19/19] test_unit_can_airlift_to(): Take map as parameter See osdn #48365 Signed-off-by: Marko Lindqvist --- client/text.c | 2 +- common/actres.c | 23 ++++++++++++----------- common/unit.c | 11 ++++++----- common/unit.h | 3 ++- server/unithand.c | 15 ++++++++------- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/client/text.c b/client/text.c index 2d79784fe4..ebc29d412e 100644 --- a/client/text.c +++ b/client/text.c @@ -556,7 +556,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/actres.c b/common/actres.c index 7e1a15a2a5..246f1f83de 100644 --- a/common/actres.c +++ b/common/actres.c @@ -278,6 +278,7 @@ enum fc_tristate actres_possible(enum action_result result, struct terrain *pterrain; bool can_see_tgt_unit; bool can_see_tgt_tile; + struct civ_map *nmap = &(wld.map); /* Only check requirement against the target unit if the actor can see it * or if the evaluator is omniscient. The game checking the rules is @@ -400,7 +401,7 @@ enum fc_tristate actres_possible(enum action_result result, /* 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 && can_player_see_tile(actor->player, otile)) { @@ -422,7 +423,7 @@ enum fc_tristate actres_possible(enum action_result result, 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 (!can_player_see_tile(actor->player, otile)) { /* Could have a city that blocks via citymindist. Even if this @@ -527,7 +528,7 @@ enum fc_tristate actres_possible(enum action_result result, 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; @@ -560,7 +561,7 @@ enum fc_tristate actres_possible(enum action_result result, 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; } @@ -569,7 +570,7 @@ enum fc_tristate actres_possible(enum action_result result, 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; } @@ -832,7 +833,7 @@ enum fc_tristate actres_possible(enum action_result result, 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; @@ -863,7 +864,7 @@ enum fc_tristate actres_possible(enum action_result result, /* 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; @@ -925,7 +926,7 @@ enum fc_tristate actres_possible(enum action_result result, 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; } @@ -940,7 +941,7 @@ enum fc_tristate actres_possible(enum action_result result, if (result == 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; } @@ -948,14 +949,14 @@ enum fc_tristate actres_possible(enum action_result result, fc_assert(result == ACTRES_TELEPORT); /* Reason: is teleporting to the tile. */ - if (!unit_can_teleport_to_tile(&(wld.map), actor->unit, target->tile, + if (!unit_can_teleport_to_tile(nmap, actor->unit, target->tile, 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 fc2621091e..5d142316fb 100644 --- a/common/unit.c +++ b/common/unit.c @@ -68,17 +68,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) { @@ -116,7 +117,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; } @@ -176,7 +177,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 c7f9d44a22..47f91ab36f 100644 --- a/common/unit.h +++ b/common/unit.h @@ -307,7 +307,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 1ed05e57fb..332a706601 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -1422,7 +1422,8 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, struct player *act_player = unit_owner(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; @@ -1518,7 +1519,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, @@ -1533,7 +1534,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), @@ -1544,7 +1545,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), @@ -1559,7 +1560,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, @@ -1570,7 +1571,7 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, break; case ACTRES_TELEPORT: if (target_tile != NULL) { - action_custom = unit_teleport_to_tile_test(&(wld.map), punit, + action_custom = unit_teleport_to_tile_test(nmap, punit, punit->activity, unit_tile(punit), target_tile, @@ -1628,7 +1629,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