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 pathspells.cc
405 lines (346 loc) · 13.5 KB
/
spells.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/*---------------------------------------------------------------------------
* ADOM Sage - frontend for ADOM
*
* Copyright (c) 2002 Joshua Kelley; see LICENSE for details
*
* Support for spells
*/
#include "adom-sage.h"
#include "states.h"
typedef STRING_HASH(int) SpellMap;
SpellMap *spell_map;
struct SpellInfo
{
int effectivity;
};
SpellInfo spell_info[numSpells];
void init_spells(void)
{
spell_map = new SpellMap;
(*spell_map)["Acid Ball"] = spellAcidBall;
(*spell_map)["Acid Bolt"] = spellAcidBolt;
(*spell_map)["Bless"] = spellBless;
(*spell_map)["Burning Hands"] = spellBurningHands;
(*spell_map)["Calm Monster"] = spellCalmMonster;
(*spell_map)["Create Item"] = spellCreateItem;
(*spell_map)["Cure Critical Wounds"] = spellCureCriticalWounds;
(*spell_map)["Cure Disease"] = spellCureDisease;
(*spell_map)["Cure Light Wounds"] = spellCureLightWounds;
(*spell_map)["Cure Serious Wounds"] = spellCureSeriousWounds;
(*spell_map)["Darkness"] = spellDarkness;
(*spell_map)["Death Ray"] = spellDeathRay;
(*spell_map)["Destroy Undead"] = spellDestroyUndead;
(*spell_map)["Disarm Trap"] = spellDisarmTrap;
(*spell_map)["Earthquake"] = spellEarthquake;
(*spell_map)["Farsight"] = spellFarsight;
(*spell_map)["Fireball"] = spellFireball;
(*spell_map)["Fire Bolt"] = spellFireBolt;
(*spell_map)["Frost Bolt"] = spellFrostBolt;
(*spell_map)["Greater Identify"] = spellGreaterIdentify;
(*spell_map)["Heal"] = spellHeal;
(*spell_map)["Ice Ball"] = spellIceBall;
(*spell_map)["Identify"] = spellIdentify;
(*spell_map)["Improved Fireball"] = spellImprovedFireball;
(*spell_map)["Invisibility"] = spellInvisibility;
(*spell_map)["Knock"] = spellKnock;
(*spell_map)["Know Alignment"] = spellKnowAlignment;
(*spell_map)["Light"] = spellLight;
(*spell_map)["Lightning Ball"] = spellLightningBall;
(*spell_map)["Lightning Bolt"] = spellLightningBolt;
(*spell_map)["Magic Lock"] = spellMagicLock;
(*spell_map)["Magic Map"] = spellMagicMap;
(*spell_map)["Magic Missile"] = spellMagicMissile;
(*spell_map)["Mystic Shovel"] = spellMysticShovel;
(*spell_map)["Neutralize Poison"] = spellNeutralizePoison;
(*spell_map)["Petrification"] = spellPetrification;
(*spell_map)["Remove Curse"] = spellRemoveCurse;
(*spell_map)["Revelation"] = spellRevelation;
(*spell_map)["Scare Monster"] = spellScareMonster;
(*spell_map)["Slow Monster"] = spellSlowMonster;
(*spell_map)["Slow Poison"] = spellSlowPoison;
(*spell_map)["Strength of Atlas"] = spellStrengthOfAtlas;
(*spell_map)["Stun Ray"] = spellStunRay;
(*spell_map)["Summon Monsters"] = spellSummonMonsters;
(*spell_map)["Teleportation"] = spellTeleportation;
(*spell_map)["Web"] = spellWeb;
(*spell_map)["Wish"] = spellWish;
(*spell_map)["Baptism of Fire"] = spellBurningHands;
(*spell_map)["Dispel Undead"] = spellDestroyUndead;
(*spell_map)["Divine Digger"] = spellMysticShovel;
(*spell_map)["Divine Favour"] = spellCreateItem;
(*spell_map)["Divine Intervention"] = spellWish;
(*spell_map)["Divine Key"] = spellKnock;
(*spell_map)["Divine Wrath"] = spellLightningBolt;
(*spell_map)["Enlightenment"] = spellIdentify;
(*spell_map)["Ethereal Bridge"] = spellTeleportation;
(*spell_map)["Freezing Fury"] = spellIceBall;
(*spell_map)["Greater Divine Touch"] = spellDeathRay;
(*spell_map)["Greater Enlightenment"] = spellGreaterIdentify;
(*spell_map)["Heavenly Fury"] = spellLightningBall;
(*spell_map)["Hellish Flames"] = spellFireBolt;
(*spell_map)["Holy Awe"] = spellScareMonster;
(*spell_map)["Invoked Devastation"] = spellImprovedFireball;
(*spell_map)["Knowledge of the Ancients"] = spellMagicMap;
(*spell_map)["Lesser Divine Touch"] = spellStunRay;
(*spell_map)["Lordly Might"] = spellStrengthOfAtlas;
(*spell_map)["Major Punishment"] = spellFireball;
(*spell_map)["Minor Punishment"] = spellMagicMissile;
(*spell_map)["Nether Bolt"] = spellFrostBolt;
(*spell_map)["Rain of Sorrow"] = spellAcidBall;
(*spell_map)["Seal of the Spheres"] = spellMagicLock;
(*spell_map)["Veil of the Gods"] = spellInvisibility;
}
StateCastSpell::StateCastSpell()
{
max_letter = 'a' - 1;
current_spell = spellUnknown;
}
int StateCastSpell::waddch(WINDOW *win, chtype ch)
{
return real_waddch(win, convert_char(ch));
}
int StateCastSpell::waddnstr(WINDOW *win, const char *str, int n)
{
const char duration[] = "Duration:";
const char range[] = "Range:";
const char diameter[] = "Diameter:";
const char damage[] = "Dmg:";
const char heals[] = "Heals:";
const char spacer[] = " ";
int E, L, W, M;
if (str[0] == '\0' && current_spell != spellUnknown)
{
E = spell_info[current_spell].effectivity;
L = game_status->player_level;
W = game_status->player_attr[attrWillpower];
M = game_status->player_attr[attrMana];
switch (current_spell)
{
case spellAcidBolt:
print_spell_details(win, range, "%i", W / 4 + L / 4 + 2);
real_waddnstr(win, spacer, -1);
print_spell_details(win, damage, "%id%i+r",
max(4, (L + E) / 3), 8);
break;
case spellAcidBall:
print_spell_details(win, diameter, "%i", max(2, W / 8));
real_waddnstr(win, spacer, -1);
print_spell_details(win, damage, "%id%i+%i",
max(3, L / 4 + 2), 9, L + E);
break;
case spellBless:
print_spell_details(win, duration, "%id%i+%i",
1, W, (M + E) * 2);
break;
case spellBurningHands:
print_spell_details(win, damage, "%id%i+%i",
min(15, L), 3, L + E);
break;
case spellCureCriticalWounds:
print_spell_details(win, heals, "%id%i+%i", 4, 8, 4 + E);
break;
case spellCureLightWounds:
print_spell_details(win, heals, "%id%i+%i", 1, 8, 1 + E);
break;
case spellCureSeriousWounds:
print_spell_details(win, heals, "%id%i+%i", 2, 10, 2 + E);
break;
case spellDarkness:
case spellLight:
print_spell_details(win, diameter, "%i",
1 + max(4, (W + E) / 4) / 2);
break;
case spellDeathRay:
print_spell_details(win, range, "%i",
max(2, min(16, (W + E) / 4)));
break;
case spellDestroyUndead:
print_spell_details(win, damage, "%id%i+%i", L + 1, 6, W + E);
break;
case spellFarsight:
print_spell_details(win, duration, "%i", (M + E) * 10);
break;
case spellFireball:
print_spell_details(win, diameter, "%i", max(2, W / 8));
real_waddnstr(win, spacer, -1);
print_spell_details(win, damage, "%id%i+%i",
max(3, L / 4 + 2), 6, L + E);
break;
case spellFireBolt:
case spellFrostBolt:
case spellLightningBolt:
print_spell_details(win, range, "%i", W / 4 + L / 4 + 2);
real_waddnstr(win, spacer, -1);
print_spell_details(win, damage, "%id%i+r",
max(4, (L + E) / 3), 6);
break;
case spellHeal:
print_spell_details(win, heals, "%id%i+%i", 10, 6, 10 + E);
break;
case spellIceBall:
print_spell_details(win, diameter, "%i", max(2, W / 8));
real_waddnstr(win, spacer, -1);
print_spell_details(win, damage, "%id%i+%i",
max(3, L / 4 + 2), 7, L + E);
break;
case spellImprovedFireball:
print_spell_details(win, diameter, "%i", max(2, W / 8));
real_waddnstr(win, spacer, -1);
print_spell_details(win, damage, "%id%i+%i",
2 + (L + E / 5), 8, L);
break;
case spellInvisibility:
print_spell_details(win, duration, "%id%i", L + E + 3, 6);
break;
case spellLightningBall:
print_spell_details(win, diameter, "%i", max(2, W / 8));
real_waddnstr(win, spacer, -1);
print_spell_details(win, damage, "%id%i+%i",
max(3, L / 4 + 2), 8, L + E);
break;
case spellMagicMissile:
print_spell_details(win, range, "%i", W / 4 + L / 4 + 2);
real_waddnstr(win, spacer, -1);
print_spell_details(win, damage, "%id%i+r",
max(2, (L + E) / 3), 4);
break;
case spellMysticShovel:
print_spell_details(win, range, "%i",
max(2, min(10, (W + E) / 5)));
break;
case spellScareMonster:
print_spell_details(win, duration, "%id%i+%i", L, 4, E);
break;
case spellSlowMonster:
print_spell_details(win, duration, "%id%i", 3, W + E);
break;
case spellStrengthOfAtlas:
print_spell_details(win, duration, "%i", (W + E) * 20);
break;
case spellStunRay:
case spellWeb:
print_spell_details(win, range, "%i",
max(3, min(12, (W + E) / 4)));
break;
default:
break;
}
}
return real_waddnstr(win, str, n);
}
int StateCastSpell::wgetch(WINDOW *win)
{
int result;
result = get_key(win);
if ((result >= 'A' && result <= max_letter) ||
(result >= 'a' && result <= max_letter - 'A' + 'a') ||
(result == 'z' || result == 'Z' || result == ' '))
{
pop_state();
}
return result;
}
int StateCastSpell::vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
return StateCastSpell::vsprintf(str, format, ap);
}
int StateCastSpell::vsprintf(char *str, const char *format, va_list ap)
{
char *spell_name;
SpellMap::iterator iter;
va_list ap_copy;
va_copy(ap_copy, ap);
// Test if we can cast spells after all
if ((strcmp(format, "Not while in the wilderness.") == 0) ||
(strcmp(format, "can't focus your thoughts enough to cast a spell.") == 0))
{
pop_state();
}
// Allowed spells
else if (strcmp(format, "%c\x03\xC6-\x03\xCE%c") == 0)
{
max_letter = va_arg(ap_copy, int); // Discard first letter
max_letter = va_arg(ap_copy, int); // Save last letter
}
else if (strcmp(format, "SELECT A SPELL TO CAST_") == 0)
{
current_spell = spellUnknown;
}
// Spell name
else if (strcmp(format, "\x03\xCE%s\x03\xC6") == 0)
{
spell_name = va_arg(ap_copy, char *);
iter = spell_map->find(spell_name);
if (iter == spell_map->end())
{
log(log_errors, "Error: unknown spell %s\n", spell_name);
}
else
{
current_spell = (Spell) iter->second;
}
}
va_end(ap_copy);
// Spell castings and cost
if (strcmp(format,
" \x03\xCE%5ld\x03\xC6, \x03\xCE%3d\x03\xC6pp ") == 0)
{
return real_vsprintf(str,
"\x03\xCE%5ld\x03\xC6,\x03\xCE%4d\x03\xC6pp ", ap);
}
// Spell effectivity
else if (strcmp(format, "____(Effectivity:_\x03\xCE%+d\x03\xC6)") == 0)
{
spell_info[current_spell].effectivity = va_arg(ap_copy, int);
return real_vsprintf(str, "_(\x03\xCE%+3d\x03\xC6)", ap);
}
// Full spell entry
else if (strcmp(format, "\x01%s\x03\xC6%c - %s\x01\n") == 0)
{
// Get arguments
va_copy(ap_copy, ap);
char *spell_details = va_arg(ap_copy, char *);
char spell_letter = va_arg(ap_copy, int);
spell_details = va_arg(ap_copy, char *);
va_end(ap_copy);
// Extract spell name
spell_name = strdup(spell_details);
char *s = strchr(spell_name, ':');
do
{
s--;
}
while (*s == ' ');
s -= 1; // Trim trailing bold sequence
*s = '\0';
// Look up matching spell
iter = spell_map->find(spell_name + 2); // Trim leading bold sequence
if (iter == spell_map->end())
{
log(log_errors, "Error: unknown spell %s\n", spell_name);
}
else
{
current_spell = (Spell) iter->second;
}
free(spell_name);
return real_sprintf(str, "\x01 \x03\xC6%c - %s\x01\n", spell_letter,
spell_details);
}
return real_vsprintf(str, format, ap);
}
void StateCastSpell::print_spell_details(WINDOW *win, const char *label,
const char *format, ...)
{
char details[255];
va_list ap;
va_start(ap, format);
real_waddnstr(win, label, -1);
real_waddch(win, ' ');
real_vsprintf(details, format, ap);
// real_vsnprintf(details, size, format, ap);
attron(A_BOLD);
real_waddnstr(win, details, -1);
attroff(A_BOLD);
va_end(ap);
}