summaryrefslogtreecommitdiff
path: root/src/map.h
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2008-03-13 07:29:30 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2008-03-13 07:29:30 +0000
commitfe474eb4fae9d89e3797d0ceaae6613798ce491f (patch)
tree2a91b2f17636ae7b20eea06a28a89942f6f36d39 /src/map.h
parent3a275cc81fe9aa1cb6736cdf12211e13e93cf2cf (diff)
downloadmana-client-fe474eb4fae9d89e3797d0ceaae6613798ce491f.tar.gz
mana-client-fe474eb4fae9d89e3797d0ceaae6613798ce491f.tar.bz2
mana-client-fe474eb4fae9d89e3797d0ceaae6613798ce491f.tar.xz
mana-client-fe474eb4fae9d89e3797d0ceaae6613798ce491f.zip
Synchronized pathfinding algorithmns with those used by the server to avoid asynchronisation.
Diffstat (limited to 'src/map.h')
-rw-r--r--src/map.h46
1 files changed, 33 insertions, 13 deletions
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.
*/
@@ -94,6 +103,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.
*/
void
@@ -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<PATH_NODE>
- 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;