From 8556a7e91080fa9e1f5c63373351fad6b29609bd Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 18 Jan 2023 17:50:48 +0200 Subject: [PATCH 39/39] expl_act_not_enabl(): Remove unnecessary unit_owner(punit) calls Use the local variable containing the owner when we already have that. See osdn #46543 Signed-off-by: Marko Lindqvist --- server/unithand.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/server/unithand.c b/server/unithand.c index b136d2484b..ec2afafebd 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -1306,7 +1306,7 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, struct player *must_war_player; const struct action *paction; struct action *blocker; - const struct player *act_player = unit_owner(punit); + struct player *act_player = unit_owner(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)); @@ -1390,7 +1390,7 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, break; case ATK_SELF: /* A unit acting against itself. */ - tgt_player = unit_owner(punit); + tgt_player = act_player; break; case ATK_COUNT: fc_assert(action_get_target_kind(paction) != ATK_COUNT); @@ -1499,8 +1499,8 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, explnat->no_act_terrain = tile_terrain(target_tile); } else if ((action_has_result_safe(paction, ACTRES_PARADROP) || action_has_result_safe(paction, ACTRES_PARADROP_CONQUER)) - && target_tile - && map_is_known_and_seen(target_tile, unit_owner(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) && (!BV_ISSET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK) @@ -1563,25 +1563,25 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, explnat->no_war_with = must_war_player; } else if (action_mp_full_makes_legal(punit, act_id)) { explnat->kind = ANEK_LOW_MP; - } else if (tgt_player - && unit_owner(punit) != tgt_player + } else if (tgt_player != NULL + && act_player != tgt_player && !can_utype_do_act_if_tgt_diplrel(unit_type_get(punit), act_id, DRO_FOREIGN, TRUE)) { explnat->kind = ANEK_FOREIGN; - } else if (tgt_player - && unit_owner(punit) == tgt_player + } else if (tgt_player != NULL + && act_player == tgt_player && !can_utype_do_act_if_tgt_diplrel(unit_type_get(punit), act_id, DRO_FOREIGN, FALSE)) { explnat->kind = ANEK_DOMESTIC; - } else if (punit + } else if (punit != NULL && does_nation_block_action(act_id, FALSE, - punit, unit_owner(punit)->nation)) { + punit, act_player->nation)) { explnat->kind = ANEK_NATION_ACT; - explnat->no_act_nation = unit_owner(punit)->nation; + explnat->no_act_nation = act_player->nation; } else if (tgt_player && does_nation_block_action(act_id, TRUE, punit, tgt_player->nation)) { @@ -1699,8 +1699,8 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, explnat->kind = ANEK_CITY_TOO_CLOSE_TGT; } else if ((action_has_result_safe(paction, ACTRES_PARADROP_CONQUER) || action_has_result_safe(paction, ACTRES_PARADROP)) - && target_tile - && !map_is_known(target_tile, unit_owner(punit))) { + && target_tile != NULL + && !map_is_known(target_tile, act_player)) { explnat->kind = ANEK_TGT_TILE_UNKNOWN; } else if ((action_has_result_safe(paction, ACTRES_CONQUER_CITY) || action_id_has_result_safe(act_id, ACTRES_CONQUER_EXTRAS) @@ -1728,7 +1728,7 @@ static struct ane_expl *expl_act_not_enabl(struct unit *punit, break; } } else if (action_has_result_safe(paction, ACTRES_SPY_BRIBE_UNIT) - && utype_player_already_has_this_unique(unit_owner(punit), + && utype_player_already_has_this_unique(act_player, unit_type_get(target_unit))) { explnat->kind = ANEK_TGT_IS_UNIQUE_ACT_HAS; explnat->no_tgt_utype = unit_type_get(target_unit); -- 2.39.0