summaryrefslogtreecommitdiff
path: root/src/help.c
blob: 73892ff73a4407365b76c4e4aaefbc0ea7c13206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/* File: help.c */

/* Purpose: ingame help */

/*
 * Copyright (c) 2001 DarkGod
 * Copyright (c) 2012 Bardur Arantsson
 *
 * This software may be copied and distributed for educational, research, and
 * not for profit purposes provided that this copyright and statement are
 * included in all such copies.
 */

#include "angband.h"

#define DESC_MAX 14
#define TRIGGERED_HELP_MAX 16

#define HELP_VOID_JUMPGATE 0
#define HELP_FOUNTAIN      1
#define HELP_FOUND_OBJECT  2
#define HELP_FOUND_ALTAR   3
#define HELP_FOUND_STAIR   4
#define HELP_GET_ESSENCE   5
#define HELP_GET_RUNE      6
#define HELP_GET_ROD       7
#define HELP_GET_ROD_TIP   8
#define HELP_GET_TRAP_KIT  9
#define HELP_GET_DEVICE   10
#define HELP_WILDERNESS   11
#define HELP_GAME_TOME    12
#define HELP_GAME_THEME   13
#define HELP_1ST_LEVEL    14
#define HELP_20TH_LEVEL   15

/**
 * Struct for help triggered by a boolean condition
 */
typedef struct triggered_help_type triggered_help_type;
struct triggered_help_type
{
	/* Help item index; see HELP_* constants above */
	int help_index;
	/* Hook type */
	int hook_type;
	/* Trigger function */
	bool_ (*trigger_func)(void *in, void *out);
	/* Description; NULL terminated */
	cptr desc[DESC_MAX];
};

/**
 * Trigger functions
 */
static bool_ trigger_void_jumpgate(void *in, void *out) {
	hook_move_in *p = (hook_move_in *) in;
	return cave[p->y][p->x].feat == FEAT_BETWEEN;
}

static bool_ trigger_fountain(void *in, void *out) {
	hook_move_in *p = (hook_move_in *) in;
	return cave[p->y][p->x].feat == FEAT_FOUNTAIN;
}

static bool_ trigger_found_object(void *in, void *out) {
	hook_move_in *p = (hook_move_in *) in;
	return cave[p->y][p->x].o_idx != 0;
}

static bool_ trigger_found_altar(void *in, void *out) {
	hook_move_in *p = (hook_move_in *) in;
	return ((cave[p->y][p->x].feat >= FEAT_ALTAR_HEAD) &&
		(cave[p->y][p->x].feat <= FEAT_ALTAR_TAIL));
}

static bool_ trigger_found_stairs(void *in, void *out) {
	hook_move_in *p = (hook_move_in *) in;
	return (cave[p->y][p->x].feat == FEAT_MORE);
}

static bool_ trigger_get_essence(void *in, void *out) {
	hook_get_in *g = (hook_get_in *) in;
	return (g->o_ptr->tval == TV_BATERIE);
}

static bool_ trigger_get_rune(void *in, void *out) {
	hook_get_in *g = (hook_get_in *) in;
	return ((g->o_ptr->tval == TV_RUNE1) ||
		(g->o_ptr->tval == TV_RUNE2));
}

static bool_ trigger_get_rod(void *in, void *out) {
	hook_get_in *g = (hook_get_in *) in;
	return (g->o_ptr->tval == TV_ROD_MAIN);
}

static bool_ trigger_get_rod_tip(void *in, void *out) {
	hook_get_in *g = (hook_get_in *) in;
	return (g->o_ptr->tval == TV_ROD);
}

static bool_ trigger_get_trap_kit(void *in, void *out) {
	hook_get_in *g = (hook_get_in *) in;
	return (g->o_ptr->tval == TV_TRAPKIT);
}

static bool_ trigger_get_magic_device(void *in, void *out) {
	hook_get_in *g = (hook_get_in *) in;
	return ((g->o_ptr->tval == TV_WAND) ||
		(g->o_ptr->tval == TV_STAFF));
}

static bool_ trigger_end_turn_wilderness(void *in, void *out) {
	return (((p_ptr->wilderness_x != 34) ||
		 (p_ptr->wilderness_y != 21)) &&
		(!p_ptr->astral));
}

static bool_ trigger_game_theme(void *in, void *out) {
	return (game_module_idx == MODULE_THEME);
}

static bool_ trigger_game_tome(void *in, void *out) {
	return (game_module_idx == MODULE_TOME);
}

static bool_ trigger_1st_level(void *in, void *out) {
	return (p_ptr->lev > 1);
}

static bool_ trigger_20th_level(void *in, void *out) {
	return (p_ptr->lev >= 20);
}

/**
 * Trigger-based help items
 */
static triggered_help_type triggered_help[TRIGGERED_HELP_MAX] =
{
	{ HELP_VOID_JUMPGATE,
	  HOOK_MOVE,
	  trigger_void_jumpgate,
	  { "Void Jumpgates can be entered by pressing the > key. They will transport",
	    "you to another jumpgate, but beware of the cold damage that might kill you.",
	    NULL }
	},
	{ HELP_FOUNTAIN,
	  HOOK_MOVE,
	  trigger_fountain,
	  { "Fountains are always magical. You can quaff from them by pressing H.",
	    "Beware that unlike potions they cannot be identified.",
	    NULL }
	},
	{ HELP_FOUND_OBJECT,
	  HOOK_MOVE,
	  trigger_found_object,
	  { "So you found your first item! Nice, eh? Now when you stumble across",
	    "objects, you can pick them up by pressing g, and if you are wondering",
	    "what they do, press I (then *, then the letter for the item) to get",
	    "some basic information. You may also want to identify them with scrolls,",
	    "staves, rods or spells.",
	    NULL }
	},
	{ HELP_FOUND_ALTAR,
	  HOOK_MOVE,
	  trigger_found_altar,
	  { "Altars are the way to reach the Valar, powers of the world,",
	    "usualy called Gods. You can press O to become a follower.",
	    "Beware that once you follow a god, you are not allowed to change.",
	    "For an exact description of what gods do and want, read the documentation.",
	    NULL }
	},
	{ HELP_FOUND_STAIR,
	  HOOK_MOVE,
	  trigger_found_stairs,
	  { "Ah, this is a stair, or a way into something. Press > to enter it.",
	    "But be ready to fight what lies within, for it might not be too friendly.",
	    NULL }
	},
	{ HELP_GET_ESSENCE,
	  HOOK_GET,
	  trigger_get_essence,
	  { "Ah, an essence! Those magical containers stores energies. They are used",
	    "with the Alchemy skill to create or modify the powers of items.",
	    NULL }
	},
	{ HELP_GET_RUNE,
	  HOOK_GET,
	  trigger_get_rune,
	  { "Ah, a rune! Runes are used with the Runecraft skill to allow you to",
	    "create spells on your own.",
	    NULL
	  }
	},
	{ HELP_GET_ROD,
	  HOOK_GET,
	  trigger_get_rod,
	  { "This is a rod. You will need to attach a rod tip to it before you",
	    "can use it. This main part of the rod may give the rod bonuses",
	    "like quicker charging time, or a larger capacity for charges.",
	    NULL
	  }
	},
	{ HELP_GET_ROD_TIP,
	  HOOK_GET,
	  trigger_get_rod_tip,
	  { "You've found a rod-tip! You will need to attach it to a rod base",
	    "before you can use it. Once it has been attatched (use the 'z' key)",
	    "you cannot unattach it! The rod tip will determine the effect of",
	    "the rod. To use your rod, 'z'ap it once it has been assembled.",
	    NULL
	  }
	},
	{ HELP_GET_TRAP_KIT,
	  HOOK_GET,
	  trigger_get_trap_kit,
	  { "Ooooh, a trapping kit. If you have ability in the trapping skill,",
	    "you can lay this trap (via the 'm' key) to harm unsuspecting foes.",
	    "You'll generally need either some ammo or magic device depending",
	    "on the exact type of trap kit.",
	    NULL
	  }
	},
	{ HELP_GET_DEVICE,
	  HOOK_GET,
	  trigger_get_magic_device,
	  { "You've found a magical device, either a staff or a wand. Each staff",
	    "contains a spell, often from one of the primary magic schools. There",
	    "is a lot of information you can find about this object if you identify",
	    "it and 'I'nspect it. Check the help file on Magic for more about these.",
	    NULL
	  }
	},
	{ HELP_WILDERNESS,
	  HOOK_END_TURN,
	  trigger_end_turn_wilderness,
	  { "Ahh wilderness travel... The overview mode will allow you to travel",
	    "fast, but that comes to the cost of GREATLY increased food consumption.",
	    "So you should bring lots of food and really watch your hunger status.",
	    "To enter the overview mode, press < while in the wilderness.",
	    NULL
	  }
	},
	{ HELP_GAME_TOME,
	  HOOK_END_TURN,
	  trigger_game_tome,
	  { "Welcome to ToME! I am the spirit of knowledge and my task is to help you",
	    "to get used to how to play. I have prepared a #vparchment#y for you to #vread#y.",
	    "Press r, then space then select it. You can also check the documentation",
	    "by pressing ? at (nearly) any time.",
	    "The first place you can explore is Barrow-downs. Go to the west of town",
	    "and you should see a #v>#y there.",
	    "If you miss any of this you can press ctrl+p to see your message log.",
	    "Now I must reveal your task here. You are on a quest to investigate",
	    "the dreadful tower of Dol Guldur in the Mirkwood forest to see what evil",
	    "lurks there, but beware, you are not yet ready.",
	    "If you do not want me to bother you any more with tips, press = then go",
	    "into the ToME options and deactivate the ingame_help option.",
	    "You can see your quest log by pressing ctrl+q. Now go to your destiny!",
	    NULL
	  }
	},
	{ HELP_GAME_THEME,
	  HOOK_END_TURN,
	  trigger_game_theme,
	  { "Welcome to Theme! I am the spirit of knowledge and my task is to help you",
	    "to get used to how to play. I have prepared a #vparchment#y for you to #vread#y.",
	    "Press r, then space then select it. You can also check the documentation",
	    "by pressing ? at (nearly) any time.",
	    "The first place you can explore is Barrow-downs. Go to the west of town",
	    "and you should see a #v>#y there.",
	    "If you miss any of this you can press ctrl+p to see your message log.",
	    "Now I must reveal your task here. You are on a quest to investigate",
	    "the dreadful tower of Dol Guldur in the Mirkwood forest to see what evil",
	    "lurks there, but beware, you are not yet ready.",
	    "If you do not want me to bother you any more with tips, press = then go",
	    "into the ToME options and deactivate the ingame_help option.",
	    "You can see your quest log by pressing ctrl+q. Now go to your destiny!",
	    NULL
	  }
	},
	{ HELP_1ST_LEVEL,
	  HOOK_PLAYER_LEVEL,
	  trigger_1st_level,
	  { "Ok, so you now gained a level, and you have skill points to spend.",
	    "To do so simply press G to learn skills. Reading the documentation",
	    "about skills and abilities is also strongly recommended.",
	    NULL
	  }
	},
	{ HELP_20TH_LEVEL,
	  HOOK_PLAYER_LEVEL,
	  trigger_20th_level,
	  { "I see you are now at least level 20. Nice! If you want to gloat about your",
	    "character you could press 'C' then 'f' to make a character dump and post it to",
	    "http://angband.oook.cz/ where it will end up in the ladder.",
	    NULL
	  }
	}
};

static bool_ triggered_help_hook(void *data, void *in, void *out)
{
	triggered_help_type *triggered_help = (triggered_help_type *) data;
	/* Not triggered before and trigger now? */
	if ((option_ingame_help) &&
	    (!p_ptr->help.activated[triggered_help->help_index]) &&
	    triggered_help->trigger_func(in,out))
	{
		int i;

		/* Triggered */
		p_ptr->help.activated[triggered_help->help_index] = TRUE;

		/* Show the description */
		for (i = 0; (i < DESC_MAX) && (triggered_help->desc[i] != NULL); i++)
		{
			cmsg_print(TERM_YELLOW, triggered_help->desc[i]);
		}
	}
	/* Don't stop processing */
	return FALSE;
}

static void setup_triggered_help_hook(int i)
{
	static int counter = 0;
	char name[40];
	triggered_help_type *h = &triggered_help[i];

	/* Build name */
	sprintf(name, "help_trigger_%d", counter);
	counter++;

	/* Add the hook */
	add_hook_new(h->hook_type,
		     triggered_help_hook,
		     name,
		     h);
}

static void setup_triggered_help_hooks()
{
	int i;

	for (i = 0; i < TRIGGERED_HELP_MAX; i++)
	{
		setup_triggered_help_hook(i);
	}
}

/*
 * Driver for the context-sensitive help system
 */
void init_hooks_help()
{
	setup_triggered_help_hooks();
}