summaryrefslogtreecommitdiff
path: root/src/beingmanager.cpp
diff options
context:
space:
mode:
authorRoderic Morris <roderic@ccs.neu.edu>2008-10-25 01:40:36 +0000
committerRoderic Morris <roderic@ccs.neu.edu>2008-10-25 01:40:36 +0000
commit796c2addfb17b57992d304667248873ee26088dc (patch)
tree8d3aaab2dd6abbc304eb9f8b70551b210894a7e2 /src/beingmanager.cpp
parentf8f3e17f72d1216bacd5aaa975789b0b790068f6 (diff)
downloadmana-796c2addfb17b57992d304667248873ee26088dc.tar.gz
mana-796c2addfb17b57992d304667248873ee26088dc.tar.bz2
mana-796c2addfb17b57992d304667248873ee26088dc.tar.xz
mana-796c2addfb17b57992d304667248873ee26088dc.zip
attack range fixes, highlight monsters in range (by Chuck Miller)
Diffstat (limited to 'src/beingmanager.cpp')
-rw-r--r--src/beingmanager.cpp39
1 files changed, 14 insertions, 25 deletions
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
index 22b3de9b..2ab29fd2 100644
--- a/src/beingmanager.cpp
+++ b/src/beingmanager.cpp
@@ -165,11 +165,21 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist,
Being *closestBeing = NULL;
int dist = 0;
+ //Why do we do this:
+ //For some reason x,y passed to this function is always
+ //in map coords, while down below its in pixels
+ //
+ //I believe there is a deeper problem under this, but
+ //for a temp solution we'll convert to coords to pixels
+ x = x * 32;
+ y = y * 32;
+ maxdist = maxdist * 32;
+
for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++)
{
Being *being = (*i);
const Vector &pos = being->getPosition();
- int d = abs((int) pos.x - x) + abs((int) pos.y - y);
+ int d = abs(((int) pos.x) - x) + abs(((int) pos.y) - y);
if ((being->getType() == type || type == Being::UNKNOWN)
&& (d < dist || closestBeing == NULL) // it is closer
@@ -180,34 +190,13 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist,
closestBeing = being;
}
}
-
- return (maxdist >= dist) ? NULL : closestBeing;
+
+ return (maxdist >= dist) ? closestBeing : NULL;
}
Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist,
Being::Type type)
{
- Being *closestBeing = NULL;
- int dist = 0;
const Vector &aroundBeingPos = aroundBeing->getPosition();
-
- for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++)
- {
- Being *being = (*i);
- const Vector &pos = being->getPosition();
- int d = abs((int) pos.x - aroundBeingPos.x) +
- abs((int) pos.y - aroundBeingPos.y);
-
- if ((being->getType() == type || type == Being::UNKNOWN)
- && (d < dist || closestBeing == NULL) // it is closer
- && being->mAction != Being::DEAD // no dead beings
- && being != aroundBeing
- )
- {
- dist = d;
- closestBeing = being;
- }
- }
-
- return (maxdist >= dist) ? NULL : closestBeing;
+ return findNearestLivingBeing((int) aroundBeingPos.x,(int) aroundBeingPos.y,maxdist,type);
}