Angband
|
Dungeon generation utilities. 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-make.h"
#include "obj-pile.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-util.h"
#include "trap.h"
#include "z-queue.h"
#include "z-type.h"
Functions | |
int | grid_to_i (struct loc grid, int w) |
Used to convert grid into an array index (i) in a chunk of width w. More... | |
void | i_to_grid (int i, int w, struct loc *grid) |
Used to convert an array index (i) into grid in a chunk of width w. More... | |
void | shuffle (int *arr, int n) |
Shuffle an array using Knuth's shuffle. More... | |
static bool | cave_find_in_range (struct chunk *c, struct loc *grid, struct loc top_left, struct loc bottom_right, square_predicate pred) |
Locate a square in a rectangle which satisfies the given predicate. More... | |
bool | cave_find (struct chunk *c, struct loc *grid, square_predicate pred) |
Locate a square in the dungeon which satisfies the given predicate. More... | |
bool | find_empty (struct chunk *c, struct loc *grid) |
Locate an empty square for 0 <= y < ymax, 0 <= x < xmax. More... | |
bool | find_empty_range (struct chunk *c, struct loc *grid, struct loc top_left, struct loc bottom_right) |
Locate an empty square in a given rectangle. More... | |
bool | find_nearby_grid (struct chunk *c, struct loc *grid, struct loc centre, int yd, int xd) |
Locate a grid within +/- yd, xd of a centre. More... | |
void | correct_dir (struct loc *offset, struct loc grid1, struct loc grid2) |
Given two points, pick a valid cardinal direction from one to the other. More... | |
void | rand_dir (struct loc *offset) |
Pick a random cardinal direction. More... | |
static bool | find_start (struct chunk *c, struct loc *grid) |
Determine whether the given coordinate is a valid starting location. More... | |
void | new_player_spot (struct chunk *c, struct player *p) |
Place the player at a random starting location. More... | |
static void | place_rubble (struct chunk *c, struct loc grid) |
Place rubble at a given location. More... | |
static void | place_stairs (struct chunk *c, struct loc grid, int feat) |
Place stairs (of the requested type 'feat' if allowed) at a given location. More... | |
void | place_random_stairs (struct chunk *c, struct loc grid) |
Place random stairs at a given location. More... | |
void | place_object (struct chunk *c, struct loc grid, int level, bool good, bool great, byte origin, int tval) |
Place a random object at a given location. More... | |
void | place_gold (struct chunk *c, struct loc grid, int level, byte origin) |
Place a random amount of gold at a given location. More... | |
void | place_secret_door (struct chunk *c, struct loc grid) |
Place a secret door at a given location. More... | |
void | place_closed_door (struct chunk *c, struct loc grid) |
Place a closed door at a given location. More... | |
void | place_random_door (struct chunk *c, struct loc grid) |
Place a random door at a given location. More... | |
void | alloc_stairs (struct chunk *c, int feat, int num) |
Place some staircases near walls. 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... | |
void | vault_objects (struct chunk *c, struct loc grid, int depth, int num) |
Create up to 'num' objects near the given coordinates in a vault. More... | |
static void | vault_trap_aux (struct chunk *c, struct loc grid, int yd, int xd) |
Place a trap near (x, y), with a given displacement. More... | |
void | vault_traps (struct chunk *c, struct loc grid, int yd, int xd, int num) |
Place 'num' traps near a location, with a given displacement. More... | |
void | vault_monsters (struct chunk *c, struct loc grid, int depth, int num) |
Place 'num' sleeping monsters near the location. More... | |
Variables | |
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... | |
Dungeon generation utilities.
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 contains various utility functions for dungeon generation - mostly for finding appropriate grids for some purposes, or placing things.
Allocates a single random object in the dungeon.
c | the current chunk |
set | where the entity is placed (corridor, room or either) |
typ | what is placed (rubble, trap, gold, item) |
depth | generation depth |
origin | item 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().
Allocates 'num' random entities in the dungeon.
c | the current chunk |
set | where the entity is placed (corridor, room or either) |
typ | what is placed (rubble, trap, gold, item) |
num | number to place |
depth | generation depth |
origin | item 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().
Place some staircases near walls.
c | the current chunk |
feat | the stair terrain type |
num | number of staircases to place |
walls | number of walls to surround the stairs (negotiable) |
References cave_find_in_range(), chunk::height, i, loc(), num, place_stairs(), square_isempty(), square_isno_stairs(), square_isvault(), square_num_walls_adjacent(), square_num_walls_diagonal(), square_suits_stairs_ok(), square_suits_stairs_well(), and chunk::width.
Referenced by cavern_gen(), classic_gen(), gauntlet_gen(), hard_centre_gen(), labyrinth_gen(), lair_gen(), modified_gen(), and moria_gen().
bool cave_find | ( | struct chunk * | c, |
struct loc * | grid, | ||
square_predicate | pred | ||
) |
Locate a square in the dungeon which satisfies the given predicate.
c | current chunk |
grid | found grid |
pred | square_predicate specifying what we're looking for |
References cave_find_in_range(), chunk::height, loc(), and chunk::width.
Referenced by find_empty(), and labyrinth_gen().
|
static |
Locate a square in a rectangle which satisfies the given predicate.
c | current chunk |
grid | found grid |
top_left | top left grid of rectangle |
bottom_right | bottom right grid of rectangle |
pred | square_predicate specifying what we're looking for |
References i, loc_diff(), mem_alloc(), mem_free(), randint0, loc::x, and loc::y.
Referenced by alloc_stairs(), cave_find(), find_empty_range(), find_nearby_grid(), and find_start().
Given two points, pick a valid cardinal direction from one to the other.
offset | found offset direction from grid 1 to grid2 |
grid1 | starting grid |
grid2 | target grid |
References CMP, randint0, loc::x, and loc::y.
Referenced by build_tunnel().
Locate an empty square for 0 <= y < ymax, 0 <= x < xmax.
c | current chunk |
grid | found grid |
References cave_find(), and square_isempty().
Referenced by alloc_object(), cave_generate(), and labyrinth_chunk().
bool find_empty_range | ( | struct chunk * | c, |
struct loc * | grid, | ||
struct loc | top_left, | ||
struct loc | bottom_right | ||
) |
Locate an empty square in a given rectangle.
c | current chunk |
grid | found grid |
top_left | top left grid of rectangle |
bottom_right | bottom right grid of rectangle |
References cave_find_in_range(), and square_isempty().
Referenced by hard_centre_gen(), and town_gen_layout().
Locate a grid within +/- yd, xd of a centre.
c | current chunk |
grid | found grid |
centre | starting grid |
yd | y-range |
xd | x-range |
References cave_find_in_range(), loc(), square_in_bounds_fully(), loc::x, and loc::y.
Referenced by build_streamer(), vault_objects(), and vault_trap_aux().
Determine whether the given coordinate is a valid starting location.
c | current chunk |
y | co-ordinates |
x | co-ordinates |
References cave_find_in_range(), chunk::height, loc(), square_isempty(), square_isno_stairs(), square_isvault(), square_num_walls_adjacent(), square_num_walls_diagonal(), square_suits_stairs_ok(), square_suits_stairs_well(), and chunk::width.
Referenced by new_player_spot().
Used to convert grid into an array index (i) in a chunk of width w.
grid | location |
w | area width |
References loc::x, and loc::y.
Referenced by build_color_point(), clear_small_regions(), connect_caverns(), ignore_point(), join_region(), lab_get_adjoin(), labyrinth_chunk(), make_noise(), and mutate_cavern().
Used to convert an array index (i) into grid in a chunk of width w.
i | grid index |
w | area width |
grid | location |
References w, loc::x, and loc::y.
Referenced by build_color_point(), join_region(), lab_get_adjoin(), labyrinth_chunk(), and make_noise().
Place the player at a random starting location.
c | current chunk |
p | the player |
References player_upkeep::create_down_stair, player_upkeep::create_up_stair, FEAT_LESS, FEAT_MORE, find_start(), player::grid, OPT, player_place(), quit(), square_in_bounds_fully(), square_isstairs(), square_set_feat(), and player::upkeep.
Referenced by cavern_gen(), classic_gen(), gauntlet_gen(), hard_centre_gen(), labyrinth_gen(), lair_gen(), modified_gen(), and moria_gen().
Place a closed door at a given location.
c | current chunk |
grid | location |
References FEAT_CLOSED, one_in_, randint1, square_set_door_lock(), and square_set_feat().
Referenced by build_circular(), build_large(), build_room_template(), effect_handler_DETECT_DOORS(), labyrinth_chunk(), place_random_door(), project_feature_handler_KILL_TRAP(), and search().
Place a random amount of gold at a given location.
c | current chunk |
grid | location |
level | generation depth |
origin | item origin |
References floor_carry(), level, list_object(), make_gold(), object_delete(), object::origin, object::origin_depth, square_canputitem(), and square_in_bounds().
Referenced by alloc_object(), blow_knock_back(), build_vault(), do_cmd_tunnel_aux(), project_feature_handler_KILL_WALL(), and vault_objects().
void place_object | ( | struct chunk * | c, |
struct loc | grid, | ||
int | level, | ||
bool | good, | ||
bool | great, | ||
byte | origin, | ||
int | tval | ||
) |
Place a random object at a given location.
c | current chunk |
grid | location |
level | generation depth |
good | is it a good object? |
great | is it a great object? |
origin | item origin |
tval | specified 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().
Place a random door at a given location.
c | current chunk |
grid | location |
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().
Place random stairs at a given location.
c | current chunk |
grid | location |
References FEAT_LESS, FEAT_MORE, place_stairs(), randint0, and square_canputitem().
Referenced by build_large(), and build_room_template().
Place rubble at a given location.
c | current chunk |
grid | location |
References FEAT_PASS_RUBBLE, FEAT_RUBBLE, one_in_, and square_set_feat().
Referenced by alloc_object().
Place a secret door at a given location.
c | current chunk |
grid | location |
References FEAT_SECRET, and square_set_feat().
Referenced by build_large(), build_room_template(), and build_vault().
Place stairs (of the requested type 'feat' if allowed) at a given location.
c | current chunk |
grid | location |
feat | stair terrain type |
All stairs from town go down. All stairs on an unfinished quest level go up.
References chunk::depth, FEAT_LESS, FEAT_MORE, is_quest(), angband_constants::max_depth, square_set_feat(), and z_info.
Referenced by alloc_stairs(), and place_random_stairs().
Pick a random cardinal direction.
offset | direction offset |
References ddgrid_ddd, i, and randint0.
Referenced by build_circular(), and build_tunnel().
Shuffle an array using Knuth's shuffle.
arr | array |
n | number of shuffle moves |
Referenced by labyrinth_chunk().
Place 'num' sleeping monsters near the location.
c | the current chunk |
grid | location to place the monsters near |
depth | generation depth |
num | number 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().
Create up to 'num' objects near the given coordinates in a vault.
c | the current chunk |
grid | location |
depth | generation depth |
num | number 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().
Place a trap near (x, y), with a given displacement.
c | the current chunk |
grid | location to place the trap near |
yd | how far afield to look for a place |
xd | how far afield to look for a place |
References find_nearby_grid(), square_add_trap(), and square_isempty().
Referenced by vault_traps().
Place 'num' traps near a location, with a given displacement.
c | the current chunk |
grid | location to place the trap near |
yd | how far afield to look for a place |
xd | how far afield to look for a place |
num | number of traps to place |
References i, num, and vault_trap_aux().
Referenced by build_crossed(), and build_large().
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 generate_starburst_room(), project(), and thrust_away().