1 /* This is the header file for quests.c, please look there for more information.
2    You may modify/use it freely as long as you give proper credit. - C. Blue
3 */
4 
5 #include "angband.h"
6 
7 /* Notes:
8 
9    Stage changes given as negative numbers will instead add a random value
10    of 0..ABS(stage) to current stage, allowing for random quest progression!
11    Eg: kill_stage == -3 -> next_stage = current_stage + randint(3).
12 
13    If a quest stage doesn't have any stage goals, nor any dialogue keywords
14    that can change the stage,
15    the quest will terminate after all automatic/timed actions of this stage
16    have been done and all eligible rewards have been handed out.
17    ++including: questor movement/teleport/revert-from-hostile and
18    timed and instant stage-change effects.
19 
20    Items retrieved will be marked as 'quest items' for easy check in case the
21    player also has to deliver them somewhere, whether they're the same items.
22    Quest items cannot stack with other items.
23 
24 
25    Data structure:
26    quest_info -> qi_questor -> qi_location
27               -> qi_stage   -> qi_goal              -> qi_kill
28                                                     -> qi_retrieve
29                                                     -> qi_deliver
30                             -> qi_reward
31                             -> qi_questitem         -> qi_location
32                             -> qi_feature
33                             -> qi_questor_morph
34                             -> qi_questor_hostility
35                             -> qi_questor_act
36                             -> qi_location (for dungeon adding)
37               -> qi_keyword
38               -> qi_kwreply
39 */
40 
41 
42 /* Sub-structure: Hold broad information about generating a specific spawn position randomly. */
43 typedef struct qi_location {
44 	/* spawn location info */
45 	byte s_location_type;				/* flags setting elibible starting location types (QI_SLOC_xxx) */
46 	u16b s_towns_array;				/* QI_SLOC_TOWN: flags setting eligible starting towns (QI_STOWN_xxx) */
47 	u32b s_terrains;				/* QI_SLOC_SURFACE: flags setting eligible starting terrains (RF8_WILD_xxx, RF8_WILD_TOO_MASK for all) */
48 	bool terrain_patch;				/* extend spawn location to nearby worldmap sectors if same terrain? */
49 	byte radius;					/* offset start_x, start_y loc randomly within a radius? */
50 
51 	/* exact spawn location info */
52 	struct worldpos start_wpos;			/* -1, -1 for random */
53 	s16b start_x, start_y;				/* -1, -1 for random */
54 
55 	/* dungeons eligible too? */
56 	byte s_dungeons;
57 	byte s_dungeon[MAX_D_IDX];			/* QI_SLOC_DUNGEON/TOWER: eligible starting dungeons/towers (idx 0 = all wilderness dungeons),
58 							   Ironman Deep Dive Challenge = 255 */
59 	/* or (for Wilderness dungeons): */
60 	u32b s_dungeon_must_flags1, s_dungeon_must_flags2, s_dungeon_must_flags3;	/*  (NI) eligible wilderness dungeon flags */
61 	u32b s_dungeon_mustnt_flags1, s_dungeon_mustnt_flags2, s_dungeon_mustnt_flags3;	/*  (NI) uneligible wilderness dungeon flags */
62 	bool s_dungeon_iddc;
63 	/* dungeon floor levels */
64 	byte dlevmin, dlevmax;				/* eligible dungeon level or world sector level (0 for any) */
65 
66 	/* specific map design? */
67 	cptr tpref;					/* filename of map to load, or empty for none */
68 	int tpref_x, tpref_y;				/* x, y offset for loading small map parts */
69 } qi_location;
70 
71 /* Sub-structure: Mandatory questor information.
72    Quests usually need at least one questor to be acquirable by interacting with it.
73    An exception are quests that are automatically spawned by other quests and auto-acquired. */
74 typedef struct qi_questor {
75 	/*-----  Fixed questor spawn information (from q_info.txt) ----- */
76 
77 	/* quest initialisation and meta actions */
78 	bool accept_los, accept_interact;		/* player gets the quest just be being in LoS / interacting once with the questor (bump/read the parchment/pickup the item) */
79 
80 	bool static_floor;				/* questor floor will be static while the quest is active */
81 	bool quit_floor;				/* if player leaves the questor's floor, the quest will terminate and be lost */
82 
83 	qi_location q_loc;				/* spawn location parameters */
84 
85 	/* type of questor */
86 	byte type;					/* QI_QUESTOR_xxx */
87 
88 	/* QI_QUESTOR_NPC */
89 	s16b ridx;
90 	char rchar;
91 	byte rattr;
92 	byte rlevmin, rlevmax;
93 
94 	/* QI_QUESTOR_PARCHMENT */
95 	s16b psval, plev;
96 
97 	/* QI_QUESTOR_ITEM_xxx. */
98 	/* No further stats/enchantments are displayed maybe? */
99 	s16b otval, osval, opval, obpval, oname1, oname2, oname2b;
100 	bool ogood, ogreat, overygreat;
101 	s16b olev;
102 	byte oattr;
103 
104 	char name[MAX_CHARS];				/* optional pseudo-unique name that overrides the normal name */
105 
106 	bool talkable;					/* questor initially starts accepting dialogue? (by bumping usually) */
107 	bool despawned;					/* questor initially starts despawned? */
108 	bool invincible;				/* questor initially starts invincible (if monster)/unpickable by monsters (if item) on spawn? */
109 	s16b death_fail;				/* If the questor dies, the quest goes to stage n? (->reset old stage goals/positions as if we just entered it, if that is possible? hm)
110 							   -1 = quest fails completely, 255 = questor death has no effect. */
111 
112 	/* ..if killable ie not invincible: */
113 	byte drops;					/* 0=none, 1=Drops regular loot (of his ridx type) instead of nothing?, 2=specific, 3=1+2 */
114 	s16b drops_tval;				/* hand over certain rewards to the player */
115 	s16b drops_sval;
116 	s16b drops_pval, drops_bpval;
117 	s16b drops_name1, drops_name2, drops_name2b;
118 	bool drops_good, drops_great, drops_vgreat;
119 	byte drops_reward;				/*  use fitting-reward algo (from highlander etc)? - 0..5 */
120 	int drops_gold;
121 	int exp;
122 
123 	/* ----- Dynamic questor information ----- */
124 
125 	/* keep track of actual resulting questor location --
126 	   this data gets generated dynamically on quest activation from q_loc */
127 	struct worldpos current_wpos;
128 	s16b current_x, current_y;
129 
130 	s16b mo_idx; /* union of m_idx and o_idx :-p */
131 
132 	s16b talk_focus;				/* questor is focussed on this player and won't give others a chance to reply with keywords (non-individual quests only) */
133 
134 	bool tainted;					/* For individual quests: Something happened that requires the questor to
135 							   get despawned and respawned after the quest has been completed, because
136 							   some game aspects changed so much  (eg questor teleported to a different
137 							   wpos during some quest stage)that it's not feasible towards other
138 							   players who are pursuing the quest too. */
139 } qi_questor;
140 
141 /* Sub-structure: Questor changes (or turns vulnerable) ('S') */
142 typedef struct qi_questor_morph {
143 	/* special questor behaviour during each stage */
144 	bool talkable;					/* questor accepts dialogue? (by bumping usually) */
145 	bool despawned;					/* questor vanishes during a quest stage? */
146 
147 	bool invincible;				/* Is the questor invincible (if monster)/unpickable by monsters (if item) during a particular stage? */
148 	s16b death_fail;				/* If the questor dies, the quest goes to stage n? (->reset old stage goals/positions as if we just entered it, if that is possible? hm)
149 							   -1 = quest fails completely, 255 = no effect */
150 	cptr name;					/* questor changes optional pseudo-unique name during this stage? */
151 	s16b ridx; 					/* questor changes to this base monster type */
152 	char rchar;
153 	byte rattr;
154 	byte rlev;
155 } qi_questor_morph;
156 
157 /* Sub-structure: Questor moves himself or the player ('S'/'H') */
158 typedef struct qi_questor_hostility {
159 	bool unquestor;					/* questor actually loses questor status and turns into a regular mob!
160 							   NOTE: This will override all hostile_... options below.
161 							         Stage change may still happen, it'll be instantly. */
162 
163 	bool hostile_player;				/* questor turns into a normal aggressor, and optionally, stage is changed when he is defeated or after a time */
164 	bool hostile_monster;				/* questor turns hostile to monsters, and optionally, stage is changed when he is defeated or after a time */
165 
166 	s16b hostile_revert_hp;				/* aggressor-questor turns back into a non-aggressive questor when falling to <= HP (death prevented!) and stage is changed */
167 #if 0 /* currently not possible since we call the quest scheduler once a minute */
168 	s16b hostile_revert_timed_ingame;		/* ..after ingame time (min).. */
169 	s16b hostile_revert_timed_ingame_abs;		/* ..at ingame time.. */
170 #else
171 	s16b hostile_revert_timed_ingame_abs;		/* ..when a certain in-game time is reached (HOUR resolution! -1 to disable) */
172 #endif
173 	s16b hostile_revert_timed_real;			/* ..after real time (s).. */
174 
175 	s16b change_stage;				/* new stage after hostility has ceased (255 for none) */
176 	bool quiet_change;				/* for the above stage-change: don't replay the stage's dialogue */
177 
178 	/* dynamic timer helper data */
179 	s16b hostile_revert_timed_countdown;		/* countdown for above timings: negative value = ingame absolute, positive value = real-time counting down */
180 } qi_questor_hostility;
181 
182 /* Sub-structure: Questor moves himself or the player ('J') */
183 typedef struct qi_questor_act {
184 	struct worldpos tp_wpos;			/* teleport self to a new wpos position (wx -1 to disable) */
185 	s16b tp_x, tp_y;				/* teleport self to a new location (x -1 to disable) */
186 
187 	struct worldpos tppy_wpos;			/* teleport participating players to a new wpos position (wx -1 to disable) */
188 	s16b tppy_x, tppy_y;				/* ..and to new location (x -1 to disable) */
189 
190 	byte walk_speed;				/* questor will actually move around during this stage? (0 to disable) */
191 	s16b walk_destx, walk_desty;			/* target waypoint for questor to move to */
192 
193 	s16b change_stage;				/* stage will change when questor arrives at destination
194 							   NOTE: To change stage right after teleporting questor/players, use 'A' line instead! */
195 	bool quiet_change;				/* for the above stage-change: don't replay the stage's dialogue */
196 } qi_questor_act;
197 
198 /* Quest goals, with a multitude of different sub-goals. Some AND with each other, some OR.
199    There are three types of goals: Kill, Retrieve (obtain an object), Deliver (this is to
200    travel to a specific location after finishing all kill/retrieve goals, or just to travel
201    there if there are no kill/retrieve goals in this stage). */
202 
203 /* Sub-structure: A single kill goal */
204 typedef struct qi_kill {
205 #if 0 /* too much, make it simpler for now */
206 	bool player_picks;				/* instead of picking one of the eligible monster criteria randomly, let the player decide which he wants to get */
207 #endif
208 	s16b ridx[10];					/* kill certain monster(s), 0 for none, -1 for any. */
209 
210 	cptr name[5];					/* partial name that can match. AND's with char/attr/lev */
211 	char rchar[5];					/*  ..certain types, 126 for any, 127 for none. AND's with name/attr/lev. */
212 	byte rattr[5];					/*  ..certain colours, 254 for any, 255 for none. AND's with name/char/lev. */
213 	byte rlevmin, rlevmax;				/* 0 for any. AND's with char/attr. */
214 
215 	s16b number;
216 
217 	s16b number_left;	//dynamic data		/* keep track of how many are left to kill */
218 } qi_kill;
219 
220 /* Sub-structure: A single retrieval goal (main mem eater) */
221 typedef struct qi_retrieve {
222 #if 0 /* too much, make it simpler for now */
223 	bool player_picks;				/* instead of picking one subgoal randomly, let the player decide which he wants to get */
224 #endif
225 	bool allow_owned;				/* give credit for items that are already owned when player picks them up? (default: no) */
226 
227 	cptr name[5];					/* partial name that can match */
228 	s16b otval[10], osval[10];			/* retrieve certain item(s) (tval or sval == -1 -> any tval or sval, 0 = not checked) */
229 	s16b opval[5], obpval[5];			/* umm, let's say 9999 = not checked :-p, -9999 = any */
230 	byte oattr[5];					/*  ..certain colours (flavoured items only), 255 = not checked, 254 = any */
231 	s16b oname1[5], oname2[5], oname2b[5];		/* -3 = not checked, -2 == any except zero, -1 = any */
232 	int ovalue;					/* minimum value of the item (0 to disab..wait) */
233 	s16b number;					/* amount of fitting items to retrieve */
234 } qi_retrieve;
235 
236 /* Sub-structure: A single deliver goal */
237 typedef struct qi_deliver {
238 	struct worldpos wpos;				/* (after optionally killing/retrieving/or whatever) MOVE TO this world pos */
239 	bool terrain_patch;				/* extend valid target location over all connected world sectors whose terrain is of the same type (eg big forest)
240 							   max radius is QI_TERRAIN_PATCH_RADIUS. */
241 	s16b pos_x, pos_y;				/* -"- ..MOVE TO specifically this position */
242 	byte radius;
243 
244 	byte return_to_questor;				/* do we need to return to a questor (bump) to get credit? */
245 
246 	cptr tpref;					/* filename of map to load, or empty for none */
247 	int tpref_x, tpref_y;				/* x, y offset for loading small map parts */
248 } qi_deliver;
249 
250 /* Sub-structure: A single quest goal (which can be kill/retrieve/deliver) */
251 typedef struct qi_goal {
252 	/* Type of goal - exactly one of them must be non-NULL */
253 	qi_kill *kill;
254 	qi_retrieve *retrieve;
255 	qi_deliver *deliver;
256 
257 	bool optional;					/* has no effect on stage completion */
258 
259 	bool cleared;		//dynamic data		/* goal has been fulfilled! */
260 	bool nisi;		//dynamic data		/* for goals set by kill/retrieve depending on deliver (for flag changes) */
261 
262 	/* 'Z' lines: goals set/clear flags */
263 	u16b setflags;
264 	u16b clearflags;
265 
266 	/* for kill/retrieve goals only (deliver goals have/need separate location info) */
267 	bool target_pos;				/* enable target pos? */
268 	struct worldpos target_wpos;			/* kill/retrieve specifically at this world pos */
269 	bool target_terrain_patch;			/* extend valid target location over all connected world sectors whose terrain is of the same type (eg big forest)
270 							   max radius is QI_TERRAIN_PATCH_RADIUS. */
271 	s16b target_pos_x, target_pos_y;		/* at specifically this position (even usable for kill/retrieve stuff?) */
272 	byte target_pos_radius;
273 
274 	cptr target_tpref;				/* filename of map to load, or empty for none */
275 	int target_tpref_x, target_tpref_y;		/* x, y offset for loading small map parts */
276 } qi_goal;
277 
278 /* Sub-structure: A single quest reward.
279    It can actually be a combination of the three things 'item', 'gold' and 'exp' in one, if desired.
280    The fourth type 'statuseffect' requires special implementation. (Could be some sort of buff/curse.) */
281 typedef struct qi_reward {
282 	s16b otval;					/* hand over certain rewards to the player */
283 	s16b osval;
284 	s16b opval, obpval;
285 	s16b oname1, oname2, oname2b;
286 	bool ogood, ogreat, ovgreat;
287 	byte oreward;					/* use fitting-reward algo (from highlander etc)? - 0..5 */
288 
289 	int gold;
290 	int exp;
291 	s16b statuseffect;				/* debuff (aka curse, maybe just for show)/un-debuff/tempbuff player? */
292 } qi_reward;
293 
294 /* Sub-structure: A special quest item <TV_SPECIAL, SV_QUEST>.
295    that will be generated on a specific target location somewhere in the world.
296    Since the item is completely blank, all these values are mandatory to
297    specify. Note that its location info ('Bl' line) is actually the same as for
298    questors ('L' line).
299    Its pval has no effect, except for allowing us to distinguish between
300    multiple quest items in retrieval quest goals. */
301 typedef struct qi_questitem {
302 	s16b opval;					/* only used to distinguish between them (by retrieve-goals) */
303 	char ochar;
304 	byte oattr;
305 	s16b oweight;
306 	byte olev;
307 	char name[MAX_CHARS]; //could use ONAME_LEN
308 
309 	byte questor_gives;				/* Do not spawn it anywhere but just hand it over on interaction with this questor */
310 
311 	qi_location q_loc;				/* spawn location parameters */
312 
313 	/* ----- Dynamic data ----- */
314 
315 	/* keep track of actual resulting quest item spawn location --
316 	   this data gets generated dynamically on quest item generation from q_loc */
317 	struct worldpos result_wpos;
318 	s16b result_x, result_y;
319 } qi_questitem;
320 
321 /* Sub-structure: A single grid feature that is imprinted ('built') onto the
322    map at a specific wpos (either directly specified or derived from a questor)
323    and a specific x,y loc, automatically on stage startup. */
324 typedef struct qi_feature {
325 	byte wpos_questor;				/* use the current wpos of one of our questors? (overrides) */
326 	byte wpos_questitem;				/* use the wpos of one of our quest items from this stage? (overrides) */
327 	struct worldpos wpos;				/* use a specific wpos */
328 
329 	s16b x, y;					/* the cave pos to change */
330 
331 	byte feat;					/* the f_info.txt feat to build */
332 } qi_feature;
333 
334 typedef struct qi_monsterspawn {
335 	s16b ridx;					/* exact ridx, ORs with block of partial criteria below */
336 
337 	cptr name;					/* partial name that can match. AND's with char/attr/lev */
338 	char rchar;
339 	byte rattr;
340 	byte rlevmin, rlevmax;
341 
342 	byte amount;					/* spawns a single monster this many times */
343 	bool groups;					/* spawns a pack of monsters instead of single monsters */
344 	bool scatter;					/* scatters the single spawns/group spawns around the map */
345 	byte clones;					/* s_clone factor (0 = normal) */
346 
347 	qi_location loc;				/* spawn location parameters */
348 
349 	bool hostile_player, hostile_questor;		/* will they attack players or questors? */
350 	bool invincible_player, invincible_questor;	/* can they be hurt by players or questors? */
351 	bool target_player, target_questor;		/* will they specifically target (move towards) players (normal behaviour) or questors? */
352 } qi_monsterspawn;
353 
354 /* Sub-structure: A single quest stage.
355    The central unit of a quest, providing goals, rewards and dialogue.
356    A quest consists of a series of stages that switch between each other
357    depending on the player fulfilling their goals or reacting to their
358    dialogue, until an ending stage is reached and the quest terminates. */
359 typedef struct qi_stage {
360 	/* quest acceptance */
361 	bool accepts;					/* player can acquire the quest during a stage */
362 
363 
364 	/* stage-change automatics */
365 	s16b activate_quest;				/* spawn a certain new quest of this index (and thereby another questor) (if not already existing) -1 for disabled */
366 	bool auto_accept;				/* player will automatically acquire the newly spawned quest (from activate_quest[]) */
367 	bool auto_accept_quiet;				/* player will automatically acquire the newly spawned quest (from activate_quest[]) but not get a quest-accept-notification type of message about it */
368 
369 	s16b change_stage;				/* automatically change to a different stage after handling everything that was to do in the current stage (-1 = disable) */
370 #if 0 /* currently not possible since we call the quest scheduler once a minute */
371 	s16b timed_ingame;				/* automatically change to a different stage after a certain amount of in-game minutes passed */
372 	s16b timed_ingame_abs;				/* automatically change to a different stage when a certain in-game time is reached (minute resolution) */
373 #else
374 	s16b timed_ingame_abs;				/* automatically change to a different stage when a certain in-game time is reached (HOUR resolution! -1 to disable) */
375 #endif
376 	s16b timed_real;				/* automatically change to a different stage after a certain amount of real minutes passed */
377 	bool quiet_change;				/* for the above auto-changes: don't replay the stage's dialogue */
378 
379 	/* dynamic timer helper data --
380 	    NOTE: we don't have that here, but instead use a helper var in quest_info for this! */
381 
382 	u16b setflags;					/* these flags will automatically be set on stage start */
383 	u16b clearflags;				/* these flags will automatically be cleared on stage start */
384 
385 	/* cave grid features to be built automatically on stage start */
386 	byte feats;
387 	qi_feature *feat;
388 
389 	/* monsters to be spawned automatically on stage start */
390 	byte mspawns;
391 	qi_monsterspawn *mspawn;
392 
393 	struct worldpos geno_wpos;
394 
395 
396 	/* create a dungeon/tower for a quest stage? completely static? predefined layouts? */
397 	byte dun_base, dun_max;
398 	bool dun_tower;
399 	byte dun_hard;					/* (0=normal,1=forcedown:2=iron) */
400 	byte dun_stores;				/* (0=none,1=iron stores,2=all stores) */
401 	byte dun_theme;					/* similar to IDDC theming */
402 	cptr dun_name;					/* custom name */
403 	bool dun_static;				/* all floors are static */
404 	bool dun_keep;					/* keep dungeon until quest ends instead of erasing it when this stage is completed */
405 	cptr dun_final_tpref;				/* template map file to load on the final floor */
406 	s16b dun_final_tpref_x, dun_final_tpref_y;
407 	u32b dun_flags1, dun_flags2, dun_flags3;
408 	qi_location dun_loc;				/* wpos/x,y location for dungeon and its entrance */
409 	/* ----- Dynamic stage information ----- */
410 	/* keep track of actual resulting dungeon location --
411 	   this data gets generated dynamically on stage activation from dun_loc */
412 	struct worldpos dun_wpos;//dynamic data
413 	s16b dun_x, dun_y;	//dynamic data
414 
415 
416 	/* Questor going bonkers? (optional/advanced) */
417 	qi_questor_morph *questor_morph[QI_QUESTORS];
418 	qi_questor_hostility *questor_hostility[QI_QUESTORS];
419 	qi_questor_act *questor_act[QI_QUESTORS];
420 
421 
422 	/* quest dialogues and responses/consequences (stage 0 means player loses the quest again) */
423 	//NOTE: '$RPM' in dialogue will be substituted by xxx_random_pick'ed monster criteria
424 	//NOTE: '$OPM' in dialogue will be substituted by xxx_random_pick'ed object criteria
425 	byte talk_examine[QI_QUESTORS];			/* questor doesn't "talk" but rather the text claims that "you are examining <questor>" (for item questors or "dead" questors) --
426 							   hack: using byte instead of bool to add additional info: stage "> 1" for 'reuse previous stage' dialogue" */
427 	byte talk_lines[QI_QUESTORS];
428 	cptr *talk[QI_QUESTORS];			/* n conversations a 10 lines a 79 characters */
429 	u16b *talk_flags[QI_QUESTORS];			/* required flags configuration for a convo line to get displayed  */
430 
431 	cptr default_reply[QI_QUESTORS];		/* default reply line, optional, replaces the 'has nothing to say about that' standard answer for unrecognised keywords */
432 
433 	byte narration_lines;
434 	cptr narration[QI_TALK_LINES];			/* display a quest-progress narration when this stage starts, a 10 lines a 79 characters, aka "You have arrived at the lake!" */
435 	u16b narration_flags[QI_TALK_LINES];		/* required flags configuration to display this narrative line */
436 
437 
438 	/* the rewards for this stage, if any */
439 	byte rewards;					/* up to QI_STAGE_REWARDS */
440 	qi_reward *reward;
441 
442 	/* contains the indices of up to QI_REWARD_GOALS different QI_GOALS goals which are AND'ed */
443 	s16b goals_for_reward[QI_STAGE_REWARDS][QI_REWARD_GOALS]; /* returns the goal's index (or -1 if none) */
444 
445 
446 	/* the goals for this stage */
447 	byte goals;					/* up to QI_STAGE_GOALS */
448 	qi_goal *goal;
449 
450 	/* determine if a new stage should begin depending on which goals we have completed */
451 	/* contains the indices of up to QI_STAGE_GOALS different QI_GOALS goals which are AND'ed; 'optional' goals are skipped in the check! */
452 	s16b goals_for_stage[QI_FOLLOWUP_STAGES][QI_STAGE_GOALS]; /* returns the goal's index (or -1 if none) */
453 	s16b next_stage_from_goals[QI_FOLLOWUP_STAGES];	/* <stage> index of the possible follow-up stages */
454 
455 	/* amout of special quest items to spawn */
456 	byte qitems;
457 	qi_questitem *qitem;
458 } qi_stage;
459 
460 /* Sub-structure: A single quest keyword.
461    A possible player response to a quest dialogue, which may cause
462    a change in quest stage. */
463 typedef struct qi_keyword {
464 	char keyword[QI_KEYWORD_LEN];			/* each convo may allow the player to reply with up to m keywords a 30 chars; 'Y' as 1st keyword and 'N' as 2nd trigger a yes/no hack */
465 	bool questor_ok[QI_QUESTORS];			/* this keyword is valid for which questor(s) ? */
466 	bool stage_ok[QI_STAGES], any_stage;		/* this keyword is valid during which stage(s) ? any_stage is an extra marker for quest_dialogue() */
467 	u16b flags;					/* required flags configuration for a keyword to be enabled */
468 
469 	u16b setflags;					/* ..and the keyword will change flags to these */
470 	u16b clearflags;				/* ..and the keyword will change flags to these */
471 
472 	s16b stage;					/* entering this keyword will bring the player to a different quest stage (or -1) */
473 } qi_keyword;
474 
475 /* Sub-structure: A single quest keyword-reply (main mem eater).
476    An automatic reply the player gets when he enters a certain keyword
477    (replies can be valid for multiple keywords each, actually). */
478 typedef struct qi_kwreply {
479 	byte keyword_idx[QI_KEYWORDS_PER_REPLY];	/* which keyword(s) will prompt this reply from the current questor? */
480 	bool questor_ok[QI_QUESTORS];			/* this keyword reply is valid for which questor(s) ? */
481 	bool stage_ok[QI_STAGES];			/* this keyword reply is valid during which stage(s) ? */
482 	u16b flags;					/* this keyword reply is only valid if the set flags match? */
483 
484 	byte lines;
485 	cptr reply[QI_TALK_LINES];			/* give a reply to the keyword (cptr table contains [QI_TALK_LINES])*/
486 	u16b replyflags[QI_TALK_LINES];			/* only print this particular text line if these flags are matching the quest flags */
487 } qi_kwreply;
488 
489 /* Main structure: The complete quest data.
490    Each quest contains info
491    -when/where to activate, scheduled repeatedly over the in-game day/night
492     cycle and what requirements players must meet to acquire it,
493    -how many questors (quest monsters/objects that the player can interact
494     with to acquire the quest or to proceed through quest stages) it has,
495    -how many quest stages it has for the player to beat,
496    -how many keywords the quest provides (possibly used by each of its stages)
497     and the automatic reply dialogue that each keyword results in. */
498 typedef struct quest_info {
499 	/* -------------------------------- MANDATORY GLOBAL QUEST DATA -------------------------------- */
500 
501 	/* ----- Dynamic quest state information ----- */
502 
503 	bool defined;					/* Quest has been loaded from q_info.txt and therefore exists. */
504 	bool active;					/* QUEST IS CURRENTLY ACTIVE (aka questor is currently spawned - \
505 							   depends on time (day/night/specific) constraints) */
506 	bool disabled; 					/* quest has been temporarily disabled, is hence deactivated and cannot \
507 							   be activated until enabled again (eg for when something breaks during quest progression) */
508 	bool disabled_on_load;				/* dynamic info for quests disabled via q_info */
509 
510 	s16b cur_cooldown;				/* in seconds, minimum respawn time for the questor. 0 for 24h default. */
511 	s32b turn_activated;				/* the turn when the quest became activated */
512 	s32b turn_acquired;				/* for global quests: the turn when it was acquired */
513 
514 	/* the current quest stage (-1 is the init stage, which progresses to 0
515 	   automatically, during which quests are usually acquired by players).
516 	   IT MUST NEVER BE -1 AFTER THE QUEST ACTIVATION HAS FINISHED or init_quest_stage() will do the segfault dance. */
517 	s16b cur_stage;					/* the current stage in the quest progress */
518 	bool dirty;					/* dirty flag, set whenever a stage completes ;) (including quest termination)
519 							   there is no need for players to have their local instances of this,
520 							   because it's used atomically in succeeding code parts that know they
521 							   can depend on each other. (uh or something) */
522 
523 	s16b objects_registered;			/* Track all objects the quest spawns except for quest items.
524 							   So this keeps track of object-type questors and of special quest items. */
525 
526 	/* global quest flags (a-p to clear, A-P to set) -- note that these are stage-independant! */
527 	u16b flags;
528 
529 	bool tainted;					/* For individual quests: Something happened that requires the quest to
530 							   get deactivated after it's been completed, because some game aspects
531 							   changed so much that it's not feasible towards other players who are
532 							   pursuing the quest too. They will have to wait until the quest gets
533 							   activated by the scheduler again. */
534 
535 
536 	/* ------ Dynymic helper vars from sub-structures,
537 		  that we store here instead for efficiency :-o */
538 	s16b timed_countdown;				/* countdown for auto-stage change: negative value = ingame absolute, positive value = real-time counting down */
539 	s16b timed_countdown_stage;			/* stage to activate */
540 	bool timed_countdown_quiet;			/* quiet stage-change? */
541 
542 	/* -----  Fixed quest data (from q_info.txt) ----- */
543 
544 //#define QI_CODENAME_LEN 10
545 	char codename[QI_CODENAME_LEN + 1];		/* short, unique, internal name for checking prerequisite quests for follow-up quests */
546 	char creator[NAME_LEN];				/* credits -- who thought up and created this quest :) */
547 	//char name[MAX_CHARS];				/* readable title of this quest */
548 	u16b name;					/* readable title of this quest - offset */
549 
550     /* QUESTOR (quest giver) RESTRICTIONS: */
551 	/* player restrictions */
552 	byte privilege;					/* quest can only be acquired by admins (for testing them etc) */
553 	byte minlev, maxlev;				/* eligible player level range (0 for any) */
554 	u32b races, classes;				/* eligible player classes/races (CFx/RFx flags) */
555 	bool mode_norm, mode_el, mode_pvp;		/* are these character modes eligible to join? (normal = normal/uw/hell) */
556 	byte must_be_fruitbat;				/* must be a true fruit bat? (OR's with body_monster!) */
557 	s16b must_be_monster;				/* must be polymorphed into this form? (OR's with body_fruitbat!) */
558 	char prerequisites[QI_PREREQUISITES][QI_CODENAME_LEN + 1]; /* prerequisite quests the player must have completed to acquire this quest */
559 
560 	/* eligible time for quest to become active and thereby spawn the questors */
561 	bool night, day;				/* Only available at night/day in general? */
562 	bool morning, forenoon, noon, afternoon, evening, midnight, deepnight; /*  Only available at very specific night/day times? */
563 	s16b time_start, time_stop;			/* Only available during very specific time interval? */
564 
565     /* QUEST DURATION */
566 	/* quest duration, after it was accepted, until it expires */
567 	byte individual;				/* quest isn't global, but stage/flags/goals are stored individually for each player,
568 							   allowing everyone to have his own personal 'instance' of the quest running simultaneusly.
569 							   For example questors may spawn other questors -> must be global, not individual.
570 							   0: global, 1: individual and sharing goals with party members, 2: solo-individual. */
571 	s16b repeatable;				/* player may repeat this quest n times (0 = can only do this quest once) */
572 	s16b cooldown;					/* in seconds, minimum respawn time for the quest. 0 for 24h default. */
573 	int max_duration;				/* in seconds, 0 for never */
574 	s16b ending_stage;				/* if this stage is reached, the quest will terminate */
575 	s16b quest_done_credit_stage;			/* minimum stage that will increase the quest_done counter of players who are pursuing the quest */
576 
577 	/* -------------------------------- (OPTIONAL) QUESTOR-SPECIFIC DATA -------------------------------- */
578 	/* Note that each 'normal' quest needs at least one questor,
579 	   for players being able to interact with to acquire the quest.
580 	   The exception are quests that are automatically acquired during a stage of another quest. */
581 
582 	/* ----- Fixed quest data (from q_info.txt) ----- */
583 
584 	/* questor restrictions (locations etc..): */
585 	byte questors;					/* how many questors were actually defined in q_info */
586 	qi_questor *questor;
587 
588 	/* -------------------------------- OPTIONAL SUB-STRUCTURED DATA -------------------------------- */
589 
590 	/* ----- Fixed quest data (from q_info.txt) ----- */
591 
592 	/* amount of different quest stages */
593 	byte stages;
594 	s16b stage_idx[QI_STAGES];			/* map a stage to a stage[]-index, for example there could be 3 stages in a quest: 0, 1 and 7 :-p */
595 	qi_stage *stage;
596 
597 	/* amount of different keywords for player-npc-dialogue */
598 	int keywords;
599 	qi_keyword *keyword;
600 	char password[QI_PASSWORDS][QI_PASSWORD_LEN + 1];/* for special keywords that are actually randomly generated passwords */
601 
602 	/* amount of different replies to keywords in player-npc-dialogue */
603 	int kwreplies;
604 	qi_kwreply *kwreply;
605 } quest_info;
606