1 /**
2  * \file game-event.h
3  * \brief Allows the registering of handlers to be told about game events.
4  *
5  * Copyright (c) 2007 Antony Sidwell
6  *
7  * This work is free software; you can redistribute it and/or modify it
8  * under the terms of either:
9  *
10  * a) the GNU General Public License as published by the Free Software
11  *    Foundation, version 2, or
12  *
13  * b) the "Angband licence":
14  *    This software may be copied and distributed for educational, research,
15  *    and not for profit purposes provided that this copyright and statement
16  *    are included in all such copies.  Other copyrights may also apply.
17  */
18 
19 #ifndef INCLUDED_GAME_EVENT_H
20 #define INCLUDED_GAME_EVENT_H
21 
22 #include "z-type.h"
23 
24 /**
25  * The various events we can send signals about.
26  */
27 typedef enum game_event_type
28 {
29 	EVENT_MAP = 0,		/* Some part of the map has changed. */
30 
31 	EVENT_STATS,  		/* One or more of the stats. */
32 	EVENT_HP,	   	/* HP or MaxHP. */
33 	EVENT_MANA,		/* Mana or MaxMana. */
34 	EVENT_AC,		/* Armour Class. */
35 	EVENT_EXPERIENCE,	/* Experience or MaxExperience. */
36 	EVENT_PLAYERLEVEL,	/* Player's level has changed */
37 	EVENT_PLAYERTITLE,	/* Player's title has changed */
38 	EVENT_GOLD,		/* Player's gold amount. */
39 	EVENT_MONSTERHEALTH,	/* Observed monster's health level. */
40 	EVENT_DUNGEONLEVEL,	/* Dungeon depth */
41 	EVENT_PLAYERSPEED,	/* Player's speed */
42 	EVENT_RACE_CLASS,	/* Race or Class */
43 	EVENT_STUDYSTATUS,	/* "Study" availability */
44 	EVENT_STATUS,		/* Status */
45 	EVENT_DETECTIONSTATUS,  /* Trap detection status */
46 	EVENT_FEELING,		/* Object level feeling */
47 	EVENT_LIGHT,		/* Light level */
48 	EVENT_STATE,		/* The two 'R's: Resting and Repeating */
49 
50 	EVENT_PLAYERMOVED,
51 	EVENT_SEEFLOOR,         /* When the player would "see" floor objects */
52 	EVENT_EXPLOSION,
53 	EVENT_BOLT,
54 	EVENT_MISSILE,
55 
56 	EVENT_INVENTORY,
57 	EVENT_EQUIPMENT,
58 	EVENT_ITEMLIST,
59 	EVENT_MONSTERLIST,
60 	EVENT_MONSTERTARGET,
61 	EVENT_OBJECTTARGET,
62 	EVENT_MESSAGE,
63 	EVENT_SOUND,
64 	EVENT_BELL,
65 	EVENT_USE_STORE,
66 	EVENT_STORECHANGED,	/* Triggered on a successful buy/retrieve or sell/drop */
67 
68 	EVENT_INPUT_FLUSH,
69 	EVENT_MESSAGE_FLUSH,
70 	EVENT_CHECK_INTERRUPT,
71 	EVENT_REFRESH,
72 	EVENT_NEW_LEVEL_DISPLAY,
73 	EVENT_COMMAND_REPEAT,
74 	EVENT_ANIMATE,
75 	EVENT_CHEAT_DEATH,
76 
77 	EVENT_INITSTATUS,	/* New status message for initialisation */
78 	EVENT_BIRTHPOINTS,	/* Change in the birth points */
79 
80 	/* Changing of the game state/context. */
81 	EVENT_ENTER_INIT,
82 	EVENT_LEAVE_INIT,
83 	EVENT_ENTER_BIRTH,
84 	EVENT_LEAVE_BIRTH,
85 	EVENT_ENTER_GAME,
86 	EVENT_LEAVE_GAME,
87 	EVENT_ENTER_WORLD,
88 	EVENT_LEAVE_WORLD,
89 	EVENT_ENTER_STORE,
90 	EVENT_LEAVE_STORE,
91 	EVENT_ENTER_DEATH,
92 	EVENT_LEAVE_DEATH,
93 
94 	EVENT_END  /* Can be sent at the end of a series of events */
95 } game_event_type;
96 
97 #define  N_GAME_EVENTS EVENT_END + 1
98 
99 typedef union
100 {
101 	struct loc point;
102 
103 	const char *string;
104 
105 	bool flag;
106 
107 	struct {
108 		const char *msg;
109 		int type;
110 	} message;
111 
112 	struct
113 	{
114 		bool reset;
115 		const char *hint;
116 		int n_choices;
117 		int initial_choice;
118 		const char **choices;
119 		const char **helptexts;
120 		void *xtra;
121 	} birthstage;
122 
123   	struct
124 	{
125 		int *stats;
126 		int remaining;
127 	} birthstats;
128 
129 	struct
130 	{
131 		int proj_type;
132 		int num_grids;
133 		int *distance_to_grid;
134 		bool drawing;
135 		bool *player_sees_grid;
136 		struct loc *blast_grid;
137 		struct loc centre;
138 	} explosion;
139 
140 	struct
141 	{
142 		int proj_type;
143 		bool drawing;
144 		bool seen;
145 		bool beam;
146 		int oy;
147 		int ox;
148 		int y;
149 		int x;
150 	} bolt;
151 
152 	struct
153 	{
154 		struct object *obj;
155 		bool seen;
156 		int y;
157 		int x;
158 	} missile;
159 
160 } game_event_data;
161 
162 
163 /**
164  * A function called when a game event occurs - these are registered to be
165  * called by event_add_handler or event_add_handler_set, and deregistered
166  * when they should no longer be called through event_remove_handler or
167  * event_remove_handler_set.
168  */
169 typedef void game_event_handler(game_event_type type, game_event_data *data, void *user);
170 
171 void event_add_handler(game_event_type type, game_event_handler *fn, void *user);
172 void event_remove_handler(game_event_type type, game_event_handler *fn, void *user);
173 void event_remove_handler_type(game_event_type type);
174 void event_remove_all_handlers(void);
175 void event_add_handler_set(game_event_type *type, size_t n_types, game_event_handler *fn, void *user);
176 void event_remove_handler_set(game_event_type *type, size_t n_types, game_event_handler *fn, void *user);
177 
178 void event_signal_birthpoints(int stats[6], int remaining);
179 
180 void event_signal_point(game_event_type, int x, int y);
181 void event_signal_string(game_event_type, const char *s);
182 void event_signal_message(game_event_type type, int t, const char *s);
183 void event_signal_flag(game_event_type type, bool flag);
184 void event_signal(game_event_type);
185 void event_signal_blast(game_event_type type,
186 						int proj_type,
187 						int num_grids,
188 						int *distance_to_grid,
189 						bool seen,
190 						bool *player_sees_grid,
191 						struct loc *blast_grid,
192 						struct loc centre);
193 void event_signal_bolt(game_event_type type,
194 					   int proj_type,
195 					   bool drawing,
196 					   bool seen,
197 					   bool beam,
198 					   int oy,
199 					   int ox,
200 					   int y,
201 					   int x);
202 void event_signal_missile(game_event_type type,
203 						  struct object *obj,
204 						  bool seen,
205 						  int y,
206 						  int x);
207 
208 #endif /* INCLUDED_GAME_EVENT_H */
209