summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFedja Beader <fedja@protonmail.ch>2024-08-18 19:59:23 +0000
committerFedja Beader <fedja@protonmail.ch>2024-08-18 19:59:23 +0000
commit59b7980cce1e171a8213390e81b8538a3661ada7 (patch)
tree603ed1cd6b73fc7c36e1a6032714aa3a716ecf67 /src
parent13b9ff5baf1f6d31cc6bfa5bd30bacd45b80539c (diff)
downloadplus-59b7980cce1e171a8213390e81b8538a3661ada7.tar.gz
plus-59b7980cce1e171a8213390e81b8538a3661ada7.tar.bz2
plus-59b7980cce1e171a8213390e81b8538a3661ada7.tar.xz
plus-59b7980cce1e171a8213390e81b8538a3661ada7.zip
Make code more readable
g **** mana/plus!77
Diffstat (limited to 'src')
-rw-r--r--src/actormanager.cpp46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/actormanager.cpp b/src/actormanager.cpp
index 9d2ea0664..7dcfdf578 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,8 +841,9 @@ 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(
@@ -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());