summaryrefslogtreecommitdiff
path: root/src/map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/map.cpp')
-rw-r--r--src/map.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/map.cpp b/src/map.cpp
index f0a5eae0..4e12ac97 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -407,7 +407,7 @@ void Map::blockTile(int x, int y, BlockType type)
if (type == BLOCKTYPE_NONE || !contains(x, y))
return;
- int tileNum = x + y * mWidth;
+ const int tileNum = x + y * mWidth;
if ((++mOccupation[type][tileNum]) > 0)
{
@@ -429,7 +429,7 @@ void Map::blockTile(int x, int y, BlockType type)
}
}
-bool Map::getWalk(int x, int y, char walkmask) const
+bool Map::getWalk(int x, int y, unsigned char walkmask) const
{
// You can't walk outside of the map
if (!contains(x, y))
@@ -439,6 +439,23 @@ bool Map::getWalk(int x, int y, char walkmask) const
return !(mMetaTiles[x + y * mWidth].blockmask & walkmask);
}
+#ifdef EATHENA_SUPPORT
+bool Map::occupied(int x, int y) const
+{
+ const Beings &beings = beingManager->getAll();
+ for (Beings::const_iterator i = beings.begin(); i != beings.end(); i++)
+ {
+ const Being *being = *i;
+
+ // job 45 is a portal, they don't collide
+ if (being->mX == x && being->mY == y && being->mJob != 45)
+ return true;
+ }
+
+ return false;
+}
+#endif
+
bool Map::contains(int x, int y) const
{
return x >= 0 && y >= 0 && x < mWidth && y < mHeight;
@@ -475,7 +492,8 @@ const std::string &Map::getName() const
static int const basicCost = 100;
-Path Map::findPath(int startX, int startY, int destX, int destY, unsigned char walkmask, int maxCost)
+Path Map::findPath(int startX, int startY, int destX, int destY,
+ unsigned char walkmask, int maxCost)
{
// Path to be built up (empty by default)
Path path;
@@ -533,7 +551,8 @@ Path Map::findPath(int startX, int startY, int destX, int destY, unsigned char w
// Skip if the tile is on the closed list or is not walkable
// unless its the destination tile
if (newTile->whichList == mOnClosedList ||
- ((newTile->blockmask & walkmask) && !(x == destX && y == destY)))
+ ((newTile->blockmask & walkmask)
+ && !(x == destX && y == destY)))
{
continue;
}
@@ -545,10 +564,8 @@ Path Map::findPath(int startX, int startY, int destX, int destY, unsigned char w
MetaTile *t1 = getMetaTile(curr.x, curr.y + dy);
MetaTile *t2 = getMetaTile(curr.x + dx, curr.y);
- if (t1->blockmask & walkmask && !(t2->blockmask & walkmask)) // I hope I didn't fuck this line up
- {
+ if ((t1->blockmask | t2->blockmask) & BLOCKMASK_WALL)
continue;
- }
}
// Calculate G cost for this route, ~sqrt(2) for moving diagonal
@@ -569,12 +586,14 @@ Path Map::findPath(int startX, int startY, int destX, int destY, unsigned char w
++Gcost;
}
+#ifdef EATHENA_SUPPORT
// It costs extra to walk through a being (needs to be enough
// to make it more attractive to walk around).
- if (!getWalk(x, y, BLOCKMASK_CHARACTER | BLOCKMASK_MONSTER))
+ if (occupied(x, y))
{
Gcost += 3 * basicCost;
}
+#endif
// Skip if Gcost becomes too much
// Warning: probably not entirely accurate