Angband
Functions | Variables
obj-chest.c File Reference

Encapsulation of chest-related functions. More...

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

Functions

byte chest_trap_type (const struct object *obj)
 The type of trap a chest has. 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...
 
void unlock_chest (struct object *obj)
 Unlock a chest. More...
 
struct objectchest_check (int y, int x, 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 (int *y, int *x, enum chest_query check_type)
 Return the number of grids holding a chests around (or under) the character. More...
 
static void chest_death (int y, int x, struct object *chest)
 Allocate objects upon opening a chest. More...
 
static void chest_trap (int y, int x, struct object *obj)
 Chests have traps too. More...
 
bool do_cmd_open_chest (int y, int x, struct object *obj)
 Attempt to open the given chest at the given location. More...
 
bool do_cmd_disarm_chest (int y, int x, struct object *obj)
 Attempt to disarm the chest at the given location. More...
 

Variables

static const byte chest_traps [64]
 Each chest has a certain set of traps, determined by pval Each chest has a "pval" from 1 to the chest level (max 55) If the "pval" is negative then the trap has been disarmed The "pval" of a chest determines the quality of its treasure Note that disarming a trap on a chest also removes the lock. More...
 

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

struct object* chest_check ( int  y,
int  x,
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, NULL, object::pval, square_object(), and tval_is_chest().

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

static void chest_death ( int  y,
int  x,
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, NULL, object::number, object_delete(), object::origin, object::origin_depth, object::pval, randint1, and tval_is_chest().

Referenced by do_cmd_open_chest().

static void chest_trap ( int  y,
int  x,
struct object obj 
)
static

Chests have traps too.

Exploding chest destroys contents (and traps). Note that the chest itself is never destroyed.

References CHEST_EXPLODE, CHEST_LOSE_CON, CHEST_LOSE_STR, CHEST_PARALYZE, CHEST_POISON, CHEST_SUMMON, chest_traps, damroll(), effect_simple(), msg, NULL, object::pval, source_object(), and take_hit().

Referenced by do_cmd_disarm_chest(), and do_cmd_open_chest().

byte chest_trap_type ( const struct object obj)

The type of trap a chest has.

References chest_traps, and object::pval.

Referenced by obj_desc_chest().

int count_chests ( int y,
int x,
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(), ddx_ddd, ddy_ddd, player::px, and player::py.

Referenced by do_cmd_disarm(), and do_cmd_open().

bool do_cmd_disarm_chest ( int  y,
int  x,
struct object obj 
)

Attempt to disarm the chest at the given location.

Assume there is no monster blocking the destination

Returns true if repeated commands may continue

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

Referenced by do_cmd_disarm().

bool do_cmd_open_chest ( int  y,
int  x,
struct object obj 
)

Attempt to open the given chest at the given location.

Assume there is no monster blocking the destination

Returns true if repeated commands may continue

References cave, chest_death(), chest_trap(), EVENT_INPUT_FLUSH, event_signal(), flag, i, object::known, msgt(), no_light(), player_upkeep::notice, object::notice, OBJ_NOTICE_IGNORE, player_exp_gain(), PN_IGNORE, object::pval, randint0, SKILL_DISARM_PHYS, player_state::skills, square_light_spot(), player::state, player::timed, and player::upkeep.

Referenced by do_cmd_open().

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(), obj_desc_chest(), and project_object_handler_KILL_TRAP().

bool is_trapped_chest ( const struct object obj)
void unlock_chest ( struct object obj)

Unlock a chest.

References object::pval.

Referenced by project_object_handler_KILL_TRAP().

Variable Documentation

const byte chest_traps[64]
static

Each chest has a certain set of traps, determined by pval Each chest has a "pval" from 1 to the chest level (max 55) If the "pval" is negative then the trap has been disarmed The "pval" of a chest determines the quality of its treasure Note that disarming a trap on a chest also removes the lock.

Referenced by chest_trap(), chest_trap_type(), do_cmd_disarm_chest(), and is_trapped_chest().