From cae3afc7e53e067874759bab13a0cc64813a34a2 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 4 Dec 2014 16:31:10 +0300 Subject: Improve a bit function findBeingByPixel. --- src/actormanager.cpp | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'src') 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(*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; } -- cgit v1.2.3-70-g09d2