00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _TMW_MAP_H
00023 #define _TMW_MAP_H
00024
00025 #include <list>
00026 #include <map>
00027 #include <string>
00028
00029 const unsigned int DEFAULT_TILE_WIDTH = 32;
00030 const unsigned int DEFAULT_TILE_HEIGHT = 32;
00031
00032 struct PATH_NODE {
00033 PATH_NODE(unsigned short u, unsigned short v)
00034 : x(u), y(v)
00035 {}
00036
00037 unsigned short x, y;
00038 };
00039
00045 class MetaTile
00046 {
00047 public:
00051 MetaTile();
00052
00053
00054 int Fcost;
00055 int Gcost;
00056 int Hcost;
00057 int whichList;
00058 int parentX;
00059 int parentY;
00060 char blockmask;
00061 };
00062
00066 class Location
00067 {
00068 public:
00072 Location(int x, int y, MetaTile *tile);
00073
00077 bool operator< (const Location &loc) const;
00078
00079 int x, y;
00080 MetaTile *tile;
00081 };
00082
00086 class Map
00087 {
00088 public:
00089 enum BlockType
00090 {
00091 BLOCKTYPE_NONE = -1,
00092 BLOCKTYPE_WALL,
00093 BLOCKTYPE_CHARACTER,
00094 BLOCKTYPE_MONSTER,
00095 NB_BLOCKTYPES
00096 };
00097
00101 Map(int width = 0, int height = 0, int twidth = 32, int theight = 32);
00102
00106 ~Map();
00107
00111 void setSize(int mWidth, int height);
00112
00116 MetaTile *getMetaTile(int x, int y);
00117
00121 void blockTile(int x, int y, BlockType type);
00122
00126 void freeTile(int x, int y, BlockType type);
00127
00131 bool getWalk(int x, int y, char walkmask) const;
00132
00136 int getWidth() const
00137 { return mWidth; }
00138
00142 int getHeight() const
00143 { return mHeight; }
00144
00148 int getTileWidth() const
00149 { return tileWidth; }
00150
00154 int getTileHeight() const
00155 { return tileHeight; }
00156
00160 const std::string &getProperty(const std::string &key) const;
00161
00165 void setProperty(const std::string& key, const std::string& val)
00166 { mProperties[key] = val; }
00167
00171 std::list<PATH_NODE> findPath(int startX, int startY,
00172 int destX, int destY,
00173 unsigned char walkmask,
00174 int maxCost = 20);
00175
00176 private:
00180 static const unsigned char BLOCKMASK_WALL = 0x80;
00181 static const unsigned char BLOCKMASK_CHARACTER = 0x01;
00182 static const unsigned char BLOCKMASK_MONSTER = 0x02;
00183 int *mOccupation[NB_BLOCKTYPES];
00184
00185
00186 int mWidth, mHeight;
00187 int tileWidth, tileHeight;
00188 std::map<std::string, std::string> mProperties;
00189
00190
00191 MetaTile *mMetaTiles;
00192 int onClosedList, onOpenList;
00193 };
00194
00195 #endif