From fe474eb4fae9d89e3797d0ceaae6613798ce491f Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Thu, 13 Mar 2008 07:29:30 +0000 Subject: Synchronized pathfinding algorithmns with those used by the server to avoid asynchronisation. --- src/map.h | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'src/map.h') diff --git a/src/map.h b/src/map.h index d8cc2189..71bbf843 100644 --- a/src/map.h +++ b/src/map.h @@ -54,7 +54,7 @@ struct MetaTile /** * Constructor. */ - MetaTile():whichList(0) {}; + MetaTile():whichList(0), blockmask(0) {}; // Pathfinding members int Fcost; /**< Estimation of total path cost */ @@ -63,7 +63,7 @@ struct MetaTile int whichList; /**< No list, open list or closed list */ int parentX; /**< X coordinate of parent tile */ int parentY; /**< Y coordinate of parent tile */ - bool walkable; /**< Can beings walk on this tile */ + unsigned char blockmask; /**< Can beings walk on this tile */ }; /** @@ -72,6 +72,15 @@ struct MetaTile class Map : public Properties { public: + enum BlockType + { + BLOCKTYPE_NONE = -1, + BLOCKTYPE_WALL, + BLOCKTYPE_CHARACTER, + BLOCKTYPE_MONSTER, + NB_BLOCKTYPES + }; + /** * Constructor, taking map and tile size as parameters. */ @@ -93,6 +102,11 @@ class Map : public Properties */ void draw(Graphics *graphics, int scrollX, int scrollY, int layer); + /** + * Visualizes collision layer for debugging + */ + void drawCollision(Graphics *graphics, int scrollX, int scrollY); + /** * Draws the overlay graphic to the given graphics output. */ @@ -129,19 +143,19 @@ class Map : public Properties MetaTile *getMetaTile(int x, int y) const; /** - * Set walkability flag for a tile. + * Marks a tile as occupied */ - void setWalk(int x, int y, bool walkable); + void blockTile(int x, int y, BlockType type); /** - * Tell if a tile is walkable or not, includes checking beings. + * Marks a tile as unoccupied */ - bool getWalk(int x, int y) const; + void freeTile(int x, int y, BlockType type); /** - * Tell if a tile collides, not including a check on beings. + * Gets walkability for a tile with a blocking bitmask */ - bool tileCollides(int x, int y) const; + bool getWalk(int x, int y, char walkmask) const; /** * Returns the width of this map. @@ -171,7 +185,7 @@ class Map : public Properties * Find a path from one location to the next. */ std::list - findPath(int startX, int startY, int destX, int destY); + findPath(int startX, int startY, int destX, int destY, unsigned char walkmask, int maxCost = 20); /** * Adds a sprite to the map. @@ -209,14 +223,20 @@ class Map : public Properties Tileset* getTilesetWithGid(int gid) const; /** - * Tells whether a tile is occupied by a being. + * Tells whether the given coordinates fall within the map boundaries. */ - bool occupied(int x, int y) const; + bool contains(int x, int y) const; /** - * Tells whether the given coordinates fall within the map boundaries. + * Blockmasks for different entities */ - bool contains(int x, int y) const; + static const unsigned char BLOCKMASK_WALL = 128; // = bin 1000 0000 + static const unsigned char BLOCKMASK_CHARACTER = 1;// = bin 0000 0001 + static const unsigned char BLOCKMASK_MONSTER = 2; // = bin 0000 0010 + int *mOccupation[NB_BLOCKTYPES]; + + // Pathfinding members + int onClosedList, onOpenList; int mWidth, mHeight; int mTileWidth, mTileHeight; -- cgit v1.2.3-70-g09d2