From 2a60ed3f85004c872eb9d0ae39d4aa1c47626543 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 8 Jun 2009 23:07:00 +0200 Subject: Reintroduced the 'occupied' check for eAthena movement code Makes sure the player walks around other players and beings when reasonably possible. This was meant to be based on the blockmask stuff, but I half removed that a few months ago. --- src/map.cpp | 23 +++++++++++++++++++++-- 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 diff --git a/src/map.h b/src/map.h index cb0271b3..6baf7411 100644 --- a/src/map.h +++ b/src/map.h @@ -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. */ -- cgit v1.2.3-60-g2f50