From a59e249efe51b8c85db683586cc50825feb38093 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 17 Dec 2022 15:39:01 +0200 Subject: [PATCH 16/16] 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/unit.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/common/unit.c b/common/unit.c index 3f5a5e5604..a299eec71c 100644 --- a/common/unit.c +++ b/common/unit.c @@ -807,6 +807,14 @@ bool can_unit_do_activity_targeted_at(const struct unit *punit, if (target != NULL) { pextra = target; + + if (!is_extra_removed_by(pextra, ERM_CLEANPOLLUTION)) { + return FALSE; + } + + if (!tile_has_extra(ptile, pextra)) { + return FALSE; + } } else { /* TODO: Make sure that all callers set target so that * we don't need this fallback. */ @@ -820,16 +828,8 @@ bool can_unit_do_activity_targeted_at(const struct unit *punit, } } - if (!is_extra_removed_by(pextra, ERM_CLEANPOLLUTION)) { - return FALSE; - } - - if (!unit_has_type_flag(punit, UTYF_SETTLERS) - || !can_remove_extra(pextra, punit, ptile)) { - return FALSE; - } - - if (tile_has_extra(ptile, pextra)) { + if (unit_has_type_flag(punit, UTYF_SETTLERS) + && can_remove_extra(pextra, punit, ptile)) { return TRUE; } @@ -846,6 +846,14 @@ bool can_unit_do_activity_targeted_at(const struct unit *punit, if (target != NULL) { pextra = target; + + if (!is_extra_removed_by(pextra, ERM_CLEANFALLOUT)) { + return FALSE; + } + + if (!tile_has_extra(ptile, pextra)) { + return FALSE; + } } else { /* TODO: Make sure that all callers set target so that * we don't need this fallback. */ @@ -854,21 +862,13 @@ bool can_unit_do_activity_targeted_at(const struct unit *punit, unit_owner(punit), punit); if (pextra == NULL) { - /* No available pollution extras */ + /* No available fallout extras */ return FALSE; } } - if (!is_extra_removed_by(pextra, ERM_CLEANFALLOUT)) { - return FALSE; - } - - if (!unit_has_type_flag(punit, UTYF_SETTLERS) - || !can_remove_extra(pextra, punit, ptile)) { - return FALSE; - } - - if (tile_has_extra(ptile, pextra)) { + if (unit_has_type_flag(punit, UTYF_SETTLERS) + && can_remove_extra(pextra, punit, ptile)) { return TRUE; } -- 2.35.1