00001
00002
00003
00004
00005
00006
00007
00008 #ifndef DUNGEON_H
00009 #define DUNGEON_H
00010
00011 #include "fixedarray.h"
00012 #include "env.h"
00013 #include "externs.h"
00014 #include "terrain.h"
00015 #include "stuff.h"
00016 #include "mapdef.h"
00017
00018 #include <vector>
00019 #include <set>
00020 #include <algorithm>
00021
00022 #define BUILD_METHOD_KEY "build_method_key"
00023 #define LAYOUT_TYPE_KEY "layout_type_key"
00024 #define LEVEL_VAULTS_KEY "level_vaults_key"
00025 #define LEVEL_EXTRAS_KEY "level_extras_key"
00026 #define LEVEL_ID_KEY "level_id_key"
00027
00028 #define YOU_PORTAL_VAULT_NAMES_KEY "you_portal_vault_names_key"
00029
00030
00031
00032 #define TEMPLE_GODS_KEY "temple_gods_key"
00033 #define OVERFLOW_TEMPLES_KEY "overflow_temples_key"
00034 #define TEMPLE_MAP_KEY "temple_map_key"
00035
00036 enum portal_type
00037 {
00038 PORTAL_NONE = 0,
00039 PORTAL_LABYRINTH,
00040 PORTAL_HELL,
00041 PORTAL_ABYSS,
00042 PORTAL_PANDEMONIUM,
00043 NUM_PORTALS
00044 };
00045
00046 const int MAKE_GOOD_ITEM = 351;
00047 const unsigned short INVALID_MAP_INDEX = 10000;
00048
00049
00050 #define MAP_SIDE ((GXM) > (GYM) ? (GXM) : (GYM))
00051
00052
00053
00054 enum map_mask_type
00055 {
00056 MMT_NONE = 0x0,
00057 MMT_VAULT = 0x01,
00058 MMT_NO_ITEM = 0x02,
00059 MMT_NO_MONS = 0x04,
00060 MMT_NO_POOL = 0x08,
00061 MMT_NO_DOOR = 0x10,
00062 MMT_NO_WALL = 0x20,
00063 MMT_OPAQUE = 0x40,
00064 MMT_NO_TRAP = 0x80,
00065 };
00066
00067 class dgn_region;
00068 typedef std::vector<dgn_region> dgn_region_list;
00069
00070 class dgn_region
00071 {
00072 public:
00073
00074 coord_def pos, size;
00075
00076 dgn_region(int left, int top, int width, int height)
00077 : pos(left, top), size(width, height)
00078 {
00079 }
00080
00081 dgn_region(const coord_def &_pos, const coord_def &_size)
00082 : pos(_pos), size(_size)
00083 {
00084 }
00085
00086 dgn_region() : pos(-1, -1), size()
00087 {
00088 }
00089
00090 coord_def end() const
00091 {
00092 return pos + size - coord_def(1, 1);
00093 }
00094
00095 coord_def random_edge_point() const;
00096 coord_def random_point() const;
00097
00098 static dgn_region absolute(int left, int top, int right, int bottom)
00099 {
00100 return dgn_region(left, top, right - left + 1, bottom - top + 1);
00101 }
00102
00103 static dgn_region absolute(const coord_def &c1, const coord_def &c2)
00104 {
00105 return dgn_region(c1.x, c1.y, c2.x, c2.y);
00106 }
00107
00108 static bool between(int val, int low, int high)
00109 {
00110 return (val >= low && val <= high);
00111 }
00112
00113 bool contains(const coord_def &p) const
00114 {
00115 return contains(p.x, p.y);
00116 }
00117
00118 bool contains(int xp, int yp) const
00119 {
00120 return (xp >= pos.x && xp < pos.x + size.x
00121 && yp >= pos.y && yp < pos.y + size.y);
00122 }
00123
00124 bool fully_contains(const coord_def &p) const
00125 {
00126 return (p.x > pos.x && p.x < pos.x + size.x - 1
00127 && p.y > pos.y && p.y < pos.y + size.y - 1);
00128 }
00129
00130 bool overlaps(const dgn_region &other) const;
00131 bool overlaps_any(const dgn_region_list &others) const;
00132 bool overlaps(const dgn_region_list &others,
00133 const map_mask &dgn_map_mask) const;
00134 bool overlaps(const map_mask &dgn_map_mask) const;
00135 };
00136
00137 struct vault_placement
00138 {
00139 public:
00140 coord_def pos;
00141 coord_def size;
00142
00143 map_section_type orient;
00144 map_def map;
00145 std::vector<coord_def> exits;
00146
00147 int level_number;
00148
00149
00150 bool seen;
00151
00152 public:
00153 vault_placement()
00154 : pos(-1, -1), size(0, 0), orient(MAP_NONE), map(),
00155 exits(), level_number(0), seen(false)
00156 {
00157 }
00158
00159 void reset();
00160 void apply_grid();
00161 void draw_at(const coord_def &c);
00162 void connect(bool spotty = false) const;
00163 };
00164
00165 class vault_place_iterator
00166 {
00167 public:
00168 vault_place_iterator(const vault_placement &vp);
00169 operator bool () const;
00170 coord_def operator * () const;
00171 const coord_def *operator -> () const;
00172 vault_place_iterator &operator ++ ();
00173 vault_place_iterator operator ++ (int);
00174 private:
00175 const vault_placement &vault_place;
00176 coord_def pos;
00177 coord_def tl, br;
00178 };
00179
00180 class unwind_vault_placement_mask
00181 {
00182 public:
00183 unwind_vault_placement_mask(const map_mask *mask);
00184 ~unwind_vault_placement_mask();
00185 private:
00186 const map_mask *oldmask;
00187 };
00188
00189 extern bool Generating_Level;
00190 extern std::vector<vault_placement> Temp_Vaults;
00191
00192 extern const map_mask *Vault_Placement_Mask;
00193
00194 void init_level_connectivity();
00195 void read_level_connectivity(reader &th);
00196 void write_level_connectivity(writer &th);
00197
00198 bool builder(int level_number, level_area_type level_type,
00199 bool enable_random_maps = true);
00200 void dgn_veto_level();
00201
00202 void dgn_clear_vault_placements(vault_placement_refv &vps);
00203 void dgn_erase_unused_vault_placements();
00204 void dgn_flush_map_memory();
00205
00206 double dgn_degrees_to_radians(int degrees);
00207 bool dgn_has_adjacent_feat(coord_def c, dungeon_feature_type feat);
00208 coord_def dgn_random_point_in_margin(int margin);
00209 coord_def dgn_random_point_from(const coord_def &c, int radius, int margin = 1);
00210 coord_def dgn_random_point_visible_from(const coord_def &c,
00211 int radius,
00212 int margin = 1,
00213 int tries = 5);
00214 coord_def dgn_find_feature_marker(dungeon_feature_type feat);
00215
00216
00217 void dgn_place_stone_stairs(bool maybe_place_hatches = false);
00218
00219
00220
00221 void dgn_set_colours_from_monsters();
00222 void dgn_set_grid_colour_at(const coord_def &c, int colour);
00223
00224 bool dgn_place_map(const map_def *map,
00225 bool clobber,
00226 bool make_no_exits,
00227 const coord_def &pos = INVALID_COORD);
00228
00229 const map_def *dgn_safe_place_map(const map_def *map,
00230 bool clobber,
00231 bool make_no_exits,
00232 const coord_def &pos = INVALID_COORD);
00233
00234 void level_clear_vault_memory();
00235 void level_welcome_messages();
00236 void run_map_epilogues ();
00237
00238
00239 bool place_specific_trap(const coord_def& where, trap_type spec_type);
00240 void place_spec_shop(int level_number, const coord_def& where,
00241 int force_s_type, bool representative = false);
00242 bool seen_replace_feat(dungeon_feature_type replace,
00243 dungeon_feature_type feature);
00244 bool map_masked(const coord_def &c, unsigned mask);
00245 coord_def dgn_find_nearby_stair(dungeon_feature_type stair_to_find,
00246 coord_def base_pos, bool find_closest);
00247
00248 class mons_spec;
00249 int dgn_place_monster(mons_spec &mspec,
00250 int monster_level, const coord_def& where,
00251 bool force_pos = false, bool generate_awake = false,
00252 bool patrolling = false);
00253 int dgn_place_item(const item_spec &spec,
00254 const coord_def &where,
00255 int level = INVALID_ABSDEPTH);
00256
00257 class item_list;
00258 void dgn_place_multiple_items(item_list &list,
00259 const coord_def& where,
00260 int level);
00261
00262 bool set_level_flags(uint32_t flags, bool silent = false);
00263 bool unset_level_flags(uint32_t flags, bool silent = false);
00264
00265 void dgn_set_lt_callback(std::string level_type_name,
00266 std::string callback_name);
00267
00268 void dgn_reset_level(bool enable_random_maps = true);
00269
00270 void dgn_register_place(const vault_placement &place, bool register_vault);
00271 void dgn_register_vault(const map_def &map);
00272
00273 void dgn_seen_vault_at(coord_def p);
00274
00275 int process_disconnected_zones(int x1, int y1, int x2, int y2,
00276 bool choose_stairless,
00277 dungeon_feature_type fill);
00278
00279
00280
00281
00282 int dgn_count_disconnected_zones(
00283 bool choose_stairless,
00284 dungeon_feature_type fill = DNGN_UNSEEN);
00285
00286 void dgn_replace_area(const coord_def& p1, const coord_def& p2,
00287 dungeon_feature_type replace,
00288 dungeon_feature_type feature,
00289 unsigned mmask = 0, bool needs_update = false);
00290 void dgn_replace_area(int sx, int sy, int ex, int ey,
00291 dungeon_feature_type replace,
00292 dungeon_feature_type feature,
00293 unsigned mmask = 0, bool needs_update = false);
00294
00295 bool dgn_ensure_vault_placed(bool vault_success,
00296 bool disable_further_vaults);
00297
00298
00299 vault_placement *dgn_vault_at(coord_def gp);
00300 void dgn_seen_vault_at(coord_def gp);
00301
00302 int count_neighbours(int x, int y, dungeon_feature_type feat);
00303 inline int count_neighbours(const coord_def& p, dungeon_feature_type feat)
00304 {
00305 return count_neighbours(p.x, p.y, feat);
00306 }
00307
00308 void remember_vault_placement(std::string key, const vault_placement &place);
00309
00310 std::string dump_vault_maps();
00311
00312 bool dgn_square_travel_ok(const coord_def &c);
00313
00314 #endif