From 68c0625ee9a3a01090f0bc93612bf84dd71eaa67 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sat, 15 Mar 2008 00:01:09 +0000 Subject: Implemented script binding for controllig movement of beings and fixed a crash caused by the new blocking system (thanks to peavey for reporting). --- src/game-server/map.cpp | 13 +++++++++---- src/game-server/movingobject.cpp | 15 +++++++++++++-- src/game-server/object.hpp | 3 ++- 3 files changed, 24 insertions(+), 7 deletions(-) (limited to 'src/game-server') 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 + #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)) {} /** -- cgit v1.2.3-60-g2f50