From 436b8580ba7e200ea04707c380f2a69c03e64052 Mon Sep 17 00:00:00 2001 From: Fedja Beader Date: Mon, 10 Mar 2025 17:55:16 +0000 Subject: Cosmetic cleanup of ActorManager::pickUpNearest Squashed with: * Fix lint.. just revert previous state, I'll deal with it when I make things pass Positions **** mana/plus!142 --- src/actormanager.cpp | 24 ++++++++++++------------ src/actormanager.h | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/actormanager.cpp b/src/actormanager.cpp index 74937a6f9..7835d3289 100644 --- a/src/actormanager.cpp +++ b/src/actormanager.cpp @@ -817,14 +817,14 @@ bool ActorManager::pickUpAll(const int x1, const int y1, } bool ActorManager::pickUpNearest(const int x, const int y, - int maxdist) const + int maxDist) const { if (localPlayer == nullptr) return false; - maxdist = maxdist * maxdist; // avoids calculating square root FloorItem *closestItem = nullptr; - int dist = maxdist + 1; + // working with squared distances avoids calculating square root. + int closestDistSq = maxDist * maxDist + 1; // if "default" is in pickup items set, then the ignore list acts // as a blacklist. Otherwise, the pickup list acts as a whitelist. @@ -843,28 +843,28 @@ bool ActorManager::pickUpNearest(const int x, const int y, const int dx = item->getTileX() - x; const int dy = item->getTileY() - y; - const int d = dx*dx + dy*dy; + const int distSq = dx*dx + dy*dy; - if ((d < dist) && + if ((distSq < closestDistSq) && (!mTargetOnlyReachable || localPlayer->isReachable( item->getTileX(), item->getTileY(), false))) { if (allowAll) { - if (mIgnorePickupItemsSet.find(item->getName()) - == mIgnorePickupItemsSet.end()) - { - dist = d; + if (mIgnorePickupItemsSet.find(item->getName()) == + mIgnorePickupItemsSet.end()) + { // item is NOT in ignore set + closestDistSq = distSq; closestItem = item; } } else { - if (mPickupItemsSet.find(item->getName()) - != mPickupItemsSet.end()) + if (mPickupItemsSet.find(item->getName()) != + mPickupItemsSet.end()) { - dist = d; + closestDistSq = distSq; closestItem = item; } } diff --git a/src/actormanager.h b/src/actormanager.h index bea1267d1..43b9341b9 100644 --- a/src/actormanager.h +++ b/src/actormanager.h @@ -295,7 +295,7 @@ class ActorManager final : public ConfigListener const int y2, const bool serverBuggy) const; - bool pickUpNearest(const int x, const int y, int maxdist) const; + bool pickUpNearest(const int x, const int y, const int maxDist) const; void optionChanged(const std::string &name) override final; -- cgit v1.2.3-70-g09d2