From a1bd8907f061fe16d61e2f4404f409b3f06a6b0d Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 17 Dec 2022 15:32:37 +0200 Subject: [PATCH 31/31] Remove redundant checks for cleaning actions When we've selected target extra from the list of cleanable extras on the tile, we don't need to check if it's cleanable and on the tile. See osdn #46120 Signed-off-by: Marko Lindqvist --- common/actions.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/common/actions.c b/common/actions.c index 0317890646..471289d16b 100644 --- a/common/actions.c +++ b/common/actions.c @@ -4405,6 +4405,14 @@ is_action_possible(const action_id wanted_action, if (target_extra != NULL) { pextra = target_extra; + + if (!is_extra_removed_by(pextra, ERM_CLEANPOLLUTION)) { + return TRI_NO; + } + + if (!tile_has_extra(target->tile, pextra)) { + return TRI_NO; + } } else { /* TODO: Make sure that all callers set target so that * we don't need this fallback. */ @@ -4418,15 +4426,7 @@ is_action_possible(const action_id wanted_action, } } - if (!is_extra_removed_by(pextra, ERM_CLEANPOLLUTION)) { - return TRI_NO; - } - - if (!can_remove_extra(pextra, actor->unit, target->tile)) { - return TRI_NO; - } - - if (tile_has_extra(target->tile, pextra)) { + if (can_remove_extra(pextra, actor->unit, target->tile)) { return TRI_YES; } @@ -4445,6 +4445,14 @@ is_action_possible(const action_id wanted_action, if (target_extra != NULL) { pextra = target_extra; + + if (!is_extra_removed_by(pextra, ERM_CLEANFALLOUT)) { + return TRI_NO; + } + + if (!tile_has_extra(target->tile, pextra)) { + return TRI_NO; + } } else { /* TODO: Make sure that all callers set target so that * we don't need this fallback. */ @@ -4453,20 +4461,12 @@ is_action_possible(const action_id wanted_action, actor->player, actor->unit); if (pextra == NULL) { - /* No available pollution extras */ + /* No available fallout extras */ return TRI_NO; } } - if (!is_extra_removed_by(pextra, ERM_CLEANFALLOUT)) { - return TRI_NO; - } - - if (!can_remove_extra(pextra, actor->unit, target->tile)) { - return TRI_NO; - } - - if (tile_has_extra(target->tile, pextra)) { + if (can_remove_extra(pextra, actor->unit, target->tile)) { return TRI_YES; } -- 2.35.1