Angband
Functions | Variables
trap.c File Reference

The trap layer - player traps, runes and door locks. More...

#include "angband.h"
#include "cave.h"
#include "effects.h"
#include "init.h"
#include "mon-util.h"
#include "obj-knowledge.h"
#include "player-attack.h"
#include "player-timed.h"
#include "player-util.h"
#include "trap.h"

Functions

struct trap_kindlookup_trap (const char *desc)
 Find a trap kind based on its short description. More...
 
bool square_trap_specific (struct chunk *c, struct loc grid, int t_idx)
 Is there a specific kind of trap in this square? More...
 
bool square_trap_flag (struct chunk *c, struct loc grid, int flag)
 Is there a trap with a given flag in this square? More...
 
static bool square_verify_trap (struct chunk *c, struct loc grid, int vis)
 Determine if a trap actually exists in this square. More...
 
bool square_player_trap_allowed (struct chunk *c, struct loc grid)
 Determine if a cave grid is allowed to have player traps in it. More...
 
static int pick_trap (struct chunk *c, int feat, int trap_level)
 Instantiate a player trap. More...
 
void place_trap (struct chunk *c, struct loc grid, int t_idx, int trap_level)
 Make a new trap of the given type. More...
 
void square_free_trap (struct chunk *c, struct loc grid)
 Free memory for all traps on a grid. More...
 
bool square_reveal_trap (struct chunk *c, struct loc grid, bool always, bool domsg)
 Reveal some of the player traps in a square. More...
 
void square_memorize_traps (struct chunk *c, struct loc grid)
 Memorize all the visible traps on a square. More...
 
bool trap_check_hit (int power)
 Determine if a trap affects the player. More...
 
void hit_trap (struct loc grid, int delayed)
 Hit a trap. More...
 
bool square_remove_all_traps (struct chunk *c, struct loc grid)
 Remove all traps from a grid. More...
 
bool square_remove_trap (struct chunk *c, struct loc grid, int t_idx_remove)
 Remove all traps with the given index. More...
 
bool square_set_trap_timeout (struct chunk *c, struct loc grid, bool domsg, int t_idx, int time)
 Disable a trap for the specified number of turns. More...
 
int square_trap_timeout (struct chunk *c, struct loc grid, int t_idx)
 Give the remaining time for a trap to be disabled; note it chooses the first appropriate trap on the grid. More...
 
void square_set_door_lock (struct chunk *c, struct loc grid, int power)
 Lock a closed door to a given power. More...
 
int square_door_power (struct chunk *c, struct loc grid)
 Return the power of the lock on a door. More...
 

Variables

struct trap_kindtrap_info
 

Detailed Description

The trap layer - player traps, runes and door locks.

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

◆ hit_trap()

void hit_trap ( struct loc  grid,
int  delayed 
)

◆ lookup_trap()

struct trap_kind* lookup_trap ( const char *  desc)

◆ pick_trap()

static int pick_trap ( struct chunk c,
int  feat,
int  trap_level 
)
static

◆ place_trap()

void place_trap ( struct chunk c,
struct loc  grid,
int  t_idx,
int  trap_level 
)

Make a new trap of the given type.

Return true if successful.

We choose a player trap at random if the index is not legal. This means that things which are not player traps must be picked by passing a valid index.

This should be the only function that places traps in the dungeon except the savefile loading code.

References trap_kind::flags, trap::flags, trap::grid, trap::kind, mem_zalloc(), trap::next, pick_trap(), trap_kind::power, trap::power, randcalc(), RANDOMISE, sqinfo_on, square(), square_light_spot(), square_note_spot(), square_player_trap_allowed(), square_set_trap(), square_trap(), trap::t_idx, angband_constants::trap_max, trf_copy, and z_info.

Referenced by alloc_object(), build_room_template(), build_vault(), get_debug_command(), square_add_glyph(), square_add_trap(), square_add_web(), square_set_door_lock(), and try_door().

◆ square_door_power()

int square_door_power ( struct chunk c,
struct loc  grid 
)

◆ square_free_trap()

void square_free_trap ( struct chunk c,
struct loc  grid 
)

Free memory for all traps on a grid.

References mem_free(), trap::next, and square_trap().

Referenced by cave_free().

◆ square_memorize_traps()

void square_memorize_traps ( struct chunk c,
struct loc  grid 
)

◆ square_player_trap_allowed()

bool square_player_trap_allowed ( struct chunk c,
struct loc  grid 
)

Determine if a cave grid is allowed to have player traps in it.

References square_istrap(), square_istrappable(), and square_object().

Referenced by place_trap(), and square_set_feat().

◆ square_remove_all_traps()

bool square_remove_all_traps ( struct chunk c,
struct loc  grid 
)

◆ square_remove_trap()

bool square_remove_trap ( struct chunk c,
struct loc  grid,
int  t_idx_remove 
)

Remove all traps with the given index.

Return true if traps were removed.

References mem_free(), trap::next, square(), square_in_bounds(), square_isseen(), square_light_spot(), square_set_trap(), square_verify_trap(), trap::t_idx, square::trap, and void().

◆ square_reveal_trap()

bool square_reveal_trap ( struct chunk c,
struct loc  grid,
bool  always,
bool  domsg 
)

◆ square_set_door_lock()

void square_set_door_lock ( struct chunk c,
struct loc  grid,
int  power 
)

◆ square_set_trap_timeout()

bool square_set_trap_timeout ( struct chunk c,
struct loc  grid,
bool  domsg,
int  t_idx,
int  time 
)

◆ square_trap_flag()

bool square_trap_flag ( struct chunk c,
struct loc  grid,
int  flag 
)

Is there a trap with a given flag in this square?

References trap::flags, trap::next, square_istrap(), square_trap(), and trf_has.

Referenced by square_isplayertrap(), and square_isvisibletrap().

◆ square_trap_specific()

bool square_trap_specific ( struct chunk c,
struct loc  grid,
int  t_idx 
)

Is there a specific kind of trap in this square?

References trap::next, square_istrap(), square_trap(), and trap::t_idx.

Referenced by square_door_power(), square_isdecoyed(), square_iswarded(), square_iswebbed(), square_set_door_lock(), and use_aux().

◆ square_trap_timeout()

int square_trap_timeout ( struct chunk c,
struct loc  grid,
int  t_idx 
)

Give the remaining time for a trap to be disabled; note it chooses the first appropriate trap on the grid.

References trap::next, square(), trap::t_idx, trap::timeout, and square::trap.

Referenced by square_isdisabledtrap().

◆ square_verify_trap()

static bool square_verify_trap ( struct chunk c,
struct loc  grid,
int  vis 
)
static

Determine if a trap actually exists in this square.

Called with vis = 0 to accept any trap, = 1 to accept only visible traps, and = -1 to accept only invisible traps.

Clear the SQUARE_TRAP flag if none exist.

References trap::flags, sqinfo_off, square(), square_note_spot(), square_trap(), and trf_has.

Referenced by hit_trap(), square_remove_all_traps(), square_remove_trap(), and square_set_trap_timeout().

◆ trap_check_hit()

bool trap_check_hit ( int  power)

Determine if a trap affects the player.

Always miss 5% of the time, Always hit 5% of the time. Otherwise, match trap power against player armor.

References player_state::ac, player::state, test_hit(), and player_state::to_a.

Referenced by hit_trap().

Variable Documentation

◆ trap_info

struct trap_kind* trap_info