Angband
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
generate.h File Reference

Dungeon generation. More...

#include "monster.h"

Go to the source code of this file.

Data Structures

struct  pit_monster_profile
 Monster base for a pit. More...
 
struct  pit_color_profile
 Monster color for a pit. More...
 
struct  pit_forbidden_monster
 Monster forbidden from a pit. More...
 
struct  pit_profile
 Profile for choosing monsters for pits, nests or other themed areas. More...
 
struct  dun_data
 Structure to hold all "dungeon generation" data. More...
 
struct  tunnel_profile
 
struct  streamer_profile
 
struct  cave_profile
 
struct  room_profile
 This tracks information needed to generate the room, including the room's name and the function used to build it. More...
 
struct  vault
 
struct  room_template
 Information about template room generation. More...
 

Macros

#define ROOM_LOG   if (OPT(player, cheat_room)) msg
 

Typedefs

typedef struct chunk *(* cave_builder )(struct player *p)
 
typedef bool(* room_builder )(struct chunk *c, int y0, int x0, int rating)
 room_builder is a function pointer which builds rooms in the cave given anchor coordinates. More...
 

Enumerations

enum  { SET_CORR = 0x01, SET_ROOM = 0x02, SET_BOTH = 0x03 }
 Dungeon allocation places and types, used with alloc_object(). More...
 
enum  {
  TYP_RUBBLE, TYP_TRAP, TYP_GOLD, TYP_OBJECT,
  TYP_GOOD, TYP_GREAT
}
 

Functions

struct chunktown_gen (struct player *p)
 Town logic flow for generation of new town. More...
 
struct chunkclassic_gen (struct player *p)
 Generate a new dungeon level. More...
 
struct chunklabyrinth_gen (struct player *p)
 Build a labyrinth level. More...
 
void ensure_connectedness (struct chunk *c)
 Make sure that all the regions of the dungeon are connected. More...
 
struct chunkcavern_gen (struct player *p)
 Make a cavern level. More...
 
struct chunkmodified_gen (struct player *p)
 Generate a new dungeon level. More...
 
struct chunkmoria_gen (struct player *p)
 Generate a new dungeon level. More...
 
struct chunkhard_centre_gen (struct player *p)
 Generate a hard centre level - a greater vault surrounded by caverns. More...
 
struct chunklair_gen (struct player *p)
 Generate a lair level - a regular cave generated with the modified algorithm, connected to a cavern with themed monsters. More...
 
struct chunkgauntlet_gen (struct player *p)
 Generate a gauntlet level - two separate caverns with an unmappable labyrinth between them, and no teleport and only upstairs from the side where the player starts. More...
 
struct chunkchunk_write (int y0, int x0, int height, int width, bool monsters, bool objects, bool traps)
 Write a chunk to memory and return a pointer to it. More...
 
void chunk_list_add (struct chunk *c)
 Add an entry to the chunk list - any problems with the length of this will be more in the memory used by the chunks themselves rather than the list. More...
 
bool chunk_list_remove (char *name)
 Remove an entry from the chunk list, return whether it was found. More...
 
struct chunkchunk_find_name (char *name)
 Find a chunk by name. More...
 
bool chunk_find (struct chunk *c)
 Find a chunk by pointer. More...
 
bool chunk_copy (struct chunk *dest, struct chunk *source, int y0, int x0, int rotate, bool reflect)
 Write a chunk, transformed, to a given offset in another chunk. More...
 
void chunk_validate_objects (struct chunk *c)
 Validate that the chunk contains no NULL objects. 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 generate_mark (struct chunk *c, int y1, int x1, int y2, int x2, int flag)
 Mark a rectangle with a sqinfo flag. 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...
 
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...
 
struct vaultrandom_vault (int depth, const char *typ)
 Chooses a vault of a particular kind at random. More...
 
bool build_vault (struct chunk *c, int y0, int x0, struct vault *v)
 Build a vault from its string representation. More...
 
bool build_simple (struct chunk *c, int y0, int x0, int rating)
 Builds a normal rectangular room. More...
 
bool build_circular (struct chunk *c, int y0, int x0, int rating)
 

Room builders

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 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...
 
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...
 
int yx_to_i (int y, int x, int w)
 Used to convert (x, y) into an array index (i) in a chunk of width w. More...
 
void i_to_yx (int i, int w, int *y, int *x)
 Used to convert an array index (i) into (x, y) in a chunk of width w. More...
 
void shuffle (int *arr, int n)
 Shuffle an array using Knuth's shuffle. More...
 
bool cave_find (struct chunk *c, int *y, int *x, square_predicate pred)
 Locate a square in the dungeon which satisfies the given predicate. More...
 
bool find_empty (struct chunk *c, int *y, int *x)
 Locate an empty square for 0 <= y < ymax, 0 <= x < xmax. More...
 
bool find_empty_range (struct chunk *c, int *y, int y1, int y2, int *x, int x1, int x2)
 Locate an empty square for y1 <= y < y2, x1 <= x < x2. More...
 
bool find_nearby_grid (struct chunk *c, int *y, int y0, int yd, int *x, int x0, int xd)
 Locate a grid nearby (y0, x0) within +/- yd, xd. More...
 
void correct_dir (int *rdir, int *cdir, int y1, int x1, int y2, int x2)
 Given two points, pick a valid cardinal direction from one to the other. More...
 
void rand_dir (int *rdir, int *cdir)
 Pick a random cardinal direction. More...
 
void new_player_spot (struct chunk *c, struct player *p)
 Place the player at a random starting location. More...
 
void place_object (struct chunk *c, int y, int x, int level, bool good, bool great, byte origin, int tval)
 Place a random object at (x, y). More...
 
void place_gold (struct chunk *c, int y, int x, int level, byte origin)
 Place a random amount of gold at (x, y). More...
 
void place_secret_door (struct chunk *c, int y, int x)
 Place a secret door at (x, y). More...
 
void place_closed_door (struct chunk *c, int y, int x)
 Place a closed door at (x, y). More...
 
void place_random_door (struct chunk *c, int y, int x)
 Place a random door at (x, y). More...
 
void place_random_stairs (struct chunk *c, int y, int x)
 Place random stairs at (x, y). More...
 
void alloc_stairs (struct chunk *c, int feat, int num, int walls)
 Place some staircases near walls. More...
 
void vault_objects (struct chunk *c, int y, int x, int depth, int num)
 Create up to 'num' objects near the given coordinates in a vault. More...
 
void vault_traps (struct chunk *c, int y, int x, int yd, int xd, int num)
 Place 'num' traps near (x, y), with a given displacement. More...
 
void vault_monsters (struct chunk *c, int y1, int x1, int depth, int num)
 Place 'num' sleeping monsters near (x, y). More...
 
void alloc_objects (struct chunk *c, int set, int typ, int num, int depth, byte origin)
 Allocates 'num' random entities in the dungeon. More...
 
bool alloc_object (struct chunk *c, int set, int typ, int depth, byte origin)
 Allocates a single random object in the dungeon. More...
 
bool mon_restrict (const char *monster_type, int depth, bool unique_ok)
 Accept characters representing a race or group of monsters and an (adjusted) depth, and use these to set values for required monster base symbol. More...
 
void spread_monsters (struct chunk *c, const char *type, int depth, int num, int y0, int x0, int dy, int dx, byte origin)
 Place monsters, up to the number asked for, in a rectangle centered on y0, x0. More...
 
void get_vault_monsters (struct chunk *c, char racial_symbol[], char *vault_type, const char *data, int y1, int y2, int x1, int x2)
 To avoid rebuilding the monster list too often (which can quickly get expensive), we handle monsters of a specified race separately. More...
 
void get_chamber_monsters (struct chunk *c, int y1, int x1, int y2, int x2, char *name, int area)
 Funtion for placing appropriate monsters in a room of chambers. More...
 

Variables

struct pit_profilepit_info
 
struct dun_datadun
 
struct vaultvaults
 
struct room_templateroom_templates
 
byte get_angle_to_grid [41][41]
 Accept values for y and x (considered as the endpoints of lines) between 0 and 40, and return an angle in degrees (divided by two). More...
 

Detailed Description

Dungeon generation.

Macro Definition Documentation

#define ROOM_LOG   if (OPT(player, cheat_room)) msg

Typedef Documentation

typedef struct chunk*(* cave_builder)(struct player *p)
typedef bool(* room_builder)(struct chunk *c, int y0, int x0, int rating)

room_builder is a function pointer which builds rooms in the cave given anchor coordinates.

Enumeration Type Documentation

anonymous enum

Dungeon allocation places and types, used with alloc_object().

Enumerator
SET_CORR 

Hallway

SET_ROOM 

Room

SET_BOTH 

Anywhere

anonymous enum
Enumerator
TYP_RUBBLE 

Rubble

TYP_TRAP 

Trap

TYP_GOLD 

Gold

TYP_OBJECT 

Object

TYP_GOOD 

Good object

TYP_GREAT 

Great object

Function Documentation

bool alloc_object ( struct chunk c,
int  set,
int  typ,
int  depth,
byte  origin 
)

Allocates a single random object in the dungeon.

Parameters
cthe current chunk
setwhere the entity is placed (corridor, room or either)
typwhat is placed (rubble, trap, gold, item)
depthgeneration depth
originitem origin (if appropriate)

'set' controls where the object is placed (corridor, room, either). 'typ' conrols the kind of object (rubble, trap, gold, item).

References find_empty(), place_gold(), place_object(), place_rubble(), place_trap(), SET_CORR, SET_ROOM, square_isroom(), TYP_GOLD, TYP_GOOD, TYP_GREAT, TYP_OBJECT, TYP_RUBBLE, and TYP_TRAP.

Referenced by alloc_objects().

void alloc_objects ( struct chunk c,
int  set,
int  typ,
int  num,
int  depth,
byte  origin 
)

Allocates 'num' random entities in the dungeon.

Parameters
cthe current chunk
setwhere the entity is placed (corridor, room or either)
typwhat is placed (rubble, trap, gold, item)
numnumber to place
depthgeneration depth
originitem origin (if appropriate)

See alloc_object() for more information.

References alloc_object(), num, and ok.

Referenced by cavern_gen(), classic_gen(), gauntlet_gen(), hard_centre_gen(), labyrinth_chunk(), labyrinth_gen(), lair_gen(), modified_gen(), and moria_gen().

void alloc_stairs ( struct chunk c,
int  feat,
int  num,
int  walls 
)

Place some staircases near walls.

Parameters
cthe current chunk
featthe stair terrain type
numnumber of staircases to place
wallsnumber of walls to surround the stairs (negotiable)

References find_empty(), i, next_to_walls(), num, and place_stairs().

Referenced by cavern_gen(), classic_gen(), gauntlet_gen(), hard_centre_gen(), labyrinth_gen(), lair_gen(), modified_gen(), and moria_gen().

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.

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().

bool cave_find ( struct chunk c,
int y,
int x,
square_predicate  pred 
)

Locate a square in the dungeon which satisfies the given predicate.

Parameters
ccurrent chunk
yfound y co-ordinate
xfound x co-ordinate
predsquare_predicate specifying what we're looking for
Returns
success

References _find_in_range(), chunk::height, and chunk::width.

Referenced by find_empty(), labyrinth_gen(), and new_player_spot().

struct chunk* cavern_gen ( struct player p)
bool chunk_copy ( struct chunk dest,
struct chunk source,
int  y0,
int  x0,
int  rotate,
bool  reflect 
)

Write a chunk, transformed, to a given offset in another chunk.

Note that objects are copied from the old chunk and not retained there

Parameters
destthe chunk where the copy is going
sourcethe chunk being copied
y0transformation parameters - see symmetry_transform()
x0transformation parameters - see symmetry_transform()
rotatetransformation parameters - see symmetry_transform()
reflecttransformation parameters - see symmetry_transform()
Returns
success - fails if the copy would not fit in the destination chunk

References cave_monster(), angband_constants::f_max, square::feat, chunk::feat_count, trap::fx, monster::fx, trap::fy, monster::fy, chunk::good_item, h, chunk::height, monster::held_obj, i, square::info, object::ix, object::iy, mem_realloc(), monster::midx, square::mon, mon_pop(), chunk::mon_rating, trap::next, object::next, NULL, square::obj, chunk::obj_max, chunk::obj_rating, chunk::objects, object::oidx, monster::race, sqinfo_copy, square_monster(), square_object(), chunk::squares, symmetry_transform(), square::trap, w, chunk::width, and z_info.

Referenced by gauntlet_gen(), hard_centre_gen(), lair_gen(), and town_gen().

bool chunk_find ( struct chunk c)

Find a chunk by pointer.

Parameters
cthe actual pointer to the sought chunk
Returns
if it was found

References chunk_list_max, and i.

struct chunk* chunk_find_name ( char *  name)

Find a chunk by name.

Parameters
namethe name of the chunk being sought
Returns
the pointer to the chunk

References chunk_list_max, i, and NULL.

Referenced by cave_generate(), and town_gen().

void chunk_list_add ( struct chunk c)

Add an entry to the chunk list - any problems with the length of this will be more in the memory used by the chunks themselves rather than the list.

Parameters
cthe chunk being added to the list

References CHUNK_LIST_INCR, chunk_list_max, mem_realloc(), and mem_zalloc().

Referenced by cave_generate(), and rd_chunks().

bool chunk_list_remove ( char *  name)

Remove an entry from the chunk list, return whether it was found.

Parameters
namethe name of the chunk being removed from the list
Returns
whether it was found; success means it was successfully removed

References CHUNK_LIST_INCR, chunk_list_max, i, mem_realloc(), and NULL.

void chunk_validate_objects ( struct chunk c)

Validate that the chunk contains no NULL objects.

Only checks for nonzero tval.

Parameters
cis the chunk to validate.

References chunk::height, monster::held_obj, square::mon, object::next, square_monster(), square_object(), chunk::squares, object::tval, and chunk::width.

Referenced by cave_generate().

struct chunk* chunk_write ( int  y0,
int  x0,
int  height,
int  width,
bool  monsters,
bool  objects,
bool  traps 
)

Write a chunk to memory and return a pointer to it.

Optionally write monsters, objects and/or traps, and in those cases delete those things from the source chunk

Parameters
y0coordinates of the top left corner of the chunk being written
x0coordinates of the top left corner of the chunk being written
heightdimensions of the chunk being written
widthdimensions of the chunk being written
monsterswhether monsters get written
objectswhether objects get written
trapswhether traps get written
Returns
the memory location of the chunk

References cave, cave_monster(), cave_new(), delete_monster(), square::feat, trap::fx, monster::fx, trap::fy, monster::fy, height, monster::held_obj, square::info, object::ix, object::iy, square::mon, new, NULL, monster::race, sqinfo_copy, square_monster(), square_object(), chunk::squares, square::trap, and width.

Referenced by cave_generate().

struct chunk* classic_gen ( struct player p)
void correct_dir ( int rdir,
int cdir,
int  y1,
int  x1,
int  y2,
int  x2 
)

Given two points, pick a valid cardinal direction from one to the other.

Parameters
rdirfound row change (up or down)
cdirfound column change (left or right)
y1starting co-ordinates
x1starting co-ordinates
y2target co-ordinates
x2target co-ordinates

References CMP, and randint0.

Referenced by build_tunnel().

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().

void ensure_connectedness ( struct chunk c)

Make sure that all the regions of the dungeon are connected.

Parameters
cis the current chunk

This function colors each connected region of the dungeon, then uses that information to join them into one conected region.

References build_colors(), chunk::height, join_regions(), mem_free(), mem_zalloc(), size, and chunk::width.

Referenced by classic_gen(), gauntlet_gen(), hard_centre_gen(), lair_gen(), modified_chunk(), and moria_chunk().

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().

bool find_empty ( struct chunk c,
int y,
int x 
)

Locate an empty square for 0 <= y < ymax, 0 <= x < xmax.

Parameters
ccurrent chunk
yfound y co-ordinate
xfound x co-ordinate
Returns
success

References cave_find(), and square_isempty().

Referenced by alloc_object(), alloc_stairs(), cave_generate(), and labyrinth_chunk().

bool find_empty_range ( struct chunk c,
int y,
int  y1,
int  y2,
int x,
int  x1,
int  x2 
)

Locate an empty square for y1 <= y < y2, x1 <= x < x2.

Parameters
ccurrent chunk
yfound y co-ordinate
y1y-range
y2y-range
xfound x co-ordinate
x1x-range
x2x-range
Returns
success

References cave_find_in_range(), and square_isempty().

Referenced by hard_centre_gen(), and town_gen_layout().

bool find_nearby_grid ( struct chunk c,
int y,
int  y0,
int  yd,
int x,
int  x0,
int  xd 
)

Locate a grid nearby (y0, x0) within +/- yd, xd.

Parameters
ccurrent chunk
yfound y co-ordinate
y0starting y co-ordinate
ydy-range
xfound x co-ordinate
x0starting x co-ordinate
xdx-range
Returns
success

References cave_find_in_range(), and square_in_bounds_fully().

Referenced by build_streamer(), vault_objects(), and vault_trap_aux().

struct chunk* gauntlet_gen ( struct player p)
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().

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().

void get_chamber_monsters ( struct chunk c,
int  y1,
int  x1,
int  y2,
int  x2,
char *  name,
int  area 
)

Funtion for placing appropriate monsters in a room of chambers.

Parameters
cthe current chunk being generated
y1the limits of the vault
x1the limits of the vault
y2the limits of the vault
x2the limits of the vault
namethe name of the monster type for use in mon_select()
areathe total room area, used for scaling monster quantity

References ABS, chunk::depth, dun, generate_mark(), get_mon_num(), i, mon_restrict(), my_strcpy(), pit_profile::name, NULL, one_in_, pick_and_place_monster(), dun_data::pit_type, randint0, set_pit_type(), square_isempty(), and void().

Referenced by build_room_of_chambers().

void get_vault_monsters ( struct chunk c,
char  racial_symbol[],
char *  vault_type,
const char *  data,
int  y1,
int  y2,
int  x1,
int  x2 
)

To avoid rebuilding the monster list too often (which can quickly get expensive), we handle monsters of a specified race separately.

Parameters
cthe current chunk being generated
racial_symbolthe allowable monster_base symbols
vault_typethe type of vault, which affects monster selection depth
datathe vault text description, which contains the racial symbol
y1the limits of the vault
y2the limits of the vault
x1the limits of the vault
x2the limits of the vault

References allow_unique, base_d_char, player::depth, format(), get_mon_num(), get_mon_num_prep(), i, mon_select(), my_strcpy(), NULL, and pick_and_place_monster().

Referenced by build_vault().

struct chunk* hard_centre_gen ( struct player p)
void i_to_yx ( int  i,
int  w,
int y,
int x 
)

Used to convert an array index (i) into (x, y) in a chunk of width w.

Parameters
igrid index
warea width
yco-ordinates
xco-ordinates

References w.

Referenced by build_color_point(), join_region(), lab_get_adjoin(), labyrinth_chunk(), and make_noise().

struct chunk* labyrinth_gen ( struct player p)

Build a labyrinth level.

Parameters
pis the player Note that if the function returns false, a level wasn't generated. Labyrinths use the dungeon level's number to determine whether to generate themselves (which means certain level numbers are more likely to generate labyrinths than others).

References alloc_objects(), alloc_stairs(), cave_find(), chunk::depth, player::depth, angband_constants::dungeon_hgt, angband_constants::dungeon_wid, FEAT_LESS, FEAT_MORE, h, i, labyrinth_chunk(), angband_constants::level_monster_min, player_upkeep::light_level, MAX, MIN, new_player_spot(), NULL, pick_and_place_distant_monster(), Rand_normal(), randint0, randint1, SET_BOTH, SET_CORR, square_isdownstairs(), square_isupstairs(), TYP_GOLD, TYP_GOOD, TYP_OBJECT, TYP_RUBBLE, TYP_TRAP, player::upkeep, w, and z_info.

struct chunk* lair_gen ( struct player p)
struct chunk* modified_gen ( struct player p)

Generate a new dungeon level.

Parameters
pis the player
Returns
a pointer to the generated chunk

This is sample code to illustrate some of the new dungeon generation methods; I think it actually produces quite nice levels. New stuff:

  • different sized levels
  • independence from block size: the block size can be set to any number from 1 (no blocks) to about 15; beyond that it struggles to generate enough floor space
  • the find_space function, called from the room builder functions, allows the room to find space for itself rather than the generation algorithm allocating it; this helps because the room knows better what size it is
  • a count is now kept of grids of the various terrains, allowing dungeon generation to terminate when enough floor is generated
  • there are three new room types - huge rooms, rooms of chambers and interesting rooms - as well as many new vaults
  • there is the ability to place specific monsters and objects in vaults and interesting rooms, as well as to make general monster restrictions in areas or the whole dungeon

References alloc_objects(), alloc_stairs(), dun_data::block_hgt, cave_profile::block_size, dun_data::block_wid, angband_constants::both_gold_av, angband_constants::both_item_av, build_streamer(), chunk::depth, player::depth, draw_rectangle(), dun, angband_constants::dungeon_hgt, angband_constants::dungeon_wid, FEAT_LESS, FEAT_MAGMA, FEAT_MORE, FEAT_PERM, FEAT_QUARTZ, chunk::height, i, is_quest(), angband_constants::level_monster_min, streamer_profile::mag, MAX, streamer_profile::mc, MIN, modified_chunk(), mon_restrict(), new_player_spot(), NULL, pick_and_place_distant_monster(), dun_data::profile, streamer_profile::qc, streamer_profile::qua, Rand_normal(), rand_range(), randint0, randint1, angband_constants::room_item_av, SET_BOTH, SET_CORR, SET_ROOM, cave_profile::str, TYP_GOLD, TYP_OBJECT, TYP_RUBBLE, TYP_TRAP, chunk::width, and z_info.

bool mon_pit_hook ( struct monster_race race)
bool mon_restrict ( const char *  monster_type,
int  depth,
bool  unique_ok 
)

Accept characters representing a race or group of monsters and an (adjusted) depth, and use these to set values for required monster base symbol.

Parameters
monster_typethe monster type to be selected, as described below
depththe native depth to choose monsters
unique_okwhether to allow uniques to be chosen
Returns
success if the monster allocation table has been rebuilt

This code has been adapted from Oangband code to make use of monster bases.

This function is called to set restrictions, point the monster allocation function to mon_select() or mon_pit_hook(), and remake monster allocation. It undoes all of this things when called with monster_type NULL. If called with a pit profile name, it will get monsters from that profile. If called with monster_type "random", it will get a random monster base and describe the monsters by its name (for use by cheat_room).

References ABS, allow_unique, base_d_char, monster_race::d_char, player::depth, dun, flags, format(), get_mon_num_prep(), i, level, lookup_pit_profile(), mon_pit_hook(), mon_select(), my_strcpy(), NULL, dun_data::pit_type, profile, r_info, angband_constants::r_max, randint1, pit_profile::rarity, rf_has, RF_UNIQUE, streq, and z_info.

Referenced by gauntlet_gen(), get_chamber_monsters(), lair_gen(), modified_gen(), moria_gen(), and spread_monsters().

struct chunk* moria_gen ( struct player p)

Generate a new dungeon level.

Parameters
pis the player
Returns
a pointer to the generated chunk

This produces Oangband-style moria levels.

Most rooms on these levels are large, ragged-edged and roughly oval-shaped.

Monsters are mostly "Moria dwellers" - orcs, ogres, trolls and giants.

Apart from the room and monster changes, generation is similar to modified levels. A good way of selecting these instead of modified (similar to labyrinth levels are selected) would be if ((c->depth >= 10) && (c->depth < 40) && one_in_(40))

References alloc_objects(), alloc_stairs(), dun_data::block_hgt, cave_profile::block_size, dun_data::block_wid, angband_constants::both_gold_av, angband_constants::both_item_av, build_streamer(), chunk::depth, player::depth, draw_rectangle(), dun, angband_constants::dungeon_hgt, angband_constants::dungeon_wid, FEAT_LESS, FEAT_MAGMA, FEAT_MORE, FEAT_PERM, FEAT_QUARTZ, chunk::height, i, is_quest(), angband_constants::level_monster_min, streamer_profile::mag, MAX, streamer_profile::mc, MIN, mon_restrict(), moria_chunk(), new_player_spot(), NULL, pick_and_place_distant_monster(), dun_data::profile, streamer_profile::qc, streamer_profile::qua, Rand_normal(), rand_range(), randint0, randint1, angband_constants::room_item_av, SET_BOTH, SET_CORR, SET_ROOM, cave_profile::str, TYP_GOLD, TYP_OBJECT, TYP_RUBBLE, TYP_TRAP, void(), chunk::width, and z_info.

void new_player_spot ( struct chunk c,
struct player p 
)
void place_closed_door ( struct chunk c,
int  y,
int  x 
)
void place_gold ( struct chunk c,
int  y,
int  x,
int  level,
byte  origin 
)

Place a random amount of gold at (x, y).

Parameters
ccurrent chunk
yco-ordinates
xco-ordinates
levelgeneration depth
originitem origin

References floor_carry(), level, list_object(), make_gold(), NULL, object_delete(), object::origin, object::origin_depth, square_canputitem(), and square_in_bounds().

Referenced by alloc_object(), build_vault(), do_cmd_tunnel_aux(), project_feature_handler_KILL_WALL(), and vault_objects().

void place_object ( struct chunk c,
int  y,
int  x,
int  level,
bool  good,
bool  great,
byte  origin,
int  tval 
)

Place a random object at (x, y).

Parameters
ccurrent chunk
yco-ordinates
xco-ordinates
levelgeneration depth
goodis it a good object?
greatis it a great object?
originitem origin
tvalspecified tval, if any

References object::artifact, artifact::created, chunk::depth, floor_carry(), chunk::good_item, list_object(), make_object(), chunk::obj_rating, object_delete(), object::origin, object::origin_depth, square_canputitem(), and square_in_bounds().

Referenced by alloc_object(), build_crossed(), build_large(), build_nest(), build_pit(), build_room_template(), build_vault(), do_cmd_tunnel_aux(), project_feature_handler_KILL_WALL(), and vault_objects().

void place_random_door ( struct chunk c,
int  y,
int  x 
)

Place a random door at (x, y).

Parameters
ccurrent chunk
yco-ordinates
xco-ordinates

The door generated could be closed, open, broken, or secret.

References FEAT_BROKEN, FEAT_OPEN, place_closed_door(), randint0, and square_set_feat().

Referenced by build_room_of_chambers(), build_tunnel(), and try_door().

void place_random_stairs ( struct chunk c,
int  y,
int  x 
)

Place random stairs at (x, y).

Parameters
ccurrent chunk
yco-ordinates
xco-ordinates

References FEAT_LESS, FEAT_MORE, place_stairs(), randint0, and square_canputitem().

Referenced by build_large(), and build_room_template().

void place_secret_door ( struct chunk c,
int  y,
int  x 
)

Place a secret door at (x, y).

Parameters
ccurrent chunk
yco-ordinates
xco-ordinates

References FEAT_SECRET, and square_set_feat().

Referenced by build_large(), build_room_template(), and build_vault().

void rand_dir ( int rdir,
int cdir 
)

Pick a random cardinal direction.

Parameters
rdirdirection co-ordinates
cdirdirection co-ordinates

References ddx_ddd, ddy_ddd, i, and randint0.

Referenced by build_circular(), and build_tunnel().

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().

void shuffle ( int arr,
int  n 
)

Shuffle an array using Knuth's shuffle.

Parameters
arrarray
nnumber of shuffle moves

References i, and randint0.

Referenced by labyrinth_chunk().

void spread_monsters ( struct chunk c,
const char *  type,
int  depth,
int  num,
int  y0,
int  x0,
int  dy,
int  dx,
byte  origin 
)

Place monsters, up to the number asked for, in a rectangle centered on y0, x0.

Accept values for monster depth, symbol, and maximum vertical and horizontal displacement. Call monster restriction functions if needed.

Parameters
cthe current chunk being generated
typethe type of monster (see comments to mon_restrict())
depthselection depth
numthe number of monsters to try and place - inexact due to groups
y0the centre of the rectangle for monster placement
x0the centre of the rectangle for monster placement
dythe dimensions of the rectangle
dxthe dimensions of the rectangle
originthe origin for monster drops

Return prematurely if the code starts looping too much (this may happen if y0 or x0 are out of bounds, or the area is already occupied).

References get_mon_num(), i, chunk::mon_max, mon_restrict(), NULL, num, pick_and_place_monster(), rand_spread, square_in_bounds(), square_isempty(), and void().

Referenced by gauntlet_gen(), and lair_gen().

struct chunk* town_gen ( struct player p)

Town logic flow for generation of new town.

Parameters
pis the player
Returns
a pointer to the generated chunk We start with a fully wiped cave of normal floors. This function does NOT do anything about the owners of the stores, nor the contents thereof. It only handles the physical layout.

References cave_illuminate(), cave_new(), chunk_copy(), chunk_find_name(), chunk::depth, player::depth, square::feat, FEAT_MORE, chunk::height, i, is_daytime(), pick_and_place_distant_monster(), player_place(), quit_fmt(), chunk::squares, town_gen_layout(), angband_constants::town_hgt, angband_constants::town_monsters_day, angband_constants::town_monsters_night, angband_constants::town_wid, chunk::width, and z_info.

void vault_monsters ( struct chunk c,
int  y1,
int  x1,
int  depth,
int  num 
)

Place 'num' sleeping monsters near (x, y).

Parameters
cthe current chunk
y1co-ordinates to place the monsters near
x1co-ordinates to place the monsters near
depthgeneration depth
numnumber of monsters to place

References i, num, pick_and_place_monster(), scatter(), square_in_bounds(), and square_isempty().

Referenced by build_circular(), build_crossed(), build_large(), and build_room_template().

void vault_objects ( struct chunk c,
int  y,
int  x,
int  depth,
int  num 
)

Create up to 'num' objects near the given coordinates in a vault.

Parameters
cthe current chunk
yco-ordinates
xco-ordinates
depthgeneeration depth
numnumber of objects

References find_nearby_grid(), i, num, place_gold(), place_object(), randint0, and square_canputitem().

Referenced by build_circular(), build_large(), and build_room_template().

void vault_traps ( struct chunk c,
int  y,
int  x,
int  yd,
int  xd,
int  num 
)

Place 'num' traps near (x, y), with a given displacement.

Parameters
cthe current chunk
yco-ordinates to place the trap near
xco-ordinates to place the trap near
ydhow far afield to look for a place
xdhow far afield to look for a place
numnumber of traps to place

References i, num, and vault_trap_aux().

Referenced by build_crossed(), and build_large().

int yx_to_i ( int  y,
int  x,
int  w 
)

Used to convert (x, y) into an array index (i) in a chunk of width w.

Parameters
yco-ordinates
xco-ordinates
warea width
Returns
grid index

Referenced by build_color_point(), clear_small_regions(), connect_caverns(), ignore_point(), join_region(), lab_get_adjoin(), labyrinth_chunk(), and make_noise().

Variable Documentation

struct dun_data* dun
byte get_angle_to_grid[41][41]

Accept values for y and x (considered as the endpoints of lines) between 0 and 40, and return an angle in degrees (divided by two).

-LM-

This table's input and output need some processing:

Because this table gives degrees for a whole circle, up to radius 20, its origin is at (x,y) = (20, 20). Therefore, the input code needs to find the origin grid (where the lines being compared come from), and then map it to table grid 20,20. Do not, however, actually try to compare the angle of a line that begins and ends at the origin with any other line - it is impossible mathematically, and the table will return the value "255".

The output of this table also needs to be massaged, in order to avoid the discontinuity at 0/180 degrees. This can be done by: rotate = 90 - first value this rotates the first input to the 90 degree line) tmp = ABS(second value + rotate) % 180 diff = ABS(90 - tmp) = the angular difference (divided by two) between the first and second values.

Note that grids diagonal to the origin have unique angles.

Referenced by effect_handler_THRUST_AWAY(), generate_starburst_room(), and project().

struct pit_profile* pit_info
struct room_template* room_templates

Referenced by random_room_template().

struct vault* vaults

Referenced by random_vault().