1 /**
2  * \file monster.h
3  * \brief Flags, structures and variables for monsters
4  *
5  * Copyright (c) 2007 Andi Sidwell
6  * Copyright (c) 2010 Chris Carr
7  *
8  * This work is free software; you can redistribute it and/or modify it
9  * under the terms of either:
10  *
11  * a) the GNU General Public License as published by the Free Software
12  *    Foundation, version 2, or
13  *
14  * b) the "Angband licence":
15  *    This software may be copied and distributed for educational, research,
16  *    and not for profit purposes provided that this copyright and statement
17  *    are included in all such copies.  Other copyrights may also apply.
18  */
19 #ifndef MONSTER_MONSTER_H
20 #define MONSTER_MONSTER_H
21 
22 #include "h-basic.h"
23 #include "z-bitflag.h"
24 #include "z-rand.h"
25 #include "cave.h"
26 #include "target.h"
27 #include "mon-timed.h"
28 #include "mon-blows.h"
29 
30 /*** Monster flags ***/
31 
32 /**
33  * Special Monster Flags (all temporary)
34  */
35 enum
36 {
37 	#define MFLAG(a, b) MFLAG_##a,
38 	#include "list-mon-temp-flags.h"
39 	#undef MFLAG
40 	MFLAG_MAX
41 };
42 
43 
44 /**
45  * The monster flag types
46  */
47 enum monster_flag_type {
48 	RFT_NONE = 0,	/* placeholder flag */
49 	RFT_OBV,		/* an obvious property */
50 	RFT_DISP,		/* for display purposes */
51 	RFT_GEN,		/* related to generation */
52 	RFT_NOTE,		/* especially noteworthy for lore */
53 	RFT_BEHAV,		/* behaviour-related */
54 	RFT_DROP,		/* drop details */
55 	RFT_DET,		/* detection properties */
56 	RFT_ALTER,		/* environment shaping */
57 	RFT_RACE_N,		/* types of monster (noun) */
58 	RFT_RACE_A,		/* types of monster (adjective) */
59 	RFT_VULN,		/* vulnerabilities with no corresponding resistance */
60 	RFT_VULN_I,		/* vulnerabilities with a corresponding resistance */
61 	RFT_RES,		/* elemental resistances */
62 	RFT_PROT,		/* immunity from status effects */
63 
64 	RFT_MAX
65 };
66 
67 #define MFLAG_SIZE                FLAG_SIZE(MFLAG_MAX)
68 
69 #define mflag_has(f, flag)        flag_has_dbg(f, MFLAG_SIZE, flag, #f, #flag)
70 #define mflag_next(f, flag)       flag_next(f, MFLAG_SIZE, flag)
71 #define mflag_is_empty(f)         flag_is_empty(f, MFLAG_SIZE)
72 #define mflag_is_full(f)          flag_is_full(f, MFLAG_SIZE)
73 #define mflag_is_inter(f1, f2)    flag_is_inter(f1, f2, MFLAG_SIZE)
74 #define mflag_is_subset(f1, f2)   flag_is_subset(f1, f2, MFLAG_SIZE)
75 #define mflag_is_equal(f1, f2)    flag_is_equal(f1, f2, MFLAG_SIZE)
76 #define mflag_on(f, flag)         flag_on_dbg(f, MFLAG_SIZE, flag, #f, #flag)
77 #define mflag_off(f, flag)        flag_off(f, MFLAG_SIZE, flag)
78 #define mflag_wipe(f)             flag_wipe(f, MFLAG_SIZE)
79 #define mflag_setall(f)           flag_setall(f, MFLAG_SIZE)
80 #define mflag_negate(f)           flag_negate(f, MFLAG_SIZE)
81 #define mflag_copy(f1, f2)        flag_copy(f1, f2, MFLAG_SIZE)
82 #define mflag_union(f1, f2)       flag_union(f1, f2, MFLAG_SIZE)
83 #define mflag_inter(f1, f2)       flag_inter(f1, f2, MFLAG_SIZE)
84 #define mflag_diff(f1, f2)        flag_diff(f1, f2, MFLAG_SIZE)
85 
86 /**
87  * Monster property and ability flags (race flags)
88  */
89 enum
90 {
91 	#define RF(a, b, c) RF_##a,
92 	#include "list-mon-race-flags.h"
93 	#undef RF
94 	RF_MAX
95 };
96 
97 #define RF_SIZE                FLAG_SIZE(RF_MAX)
98 
99 #define rf_has(f, flag)        flag_has_dbg(f, RF_SIZE, flag, #f, #flag)
100 #define rf_next(f, flag)       flag_next(f, RF_SIZE, flag)
101 #define rf_count(f)            flag_count(f, RF_SIZE)
102 #define rf_is_empty(f)         flag_is_empty(f, RF_SIZE)
103 #define rf_is_full(f)          flag_is_full(f, RF_SIZE)
104 #define rf_is_inter(f1, f2)    flag_is_inter(f1, f2, RF_SIZE)
105 #define rf_is_subset(f1, f2)   flag_is_subset(f1, f2, RF_SIZE)
106 #define rf_is_equal(f1, f2)    flag_is_equal(f1, f2, RF_SIZE)
107 #define rf_on(f, flag)         flag_on_dbg(f, RF_SIZE, flag, #f, #flag)
108 #define rf_off(f, flag)        flag_off(f, RF_SIZE, flag)
109 #define rf_wipe(f)             flag_wipe(f, RF_SIZE)
110 #define rf_setall(f)           flag_setall(f, RF_SIZE)
111 #define rf_negate(f)           flag_negate(f, RF_SIZE)
112 #define rf_copy(f1, f2)        flag_copy(f1, f2, RF_SIZE)
113 #define rf_union(f1, f2)       flag_union(f1, f2, RF_SIZE)
114 #define rf_comp_union(f1, f2)  flag_comp_union(f1, f2, RF_SIZE)
115 #define rf_inter(f1, f2)       flag_inter(f1, f2, RF_SIZE)
116 #define rf_diff(f1, f2)        flag_diff(f1, f2, RF_SIZE)
117 
118 
119 /**
120  * Monster spell flag indices
121  */
122 enum
123 {
124     #define RSF(a, b) RSF_##a,
125     #include "list-mon-spells.h"
126     #undef RSF
127 };
128 
129 #define RSF_SIZE               FLAG_SIZE(RSF_MAX)
130 
131 
132 /** Structures **/
133 
134 /**
135  * The monster flag structure
136  */
137 struct monster_flag {
138 	u16b index;				/* the RF_ index */
139 	u16b type;				/* RFT_ category */
140 	const char *desc;		/* lore description */
141 };
142 
143 /**
144  * Monster blows
145  */
146 struct monster_blow {
147 	struct monster_blow *next;	/* Unused after parsing */
148 
149 	struct blow_method *method;	/* Method */
150 	struct blow_effect *effect;	/* Effect */
151 	random_value dice;			/* Damage dice */
152 	int times_seen;				/* Sightings of the blow (lore only) */
153 };
154 
155 /**
156  * Monster pain messages
157  */
158 struct monster_pain {
159 	const char *messages[7];
160 	int pain_idx;
161 
162 	struct monster_pain *next;
163 };
164 
165 
166 /**
167  * Monster spell levels
168  */
169 struct monster_spell_level {
170 	struct monster_spell_level *next;
171 
172 	int power;				/* Spell power at which this level starts */
173 	char *lore_desc;		/* Description of the attack used in lore text */
174 	byte lore_attr;			/* Color of the attack used in lore text */
175 	byte lore_attr_resist;	/* Color used in lore text when resisted */
176 	byte lore_attr_immune;	/* Color used in lore text when resisted strongly */
177 	char *message;			/* Description of the attack */
178 	char *blind_message;	/* Description of the attack if unseen */
179 	char *miss_message;		/* Description of a missed attack */
180 	char *save_message;		/* Message on passing saving throw, if any */
181 };
182 
183 /**
184  * Monster spell types
185  */
186 struct monster_spell {
187 	struct monster_spell *next;
188 
189 	u16b index;				/* Numerical index (RSF_FOO) */
190 	int msgt;				/* Flag for message colouring */
191 	int hit;				/* To-hit level for the attack */
192 	struct effect *effect;	/* Effect(s) of the spell */
193 	struct monster_spell_level *level;	/* Spell power dependent details */
194 };
195 
196 
197 /**
198  * Base monster type
199  */
200 struct monster_base {
201 	struct monster_base *next;
202 
203 	char *name;						/* Name for recognition in code */
204 	char *text;						/* In-game name */
205 
206 	bitflag flags[RF_SIZE];         /* Flags */
207 	bitflag spell_flags[RSF_SIZE];  /* Spell flags */
208 
209 	wchar_t d_char;					/* Default monster character */
210 
211 	struct monster_pain *pain;				/* Pain messages */
212 };
213 
214 
215 /**
216  * Specified monster drops
217  */
218 struct monster_drop {
219 	struct monster_drop *next;
220 	struct object_kind *kind;
221 	unsigned int tval;
222 	unsigned int percent_chance;
223 	unsigned int min;
224 	unsigned int max;
225 };
226 
227 enum monster_group_role {
228 	MON_GROUP_LEADER,
229 	MON_GROUP_SERVANT,
230 	MON_GROUP_BODYGUARD,
231 	MON_GROUP_MEMBER,
232 	MON_GROUP_SUMMON
233 };
234 
235 /**
236  * Monster friends (specific monster)
237  */
238 struct monster_friends {
239 	struct monster_friends *next;
240 	char *name;
241 	struct monster_race *race;
242 	enum monster_group_role role;
243 	unsigned int percent_chance;
244 	unsigned int number_dice;
245 	unsigned int number_side;
246 };
247 
248 /**
249  * Monster friends (general type)
250  */
251 struct monster_friends_base {
252 	struct monster_friends_base *next;
253 	struct monster_base *base;
254 	enum monster_group_role role;
255 	unsigned int percent_chance;
256 	unsigned int number_dice;
257 	unsigned int number_side;
258 };
259 
260 /**
261  * Monster group info
262  */
263 struct monster_group_info {
264 	int index;
265 	enum monster_group_role role;
266 };
267 
268 enum monster_group_type {
269 	PRIMARY_GROUP,
270 	SUMMON_GROUP,
271 	GROUP_MAX
272 };
273 
274 /**
275  * How monsters mimic
276  */
277 struct monster_mimic {
278 	struct monster_mimic *next;
279 	struct object_kind *kind;
280 };
281 
282 /**
283  * Different shapes a monster can take
284  */
285 struct monster_shape {
286 	struct monster_shape *next;
287 	char *name;
288 	struct monster_race *race;
289 	struct monster_base *base;
290 };
291 
292 /**
293  * Monster "race" information, including racial memories
294  *
295  * Note that "d_attr" and "d_char" are used for MORE than "visual" stuff.
296  *
297  * Note that "cur_num" (and "max_num") represent the number of monsters
298  * of the given race currently on (and allowed on) the current level.
299  * This information yields the "dead" flag for Unique monsters.
300  *
301  * Note that "max_num" is reset when a new player is created.
302  * Note that "cur_num" is reset when a new level is created.
303  *
304  * Maybe "cur_num", and "max_num" should be moved out of this array since
305  * they are not read from "monster.txt".
306  */
307 struct monster_race {
308 	struct monster_race *next;
309 
310 	unsigned int ridx;
311 
312 	char *name;
313 	char *text;
314 	char *plural;			/* Optional pluralized name */
315 
316 	struct monster_base *base;
317 
318 	int avg_hp;				/* Average HP for this creature */
319 
320 	int ac;					/* Armour Class */
321 
322 	int sleep;				/* Inactive counter (base) */
323 	int hearing;			/* Monster sense of hearing (1-100, standard 20) */
324 	int smell;				/* Monster sense of smell (0-50, standard 20) */
325 	int speed;				/* Speed (normally 110) */
326 	int light;				/* Light intensity */
327 
328 	int mexp;				/* Exp value for kill */
329 
330 	int freq_innate;		/* Innate spell frequency */
331 	int freq_spell;			/* Other spell frequency */
332 	int spell_power;		/* Power of spells */
333 
334 	bitflag flags[RF_SIZE];         /* Flags */
335 	bitflag spell_flags[RSF_SIZE];  /* Spell flags */
336 
337 	struct monster_blow *blow; /* Melee blows */
338 
339 	int level;				/* Level of creature */
340 	int rarity;				/* Rarity of creature */
341 
342 	byte d_attr;			/* Default monster attribute */
343 	wchar_t d_char;			/* Default monster character */
344 
345 	byte max_num;			/* Maximum population allowed per level */
346 	int cur_num;			/* Monster population on current level */
347 
348 	struct monster_drop *drops;
349 
350     struct monster_friends *friends;
351 
352     struct monster_friends_base *friends_base;
353 
354 	struct monster_mimic *mimic_kinds;
355 
356 	struct monster_shape *shapes;
357 	int num_shapes;
358 };
359 
360 
361 /**
362  * Monster information, for a specific monster.
363  *
364  * Note: fy, fx constrain dungeon size to 256x256
365  *
366  * The "held_obj" field points to the first object of a stack
367  * of objects (if any) being carried by the monster (see above).
368  */
369 struct monster {
370 	struct monster_race *race;			/* Monster's (current) race */
371 	struct monster_race *original_race;	/* Changed monster's original race */
372 	int midx;
373 
374 	struct loc grid;					/* Location on map */
375 
376 	s16b hp;							/* Current Hit points */
377 	s16b maxhp;							/* Max Hit points */
378 
379 	s16b m_timed[MON_TMD_MAX];			/* Timed monster status effects */
380 
381 	byte mspeed;						/* Monster "speed" */
382 	byte energy;						/* Monster "energy" */
383 
384 	byte cdis;							/* Current dis from player */
385 
386 	bitflag mflag[MFLAG_SIZE];			/* Temporary monster flags */
387 
388 	struct object *mimicked_obj;		/* Object this monster is mimicking */
389 	struct object *held_obj;			/* Object being held (if any) */
390 
391 	byte attr;  						/* attr last used for drawing monster */
392 
393 	struct player_state known_pstate;	/* Known player state */
394 
395     struct target target;				/* Monster target */
396 
397 	struct monster_group_info group_info[GROUP_MAX];/* Monster group details */
398 	struct heatmap heatmap;				/* Monster location heatmap */
399 
400     byte min_range;						/* What is the closest we want to be? */
401     byte best_range;					/* How close do we want to be? */
402 };
403 
404 /** Variables **/
405 
406 extern struct monster_pain *pain_messages;
407 extern struct monster_spell *monster_spells;
408 extern struct monster_base *rb_info;
409 extern struct monster_race *r_info;
410 extern const struct monster_race *ref_race;
411 
412 #endif /* !MONSTER_MONSTER_H */
413