diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2008-03-13 07:29:01 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2008-03-13 07:29:01 +0000 |
commit | efe4ef65bedbaa66e35f3a4354f7422c313ce624 (patch) | |
tree | c1259e6a60e80ee5b8ba97c44f9223071aba4df7 /src/game-server/movingobject.cpp | |
parent | 344fe375ff6e7db425da6ca266e02ea93dd7cc4d (diff) | |
download | manaserv-efe4ef65bedbaa66e35f3a4354f7422c313ce624.tar.gz manaserv-efe4ef65bedbaa66e35f3a4354f7422c313ce624.tar.bz2 manaserv-efe4ef65bedbaa66e35f3a4354f7422c313ce624.tar.xz manaserv-efe4ef65bedbaa66e35f3a4354f7422c313ce624.zip |
Implemented dynamic and selective pathblocking. Monsters are blocked by player characters and other monsters, player characters only by monsters.
Diffstat (limited to 'src/game-server/movingobject.cpp')
-rw-r--r-- | src/game-server/movingobject.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/game-server/movingobject.cpp b/src/game-server/movingobject.cpp index a24e1070..f7db2d93 100644 --- a/src/game-server/movingobject.cpp +++ b/src/game-server/movingobject.cpp @@ -24,6 +24,35 @@ #include "game-server/mapcomposite.hpp" #include "game-server/movingobject.hpp" + +void MovingObject::setPosition(const Point &p) +{ + //update blockmap + if (getMap()) + { + Point oldP = getPosition(); + if ((oldP.x / 32 != p.x / 32 || oldP.y / 32 != p.y / 32)) + { + getMap()->getMap()->freeTile(oldP.x / 32, oldP.y / 32, getBlockType()); + getMap()->getMap()->blockTile(p.x / 32, p.y / 32, getBlockType()); + } + } + + Object::setPosition(p); +} + +void MovingObject::setMap(MapComposite *map) +{ + Point p = getPosition(); + MapComposite *oldMap = getMap(); + if (oldMap) + { + oldMap->getMap()->freeTile(p.x / 32, p.y / 32, getBlockType()); + } + map->getMap()->blockTile(p.x / 32, p.y / 32, getBlockType()); + Object::setMap(map); +} + void MovingObject::setDestination(Point const &dst) { mDst = dst; @@ -63,7 +92,7 @@ void MovingObject::move() for (std::list<PATH_NODE>::iterator pathIterator = mPath.begin(); pathIterator != mPath.end(); pathIterator++) { - if (!map->getWalk(pathIterator->x, pathIterator->y)) + if (!map->getWalk(pathIterator->x, pathIterator->y, getWalkMask())) { mPath.clear(); break; @@ -74,7 +103,7 @@ void MovingObject::move() { // No path exists: the walkability of cached path has changed, the // destination has changed, or a path was never set. - mPath = map->findPath(tileSX, tileSY, tileDX, tileDY); + mPath = map->findPath(tileSX, tileSY, tileDX, tileDY, getWalkMask()); } if (mPath.empty()) |