1 /*
2  * traps.h
3  * Copyright (C) 2009-2011, 2012 Joachim de Groot <jdegroot@web.de>
4  *
5  * NLarn is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * NLarn is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __TRAPS_H_
20 #define __TRAPS_H_
21 
22 #include "monsters.h"
23 
24 typedef enum trap_types
25 {
26     TT_NONE,
27     TT_ARROW,
28     TT_DART,
29     TT_TELEPORT,
30     TT_PIT,
31     TT_SPIKEDPIT,
32     TT_SLEEPGAS,
33     TT_MANADRAIN,
34     TT_TRAPDOOR,
35     TT_MAX
36 } trap_t;
37 
38 typedef struct trap_data
39 {
40     trap_t type;             /* trap type */
41     int effect_t;            /* effect caused by this trap */
42     int color;               /* glyph color */
43     int chance;              /* chance this trap triggers */
44     int effect_chance;       /* chance the effect is activated */
45     int damage;              /* base damage */
46     const char *description; /* description of trap */
47     const char *p_message;   /* message given to player when triggered */
48     const char *e_message;   /* message shown when trap effect is activated */
49     const char *m_message;   /* message displayed when a monster triggered the trap */
50 } trap_data;
51 
52 extern const trap_data traps[TT_MAX];
53 
54 /* forward declarations */
55 struct player;
56 
57 
58 /* functions */
59 /**
60  * Player stepped on a trap
61  *
62  * @param the player
63  * @param the trap
64  * @return number of turns this move took
65  */
66 int player_trap_trigger(struct player *p, trap_t trap, int force);
67 
68 /**
69  * A monster stepped on a trap.
70  *
71  * @param The monster.
72  * @return the monster, or NULL if the monster died.
73  */
74 monster *monster_trap_trigger(monster *m);
75 
76 /**
77   * @brief Disarm a trap.
78   *
79   * @params The player.
80   * @return The number of turns elapsed.
81   */
82 guint trap_disarm(struct player *p);
83 
84 /* macros */
85 #define trap_effect(trap) (traps[(trap)].effect_t)
86 #define trap_colour(trap) (traps[(trap)].color)
87 #define trap_chance(trap) (traps[(trap)].chance)
88 #define trap_effect_chance(trap) (traps[(trap)].effect_chance)
89 #define trap_damage(trap) (traps[(trap)].damage)
90 #define trap_description(trap) (traps[(trap)].description)
91 #define trap_p_message(trap) (traps[(trap)].p_message)
92 #define trap_e_message(trap) (traps[(trap)].e_message)
93 #define trap_m_message(trap) (traps[(trap)].m_message)
94 
95 #endif
96