-
Notifications
You must be signed in to change notification settings - Fork 541
Expand file tree
/
Copy pathexplode.c
More file actions
1067 lines (1004 loc) · 39.1 KB
/
explode.c
File metadata and controls
1067 lines (1004 loc) · 39.1 KB
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
/* NetHack 3.7 explode.c $NHDT-Date: 1736530208 2025/01/10 09:30:08 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.122 $ */
/* Copyright (C) 1990 by Ken Arromdee */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
staticfn int explosionmask(struct monst *, uchar, char) NONNULLARG1;
staticfn void engulfer_explosion_msg(uchar, char);
/* Note: Arrays are column first, while the screen is row first */
static const int explosion[3][3] = {
{ S_expl_tl, S_expl_ml, S_expl_bl },
{ S_expl_tc, S_expl_mc, S_expl_bc },
{ S_expl_tr, S_expl_mr, S_expl_br } };
/* what to do at [x+i][y+j] for i=-1,0,1 and j=-1,0,1 */
enum explode_action {
EXPL_NONE = 0, /* not specified yet or no shield effect needed */
EXPL_MON = 1, /* monster is affected */
EXPL_HERO = 2, /* hero is affected */
EXPL_SKIP = 4 /* don't apply shield effect (out of bounds) */
};
/* check if shield effects are needed for location affected by explosion */
staticfn int
explosionmask(
struct monst *m, /* target monster (might be youmonst) */
uchar adtyp, /* damage type */
char olet) /* object class (only matters for AD_DISN) */
{
int res = EXPL_NONE;
if (m == &gy.youmonst) {
switch (adtyp) {
case AD_PHYS:
/* leave 'res' with EXPL_NONE */
break;
case AD_MAGM:
if (Antimagic)
res = EXPL_HERO;
break;
case AD_FIRE:
if (Fire_resistance)
res = EXPL_HERO;
break;
case AD_COLD:
if (Cold_resistance)
res = EXPL_HERO;
break;
case AD_DISN:
if ((olet == WAND_CLASS)
? (nonliving(m->data) || is_demon(m->data))
: Disint_resistance)
res = EXPL_HERO;
break;
case AD_ELEC:
if (Shock_resistance)
res = EXPL_HERO;
break;
case AD_DRST:
if (Poison_resistance)
res = EXPL_HERO;
break;
case AD_ACID:
if (Acid_resistance)
res = EXPL_HERO;
break;
default:
impossible("explosion type %d?", adtyp);
break;
}
} else {
/* 'm' is a monster */
switch (adtyp) {
case AD_PHYS:
break;
case AD_MAGM:
if (resists_magm(m))
res = EXPL_MON;
break;
case AD_FIRE:
if (resists_fire(m))
res = EXPL_MON;
break;
case AD_COLD:
if (resists_cold(m))
res = EXPL_MON;
break;
case AD_DISN:
if ((olet == WAND_CLASS)
? (nonliving(m->data) || is_demon(m->data)
|| is_vampshifter(m))
: !!resists_disint(m))
res = EXPL_MON;
break;
case AD_ELEC:
if (resists_elec(m))
res = EXPL_MON;
break;
case AD_DRST:
if (resists_poison(m))
res = EXPL_MON;
break;
case AD_ACID:
if (resists_acid(m))
res = EXPL_MON;
break;
default:
impossible("explosion type %d?", adtyp);
break;
}
}
return res;
}
staticfn void
engulfer_explosion_msg(uchar adtyp, char olet)
{
const char *adj = (char *) 0;
if (digests(u.ustuck->data)) {
switch (adtyp) {
case AD_FIRE:
adj = "heartburn";
break;
case AD_COLD:
adj = "chilly";
break;
case AD_DISN:
if (olet == WAND_CLASS)
adj = "irradiated by pure energy";
else
adj = "perforated";
break;
case AD_ELEC:
adj = "shocked";
break;
case AD_DRST:
adj = "poisoned";
break;
case AD_ACID:
adj = "an upset stomach";
break;
default:
adj = "fried";
break;
}
pline("%s gets %s!", Monnam(u.ustuck), adj);
} else {
switch (adtyp) {
case AD_FIRE:
adj = "toasted";
break;
case AD_COLD:
adj = "chilly";
break;
case AD_DISN:
if (olet == WAND_CLASS)
adj = "overwhelmed by pure energy";
else
adj = "perforated";
break;
case AD_ELEC:
adj = "shocked";
break;
case AD_DRST:
adj = "intoxicated";
break;
case AD_ACID:
adj = "burned";
break;
default:
adj = "fried";
break;
}
pline("%s gets slightly %s!", Monnam(u.ustuck), adj);
}
}
/* Note: I had to choose one of three possible kinds of "type" when writing
* this function: a wand type (like in zap.c), an adtyp, or an object type.
* Wand types get complex because they must be converted to adtyps for
* determining such things as fire resistance. Adtyps get complex in that
* they don't supply enough information--was it a player or a monster that
* did it, and with a wand, spell, or breath weapon? Object types share both
* these disadvantages....
*
* Note: anything with a AT_BOOM AD_PHYS attack uses PHYS_EXPL_TYPE for type.
*
* Important note about Half_physical_damage:
* Unlike losehp(), explode() makes the Half_physical_damage adjustments
* itself, so the caller should never have done that ahead of time.
* It has to be done this way because the damage value is applied to
* things beside the player. Care is taken within explode() to ensure
* that Half_physical_damage only affects the damage applied to the hero.
*/
void
explode(
coordxy x, coordxy y, /* explosion's location;
* adjacent spots are also affected */
int type, /* same as in zap.c; -(wand typ) for some WAND_CLASS */
int dam, /* damage amount */
char olet, /* object class or BURNING_OIL or MON_EXPLODE */
int expltype) /* explosion type: controls color of explosion glyphs */
{
int i, j, k, damu = dam;
boolean starting = 1;
boolean visible, any_shield;
int uhurt = 0; /* 0=unhurt, 1=items damaged, 2=you and items damaged */
const char *str = (const char *) 0;
struct monst *mtmp, *mdef = 0;
uchar adtyp;
int explmask[3][3]; /* 0=normal explosion, 1=do shieldeff, 2=do nothing */
coordxy xx, yy;
boolean shopdamage = FALSE, generic = FALSE,
do_hallu = FALSE, inside_engulfer, grabbed, grabbing;
coord grabxy;
char hallu_buf[BUFSZ], killr_buf[BUFSZ];
short exploding_wand_typ = 0;
boolean you_exploding = (olet == MON_EXPLODE && type >= 0);
boolean didmsg = FALSE;
if (olet == WAND_CLASS) { /* retributive strike */
/* 'type' is passed as (wand's object type * -1); save
object type and convert 'type' itself to zap-type */
if (type < 0) {
type = -type;
exploding_wand_typ = (short) type;
/* most attack wands produce specific explosions;
other types produce a generic magical explosion */
if (objects[type].oc_dir == RAY
&& type != WAN_DIGGING && type != WAN_SLEEP) {
type -= WAN_MAGIC_MISSILE;
if (type < 0 || type > 9) {
impossible("explode: wand has bad zap type (%d).", type);
type = 0;
}
} else
type = 0;
}
switch (Role_switch) {
case PM_CLERIC:
case PM_MONK:
case PM_WIZARD:
damu /= 5;
break;
case PM_HEALER:
case PM_KNIGHT:
damu /= 2;
break;
default:
break;
}
} else if (olet == BURNING_OIL) {
/* used to provide extra information to zap_over_floor() */
exploding_wand_typ = POT_OIL;
} else if (olet == SCROLL_CLASS) {
/* ditto */
exploding_wand_typ = SCR_FIRE;
} else if (olet == TRAP_EXPLODE) {
type = 0; /* hardcoded to generic magic explosion */
}
/* muse_unslime: SCR_FIRE */
if (expltype < 0) {
/* hero gets credit/blame for killing this monster, not others */
mdef = m_at(x, y);
expltype = -expltype;
}
/* if hero is engulfed and caused the explosion, only hero and
engulfer will be affected */
inside_engulfer = (u.uswallow && type >= 0);
/* held but not engulfed implies holder is reaching into second spot
so might get hit by double damage */
grabbed = grabbing = FALSE;
if (u.ustuck && !u.uswallow) {
if (Upolyd && sticks(gy.youmonst.data))
grabbing = TRUE;
else
grabbed = TRUE;
grabxy.x = u.ustuck->mx;
grabxy.y = u.ustuck->my;
} else
grabxy.x = grabxy.y = 0; /* lint suppression */
/* FIXME:
* It is possible for a grabber to be outside the explosion
* radius and reaching inside to hold the hero. If so, it ought
* to take damage (the extra half of double damage). It is also
* possible for poly'd hero to be outside the radius and reaching
* in to hold a monster. Hero should take damage in that situation.
*
* Probably the simplest way to handle this would be to expand
* the radius used when collecting targets but exclude everything
* beyond the regular radius which isn't reaching inside. Then
* skip harm to gear of any extended targets when inflicting damage.
*/
if (olet == MON_EXPLODE && !you_exploding) {
/* when explode() is called recursively, svk.killer.name might change
so retain a copy of the current value for this explosion */
str = strcpy(killr_buf, svk.killer.name);
do_hallu = (Hallucination
&& (strstri(str, "'s explosion")
|| strstri(str, "s' explosion")));
}
if (type == PHYS_EXPL_TYPE) {
/* currently only gas spores */
adtyp = AD_PHYS;
} else {
/* If str is e.g. "flaming sphere's explosion" from above, we want to
* still assign adtyp appropriately, but not replace str. */
const char *adstr = NULL;
switch (abs(type) % 10) {
case 0:
adstr = "magical blast";
adtyp = AD_MAGM;
break;
case 1:
adstr = (olet == BURNING_OIL) ? "burning oil"
: (olet == SCROLL_CLASS) ? "tower of flame" : "fireball";
/* fire damage, not physical damage */
adtyp = AD_FIRE;
break;
case 2:
adstr = "ball of cold";
adtyp = AD_COLD;
break;
case 4:
adstr = (olet == WAND_CLASS) ? "death field"
: "disintegration field";
adtyp = AD_DISN;
break;
case 5:
adstr = "ball of lightning";
adtyp = AD_ELEC;
break;
case 6:
adstr = "poison gas cloud";
adtyp = AD_DRST;
break;
case 7:
adstr = "splash of acid";
adtyp = AD_ACID;
break;
default:
impossible("explosion base type %d?", type);
return;
}
if (!str)
str = adstr;
}
any_shield = visible = FALSE;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++) {
xx = x + i - 1;
yy = y + j - 1;
if (!isok(xx, yy)) {
explmask[i][j] = EXPL_SKIP;
continue;
}
explmask[i][j] = EXPL_NONE;
if (u_at(xx, yy)) {
explmask[i][j] = explosionmask(&gy.youmonst, adtyp, olet);
}
/* can be both you and mtmp if you're swallowed or riding */
mtmp = m_at(xx, yy);
if (!mtmp && u_at(xx, yy))
mtmp = u.usteed;
if (mtmp && DEADMONSTER(mtmp))
mtmp = 0;
if (mtmp) {
explmask[i][j] |= explosionmask(mtmp, adtyp, olet);
}
if (mtmp && cansee(xx, yy) && !canspotmon(mtmp))
map_invisible(xx, yy);
else if (!mtmp)
(void) unmap_invisible(xx, yy);
if (cansee(xx, yy))
visible = TRUE;
if ((explmask[i][j] & (EXPL_MON | EXPL_HERO)) != 0)
any_shield = TRUE;
}
if (visible) {
/* Start the explosion */
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++) {
if (explmask[i][j] == EXPL_SKIP)
continue;
xx = x + i - 1;
yy = y + j - 1;
tmp_at(starting ? DISP_BEAM : DISP_CHANGE,
explosion_to_glyph(expltype, explosion[i][j]));
tmp_at(xx, yy);
starting = 0;
}
curs_on_u(); /* will flush screen and output */
if (any_shield && flags.sparkle) { /* simulate shield effect */
for (k = 0; k < SHIELD_COUNT; k++) {
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++) {
xx = x + i - 1;
yy = y + j - 1;
if ((explmask[i][j] & (EXPL_MON | EXPL_HERO)) != 0)
/*
* Bypass tmp_at() and send the shield glyphs
* directly to the buffered screen. tmp_at()
* will clean up the location for us later.
*/
show_glyph(xx, yy,
cmap_to_glyph(shield_static[k]));
}
curs_on_u(); /* will flush screen and output */
nh_delay_output();
}
/* Cover last shield glyph with blast symbol. */
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++) {
xx = x + i - 1;
yy = y + j - 1;
if ((explmask[i][j] & (EXPL_MON | EXPL_HERO)) != 0)
show_glyph(xx, yy,
explosion_to_glyph(expltype,
explosion[i][j]));
}
} else { /* delay a little bit. */
nh_delay_output();
nh_delay_output();
}
tmp_at(DISP_END, 0); /* clear the explosion */
} else {
if (olet == MON_EXPLODE || olet == TRAP_EXPLODE) {
str = "explosion";
generic = TRUE;
}
if (!Deaf && olet != SCROLL_CLASS) {
Soundeffect(se_blast, 75);
You_hear("a blast.");
didmsg = TRUE;
}
}
if (!Deaf && !didmsg)
pline("Boom!");
/* apply effects to monsters and floor objects first, in case the
damage to the hero is fatal and leaves bones */
if (dam) {
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
int itemdmg = 0;
if (explmask[i][j] == EXPL_SKIP)
continue;
xx = x + i - 1;
yy = y + j - 1;
if (u_at(xx, yy)) {
uhurt = ((explmask[i][j] & EXPL_HERO) != 0) ? 1 : 2;
/* If the player is attacking via polyself into something
* with an explosion attack, leave them (and their gear)
* unharmed, to avoid punishing them from using such
* polyforms creatively */
if (!svc.context.mon_moving && you_exploding)
uhurt = 0;
} else if (inside_engulfer) {
/* for inside_engulfer, only <u.ux,u.uy> is affected */
continue;
}
/* Affect the floor unless the player caused the explosion
* from inside their engulfer. */
if (!(u.uswallow && !svc.context.mon_moving))
(void) zap_over_floor(xx, yy, type,
&shopdamage, FALSE,
exploding_wand_typ);
mtmp = m_at(xx, yy);
if (!mtmp && u_at(xx, yy))
mtmp = u.usteed;
if (!mtmp)
continue;
if (do_hallu) {
int tryct = 0;
/* replace "gas spore" with a different description
for each target (we can't distinguish personal names
like "Barney" here in order to suppress "the" below,
so avoid any which begins with a capital letter) */
do {
Sprintf(hallu_buf, "%s explosion",
s_suffix(rndmonnam((char *) 0)));
} while (*hallu_buf != lowc(*hallu_buf) && ++tryct < 20);
str = hallu_buf;
}
if (engulfing_u(mtmp)) {
engulfer_explosion_msg(adtyp, olet);
} else if (cansee(xx, yy)) {
if (mtmp->m_ap_type)
seemimic(mtmp);
pline("%s is caught in the %s!", Monnam(mtmp), str);
}
itemdmg = destroy_items(mtmp, (int) adtyp, dam);
if (adtyp == AD_FIRE) {
(void) burnarmor(mtmp);
ignite_items(mtmp->minvent);
}
if ((explmask[i][j] & EXPL_MON) != 0) {
/* Damage from ring/wand explosion isn't itself
* electrical in nature, nor is damage from freezing
* potion really cold in nature, nor is damage from
* boiling potion or exploding oil; only burning items
* damage is the "same type" as the explosion. Because
* this is imperfect and marginal (burning items only
* deal 1 damage), ignore it for golemeffects(). */
golemeffects(mtmp, (int) adtyp, dam);
mtmp->mhp -= itemdmg; /* item destruction dmg */
} else {
/* Call resist with 0 and do damage manually so 1) we can
* get out the message before doing the damage, and 2) we
* can call mondied, not killed, if it's not your blast.
*/
int mdam = dam;
if (resist(mtmp, olet, 0, FALSE)) {
/* inside_engulfer: <xx,yy> == <u.ux,u.uy> */
if (cansee(xx, yy) || inside_engulfer)
pline("%s resists the %s!", Monnam(mtmp), str);
mdam = (dam + 1) / 2;
}
/* if grabber is reaching into hero's spot and
hero's spot is within explosion radius, grabber
gets hit by double damage */
if (grabbed && mtmp == u.ustuck && next2u(x, y))
mdam *= 2;
/* being resistant to opposite type of damage makes
target more vulnerable to current type of damage
(when target is also resistant to current type,
we won't get here) */
if (resists_cold(mtmp) && adtyp == AD_FIRE)
mdam *= 2;
else if (resists_fire(mtmp) && adtyp == AD_COLD)
mdam *= 2;
mtmp->mhp -= mdam + itemdmg;
}
if (DEADMONSTER(mtmp)) {
int xkflg = ((adtyp == AD_FIRE
&& completelyburns(mtmp->data))
? XKILL_NOCORPSE : 0);
if (!svc.context.mon_moving) {
xkilled(mtmp, XKILL_GIVEMSG | xkflg);
} else if (mdef && mtmp == mdef) {
/* 'mdef' killed self trying to cure being turned
* into slime due to some action by the player.
* Hero gets the credit (experience) and most of
* the blame (possible loss of alignment and/or
* luck and/or telepathy depending on mtmp) but
* doesn't break pacifism. xkilled()'s message
* would be "you killed <mdef>" so give our own.
*/
if (cansee(mtmp->mx, mtmp->my) || canspotmon(mtmp))
pline("%s is %s!", Monnam(mtmp),
xkflg ? "burned completely"
: nonliving(mtmp->data) ? "destroyed"
: "killed");
xkilled(mtmp, XKILL_NOMSG | XKILL_NOCONDUCT | xkflg);
} else {
if (xkflg)
adtyp = AD_RBRE; /* no corpse */
monkilled(mtmp, "", (int) adtyp);
}
} else if (!svc.context.mon_moving) {
/* all affected monsters, even if mdef is set */
setmangry(mtmp, TRUE);
}
}
}
}
/* Do your injury last */
if (uhurt) {
/* give message for any monster-induced explosion
or player-induced one other than scroll of fire */
if (flags.verbose && (type < 0 || olet != SCROLL_CLASS)) {
if (do_hallu) { /* (see explanation above) */
do {
Sprintf(hallu_buf, "%s explosion",
s_suffix(rndmonnam((char *) 0)));
} while (*hallu_buf != lowc(*hallu_buf));
str = hallu_buf;
}
You("are caught in the %s!", str);
iflags.last_msg = PLNMSG_CAUGHT_IN_EXPLOSION;
}
/* do property damage first, in case we end up leaving bones */
if (adtyp == AD_FIRE)
burn_away_slime();
if (Invulnerable) {
damu = 0;
You("are unharmed!");
} else if (adtyp == AD_PHYS || adtyp == AD_ACID)
damu = Maybe_Half_Phys(damu);
if (adtyp == AD_FIRE) {
(void) burnarmor(&gy.youmonst);
ignite_items(gi.invent);
}
(void) destroy_items(&gy.youmonst, (int) adtyp, dam);
ugolemeffects((int) adtyp, damu);
if (uhurt == 2) {
/* if poly'd hero is grabbing another victim, hero takes
double damage (note: don't rely on u.ustuck here because
that victim might have been killed when hit by the blast) */
if (grabbing && dist2((int) grabxy.x, (int) grabxy.y, x, y) <= 2)
damu *= 2;
/* hero does not get same fire-resistant vs cold and
cold-resistant vs fire double damage as monsters [why not?] */
if (Upolyd)
u.mh -= damu;
else
u.uhp -= damu;
disp.botl = TRUE;
}
/* You resisted the damage, lets not keep that to ourselves */
if (uhurt == 1)
monstseesu_ad(adtyp);
else
monstunseesu_ad(adtyp);
if (u.uhp <= 0 || (Upolyd && u.mh <= 0)) {
if (Upolyd) {
rehumanize();
} else {
if (olet == MON_EXPLODE) {
if (generic) /* explosion was unseen; str=="explosion", */
; /* svk.killer.name=="gas spore's explosion". */
else if (str != svk.killer.name && str != hallu_buf)
Strcpy(svk.killer.name, str);
svk.killer.format = KILLED_BY_AN;
} else if (olet == TRAP_EXPLODE) {
svk.killer.format = NO_KILLER_PREFIX;
Snprintf(svk.killer.name, sizeof svk.killer.name,
"caught %sself in a %s", uhim(),
str);
} else if (type >= 0 && olet != SCROLL_CLASS) {
svk.killer.format = NO_KILLER_PREFIX;
Snprintf(svk.killer.name, sizeof svk.killer.name,
"caught %sself in %s own %s", uhim(),
uhis(), str);
} else {
svk.killer.format = (!strcmpi(str, "tower of flame")
|| !strcmpi(str, "fireball"))
? KILLED_BY_AN
: KILLED_BY;
Strcpy(svk.killer.name, str);
}
if (iflags.last_msg == PLNMSG_CAUGHT_IN_EXPLOSION
|| iflags.last_msg == PLNMSG_TOWER_OF_FLAME) /*seffects()*/
pline("It is fatal.");
else
pline_The("%s is fatal.", str);
/* Known BUG: BURNING suppresses corpse in bones data,
but done does not handle killer reason correctly */
done((adtyp == AD_FIRE) ? BURNING : DIED);
}
}
exercise(A_STR, FALSE);
}
if (shopdamage) {
pay_for_damage((adtyp == AD_FIRE) ? "burn away"
: (adtyp == AD_COLD) ? "shatter"
: (adtyp == AD_DISN) ? "disintegrate"
: "destroy",
FALSE);
}
/* explosions are noisy */
i = dam * dam;
if (i < 50)
i = 50; /* in case random damage is very small */
if (inside_engulfer)
i = (i + 3) / 4;
wake_nearto(x, y, i);
}
struct scatter_chain {
struct scatter_chain *next; /* pointer to next scatter item */
struct obj *obj; /* pointer to the object */
coordxy ox; /* location of */
coordxy oy; /* item */
schar dx; /* direction of */
schar dy; /* travel */
int range; /* range of object */
boolean stopped; /* flag for in-motion/stopped */
};
/*
* scflags:
* VIS_EFFECTS Add visual effects to display
* MAY_HITMON Objects may hit monsters
* MAY_HITYOU Objects may hit hero
* MAY_HIT Objects may hit you or monsters
* MAY_DESTROY Objects may be destroyed at random
* MAY_FRACTURE Stone objects can be fractured (statues, boulders)
*/
/* returns number of scattered objects */
long
scatter(coordxy sx, coordxy sy, /* location of objects to scatter */
int blastforce, /* force behind the scattering */
unsigned int scflags,
struct obj *obj) /* only scatter this obj */
{
struct obj *otmp;
int tmp;
int farthest = 0;
uchar typ;
long qtmp;
boolean used_up;
boolean individual_object = obj ? TRUE : FALSE;
boolean shop_origin, lostgoods = FALSE;
struct monst *mtmp, *shkp = 0;
struct scatter_chain *stmp, *stmp2 = 0;
struct scatter_chain *schain = (struct scatter_chain *) 0;
long total = 0L;
if (individual_object && (obj->ox != sx || obj->oy != sy))
impossible("scattered object <%d,%d> not at scatter site <%d,%d>",
obj->ox, obj->oy, sx, sy);
shop_origin = ((shkp = shop_keeper(*in_rooms(sx, sy, SHOPBASE))) != 0
&& costly_spot(sx, sy));
if (shop_origin)
credit_report(shkp, 0, TRUE); /* establish baseline, without msgs */
while ((otmp = (individual_object ? obj
: svl.level.objects[sx][sy])) != 0) {
if (otmp == uball || otmp == uchain) {
boolean waschain = (otmp == uchain);
Soundeffect(se_chain_shatters, 25);
pline_The("chain shatters!");
unpunish();
if (waschain)
continue;
}
if (otmp->quan > 1L) {
qtmp = otmp->quan - 1L;
if (qtmp > LARGEST_INT)
qtmp = LARGEST_INT;
qtmp = (long) rnd((int) qtmp);
otmp = splitobj(otmp, qtmp);
} else {
obj = (struct obj *) 0; /* all used */
}
obj_extract_self(otmp);
used_up = FALSE;
/* 9 in 10 chance of fracturing boulders or statues */
if ((scflags & MAY_FRACTURE) != 0
&& (otmp->otyp == BOULDER || otmp->otyp == STATUE)
&& rn2(10)) {
if (otmp->otyp == BOULDER) {
if (cansee(sx, sy)) {
pline("%s apart.", Tobjnam(otmp, "break"));
} else {
Soundeffect(se_stone_breaking, 100);
You_hear("stone breaking.");
}
fracture_rock(otmp);
place_object(otmp, sx, sy);
if ((otmp = sobj_at(BOULDER, sx, sy)) != 0) {
/* another boulder here, restack it to the top */
obj_extract_self(otmp);
place_object(otmp, sx, sy);
}
} else {
struct trap *trap;
if ((trap = t_at(sx, sy)) && trap->ttyp == STATUE_TRAP)
deltrap(trap);
if (cansee(sx, sy)) {
pline("%s.", Tobjnam(otmp, "crumble"));
} else {
Soundeffect(se_stone_crumbling, 100);
You_hear("stone crumbling.");
}
(void) break_statue(otmp);
place_object(otmp, sx, sy); /* put fragments on floor */
}
newsym(sx, sy); /* in case it's beyond radius of 'farthest' */
used_up = TRUE;
/* 1 in 10 chance of destruction of obj; glass, egg destruction */
} else if ((scflags & MAY_DESTROY) != 0
&& (!rn2(10) || (objects[otmp->otyp].oc_material == GLASS
|| otmp->otyp == EGG))) {
if (breaks(otmp, sx, sy))
used_up = TRUE;
}
if (!used_up) {
stmp = (struct scatter_chain *) alloc(sizeof *stmp);
stmp->next = (struct scatter_chain *) 0;
stmp->obj = otmp;
stmp->ox = sx;
stmp->oy = sy;
tmp = rn2(N_DIRS); /* get the direction */
stmp->dx = xdir[tmp];
stmp->dy = ydir[tmp];
tmp = blastforce - (otmp->owt / 40);
if (tmp < 1)
tmp = 1;
stmp->range = rnd(tmp); /* anywhere up to that determ. by wt */
if (farthest < stmp->range)
farthest = stmp->range;
stmp->stopped = FALSE;
if (!schain)
schain = stmp;
else
stmp2->next = stmp;
stmp2 = stmp;
}
}
while (farthest-- > 0) {
for (stmp = schain; stmp; stmp = stmp->next) {
if ((stmp->range-- > 0) && (!stmp->stopped)) {
gt.thrownobj = stmp->obj; /* mainly in case it kills hero */
gb.bhitpos.x = stmp->ox + stmp->dx;
gb.bhitpos.y = stmp->oy + stmp->dy;
if (isok(gb.bhitpos.x, gb.bhitpos.y))
typ = levl[gb.bhitpos.x][gb.bhitpos.y].typ;
else
typ = STONE;
if (!isok(gb.bhitpos.x, gb.bhitpos.y)) {
gb.bhitpos.x -= stmp->dx;
gb.bhitpos.y -= stmp->dy;
stmp->stopped = TRUE;
} else if (!ZAP_POS(typ)
|| closed_door(gb.bhitpos.x, gb.bhitpos.y)) {
gb.bhitpos.x -= stmp->dx;
gb.bhitpos.y -= stmp->dy;
stmp->stopped = TRUE;
} else if ((mtmp = m_at(gb.bhitpos.x, gb.bhitpos.y)) != 0) {
if (scflags & MAY_HITMON) {
stmp->range--;
if (ohitmon(mtmp, stmp->obj, 1, FALSE)) {
stmp->obj = (struct obj *) 0;
stmp->stopped = TRUE;
}
}
} else if (u_at(gb.bhitpos.x, gb.bhitpos.y)) {
if (scflags & MAY_HITYOU) {
int hitvalu, hitu;
if (gm.multi)
nomul(0);
hitvalu = 8 + stmp->obj->spe;
if (bigmonst(gy.youmonst.data))
hitvalu++;
hitu = thitu(hitvalu, dmgval(stmp->obj, &gy.youmonst),
&stmp->obj, (char *) 0);
if (!stmp->obj)
stmp->stopped = TRUE;
if (hitu) {
stmp->range -= 3;
stop_occupation();
}
}
} else {
if (scflags & VIS_EFFECTS) {
/* tmp_at(gb.bhitpos.x, gb.bhitpos.y); */
/* nh_delay_output(); */
}
}
stmp->ox = gb.bhitpos.x;
stmp->oy = gb.bhitpos.y;
if (IS_SINK(levl[stmp->ox][stmp->oy].typ))
stmp->stopped = TRUE;
gt.thrownobj = (struct obj *) 0;
}
}
}
for (stmp = schain; stmp; stmp = stmp2) {
coordxy x, y;
boolean obj_left_shop = FALSE;
stmp2 = stmp->next;
x = stmp->ox;
y = stmp->oy;
if (stmp->obj) {
if (x != sx || y != sy) {
total += stmp->obj->quan;
obj_left_shop = (shop_origin && !costly_spot(x, y));
}
if (!flooreffects(stmp->obj, x, y, "land")) {
if (obj_left_shop
&& strchr(u.urooms, *in_rooms(u.ux, u.uy, SHOPBASE))) {
/* At the moment this only takes on gold. While it is
simple enough to call addtobill for other items that
leave the shop due to scatter(), by default the hero
will get billed for the full shopkeeper asking-price
on the object's way out of shop. That can leave the
hero in a pickle. Even if the hero then manages to
retrieve the item and drop it back inside the shop,
the owed charges will only be reduced at that point
by the lesser shopkeeper buying-price.
The non-gold situation will likely get adjusted
further.
*/
if (stmp->obj->otyp == GOLD_PIECE) {
addtobill(stmp->obj, FALSE, FALSE, TRUE);
lostgoods = TRUE;
}
}
place_object(stmp->obj, x, y);
stackobj(stmp->obj);
}
}
free((genericptr_t) stmp);
newsym(x, y);
}
newsym(sx, sy);
if (u_at(sx, sy) && u.uundetected && hides_under(gy.youmonst.data))
(void) hideunder(&gy.youmonst);
if (((mtmp = m_at(sx, sy)) != 0) && mtmp->mtrapped)
mtmp->mtrapped = 0;
maybe_unhide_at(sx, sy);
if (lostgoods) /* implies shop_origin and therefore shkp valid */
credit_report(shkp, 1, FALSE);
return total;
}
/*
* Splatter burning oil from x,y to the surrounding area.
*
* This routine should really take a how and direction parameters.
* The how is how it was caused, e.g. kicked verses thrown. The
* direction is which way to spread the flaming oil. Different
* "how"s would give different dispersal patterns. For example,
* kicking a burning flask will splatter differently from a thrown
* flask hitting the ground.
*
* For now, just perform a "regular" explosion.
*/
void
splatter_burning_oil(coordxy x, coordxy y, boolean diluted_oil)
{
int dmg = d(diluted_oil ? 3 : 4, 4);
/* ZT_SPELL(ZT_FIRE) = ZT_SPELL(AD_FIRE-1) = 10+(2-1) = 11 */
#define ZT_SPELL_O_FIRE 11 /* value kludge, see zap.c */
explode(x, y, ZT_SPELL_O_FIRE, dmg, BURNING_OIL, EXPL_FIERY);
}
/* lit potion of oil is exploding; extinguish it as a light source before
possibly killing the hero and attempting to save bones */
void
explode_oil(struct obj *obj, coordxy x, coordxy y)
{
boolean diluted_oil = obj->odiluted;
if (!obj->lamplit)
impossible("exploding unlit oil");
end_burn(obj, TRUE);
obj->how_lost = LOST_EXPLODING;
splatter_burning_oil(x, y, diluted_oil);
}
/* Convert a damage type into an explosion display type. */
int
adtyp_to_expltype(const int adtyp)
{
switch(adtyp) {
case AD_ELEC:
/* Electricity isn't magical, but there currently isn't an electric
* explosion type. Magical is the next best thing. */
case AD_SPEL:
case AD_DREN:
case AD_ENCH:
return EXPL_MAGICAL;
case AD_FIRE:
return EXPL_FIERY;
case AD_COLD:
return EXPL_FROSTY;
case AD_DRST:
case AD_DRDX: