Angband
Functions | Variables
cave.c File Reference

chunk allocation and utility functions More...

#include "angband.h"
#include "cave.h"
#include "cmds.h"
#include "cmd-core.h"
#include "game-event.h"
#include "game-world.h"
#include "init.h"
#include "monster.h"
#include "obj-ignore.h"
#include "obj-pile.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "object.h"
#include "player-timed.h"
#include "trap.h"

Functions

int lookup_feat (const char *name)
 Find a terrain feature index by name. More...
 
void set_terrain (void)
 Set terrain constants to the indices from terrain.txt. More...
 
struct chunkcave_new (int height, int width)
 Allocate a new chunk of the world. More...
 
void cave_free (struct chunk *c)
 Free a chunk. More...
 
void list_object (struct chunk *c, struct object *obj)
 Enter an object in the list of objects for the current level/chunk. More...
 
void delist_object (struct chunk *c, struct object *obj)
 Remove an object from the list of objects for the current level/chunk. More...
 
void object_lists_check_integrity (struct chunk *c, struct chunk *c_k)
 Check that a pair of object lists are consistent and relate to locations of objects correctly. More...
 
void scatter (struct chunk *c, int *yp, int *xp, int y, int x, int d, bool need_los)
 Standard "find me a location" function, now with all legal outputs! More...
 
struct monstercave_monster (struct chunk *c, int idx)
 Get a monster on the current level by its index. More...
 
int cave_monster_max (struct chunk *c)
 The maximum number of monsters allowed in the level. More...
 
int cave_monster_count (struct chunk *c)
 The current number of monsters present on the level. More...
 
int count_feats (int *y, int *x, bool(*test)(struct chunk *c, int y, int x), bool under)
 Return the number of doors/traps around (or under) the character. More...
 

Variables

struct featuref_info
 
struct chunkcave = NULL
 
int FEAT_NONE
 
int FEAT_FLOOR
 
int FEAT_CLOSED
 
int FEAT_OPEN
 
int FEAT_BROKEN
 
int FEAT_LESS
 
int FEAT_MORE
 
int FEAT_SECRET
 
int FEAT_RUBBLE
 
int FEAT_PASS_RUBBLE
 
int FEAT_MAGMA
 
int FEAT_QUARTZ
 
int FEAT_MAGMA_K
 
int FEAT_QUARTZ_K
 
int FEAT_GRANITE
 
int FEAT_PERM
 
int FEAT_LAVA
 
const s16b ddd [9]
 Global array for looping through the "keypad directions". More...
 
const s16b ddx [10]
 Global arrays for converting "keypad direction" into "offsets". More...
 
const s16b ddy [10]
 
const s16b ddx_ddd [9]
 Global arrays for optimizing "ddx[ddd[i]]" and "ddy[ddd[i]]". More...
 
const s16b ddy_ddd [9]
 
static const int d_off_y_0 []
 Hack – Precompute a bunch of calls to distance(). More...
 
static const int d_off_x_0 []
 
static const int d_off_y_1 []
 
static const int d_off_x_1 []
 
static const int d_off_y_2 []
 
static const int d_off_x_2 []
 
static const int d_off_y_3 []
 
static const int d_off_x_3 []
 
static const int d_off_y_4 []
 
static const int d_off_x_4 []
 
static const int d_off_y_5 []
 
static const int d_off_x_5 []
 
static const int d_off_y_6 []
 
static const int d_off_x_6 []
 
static const int d_off_y_7 []
 
static const int d_off_x_7 []
 
static const int d_off_y_8 []
 
static const int d_off_x_8 []
 
static const int d_off_y_9 []
 
static const int d_off_x_9 []
 
const intdist_offsets_y [10]
 
const intdist_offsets_x [10]
 
const byte side_dirs [20][8]
 Given a central direction at position [dir #][0], return a series of directions radiating out on both sides from the central direction all the way back to its rear. More...
 

Detailed Description

chunk allocation and utility functions

Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke

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.

Function Documentation

void cave_free ( struct chunk c)
struct monster* cave_monster ( struct chunk c,
int  idx 
)
int cave_monster_count ( struct chunk c)

The current number of monsters present on the level.

References chunk::mon_cnt.

Referenced by process_world().

int cave_monster_max ( struct chunk c)
struct chunk* cave_new ( int  height,
int  width 
)
int count_feats ( int y,
int x,
bool(*)(struct chunk *c, int y, int x)  test,
bool  under 
)

Return the number of doors/traps around (or under) the character.

References ddx_ddd, ddy_ddd, player::px, player::py, square_in_bounds_fully(), and square_isknown().

Referenced by do_cmd_close(), do_cmd_disarm(), do_cmd_open(), and effect_handler_RUBBLE().

void delist_object ( struct chunk c,
struct object obj 
)

Remove an object from the list of objects for the current level/chunk.

This function is robust against delisting of unlisted objects.

References player::cave, NULL, chunk::objects, and object::oidx.

Referenced by become_aware(), delete_monster_idx(), floor_carry(), floor_carry_fail(), floor_object_for_use(), player_pickup_aux(), player_pickup_gold(), process_monster_grab_objects(), project_o(), square_know_pile(), and uncurse_object().

void list_object ( struct chunk c,
struct object obj 
)

Enter an object in the list of objects for the current level/chunk.

This function is robust against listing of duplicates or non-objects

References player::cave, i, mem_realloc(), NULL, chunk::obj_max, OBJECT_LIST_INCR, chunk::objects, and object::oidx.

Referenced by floor_carry(), monster_carry(), place_gold(), place_monster(), and place_object().

int lookup_feat ( const char *  name)

Find a terrain feature index by name.

References angband_constants::f_max, i, feature::name, quit_fmt(), streq, and z_info.

Referenced by map_info(), parse_prefs_feat(), set_terrain(), and square_apparent_name().

void object_lists_check_integrity ( struct chunk c,
struct chunk c_k 
)

Check that a pair of object lists are consistent and relate to locations of objects correctly.

References i, object::ix, object::iy, object::known, square::obj, chunk::obj_max, chunk::objects, object::oidx, pile_contains(), and chunk::squares.

Referenced by square_know_pile().

void scatter ( struct chunk c,
int yp,
int xp,
int  y,
int  x,
int  d,
bool  need_los 
)

Standard "find me a location" function, now with all legal outputs!

Obtains a legal location within the given distance of the initial location, and with "los()" from the source to destination location.

This function is often called from inside a loop which searches for locations while increasing the "d" distance.

need_los determines whether line of sight is needed

References distance(), los(), rand_spread, and square_in_bounds_fully().

Referenced by build_quest_stairs(), do_cmd_wiz_named(), multiply_monster(), place_friends(), summon_specific(), and vault_monsters().

void set_terrain ( void  )

Variable Documentation

struct chunk* cave = NULL

Referenced by acquirement(), autoinscribe_ground(), become_aware(), blow_after_effects(), build_quest_stairs(), call_monster(), can_call_monster(), cave_generate(), cave_known(), cave_light(), cave_room_aux(), cave_unlight(), chest_check(), chest_death(), chunk_write(), cleanup_angband(), close_game(), compact_monsters(), compact_monsters_aux(), context_menu_cave(), context_menu_object(), context_menu_player(), delete_monster(), delete_monster_idx(), display_feeling(), display_map(), do_animation(), do_autopickup(), do_cmd_alter_aux(), do_cmd_buy(), do_cmd_close(), do_cmd_close_aux(), do_cmd_close_test(), do_cmd_disarm(), do_cmd_disarm_aux(), do_cmd_disarm_test(), do_cmd_go_down(), do_cmd_go_up(), do_cmd_hold(), do_cmd_lock_door(), do_cmd_open(), do_cmd_open_aux(), do_cmd_open_chest(), do_cmd_open_test(), do_cmd_retrieve(), do_cmd_sell(), do_cmd_stash(), do_cmd_tunnel(), do_cmd_tunnel_aux(), do_cmd_tunnel_test(), do_cmd_walk(), do_cmd_walk_test(), do_cmd_wiz_bamf(), do_cmd_wiz_features(), do_cmd_wiz_hack_nick(), do_cmd_wiz_named(), do_cmd_wiz_query(), do_cmd_wiz_zap(), draw_path(), drop_find_grid(), drop_near(), effect_handler_BALL(), effect_handler_BANISH(), effect_handler_BREATH(), effect_handler_CREATE_STAIRS(), effect_handler_DAMAGE(), effect_handler_DESTRUCTION(), effect_handler_DETECT_DOORS(), effect_handler_DETECT_EVIL(), effect_handler_DETECT_GOLD(), effect_handler_DETECT_INVISIBLE_MONSTERS(), effect_handler_DETECT_OBJECTS(), effect_handler_DETECT_STAIRS(), effect_handler_DETECT_TRAPS(), effect_handler_DETECT_VISIBLE_MONSTERS(), effect_handler_DRAIN_MANA(), effect_handler_EARTHQUAKE(), effect_handler_LIGHT_LEVEL(), effect_handler_MAP_AREA(), effect_handler_MASS_BANISH(), effect_handler_MON_HEAL_HP(), effect_handler_MON_HEAL_KIN(), effect_handler_MON_TIMED_INC(), effect_handler_PROBE(), effect_handler_PROJECT_LOS(), effect_handler_PROJECT_LOS_AWARE(), effect_handler_RUBBLE(), effect_handler_RUNE(), effect_handler_SENSE_OBJECTS(), effect_handler_SUMMON(), effect_handler_TELEPORT(), effect_handler_TELEPORT_TO(), effect_handler_THRUST_AWAY(), effect_handler_WAKE(), enter_store(), fill_terrain_info(), find_artifact(), findpath(), floor_carry_fail(), floor_object_for_use(), get_debug_command(), get_moves(), get_moves_advance(), get_panel_skills(), get_target(), grid_data_as_text(), hit_trap(), hp_colour_change(), ignore_drop(), ignore_known_item_ok(), inven_drop(), is_valid_pf(), item_is_available(), light_room(), look_mon_desc(), make_attack_spell(), make_noise(), make_ranged_shot(), make_ranged_throw(), map_info(), melee_effect_handler_EAT_GOLD(), melee_effect_handler_EAT_ITEM(), modify_panel(), monster_can_hear(), monster_can_smell(), monster_death(), monster_list_can_update(), monster_list_collect(), monster_list_new(), monster_list_reset(), monster_list_show_subwindow(), monster_reduce_sleep(), monster_swap(), monster_take_terrain_damage(), move_player(), multiply_monster(), near_permwall(), no_light(), object_delete(), object_flavor_aware(), object_list_collect(), object_list_entry_line_attribute(), object_list_format_name(), object_list_should_ignore_object(), object_list_standard_compare(), origin_get_loc(), pack_overflow(), panel_should_modify(), path_analyse(), player_check_terrain_damage(), player_inc_check(), player_know_object(), player_pickup_aux(), player_pickup_gold(), player_pickup_item(), player_take_terrain_damage(), process_player_cleanup(), process_world(), project(), project_feature_handler_ACID(), project_feature_handler_ARROW(), project_feature_handler_CHAOS(), project_feature_handler_COLD(), project_feature_handler_DARK_WEAK(), project_feature_handler_DISEN(), project_feature_handler_ELEC(), project_feature_handler_FIRE(), project_feature_handler_FORCE(), project_feature_handler_GRAVITY(), project_feature_handler_HOLY_ORB(), project_feature_handler_ICE(), project_feature_handler_INERTIA(), project_feature_handler_KILL_DOOR(), project_feature_handler_KILL_TRAP(), project_feature_handler_KILL_WALL(), project_feature_handler_LIGHT_WEAK(), project_feature_handler_MAKE_DOOR(), project_feature_handler_MAKE_TRAP(), project_feature_handler_MANA(), project_feature_handler_METEOR(), project_feature_handler_MISSILE(), project_feature_handler_NETHER(), project_feature_handler_NEXUS(), project_feature_handler_PLASMA(), project_feature_handler_POIS(), project_feature_handler_SHARD(), project_feature_handler_SOUND(), project_feature_handler_TIME(), project_feature_handler_WATER(), project_m(), project_m_apply_side_effects(), project_o(), project_p(), project_path(), project_player_handler_NEXUS(), prt_dtrap(), prt_level_feeling(), prt_map(), prt_map_aux(), push_object(), py_attack(), py_attack_real(), ranged_helper(), rd_dungeon(), rd_monsters(), rd_objects(), rd_traps(), recharge_objects(), refill_lamp(), remove_bad_spells(), reset_monsters(), run_game_loop(), run_step(), run_test(), rune_autoinscribe(), scan_distant_floor(), scan_floor(), search(), see_wall(), show_obj(), spell_value_base_dungeon_level(), spell_value_base_spell_power(), square_forget(), square_isknown(), square_isnotknown(), square_know_pile(), square_light_spot(), square_memorize(), square_note_spot(), square_sense_pile(), start_game(), store_at(), store_will_buy_tester(), summon_possible(), summon_specific(), take1(), target_able(), target_accept(), target_get_monsters(), target_recall_loop_object(), target_set_closest(), target_set_interactive(), target_set_interactive_aux(), target_set_location(), target_sighted(), test_drop_eat(), test_drop_pickup(), test_loadgame(), test_magic_missile(), test_newgame(), textui_process_click(), twall(), uncurse_object(), update_minimap_subwindow(), update_monsters(), update_player_object_knowledge(), update_scent(), update_stuff(), use_aux(), use_store(), wiz_create_item_drop_object(), wiz_statistics(), wiz_test_kind(), wr_dungeon(), wr_monsters(), wr_objects(), and wr_traps().

const int d_off_x_0[]
static
Initial value:
=
{ 0 }
const int d_off_x_1[]
static
Initial value:
=
{ -1, 0, 1, -1, 1, -1, 0, 1, 0 }
const int d_off_x_2[]
static
Initial value:
=
{ -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 }
const int d_off_x_3[]
static
Initial value:
=
{ -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2,
-1, 0, 1, 0 }
const int d_off_x_4[]
static
Initial value:
=
{ -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4,
-4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 }
const int d_off_x_5[]
static
Initial value:
=
{ -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
-5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
0, 1, 0 }
const int d_off_x_6[]
static
Initial value:
=
{ -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
-3, 2, 3, -1, 0, 1, 0 }
const int d_off_x_7[]
static
Initial value:
=
{ -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
-3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
1, 0 }
const int d_off_x_8[]
static
Initial value:
=
{ -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
2, 3, -1, 0, 1, 0 }
const int d_off_x_9[]
static
Initial value:
=
{ -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
-5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
4, 5, -2, -3, 2, 3, -1, 0, 1, 0 }
const int d_off_y_0[]
static
Initial value:
=
{ 0 }

Hack – Precompute a bunch of calls to distance().

The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the offsets of all the locations with a distance of n from a central point, with an offset of (0,0) indicating no more offsets at this distance.

This is, of course, fairly unreadable, but it eliminates multiple loops from the previous version.

It is probably better to replace these arrays with code to compute the relevant arrays, even if the storage is pre-allocated in hard coded sizes. At the very least, code should be included which is able to generate and dump these arrays (ala "los()"). XXX XXX XXX

const int d_off_y_1[]
static
Initial value:
=
{ -1, -1, -1, 0, 0, 1, 1, 1, 0 }
const int d_off_y_2[]
static
Initial value:
=
{ -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 }
const int d_off_y_3[]
static
Initial value:
=
{ -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2,
3, 3, 3, 0 }
const int d_off_y_4[]
static
Initial value:
=
{ -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0,
0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 }
const int d_off_y_5[]
static
Initial value:
=
{ -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
-5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
5, 0 }
const int d_off_y_6[]
static
Initial value:
=
{ -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
-6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
5, 5, 6, 6, 6, 0 }
const int d_off_y_7[]
static
Initial value:
=
{ -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
-6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 }
const int d_off_y_8[]
static
Initial value:
=
{ -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
-6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
8, 8, 8, 0 }
const int d_off_y_9[]
static
Initial value:
=
{ -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
-7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
7, 8, 8, 8, 8, 9, 9, 9, 0 }
const s16b ddd[9]
Initial value:
=
{ 2, 8, 6, 4, 3, 1, 9, 7, 5 }

Global array for looping through the "keypad directions".

Referenced by build_streamer(), player_confuse_dir(), and process_monster().

const s16b ddx[10]
const s16b ddx_ddd[9]
const s16b ddy[10]
const s16b ddy_ddd[9]
const int* dist_offsets_x[10]
Initial value:
=
{
}
static const int d_off_x_5[]
Definition: cave.c:144
static const int d_off_x_4[]
Definition: cave.c:134
static const int d_off_x_9[]
Definition: cave.c:192
static const int d_off_x_3[]
Definition: cave.c:125
static const int d_off_x_1[]
Definition: cave.c:110
static const int d_off_x_2[]
Definition: cave.c:117
static const int d_off_x_8[]
Definition: cave.c:179
static const int d_off_x_7[]
Definition: cave.c:166
static const int d_off_x_6[]
Definition: cave.c:155
static const int d_off_x_0[]
Definition: cave.c:103

Referenced by find_hiding(), and find_safety().

const int* dist_offsets_y[10]
Initial value:
=
{
}
static const int d_off_y_1[]
Definition: cave.c:107
static const int d_off_y_7[]
Definition: cave.c:161
static const int d_off_y_8[]
Definition: cave.c:173
static const int d_off_y_6[]
Definition: cave.c:150
static const int d_off_y_2[]
Definition: cave.c:114
static const int d_off_y_5[]
Definition: cave.c:139
static const int d_off_y_4[]
Definition: cave.c:130
static const int d_off_y_0[]
Hack – Precompute a bunch of calls to distance().
Definition: cave.c:100
static const int d_off_y_3[]
Definition: cave.c:121
static const int d_off_y_9[]
Definition: cave.c:186

Referenced by find_hiding(), and find_safety().

struct feature* f_info
int FEAT_BROKEN
int FEAT_CLOSED
int FEAT_FLOOR
int FEAT_GRANITE
int FEAT_LAVA
int FEAT_LESS
int FEAT_MAGMA
int FEAT_MAGMA_K
int FEAT_MORE
int FEAT_NONE
int FEAT_OPEN
int FEAT_PASS_RUBBLE
int FEAT_PERM
int FEAT_QUARTZ
int FEAT_QUARTZ_K
int FEAT_RUBBLE
int FEAT_SECRET
const byte side_dirs[20][8]
Initial value:
= {
{0, 0, 0, 0, 0, 0, 0, 0},
{1, 4, 2, 7, 3, 8, 6, 9},
{2, 1, 3, 4, 6, 7, 9, 8},
{3, 2, 6, 1, 9, 4, 8, 7},
{4, 7, 1, 8, 2, 9, 3, 6},
{5, 5, 5, 5, 5, 5, 5, 5},
{6, 3, 9, 2, 8, 1, 7, 4},
{7, 8, 4, 9, 1, 6, 2, 3},
{8, 9, 7, 6, 4, 3, 1, 2},
{9, 6, 8, 3, 7, 2, 4, 1},
{0, 0, 0, 0, 0, 0, 0, 0},
{1, 2, 4, 3, 7, 6, 8, 9},
{2, 3, 1, 6, 4, 9, 7, 8},
{3, 6, 2, 9, 1, 8, 4, 7},
{4, 1, 7, 2, 8, 3, 9, 6},
{5, 5, 5, 5, 5, 5, 5, 5},
{6, 9, 3, 8, 2, 7, 1, 4},
{7, 4, 8, 1, 9, 2, 6, 3},
{8, 7, 9, 4, 6, 1, 3, 2},
{9, 8, 6, 7, 3, 4, 2, 1}
}

Given a central direction at position [dir #][0], return a series of directions radiating out on both sides from the central direction all the way back to its rear.

Side directions come in pairs; for example, directions '1' and '3' flank direction '2'. The code should know which side to consider first. If the left, it must add 10 to the central direction to access the second part of the table.

Referenced by process_monster().