diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2008-03-15 00:01:09 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2008-03-15 00:01:09 +0000 |
commit | 68c0625ee9a3a01090f0bc93612bf84dd71eaa67 (patch) | |
tree | d1cd93e73bb2e5a2746f8cbd2c1cfac2c5dcce39 /src/game-server | |
parent | 4736ec595c1ed46f8b076f89bc31660ae21e9231 (diff) | |
download | manaserv-68c0625ee9a3a01090f0bc93612bf84dd71eaa67.tar.gz manaserv-68c0625ee9a3a01090f0bc93612bf84dd71eaa67.tar.bz2 manaserv-68c0625ee9a3a01090f0bc93612bf84dd71eaa67.tar.xz manaserv-68c0625ee9a3a01090f0bc93612bf84dd71eaa67.zip |
Implemented script binding for controllig movement of beings and fixed a crash caused by the new blocking system (thanks to peavey for reporting).
Diffstat (limited to 'src/game-server')
-rw-r--r-- | src/game-server/map.cpp | 13 | ||||
-rw-r--r-- | src/game-server/movingobject.cpp | 15 | ||||
-rw-r--r-- | src/game-server/object.hpp | 3 |
3 files changed, 24 insertions, 7 deletions
diff --git a/src/game-server/map.cpp b/src/game-server/map.cpp index c4f2c02e..ceb48b04 100644 --- a/src/game-server/map.cpp +++ b/src/game-server/map.cpp @@ -98,9 +98,12 @@ Map::setSize(int width, int height) void Map::blockTile(int x, int y, BlockType type) { - if (type == BLOCKTYPE_NONE) return; + if (type == BLOCKTYPE_NONE || x < 0 || y < 0 || x >= mWidth || y >= mHeight) + { + return; + } + int tileNum = x + y * mWidth; - assert (tileNum <= mWidth * mHeight); if (++mOccupation[type][tileNum]) { @@ -124,10 +127,12 @@ void Map::blockTile(int x, int y, BlockType type) void Map::freeTile(int x, int y, BlockType type) { - if (type == BLOCKTYPE_NONE) return; + if (type == BLOCKTYPE_NONE || x < 0 || y < 0 || x >= mWidth || y >= mHeight) + { + return; + } int tileNum = x + y * mWidth; - assert (tileNum <= mWidth * mHeight); if (!(--mOccupation[type][tileNum])) { diff --git a/src/game-server/movingobject.cpp b/src/game-server/movingobject.cpp index f7db2d93..70334341 100644 --- a/src/game-server/movingobject.cpp +++ b/src/game-server/movingobject.cpp @@ -20,6 +20,8 @@ * $Id$ */ +#include <cassert> + #include "game-server/map.hpp" #include "game-server/mapcomposite.hpp" #include "game-server/movingobject.hpp" @@ -43,14 +45,22 @@ void MovingObject::setPosition(const Point &p) void MovingObject::setMap(MapComposite *map) { - Point p = getPosition(); + assert (map); MapComposite *oldMap = getMap(); + Point p = getPosition(); + 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); + map->getMap()->blockTile(p.x / 32, p.y / 32, getBlockType()); + /* the last line might look illogical because the current position is + * invalid on the new map, but it is necessary to block the old position + * because the next call of setPosition() will automatically free the old + * position. When we don't block the position now the occupation counting + * will be off. + */ } void MovingObject::setDestination(Point const &dst) @@ -63,6 +73,7 @@ void MovingObject::setDestination(Point const &dst) void MovingObject::move() { mOld = getPosition(); + if (mActionTime > 100) { // Current move has not yet ended diff --git a/src/game-server/object.hpp b/src/game-server/object.hpp index f50dff4d..92980d02 100644 --- a/src/game-server/object.hpp +++ b/src/game-server/object.hpp @@ -51,7 +51,8 @@ class Object : public Thing */ Object(int type) : Thing(type), - mUpdateFlags(0) + mUpdateFlags(0), + mPos(Point(0, 0)) {} /** |