/
spells.c
2605 lines (2398 loc) · 54.8 KB
/
spells.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
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include "constants.h"
#include "config.h"
#include "types.h"
#include "externs.h"
#ifdef USG
#include <string.h>
#else
#include <strings.h>
#endif
#ifdef sun /* correct SUN stupidity in the stdio.h file */
char *sprintf();
#endif
extern char cur_char2();
/* Following are spell procedure/functions -RAK- */
/* These routines are commonly used in the scroll, potion, wands, and */
/* staves routines, and are occasionally called from other areas. */
/* Now included are creature spells also... -RAK */
monster_name (m_name, m_ptr, r_ptr)
char *m_name;
monster_type *m_ptr;
creature_type *r_ptr;
{
if ((!m_ptr->ml) || (py.flags.blind > 0) ||
((0x10000 & r_ptr->cmove) && (!py.flags.see_inv)))
(void) strcpy (m_name, "It");
else
(void) sprintf (m_name, "The %s", r_ptr->name);
}
lower_monster_name (m_name, m_ptr, r_ptr)
char *m_name;
monster_type *m_ptr;
creature_type *r_ptr;
{
if ((!m_ptr->ml) || (py.flags.blind > 0) ||
((0x10000 & r_ptr->cmove) && (!py.flags.see_inv)))
(void) strcpy (m_name, "it");
else
(void) sprintf (m_name, "the %s", r_ptr->name);
}
/* Sleep creatures adjacent to player -RAK- */
int sleep_monsters1(y, x)
int y, x;
{
register int i, j;
register cave_type *c_ptr;
register monster_type *m_ptr;
register creature_type *r_ptr;
int sleep;
vtype out_val;
vtype m_name;
sleep = FALSE;
for (i = y-1; i <= y+1; i++)
for (j = x-1; j <= x+1; j++)
{
c_ptr = &cave[i][j];
if (c_ptr->cptr > 1)
{
m_ptr = &m_list[c_ptr->cptr];
r_ptr = &c_list[m_ptr->mptr];
monster_name (m_name, m_ptr, r_ptr);
if ((randint(MAX_MONS_LEVEL) < r_ptr->level) ||
(0x1000 & r_ptr->cdefense))
{
(void) sprintf(out_val, "%s is unaffected.", m_name);
msg_print(out_val);
}
else
{
sleep = TRUE;
m_ptr->csleep = 500;
(void) sprintf(out_val, "%s falls asleep.", m_name);
msg_print(out_val);
}
}
}
return(sleep);
}
/* Detect any treasure on the current panel -RAK- */
int detect_treasure()
{
register int i, j;
register int detect;
register cave_type *c_ptr;
detect = FALSE;
for (i = panel_row_min; i <= panel_row_max; i++)
for (j = panel_col_min; j <= panel_col_max; j++)
{
c_ptr = &cave[i][j];
if (c_ptr->tptr != 0)
if (t_list[c_ptr->tptr].tval == 100)
if (!test_light(i, j))
{
lite_spot(i, j);
c_ptr->tl = TRUE;
detect = TRUE;
}
}
return(detect);
}
/* Detect all objects on the current panel -RAK- */
int detect_object()
{
register int i, j;
register int detect;
register cave_type *c_ptr;
detect = FALSE;
for (i = panel_row_min; i <= panel_row_max; i++)
for (j = panel_col_min; j <= panel_col_max; j++)
{
c_ptr = &cave[i][j];
if (c_ptr->tptr != 0)
if (t_list[c_ptr->tptr].tval < 100)
if (!test_light(i, j))
{
lite_spot(i, j);
c_ptr->tl = TRUE;
detect = TRUE;
}
}
return(detect);
}
/* Locates and displays traps on current panel -RAK- */
int detect_trap()
{
register int i, j;
int detect;
register cave_type *c_ptr;
register treasure_type *t_ptr;
detect = FALSE;
for (i = panel_row_min; i <= panel_row_max; i++)
for (j = panel_col_min; j <= panel_col_max; j++)
{
c_ptr = &cave[i][j];
if (c_ptr->tptr != 0)
if (t_list[c_ptr->tptr].tval == 101)
{
change_trap(i, j);
c_ptr->fm = TRUE;
detect = TRUE;
}
else if (t_list[c_ptr->tptr].tval == 2)
{
t_ptr = &t_list[c_ptr->tptr];
known2(t_ptr->name);
}
}
return(detect);
}
/* Locates and displays all secret doors on current panel -RAK- */
int detect_sdoor()
{
register int i, j;
register int detect;
register cave_type *c_ptr;
detect = FALSE;
for (i = panel_row_min; i <= panel_row_max; i++)
for (j = panel_col_min; j <= panel_col_max; j++)
{
c_ptr = &cave[i][j];
if (c_ptr->tptr != 0)
/* Secret doors */
if (t_list[c_ptr->tptr].tval == 109)
{
c_ptr->fval = corr_floor3.ftval;
change_trap(i, j);
c_ptr->fm = TRUE;
detect = TRUE;
}
/* Staircases */
else if ((t_list[c_ptr->tptr].tval == 107) ||
(t_list[c_ptr->tptr].tval == 108))
if (!c_ptr->fm)
{
c_ptr->fm = TRUE;
lite_spot(i, j);
detect = TRUE;
}
}
return(detect);
}
/* Locates and displays all invisible creatures on current panel -RAK-*/
int detect_invisible()
{
register int i;
register int flag;
char tmp_str[2];
register monster_type *m_ptr;
flag = FALSE;
i = muptr;
while (i > 0)
{
m_ptr = &m_list[i];
if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx))
if (0x10000 & c_list[m_ptr->mptr].cmove)
{
m_ptr->ml = TRUE;
tmp_str[0] = c_list[m_ptr->mptr].cchar;
tmp_str[1] = '\0';
print(tmp_str, (int)m_ptr->fy, (int)m_ptr->fx);
flag = TRUE;
}
i = m_list[i].nptr;
}
if (flag)
{
msg_print("You sense the presence of invisible creatures!");
/* make sure player sees the message */
msg_print(" ");
msg_flag = FALSE;
}
return(flag);
}
/* Light an area: 1. If corridor light immediate area -RAK-*/
/* 2. If room light entire room. */
int light_area(y, x)
register int y, x;
{
register int i, j;
register int light;
msg_print("You are surrounded by a white light.");
light = TRUE;
if (((cave[y][x].fval == 1) || (cave[y][x].fval == 2)) && (dun_level > 0))
light_room(y, x);
else
for (i = y-1; i <= y+1; i++)
for (j = x-1; j <= x+1; j++)
if (in_bounds(i, j))
{
if (!test_light(i, j))
lite_spot(i, j);
cave[i][j].pl = TRUE;
}
return(light);
}
/* Darken an area, opposite of light area -RAK- */
int unlight_area(y, x)
int y, x;
{
register int i, j, k;
int tmp1, tmp2;
int start_row, start_col;
int end_row, end_col;
int flag;
int unlight;
register cave_type *c_ptr;
vtype out_val;
flag = FALSE;
if (((cave[y][x].fval == 1) || (cave[y][x].fval == 2)) && (dun_level > 0))
{
tmp1 = (SCREEN_HEIGHT/2);
tmp2 = (SCREEN_WIDTH /2);
start_row = (y/tmp1)*tmp1 + 1;
start_col = (x/tmp2)*tmp2 + 1;
end_row = start_row + tmp1 - 1;
end_col = start_col + tmp2 - 1;
for (i = start_row; i <= end_row; i++)
{
out_val[0] = '\0';
k = 0;
for (j = start_col; j <= end_col; j++)
{
c_ptr = &cave[i][j];
if ((c_ptr->fval == 1) || (c_ptr->fval == 2))
{
c_ptr->pl = FALSE;
c_ptr->fval = 1;
if (!test_light(i, j))
{
if (k == 0)
k = j;
(void) strcat(out_val, " ");
}
else if (k > 0)
{
flag = TRUE;
print(out_val, i, k);
out_val[0] = '\0';
k = 0;
}
}
else if (k > 0)
{
flag = TRUE;
print(out_val, i, k);
out_val[0] = '\0';
k = 0;
}
if (k > 0)
{
flag = TRUE;
print(out_val, i, k);
}
}
}
}
else
for (i = y-1; i <= y+1; i++)
for (j = x-1; j <= x+1; j++)
if (in_bounds(i, j))
{
c_ptr = &cave[i][j];
if ((c_ptr->fval == 4) || (c_ptr->fval == 5) || (c_ptr->fval ==6))
if (c_ptr->pl)
{
c_ptr->pl = FALSE;
flag = TRUE;
}
if (flag)
{
msg_print("Darkness surrounds you...");
unlight = TRUE;
}
}
else
unlight = FALSE;
return(unlight);
}
/* Map the current area plus some -RAK- */
int map_area()
{
register cave_type *c_ptr;
register int i7, i8, n, m;
int i, j, k, l;
int map;
map = TRUE;
i = panel_row_min - randint(10);
j = panel_row_max + randint(10);
k = panel_col_min - randint(20);
l = panel_col_max + randint(20);
for (m = i; m <= j; m++)
for (n = k; n <= l; n++)
if (in_bounds(m, n))
if (set_floor(cave[m][n].fval))
for (i7 = m-1; i7 <= m+1; i7++)
for (i8 = n-1; i8 <= n+1; i8++)
{
c_ptr = &cave[i7][i8];
if (((c_ptr->fval >= 10) && (c_ptr->fval <= 12)) ||
(c_ptr->fval == 15))
c_ptr->pl = TRUE;
else if (c_ptr->tptr != 0)
if ((t_list[c_ptr->tptr].tval >= 102) &&
(t_list[c_ptr->tptr].tval <= 110) &&
(t_list[c_ptr->tptr].tval != 106))
c_ptr->fm = TRUE;
}
prt_map();
return(map);
}
/* Identify an object -RAK- */
int ident_spell()
{
int item_val;
vtype out_val, tmp_str;
int redraw;
int ident;
register treasure_type *i_ptr;
ident = FALSE;
redraw = FALSE;
if (get_item(&item_val, "Item you wish identified?",
&redraw, 0, inven_ctr-1))
{
i_ptr = &inventory[item_val];
ident = TRUE;
identify(inventory[item_val]);
known2(i_ptr->name);
objdes(tmp_str, item_val, TRUE);
(void) sprintf(out_val, "%c%c %s", item_val+97, cur_char2(item_val),
tmp_str);
msg_print(out_val);
}
if (redraw)
{
/* make sure player sees message before draw cave erases it */
msg_print(" ");
draw_cave();
}
return(ident);
}
/* Get all the monsters on the level pissed off... -RAK- */
int aggravate_monster (dis_affect)
int dis_affect;
{
register int i;
int aggravate;
register monster_type *m_ptr;
aggravate = TRUE;
i = muptr;
while (i > 0)
{
m_ptr = &m_list[i];
m_ptr->csleep = 0;
if (m_ptr->cdis <= dis_affect)
if (m_ptr->cspeed < 2)
m_ptr->cspeed++;
i = m_list[i].nptr;
}
return(aggravate);
}
/* Surround the fool with traps (chuckle) -RAK- */
int trap_creation()
{
register int i, j;
register int trap;
register cave_type *c_ptr;
trap = TRUE;
for (i = char_row-1; i <= char_row+1; i++)
for (j = char_col-1; j <= char_col+1; j++)
{
c_ptr = &cave[i][j];
if (set_floor(c_ptr->fval))
{
if (c_ptr->tptr != 0)
(void) delete_object(i, j);
place_trap(i, j, 1, randint(MAX_TRAPA)-1);
}
}
return(trap);
}
/* Surround the player with doors... -RAK- */
int door_creation()
{
register int i, j;
int k;
register int door;
register cave_type *c_ptr;
door = TRUE;
for (i = char_row-1; i <= char_row+1; i++)
for (j = char_col-1; j <= char_col+1; j++)
if ((i != char_row) || (j != char_col))
{
c_ptr = &cave[i][j];
if (set_floor(c_ptr->fval))
{
popt(&k);
if (c_ptr->tptr != 0)
(void) delete_object(i, j);
c_ptr->fopen = FALSE;
c_ptr->tptr = k;
t_list[k] = door_list[1];
if (test_light(i, j))
lite_spot(i, j);
}
}
return(door);
}
/* Destroys any adjacent door(s)/trap(s) -RAK- */
int td_destroy()
{
register int i, j;
register int destroy;
register cave_type *c_ptr;
destroy = FALSE;
for (i = char_row-1; i <= char_row+1; i++)
for (j = char_col-1; j <= char_col+1; j++)
{
c_ptr = &cave[i][j];
if (c_ptr->tptr != 0)
{
if (((t_list[c_ptr->tptr].tval >= 101) &&
(t_list[c_ptr->tptr].tval <= 105) &&
(t_list[c_ptr->tptr].tval != 103)) ||
(t_list[c_ptr->tptr].tval == 109))
{
if (delete_object(i, j))
destroy = TRUE;
}
else if (t_list[c_ptr->tptr].tval == 2)
/* destroy traps on chest and unlock */
t_list[c_ptr->tptr].flags &= 0xFF000000;
}
}
return(destroy);
}
/* Display all creatures on the current panel -RAK- */
int detect_monsters()
{
register int i;
register int flag, detect;
char tmp_str[2];
register monster_type *m_ptr;
flag = FALSE;
i = muptr;
while (i > 0)
{
m_ptr = &m_list[i];
if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx))
if ((0x10000 & c_list[m_ptr->mptr].cmove) == 0)
{
m_ptr->ml = TRUE;
tmp_str[0] = c_list[m_ptr->mptr].cchar;
tmp_str[1] = '\0';
print(tmp_str, (int)m_ptr->fy, (int)m_ptr->fx);
flag = TRUE;
}
i = m_list[i].nptr;
}
if (flag)
{
msg_print("You sense the presence of monsters!");
/* make sure player sees the message */
msg_print(" ");
msg_flag = FALSE;
detect = TRUE;
}
detect = flag;
return(detect);
}
/* Leave a line of light in given dir, blue light can sometimes */
/* hurt creatures... -RAK- */
light_line(dir, y, x)
int dir, y, x;
{
register int i;
register cave_type *c_ptr;
register monster_type *m_ptr;
register creature_type *r_ptr;
vtype out_val;
vtype m_name;
char tmp_str[2];
while (cave[y][x].fopen){
c_ptr = &cave[y][x];
if (panel_contains(y, x))
{
if ((!c_ptr->tl) && (!c_ptr->pl))
if (c_ptr->fval == 2)
light_room(y, x);
else
lite_spot(y, x);
if (c_ptr->cptr > 1)
{
m_ptr = &m_list[c_ptr->cptr];
r_ptr = &c_list[m_ptr->mptr];
m_ptr->ml = TRUE;
tmp_str[0] = r_ptr->cchar;
tmp_str[1] = '\0';
print(tmp_str, (int)m_ptr->fy, (int)m_ptr->fx);
monster_name (m_name, m_ptr, r_ptr);
if (0x0100 & r_ptr->cdefense)
{
(void) sprintf(out_val, "%s wails out in pain!", m_name);
msg_print(out_val);
i = mon_take_hit((int)c_ptr->cptr, damroll("2d8"));
if (i >= 0)
{
(void) sprintf(out_val, "%s dies in a fit of agony.",
m_name);
msg_print(out_val);
}
}
}
c_ptr->pl = TRUE;
}
(void) move(dir, &y, &x);
}
}
/* Light line in all directions -RAK- */
int starlite(y, x)
register int y, x;
{
register int i;
msg_print("The end of the staff bursts into a blue shimmering light.");
for (i = 1; i <= 9; i++)
if (i != 5)
light_line(i, y, x);
return(TRUE);
}
/* Disarms all traps/chests in a given direction -RAK- */
int disarm_all(dir, y, x)
int dir, y, x;
{
register cave_type *c_ptr;
register treasure_type *t_ptr;
register int i, oldy, oldx;
int disarm;
char *string;
disarm = FALSE;
do
{
c_ptr = &cave[y][x];
if (c_ptr->tptr != 0)
{
t_ptr = &t_list[c_ptr->tptr];
if ((t_ptr->tval == 101) || (t_ptr->tval == 102))
{
if (delete_object(y, x))
disarm = TRUE;
}
else if (t_ptr->tval == 105)
{
t_ptr->p1 = 0;
}
else if (t_ptr->tval == 109)
{
c_ptr->fval = corr_floor3.ftval;
change_trap(y, x);
c_ptr->fm = TRUE;
disarm = TRUE;
}
else if (t_ptr->tval == 2)
if (t_ptr->flags != 0)
{
msg_print("Click!");
t_ptr->flags = 0;
disarm = TRUE;
string = index(t_ptr->name, '(');
if (string)
i = strlen(t_ptr->name) - strlen(string);
else
i = -1;
if (i >= 0)
t_ptr->name[i] = '\0';
(void) strcat(t_ptr->name, " (Unlocked)");
known2(t_ptr->name);
}
}
oldy = y;
oldx = x;
(void) move(dir, &y, &x);
}
while (cave[oldy][oldx].fopen);
return(disarm);
}
/* Return flags for given type area affect -RAK- */
get_flags(typ, weapon_type, harm_type, destroy)
int typ;
int *weapon_type, *harm_type;
int (**destroy)();
{
int set_null(), set_fire_destroy(), set_frost_destroy();
int set_acid_destroy(), set_lightning_destroy();
switch(typ)
{
case 1: /* Lightning */
*weapon_type = 0x00080000;
*harm_type = 0x0100;
*destroy = set_lightning_destroy;
break;
case 2: /* Poison Gas */
*weapon_type = 0x00100000;
*harm_type = 0x0040;
*destroy = set_null;
break;
case 3: /* Acid */
*weapon_type = 0x00200000;
*harm_type = 0x0080;
*destroy = set_acid_destroy;
break;
case 4: /* Frost */
*weapon_type = 0x00400000;
*harm_type = 0x0010;
*destroy = set_frost_destroy;
break;
case 5: /* Fire */
*weapon_type = 0x00800000;
*harm_type = 0x0020;
*destroy = set_fire_destroy;
break;
case 6: /* Holy Orb */
*weapon_type = 0x00000000;
*harm_type = 0x0004;
*destroy = set_null;
break;
default:
*weapon_type = 0;
*harm_type = 0;
*destroy = set_null;
}
}
/* Shoot a bolt in a given direction -RAK- */
int fire_bolt(typ, dir, y, x, dam, bolt_typ)
int typ, dir, y, x, dam;
ctype bolt_typ;
{
int i, oldy, oldx, dist;
int weapon_type, harm_type;
int flag;
int (*dummy)();
register cave_type *c_ptr;
register monster_type *m_ptr;
register creature_type *r_ptr;
vtype out_val;
vtype m_name;
char tmp_str[2];
flag = FALSE;
get_flags(typ, &weapon_type, &harm_type, &dummy);
oldy = y;
oldx = x;
dist = 0;
do
{
(void) move(dir, &y, &x);
if (test_light(oldy, oldx))
lite_spot(oldy, oldx);
else
unlite_spot(oldy, oldx);
dist++;
if (dist > OBJ_BOLT_RANGE)
flag = TRUE;
else
{
c_ptr = &cave[y][x];
if (c_ptr->fopen)
{
if (c_ptr->cptr > 1)
{
flag = TRUE;
m_ptr = &m_list[c_ptr->cptr];
r_ptr = &c_list[m_ptr->mptr];
/* light it up first, then check to see if visible */
m_list[c_ptr->cptr].ml = TRUE;
lower_monster_name(m_name, m_ptr, r_ptr);
(void) sprintf(out_val, "The %s strikes %s.", bolt_typ,
m_name);
msg_print(out_val);
if (harm_type & r_ptr->cdefense)
dam = dam*2;
else if (weapon_type & r_ptr->spells)
dam = (dam/4.0);
i = mon_take_hit((int)c_ptr->cptr, dam);
monster_name(m_name, m_ptr, r_ptr);
if (i >= 0)
{
(void) sprintf(out_val, "%s dies in a fit of agony.",
m_name);
msg_print(out_val);
}
else
{
if (panel_contains(y, x))
{
tmp_str[0] = c_list[m_ptr->mptr].cchar;
tmp_str[1] = '\0';
print(tmp_str, y, x);
}
if (dam > 0)
{
(void) sprintf (out_val, "%s screams in agony.",
m_name);
msg_print (out_val);
}
}
}
else if (panel_contains(y, x))
{
print("*", y, x);
/* show the bolt */
put_qio();
}
}
else
flag = TRUE;
}
oldy = y;
oldx = x;
}
while (!flag);
}
/* Shoot a ball in a given direction. Note that balls have an */
/* area affect.... -RAK- */
int fire_ball(typ, dir, y, x, dam_hp, descrip)
int typ, dir, y, x, dam_hp;
ctype descrip;
{
register int i, j;
int dam, max_dis, thit, tkill, k;
int oldy, oldx, dist;
int weapon_type, harm_type;
int flag;
int (*destroy)();
register cave_type *c_ptr;
register monster_type *m_ptr;
register creature_type *r_ptr;
vtype out_val;
char tmp_str[2];
thit = 0;
tkill = 0;
max_dis = 2;
get_flags(typ, &weapon_type, &harm_type, &destroy);
flag = FALSE;
oldy = y;
oldx = x;
dist = 0;
do
{
(void) move(dir, &y, &x);
dist++;
if (test_light(oldy, oldx))
lite_spot(oldy, oldx);
else
unlite_spot(oldy, oldx);
if (dist > OBJ_BOLT_RANGE)
flag = TRUE;
else
{
c_ptr = &cave[y][x];
if ((!c_ptr->fopen) || (c_ptr->cptr > 1))
{
flag = TRUE;
if (!c_ptr->fopen)
{
y = oldy;
x = oldx;
}
/* The ball hits and explodes... */
/* The explosion... */
for (i = y-max_dis; i <= y+max_dis; i++)
for (j = x-max_dis; j <= x+max_dis; j++)
if (in_bounds(i, j))
if (distance(y, x, i, j) <= max_dis)
if (los(y, x, i, j)) /* FIXED BUG V4.5 */
{
c_ptr = &cave[i][j];
if (c_ptr->tptr != 0)
if ((*destroy)(t_list[c_ptr->tptr].tval))
(void) delete_object(i, j);
if (c_ptr->fopen)
{
if (panel_contains(i, j)) print("*", i, j);
if (c_ptr->cptr > 1)
{
m_ptr = &m_list[c_ptr->cptr];
r_ptr = &c_list[m_ptr->mptr];
thit++;
dam = dam_hp;
if (harm_type & r_ptr->cdefense)
dam = dam*2;
else if (weapon_type & r_ptr->spells)
dam = dam / 4;
dam = (dam/(distance(i, j, y, x)+1));
k = mon_take_hit((int)c_ptr->cptr, dam);
if (k >= 0)
tkill++;
else
{
if (panel_contains(i, j))
{
tmp_str[0] = r_ptr->cchar;
tmp_str[1] = '\0';
print(tmp_str, i, j);
m_ptr->ml = TRUE;
}
}
}
}
}
/* show ball of whatever */
put_qio();
for (i = (y - 2); i <= (y + 2); i++)
for (j = (x - 2); j <= (x + 2); j++)
if (in_bounds(i, j))
if (panel_contains(i, j))
if (distance(y, x, i, j) <= max_dis)
{
c_ptr = &cave[i][j];
if (test_light(i, j))
lite_spot(i, j);
else if (c_ptr->cptr == 1)
lite_spot(i, j);
else if (c_ptr->cptr > 1)
if (m_list[c_ptr->cptr].ml)
lite_spot(i, j);
else
unlite_spot(i, j);
else
unlite_spot(i, j);
}
/* End explosion... */
if (thit == 1)
{
(void) sprintf(out_val,
"The %s envelopes a creature!",
descrip);
msg_print(out_val);
}
else if (thit > 1)
{
(void) sprintf(out_val,
"The %s envelopes several creatures!",
descrip);
msg_print(out_val);
}
if (tkill == 1)
msg_print("There is a scream of agony!");
else if (tkill > 1)
msg_print("There are several screams of agony!");
/* End ball hitting... */
}
else if (panel_contains(y, x))
{
print("*", y, x);
/* show bolt */
put_qio();
}
oldy = y;
oldx = x;
}
}
while (!flag);
}
/* Breath weapon works like a fire_ball, but affects the player. */
/* Note the area affect.... -RAK- */
breath(typ, y, x, dam_hp, ddesc)
int typ, y, x, dam_hp;
char *ddesc;
{
register int i, j;
int dam, max_dis;
int weapon_type, harm_type;
int (*destroy)();
register cave_type *c_ptr;
register monster_type *m_ptr;
register creature_type *r_ptr;
max_dis = 2;
get_flags(typ, &weapon_type, &harm_type, &destroy);
for (i = y-2; i <= y+2; i++)
for (j = x-2; j <= x+2; j++)
if (in_bounds(i, j))
if (distance(y, x, i, j) <= max_dis)
{
c_ptr = &cave[i][j];
if (c_ptr->tptr != 0)
if ((*destroy)(t_list[c_ptr->tptr].tval))
(void) delete_object(i, j);
if (c_ptr->fopen)
{