1 /**
2  * \file trap.h
3  * \brief trap predicates, structs and functions
4  */
5 
6 #ifndef TRAP_H
7 #define TRAP_H
8 
9 /*** Trap flags ***/
10 
11 enum
12 {
13 	#define TRF(a,b) TRF_##a,
14 	#include "list-trap-flags.h"
15 	#undef TRF
16 	TRF_MAX
17 };
18 
19 #define TRF_SIZE                FLAG_SIZE(TRF_MAX)
20 
21 #define trf_has(f, flag)        flag_has_dbg(f, TRF_SIZE, flag, #f, #flag)
22 #define trf_next(f, flag)       flag_next(f, TRF_SIZE, flag)
23 #define trf_is_empty(f)         flag_is_empty(f, TRF_SIZE)
24 #define trf_is_full(f)          flag_is_full(f, TRF_SIZE)
25 #define trf_is_inter(f1, f2)    flag_is_inter(f1, f2, TRF_SIZE)
26 #define trf_is_subset(f1, f2)   flag_is_subset(f1, f2, TRF_SIZE)
27 #define trf_is_equal(f1, f2)    flag_is_equal(f1, f2, TRF_SIZE)
28 #define trf_on(f, flag)         flag_on_dbg(f, TRF_SIZE, flag, #f, #flag)
29 #define trf_off(f, flag)        flag_off(f, TRF_SIZE, flag)
30 #define trf_wipe(f)             flag_wipe(f, TRF_SIZE)
31 #define trf_setall(f)           flag_setall(f, TRF_SIZE)
32 #define trf_negate(f)           flag_negate(f, TRF_SIZE)
33 #define trf_copy(f1, f2)        flag_copy(f1, f2, TRF_SIZE)
34 #define trf_union(f1, f2)       flag_union(f1, f2, TRF_SIZE)
35 #define trf_inter(f1, f2)       flag_inter(f1, f2, TRF_SIZE)
36 #define trf_diff(f1, f2)        flag_diff(f1, f2, TRF_SIZE)
37 
38 
39 /* Types of glyph */
40 enum {
41 	GLYPH_NONE,
42 	GLYPH_WARDING,
43 	GLYPH_DECOY
44 };
45 
46 /**
47  * A trap template.
48  */
49 struct trap_kind
50 {
51 	char *name;					/**< Name  */
52 	char *text;					/**< Text  */
53 	char *desc;					/**< Short description  */
54 	char *msg;					/**< Message on hitting */
55 	char *msg_good;				/**< Message on saving */
56 	char *msg_bad;				/**< Message on failing to save */
57 	char *msg_xtra;				/**< Message on getting an extra effect */
58 
59 	struct trap_kind *next;
60 	int tidx;					/**< Trap kind index */
61 
62 	byte d_attr;				/**< Default trap attribute */
63 	wchar_t d_char;				/**< Default trap character */
64 
65 	int rarity;					/**< Rarity */
66 	int min_depth;				/**< Minimum depth */
67 	int max_num;				/**< Unused */
68 	random_value power;			/**< Visibility of player trap */
69 
70 	bitflag flags[TRF_SIZE];	/**< Trap flags (all traps of this kind) */
71 	bitflag save_flags[OF_SIZE];/**< Save flags (player with these saves) */
72 
73 	struct effect *effect;		/**< Effect on entry to grid */
74 	struct effect *effect_xtra;	/**< Possible extra effect */
75 };
76 
77 extern struct trap_kind *trap_info;
78 
79 /**
80  * An actual trap.
81  */
82 struct trap
83 {
84 	byte t_idx;					/**< Trap kind index */
85 	struct trap_kind *kind;		/**< Trap kind */
86 	struct trap *next;			/**< Next trap in this location */
87 
88 	struct loc grid;			/**< Location of trap */
89 
90 	byte power;					/**< Power for locks, visibility for traps */
91 	byte timeout;				/**< Timer for disabled traps */
92 
93 	bitflag flags[TRF_SIZE];	/**< Trap flags (only this particular trap) */
94 };
95 
96 struct trap_kind *lookup_trap(const char *desc);
97 bool square_trap_specific(struct chunk *c, struct loc grid, int t_idx);
98 bool square_trap_flag(struct chunk *c, struct loc grid, int flag);
99 bool square_reveal_trap(struct chunk *c, struct loc grid, bool always,
100 						bool domsg);
101 void square_memorize_traps(struct chunk *c, struct loc grid);
102 bool trap_check_hit(int power);
103 void hit_trap(struct loc grid, int delayed);
104 bool square_player_trap_allowed(struct chunk *c, struct loc grid);
105 void place_trap(struct chunk *c, struct loc grid, int t_idx, int trap_level);
106 void square_free_trap(struct chunk *c, struct loc grid);
107 void wipe_trap_list(struct chunk *c);
108 bool square_remove_all_traps(struct chunk *c, struct loc grid);
109 bool square_remove_trap(struct chunk *c, struct loc grid, int t_idx);
110 bool square_set_trap_timeout(struct chunk *c, struct loc grid, bool domsg,
111 							 int t_idx, int time);
112 int square_trap_timeout(struct chunk *c, struct loc grid, int t_idx);
113 void square_set_door_lock(struct chunk *c, struct loc grid, int power);
114 int square_door_power(struct chunk *c, struct loc grid);
115 
116 #endif /* !TRAP_H */
117