Angband
Functions | Variables
obj-chest.c File Reference

Encapsulation of chest-related functions. More...

#include "angband.h"
#include "cave.h"
#include "effects.h"
#include "init.h"
#include "mon-lore.h"
#include "obj-chest.h"
#include "obj-ignore.h"
#include "obj-knowledge.h"
#include "obj-make.h"
#include "obj-pile.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-calcs.h"
#include "player-spell.h"
#include "player-timed.h"
#include "player-util.h"

Functions

static enum parser_error parse_chest_trap_name (struct parser *p)
 

Parsing functions for chest_trap.txt and chest.txt

More...
 
static enum parser_error parse_chest_trap_code (struct parser *p)
 
static enum parser_error parse_chest_trap_level (struct parser *p)
 
static enum parser_error parse_chest_trap_effect (struct parser *p)
 
static enum parser_error parse_chest_trap_dice (struct parser *p)
 
static enum parser_error parse_chest_trap_expr (struct parser *p)
 
static enum parser_error parse_chest_trap_destroy (struct parser *p)
 
static enum parser_error parse_chest_trap_magic (struct parser *p)
 
static enum parser_error parse_chest_trap_msg (struct parser *p)
 
static enum parser_error parse_chest_trap_msg_death (struct parser *p)
 
struct parserinit_parse_chest_trap (void)
 
static errr run_parse_chest_trap (struct parser *p)
 
static errr finish_parse_chest_trap (struct parser *p)
 
static void cleanup_chest_trap (void)
 
char * chest_trap_name (const struct object *obj)
 

Chest trap information

More...
 
bool is_trapped_chest (const struct object *obj)
 Determine if a chest is trapped. More...
 
bool is_locked_chest (const struct object *obj)
 Determine if a chest is locked or trapped. More...
 
static int pick_one_chest_trap (int level)
 

Chest trap actions

More...
 
int pick_chest_traps (struct object *obj)
 Pick a set of chest traps Currently this only depends on the level of the chest object. More...
 
void unlock_chest (struct object *obj)
 Unlock a chest. More...
 
struct objectchest_check (struct loc grid, enum chest_query check_type)
 Determine if a grid contains a chest matching the query type, and return a pointer to the first such chest. More...
 
int count_chests (struct loc *grid, enum chest_query check_type)
 Return the number of grids holding a chests around (or under) the character. More...
 
static void chest_death (struct loc grid, struct object *chest)
 Allocate objects upon opening a chest. More...
 
static void chest_trap (struct object *obj)
 Chests have traps too. More...
 
bool do_cmd_open_chest (struct loc grid, struct object *obj)
 Attempt to open the given chest at the given location. More...
 
bool do_cmd_disarm_chest (struct object *obj)
 Attempt to disarm the chest at the given location Assume there is no monster blocking the destination. More...
 

Variables

struct chest_trapchest_traps
 Chest traps are specified in the file chest_trap.txt. More...
 
struct file_parser chest_trap_parser
 

Detailed Description

Encapsulation of chest-related functions.

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

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

◆ chest_check()

struct object* chest_check ( struct loc  grid,
enum chest_query  check_type 
)

Determine if a grid contains a chest matching the query type, and return a pointer to the first such chest.

References cave, CHEST_ANY, CHEST_OPENABLE, CHEST_TRAPPED, ignore_item_ok(), is_trapped_chest(), object::known, object::next, object::pval, square_object(), and tval_is_chest().

Referenced by context_menu_cave(), count_chests(), do_cmd_alter_aux(), do_cmd_disarm(), and do_cmd_open().

◆ chest_death()

static void chest_death ( struct loc  grid,
struct object chest 
)
static

Allocate objects upon opening a chest.

Disperse treasures from the given chest, centered at (x,y).

Wooden chests contain 1 item, Iron chests contain 2 items, and Steel chests contain 3 items. Small chests now contain good items, large chests great items, out of depth for the level on which the chest is generated.

Judgment of size and construction of chests is currently made from the name.

References cave, drop_near(), object::kind, object::known, level, make_object(), object_kind::name, object_delete(), object::origin, object::origin_depth, object::pval, randint1, and tval_is_chest().

Referenced by do_cmd_open_chest().

◆ chest_trap()

static void chest_trap ( struct object obj)
static

◆ chest_trap_name()

char* chest_trap_name ( const struct object obj)


Chest trap information

The name of a chest trap

References chest_traps, chest_trap::name, chest_trap::next, chest_trap::pval, and object::pval.

Referenced by obj_desc_chest().

◆ cleanup_chest_trap()

static void cleanup_chest_trap ( void  )
static

◆ count_chests()

int count_chests ( struct loc grid,
enum chest_query  check_type 
)

Return the number of grids holding a chests around (or under) the character.

If requested, count only trapped chests.

References chest_check(), ddgrid_ddd, player::grid, and loc_sum().

Referenced by do_cmd_disarm(), and do_cmd_open().

◆ do_cmd_disarm_chest()

bool do_cmd_disarm_chest ( struct object obj)

Attempt to disarm the chest at the given location Assume there is no monster blocking the destination.

The calculation of difficulty assumes that there are 6 types of chest trap; if more are added, it will need adjusting.

Returns true if repeated commands may continue

References chest_trap(), EVENT_INPUT_FLUSH, event_signal(), is_trapped_chest(), object::known, chest_trap::magic, msg, msgt(), chest_trap::next, no_light(), player_exp_gain(), chest_trap::pval, object::pval, randint0, SKILL_DISARM_MAGIC, SKILL_DISARM_PHYS, player_state::skills, player::state, and player::timed.

Referenced by do_cmd_alter_aux(), and do_cmd_disarm().

◆ do_cmd_open_chest()

bool do_cmd_open_chest ( struct loc  grid,
struct object obj 
)

◆ finish_parse_chest_trap()

static errr finish_parse_chest_trap ( struct parser p)
static

References parser_destroy().

◆ init_parse_chest_trap()

struct parser* init_parse_chest_trap ( void  )

◆ is_locked_chest()

bool is_locked_chest ( const struct object obj)

Determine if a chest is locked or trapped.

References ignore_item_ok(), object::pval, and tval_is_chest().

Referenced by context_menu_cave(), and project_object_handler_KILL_TRAP().

◆ is_trapped_chest()

bool is_trapped_chest ( const struct object obj)

Determine if a chest is trapped.

References ignore_item_ok(), object::pval, and tval_is_chest().

Referenced by chest_check(), do_cmd_disarm_chest(), effect_handler_DETECT_TRAPS(), and search().

◆ parse_chest_trap_code()

static enum parser_error parse_chest_trap_code ( struct parser p)
static

◆ parse_chest_trap_destroy()

static enum parser_error parse_chest_trap_destroy ( struct parser p)
static

◆ parse_chest_trap_dice()

static enum parser_error parse_chest_trap_dice ( struct parser p)
static

◆ parse_chest_trap_effect()

static enum parser_error parse_chest_trap_effect ( struct parser p)
static

◆ parse_chest_trap_expr()

static enum parser_error parse_chest_trap_expr ( struct parser p)
static

◆ parse_chest_trap_level()

static enum parser_error parse_chest_trap_level ( struct parser p)
static

◆ parse_chest_trap_magic()

static enum parser_error parse_chest_trap_magic ( struct parser p)
static

◆ parse_chest_trap_msg()

static enum parser_error parse_chest_trap_msg ( struct parser p)
static

◆ parse_chest_trap_msg_death()

static enum parser_error parse_chest_trap_msg_death ( struct parser p)
static

◆ parse_chest_trap_name()

static enum parser_error parse_chest_trap_name ( struct parser p)
static


Parsing functions for chest_trap.txt and chest.txt

References h, mem_zalloc(), chest_trap::name, chest_trap::next, parser_getstr(), parser_priv(), parser_setpriv(), chest_trap::pval, and string_make().

Referenced by init_parse_chest_trap().

◆ pick_chest_traps()

int pick_chest_traps ( struct object obj)

Pick a set of chest traps Currently this only depends on the level of the chest object.

References object::kind, object_kind::level, one_in_, and pick_one_chest_trap().

Referenced by apply_magic().

◆ pick_one_chest_trap()

static int pick_one_chest_trap ( int  level)
static


Chest trap actions

Pick a single chest trap for a given level of chest object

References chest_trap::level, chest_trap::next, chest_trap::pval, and randint0.

Referenced by pick_chest_traps().

◆ run_parse_chest_trap()

static errr run_parse_chest_trap ( struct parser p)
static

◆ unlock_chest()

void unlock_chest ( struct object obj)

Unlock a chest.

References object::pval.

Referenced by project_object_handler_KILL_TRAP().

Variable Documentation

◆ chest_trap_parser

struct file_parser chest_trap_parser
Initial value:
= {
"chest_trap",
}
static errr finish_parse_chest_trap(struct parser *p)
Definition: obj-chest.c:262
static errr run_parse_chest_trap(struct parser *p)
Definition: obj-chest.c:258
struct parser * init_parse_chest_trap(void)
Definition: obj-chest.c:242
static void cleanup_chest_trap(void)
Definition: obj-chest.c:267

◆ chest_traps

struct chest_trap* chest_traps

Chest traps are specified in the file chest_trap.txt.

Chests are described by their 16-bit pval as follows:

  • pval of 0 is an empty chest
  • pval of 1 is a locked chest with no traps
  • pval > 1 is a trapped chest, with each bit of the pval aside from the lowest and highest (potentially) representing a different trap
  • pval < 1 is a disarmed/unlocked chest; the disarming process is simply to negate the pval

The chest pval also determines the difficulty of disarming the chest. Currently the maximum difficulty is 60 (32 + 16 + 8 + 4); if more traps are added to chest_trap.txt, the disarming calculation will need adjusting.

Referenced by chest_trap_name(), and cleanup_chest_trap().