00001 #ifndef MAP_KNOWLEDGE_H
00002 #define MAP_KNOWLEDGE_H
00003
00004 #include "show.h"
00005 #include "mon-info.h"
00006
00007 #define MAP_MAGIC_MAPPED_FLAG 0x01
00008 #define MAP_SEEN_FLAG 0x02
00009 #define MAP_CHANGED_FLAG 0x04 // FIXME: this doesn't belong here
00010 #define MAP_DETECTED_MONSTER 0x08
00011 #define MAP_INVISIBLE_MONSTER 0x10
00012 #define MAP_DETECTED_ITEM 0x20
00013 #define MAP_VISIBLE_FLAG 0x40
00014 #define MAP_GRID_KNOWN 0xFF
00015
00016 #define MAP_EMPHASIZE 0x100
00017 #define MAP_MORE_ITEMS 0x200
00018 #define MAP_HALOED 0x400
00019 #define MAP_SILENCED 0x800
00020 #define MAP_BLOODY 0x1000
00021 #define MAP_CORRODING 0x2000
00022
00023
00024 #define MAP_EXCLUDED_STAIRS 0x10000
00025 #define MAP_MOLDY 0x20000
00026 #define MAP_GLOWING_MOLDY 0x40000
00027 #define MAP_SANCTUARY_1 0x80000
00028 #define MAP_SANCTUARY_2 0x100000
00029 #define MAP_WITHHELD 0x200000
00030 #define MAP_LIQUEFIED 0x400000
00031
00032
00033
00034
00035
00036 struct map_cell
00037 {
00038 uint32_t flags;
00039
00040 map_cell() : flags(0), _feat(DNGN_UNSEEN), _feat_colour(0),
00041 _item(0), _cloud(CLOUD_NONE), _cloud_colour(0)
00042 {
00043 memset(&_mons, 0, sizeof(_mons));
00044 }
00045
00046 map_cell(const map_cell& c)
00047 {
00048 memcpy(this, &c, sizeof(map_cell));
00049 if (!(flags & MAP_DETECTED_MONSTER) && _mons.info)
00050 _mons.info = new monster_info(*_mons.info);
00051 if (_item)
00052 _item = new item_info(*_item);
00053 }
00054
00055 ~map_cell()
00056 {
00057 if (!(flags & MAP_DETECTED_MONSTER) && _mons.info)
00058 delete _mons.info;
00059 if (_item)
00060 delete _item;
00061 }
00062
00063 map_cell& operator=(const map_cell& c)
00064 {
00065 if (!(flags & MAP_DETECTED_MONSTER) && _mons.info)
00066 delete _mons.info;
00067 if (_item)
00068 delete _item;
00069 memcpy(this, &c, sizeof(map_cell));
00070 if (!(flags & MAP_DETECTED_MONSTER) && _mons.info)
00071 _mons.info = new monster_info(*_mons.info);
00072 if (_item)
00073 _item = new item_info(*_item);
00074 return (*this);
00075 }
00076
00077 void clear()
00078 {
00079 *this = map_cell();
00080 }
00081
00082
00083 void clear_data()
00084 {
00085 const uint8_t f = flags & MAP_SEEN_FLAG;
00086 clear();
00087 flags = f;
00088 }
00089
00090 dungeon_feature_type feat() const
00091 {
00092 return _feat;
00093 }
00094
00095 unsigned feat_colour() const
00096 {
00097 return _feat_colour;
00098 }
00099
00100 void set_feature(dungeon_feature_type nfeat, unsigned colour = 0)
00101 {
00102 _feat = nfeat;
00103 _feat_colour = colour;
00104 }
00105
00106 item_info* item() const
00107 {
00108 return _item;
00109 }
00110
00111 bool detected_item() const
00112 {
00113 return !!(flags & MAP_DETECTED_ITEM);
00114 }
00115
00116 void set_item(const item_info& ii, bool more_items)
00117 {
00118 clear_item();
00119 _item = new item_info(ii);
00120 if (more_items)
00121 flags |= MAP_MORE_ITEMS;
00122 }
00123
00124 void set_detected_item();
00125
00126 void clear_item()
00127 {
00128 if (_item)
00129 {
00130 delete _item;
00131 _item = 0;
00132 }
00133 flags &= ~(MAP_DETECTED_ITEM | MAP_MORE_ITEMS);
00134 }
00135
00136 monster_type monster() const
00137 {
00138 if (flags & MAP_DETECTED_MONSTER)
00139 return _mons.detected;
00140 else if (_mons.info)
00141 return _mons.info->type;
00142 else
00143 return MONS_NO_MONSTER;
00144 }
00145
00146 monster_info* monsterinfo() const
00147 {
00148 if (flags & MAP_DETECTED_MONSTER)
00149 return 0;
00150 else
00151 return _mons.info;
00152 }
00153
00154 void set_monster(const monster_info& mi)
00155 {
00156 clear_monster();
00157 _mons.info = new monster_info(mi);
00158 }
00159
00160 bool detected_monster() const
00161 {
00162 return !!(flags & MAP_DETECTED_MONSTER);
00163 }
00164
00165 bool invisible_monster() const
00166 {
00167 return !!(flags & MAP_INVISIBLE_MONSTER);
00168 }
00169
00170 void set_detected_monster(monster_type mons)
00171 {
00172 clear_monster();
00173 _mons.detected = mons;
00174 flags |= MAP_DETECTED_MONSTER;
00175 }
00176
00177 void set_invisible_monster()
00178 {
00179 clear_monster();
00180 flags |= MAP_INVISIBLE_MONSTER;
00181 }
00182
00183 void clear_monster()
00184 {
00185 if (!(flags & MAP_DETECTED_MONSTER) && _mons.info)
00186 delete _mons.info;
00187 flags &= ~(MAP_DETECTED_MONSTER | MAP_INVISIBLE_MONSTER);
00188 memset(&_mons, 0, sizeof(_mons));
00189 }
00190
00191 cloud_type cloud() const
00192 {
00193 return _cloud;
00194 }
00195
00196 unsigned cloud_colour() const
00197 {
00198 return _cloud_colour;
00199 }
00200
00201 void set_cloud(cloud_type ncloud, unsigned colour = 0)
00202 {
00203 _cloud = ncloud;
00204 _cloud_colour = colour;
00205 }
00206
00207 bool known() const
00208 {
00209 return !!(flags & MAP_GRID_KNOWN);
00210 }
00211
00212 bool seen() const
00213 {
00214 return !!(flags & MAP_SEEN_FLAG);
00215 }
00216
00217 bool visible() const
00218 {
00219 return !!(flags & MAP_VISIBLE_FLAG);
00220 }
00221
00222 bool changed() const
00223 {
00224 return !!(flags & MAP_CHANGED_FLAG);
00225 }
00226
00227 bool mapped() const
00228 {
00229 return !!(flags & MAP_MAGIC_MAPPED_FLAG);
00230 }
00231
00232 private:
00233 dungeon_feature_type _feat;
00234 uint8_t _feat_colour;
00235 item_info* _item;
00236 union
00237 {
00238 monster_info* info;
00239 monster_type detected;
00240 } _mons;
00241 cloud_type _cloud;
00242 uint8_t _cloud_colour;
00243 };
00244
00245 void set_terrain_mapped(int x, int y);
00246 inline void set_terrain_mapped(const coord_def& c) {
00247 set_terrain_mapped(c.x,c.y);
00248 }
00249 void set_terrain_seen(int x, int y);
00250 inline void set_terrain_seen(const coord_def& c) {
00251 set_terrain_seen(c.x, c.y);
00252 }
00253 void set_terrain_changed(int x, int y);
00254
00255 inline void set_terrain_changed(const coord_def &c)
00256 {
00257 set_terrain_changed(c.x, c.y);
00258 }
00259
00260 void set_terrain_visible(const coord_def &c);
00261 void clear_terrain_visibility();
00262
00263 int count_detected_mons(void);
00264 void map_knowledge_forget_mons(const coord_def &c);
00265
00266 void clear_map(bool clear_items = true, bool clear_mons = true);
00267
00268 #endif