1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
#include "AppHdr.h"
#include "map_knowledge.h"
#include "coordit.h"
#include "dgn-overview.h"
#include "dgnevent.h"
#include "directn.h"
#include "env.h"
#include "feature.h"
#include "los.h"
#include "mon-util.h"
#include "notes.h"
#include "options.h"
#include "show.h"
#include "showsymb.h"
#include "stuff.h"
#include "terrain.h"
#ifdef USE_TILE
#include "tilepick.h"
#include "tileview.h"
#endif
#include "view.h"
// These are hidden from the rest of the world... use the functions
// below to get information about the map grid.
#define MAP_MAGIC_MAPPED_FLAG 0x01
#define MAP_SEEN_FLAG 0x02
#define MAP_CHANGED_FLAG 0x04 // FIXME: this doesn't belong here
#define MAP_DETECTED_MONSTER 0x08
#define MAP_DETECTED_ITEM 0x10
#define MAP_GRID_KNOWN 0xFF
unsigned map_cell::glyph(bool clean_map) const
{
if (!object)
return (' ');
if ((clean_map && object.is_cleanable_monster())
|| object.cls < SH_MONSTER)
{
const feature_def &fdef = get_feature_def(object);
return ((flags & MAP_SEEN_FLAG) ? fdef.symbol : fdef.magic_symbol);
}
else
return (mons_char(object.mons));
}
dungeon_feature_type map_cell::feat() const
{
return (object.feat);
}
show_item_type map_cell::item() const
{
return (object.item);
}
bool map_cell::known() const
{
return (object && (flags & MAP_GRID_KNOWN));
}
bool map_cell::seen() const
{
return (object && (flags & MAP_SEEN_FLAG));
}
unsigned get_map_knowledge_char(int x, int y)
{
return env.map_knowledge[x][y].glyph(Options.clean_map);
}
show_type get_map_knowledge_obj(int x, int y)
{
return (env.map_knowledge[x][y].object);
}
void set_map_knowledge_detected_item(int x, int y, bool detected)
{
if (detected)
{
env.map_knowledge[x][y].flags |= MAP_DETECTED_ITEM;
env.map_knowledge[x][y].object.colour = Options.detected_item_colour;
}
else
env.map_knowledge[x][y].flags &= ~MAP_DETECTED_ITEM;
}
bool is_map_knowledge_detected_item(int x, int y)
{
return (env.map_knowledge[x][y].flags & MAP_DETECTED_ITEM);
}
void set_map_knowledge_detected_mons(int x, int y, bool detected)
{
if (detected)
{
env.map_knowledge[x][y].flags |= MAP_DETECTED_MONSTER;
env.map_knowledge[x][y].object.colour = Options.detected_monster_colour;
}
else
env.map_knowledge[x][y].flags &= ~MAP_DETECTED_MONSTER;
}
bool is_map_knowledge_detected_mons(int x, int y)
{
return (env.map_knowledge[x][y].flags & MAP_DETECTED_MONSTER);
}
void map_knowledge_forget_mons(const coord_def& c)
{
if (!is_map_knowledge_detected_mons(c))
return;
env.map_knowledge(c).flags &= ~MAP_DETECTED_MONSTER;
show_type* obj = &env.map_knowledge(c).object;
if (obj->cls == SH_MONSTER)
obj->cls = (obj->feat == DNGN_UNSEEN ? SH_NOTHING : SH_FEATURE);
}
void set_map_knowledge_obj(const coord_def& where, show_type obj)
{
env.map_knowledge(where).object = obj;
#ifdef USE_TILE
tiles.update_minimap(where);
#endif
}
bool is_map_knowledge_item(int x, int y)
{
return (env.map_knowledge[x][y].object.cls == SH_ITEM);
}
bool is_map_knowledge_mons(int x, int y)
{
return (env.map_knowledge[x][y].object.cls == SH_MONSTER);
}
int get_map_knowledge_col(const coord_def& p)
{
return (env.map_knowledge[p.x][p.y].object.colour);
}
bool is_terrain_known( int x, int y )
{
return (env.map_knowledge[x][y].known());
}
bool is_terrain_known(const coord_def &p)
{
return (env.map_knowledge(p).known());
}
bool is_terrain_seen( int x, int y )
{
return (env.map_knowledge[x][y].flags & MAP_SEEN_FLAG);
}
bool is_terrain_changed( int x, int y )
{
return (env.map_knowledge[x][y].flags & MAP_CHANGED_FLAG);
}
bool is_terrain_mapped(const coord_def &p)
{
return (env.map_knowledge(p).flags & MAP_MAGIC_MAPPED_FLAG);
}
// Used to mark dug out areas, unset when terrain is seen or mapped again.
void set_terrain_changed( int x, int y )
{
env.map_knowledge[x][y].flags |= MAP_CHANGED_FLAG;
dungeon_events.fire_position_event(DET_FEAT_CHANGE, coord_def(x, y));
los_terrain_changed(coord_def(x,y));
}
void set_terrain_mapped( int x, int y )
{
const coord_def gc(x, y);
map_cell* cell = &env.map_knowledge(gc);
cell->flags &= (~MAP_CHANGED_FLAG);
cell->flags |= MAP_MAGIC_MAPPED_FLAG;
cell->object.colour = get_feature_def(cell->object).map_colour;
#ifdef USE_TILE
tiles.update_minimap(gc);
#endif
}
int count_detected_mons()
{
int count = 0;
for (rectangle_iterator ri(BOUNDARY_BORDER - 1); ri; ++ri)
{
// Don't expose new dug out areas:
// Note: assumptions are being made here about how
// terrain can change (eg it used to be solid, and
// thus monster/item free).
if (is_terrain_changed(*ri))
continue;
if (is_map_knowledge_detected_mons(*ri))
count++;
}
return (count);
}
void clear_map(bool clear_detected_items, bool clear_detected_monsters)
{
for (rectangle_iterator ri(BOUNDARY_BORDER - 1); ri; ++ri)
{
const coord_def p = *ri;
if (!is_terrain_known(p))
continue;
if (is_map_knowledge_item(p))
continue;
if (!clear_detected_items && is_map_knowledge_detected_item(p))
continue;
if (!clear_detected_monsters && is_map_knowledge_detected_mons(p))
continue;
show_type plain = env.map_knowledge(p).object;
// If it's an immobile monster or a feature, don't erase.
if ((plain.cls != SH_MONSTER || plain.is_cleanable_monster())
&& plain.cls != SH_FEATURE)
{
plain = show_type(plain.feat);
#ifdef USE_TILE
tile_clear_map(p);
#endif
}
set_map_knowledge_obj(p, to_knowledge(plain));
set_map_knowledge_detected_mons(p, false);
set_map_knowledge_detected_item(p, false);
}
}
static void _automap_from( int x, int y, int mutated )
{
if (mutated)
magic_mapping(8 * mutated, 25, true, false,
true, true, coord_def(x,y));
}
void reautomap_level( )
{
int passive = player_mutation_level(MUT_PASSIVE_MAPPING);
for (int x = X_BOUND_1; x <= X_BOUND_2; ++x)
for (int y = Y_BOUND_1; y <= Y_BOUND_2; ++y)
if (env.map_knowledge[x][y].flags & MAP_SEEN_FLAG)
_automap_from(x, y, passive);
}
void set_terrain_seen( int x, int y )
{
const dungeon_feature_type feat = grd[x][y];
map_cell* cell = &env.map_knowledge[x][y];
// First time we've seen a notable feature.
// In unmappable areas, this doesn't work since
// map knowledge gets wiped each turn.
if (!(cell->flags & MAP_SEEN_FLAG) && player_in_mappable_area())
{
_automap_from(x, y, player_mutation_level(MUT_PASSIVE_MAPPING));
const bool boring = !is_notable_terrain(feat)
// A portal deeper into the Zigguart is boring.
|| (feat == DNGN_ENTER_PORTAL_VAULT
&& you.level_type == LEVEL_PORTAL_VAULT)
// Altars in the temple are boring.
|| (feat_is_altar(feat)
&& player_in_branch(BRANCH_ECUMENICAL_TEMPLE))
// Only note the first entrance to the Abyss/Pan/Hell
// which is found.
|| ((feat == DNGN_ENTER_ABYSS || feat == DNGN_ENTER_PANDEMONIUM
|| feat == DNGN_ENTER_HELL)
&& overview_knows_num_portals(feat) > 1)
// There are at least three Zot entrances, and they're always
// on D:27, so ignore them.
|| feat == DNGN_ENTER_ZOT;
if (!boring)
{
coord_def pos(x, y);
std::string desc =
feature_description(pos, false, DESC_NOCAP_A);
take_note(Note(NOTE_SEEN_FEAT, 0, 0, desc.c_str()));
}
}
cell->flags &= (~MAP_CHANGED_FLAG);
cell->flags |= MAP_SEEN_FLAG;
cell->object.colour = get_feature_def(cell->object).seen_colour;
}
void clear_map_knowledge_grid( const coord_def& p )
{
env.map_knowledge(p).clear();
}
void clear_map_knowledge_grid( int x, int y )
{
env.map_knowledge[x][y].clear();
}
|