From 0bcc88159aee0e680d4cdc2949b24b10b571135f Mon Sep 17 00:00:00 2001 From: Fedja Beader <fedja@protonmail.ch> Date: Sun, 6 Apr 2025 00:17:58 +0000 Subject: Refactor ActorManager::validateBeing() Squashed with: * More docs for validateBeing * addendum documentation for validateBeing **** mana/plus!154 --- src/actormanager.cpp | 32 ++++++++++++++++++++++++++------ src/actormanager.h | 14 ++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/actormanager.cpp b/src/actormanager.cpp index 2e1079487..e33798bab 100644 --- a/src/actormanager.cpp +++ b/src/actormanager.cpp @@ -1386,12 +1386,32 @@ bool ActorManager::validateBeing(const Being *const aroundBeing, { if (localPlayer == nullptr) return false; - return (being != nullptr) && ((being->getType() == type - || type == ActorType::Unknown) && (being->isAlive() - || (mTargetDeadPlayers && type == ActorType::Player)) - && being != aroundBeing) && being != excluded - && (type != ActorType::Monster || !mTargetOnlyReachable - || localPlayer->isReachable(being, maxCost)); + + if (being == nullptr) + return false; + + if (being == aroundBeing) + return false; + + if (being == excluded) + return false; + + // If specific being type is given, it must match. + if (!(being->getType() == type || type == ActorType::Unknown)) + return false; + + if (!being->isAlive()) + if (!mTargetDeadPlayers || type != ActorType::Player) + return false; + + // Why are we ignoring real reachability checks for non-monsters? + if (type != ActorType::Monster) + return true; + + if (!mTargetOnlyReachable) + return true; + + return localPlayer->isReachable(being, maxCost); } #ifdef TMWA_SUPPORT diff --git a/src/actormanager.h b/src/actormanager.h index 43b9341b9..15841f61d 100644 --- a/src/actormanager.h +++ b/src/actormanager.h @@ -393,6 +393,20 @@ class ActorManager final : public ConfigListener #ifndef UNITTESTS protected: #endif // UNITTESTS + /* + * General checks if a being is valid for selection. + * Additionally, localPlayer is checked to exist + * + * @param aroundBeing being must not equal this one + * @param being being under scrutiny. Nullptr check performed + * it must be alive unless a player and + * mTargetDeadPlayers is true. + * @param type pass ActorType::Unknown if no matching desired + * @param exluded being must not equal this one + * @param maxCost allowed max pathfinder distance, if applicable + * (only if being is a monster and + * mTargetOnlyReachable is true) + */ bool validateBeing(const Being *const aroundBeing, Being *const being, const ActorTypeT &type, -- cgit v1.2.3-70-g09d2