summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedja Beader <fedja@protonmail.ch>2023-05-10 18:09:18 +0200
committerFedja Beader <fedja@protonmail.ch>2024-04-27 18:17:50 +0000
commit0f90810e627804f5a1f2692a5f5b06d7b2f28f85 (patch)
treedf1183006a1739f5321c7940941e01049ddab85a
parent52b591d71bbb4aec2b212b4d8190e6db18a46c73 (diff)
downloadmanaplus-cleanup.tar.gz
manaplus-cleanup.tar.bz2
manaplus-cleanup.tar.xz
manaplus-cleanup.zip
Make code more readablecleanup
-rw-r--r--src/actormanager.cpp54
1 files changed, 33 insertions, 21 deletions
diff --git a/src/actormanager.cpp b/src/actormanager.cpp
index 9d2ea0664..b0e325271 100644
--- a/src/actormanager.cpp
+++ b/src/actormanager.cpp
@@ -153,6 +153,7 @@ class SortBeingFunctor final
if (w1 != w2)
return w1 < w2;
}
+
if (being1->getDistance() != being2->getDistance())
{
if (specialDistance && being1->getDistance() <= 2
@@ -171,12 +172,13 @@ class SortBeingFunctor final
}
const int d1 = abs(being1->getTileX() - x)
- + abs(being1->getTileY() - y);
+ + abs(being1->getTileY() - y);
const int d2 = abs(being2->getTileX() - x)
- + abs(being2->getTileY() - y);
+ + abs(being2->getTileY() - y);
if (d1 != d2)
return d1 < d2;
+
if (attackBeings != nullptr)
{
int w1 = defaultAttackIndex;
@@ -275,9 +277,10 @@ void ActorManager::setPlayer(LocalPlayer *const player)
mActors.insert(player);
mActorsIdMap[player->getId()] = player;
if (socialWindow != nullptr)
+ {
socialWindow->updateAttackFilter();
- if (socialWindow != nullptr)
socialWindow->updatePickupFilter();
+ }
}
Being *ActorManager::createBeing(const BeingId id,
@@ -718,8 +721,11 @@ bool ActorManager::pickUpAll(const int x1, const int y1,
return false;
bool finded(false);
- const bool allowAll = mPickupItemsSet.find(std::string()) !=
- mPickupItemsSet.end();
+ // if "default" is in pickup items set, then the ignore list acts
+ // as a blacklist. Otherwise, the pickup list acts as a whitelist.
+ const bool allowAll = mPickupItemsSet.find(std::string())
+ != mPickupItemsSet.end();
+
if (!serverBuggy)
{
for_actorsm
@@ -816,11 +822,14 @@ bool ActorManager::pickUpNearest(const int x, const int y,
if (localPlayer == nullptr)
return false;
- maxdist = maxdist * maxdist;
+ maxdist = maxdist * maxdist; // avoids calculating square root
FloorItem *closestItem = nullptr;
int dist = 0;
- const bool allowAll = mPickupItemsSet.find(std::string()) !=
- mPickupItemsSet.end();
+
+ // if "default" is in pickup items set, then the ignore list acts
+ // as a blacklist. Otherwise, the pickup list acts as a whitelist.
+ const bool allowAll = mPickupItemsSet.find(std::string())
+ != mPickupItemsSet.end();
for_actorsm
{
@@ -832,13 +841,14 @@ bool ActorManager::pickUpNearest(const int x, const int y,
{
FloorItem *const item = static_cast<FloorItem*>(*it);
- const int d = (item->getTileX() - x) * (item->getTileX() - x)
- + (item->getTileY() - y) * (item->getTileY() - y);
+ const int dx = item->getTileX() - x;
+ const int dy = item->getTileY() - y;
+ const int d = dx*dx + dy*dy;
- if ((d < dist || closestItem == nullptr) &&
- (!mTargetOnlyReachable || localPlayer->isReachable(
- item->getTileX(), item->getTileY(),
- false)))
+ if ((d < dist || closestItem == nullptr)
+ && (!mTargetOnlyReachable
+ || localPlayer->isReachable(item->getTileX(),
+ item->getTileY(), false)) )
{
if (allowAll)
{
@@ -900,8 +910,8 @@ Being *ActorManager::findNearestByName(const std::string &name,
int dist = 0;
Being* closestBeing = nullptr;
- int x = localPlayer->getTileX();
- int y = localPlayer->getTileY();
+ const int x = localPlayer->getTileX();
+ const int y = localPlayer->getTileY();
for_actorsm
{
@@ -924,8 +934,9 @@ Being *ActorManager::findNearestByName(const std::string &name,
{
return being;
}
- const int d = (being->getTileX() - x) * (being->getTileX() - x)
- + (being->getTileY() - y) * (being->getTileY() - y);
+ const int dx = being->getTileX() - x;
+ const int dy = being->getTileY() - y;
+ const int d = dx*dx + dy*dy;
if (validateBeing(nullptr, being, type, nullptr, 50)
&& (d < dist || closestBeing == nullptr))
@@ -1321,8 +1332,9 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing,
if (being->getType() != ActorType::Monster
|| !mTargetOnlyReachable)
{ // if distance not calculated, use old distance
- d = (being->getTileX() - x) * (being->getTileX() - x)
- + (being->getTileY() - y) * (being->getTileY() - y);
+ const int dx = being->getTileX() - x;
+ const int dy = being->getTileY() - y;
+ d = dx*dx + dy*dy;
}
if (!valid)
@@ -2109,7 +2121,7 @@ Being *ActorManager::cloneBeing(const Being *const srcBeing,
dstBeing->setGender(srcBeing->getGender());
dstBeing->setAction(srcBeing->getCurrentAction(), 0);
dstBeing->setTileCoords(srcBeing->getTileX() + dx,
- srcBeing->getTileY() + dy);
+ srcBeing->getTileY() + dy);
dstBeing->setName(srcBeing->getName());
dstBeing->setDirection(srcBeing->getDirection());
const int sz = CAST_S32(srcBeing->mSprites.size());