Angband
Functions
gen-room.c File Reference

Dungeon room generation. More...

#include "angband.h"
#include "cave.h"
#include "datafile.h"
#include "math.h"
#include "game-event.h"
#include "generate.h"
#include "init.h"
#include "mon-make.h"
#include "mon-spell.h"
#include "obj-tval.h"
#include "trap.h"
#include "z-queue.h"
#include "z-type.h"

Functions

struct room_templaterandom_room_template (int typ, int rating)
 

Selection of random templates

More...
 
struct vaultrandom_vault (int depth, const char *typ)
 Chooses a vault of a particular kind at random. More...
 
static void generate_room (struct chunk *c, int y1, int x1, int y2, int x2, int light)
 

Room build helper functions

More...
 
void generate_mark (struct chunk *c, int y1, int x1, int y2, int x2, int flag)
 Mark a rectangle with a sqinfo flag. More...
 
void fill_rectangle (struct chunk *c, int y1, int x1, int y2, int x2, int feat, int flag)
 Fill a rectangle with a feature. More...
 
void draw_rectangle (struct chunk *c, int y1, int x1, int y2, int x2, int feat, int flag)
 Fill the edges of a rectangle with a feature. More...
 
static void fill_xrange (struct chunk *c, int y, int x1, int x2, int feat, int flag, bool light)
 Fill a horizontal range with the given feature/info. More...
 
static void fill_yrange (struct chunk *c, int x, int y1, int y2, int feat, int flag, bool light)
 Fill a vertical range with the given feature/info. More...
 
static void fill_circle (struct chunk *c, int y0, int x0, int radius, int border, int feat, int flag, bool light)
 Fill a circle with the given feature/info. More...
 
static void generate_plus (struct chunk *c, int y1, int x1, int y2, int x2, int feat, int flag)
 Fill the lines of a cross/plus with a feature. More...
 
static void generate_open (struct chunk *c, int y1, int x1, int y2, int x2, int feat)
 Generate helper – open all sides of a rectangle with a feature. More...
 
static void generate_hole (struct chunk *c, int y1, int x1, int y2, int x2, int feat)
 Generate helper – open one side of a rectangle with a feature. More...
 
void set_marked_granite (struct chunk *c, int y, int x, int flag)
 Place a square of granite with a flag. More...
 
bool generate_starburst_room (struct chunk *c, int y1, int x1, int y2, int x2, bool light, int feat, bool special_ok)
 Make a starburst room. More...
 
bool mon_pit_hook (struct monster_race *race)
 Hook for picking monsters appropriate to a nest/pit or region. More...
 
void set_pit_type (int depth, int type)
 Pick a type of monster for pits (or other purposes), based on the level. More...
 
static bool find_space (int *y, int *x, int height, int width)
 Find a good spot for the next room. More...
 
static bool build_room_template (struct chunk *c, int y0, int x0, int ymax, int xmax, int doors, const char *data, int tval)
 Build a room template from its string representation. More...
 
static bool build_room_template_type (struct chunk *c, int y0, int x0, int typ, int rating)
 Helper function for building room templates. More...
 
bool build_vault (struct chunk *c, int y0, int x0, struct vault *v)
 Build a vault from its string representation. More...
 
static bool build_vault_type (struct chunk *c, int y0, int x0, const char *typ)
 Helper function for building vaults. More...
 
static void make_inner_chamber_wall (struct chunk *c, int y, int x)
 Helper for rooms of chambers; builds a marked wall grid if appropriate. More...
 
static void make_chamber (struct chunk *c, int y1, int x1, int y2, int x2)
 Helper function for rooms of chambers. More...
 
static void hollow_out_room (struct chunk *c, int y, int x)
 Expand in every direction from a start point, turning magma into rooms. More...
 
bool build_circular (struct chunk *c, int y0, int x0, int rating)
 

Room builders

More...
 
bool build_simple (struct chunk *c, int y0, int x0, int rating)
 Builds a normal rectangular room. More...
 
bool build_overlap (struct chunk *c, int y0, int x0, int rating)
 Builds an overlapping rectangular room. More...
 
bool build_crossed (struct chunk *c, int y0, int x0, int rating)
 Builds a cross-shaped room. More...
 
bool build_large (struct chunk *c, int y0, int x0, int rating)
 Build a large room with an inner room. More...
 
bool build_nest (struct chunk *c, int y0, int x0, int rating)
 Build a monster nest. More...
 
bool build_pit (struct chunk *c, int y0, int x0, int rating)
 Build a monster pit. More...
 
bool build_template (struct chunk *c, int y0, int x0, int rating)
 Build a template room. More...
 
bool build_interesting (struct chunk *c, int y0, int x0, int rating)
 Build an interesting room. More...
 
bool build_lesser_vault (struct chunk *c, int y0, int x0, int rating)
 Build a lesser vault. More...
 
bool build_medium_vault (struct chunk *c, int y0, int x0, int rating)
 Build a medium vault. More...
 
bool build_greater_vault (struct chunk *c, int y0, int x0, int rating)
 Build a greater vaults. More...
 
bool build_moria (struct chunk *c, int y0, int x0, int rating)
 Moria room (from Oangband). More...
 
bool build_room_of_chambers (struct chunk *c, int y0, int x0, int rating)
 Rooms of chambers. More...
 
bool build_huge (struct chunk *c, int y0, int x0, int rating)
 A single starburst-shaped room of extreme size, usually dotted or even divided with irregularly-shaped fields of rubble. More...
 
bool room_build (struct chunk *c, int by0, int bx0, struct room_profile profile, bool finds_own_space)
 Attempt to build a room of the given type at the given block. More...
 

Detailed Description

Dungeon room generation.

Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke Copyright (c) 2013 Erik Osheim, Nick McConnell

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

This file covers everything to do with generation of individual rooms in the dungeon. It consists of room generating helper functions plus the actual room builders (which are referred to in the room profiles in generate.c).

The room builders all take as arguments the chunk they are being generated in, and the co-ordinates of the room centre in that chunk. Each room builder is also able to find space for itself in the chunk using the find_space() function; the chunk generating functions can ask it to do that by passing too large centre co-ordinates.

Function Documentation

bool build_circular ( struct chunk c,
int  y0,
int  x0,
int  rating 
)


Room builders

Build a circular room (interior radius 4-7).

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

References chunk::depth, draw_rectangle(), FEAT_FLOOR, FEAT_GRANITE, fill_circle(), find_space(), chunk::height, place_closed_door(), rand_dir(), randint0, randint1, vault_monsters(), vault_objects(), and chunk::width.

bool build_crossed ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

Builds a cross-shaped room.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

Room "a" runs north/south, and Room "b" runs east/east So a "central pillar" would run from x1a,y1b to x2a,y2b.

Note that currently, the "center" is always 3x3, but I think that the code below will work for 5x5 (and perhaps even for unsymetric values like 4x3 or 5x3 or 3x4 or 3x5).

References chunk::depth, draw_rectangle(), FEAT_CLOSED, FEAT_FLOOR, FEAT_GRANITE, FEAT_SECRET, fill_rectangle(), find_space(), generate_hole(), generate_open(), generate_plus(), generate_room(), chunk::height, height, MAX, one_in_, place_object(), rand_range(), randint0, randint1, set_marked_granite(), vault_monsters(), vault_traps(), chunk::width, and width.

bool build_greater_vault ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

Build a greater vaults.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

Classic profile: Since Greater Vaults are so large (4x6 blocks, in a 6x18 dungeon) there is a 63% chance that a randomly chosen quadrant to start a GV on won't work. To balance this, we give Greater Vaults an artificially high probability of being attempted, and then in this function use a depth check to cancel vault creation except at deep depths.

Newer profiles: We reject 2/3 of attempts which pass other checks to get roughly the same chnce of a GV as the classic profile

The following code should make a greater vault with frequencies: dlvl freq 100+ 18.0% 90-99 16.0 - 18.0% 80-89 10.0 - 11.0% 70-79 5.7 - 6.5% 60-69 3.3 - 3.8% 50-59 1.8 - 2.1% 0-49 0.0 - 1.0%

References build_vault_type(), dun_data::cent_n, chunk::depth, dun, i, cave_profile::name, one_in_, dun_data::profile, randint0, and streq.

bool build_huge ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

A single starburst-shaped room of extreme size, usually dotted or even divided with irregularly-shaped fields of rubble.

No special monsters. Appears deeper than level 40.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

These are the largest, most difficult to position, and thus highest- priority rooms in the dungeon. They should be rare, so as not to interfere with greater vaults.

References dun_data::cent_n, dun, FEAT_FLOOR, FEAT_PASS_RUBBLE, find_space(), generate_starburst_room(), chunk::height, height, i, one_in_, randint0, randint1, ROOM_LOG, chunk::width, and width.

bool build_interesting ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

Build an interesting room.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

References build_vault_type().

bool build_large ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

Build a large room with an inner room.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

Possible sub-types: 1 - An inner room 2 - An inner room with a small inner room 3 - An inner room with a pillar or pillars 4 - An inner room with a checkerboard 5 - An inner room with four compartments

References chunk::depth, draw_rectangle(), FEAT_CLOSED, FEAT_FLOOR, FEAT_GRANITE, fill_rectangle(), find_space(), generate_hole(), generate_plus(), generate_room(), chunk::height, height, i, one_in_, place_closed_door(), place_object(), place_random_stairs(), place_secret_door(), randint0, randint1, set_marked_granite(), square_iscloseddoor(), square_set_door_lock(), vault_monsters(), vault_objects(), vault_traps(), chunk::width, and width.

bool build_lesser_vault ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

Build a lesser vault.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

References build_vault_type(), dun, cave_profile::name, one_in_, dun_data::profile, and streq.

bool build_medium_vault ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

Build a medium vault.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

References build_vault_type(), dun, cave_profile::name, one_in_, dun_data::profile, and streq.

bool build_moria ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

Moria room (from Oangband).

Uses the "starburst room" code.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

References chunk::depth, FEAT_FLOOR, FEAT_PASS_RUBBLE, find_space(), generate_starburst_room(), chunk::height, height, i, one_in_, randint0, randint1, void(), chunk::width, and width.

bool build_nest ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

Build a monster nest.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

A monster nest consists of a rectangular moat around a room containing monsters of a given type.

The monsters are chosen from a set of 64 randomly selected monster races, to allow the nest creation to fail instead of having "holes".

Note the use of the "get_mon_num_prep()" function to prepare the "monster allocation table" in such a way as to optimize the selection of "appropriate" non-unique monsters for the nest.

The available monster nests are specified in edit/pit.txt.

Note that get_mon_num() function can fail, in which case the nest will be empty, and will not affect the level rating.

Monster nests will never contain unique monsters.

References pit_profile::ave, chunk::depth, draw_rectangle(), dun, FEAT_CLOSED, FEAT_FLOOR, FEAT_GRANITE, fill_rectangle(), find_space(), generate_hole(), generate_room(), get_mon_num(), get_mon_num_prep(), chunk::height, height, i, mon_pit_hook(), chunk::mon_rating, pit_profile::name, NULL, pit_profile::obj_rarity, one_in_, dun_data::pit_type, place_new_monster(), place_object(), randint0, ROOM_LOG, set_pit_type(), chunk::width, and width.

bool build_overlap ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

Builds an overlapping rectangular room.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

References chunk::depth, draw_rectangle(), FEAT_FLOOR, FEAT_GRANITE, fill_rectangle(), find_space(), generate_room(), chunk::height, height, MAX, randint1, chunk::width, and width.

bool build_pit ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

Build a monster pit.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

Monster pits are laid-out similarly to monster nests.

The available monster pits are specified in edit/pit.txt.

The inside room in a monster pit appears as shown below, where the actual monsters in each location depend on the type of the pit

#11000000011# #01234543210# #01236763210# #01234543210# #11000000011#

Note that the monsters in the pit are chosen by using get_mon_num() to request 16 "appropriate" monsters, sorting them by level, and using the "even" entries in this sorted list for the contents of the pit.

Note the use of get_mon_num_prep() to prepare the monster allocation table in such a way as to optimize the selection of appropriate non-unique monsters for the pit.

The get_mon_num() function can fail, in which case the pit will be empty, and will not effect the level rating.

Like monster nests, monster pits will never contain unique monsters.

References pit_profile::ave, chunk::depth, draw_rectangle(), dun, FEAT_CLOSED, FEAT_FLOOR, FEAT_GRANITE, fill_rectangle(), find_space(), generate_hole(), generate_room(), get_mon_num(), get_mon_num_prep(), chunk::height, height, i, i1, i2, monster_race::level, mon_pit_hook(), chunk::mon_rating, pit_profile::name, NULL, pit_profile::obj_rarity, one_in_, dun_data::pit_type, place_new_monster(), place_object(), randint0, ROOM_LOG, set_pit_type(), chunk::width, and width.

bool build_room_of_chambers ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

Rooms of chambers.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

Build a room, varying in size between 22x22 and 44x66, consisting of many smaller, irregularly placed, chambers all connected by doors or short tunnels. -LM-

Plop down an area-dependent number of magma-filled chambers, and remove blind doors and tiny rooms.

Hollow out a chamber near the center, connect it to new chambers, and hollow them out in turn. Continue in this fashion until there are no remaining chambers within two squares of any cleared chamber.

Clean up doors. Neaten up the wall types. Turn floor grids into rooms, illuminate if requested.

Fill the room with up to 35 (sometimes up to 50) monsters of a creature race or type that offers a challenge at the character's depth. This is similar to monster pits, except that we choose among a wider range of monsters.

References ABS, area, ddx_ddd, ddy_ddd, chunk::depth, square::feat, FEAT_BROKEN, FEAT_FLOOR, FEAT_GRANITE, FEAT_MAGMA, FEAT_OPEN, find_space(), get_chamber_monsters(), chunk::height, height, hollow_out_room(), i, square::info, m_bonus(), make_chamber(), chunk::mon_rating, place_random_door(), randint0, randint1, ROOM_LOG, set_marked_granite(), size, sqinfo_on, square_in_bounds(), square_in_bounds_fully(), square_isfloor(), square_iswall_inner(), square_iswall_outer(), square_iswall_solid(), square_set_feat(), chunk::squares, chunk::width, and width.

static bool build_room_template ( struct chunk c,
int  y0,
int  x0,
int  ymax,
int  xmax,
int  doors,
const char *  data,
int  tval 
)
static

Build a room template from its string representation.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
ymaxthe room dimensions
xmaxthe room dimensions
doorsthe door position
datathe room template text description
tvalthe object type for any included objects
Returns
success

References chunk::depth, FEAT_FLOOR, find_space(), chunk::height, square::info, int, one_in_, place_closed_door(), place_object(), place_random_stairs(), place_secret_door(), place_trap(), randint0, randint1, set_marked_granite(), sqinfo_on, square_isempty(), square_set_feat(), chunk::squares, vault_monsters(), vault_objects(), and chunk::width.

Referenced by build_room_template_type().

static bool build_room_template_type ( struct chunk c,
int  y0,
int  x0,
int  typ,
int  rating 
)
static

Helper function for building room templates.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
typthe room template type (currently unused)
Returns
success

References build_room_template(), room_template::dor, room_template::hgt, room_template::name, NULL, random_room_template(), ROOM_LOG, room_template::text, room_template::tval, and room_template::wid.

Referenced by build_template().

bool build_simple ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

Builds a normal rectangular room.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

References chunk::depth, draw_rectangle(), FEAT_FLOOR, FEAT_GRANITE, fill_rectangle(), find_space(), generate_room(), chunk::height, height, one_in_, randint1, set_marked_granite(), chunk::width, and width.

bool build_template ( struct chunk c,
int  y0,
int  x0,
int  rating 
)

Build a template room.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
Returns
success

References build_room_template_type().

bool build_vault ( struct chunk c,
int  y0,
int  x0,
struct vault v 
)

Build a vault from its string representation.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
vpointer to the vault template
Returns
success

References data, chunk::depth, FEAT_FLOOR, FEAT_LAVA, FEAT_LESS, FEAT_MAGMA_K, FEAT_MORE, FEAT_PASS_RUBBLE, FEAT_PERM, FEAT_QUARTZ_K, FEAT_RUBBLE, find_space(), generate_mark(), get_vault_monsters(), chunk::height, vault::hgt, square::info, is_quest(), angband_constants::max_depth, one_in_, pick_and_place_monster(), place_gold(), place_object(), place_secret_door(), place_trap(), randint0, randint1, set_marked_granite(), sqinfo_on, square_isempty(), square_set_feat(), chunk::squares, vault::text, room_template::tval, vault::typ, vault::wid, chunk::width, and z_info.

Referenced by build_vault_type(), and vault_chunk().

static bool build_vault_type ( struct chunk c,
int  y0,
int  x0,
const char *  typ 
)
static

Helper function for building vaults.

Parameters
cthe chunk the room is being built in
y0co-ordinates of the centre; out of chunk bounds invoke find_space()
x0co-ordinates of the centre; out of chunk bounds invoke find_space()
typthe vault type
labelname of the vault type (eg "Greater vault")
Returns
success

References build_vault(), chunk::depth, chunk::mon_rating, vault::name, NULL, random_vault(), vault::rat, and ROOM_LOG.

Referenced by build_greater_vault(), build_interesting(), build_lesser_vault(), and build_medium_vault().

void draw_rectangle ( struct chunk c,
int  y1,
int  x1,
int  y2,
int  x2,
int  feat,
int  flag 
)

Fill the edges of a rectangle with a feature.

Parameters
cthe current chunk
y1inclusive room boundaries
x1inclusive room boundaries
y2inclusive room boundaries
x2inclusive room boundaries
featthe terrain feature
flagthe SQUARE_* flag we are marking with

References generate_mark(), and square_set_feat().

Referenced by build_circular(), build_crossed(), build_large(), build_nest(), build_overlap(), build_pit(), build_simple(), cavern_gen(), classic_gen(), gauntlet_gen(), hard_centre_gen(), labyrinth_chunk(), lair_gen(), modified_chunk(), modified_gen(), moria_chunk(), moria_gen(), and town_gen_layout().

static void fill_circle ( struct chunk c,
int  y0,
int  x0,
int  radius,
int  border,
int  feat,
int  flag,
bool  light 
)
static

Fill a circle with the given feature/info.

Parameters
cthe current chunk
y0the circle centre
x0the circle centre
radiusthe circle radius
borderthe width of the circle border
featthe terrain feature
flagthe SQUARE_* flag we are marking with
lightlit or not

References fill_xrange(), fill_yrange(), i, and int.

Referenced by build_circular().

void fill_rectangle ( struct chunk c,
int  y1,
int  x1,
int  y2,
int  x2,
int  feat,
int  flag 
)

Fill a rectangle with a feature.

Parameters
cthe current chunk
y1inclusive room boundaries
x1inclusive room boundaries
y2inclusive room boundaries
x2inclusive room boundaries
featthe terrain feature
flagthe SQUARE_* flag we are marking with

References generate_mark(), and square_set_feat().

Referenced by build_crossed(), build_large(), build_nest(), build_overlap(), build_pit(), build_simple(), build_store(), classic_gen(), gauntlet_gen(), init_cavern(), labyrinth_chunk(), make_chamber(), modified_chunk(), and moria_chunk().

static void fill_xrange ( struct chunk c,
int  y,
int  x1,
int  x2,
int  feat,
int  flag,
bool  light 
)
static

Fill a horizontal range with the given feature/info.

Parameters
cthe current chunk
yinclusive room boundaries
x1inclusive room boundaries
x2inclusive range boundaries
featthe terrain feature
flagthe SQUARE_* flag we are marking with
lightlit or not

References square::info, sqinfo_on, square_set_feat(), and chunk::squares.

Referenced by fill_circle().

static void fill_yrange ( struct chunk c,
int  x,
int  y1,
int  y2,
int  feat,
int  flag,
bool  light 
)
static

Fill a vertical range with the given feature/info.

Parameters
cthe current chunk
xinclusive room boundaries
y1inclusive room boundaries
y2inclusive range boundaries
featthe terrain feature
flagthe SQUARE_* flag we are marking with
lightlit or not

References square::info, sqinfo_on, square_set_feat(), and chunk::squares.

Referenced by fill_circle().

static bool find_space ( int y,
int x,
int  height,
int  width 
)
static

Find a good spot for the next room.

Parameters
ycentre of the room
xcentre of the room
heightdimensions of the room
widthdimensions of the room
Returns
success

Find and allocate a free space in the dungeon large enough to hold the room calling this function.

We allocate space in blocks.

Be careful to include the edges of the room in height and width!

Return true and values for the center of the room if all went well. Otherwise, return false.

References dun_data::block_hgt, dun_data::block_wid, dun_data::cent, dun_data::cent_n, dun_data::col_blocks, dun, i, angband_constants::level_room_max, randint0, dun_data::room_map, dun_data::row_blocks, loc::x, loc::y, and z_info.

Referenced by build_circular(), build_crossed(), build_huge(), build_large(), build_moria(), build_nest(), build_overlap(), build_pit(), build_room_of_chambers(), build_room_template(), build_simple(), and build_vault().

static void generate_hole ( struct chunk c,
int  y1,
int  x1,
int  y2,
int  x2,
int  feat 
)
static

Generate helper – open one side of a rectangle with a feature.

Parameters
cthe current chunk
y1inclusive room boundaries
x1inclusive room boundaries
y2inclusive room boundaries
x2inclusive room boundaries
featthe terrain feature

References randint0, and square_set_feat().

Referenced by build_crossed(), build_large(), build_nest(), and build_pit().

void generate_mark ( struct chunk c,
int  y1,
int  x1,
int  y2,
int  x2,
int  flag 
)

Mark a rectangle with a sqinfo flag.

Parameters
cthe current chunk
y1inclusive room boundaries
x1inclusive room boundaries
y2inclusive room boundaries
x2inclusive room boundaries
flagthe SQUARE_* flag we are marking with

References square::info, sqinfo_on, and chunk::squares.

Referenced by build_vault(), draw_rectangle(), fill_rectangle(), gauntlet_gen(), generate_plus(), get_chamber_monsters(), and set_marked_granite().

static void generate_open ( struct chunk c,
int  y1,
int  x1,
int  y2,
int  x2,
int  feat 
)
static

Generate helper – open all sides of a rectangle with a feature.

Parameters
cthe current chunk
y1inclusive room boundaries
x1inclusive room boundaries
y2inclusive room boundaries
x2inclusive room boundaries
featthe terrain feature

References square_set_feat().

Referenced by build_crossed().

static void generate_plus ( struct chunk c,
int  y1,
int  x1,
int  y2,
int  x2,
int  feat,
int  flag 
)
static

Fill the lines of a cross/plus with a feature.

Parameters
cthe current chunk
y1inclusive room boundaries
x1inclusive room boundaries
y2inclusive room boundaries
x2inclusive room boundaries
featthe terrain feature
flagthe SQUARE_* flag we are marking with When combined with draw_rectangle() this will generate a large rectangular room which is split into four sub-rooms.

References generate_mark(), and square_set_feat().

Referenced by build_crossed(), and build_large().

static void generate_room ( struct chunk c,
int  y1,
int  x1,
int  y2,
int  x2,
int  light 
)
static


Room build helper functions

Mark squares as being in a room, and optionally light them.

Parameters
cthe current chunk
y1inclusive room boundaries
x1inclusive room boundaries
y2inclusive room boundaries
x2inclusive room boundaries
lightwhether or not to light the room

References square::info, sqinfo_on, and chunk::squares.

Referenced by build_crossed(), build_large(), build_nest(), build_overlap(), build_pit(), and build_simple().

bool generate_starburst_room ( struct chunk c,
int  y1,
int  x1,
int  y2,
int  x2,
bool  light,
int  feat,
bool  special_ok 
)

Make a starburst room.

-LM-

Parameters
cthe current chunk
y1boundaries which will contain the starburst
x1boundaries which will contain the starburst
y2boundaries which will contain the starburst
x2boundaries which will contain the starburst
lightlit or not
featthe terrain feature to make the starburst of
special_okallow wacky cloverleaf rooms
Returns
success

Starburst rooms are made in three steps: 1: Choose a room size-dependent number of arcs. Large rooms need to look less granular and alter their shape more often, so they need more arcs. 2: For each of the arcs, calculate the portion of the full circle it includes, and its maximum effect range (how far in that direction we can change features in). This depends on room size, shape, and the maximum effect range of the previous arc. 3: Use the table "get_angle_to_grid" to supply angles to each grid in the room. If the distance to that grid is not greater than the maximum effect range that applies at that angle, change the feature if appropriate (this depends on feature type).

Usage notes:

  • This function uses a table that cannot handle distances larger than 20, so it calculates a distance conversion factor for larger rooms.
  • This function is not good at handling rooms much longer along one axis than the other, so it divides such rooms up, and calls itself to handle each section.
  • It is safe to call this function on areas that might contain vaults or pits, because "icky" and occupied grids are left untouched.
  • Mixing these rooms (using normal floor) with rectangular ones on a regular basis produces a somewhat chaotic looking dungeon. However, this code does works well for lakes, etc.

References ABS, ddx_ddd, ddy_ddd, distance(), square::feat, FEAT_GRANITE, feat_is_floor(), feat_is_passable(), feat_is_smooth(), generate_starburst_room(), get_angle_to_grid, height, i, square::info, randint0, randint1, set_marked_granite(), sqinfo_off, sqinfo_on, square_in_bounds(), square_isfloor(), square_isvault(), square_monster(), square_object(), square_set_feat(), chunk::squares, void(), and width.

Referenced by build_huge(), build_moria(), generate_starburst_room(), and town_gen_layout().

static void hollow_out_room ( struct chunk c,
int  y,
int  x 
)
static

Expand in every direction from a start point, turning magma into rooms.

Stop only when the magma and the open doors totally run out.

Parameters
cthe chunk the room is being built in
yco-ordinates to start hollowing
xco-ordinates to start hollowing

References ddx_ddd, ddy_ddd, square::feat, FEAT_BROKEN, FEAT_FLOOR, FEAT_MAGMA, FEAT_OPEN, square_set_feat(), and chunk::squares.

Referenced by build_room_of_chambers().

static void make_chamber ( struct chunk c,
int  y1,
int  x1,
int  y2,
int  x2 
)
static

Helper function for rooms of chambers.

Fill a room matching the rectangle input with magma, and surround it with inner wall. Create a door in a random inner wall grid along the border of the rectangle.

Parameters
cthe chunk the room is being built in
y1chamber dimensions
x1chamber dimensions
y2chamber dimensions
x2chamber dimensions

References ABS, ddx_ddd, ddy_ddd, square::feat, FEAT_MAGMA, FEAT_OPEN, fill_rectangle(), i, make_inner_chamber_wall(), one_in_, randint0, square_in_bounds_fully(), square_iswall_inner(), square_set_feat(), and chunk::squares.

Referenced by build_room_of_chambers().

static void make_inner_chamber_wall ( struct chunk c,
int  y,
int  x 
)
static

Helper for rooms of chambers; builds a marked wall grid if appropriate.

Parameters
cthe chunk the room is being built in
yco-ordinates
xco-ordinates

References square::feat, FEAT_GRANITE, FEAT_MAGMA, set_marked_granite(), square_iswall_outer(), square_iswall_solid(), and chunk::squares.

Referenced by make_chamber().

bool mon_pit_hook ( struct monster_race race)
struct room_template* random_room_template ( int  typ,
int  rating 
)


Selection of random templates

Chooses a room template of a particular kind at random.

Parameters
typtemplate room type - currently unused
Returns
a pointer to the room template

References room_template::next, NULL, one_in_, room_template::rat, room_templates, and room_template::typ.

Referenced by build_room_template_type().

struct vault* random_vault ( int  depth,
const char *  typ 
)

Chooses a vault of a particular kind at random.

Parameters
depththe current depth, for vault boun checking
typvault type
Returns
a pointer to the vault template

References vault::max_lev, vault::min_lev, vault::next, NULL, one_in_, streq, vault::typ, and vaults.

Referenced by build_vault_type(), and vault_chunk().

bool room_build ( struct chunk c,
int  by0,
int  bx0,
struct room_profile  profile,
bool  finds_own_space 
)

Attempt to build a room of the given type at the given block.

Parameters
cthe chunk the room is being built in
by0block co-ordinates of the top left block
bx0block co-ordinates of the top left block
profilethe profile of the rooom we're trying to build
finds_own_spacewhether we are allowing the room to place itself
Returns
success

Note that this code assumes that profile height and width are the maximum possible grid sizes, and then allocates a number of blocks that will always contain them.

Note that we restrict the number of pits/nests to reduce the chance of overflowing the monster list during level creation.

References dun_data::block_hgt, dun_data::block_wid, room_profile::builder, dun_data::cent, dun_data::cent_n, dun_data::col_blocks, chunk::depth, dun, chunk::height, room_profile::height, room_profile::level, angband_constants::level_pit_max, angband_constants::level_room_max, room_profile::pit, dun_data::pit_num, room_profile::rating, dun_data::room_map, dun_data::row_blocks, chunk::width, room_profile::width, loc::x, loc::y, and z_info.

Referenced by classic_gen(), modified_chunk(), and moria_chunk().

void set_marked_granite ( struct chunk c,
int  y,
int  x,
int  flag 
)

Place a square of granite with a flag.

Parameters
cthe current chunk
ythe square co-ordinates
xthe square co-ordinates
flagthe SQUARE_* flag we are marking with

References FEAT_GRANITE, generate_mark(), and square_set_feat().

Referenced by build_crossed(), build_large(), build_room_of_chambers(), build_room_template(), build_simple(), build_tunnel(), build_vault(), clear_small_regions(), generate_starburst_room(), make_inner_chamber_wall(), and mutate_cavern().

void set_pit_type ( int  depth,
int  type 
)

Pick a type of monster for pits (or other purposes), based on the level.

We scan through all pit profiles, and for each one generate a random depth using a normal distribution, with the mean given in pit.txt, and a standard deviation of 10. Then we pick the profile that gave us a depth that is closest to the player's actual depth.

Sets dun->pit_type, which is required for mon_pit_hook.

Parameters
depthis the pit profile depth to aim for in selection
typeis 1 for pits, 2 for nests, 0 for any profile

References ABS, pit_profile::ave, dun, i, pit_profile::name, one_in_, pit_profile::pit_idx, pit_info, angband_constants::pit_max, dun_data::pit_type, Rand_normal(), pit_profile::rarity, pit_profile::room_type, and z_info.

Referenced by build_nest(), build_pit(), gauntlet_gen(), get_chamber_monsters(), and lair_gen().