diff options
author | Fedja Beader <fedja@protonmail.ch> | 2025-03-10 17:55:16 +0000 |
---|---|---|
committer | Fedja Beader <fedja@protonmail.ch> | 2025-03-10 17:55:16 +0000 |
commit | 436b8580ba7e200ea04707c380f2a69c03e64052 (patch) | |
tree | b1b69d218245a19f3158f4c4431b5e20f29d93a5 | |
parent | 6c500b492e4b82caa5b1ec420a41beaecdd426ae (diff) | |
download | mv-436b8580ba7e200ea04707c380f2a69c03e64052.tar.gz mv-436b8580ba7e200ea04707c380f2a69c03e64052.tar.bz2 mv-436b8580ba7e200ea04707c380f2a69c03e64052.tar.xz mv-436b8580ba7e200ea04707c380f2a69c03e64052.zip |
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
-rw-r--r-- | src/actormanager.cpp | 24 | ||||
-rw-r--r-- | 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; |