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 /src/actormanager.cpp | |
parent | 6c500b492e4b82caa5b1ec420a41beaecdd426ae (diff) | |
download | manaplus-436b8580ba7e200ea04707c380f2a69c03e64052.tar.gz manaplus-436b8580ba7e200ea04707c380f2a69c03e64052.tar.bz2 manaplus-436b8580ba7e200ea04707c380f2a69c03e64052.tar.xz manaplus-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
Diffstat (limited to 'src/actormanager.cpp')
-rw-r--r-- | src/actormanager.cpp | 24 |
1 files changed, 12 insertions, 12 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; } } |