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, int y, int x, int t_idx)
 Is there a specific kind of trap in this square? More...
 
bool square_trap_flag (struct chunk *c, int y, int x, int flag)
 Is there a trap with a given flag in this square? More...
 
static bool square_verify_trap (struct chunk *c, int y, int x, int vis)
 Determine if a trap actually exists in this square. More...
 
bool square_player_trap_allowed (struct chunk *c, int y, int x)
 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, int y, int x, int t_idx, int trap_level)
 Make a new trap of the given type. More...
 
void square_free_trap (struct chunk *c, int y, int x)
 Free memory for all traps on a grid. More...
 
bool square_reveal_trap (struct chunk *c, int y, int x, bool always, bool domsg)
 Reveal some of the player traps in a square. More...
 
int num_traps (struct chunk *c, int y, int x, int vis)
 Count the number of player traps in this location. More...
 
bool trap_check_hit (int power)
 Determine if a trap affects the player. More...
 
void hit_trap (int y, int x)
 Hit a trap. More...
 
bool square_remove_all_traps (struct chunk *c, int y, int x)
 Remove all traps from a grid. More...
 
bool square_remove_trap (struct chunk *c, int y, int x, int t_idx_remove)
 Remove traps. More...
 
bool square_set_trap_timeout (struct chunk *c, int y, int x, bool domsg, int t_idx, int time)
 Remove traps. More...
 
int square_trap_timeout (struct chunk *c, int y, int x, 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, int y, int x, int power)
 Lock a closed door to a given power. More...
 
int square_door_power (struct chunk *c, int y, int x)
 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

void hit_trap ( int  y,
int  x 
)
struct trap_kind* lookup_trap ( const char *  desc)
int num_traps ( struct chunk c,
int  y,
int  x,
int  vis 
)

Count the number of player traps in this location.

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

References trap_kind::flags, trap::flags, trap::kind, trap::next, num, square_trap(), and trf_has.

Referenced by hit_trap().

static int pick_trap ( struct chunk c,
int  feat,
int  trap_level 
)
static
void place_trap ( struct chunk c,
int  y,
int  x,
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 square::feat, trap_kind::flags, trap::flags, trap::fx, trap::fy, square::info, trap::kind, mem_zalloc(), trap::next, pick_trap(), trap_kind::power, trap::power, randcalc(), RANDOMISE, sqinfo_on, square_light_spot(), square_player_trap_allowed(), square_trap(), chunk::squares, trap::t_idx, square::trap, angband_constants::trap_max, trf_copy, and z_info.

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

int square_door_power ( struct chunk c,
int  y,
int  x 
)
void square_free_trap ( struct chunk c,
int  y,
int  x 
)

Free memory for all traps on a grid.

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

Referenced by cave_free().

bool square_player_trap_allowed ( struct chunk c,
int  y,
int  x 
)

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().

bool square_remove_all_traps ( struct chunk c,
int  y,
int  x 
)
bool square_remove_trap ( struct chunk c,
int  y,
int  x,
int  t_idx_remove 
)

Remove traps.

If called with t_idx < 0, will remove all traps in the location given. Otherwise, will remove all traps with the given kind.

Return true if traps were removed.

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

Referenced by square_remove_ward().

bool square_reveal_trap ( struct chunk c,
int  y,
int  x,
bool  always,
bool  domsg 
)
void square_set_door_lock ( struct chunk c,
int  y,
int  x,
int  power 
)
bool square_set_trap_timeout ( struct chunk c,
int  y,
int  x,
bool  domsg,
int  t_idx,
int  time 
)

Remove traps.

If called with t_idx < 0, will remove all traps in the location given. Otherwise, will remove all traps with the given kind.

Return true if no traps now exist in this grid.

References trap::kind, msg, trap_kind::name, trap::next, NULL, square_in_bounds(), square_isseen(), square_light_spot(), square_verify_trap(), chunk::squares, trap::t_idx, trap::timeout, and square::trap.

Referenced by square_disable_trap().

bool square_trap_flag ( struct chunk c,
int  y,
int  x,
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().

bool square_trap_specific ( struct chunk c,
int  y,
int  x,
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_iswarded(), square_set_door_lock(), and use_aux().

int square_trap_timeout ( struct chunk c,
int  y,
int  x,
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, chunk::squares, trap::t_idx, trap::timeout, and square::trap.

Referenced by square_isdisabledtrap().

static bool square_verify_trap ( struct chunk c,
int  y,
int  x,
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, square::info, sqinfo_off, square_note_spot(), square_trap(), chunk::squares, and trf_has.

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

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

struct trap_kind* trap_info