forked from muspellsson/omega-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspell.c
875 lines (746 loc) · 19.1 KB
/
spell.c
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
/* omega copyright (C) by Laurence Raphael Brothers, 1987,1988,1989 */
/* spell.c */
/* functions having to do with spellcasting */
#include "glob.h"
void s_nutrition(void)
{
#ifdef TRADEMARK_VIOLATION
mprint("Magically Delicious!");
#else
mprint("Scrumptious!");
#endif
Player.food = 44;
foodcheck();
}
void s_wish(void)
{
if (random_range(100) > Player.iq+Player.pow+Player.level) {
mprint("Your concentration is flawed!");
mprint("The spell energy backfires!");
p_damage(random_range(Spells[S_WISH].powerdrain),
UNSTOPPABLE,
"a backfired wish spell");
}
else {
wish(0);
if (Spells[S_WISH].known) {
mprint("The power of the spell is too much for you to withstand!");
mprint("All memory of the spell is expunged from your brain.");
Spells[S_WISH].known = FALSE;
}
}
}
void s_firebolt(void)
{
int x=Player.x,y=Player.y;
setspot(&x,&y);
fbolt(Player.x,Player.y,x,y,Player.dex*2+Player.level,Player.level*10+10);
}
void s_missile(void)
{
int x=Player.x,y=Player.y;
setspot(&x,&y);
nbolt(Player.x,Player.y,x,y,Player.dex*2+Player.level,Player.level*3+3);
}
void s_teleport(void)
{
p_teleport(0);
}
void s_disrupt(void)
{
int x=Player.x,y=Player.y;
setspot(&x,&y);
disrupt(x,y,Player.level*10+25);
}
void s_disintegrate(void)
{
int x=Player.x,y=Player.y;
setspot(&x,&y);
disintegrate(x,y);
}
void s_sleep(void)
{
sleep_monster(0);
}
void s_heal(void)
{
heal(3);
}
void s_dispel(void)
{
dispel((Player.level+Player.maxpow)/10);
}
void s_breathe(void)
{
breathe(0);
}
void s_invisible(void)
{
invisible(0);
}
void s_warp(void)
{
warp(1);
}
void s_enchant(void)
{
enchant(1);
}
void s_bless(void)
{
bless(0);
}
void s_restore(void)
{
recover_stat(0);
}
void s_cure(void)
{
cure(0);
}
void s_truesight(void)
{
truesight(0);
}
void s_hellfire(void)
{
int x=Player.x,y=Player.y;
setspot(&x,&y);
hellfire(x,y,0);
Spells[S_HELLFIRE].powerdrain *= 2;
if (Spells[S_HELLFIRE].powerdrain > 90) /* 90 is original casting cost */
{
mprint("The power of the spell is too much for you to withstand!");
mprint("All memory of the spell is expunged from your brain.");
Spells[S_HELLFIRE].powerdrain = 90;
Spells[S_HELLFIRE].known = FALSE;
}
}
void s_knowledge(void)
{
knowledge(0);
}
void s_hero(void)
{
hero(0);
}
/* spell takes longer and longer to work deeper into dungeon */
void s_return(void)
{
mprint("You hear a whine as your spell begins to charge up.");
Player.status[RETURNING] =
((Current_Environment == Current_Dungeon) ? difficulty() : 1);
}
void s_desecrate(void)
{
sanctify(-1);
}
void s_haste(void)
{
haste(0);
}
void s_summon(void)
{
summon(0,-1);
}
void s_sanctuary(void)
{
sanctuary();
}
void s_sanctify(void)
{
sanctify(1);
}
void s_accuracy(void)
{
accuracy(0);
}
void s_fear(void)
{
int x = Player.x,y=Player.y;
setspot(&x,&y);
inflict_fear(x,y);
}
/* Has all kinds of effects in different circumstances.
Eventually will be more interesting */
void s_ritual(void)
{
pob symbol;
int i,roomno;
int x,y;
mprint("You begin your ritual....");
mprint("You enter a deep trance. Time Passes...");
setgamestatus(SKIP_PLAYER);
time_clock(FALSE);
setgamestatus(SKIP_PLAYER);
time_clock(FALSE);
setgamestatus(SKIP_PLAYER);
time_clock(FALSE);
setgamestatus(SKIP_PLAYER);
time_clock(FALSE);
setgamestatus(SKIP_PLAYER);
time_clock(FALSE);
if (RitualHour == hour())
mprint("Your mental fatigue prevents from completing the ritual!");
else if (random_range(100) > Player.iq+Player.pow+Player.level)
mprint("Your concentration was broken -- the ritual fails!");
else {
mprint("You charge the ritual with magical energy and focus your will.");
mprint("Time Passes...");
setgamestatus(SKIP_PLAYER);
time_clock(FALSE);
setgamestatus(SKIP_PLAYER);
time_clock(FALSE);
setgamestatus(SKIP_PLAYER);
time_clock(FALSE);
setgamestatus(SKIP_PLAYER);
time_clock(FALSE);
setgamestatus(SKIP_PLAYER);
time_clock(FALSE);
RitualHour = hour();
/* set of random conditions for different ritual effects */
if (Current_Environment == E_CITY) {
mprint("Flowing waves of mystical light congeal all around you.");
mprint("'Like wow, man! Colors!'");
mprint("Appreciative citizens throw you spare change.");
Player.cash +=random_range(50);
}
else if ( (roomno=Level->site[Player.x][Player.y].roomnumber) >= ROOMBASE )
{
if (RitualRoom == roomno)
mprint("For some reason the ritual doesn't work this time...");
else {
RitualRoom = roomno;
switch (RitualRoom) {
case RS_TREASURE: /* ransacked treasure chamber */
mprint("Your spell sets off frenetic growth all around you!");
for(i=0;i<8;i++){
Level->site[Player.x+Dirs[0][i]][Player.y+Dirs[1][i]].locchar =
HEDGE;
Level->site[Player.x+Dirs[0][i]][Player.y+Dirs[1][i]].p_locf =
L_TRIFID;
lset(Player.x+Dirs[0][i], Player.y+Dirs[1][i], CHANGED);
}
break;
case RS_HAREM: /* harem */
case RS_BOUDOIR: /* boudoir */
mprint("A secret panel opens next to the bed....");
if (random_range(2))
summon(0,INCUBUS); /* succubus/incubus */
else summon(0,SATYR); /* satyr/nymph */
break;
case RS_SHRINE: /*shrine to high magic */
mprint("A storm of mana coaelesces around you.");
mprint("You are buffeted by bursts of random magic.");
p_damage(random_range(Player.pow),UNSTOPPABLE,"high magic");
mprint("Continue ritual? Could be dangerous.... [yn] ");
if (ynq()=='y') s_wish();
else mprint("The mana fades away to nothingness.");
x = Player.x;
y = Player.y;
while (x >= 0 && Level->site[x - 1][y].roomnumber == RS_SHRINE)
x--;
while (y >= 0 && Level->site[x][y - 1].roomnumber == RS_SHRINE)
y--;
for (i = 0; Level->site[x][y].roomnumber == RS_SHRINE;) {
Level->site[x][y].roomnumber = RS_ZORCH;
lset(x, y, CHANGED);
x++;
i++;
if (Level->site[x][y].roomnumber != RS_SHRINE) {
x -= i;
i = 0;
y++;
}
}
break;
case RS_MAGIC_LAB: /* magician's lab */
mprint("Your magical activity sets off a latent spell in the lab!");
cast_spell(random_range(NUMSPELLS));
break;
case RS_PENTAGRAM: /* pentagram room */
mprint("A smoky form begins to coalesce....");
summon(-1,-1);
mprint("Fortunately, it seems confined to the pentagram.");
m_status_reset(Level->mlist->m,MOBILE);
break;
case RS_OMEGA_DAIS: /* blue omega room */
mprint("The Lords of Destiny look upon you....");
if (Player.level > 10) {
mprint("A curtain of blue flames leaps up from the omega.");
morewait();
l_adept();
}
else {
if (Player.patron == DESTINY) {
mprint("Your patrons take pity on you.");
if ((Player.rank[PRIESTHOOD]<SPRIEST) &&
(! find_item(&symbol,OB_SYMBOL_DESTINY,-1))) {
symbol = ((pob) checkmalloc(sizeof(objtype)));
*symbol = Objects[OB_SYMBOL_DESTINY];
symbol->known = 2;
symbol->charge = 17;
gain_item(symbol);
mprint("You feel uplifted.");
}
else gain_experience(min(1000,Player.xp));
}
else if (random_range(3)==1) {
mprint("You feel Fated.");
gain_experience(Player.level*Player.level*10);
Player.hp = max(Player.hp, Player.maxhp);
}
else if (random_range(2)) {
mprint("You feel Doomed.");
Player.hp = 1;
Player.mana = 0;
Player.xp = 0;
}
else mprint("The Lords of Destiny laugh at you!");
}
break;
default:
mprint("Well, not much effect. Chalk it up to experience.");
gain_experience(Player.level*5);
break;
}
}
}
else {
if (RitualRoom == Level->site[Player.x][Player.y].roomnumber)
mprint("The ritual fails for some unexplainable reason.");
else {
mprint("The ritual seems to be generating some spell effect.");
RitualRoom = Level->site[Player.x][Player.y].roomnumber;
switch (RitualRoom) {
case RS_WALLSPACE:
shadowform();
break;
case RS_CORRIDOR:
haste(0);
break;
case RS_PONDS:
breathe(0);
break;
case RS_ADEPT:
hero(1);
break;
default:
mprint("The ritual doesn't seem to produce any tangible results...");
gain_experience(Player.level*6);
}
}
}
}
}
void s_apport(void)
{
apport(0);
}
void s_shadowform(void)
{
shadowform();
}
void s_alert(void)
{
alert(0);
}
void s_regenerate(void)
{
regenerate(0);
}
void s_clairvoyance(void)
{
clairvoyance(10);
}
void s_drain(void)
{
drain(0);
}
void s_levitate(void)
{
levitate(0);
}
void s_polymorph(void)
{
polymorph(0);
}
/* lball spell */
void s_lball(void)
{
int x=Player.x,y=Player.y;
setspot(&x,&y);
lball(Player.x,Player.y,x,y,Player.level*10+10);
}
void s_identify(void)
{
identify(0);
}
void s_objdet(void)
{
objdet(1);
}
void s_mondet(void)
{
mondet(1);
}
/* select a spell to cast */
int getspell(void)
{
int spell= ABORT - 1;
do {
mprint("Cast Spell: [type spell abbrev, ?, or ESCAPE]: ");
spell = spellparse();
} while (spell < ABORT);
return(spell);
}
char *spellid(int id)
{
switch(id) {
case S_MON_DET:return("monster detection");
case S_OBJ_DET:return("object detection");
case S_IDENTIFY:return("identification");
case S_FIREBOLT:return("firebolt");
case S_LBALL:return("ball lightning");
case S_SLEEP:return("sleep");
case S_DISRUPT:return("disrupt");
case S_DISINTEGRATE:return("disintegrate");
case S_TELEPORT:return("teleport");
case S_MISSILE:return("magic missile");
case S_HEAL:return("healing");
case S_DISPEL:return("dispelling");
case S_BREATHE:return("breathing");
case S_INVISIBLE:return("invisibility");
case S_WARP:return("the warp");
case S_ENCHANT:return("enchantment");
case S_BLESS:return("blessing");
case S_RESTORE:return("restoration");
case S_CURE:return("curing");
case S_TRUESIGHT:return("true sight");
case S_HELLFIRE:return("hellfire");
case S_KNOWLEDGE:return("self knowledge");
case S_HERO:return("heroism");
case S_RETURN:return("return");
case S_DESECRATE:return("desecration");
case S_HASTE:return("haste");
case S_SUMMON:return("summoning");
case S_SANCTUARY:return("sanctuary");
case S_ACCURACY:return("accuracy");
case S_RITUAL:return("ritual magic");
case S_APPORT:return("apportation");
case S_SHADOWFORM:return("shadow form");
case S_ALERT:return("alertness");
case S_REGENERATE:return("regeneration");
case S_SANCTIFY:return("sanctification");
case S_CLAIRVOYANCE:return("clairvoyance");
case S_DRAIN:return("energy drain");
case S_LEVITATE:return("levitate");
case S_POLYMORPH:return("polymorph");
case S_FEAR:return("fear");
case S_WISH:return("wishing");
case S_NUTRITION:return("nutrition");
default:return("???");
}
}
void initspells(void)
{
int i;
for (i=0; i<NUMSPELLS; i++)
Spells[i].known = FALSE;
Spells[S_MON_DET].powerdrain = 3;
Spells[S_MON_DET].id = S_MON_DET;
Spells[S_OBJ_DET].powerdrain = 3;
Spells[S_OBJ_DET].id = S_OBJ_DET;
Spells[S_IDENTIFY].powerdrain = 10;
Spells[S_IDENTIFY].id = S_IDENTIFY;
Spells[S_FIREBOLT].powerdrain = 20;
Spells[S_FIREBOLT].id = S_FIREBOLT;
Spells[S_SLEEP].powerdrain = 15;
Spells[S_SLEEP].id = S_SLEEP;
Spells[S_LBALL].powerdrain = 25;
Spells[S_LBALL].id = S_LBALL;
Spells[S_TELEPORT].powerdrain = 20;
Spells[S_TELEPORT].id = S_TELEPORT;
Spells[S_DISRUPT].powerdrain = 30;
Spells[S_DISRUPT].id = S_DISRUPT;
Spells[S_DISINTEGRATE].powerdrain = 40;
Spells[S_DISINTEGRATE].id = S_DISINTEGRATE;
Spells[S_MISSILE].powerdrain = 10;
Spells[S_MISSILE].id = S_MISSILE;
Spells[S_HEAL].powerdrain = 15;
Spells[S_HEAL].id = S_HEAL;
Spells[S_DISPEL].powerdrain = 40;
Spells[S_DISPEL].id = S_DISPEL;
Spells[S_BREATHE].powerdrain = 20;
Spells[S_BREATHE].id = S_BREATHE;
Spells[S_INVISIBLE].powerdrain = 15;
Spells[S_INVISIBLE].id = S_INVISIBLE;
Spells[S_WARP].powerdrain = 50;
Spells[S_WARP].id = S_WARP;
Spells[S_ENCHANT].powerdrain = 30;
Spells[S_ENCHANT].id = S_ENCHANT;
Spells[S_BLESS].powerdrain = 30;
Spells[S_BLESS].id = S_BLESS;
Spells[S_RESTORE].powerdrain = 20;
Spells[S_RESTORE].id = S_RESTORE;
Spells[S_CURE].powerdrain = 20;
Spells[S_CURE].id = S_CURE;
Spells[S_TRUESIGHT].powerdrain = 20;
Spells[S_TRUESIGHT].id = S_TRUESIGHT;
Spells[S_HELLFIRE].powerdrain = 90;
Spells[S_HELLFIRE].id = S_HELLFIRE;
Spells[S_KNOWLEDGE].powerdrain = 10;
Spells[S_KNOWLEDGE].id = S_KNOWLEDGE;
Spells[S_HERO].powerdrain = 20;
Spells[S_HERO].id = S_HERO;
Spells[S_RETURN].powerdrain = 10;
Spells[S_RETURN].id = S_RETURN;
Spells[S_DESECRATE].powerdrain = 50;
Spells[S_DESECRATE].id = S_DESECRATE;
Spells[S_HASTE].powerdrain = 15;
Spells[S_HASTE].id = S_HASTE;
Spells[S_SUMMON].powerdrain = 20;
Spells[S_SUMMON].id = S_SUMMON;
Spells[S_SANCTUARY].powerdrain = 75;
Spells[S_SANCTUARY].id = S_SANCTUARY;
Spells[S_ACCURACY].powerdrain = 20;
Spells[S_ACCURACY].id = S_ACCURACY;
Spells[S_RITUAL].powerdrain = 50;
Spells[S_RITUAL].id = S_RITUAL;
Spells[S_APPORT].powerdrain = 15;
Spells[S_APPORT].id = S_APPORT;
Spells[S_SHADOWFORM].powerdrain = 50;
Spells[S_SHADOWFORM].id = S_SHADOWFORM;
Spells[S_ALERT].powerdrain = 15;
Spells[S_ALERT].id = S_ALERT;
Spells[S_REGENERATE].powerdrain = 20;
Spells[S_REGENERATE].id = S_REGENERATE;
Spells[S_SANCTIFY].powerdrain = 75;
Spells[S_SANCTIFY].id = S_SANCTIFY;
Spells[S_CLAIRVOYANCE].powerdrain = 10;
Spells[S_CLAIRVOYANCE].id = S_CLAIRVOYANCE;
Spells[S_DRAIN].powerdrain = 40;
Spells[S_DRAIN].id = S_DRAIN;
Spells[S_LEVITATE].powerdrain = 25;
Spells[S_LEVITATE].id = S_LEVITATE;
Spells[S_POLYMORPH].powerdrain = 30;
Spells[S_POLYMORPH].id = S_POLYMORPH;
Spells[S_FEAR].powerdrain = 10;
Spells[S_FEAR].id = S_FEAR;
Spells[S_WISH].powerdrain = 100;
Spells[S_WISH].id = S_WISH;
Spells[S_NUTRITION].powerdrain = 25;
Spells[S_NUTRITION].id = S_NUTRITION;
}
void cast_spell(int spell)
{
switch(spell) {
case S_MON_DET:s_mondet();
break;
case S_OBJ_DET:s_objdet();
break;
case S_IDENTIFY:s_identify();
break;
case S_FIREBOLT:s_firebolt();
break;
case S_SLEEP:s_sleep();
break;
case S_LBALL:s_lball();
break;
case S_TELEPORT:s_teleport();
break;
case S_DISRUPT:s_disrupt();
break;
case S_DISINTEGRATE:s_disintegrate();
break;
case S_MISSILE:s_missile();
break;
case S_HEAL:s_heal();
break;
case S_DISPEL:s_dispel();
break;
case S_BREATHE:s_breathe();
break;
case S_INVISIBLE:s_invisible();
break;
case S_WARP:s_warp();
break;
case S_ENCHANT:s_enchant();
break;
case S_BLESS:s_bless();
break;
case S_RESTORE:s_restore();
break;
case S_CURE:s_cure();
break;
case S_TRUESIGHT:s_truesight();
break;
case S_HELLFIRE:s_hellfire();
break;
case S_KNOWLEDGE:s_knowledge();
break;
case S_HERO:s_hero();
break;
case S_RETURN:s_return();
break;
case S_DESECRATE:s_desecrate();
break;
case S_HASTE:s_haste();
break;
case S_SUMMON:s_summon();
break;
case S_SANCTUARY:s_sanctuary();
break;
case S_ACCURACY:s_accuracy();
break;
case S_RITUAL:s_ritual();
break;
case S_APPORT:s_apport();
break;
case S_SHADOWFORM:s_shadowform();
break;
case S_ALERT:s_alert();
break;
case S_REGENERATE:s_regenerate();
break;
case S_SANCTIFY:s_sanctify();
break;
case S_CLAIRVOYANCE:s_clairvoyance();
break;
case S_DRAIN:s_drain();
break;
case S_LEVITATE:s_levitate();
break;
case S_FEAR:s_fear();
break;
case S_POLYMORPH:s_polymorph();
break;
case S_WISH:s_wish();
break;
case S_NUTRITION:s_nutrition();
break;
default: mprint("Your odd spell fizzles with a small 'sput'.");
break;
}
}
static char *spell_names[] = { /* alphabetical listing */
"accuracy", "alertness", "apportation", "ball lightning", "blessing",
"breathing", "clairvoyance", "curing", "desecration", "disintegrate",
"dispelling", "disrupt", "enchantment", "energy drain", "fear", "firebolt",
"haste", "healing", "hellfire", "heroism", "identification", "invisibility",
"levitate", "magic missile", "monster detection", "nutrition", "object detection",
"polymorph", "regeneration", "restoration", "return", "ritual magic",
"sanctification", "sanctuary", "self knowledge", "shadow form", "sleep",
"summoning", "teleport", "the warp", "true sight", "wishing" };
static int spell_ids[] = { /* in the same order as spell_names[] */
S_ACCURACY, S_ALERT, S_APPORT, S_LBALL, S_BLESS, S_BREATHE, S_CLAIRVOYANCE,
S_CURE, S_DESECRATE, S_DISINTEGRATE, S_DISPEL, S_DISRUPT, S_ENCHANT, S_DRAIN,
S_FEAR, S_FIREBOLT, S_HASTE, S_HEAL, S_HELLFIRE, S_HERO, S_IDENTIFY,
S_INVISIBLE, S_LEVITATE, S_MISSILE, S_MON_DET, S_NUTRITION, S_OBJ_DET, S_POLYMORPH,
S_REGENERATE, S_RESTORE, S_RETURN, S_RITUAL, S_SANCTIFY, S_SANCTUARY,
S_KNOWLEDGE, S_SHADOWFORM, S_SLEEP, S_SUMMON, S_TELEPORT, S_WARP, S_TRUESIGHT,
S_WISH };
void showknownspells(int first, int last)
{
int i,printed=FALSE;
menuclear();
menuprint("\nPossible Spells:\n");
for (i = first; i <= last; i++)
if (Spells[spell_ids[i]].known) {
printed = TRUE;
menuprint(spell_names[i]);
menuprint(" (");
menunumprint(Spells[spell_ids[i]].powerdrain);
menuprint(" mana)");
menuprint("\n");
}
if (! printed)
menuprint("\nNo spells match that prefix!");
showmenu();
}
int spellparse(void)
{
int first, last, pos;
char byte, prefix[80];
int found = 0;
int f, l;
first = 0;
while (first < NUMSPELLS && !Spells[spell_ids[first]].known)
first++;
if (first == NUMSPELLS) {
print1("You don't know any spells!");
return ABORT;
}
last = NUMSPELLS - 1;
pos = 0;
print2("");
do {
byte = mgetc();
if (byte == BACKSPACE || byte == DELETE) {
if (pos > 0) {
prefix[--pos] = '\0';
byte = prefix[pos - 1];
f = first;
while (f >= 0 && !strncmp(prefix, spell_names[f], pos)) {
if (Spells[spell_ids[f]].known)
first = f;
f--;
}
l = last;
while (l < NUMSPELLS && !strncmp(prefix, spell_names[l], pos)) {
if (Spells[spell_ids[l]].known)
last = l;
l++;
}
if (found)
found = 0;
print2(prefix);
}
if (pos == 0) {
first = 0;
last = NUMSPELLS - 1;
found = 0;
print2("");
}
}
else if (byte == ESCAPE) {
xredraw();
return ABORT;
}
else if (byte == '?')
showknownspells(first, last);
else if (byte != '\n') {
if (byte >= 'A' && byte <= 'Z')
byte += 'a' - 'A';
if (found)
continue;
f = first;
l = last;
while (f < NUMSPELLS &&
(!Spells[spell_ids[f]].known ||
strlen(spell_names[f]) < pos || spell_names[f][pos] < byte))
f++;
while (l >= 0 && (!Spells[spell_ids[l]].known ||
strlen(spell_names[l]) < pos || spell_names[l][pos] > byte))
l--;
if (l < f)
continue;
prefix[pos++] = byte;
prefix[pos] = '\0';
nprint2(prefix + pos - 1);
first = f;
last = l;
if (first == last && !found) { /* unique name */
found = 1;
nprint2(spell_names[first] + pos);
}
}
} while (byte != '\n');
xredraw();
if (found)
return spell_ids[first];
else {
print3("That is an ambiguous abbreviation!");
return ABORT;
}
}