diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-06-08 23:07:00 +0200 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-06-08 23:07:50 +0200 |
commit | 2a60ed3f85004c872eb9d0ae39d4aa1c47626543 (patch) | |
tree | 45db39c43ebe0b2ae8b3dc1d061d000d02c2e5a5 | |
parent | 32457dd5b2f9431d4f5d503dc8b090a9c1b7f944 (diff) | |
download | mana-2a60ed3f85004c872eb9d0ae39d4aa1c47626543.tar.gz mana-2a60ed3f85004c872eb9d0ae39d4aa1c47626543.tar.bz2 mana-2a60ed3f85004c872eb9d0ae39d4aa1c47626543.tar.xz mana-2a60ed3f85004c872eb9d0ae39d4aa1c47626543.zip |
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.
-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. */ |