summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp49
1 files changed, 23 insertions, 26 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 7bd1ad2d..fdfc5c8c 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -23,6 +23,7 @@
#include "being.h"
+#include <algorithm>
#include <sstream>
#include "game.h"
@@ -139,39 +140,35 @@ Being *findNode(Uint32 id)
return NULL;
}
-Being *findNode(Uint16 x, Uint16 y)
+class FindNodeFunctor
{
- for (Beings::iterator i = beings.begin(); i != beings.end(); i++)
- {
- Being *being = (*i);
- // Return being if found and it is not a dead monster
- if (being->x == x &&
- (being->y == y ||
- (being->getType() == Being::NPC && being->y == y + 1)) &&
- being->action != Being::MONSTER_DEAD)
+ public:
+ bool operator() (Being *being)
{
- return being;
+ Uint16 other_y = y + ((being->getType() == Being::NPC) ? 1 : 0);
+ return (being->x == x && (being->y == y || being->y == other_y) &&
+ being->action != Being::MONSTER_DEAD &&
+ (type == Being::UNKNOWN || being->getType() == type));
}
- }
- return NULL;
+
+ Uint16 x, y;
+ Being::Type type;
+} nodeFinder;
+
+Being *findNode(Uint16 x, Uint16 y)
+{
+ return findNode(x, y, Being::UNKNOWN);
}
Being* findNode(Uint16 x, Uint16 y, Being::Type type)
{
- for (Beings::iterator i = beings.begin(); i != beings.end(); i++)
- {
- Being *being = (*i);
- // Check if is a NPC (only low job ids)
- if (being->x == x &&
- (being->y == y ||
- (being->getType() == Being::NPC && being->y == y + 1)) &&
- being->getType() == type &&
- being->action != Being::MONSTER_DEAD)
- {
- return being;
- }
- }
- return NULL;
+ nodeFinder.x = x;
+ nodeFinder.y = y;
+ nodeFinder.type = type;
+
+ Beings::iterator i = find_if(beings.begin(), beings.end(), nodeFinder);
+
+ return (i == beings.end()) ? NULL : *i;
}
Being::Being():