diff options
-rw-r--r-- | src/map.cpp | 23 | ||||
-rw-r--r-- | src/map.h | 7 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/map.cpp b/src/map.cpp index 0b1550db..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) { @@ -439,6 +439,23 @@ bool Map::getWalk(int x, int y, unsigned 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; @@ -569,12 +586,14 @@ Path Map::findPath(int startX, int startY, int destX, int destY, ++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 @@ -227,6 +227,13 @@ class Map : public Properties bool getWalk(int x, int y, unsigned char walkmask = BLOCKMASK_WALL) const; +#ifdef EATHENA_SUPPORT + /** + * Tells whether a tile is occupied by a being. + */ + bool occupied(int x, int y) const; +#endif + /** * Returns the width of this map in tiles. */ |