-
Notifications
You must be signed in to change notification settings - Fork 21
/
mon.c
6772 lines (6263 loc) · 232 KB
/
mon.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
/* NetHack 3.6 mon.c $NHDT-Date: 1569276991 2019/09/23 22:16:31 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.297 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Derek S. Ray, 2015. */
/* NetHack may be freely redistributed. See license for details. */
/* If you're using precompiled headers, you don't want this either */
#ifdef MICROPORT_BUG
#define MKROOM_H
#endif
#include "hack.h"
#include "mfndpos.h"
#include <ctype.h>
STATIC_VAR boolean rise_msg, disintegested;
STATIC_DCL void FDECL(sanity_check_single_mon, (struct monst *, BOOLEAN_P,
const char *));
STATIC_DCL boolean FDECL(restrap, (struct monst *));
STATIC_DCL long FDECL(mm_displacement, (struct monst *, struct monst *));
STATIC_DCL int NDECL(pick_animal);
STATIC_DCL void FDECL(kill_eggs, (struct obj *));
STATIC_DCL int FDECL(pickvampshape, (struct monst *));
STATIC_DCL boolean FDECL(isspecmon, (struct monst *));
STATIC_DCL boolean FDECL(validspecmon, (struct monst *, int));
STATIC_DCL struct permonst *FDECL(accept_newcham_form, (struct monst *, int));
STATIC_DCL struct obj *FDECL(make_corpse, (struct monst *, unsigned));
STATIC_DCL short FDECL(m_chooserace, (unsigned long));
STATIC_OVL long FDECL(mm_2way_aggression, (struct monst *, struct monst *));
STATIC_DCL void FDECL(m_detach, (struct monst *, struct permonst *));
STATIC_DCL void FDECL(lifesaved_monster, (struct monst *));
STATIC_DCL void FDECL(migrate_mon, (struct monst *, XCHAR_P, XCHAR_P));
STATIC_DCL boolean FDECL(ok_to_obliterate, (struct monst *));
STATIC_DCL void FDECL(icequeenrevive, (struct monst *));
/* note: duplicated in dog.c */
#define LEVEL_SPECIFIC_NOCORPSE(mdat) \
(Is_rogue_level(&u.uz) \
|| (level.flags.graveyard && is_undead(mdat) && rn2(3)))
/* A specific combination of x_monnam flags for livelogging. The livelog
* shouldn't show that you killed a hallucinatory monster and not what it
* actually is. */
#define livelog_mon_nam(mtmp) \
x_monnam(mtmp, ARTICLE_THE, (char *) 0, \
(SUPPRESS_IT | SUPPRESS_HALLUCINATION), FALSE)
#if 0
/* part of the original warning code which was replaced in 3.3.1 */
const char *warnings[] = {
"white", "pink", "red", "ruby", "purple", "black"
};
#endif /* 0 */
STATIC_OVL void
sanity_check_single_mon(mtmp, chk_geno, msg)
struct monst *mtmp;
boolean chk_geno;
const char *msg;
{
struct permonst *mptr = mtmp->data;
int mx = mtmp->mx, my = mtmp->my;
if (!mptr || mptr < &mons[LOW_PM] || mptr >= &mons[NUMMONS]) {
/* most sanity checks issue warnings if they detect a problem,
but this would be too extreme to keep going */
panic("illegal mon data %s; mnum=%d (%s)",
fmt_ptr((genericptr_t) mptr), mtmp->mnum, msg);
} else {
int mndx = monsndx(mptr);
if (mtmp->mnum != mndx) {
impossible("monster mnum=%d, monsndx=%d (%s)",
mtmp->mnum, mndx, msg);
mtmp->mnum = mndx;
}
if (DEADMONSTER(mtmp)) {
#if 0
/* bad if not fmons list or if not vault guard */
if (strcmp(msg, "fmon") || !mtmp->isgd)
impossible("dead monster on %s; %s at <%d,%d>",
msg, mons[mndx].mname, mtmp->mx, mtmp->my);
#endif
return;
}
if (chk_geno && (mvitals[mndx].mvflags & G_GENOD) != 0)
impossible("genocided %s in play (%s)", mons[mndx].mname, msg);
}
if (mtmp->isshk && !has_eshk(mtmp))
impossible("shk without eshk (%s)", msg);
if (mtmp->ispriest && !has_epri(mtmp))
impossible("priest without epri (%s)", msg);
if (mtmp->isgd && !has_egd(mtmp))
impossible("guard without egd (%s)", msg);
if (mtmp->isminion && !has_emin(mtmp))
impossible("minion without emin (%s)", msg);
/* guardian angel on astral level is tame but has emin rather than edog */
if (mtmp->mtame && !has_edog(mtmp) && !mtmp->isminion)
impossible("pet without edog (%s)", msg);
if (mtmp->mtrapped) {
if (mtmp->wormno) {
/* TODO: how to check worm in trap? */
} else if (!t_at(mtmp->mx, mtmp->my))
impossible("trapped without a trap (%s)", msg);
}
/* monster is hiding? */
if (mtmp->mundetected) {
struct trap *t;
if (!isok(mx, my)) /* caller will have checked this but not fixed it */
mx = my = 0;
if (mtmp == u.ustuck)
impossible("hiding monster stuck to you (%s)", msg);
if (m_at(mtmp->mx, mtmp->my) == mtmp
&& hides_under(mtmp->data) && !OBJ_AT(mtmp->mx, mtmp->my))
impossible("mon hiding under nonexistent obj (%s)", msg);
if (mtmp->data->mlet == S_EEL
&& !is_damp_terrain(mtmp->mx, mtmp->my) && !Is_waterlevel(&u.uz))
impossible("eel hiding out of water (%s)", msg);
if (ceiling_hider(mptr)
/* normally !accessible would be overridable with passes_walls,
but not for hiding on the ceiling */
&& (!has_ceiling(&u.uz) || !accessible(mx, my)))
impossible("ceiling hider hiding %s (%s)",
!has_ceiling(&u.uz) ? "without ceiling"
: "in solid stone",
msg);
if (mtmp->mtrapped && (t = t_at(mx, my)) != 0 && !is_pit(t->ttyp))
impossible("hiding while trapped in a non-pit (%s)", msg);
}
}
void
mon_sanity_check()
{
int x, y;
struct monst *mtmp, *m;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
/* dead monsters should still have sane data */
sanity_check_single_mon(mtmp, TRUE, "fmon");
if (DEADMONSTER(mtmp) && !mtmp->isgd)
continue;
x = mtmp->mx, y = mtmp->my;
if (!isok(x, y) && !(mtmp->isgd && x == 0 && y == 0)) {
impossible("mon (%s) claims to be at <%d,%d>?",
fmt_ptr((genericptr_t) mtmp), x, y);
} else if (mtmp == u.usteed) {
/* steed is in fmon list but not on the map; its
<mx,my> coordinates should match hero's location */
if (x != u.ux || y != u.uy)
impossible("steed (%s) claims to be at <%d,%d>?",
fmt_ptr((genericptr_t) mtmp), x, y);
} else if (mtmp->ridden_by) {
continue;
} else if (mtmp != (m = level.monsters[x][y])) {
if (!m || m->ridden_by != mtmp->m_id)
impossible("mon (%s) at <%d,%d> is not there!",
fmt_ptr((genericptr_t) mtmp), x, y);
} else if (mtmp->wormno) {
sanity_check_worm(mtmp);
}
}
for (x = 1; x < COLNO; x++)
for (y = 0; y < ROWNO; y++)
if ((mtmp = level.monsters[x][y]) != 0) {
for (m = fmon; m; m = m->nmon)
if (m == mtmp)
break;
if (!m)
impossible("map mon (%s) at <%d,%d> not in fmon list!",
fmt_ptr((genericptr_t) mtmp), x, y);
else if (mtmp == u.usteed)
impossible("steed (%s) is on the map at <%d,%d>!",
fmt_ptr((genericptr_t) mtmp), x, y);
else if ((mtmp->mx != x || mtmp->my != y)
&& mtmp->data != &mons[PM_LONG_WORM] && !mtmp->ridden_by)
impossible("map mon (%s) at <%d,%d> is found at <%d,%d>?",
fmt_ptr((genericptr_t) mtmp),
mtmp->mx, mtmp->my, x, y);
}
for (mtmp = migrating_mons; mtmp; mtmp = mtmp->nmon) {
sanity_check_single_mon(mtmp, FALSE, "migr");
}
}
/* Would monster be OK with poison gas? */
/* Does not check for actual poison gas at the location. */
/* Returns one of M_POISONGAS_foo */
int
m_poisongas_ok(mtmp)
struct monst *mtmp;
{
int px, py;
/* Non living, non breathing, immune monsters are not concerned */
if (nonliving(mtmp->data) || is_vampshifter(mtmp)
|| breathless(mtmp->data) || immune_poisongas(mtmp->data))
return M_POISONGAS_OK;
/* not is_swimmer(); assume that non-fish are swimming on
the surface and breathing the air above it periodically
unless located at water spot on plane of water */
px = (mtmp == &youmonst) ? u.ux : mtmp->mx;
py = (mtmp == &youmonst) ? u.uy : mtmp->my;
if ((mtmp->data->mlet == S_EEL || Is_waterlevel(&u.uz))
&& isok(px, py) && is_pool(px, py))
return M_POISONGAS_OK;
/* exclude monsters with poison gas breath attack:
adult green dragon and Tiamat (and iron golem,
but nonliving() and breathless() tests also catch that) */
if (attacktype_fordmg(mtmp->data, AT_BREA, AD_DRST)
|| attacktype_fordmg(mtmp->data, AT_BREA, AD_RBRE))
return M_POISONGAS_OK;
if ((mtmp == &youmonst)
&& (u.uinvulnerable || Breathless || Underwater))
return M_POISONGAS_OK;
if ((resists_poison(mtmp) || defended(mtmp, AD_DRST) || (mtmp == &youmonst))
&& Poison_resistance)
return M_POISONGAS_MINOR;
return M_POISONGAS_BAD;
}
/* Return TRUE if this monster is capable of converting other monsters into
* zombies. */
boolean
zombie_maker(pm)
struct permonst * pm;
{
switch(pm->mlet) {
case S_ZOMBIE:
/* Z-class monsters that aren't actually zombies go here */
if (is_not_zombie(pm))
return FALSE;
return TRUE;
}
return FALSE;
}
/* From xNetHack: return the monster index of the zombie monster which this monster could be
* turned into, or NON_PM if it doesn't have a direct counterpart. Sort of the
* zombie-specific inverse of undead_to_corpse.
* If a zombie gets passed to this function, it should return NON_PM, not the
* same monster again. */
int
zombie_form(pm)
struct permonst *pm;
{
switch (pm->mlet) {
case S_KOBOLD:
return PM_KOBOLD_ZOMBIE;
case S_ORC:
return PM_ORC_ZOMBIE;
case S_GIANT:
if (pm == &mons[PM_ETTIN])
return PM_ETTIN_ZOMBIE;
return PM_GIANT_ZOMBIE;
case S_HUMAN:
case S_KOP:
if (is_elf(pm))
return PM_ELF_ZOMBIE;
if (is_drow(pm))
return PM_DROW_ZOMBIE;
if (is_dwarf(pm))
return PM_DWARF_ZOMBIE;
if (is_gnome(pm))
return PM_GNOME_ZOMBIE;
if (is_orc(pm))
return PM_ORC_ZOMBIE;
if (is_hobbit(pm))
return PM_HOBBIT_ZOMBIE;
if (is_giant(pm))
return PM_GIANT_ZOMBIE;
if (is_illithid(pm))
return NON_PM;
return PM_HUMAN_ZOMBIE;
case S_HUMANOID:
if (is_dwarf(pm))
return PM_DWARF_ZOMBIE;
if (is_hobbit(pm))
return PM_HOBBIT_ZOMBIE;
if (is_gnoll(pm))
return PM_GNOLL_WITHERLING;
else
break;
case S_GNOME:
return PM_GNOME_ZOMBIE;
}
return NON_PM;
}
void
become_flayer(mdef)
struct monst* mdef;
{
struct permonst* mdat = mdef->data;
boolean willspot, couldspot = canspotmon(mdef);
mdef->data = &mons[PM_MIND_FLAYER];
willspot = canspotmon(mdef);
mdef->data = mdat;
if (couldspot && willspot) {
/* only print if you can spot both the dying monster and the arising
* mind flayer */
pline("%s transforms into a mind flayer!", Monnam(mdef));
}
if (newcham(mdef, &mons[PM_MIND_FLAYER], FALSE, FALSE)) {
char name[PL_PSIZ];
/* off-chance Izchak succumbs to a mind flayer larva's physical attack */
if (is_izchak(mdef, TRUE) && racial_human(mdef)) {
pline("But wait! %s transforms again into his true form!",
Monnam(mdef));
newcham(mdef, &mons[PM_ARCHANGEL], FALSE, FALSE);
mdef->mcanmove = 1;
mdef->mfrozen = 0;
mdef->mstone = 0;
mdef->msick = 0;
mdef->mdiseased = 0;
mdef->mwither = 0;
mdef->mconf = 0;
mdef->mstun = 0;
free_erac(mdef);
mdef->mhp = mdef->mhpmax = 1500;
newsym(mdef->mx, mdef->my);
return;
}
/* don't continue if failed to turn into a mind flayer (extinct?) */
mdef->mcanmove = 1;
mdef->mfrozen = 0;
set_malign(mdef);
/* clear other data structures tracking shk information */
if (mdef->isshk)
shkgone(mdef);
/* wipe all mextra structs (to prevent a compromised shk/priest/guard/etc
* from continuing to behave as what it used to be), then restore name
* if present */
name[0] = '\0';
if (has_eshk(mdef)) {
if (!Hallucination)
Strcpy(name, shkname(mdef));
free_eshk(mdef);
}
if (has_epri(mdef))
free_epri(mdef);
if (has_egd(mdef))
free_egd(mdef);
if (name[0] != '\0') {
christen_monst(mdef, name);
}
mdef->isshk = mdef->isminion = mdef->isgd = mdef->ispriest = 0;
/* if mdef->iswiz, leave that alone - the Wizard doesn't have any mextra
* structs and can handle being transformed into other monster types */
newsym(mdef->mx, mdef->my); /* cover bases */
/* The mhp is presumably the fraction of what it was before -
* less than zero. Set it to full. */
mdef->mhp = mdef->mhpmax;
}
}
/* convert the monster index of an undead to its living counterpart */
int
undead_to_corpse(mndx)
int mndx;
{
switch (mndx) {
case PM_KOBOLD_ZOMBIE:
case PM_KOBOLD_MUMMY:
mndx = PM_KOBOLD;
break;
case PM_DWARF_ZOMBIE:
case PM_DWARF_MUMMY:
mndx = PM_DWARF;
break;
case PM_GNOME_ZOMBIE:
case PM_GNOME_MUMMY:
mndx = PM_GNOME;
break;
case PM_ORC_ZOMBIE:
case PM_ORC_MUMMY:
mndx = PM_ORC;
break;
case PM_ELF_ZOMBIE:
case PM_ELF_MUMMY:
mndx = PM_ELF;
break;
case PM_DROW_ZOMBIE:
case PM_DROW_MUMMY:
mndx = PM_DROW;
break;
case PM_HOBBIT_ZOMBIE:
case PM_HOBBIT_MUMMY:
mndx = PM_HOBBIT;
break;
case PM_VAMPIRE:
case PM_VAMPIRE_NOBLE:
case PM_VAMPIRE_ROYAL:
case PM_VAMPIRE_MAGE:
case PM_HUMAN_ZOMBIE:
case PM_HUMAN_MUMMY:
mndx = PM_HUMAN;
break;
case PM_GIANT_ZOMBIE:
case PM_GIANT_MUMMY:
mndx = PM_GIANT;
break;
case PM_ETTIN_ZOMBIE:
case PM_ETTIN_MUMMY:
mndx = PM_ETTIN;
break;
case PM_GNOLL_WITHERLING:
mndx = PM_GNOLL;
default:
break;
}
return mndx;
}
/* Convert the monster index of some monsters (such as quest guardians)
* to their generic species type.
*
* Return associated character class monster, rather than species
* if mode is 1.
*/
int
genus(mndx, mode)
int mndx, mode;
{
switch (mndx) {
/* Quest guardians */
case PM_STUDENT:
mndx = mode ? PM_ARCHEOLOGIST : PM_HUMAN;
break;
case PM_CHIEFTAIN:
mndx = mode ? PM_BARBARIAN : PM_HUMAN;
break;
case PM_NEANDERTHAL:
mndx = mode ? PM_CAVEMAN : PM_HUMAN;
break;
case PM_INMATE:
mndx = mode ? PM_CONVICT : PM_HUMAN;
break;
case PM_ASPIRANT:
mndx = mode ? PM_DRUID : PM_HUMAN;
break;
case PM_ATTENDANT:
mndx = mode ? PM_HEALER : PM_HUMAN;
break;
case PM_CULTIST:
mndx = mode ? PM_INFIDEL : PM_HUMAN;
break;
case PM_PAGE:
mndx = mode ? PM_KNIGHT : PM_HUMAN;
break;
case PM_ABBOT:
mndx = mode ? PM_MONK : PM_HUMAN;
break;
case PM_ACOLYTE:
mndx = mode ? PM_PRIEST : PM_HUMAN;
break;
case PM_HUNTER:
mndx = mode ? PM_RANGER : PM_HUMAN;
break;
case PM_THUG:
mndx = mode ? PM_ROGUE : PM_HUMAN;
break;
case PM_ROSHI:
mndx = mode ? PM_SAMURAI : PM_HUMAN;
break;
case PM_GUIDE:
mndx = mode ? PM_TOURIST : PM_HUMAN;
break;
case PM_APPRENTICE:
mndx = mode ? PM_WIZARD : PM_HUMAN;
break;
case PM_WARRIOR:
mndx = mode ? PM_VALKYRIE : PM_HUMAN;
break;
default:
if (mndx >= LOW_PM && mndx < NUMMONS) {
struct permonst *ptr = &mons[mndx];
if (is_human(ptr))
mndx = PM_HUMAN;
else if (is_elf(ptr))
mndx = PM_ELF;
else if (is_drow(ptr))
mndx = PM_DROW;
else if (is_dwarf(ptr))
mndx = PM_DWARF;
else if (is_gnome(ptr))
mndx = PM_GNOME;
else if (is_orc(ptr))
mndx = PM_ORC;
else if (is_centaur(ptr))
mndx = PM_CENTAUR;
else if (is_giant(ptr))
mndx = PM_GIANT;
else if (is_hobbit(ptr))
mndx = PM_HOBBIT;
else if (is_illithid(ptr))
mndx = PM_ILLITHID;
else if (is_tortle(ptr))
mndx = PM_TORTLE;
}
break;
}
return mndx;
}
/* return monster index if chameleon, or NON_PM if not */
int
pm_to_cham(mndx)
int mndx;
{
int mcham = NON_PM;
/*
* As of 3.6.0 we just check M2_SHAPESHIFTER instead of having a
* big switch statement with hardcoded shapeshifter types here.
*/
if (mndx >= LOW_PM && is_shapeshifter(&mons[mndx]))
mcham = mndx;
return mcham;
}
/* for deciding whether corpse will carry along full monster data */
#define KEEPTRAITS(mon) \
((mon)->isshk || (mon)->mtame || unique_corpstat((mon)->data) \
|| has_erac(mon) \
|| is_reviver((mon)->data) \
/* normally quest leader will be unique, */ \
/* but he or she might have been polymorphed */ \
|| (mon)->m_id == quest_status.leader_m_id \
/* special cancellation handling for these */ \
|| (dmgtype((mon)->data, AD_SEDU) || dmgtype((mon)->data, AD_SSEX)))
/* Creates a monster corpse, a "special" corpse, or nothing if it doesn't
* leave corpses. Monsters which leave "special" corpses should have
* G_NOCORPSE set in order to prevent wishing for one, finding tins of one,
* etc....
*/
STATIC_OVL struct obj *
make_corpse(mtmp, corpseflags)
register struct monst *mtmp;
unsigned corpseflags;
{
register struct permonst *mdat = mtmp->data;
int num;
struct obj *obj = (struct obj *) 0;
struct obj *otmp = (struct obj *) 0;
int x = mtmp->mx, y = mtmp->my;
int mndx = monsndx(mdat);
unsigned corpstatflags = corpseflags;
boolean burythem = ((corpstatflags & CORPSTAT_BURIED) != 0);
switch (mndx) {
case PM_GRAY_DRAGON:
case PM_SILVER_DRAGON:
case PM_SHIMMERING_DRAGON:
case PM_RED_DRAGON:
case PM_ORANGE_DRAGON:
case PM_WHITE_DRAGON:
case PM_BLACK_DRAGON:
case PM_BLUE_DRAGON:
case PM_GREEN_DRAGON:
case PM_GOLD_DRAGON:
case PM_SEA_DRAGON:
case PM_YELLOW_DRAGON:
case PM_SHADOW_DRAGON:
case PM_CELESTIAL_DRAGON:
/* Make dragon scales. This assumes that the order of the
dragons is the same as the order of the scales.
If the dragon is a pet, no scales generated. */
if (!mtmp->mtame && !rn2(mtmp->mrevived ? 20 : 3)) {
num = mndx_to_dragon_scales(monsndx(mdat));
obj = mksobj_at(num, x, y, FALSE, FALSE);
obj->spe = 0;
obj->cursed = obj->blessed = FALSE;
}
goto default_1;
case PM_TIAMAT:
/* Make chromatic dragon scales */
if (!rn2(3)) { /* Tiamat cannot be revived, no corpse */
obj = mksobj_at(CHROMATIC_DRAGON_SCALES, x, y, FALSE, FALSE);
obj->spe = 0;
obj->cursed = obj->blessed = FALSE;
}
goto default_1;
case PM_WHITE_UNICORN:
case PM_GRAY_UNICORN:
case PM_BLACK_UNICORN:
if (mtmp->mrevived && rn2(2)) {
if (canseemon(mtmp))
pline("%s recently regrown horn crumbles to dust.",
s_suffix(Monnam(mtmp)));
} else {
obj = mksobj_at(UNICORN_HORN, x, y, TRUE, FALSE);
if (obj && mtmp->mrevived)
obj->degraded_horn = 1;
}
goto default_1;
case PM_LONG_WORM:
(void) mksobj_at(WORM_TOOTH, x, y, TRUE, FALSE);
goto default_1;
case PM_VAMPIRE:
case PM_VAMPIRE_NOBLE:
case PM_VAMPIRE_ROYAL:
case PM_VAMPIRE_MAGE:
/* include mtmp in the mkcorpstat() call */
num = undead_to_corpse(mndx);
corpstatflags |= CORPSTAT_INIT;
obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags);
obj->age -= 100; /* this is an *OLD* corpse */
break;
case PM_KOBOLD_ZOMBIE:
case PM_DWARF_ZOMBIE:
case PM_GNOME_ZOMBIE:
case PM_ORC_ZOMBIE:
case PM_ELF_ZOMBIE:
case PM_DROW_ZOMBIE:
case PM_HOBBIT_ZOMBIE:
case PM_HUMAN_ZOMBIE:
case PM_GIANT_ZOMBIE:
case PM_ETTIN_ZOMBIE:
case PM_GNOLL_WITHERLING:
corpstatflags |= CORPSTAT_ZOMBIE;
/* FALLTHRU */
case PM_KOBOLD_MUMMY:
case PM_DWARF_MUMMY:
case PM_GNOME_MUMMY:
case PM_ORC_MUMMY:
case PM_ELF_MUMMY:
case PM_DROW_MUMMY:
case PM_HOBBIT_MUMMY:
case PM_HUMAN_MUMMY:
case PM_GIANT_MUMMY:
case PM_ETTIN_MUMMY:
num = undead_to_corpse(mndx);
corpstatflags |= CORPSTAT_INIT;
obj = mkcorpstat(CORPSE, mtmp, &mons[num], x, y, corpstatflags);
obj->age -= 100; /* this is an *OLD* corpse */
break;
case PM_IRON_GOLEM:
num = d(2, 6);
while (num--) {
obj = mkobj_at(RANDOM_CLASS, x, y, FALSE);
if (!valid_obj_material(obj, IRON)) {
delobj(obj);
obj = mksobj_at(IRON_CHAIN, x, y, TRUE, FALSE);
}
set_material(obj, IRON);
}
free_mname(mtmp); /* don't christen obj */
break;
case PM_GLASS_GOLEM:
num = d(2, 4); /* very low chance of creating all glass gems */
while (num--) {
obj = mkobj_at(RANDOM_CLASS, x, y, FALSE);
if (!valid_obj_material(obj, GLASS)
|| obj->oclass == POTION_CLASS) {
delobj(obj);
obj = mksobj_at((LAST_GEM + rnd(9)), x, y, TRUE, FALSE);
}
set_material(obj, GLASS);
}
free_mname(mtmp);
break;
case PM_CLAY_GOLEM:
obj = mksobj_at(ROCK, x, y, FALSE, FALSE);
obj->quan = (long) (rn2(20) + 50);
obj->owt = weight(obj);
free_mname(mtmp);
break;
case PM_STONE_GOLEM:
corpstatflags &= ~CORPSTAT_INIT;
obj =
mkcorpstat(STATUE, (struct monst *) 0, mdat, x, y, corpstatflags);
break;
case PM_WOOD_GOLEM:
num = d(2, 4);
while (num--) {
obj = mkobj_at(RANDOM_CLASS, x, y, FALSE);
if (!valid_obj_material(obj, WOOD)) {
delobj(obj);
obj = mksobj_at(QUARTERSTAFF, x, y, TRUE, FALSE);
}
set_material(obj, WOOD);
}
free_mname(mtmp);
break;
case PM_LEATHER_GOLEM:
num = d(2, 4);
while (num--) {
obj = mkobj_at(RANDOM_CLASS, x, y, FALSE);
if (!valid_obj_material(obj, LEATHER)) {
delobj(obj);
obj = mksobj_at(ARMOR, x, y, TRUE, FALSE);
}
set_material(obj, LEATHER);
}
free_mname(mtmp);
break;
case PM_GOLD_GOLEM:
/* Good luck gives more coins */
obj = mkgold((long) (200 - rnl(101)), x, y);
free_mname(mtmp);
break;
case PM_PAPER_GOLEM:
num = rnd(4);
while (num--) {
obj = mkobj_at(RANDOM_CLASS, x, y, FALSE);
if (!valid_obj_material(obj, PAPER) || obj->oclass == SCROLL_CLASS
|| obj->oclass == SPBOOK_CLASS) {
delobj(obj);
obj = mksobj_at(SCR_BLANK_PAPER, x, y, TRUE, FALSE);
}
set_material(obj, PAPER);
}
free_mname(mtmp);
break;
/* expired puddings will congeal into a large blob;
like dragons, relies on the order remaining consistent */
case PM_GRAY_OOZE:
case PM_BROWN_PUDDING:
case PM_GREEN_SLIME:
case PM_BLACK_PUDDING:
/* we have to do this here because most other places
expect there to be an object coming back; not this one */
obj = mksobj_at(GLOB_OF_BLACK_PUDDING - (PM_BLACK_PUDDING - mndx),
x, y, TRUE, FALSE);
while (obj && (otmp = obj_nexto(obj)) != (struct obj *) 0) {
pudding_merge_message(obj, otmp);
obj = obj_meld(&obj, &otmp);
}
free_mname(mtmp);
return obj;
default_1:
default:
if (mvitals[mndx].mvflags & G_NOCORPSE) {
return (struct obj *) 0;
} else {
corpstatflags |= CORPSTAT_INIT;
/* preserve the unique traits of some creatures */
obj = mkcorpstat(CORPSE, KEEPTRAITS(mtmp) ? mtmp : 0,
mdat, x, y, corpstatflags);
if (burythem) {
boolean dealloc;
(void) bury_an_obj(obj, &dealloc);
newsym(x, y);
return dealloc ? (struct obj *) 0 : obj;
}
}
break;
}
/* All special cases should precede the G_NOCORPSE check */
if (!obj)
return (struct obj *) 0;
/* if polymorph or undead turning has killed this monster,
prevent the same attack beam from hitting its corpse */
if (context.bypasses)
bypass_obj(obj);
if (has_mname(mtmp))
obj = oname(obj, MNAME(mtmp));
/* Avoid "It was hidden under a green mold corpse!"
* during Blind combat. An unseen monster referred to as "it"
* could be killed and leave a corpse. If a hider then hid
* underneath it, you could be told the corpse type of a
* monster that you never knew was there without this.
* The code in hitmu() substitutes the word "something"
* if the corpse's obj->dknown is 0.
*/
if (Blind && !sensemon(mtmp))
obj->dknown = 0;
stackobj(obj);
newsym(x, y);
return obj;
}
/* check mtmp and water/lava/air for compatibility, 0 (survived), 1 (died) */
int
minliquid(mtmp)
register struct monst *mtmp;
{
boolean inpool, inlava, infountain, inshallow, inforge, inopenair;
/* [ceiling clingers are handled below] */
inpool = (is_pool(mtmp->mx, mtmp->my)
&& (!(is_flyer(mtmp->data)
|| is_floater(mtmp->data) || can_levitate(mtmp))
/* there's no "above the surface" on the plane of water */
|| Is_waterlevel(&u.uz)));
inlava = (is_lava(mtmp->mx, mtmp->my)
&& !(is_flyer(mtmp->data)
|| is_floater(mtmp->data) || can_levitate(mtmp)));
infountain = IS_FOUNTAIN(levl[mtmp->mx][mtmp->my].typ);
inforge = IS_FORGE(levl[mtmp->mx][mtmp->my].typ);
inshallow = ((is_puddle(mtmp->mx, mtmp->my) || is_sewage(mtmp->mx, mtmp->my))
&& !(is_flyer(mtmp->data)
|| is_floater(mtmp->data) || can_levitate(mtmp)));
inopenair = (is_open_air(mtmp->mx, mtmp->my)
&& !(is_flyer(mtmp->data) || is_floater(mtmp->data)
|| is_clinger(mtmp->data) || can_levitate(mtmp)
|| ((mtmp == u.usteed) && Flying)));
/* Flying and levitation keeps our steed out of the liquid
(but not water-walking or swimming; note: if hero is in a
water location on the Plane of Water, flight and levitating
are blocked so this (Flying || Levitation) test fails there
and steed will be subject to water effects, as intended) */
if (mtmp == u.usteed && (Flying || Levitation))
return 0;
/* Gremlin multiplying won't go on forever since the hit points
* keep going down, and when it gets to 1 hit point the clone
* function will fail.
*/
if (mtmp->data == &mons[PM_GREMLIN]
&& (inpool || infountain || inshallow) && rn2(3)) {
if (split_mon(mtmp, (struct monst *) 0))
dryup(mtmp->mx, mtmp->my, FALSE);
if (inpool)
water_damage_chain(mtmp->minvent, FALSE, 0,
TRUE, mtmp->mx, mtmp->my);
return 0;
} else if (mtmp->data == &mons[PM_LAVA_GREMLIN]
&& (inlava || inforge) && rn2(3)) {
if (split_mon(mtmp, (struct monst *) 0))
dryup(mtmp->mx, mtmp->my, FALSE);
/* no lava damage chain func (yet), so this is commented out
water_damage_chain(mtmp->minvent, FALSE, 0, TRUE); */
if (inforge && !rn2(3))
blowupforge(mtmp->mx, mtmp->my);
return 0;
} else if (mtmp->data == &mons[PM_IRON_GOLEM]
&& ((inpool && !rn2(5)) || (inshallow && rn2(2)))) {
int dam = d(2, 6);
if (cansee(mtmp->mx, mtmp->my))
pline("%s rusts.", Monnam(mtmp));
damage_mon(mtmp, dam, AD_PHYS); /* Not quite accurate but no resistance to rusting */
if (mtmp->mhpmax > dam)
mtmp->mhpmax -= dam;
if (DEADMONSTER(mtmp)) {
if (canseemon(mtmp))
pline("%s falls to pieces.", Monnam(mtmp));
mondead(mtmp);
if (DEADMONSTER(mtmp)) {
if (mtmp->mtame && !canseemon(mtmp))
pline("May %s rust in peace.", mon_nam(mtmp));
return 1;
}
}
if (inshallow)
water_damage(which_armor(mtmp, W_ARMF), 0,
FALSE, mtmp->mx, mtmp->my);
else
water_damage_chain(mtmp->minvent, FALSE, 0,
TRUE, mtmp->mx, mtmp->my);
return 0;
} else if (is_longworm(mtmp->data) && inshallow) {
int dam = d(3, 12);
if (canseemon(mtmp))
pline("The water burns %s flesh!", s_suffix(mon_nam(mtmp)));
mtmp->mhp -= dam;
if (mtmp->mhpmax > dam)
mtmp->mhpmax -= (dam + 1) / 2;
if (DEADMONSTER(mtmp)) {
if (canseemon(mtmp))
pline("%s dies.", Monnam(mtmp));
mondead(mtmp);
if (DEADMONSTER(mtmp))
return 1;
}
return 0;
}
if (inlava) {
/*
* Lava effects much as water effects. Lava likers are able to
* protect their stuff. Fire resistant monsters can only protect
* themselves --ALI
*/
if (!is_clinger(mtmp->data) && !likes_lava(mtmp->data)) {
/* not fair...? hero doesn't automatically teleport away
from lava, just from water */
if (can_teleport(mtmp->data) && !tele_restrict(mtmp)) {
if (rloc(mtmp, TRUE))
return 0;
}
if (!(resists_fire(mtmp) || defended(mtmp, AD_FIRE))) {
if (cansee(mtmp->mx, mtmp->my))
pline("%s %s.", Monnam(mtmp), on_fire(mtmp, ON_FIRE_DEAD));
/* unlike fire -> melt ice -> pool, there's no way for the
hero to create lava beneath a monster, so the !mon_moving
case is not expected to happen (and we haven't made a
player-against-monster variation of the message above) */
if (context.mon_moving)
mondead(mtmp);
else
xkilled(mtmp, XKILL_NOMSG);
} else {
damage_mon(mtmp, 1, AD_FIRE);
if (DEADMONSTER(mtmp)) {
if (cansee(mtmp->mx, mtmp->my))
pline("%s surrenders to the fire.", Monnam(mtmp));
mondead(mtmp);
} else if (cansee(mtmp->mx, mtmp->my))
pline("%s burns slightly.", Monnam(mtmp));
}
if (!DEADMONSTER(mtmp)) {
(void) fire_damage_chain(mtmp->minvent, FALSE, FALSE,
mtmp->mx, mtmp->my);
(void) rloc(mtmp, FALSE);
return 0;
}
return 1;
}
} else if (inopenair) {
if (cansee(mtmp->mx, mtmp->my)) {
pline("%s plummets several thousand feet to %s death.",
Monnam(mtmp), mhis(mtmp));
}
if (u.ustuck && u.uswallow && u.ustuck == mtmp) {
/* This can happen after a purple worm plucks you off a
flying steed while you are over air. */
pline("%s falls as %s rushes in and forces you out.",
Monnam(mtmp), hliquid("air"));
}
if (context.mon_moving) {
/* no corpse or objects as both are now
several thousand feet down */
mongone(mtmp);
} else {
xkilled(mtmp, XKILL_NOMSG | XKILL_NOCORPSE);
}
if (!DEADMONSTER(mtmp)) {
if (!rloc(mtmp, TRUE))
deal_with_overcrowding(mtmp);
return 0;
}
return 1;
} else if (inpool) {
/* Most monsters drown in pools. flooreffects() will take care of
* water damage to dead monsters' inventory, but survivors need to
* be handled here. Swimmers are able to protect their stuff...
*/
if (!is_clinger(mtmp->data) && !is_swimmer(mtmp->data)
&& !amphibious(mtmp->data) && !can_wwalk(mtmp)) {
/* like hero with teleport intrinsic or spell, teleport away
if possible */
if (can_teleport(mtmp->data) && !tele_restrict(mtmp)) {
if (rloc(mtmp, TRUE))
return 0;
}
if (cansee(mtmp->mx, mtmp->my)) {
if (context.mon_moving)
pline("%s drowns.", Monnam(mtmp));
else
/* hero used fire to melt ice that monster was on */
You("drown %s.", mon_nam(mtmp));
}
if (u.ustuck && u.uswallow && u.ustuck == mtmp) {
/* This can happen after a purple worm plucks you off a
flying steed while you are over water. */
pline("%s sinks as %s rushes in and flushes you out.",
Monnam(mtmp), hliquid("water"));
}
if (context.mon_moving)
mondead(mtmp);
else
xkilled(mtmp, XKILL_NOMSG);
if (!DEADMONSTER(mtmp)) {
water_damage_chain(mtmp->minvent, FALSE, 0,
TRUE, mtmp->mx, mtmp->my);
if (!rloc(mtmp, TRUE))
deal_with_overcrowding(mtmp);
return 0;
}