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 "player-attack.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.
bool square_trap_specific (struct chunk *c, int y, int x, int t_idx)
 Is there a specific kind of trap in this square?
bool square_trap_flag (struct chunk *c, int y, int x, int flag)
 Is there a trap with a given flag in this square?
static bool square_verify_trap (struct chunk *c, int y, int x, int vis)
 Determine if a trap actually exists in this square.
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.
static int pick_trap (int feat, int trap_level)
 Instantiate a player trap.
void place_trap (struct chunk *c, int y, int x, int t_idx, int trap_level)
 Make a new trap of the given type.
void square_free_trap (struct chunk *c, int y, int x)
 Free memory for all traps on a grid.
bool square_reveal_trap (struct chunk *c, int y, int x, int chance, bool domsg)
 Reveal some of the player traps in a square.
int num_traps (struct chunk *c, int y, int x, int vis)
 Count the number of player traps in this location.
bool trap_check_hit (int power)
 Determine if a trap affects the player.
void hit_trap (int y, int x)
 Hit a trap.
static void remove_trap_aux (struct chunk *c, struct trap *trap, int y, int x, bool domsg)
 Remove a trap.
bool square_remove_trap (struct chunk *c, int y, int x, bool domsg, int t_idx)
 Remove traps.
void square_set_door_lock (struct chunk *c, int y, int x, int power)
 Lock a closed door to a given power.
int square_door_power (struct chunk *c, int y, int x)
 Return the power of the lock on a door.

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)
read
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, chunk::squares, square::trap, and trf_has.

Referenced by hit_trap().

static int pick_trap ( 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(), sqinfo_on, square_light_spot(), square_player_trap_allowed(), chunk::squares, trap::t_idx, square::trap, angband_constants::trap_max, trf_copy, and z_info.

Referenced by alloc_object(), build_vault(), project_feature_handler_MAKE_TRAP(), square_add_trap(), square_add_ward(), square_set_door_lock(), and vault_trap_aux().

static void remove_trap_aux ( struct chunk c,
struct trap trap,
int  y,
int  x,
bool  domsg 
)
static

Remove a trap.

References trap::flags, trap::kind, mem_free(), msg, msgt(), trap_kind::name, and trf_has.

Referenced by square_remove_trap().

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, chunk::squares, 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 f_info, FALSE, square::feat, feature::flags, square_istrap(), square_object(), chunk::squares, and tf_has.

Referenced by place_trap().

bool square_remove_trap ( struct chunk c,
int  y,
int  x,
bool  domsg,
int  t_idx 
)

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::next, player_can_see_bold(), remove_trap_aux(), square_light_spot(), square_verify_trap(), chunk::squares, and square::trap.

Referenced by square_destroy_door(), square_destroy_trap(), square_open_door(), square_remove_ward(), and square_smash_door().

bool square_reveal_trap ( struct chunk c,
int  y,
int  x,
int  chance,
bool  domsg 
)
void square_set_door_lock ( struct chunk c,
int  y,
int  x,
int  power 
)
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 FALSE, trap::flags, trap::next, square_istrap(), chunk::squares, square::trap, trf_has, and TRUE.

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 FALSE, trap::next, square_istrap(), chunk::squares, trap::t_idx, square::trap, and TRUE.

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

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 FALSE, trap::flags, square::info, sqinfo_off, square_note_spot(), chunk::squares, square::trap, trf_has, and TRUE.

Referenced by hit_trap(), and square_remove_trap().

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(), player_state::to_a, and TRUE.

Referenced by effect_handler_TRAP_DART_LOSE_CON(), effect_handler_TRAP_DART_LOSE_DEX(), effect_handler_TRAP_DART_LOSE_STR(), and effect_handler_TRAP_DART_SLOW().

Variable Documentation

struct trap_kind* trap_info