1 /** 2 * \file generate.h 3 * \brief Dungeon generation. 4 */ 5 6 7 #ifndef GENERATE_H 8 #define GENERATE_H 9 10 #include "monster.h" 11 12 #if __STDC_VERSION__ < 199901L 13 #define ROOM_LOG if (OPT(player, cheat_room)) msg 14 #else 15 #define ROOM_LOG(...) if (OPT(player, cheat_room)) msg(__VA_ARGS__); 16 #endif 17 18 /** 19 * Dungeon allocation places and types, used with alloc_object(). 20 */ 21 enum 22 { 23 SET_CORR = 0x01, /*!< Hallway */ 24 SET_ROOM = 0x02, /*!< Room */ 25 SET_BOTH = 0x03 /*!< Anywhere */ 26 }; 27 28 enum 29 { 30 TYP_RUBBLE, /*!< Rubble */ 31 TYP_TRAP, /*!< Trap */ 32 TYP_GOLD, /*!< Gold */ 33 TYP_OBJECT, /*!< Object */ 34 TYP_GOOD, /*!< Good object */ 35 TYP_GREAT /*!< Great object */ 36 }; 37 38 /** 39 * Monster base for a pit 40 */ 41 struct pit_monster_profile { 42 struct pit_monster_profile *next; 43 44 struct monster_base *base; 45 }; 46 47 /** 48 * Monster color for a pit 49 */ 50 struct pit_color_profile { 51 struct pit_color_profile *next; 52 53 byte color; 54 }; 55 56 /** 57 * Monster forbidden from a pit 58 */ 59 struct pit_forbidden_monster { 60 struct pit_forbidden_monster *next; 61 62 struct monster_race *race; 63 }; 64 65 /** 66 * Profile for choosing monsters for pits, nests or other themed areas 67 */ 68 struct pit_profile { 69 struct pit_profile *next; /*!< Pointer to next pit profile */ 70 71 int pit_idx; /**< Index in pit_info */ 72 const char *name; 73 int room_type; /**< Is this a pit or a nest? */ 74 int ave; /**< Level where this pit is most common */ 75 int rarity; /**< How unusual this pit is */ 76 int obj_rarity; /**< How rare objects are in this pit */ 77 bitflag flags[RF_SIZE]; /**< Required flags */ 78 bitflag forbidden_flags[RF_SIZE]; /**< Forbidden flags */ 79 int freq_innate; /**< Minimum innate frequency */ 80 bitflag spell_flags[RSF_SIZE]; /**< Required spell flags */ 81 bitflag forbidden_spell_flags[RSF_SIZE]; /**< Forbidden spell flags */ 82 struct pit_monster_profile *bases; /**< List of vaild monster bases */ 83 struct pit_color_profile *colors; /**< List of valid monster colors */ 84 struct pit_forbidden_monster *forbidden_monsters; /**< Forbidden monsters */ 85 }; 86 87 extern struct pit_profile *pit_info; 88 89 90 /** 91 * Structure to hold all "dungeon generation" data 92 */ 93 struct dun_data { 94 /*!< The profile used to generate the level */ 95 const struct cave_profile *profile; 96 97 /*!< Array of centers of rooms */ 98 int cent_n; 99 struct loc *cent; 100 101 /*!< Array of possible door locations */ 102 int door_n; 103 struct loc *door; 104 105 /*!< Array of wall piercing locations */ 106 int wall_n; 107 struct loc *wall; 108 109 /*!< Array of tunnel grids */ 110 int tunn_n; 111 struct loc *tunn; 112 113 /*!< Number of grids in each block (vertically) */ 114 int block_hgt; 115 116 /*!< Number of grids in each block (horizontally) */ 117 int block_wid; 118 119 /*!< Number of blocks along each axis */ 120 int row_blocks; 121 int col_blocks; 122 123 /*!< Array of which blocks are used */ 124 bool **room_map; 125 126 /*!< Number of pits/nests on the level */ 127 int pit_num; 128 129 /*!< Current pit profile in use */ 130 struct pit_profile *pit_type; 131 132 /*!< Info for connecting to persistent levels */ 133 struct connector *join; 134 }; 135 136 137 struct tunnel_profile { 138 const char *name; 139 int rnd; /*!< % chance of choosing random direction */ 140 int chg; /*!< % chance of changing direction */ 141 int con; /*!< % chance of extra tunneling */ 142 int pen; /*!< % chance of placing doors at room entrances */ 143 int jct; /*!< % chance of doors at tunnel junctions */ 144 }; 145 146 struct streamer_profile { 147 const char *name; 148 int den; /*!< Density of streamers */ 149 int rng; /*!< Width of streamers */ 150 int mag; /*!< Number of magma streamers */ 151 int mc; /*!< 1/chance of treasure per magma */ 152 int qua; /*!< Number of quartz streamers */ 153 int qc; /*!< 1/chance of treasure per quartz */ 154 }; 155 156 /* 157 * cave_builder is a function pointer which builds a level. 158 */ 159 typedef struct chunk * (*cave_builder) (struct player *p, int h, int w); 160 161 162 struct cave_profile { 163 struct cave_profile *next; 164 165 const char *name; 166 cave_builder builder; /*!< Function used to build the level */ 167 int block_size; /*!< Default height and width of dungeon blocks */ 168 int dun_rooms; /*!< Number of rooms to attempt */ 169 int dun_unusual; /*!< Level/chance of unusual room */ 170 int max_rarity; /*!< Max number of room generation rarity levels */ 171 int n_room_profiles; /*!< Number of room profiles */ 172 struct tunnel_profile tun; /*!< Used to build tunnels */ 173 struct streamer_profile str; /*!< Used to build mineral streamers*/ 174 struct room_profile *room_profiles; /*!< Used to build rooms */ 175 int min_level; /*!< Shallowest level to use this profile */ 176 int alloc; /*!< Allocation weight for this profile */ 177 }; 178 179 180 /** 181 * room_builder is a function pointer which builds rooms in the cave given 182 * anchor coordinates. 183 */ 184 typedef bool (*room_builder) (struct chunk *c, struct loc centre, int rating); 185 186 187 /** 188 * This tracks information needed to generate the room, including the room's 189 * name and the function used to build it. 190 */ 191 struct room_profile { 192 struct room_profile *next; 193 194 const char *name; 195 room_builder builder; /*!< Function used to build fixed size rooms */ 196 int rating; /*!< Extra control for template rooms */ 197 int height, width; /*!< Space required in grids */ 198 int level; /*!< Minimum dungeon level */ 199 bool pit; /*!< Whether this room is a pit/nest or not */ 200 int rarity; /*!< How unusual this room is */ 201 int cutoff; /*!< Upper limit of 1-100 roll for room gen */ 202 }; 203 204 205 /* 206 * Information about vault generation 207 */ 208 struct vault { 209 struct vault *next; /*!< Pointer to next vault template */ 210 211 char *name; /*!< Vault name */ 212 char *text; /*!< Grid by grid description of vault layout */ 213 214 char *typ; /*!< Vault type */ 215 216 byte rat; /*!< Vault rating */ 217 218 byte hgt; /*!< Vault height */ 219 byte wid; /*!< Vault width */ 220 221 byte min_lev; /*!< Minimum allowable level, if specified. */ 222 byte max_lev; /*!< Maximum allowable level, if specified. */ 223 }; 224 225 226 227 /** 228 * Information about template room generation 229 */ 230 struct room_template { 231 struct room_template *next; /*!< Pointer to next room template */ 232 233 char *name; /*!< Room name */ 234 char *text; /*!< Grid by grid description of room layout */ 235 236 byte typ; /*!< Room type */ 237 238 byte rat; /*!< Room rating */ 239 240 byte hgt; /*!< Room height */ 241 byte wid; /*!< Room width */ 242 byte dor; /*!< Random door options */ 243 byte tval; /*!< tval for objects in this room */ 244 }; 245 246 extern struct dun_data *dun; 247 extern struct vault *vaults; 248 extern struct room_template *room_templates; 249 250 /* gen-cave.c */ 251 struct chunk *town_gen(struct player *p, int min_height, int min_width); 252 struct chunk *classic_gen(struct player *p, int min_height, int min_width); 253 struct chunk *labyrinth_gen(struct player *p, int min_height, int min_width); 254 void ensure_connectedness(struct chunk *c); 255 struct chunk *cavern_gen(struct player *p, int min_height, int min_width); 256 struct chunk *modified_gen(struct player *p, int min_height, int min_width); 257 struct chunk *moria_gen(struct player *p, int min_height, int min_width); 258 struct chunk *hard_centre_gen(struct player *p, int min_height, int min_width); 259 struct chunk *lair_gen(struct player *p, int min_height, int min_width); 260 struct chunk *gauntlet_gen(struct player *p, int min_height, int min_width); 261 struct chunk *arena_gen(struct player *p, int min_height, int min_width); 262 263 /* gen-chunk.c */ 264 struct chunk *chunk_write(struct chunk *c); 265 void chunk_list_add(struct chunk *c); 266 bool chunk_list_remove(char *name); 267 struct chunk *chunk_find_name(char *name); 268 bool chunk_find(struct chunk *c); 269 struct chunk *chunk_find_adjacent(struct player *p, bool above); 270 bool chunk_copy(struct chunk *dest, struct chunk *source, int y0, int x0, 271 int rotate, bool reflect); 272 273 void chunk_validate_objects(struct chunk *c); 274 275 276 /* gen-room.c */ 277 void fill_rectangle(struct chunk *c, int y1, int x1, int y2, int x2, int feat, 278 int flag); 279 void generate_mark(struct chunk *c, int y1, int x1, int y2, int x2, int flag); 280 void draw_rectangle(struct chunk *c, int y1, int x1, int y2, int x2, int feat, 281 int flag); 282 void set_marked_granite(struct chunk *c, struct loc grid, int flag); 283 extern bool generate_starburst_room(struct chunk *c, int y1, int x1, int y2, 284 int x2, bool light, int feat, 285 bool special_ok); 286 287 struct vault *random_vault(int depth, const char *typ); 288 bool build_vault(struct chunk *c, struct loc centre, struct vault *v); 289 290 bool build_staircase(struct chunk *c, struct loc centre, int rating); 291 bool build_simple(struct chunk *c, struct loc centre, int rating); 292 bool build_circular(struct chunk *c, struct loc centre, int rating); 293 bool build_overlap(struct chunk *c, struct loc centre, int rating); 294 bool build_crossed(struct chunk *c, struct loc centre, int rating); 295 bool build_large(struct chunk *c, struct loc centre, int rating); 296 bool mon_pit_hook(struct monster_race *race); 297 void set_pit_type(int depth, int type); 298 bool build_nest(struct chunk *c, struct loc centre, int rating); 299 bool build_pit(struct chunk *c, struct loc centre, int rating); 300 bool build_template(struct chunk *c, struct loc centre, int rating); 301 bool build_interesting(struct chunk *c, struct loc centre, int rating); 302 bool build_lesser_vault(struct chunk *c, struct loc centre, int rating); 303 bool build_medium_vault(struct chunk *c, struct loc centre, int rating); 304 bool build_greater_vault(struct chunk *c, struct loc centre, int rating); 305 bool build_moria(struct chunk *c, struct loc centre, int rating); 306 bool build_room_of_chambers(struct chunk *c, struct loc centre, int rating); 307 bool build_huge(struct chunk *c, struct loc centre, int rating); 308 bool room_build(struct chunk *c, int by0, int bx0, struct room_profile profile, 309 bool finds_own_space); 310 311 312 /* gen-util.c */ 313 extern byte get_angle_to_grid[41][41]; 314 315 int grid_to_i(struct loc grid, int w); 316 void i_to_grid(int i, int w, struct loc *grid); 317 void shuffle(int *arr, int n); 318 bool cave_find(struct chunk *c, struct loc *grid, square_predicate pred); 319 bool find_empty(struct chunk *c, struct loc *grid); 320 bool find_empty_range(struct chunk *c, struct loc *grid, struct loc top_left, 321 struct loc bottom_right); 322 bool find_nearby_grid(struct chunk *c, struct loc *grid, struct loc centre, 323 int yd, int xd); 324 void correct_dir(struct loc *offset, struct loc grid1, struct loc grid2); 325 void rand_dir(struct loc *offset); 326 void new_player_spot(struct chunk *c, struct player *p); 327 void place_object(struct chunk *c, struct loc grid, int level, bool good, 328 bool great, byte origin, int tval); 329 void place_gold(struct chunk *c, struct loc grid, int level, byte origin); 330 void place_secret_door(struct chunk *c, struct loc grid); 331 void place_closed_door(struct chunk *c, struct loc grid); 332 void place_random_door(struct chunk *c, struct loc grid); 333 void place_random_stairs(struct chunk *c, struct loc grid); 334 void alloc_stairs(struct chunk *c, int feat, int num); 335 void vault_objects(struct chunk *c, struct loc grid, int depth, int num); 336 void vault_traps(struct chunk *c, struct loc grid, int yd, int xd, int num); 337 void vault_monsters(struct chunk *c, struct loc grid, int depth, int num); 338 void alloc_objects(struct chunk *c, int set, int typ, int num, int depth, byte origin); 339 bool alloc_object(struct chunk *c, int set, int typ, int depth, byte origin); 340 void dump_level_simple(const char *basefilename, const char *title, 341 struct chunk *c); 342 void dump_level(ang_file *fo, const char *title, struct chunk *c, int **dist); 343 void dump_level_header(ang_file *fo, const char *title); 344 void dump_level_body(ang_file *fo, const char *title, struct chunk *c, 345 int **dist); 346 void dump_level_footer(ang_file *fo); 347 348 /* gen-monster.c */ 349 bool mon_restrict(const char *monster_type, int depth, bool unique_ok); 350 void spread_monsters(struct chunk *c, const char *type, int depth, int num, 351 int y0, int x0, int dy, int dx, byte origin); 352 void get_vault_monsters(struct chunk *c, char racial_symbol[], char *vault_type, 353 const char *data, int y1, int y2, int x1, int x2); 354 void get_chamber_monsters(struct chunk *c, int y1, int x1, int y2, int x2, char *name, int area); 355 356 357 #endif /* !GENERATE_H */ 358