This repository has been archived by the owner on Nov 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmsg_handlers.cc
363 lines (310 loc) · 10.4 KB
/
msg_handlers.cc
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
359
360
361
362
/*---------------------------------------------------------------------------
* ADOM Sage - frontend for ADOM
*
* Copyright (c) 2002 Joshua Kelley; see LICENSE for details
*
* Message handlers
*/
#include "adom-sage.h"
#include "states.h"
#define MSG_HANDLER(handler) void handler (StateCmdProcessor *state, \
void *data, char *str, const char *format, va_list ap)
/*---------------------------------------------------------------------------
* Config option tracking
*/
const char *fastmore_msg =
"[The game will now accept any key at the (more) prompt.]";
MSG_HANDLER(fastmore_handler)
{
config->fast_more = 1;
state->ignore_more++;
}
const char *no_fastmore_msg =
"[The game will now accept only SPACE and ENTER at the (more) prompt.]";
MSG_HANDLER(no_fastmore_handler)
{
config->fast_more = 0;
state->ignore_more++;
}
/*---------------------------------------------------------------------------
* State tracking
*/
const char *levelup_msg =
"Congratulations! You advance to level %d.";
MSG_HANDLER(levelup_handler)
{
state->next_state = new StateLevelUp;
}
const char *examine_msg =
"Use the movement keys to position the cursor. Abort with [SPACE] or [Z].";
MSG_HANDLER(examine_handler)
{
push_state(new StateExamine);
}
const char *locate_msg =
"Move the cursor to the desired position and press [SPACE] when done.";
MSG_HANDLER(locate_handler)
{
push_state(new StateLocate);
}
const char *target_msg =
"[T]arget --";
MSG_HANDLER(target_handler)
{
// HACK
if (strcmp(cur_state()->name(), "target") != 0)
{
push_state(new StateTarget);
}
}
const char *recall_msg =
"<<<<<--- %s (";
MSG_HANDLER(recall_handler)
{
push_state(new StateRecall);
}
const char *minstrel_msg
= "The Mad Minstrel sings a song.";
MSG_HANDLER(minstrel_handler)
{
state->next_state = new StateInfoScreen;
}
const char *game_summary_msg
= "Game Summary for '%s'";
MSG_HANDLER(game_summary_handler)
{
push_state(new StateGameSummary);
}
const char *memorial_msg
= "Do you want to create a memorial file about your character? [y/N]_";
MSG_HANDLER(memorial_handler)
{
push_state(new StateMemorial(state));
}
const char *flg_success_msg
= "Final log written to '%s' in directory '%s'.";
MSG_HANDLER(flg_success_handler)
{
push_state(new StateFlgSuccess(state));
}
/*---------------------------------------------------------------------------
* Game status tracking
*/
MSG_HANDLER(location_handler)
{
log(log_game_status, "Game status: location %i\n", (int)(intptr_t) data);
game_status->loc = (Location) (int)(intptr_t) data;
}
const char *stat_msg =
"%s:%2d_";
MSG_HANDLER(stat_handler)
{
char *stat_name;
int stat_val;
stat_name = va_arg(ap, char *);
stat_val = va_arg(ap, int);
log(log_game_status, "Game status: %s %d\n", stat_name, stat_val);
game_status->player_attr[(*attr_map)[stat_name]] = stat_val;
}
const char *exp_msg =
"Exp: %d/%lu__";
const char *exp_msg_2 =
"Exp: %d/%lld__";
MSG_HANDLER(exp_handler)
{
int level;
long unsigned exp;
level = va_arg(ap, int);
exp = va_arg(ap, long unsigned);
game_status->player_level = level;
log(log_game_status, "Game status: player level %i\n",
game_status->player_level);
}
/*---------------------------------------------------------------------------
* ToEF messages
*/
const char *toef_msg =
"The air is extremely hot!";
const char *ring_ice_msg =
"Your equipment is protected from the fire by a thin sheet of ice emanating from your hands.";
MSG_HANDLER(toef_handler)
{
if (config->suppress_toef && game_status->loc == locToEF)
{
strcpy(str, "");
}
}
/*---------------------------------------------------------------------------
* Resistance messages
*/
static int resisted = 0;
const char *resist_msg =
"You resist the";
MSG_HANDLER(resist_handler)
{
resisted = 1;
strcpy(str, "");
}
const char *resist_fire_msg =
"searing flames.";
const char *resist_ice_msg =
"icy blast.";
const char *resist_shock_msg =
"shock waves.";
const char *resist_acid_msg =
"acidic fluids.";
const char *resist_water_msg =
"water blast.";
MSG_HANDLER(resist_elem_handler)
{
if (resisted)
{
if (config->suppress_toef && game_status->loc == locToEF
&& ((int)(intptr_t) data) == elemFire)
{
strcpy(str, "");
}
else
{
sprintf(str, "You resist the %s", format);
}
resisted = 0;
}
}
/*---------------------------------------------------------------------------
* Fast selling support
*/
static int sale_offer = 0;
const char *sale_offer_msg =
"Do you want to accept the offer? [Y/n]_";
MSG_HANDLER(sale_offer_handler)
{
if (config->fast_selling)
{
strcpy(str, "Do you accept? [Y/n]_");
sale_offer = 1;
}
}
const char *no_sale_msg =
"\"Then take yer stuff with ye!\"";
MSG_HANDLER(no_sale_handler)
{
if (config->fast_selling)
{
strcpy(str, "");
sale_offer = 0;
}
}
const char *drop_msg =
"You drop the %s.";
MSG_HANDLER(drop_handler)
{
if (sale_offer && config->fast_selling)
{
strcpy(str, "");
sale_offer = 0;
}
}
/*---------------------------------------------------------------------------
* Auto-swap-with-neutrals support
*/
const char *confirm_msg
= "Really %s? [%s]_";
MSG_HANDLER(confirm_handler)
{
if (config->auto_swap_neutral && (state->last_cmd >= cmdMoveSW)
&& state->last_cmd <= cmdMoveNE
&& reverse_keymap[cmdSwapPosition])
{
char *s = va_arg(ap, char *);
if (strncmp(s, "attack ", strlen("attack ")) == 0
|| strncmp(s, "backstab ", strlen("backstab ")) == 0)
{
// If we're asked, "Really attack/backstab the foo?", then
// attempt to swap places instead.
push_state(new StateSwap(state, state->last_cmd));
str[0] = '\0';
}
}
}
// Version messages
const char *flg_version_msg = "Version 1.2.0";
const char *flg_version_msg_r = "Ancient Domains Of Mystery\n%s\n";
MSG_HANDLER(flg_handler)
{
int release = get_version() - 12000;
sprintf(str, "Ancient Domains of Mystery\nRelease %d\nwith ADOM Sage version %s\n", release, SAGE_VERSION);
}
const char *version_msg_111 = "Ancient Domains of Mystery__ Version 1.1.1";
const char *version_msg_100 = "Ancient Domains of Mystery__ Version 1.0.0";
const char *version_msg_120 = "Ancient Domains of Mystery__ Version 1.2.0";
const char *version_msg_r = "Ancient Domains of Mystery %s";
MSG_HANDLER(version_handler)
{
int release = get_version() - 12000;
sprintf(str, "Ancient Domains of Mystery (release %d) with ADOM Sage version %s", release, SAGE_VERSION);
}
/*---------------------------------------------------------------------------
* Initialization
*/
void init_msg_maps(void)
{
main_msgmap = new MsgMap;
regex_msgmap = new MsgMap;
// Tracking state changes
(*main_msgmap)[levelup_msg] = new MsgInfo(levelup_handler, NULL);
(*main_msgmap)[examine_msg] = new MsgInfo(examine_handler, NULL);
(*main_msgmap)[locate_msg] = new MsgInfo(locate_handler, NULL);
(*main_msgmap)[target_msg] = new MsgInfo(target_handler, NULL);
(*main_msgmap)[recall_msg] = new MsgInfo(recall_handler, NULL);
(*main_msgmap)[minstrel_msg] = new MsgInfo(minstrel_handler, NULL);
(*main_msgmap)[game_summary_msg] = new MsgInfo(game_summary_handler, NULL);
(*main_msgmap)[memorial_msg] = new MsgInfo(memorial_handler, NULL);
(*main_msgmap)[flg_success_msg] = new MsgInfo(flg_success_handler, NULL);
// Tracking configuration changes
(*main_msgmap)[fastmore_msg] = new MsgInfo(fastmore_handler, NULL);
(*main_msgmap)[no_fastmore_msg] = new MsgInfo(no_fastmore_handler, NULL);
// Tracking game status changes
(*main_msgmap)["DrCh_"] = new MsgInfo(location_handler,
(void *) locWilderness);
(*main_msgmap)["TF: 1_"] = new MsgInfo(location_handler, (void *) locToEF);
(*main_msgmap)["TF: 2_"] = new MsgInfo(location_handler, (void *) locToEF);
(*main_msgmap)["TF: 3_"] = new MsgInfo(location_handler, (void *) locToEF);
(*main_msgmap)["TF: 4_"] = new MsgInfo(location_handler, (void *) locToEF);
(*main_msgmap)[stat_msg] = new MsgInfo(stat_handler, NULL);
(*main_msgmap)[exp_msg] = new MsgInfo(exp_handler, NULL);
(*main_msgmap)[exp_msg_2] = new MsgInfo(exp_handler, NULL);
// Tower of Eternal Flames messages
(*main_msgmap)[toef_msg] = new MsgInfo(toef_handler, NULL);
(*main_msgmap)[ring_ice_msg] = new MsgInfo(toef_handler, NULL);
// Resistance messages
(*main_msgmap)[resist_msg] = new MsgInfo(resist_handler, NULL);
(*main_msgmap)[resist_fire_msg] = new MsgInfo(resist_elem_handler,
(void *) elemFire);
(*main_msgmap)[resist_ice_msg] = new MsgInfo(resist_elem_handler,
(void *) elemIce);
(*main_msgmap)[resist_shock_msg] = new MsgInfo(resist_elem_handler,
(void *) elemShock);
(*main_msgmap)[resist_acid_msg] = new MsgInfo(resist_elem_handler,
(void *) elemAcid);
(*main_msgmap)[resist_water_msg] = new MsgInfo(resist_elem_handler,
(void *) elemWater);
// Selling messages
(*main_msgmap)[sale_offer_msg] = new MsgInfo(sale_offer_handler, NULL);
(*main_msgmap)[no_sale_msg] = new MsgInfo(no_sale_handler, NULL);
(*main_msgmap)[drop_msg] = new MsgInfo(drop_handler, NULL);
// Auto swap with neutrals
(*main_msgmap)[confirm_msg] = new MsgInfo(confirm_handler, NULL);
// Version info
attr_t attr = A_NORMAL;
short color = COLOR_WHITE;
get_color("yellow", &attr, &color);
(*main_msgmap)[flg_version_msg] = new MsgInfo("Version 1.2.0 with ADOM Sage " SAGE_VERSION);
(*main_msgmap)[flg_version_msg_r] = new MsgInfo(flg_handler, NULL);
(*main_msgmap)[version_msg_111] = new MsgInfo(0, attr, color, "Ancient Domains of Mystery__ Version 1.1.1 with ADOM Sage " SAGE_VERSION);
(*main_msgmap)[version_msg_100] = new MsgInfo(0, attr, color, "Ancient Domains of Mystery__ Version 1.0.0 with ADOM Sage " SAGE_VERSION);
(*main_msgmap)[version_msg_120] = new MsgInfo(0, attr, color, "Ancient Domains of Mystery__ Version 1.2.0 with ADOM Sage " SAGE_VERSION);
(*main_msgmap)[version_msg_r] = new MsgInfo(version_handler, NULL);
(*main_msgmap)[version_msg_r]->color = color;
(*main_msgmap)[version_msg_r]->attr = attr;
}