summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-12-04 16:31:10 +0300
committerAndrei Karas <akaras@inbox.ru>2014-12-04 16:37:25 +0300
commitcae3afc7e53e067874759bab13a0cc64813a34a2 (patch)
treeb40321feb61329bfcf99a4f1c06bcce574d5d2cc
parent93f7e4f666dc1e1d9bf9715307080bd9c3027109 (diff)
downloadmanaplus-cae3afc7e53e067874759bab13a0cc64813a34a2.tar.gz
manaplus-cae3afc7e53e067874759bab13a0cc64813a34a2.tar.bz2
manaplus-cae3afc7e53e067874759bab13a0cc64813a34a2.tar.xz
manaplus-cae3afc7e53e067874759bab13a0cc64813a34a2.zip
Improve a bit function findBeingByPixel.
-rw-r--r--src/actormanager.cpp43
1 files changed, 25 insertions, 18 deletions
diff --git a/src/actormanager.cpp b/src/actormanager.cpp
index 622ae0d71..5126a49bc 100644
--- a/src/actormanager.cpp
+++ b/src/actormanager.cpp
@@ -382,10 +382,12 @@ Being *ActorManager::findBeingByPixel(const int x, const int y,
{
const FloorItem *const floor
= static_cast<const FloorItem*>(*it);
- if ((floor->getPixelX() - mapTileSize <= x) &&
- (floor->getPixelX() + mapTileSize > x) &&
- (floor->getPixelY() - mapTileSize * 2 <= y) &&
- (floor->getPixelY() + mapTileSize / 2 > y))
+ const int px = floor->getPixelX();
+ const int py = floor->getPixelY();
+ if ((px - mapTileSize <= x) &&
+ (px + mapTileSize > x) &&
+ (py - mapTileSize * 2 <= y) &&
+ (py + mapTileSize / 2 > y))
{
noBeing = true;
}
@@ -401,21 +403,24 @@ Being *ActorManager::findBeingByPixel(const int x, const int y,
continue;
}
- if ((being->isAlive()
+ if ((being->mAction != BeingAction::DEAD
|| (targetDead && being->getType() == ActorType::Player))
- && (allPlayers || being != localPlayer))
+ && (allPlayers || being != localPlayer))
{
- if ((being->getPixelX() - mapTileSize / 2 <= x) &&
- (being->getPixelX() + mapTileSize / 2 > x) &&
- (being->getPixelY() - mapTileSize <= y) &&
- (being->getPixelY() > y))
+ const int px = being->getPixelX();
+ const int py = being->getPixelY();
+ if ((px - mapTileSize / 2 <= x) &&
+ (px + mapTileSize / 2 > x) &&
+ (py - mapTileSize <= y) &&
+ (py > y))
{
return being;
}
- else if (!noBeing && (being->getPixelX() - mapTileSize <= x) &&
- (being->getPixelX() + mapTileSize > x) &&
- (being->getPixelY() - mapTileSize * 2 <= y) &&
- (being->getPixelY() + mapTileSize / 2 > y))
+ else if (!noBeing &&
+ (px - mapTileSize <= x) &&
+ (px + mapTileSize > x) &&
+ (py - mapTileSize * 2 <= y) &&
+ (py + mapTileSize / 2 > y))
{
if (tempBeing)
noBeing = true;
@@ -450,10 +455,12 @@ Being *ActorManager::findBeingByPixel(const int x, const int y,
continue;
}
- if ((being->getPixelX() - mapTileSize / 2 <= x) &&
- (being->getPixelX() + mapTileSize / 2 > x) &&
- (being->getPixelY() - mapTileSize <= y) &&
- (being->getPixelY() > y))
+ const int px = being->getPixelX();
+ const int py = being->getPixelY();
+ if ((px - mapTileSize / 2 <= x) &&
+ (px + mapTileSize / 2 > x) &&
+ (py - mapTileSize <= y) &&
+ (py > y))
{
return being;
}