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 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/map.cpp') 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 -- cgit v1.2.3-60-g2f50