-
Notifications
You must be signed in to change notification settings - Fork 453
/
mondata.c
1567 lines (1430 loc) · 52.1 KB
/
mondata.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.7 mondata.c $NHDT-Date: 1685180674 2023/05/27 09:44:34 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.122 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2011. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
/*
* These routines provide basic data for any type of monster.
*/
/* set up an individual monster's base type (initial creation, shapechange) */
void
set_mon_data(struct monst *mon, struct permonst *ptr)
{
int new_speed, old_speed = mon->data ? mon->data->mmove : 0;
short *movement_p = (mon == &gy.youmonst) ? &u.umovement : &mon->movement;
mon->data = ptr;
mon->mnum = (short) monsndx(ptr);
if (*movement_p) { /* used to adjust poly'd hero as well as monsters */
new_speed = ptr->mmove;
/* prorate unused movement if new form is slower so that
it doesn't get extra moves leftover from previous form;
if new form is faster, leave unused movement as is */
if (new_speed < old_speed) {
/*
* Some static analysis warns that this might divide by 0
mon->movement = new_speed * mon->movement / old_speed;
* so add a redundant test to suppress that.
*/
*movement_p *= new_speed;
if (old_speed > 0) /* old > new and new >= 0, so always True */
*movement_p /= old_speed;
}
}
return;
}
/* does monster-type have any attack for a specific type of damage? */
struct attack *
attacktype_fordmg(struct permonst *ptr, int atyp, int dtyp)
{
struct attack *a;
for (a = &ptr->mattk[0]; a < &ptr->mattk[NATTK]; a++)
if (a->aatyp == atyp && (dtyp == AD_ANY || a->adtyp == dtyp))
return a;
return (struct attack *) 0;
}
/* does monster-type have a particular type of attack */
boolean
attacktype(struct permonst *ptr, int atyp)
{
return attacktype_fordmg(ptr, atyp, AD_ANY) ? TRUE : FALSE;
}
/* returns True if monster doesn't attack, False if it does */
boolean
noattacks(struct permonst *ptr)
{
int i;
struct attack *mattk = ptr->mattk;
for (i = 0; i < NATTK; i++) {
/* AT_BOOM "passive attack" (gas spore's explosion upon death)
isn't an attack as far as our callers are concerned */
if (mattk[i].aatyp == AT_BOOM)
continue;
if (mattk[i].aatyp)
return FALSE;
}
return TRUE;
}
/* does monster-type transform into something else when petrified? */
boolean
poly_when_stoned(struct permonst *ptr)
{
/* non-stone golems turn into stone golems unless latter is genocided */
return (boolean) (is_golem(ptr) && ptr != &mons[PM_STONE_GOLEM]
&& !(gm.mvitals[PM_STONE_GOLEM].mvflags & G_GENOD));
/* allow G_EXTINCT */
}
/* is 'mon' (possibly youmonst) protected against damage type 'adtype' via
wielded weapon or worn dragon scales? [or by virtue of being a dragon?] */
boolean
defended(struct monst *mon, int adtyp)
{
struct obj *o, otemp;
int mndx;
boolean is_you = (mon == &gy.youmonst);
/* is 'mon' wielding an artifact that protects against 'adtyp'? */
o = is_you ? uwep : MON_WEP(mon);
if (o && o->oartifact && defends(adtyp, o))
return TRUE;
/* if 'mon' is an adult dragon, treat it as if it was wearing scales
so that it has the same benefit as a hero wearing dragon scales */
mndx = monsndx(mon->data);
if (mndx >= PM_GRAY_DRAGON && mndx <= PM_YELLOW_DRAGON) {
/* a dragon is its own suit... if mon is poly'd hero, we don't
care about embedded scales (uskin) because being a dragon with
embedded scales is no better than just being a dragon */
otemp = cg.zeroobj;
otemp.oclass = ARMOR_CLASS;
otemp.otyp = GRAY_DRAGON_SCALES + (mndx - PM_GRAY_DRAGON);
/* defends() and Is_dragon_armor() only care about otyp so ignore
the rest of otemp's fields */
o = &otemp;
} else {
/* ordinary case: not an adult dragon */
o = is_you ? uarm : which_armor(mon, W_ARM);
}
/* is 'mon' wearing dragon scales that protect against 'adtyp'? */
if (o && Is_dragon_armor(o) && defends(adtyp, o))
return TRUE;
return FALSE;
}
/* returns True if monster is drain-life resistant */
boolean
resists_drli(struct monst *mon)
{
struct permonst *ptr = mon->data;
if (is_undead(ptr) || is_demon(ptr) || is_were(ptr)
/* is_were() doesn't handle hero in human form */
|| (mon == &gy.youmonst && u.ulycn >= LOW_PM)
|| ptr == &mons[PM_DEATH] || is_vampshifter(mon))
return TRUE;
return defended(mon, AD_DRLI);
}
/* True if monster is magic-missile (actually, general magic) resistant */
boolean
resists_magm(struct monst *mon)
{
struct permonst *ptr = mon->data;
boolean is_you = (mon == &gy.youmonst);
long slotmask;
struct obj *o;
/* as of 3.2.0: gray dragons, Angels, Oracle, Yeenoghu */
if (dmgtype(ptr, AD_MAGM) || ptr == &mons[PM_BABY_GRAY_DRAGON]
|| dmgtype(ptr, AD_RBRE)) /* Chromatic Dragon */
return TRUE;
/* check for magic resistance granted by wielded weapon */
o = is_you ? uwep : MON_WEP(mon);
if (o && o->oartifact && defends(AD_MAGM, o))
return TRUE;
/* check for magic resistance granted by worn or carried items */
o = is_you ? gi.invent : mon->minvent;
slotmask = W_ARMOR | W_ACCESSORY;
if (!is_you /* assumes monsters don't wield non-weapons */
|| (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep))))
slotmask |= W_WEP;
if (is_you && u.twoweap)
slotmask |= W_SWAPWEP;
for (; o; o = o->nobj)
if (((o->owornmask & slotmask) != 0L
&& objects[o->otyp].oc_oprop == ANTIMAGIC)
|| (o->oartifact && defends_when_carried(AD_MAGM, o)))
return TRUE;
return FALSE;
}
/* True iff monster is resistant to light-induced blindness */
boolean
resists_blnd(struct monst *mon)
{
struct permonst *ptr = mon->data;
boolean is_you = (mon == &gy.youmonst);
long slotmask;
struct obj *o;
if (is_you ? (Blind || Unaware)
: (mon->mblinded || !mon->mcansee || !haseyes(ptr)
/* BUG: temporary sleep sets mfrozen, but since
paralysis does too, we can't check it */
|| mon->msleeping))
return TRUE;
/* yellow light, Archon; !dust vortex, !cobra, !raven */
if (dmgtype_fromattack(ptr, AD_BLND, AT_EXPL)
|| dmgtype_fromattack(ptr, AD_BLND, AT_GAZE))
return TRUE;
o = is_you ? uwep : MON_WEP(mon);
if (o && o->oartifact && defends(AD_BLND, o))
return TRUE;
o = is_you ? gi.invent : mon->minvent;
slotmask = W_ARMOR | W_ACCESSORY;
if (!is_you /* assumes monsters don't wield non-weapons */
|| (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep))))
slotmask |= W_WEP;
if (is_you && u.twoweap)
slotmask |= W_SWAPWEP;
for (; o; o = o->nobj)
if (((o->owornmask & slotmask) != 0L
&& objects[o->otyp].oc_oprop == BLINDED)
|| (o->oartifact && defends_when_carried(AD_BLND, o)))
return TRUE;
return FALSE;
}
/* True iff monster can be blinded by the given attack;
note: may return True when mdef is blind (e.g. new cream-pie attack)
magr can be NULL.
*/
boolean
can_blnd(
struct monst *magr, /* NULL == no specific aggressor */
struct monst *mdef,
uchar aatyp,
struct obj *obj) /* aatyp == AT_WEAP, AT_SPIT */
{
boolean is_you = (mdef == &gy.youmonst);
boolean check_visor = FALSE;
struct obj *o;
/* no eyes protect against all attacks for now */
if (!haseyes(mdef->data))
return FALSE;
/* if monster has been permanently blinded, the deed is already done */
if (!is_you && mon_perma_blind(mdef))
return FALSE;
/* /corvus oculum corvi non eruit/
a saying expressed in Latin rather than a zoological observation:
"a crow will not pluck out the eye of another crow"
so prevent ravens from blinding each other */
if (magr && magr->data == &mons[PM_RAVEN] && mdef->data == &mons[PM_RAVEN])
return FALSE;
switch (aatyp) {
case AT_EXPL:
case AT_BOOM:
case AT_GAZE:
case AT_MAGC:
case AT_BREA: /* assumed to be lightning */
/* light-based attacks may be cancelled or resisted */
if (magr && magr->mcan)
return FALSE;
return !resists_blnd(mdef);
case AT_WEAP:
case AT_SPIT:
case AT_NONE:
/* an object is used (thrown/spit/other) */
if (obj && (obj->otyp == CREAM_PIE)) {
if (is_you && Blindfolded)
return FALSE;
} else if (obj && (obj->otyp == BLINDING_VENOM)) {
/* all ublindf, including LENSES, protect, cream-pies too */
if (is_you && (ublindf || u.ucreamed))
return FALSE;
check_visor = TRUE;
} else if (obj && (obj->otyp == POT_BLINDNESS)) {
return TRUE; /* no defense */
} else
return FALSE; /* other objects cannot cause blindness yet */
if ((magr == &gy.youmonst) && u.uswallow)
return FALSE; /* can't affect eyes while inside monster */
break;
case AT_ENGL:
if (is_you && (Blindfolded || Unaware || u.ucreamed))
return FALSE;
if (!is_you && mdef->msleeping)
return FALSE;
break;
case AT_CLAW:
/* e.g. raven: all ublindf, including LENSES, protect */
if (is_you && ublindf)
return FALSE;
if ((magr == &gy.youmonst) && u.uswallow)
return FALSE; /* can't affect eyes while inside monster */
check_visor = TRUE;
break;
case AT_TUCH:
case AT_STNG:
/* some physical, blind-inducing attacks can be cancelled */
if (magr && magr->mcan)
return FALSE;
break;
default:
break;
}
/* check if wearing a visor (only checked if visor might help) */
if (check_visor) {
o = (mdef == &gy.youmonst) ? gi.invent : mdef->minvent;
for (; o; o = o->nobj)
if ((o->owornmask & W_ARMH)
&& objdescr_is(o, "visored helmet"))
return FALSE;
}
return TRUE;
}
/* returns True if monster can attack at range */
boolean
ranged_attk(struct permonst *ptr)
{
int i;
for (i = 0; i < NATTK; i++)
if (DISTANCE_ATTK_TYPE(ptr->mattk[i].aatyp))
return TRUE;
return FALSE;
}
#if defined(MAKEDEFS_C) \
|| (NH_DEVEL_STATUS != NH_STATUS_RELEASED) || defined(DEBUG)
/*
* If adding a new monster, include a guestimate for difficulty,
* build the program, then run it in wizard mode and use the
* #mondifficulty command. If it reports a discrepancy, update
* the monsters array with the more accurate value (or possibly
* modify the 'mstrength()' algorithm to generate the guessed one).
*/
static boolean mstrength_ranged_attk(struct permonst *);
/* This routine is designed to return an integer value which represents
an approximation of monster strength. It uses a similar method of
determination as "experience()" to arrive at the strength. */
int
mstrength(struct permonst *ptr)
{
int i, tmp2, n, tmp = ptr->mlevel;
if (tmp > 49) /* special fixed hp monster */
tmp = 2 * (tmp - 6) / 4;
/* for creation in groups */
n = (!!(ptr->geno & G_SGROUP));
n += (!!(ptr->geno & G_LGROUP)) << 1;
/* for ranged attacks */
if (mstrength_ranged_attk(ptr))
n++;
/* for higher ac values */
n += (ptr->ac < 4);
n += (ptr->ac < 0);
/* for very fast monsters */
n += (ptr->mmove >= 18);
/* for each attack and "special" attack */
for (i = 0; i < NATTK; i++) {
tmp2 = ptr->mattk[i].aatyp;
n += (tmp2 > 0);
n += (tmp2 == AT_MAGC);
n += (tmp2 == AT_WEAP && (ptr->mflags2 & M2_STRONG));
if (tmp2 == AT_EXPL) {
int tmp3 = ptr->mattk[i].adtyp;
/* {freezing,flaming,shocking} spheres are fairly weak but
can destroy equipment; {yellow,black} lights can't */
n += ((tmp3 == AD_COLD || tmp3 == AD_FIRE) ? 3
: (tmp3 == AD_ELEC) ? 5
: 0);
}
}
/* for each "special" damage type */
for (i = 0; i < NATTK; i++) {
tmp2 = ptr->mattk[i].adtyp;
if ((tmp2 == AD_DRLI) || (tmp2 == AD_STON) || (tmp2 == AD_DRST)
|| (tmp2 == AD_DRDX) || (tmp2 == AD_DRCO) || (tmp2 == AD_WERE))
n += 2;
else if (strcmp(ptr->pmnames[NEUTRAL], "grid bug"))
n += (tmp2 != AD_PHYS);
n += ((int) (ptr->mattk[i].damd * ptr->mattk[i].damn) > 23);
}
/* Leprechauns are special cases. They have many hit dice so they
can hit and are hard to kill, but they don't really do much damage. */
if (!strcmp(ptr->pmnames[NEUTRAL], "leprechaun"))
n -= 2;
/* finally, adjust the monster level 0 <= n <= 24 (approx.) */
if (n == 0)
tmp -= 1;
else if (n < 6)
tmp += (n / 3 + 1);
else
tmp += (n / 2);
return (tmp >= 0) ? tmp : 0;
}
/* returns True if monster can attack at range */
static boolean
mstrength_ranged_attk(struct permonst *ptr)
{
register int i, j;
register int atk_mask = (1 << AT_BREA) | (1 << AT_SPIT) | (1 << AT_GAZE);
for (i = 0; i < NATTK; i++) {
if ((j = ptr->mattk[i].aatyp) >= AT_WEAP
|| (j < 32 && (atk_mask & (1 << j)) != 0))
return TRUE;
}
return FALSE;
}
#endif /* (NH_DEVEL_STATUS != NH_STATUS_RELEASED) || DEBUG || MAKEDEFS_C */
/* True if specific monster is especially affected by silver weapons */
boolean
mon_hates_silver(struct monst *mon)
{
return (boolean) (is_vampshifter(mon) || hates_silver(mon->data));
}
/* True if monster-type is especially affected by silver weapons */
boolean
hates_silver(struct permonst *ptr)
{
return (boolean) (is_were(ptr) || ptr->mlet == S_VAMPIRE || is_demon(ptr)
|| ptr == &mons[PM_SHADE]
|| (ptr->mlet == S_IMP && ptr != &mons[PM_TENGU]));
}
/* True if specific monster is especially affected by blessed objects */
boolean
mon_hates_blessings(struct monst *mon)
{
return (boolean) (is_vampshifter(mon) || hates_blessings(mon->data));
}
/* True if monster-type is especially affected by blessed objects */
boolean
hates_blessings(struct permonst *ptr)
{
return (boolean) (is_undead(ptr) || is_demon(ptr));
}
/* True if specific monster is especially affected by light-emitting weapons */
boolean
mon_hates_light(struct monst *mon)
{
return (boolean) hates_light(mon->data);
}
/* True iff the type of monster pass through iron bars */
boolean
passes_bars(struct permonst *mptr)
{
return (boolean) (passes_walls(mptr) || amorphous(mptr) || unsolid(mptr)
|| is_whirly(mptr) || verysmall(mptr)
/* rust monsters and some puddings can destroy bars */
|| dmgtype(mptr, AD_RUST) || dmgtype(mptr, AD_CORR)
/* rock moles can eat bars */
|| metallivorous(mptr)
|| (slithy(mptr) && !bigmonst(mptr)));
}
/* returns True if monster can blow (whistle, etc) */
boolean
can_blow(struct monst *mtmp)
{
if ((is_silent(mtmp->data) || mtmp->data->msound == MS_BUZZ)
&& (breathless(mtmp->data) || verysmall(mtmp->data)
|| !has_head(mtmp->data) || mtmp->data->mlet == S_EEL))
return FALSE;
if ((mtmp == &gy.youmonst) && Strangled)
return FALSE;
return TRUE;
}
/* for casting spells and reading scrolls while blind */
boolean
can_chant(struct monst *mtmp)
{
if ((mtmp == &gy.youmonst && Strangled)
|| is_silent(mtmp->data) || !has_head(mtmp->data)
|| mtmp->data->msound == MS_BUZZ || mtmp->data->msound == MS_BURBLE)
return FALSE;
return TRUE;
}
/* True if mon is vulnerable to strangulation */
boolean
can_be_strangled(struct monst *mon)
{
struct obj *mamul;
boolean nonbreathing, nobrainer;
/* For amulet of strangulation support: here we're considering
strangulation to be loss of blood flow to the brain due to
constriction of the arteries in the neck, so all headless
creatures are immune (no neck) as are mindless creatures
who don't need to breathe (brain, if any, doesn't care).
Mindless creatures who do need to breath are vulnerable, as
are non-breathing creatures which have higher brain function. */
if (!has_head(mon->data))
return FALSE;
if (mon == &gy.youmonst) {
/* hero can't be mindless but poly'ing into mindless form can
confer strangulation protection */
nobrainer = mindless(gy.youmonst.data);
nonbreathing = Breathless;
} else {
nobrainer = mindless(mon->data);
/* monsters don't wear amulets of magical breathing,
so second part doesn't achieve anything useful... */
nonbreathing = (breathless(mon->data)
|| ((mamul = which_armor(mon, W_AMUL)) != 0
&& (mamul->otyp == AMULET_OF_MAGICAL_BREATHING)));
}
return (boolean) (!nobrainer || !nonbreathing);
}
/* returns True if monster can track well */
boolean
can_track(struct permonst *ptr)
{
if (u_wield_art(ART_EXCALIBUR))
return TRUE;
return (boolean) haseyes(ptr);
}
/* creature will slide out of armor */
boolean
sliparm(struct permonst *ptr)
{
return (boolean) (is_whirly(ptr) || ptr->msize <= MZ_SMALL
|| noncorporeal(ptr));
}
/* creature will break out of armor */
boolean
breakarm(struct permonst *ptr)
{
if (sliparm(ptr))
return FALSE;
return (boolean) (bigmonst(ptr)
|| (ptr->msize > MZ_SMALL && !humanoid(ptr))
/* special cases of humanoids that cannot wear suits */
|| ptr == &mons[PM_MARILITH]
|| ptr == &mons[PM_WINGED_GARGOYLE]);
}
/* creature sticks other creatures it hits */
boolean
sticks(register struct permonst *ptr)
{
return (boolean) (dmgtype(ptr, AD_STCK)
|| (dmgtype(ptr, AD_WRAP) && !attacktype(ptr, AT_ENGL))
|| attacktype(ptr, AT_HUGS));
}
/* some monster-types can't vomit */
boolean
cantvomit(struct permonst *ptr)
{
/* rats and mice are incapable of vomiting;
which other creatures have the same limitation? */
if (ptr->mlet == S_RODENT && ptr != &mons[PM_ROCK_MOLE]
&& ptr != &mons[PM_WOODCHUCK])
return TRUE;
return FALSE;
}
/* number of horns this type of monster has on its head */
int
num_horns(struct permonst *ptr)
{
switch (monsndx(ptr)) {
case PM_HORNED_DEVIL: /* ? "more than one" */
case PM_MINOTAUR:
case PM_ASMODEUS:
case PM_BALROG:
return 2;
case PM_WHITE_UNICORN:
case PM_GRAY_UNICORN:
case PM_BLACK_UNICORN:
case PM_KI_RIN:
return 1;
default:
break;
}
return 0;
}
/* does monster-type deal out a particular type of damage from a particular
type of attack? */
struct attack *
dmgtype_fromattack(struct permonst *ptr, int dtyp, int atyp)
{
struct attack *a;
for (a = &ptr->mattk[0]; a < &ptr->mattk[NATTK]; a++)
if (a->adtyp == dtyp && (atyp == AT_ANY || a->aatyp == atyp))
return a;
return (struct attack *) 0;
}
/* does monster-type deal out a particular type of damage from any attack */
boolean
dmgtype(struct permonst *ptr, int dtyp)
{
return dmgtype_fromattack(ptr, dtyp, AT_ANY) ? TRUE : FALSE;
}
/* returns the maximum damage a defender can do to the attacker via
a passive defense */
int
max_passive_dmg(register struct monst *mdef, register struct monst *magr)
{
int i, dmg, multi2 = 0;
uchar adtyp;
/* each attack by magr can result in passive damage */
for (i = 0; i < NATTK; i++)
switch (magr->data->mattk[i].aatyp) {
case AT_CLAW:
case AT_BITE:
case AT_KICK:
case AT_BUTT:
case AT_TUCH:
case AT_STNG:
case AT_HUGS:
case AT_ENGL:
case AT_TENT:
case AT_WEAP:
multi2++;
break;
default:
break;
}
dmg = 0;
for (i = 0; i < NATTK; i++)
if (mdef->data->mattk[i].aatyp == AT_NONE
|| mdef->data->mattk[i].aatyp == AT_BOOM) {
adtyp = mdef->data->mattk[i].adtyp;
if ((adtyp == AD_FIRE && completelyburns(magr->data))
|| (adtyp == AD_DCAY && completelyrots(magr->data))
|| (adtyp == AD_RUST && completelyrusts(magr->data))) {
dmg = magr->mhp;
} else if ((adtyp == AD_ACID && !resists_acid(magr))
|| (adtyp == AD_COLD && !resists_cold(magr))
|| (adtyp == AD_FIRE && !resists_fire(magr))
|| (adtyp == AD_ELEC && !resists_elec(magr))
|| adtyp == AD_PHYS) {
dmg = mdef->data->mattk[i].damn;
if (!dmg)
dmg = mdef->data->mlevel + 1;
dmg *= mdef->data->mattk[i].damd;
}
dmg *= multi2;
break;
}
return dmg;
}
/* determine whether two monster types are from the same species */
boolean
same_race(struct permonst *pm1, struct permonst *pm2)
{
char let1 = pm1->mlet, let2 = pm2->mlet;
if (pm1 == pm2)
return TRUE; /* exact match */
/* player races have their own predicates */
if (is_human(pm1))
return is_human(pm2);
if (is_elf(pm1))
return is_elf(pm2);
if (is_dwarf(pm1))
return is_dwarf(pm2);
if (is_gnome(pm1))
return is_gnome(pm2);
if (is_orc(pm1))
return is_orc(pm2);
/* other creatures are less precise */
if (is_giant(pm1))
return is_giant(pm2); /* open to quibbling here */
if (is_golem(pm1))
return is_golem(pm2); /* even moreso... */
if (is_mind_flayer(pm1))
return is_mind_flayer(pm2);
if (let1 == S_KOBOLD || pm1 == &mons[PM_KOBOLD_ZOMBIE]
|| pm1 == &mons[PM_KOBOLD_MUMMY])
return (let2 == S_KOBOLD || pm2 == &mons[PM_KOBOLD_ZOMBIE]
|| pm2 == &mons[PM_KOBOLD_MUMMY]);
if (let1 == S_OGRE)
return (let2 == S_OGRE);
if (let1 == S_NYMPH)
return (let2 == S_NYMPH);
if (let1 == S_CENTAUR)
return (let2 == S_CENTAUR);
if (is_unicorn(pm1))
return is_unicorn(pm2);
if (let1 == S_DRAGON)
return (let2 == S_DRAGON);
if (let1 == S_NAGA)
return (let2 == S_NAGA);
/* other critters get steadily messier */
if (is_rider(pm1))
return is_rider(pm2); /* debatable */
if (is_minion(pm1))
return is_minion(pm2); /* [needs work?] */
/* tengu don't match imps (first test handled case of both being tengu) */
if (pm1 == &mons[PM_TENGU] || pm2 == &mons[PM_TENGU])
return FALSE;
if (let1 == S_IMP)
return (let2 == S_IMP);
/* and minor demons (imps) don't match major demons */
else if (let2 == S_IMP)
return FALSE;
if (is_demon(pm1))
return is_demon(pm2);
if (is_undead(pm1)) {
if (let1 == S_ZOMBIE)
return (let2 == S_ZOMBIE);
if (let1 == S_MUMMY)
return (let2 == S_MUMMY);
if (let1 == S_VAMPIRE)
return (let2 == S_VAMPIRE);
if (let1 == S_LICH)
return (let2 == S_LICH);
if (let1 == S_WRAITH)
return (let2 == S_WRAITH);
if (let1 == S_GHOST)
return (let2 == S_GHOST);
} else if (is_undead(pm2))
return FALSE;
/* check for monsters which grow into more mature forms */
if (let1 == let2) {
int m1 = monsndx(pm1), m2 = monsndx(pm2), prv, nxt;
/* we know m1 != m2 (very first check above); test all smaller
forms of m1 against m2, then all larger ones; don't need to
make the corresponding tests for variants of m2 against m1 */
for (prv = m1, nxt = big_to_little(m1); nxt != prv;
prv = nxt, nxt = big_to_little(nxt))
if (nxt == m2)
return TRUE;
for (prv = m1, nxt = little_to_big(m1); nxt != prv;
prv = nxt, nxt = little_to_big(nxt))
if (nxt == m2)
return TRUE;
}
/* not caught by little/big handling */
if (pm1 == &mons[PM_GARGOYLE] || pm1 == &mons[PM_WINGED_GARGOYLE])
return (pm2 == &mons[PM_GARGOYLE]
|| pm2 == &mons[PM_WINGED_GARGOYLE]);
if (pm1 == &mons[PM_KILLER_BEE] || pm1 == &mons[PM_QUEEN_BEE])
return (pm2 == &mons[PM_KILLER_BEE] || pm2 == &mons[PM_QUEEN_BEE]);
if (is_longworm(pm1))
return is_longworm(pm2); /* handles tail */
/* [currently there's no reason to bother matching up
assorted bugs and blobs with their closest variants] */
/* didn't match */
return FALSE;
}
/* for handling alternate spellings */
struct alt_spl {
const char *name;
short pm_val;
int genderhint;
};
/* figure out what type of monster a user-supplied string is specifying;
ignore anything past the monster name */
int
name_to_mon(const char *in_str, int *gender_name_var)
{
return name_to_monplus(in_str, (const char **) 0, gender_name_var);
}
/* figure out what type of monster a user-supplied string is specifying;
return a pointer to whatever is past the monster name--necessary if
caller wants to strip off the name and it matches one of the alternate
names rather the canonical mons[].mname */
int
name_to_monplus(
const char *in_str,
const char **remainder_p,
int *gender_name_var)
{
/* Be careful. We must check the entire string in case it was
* something such as "ettin zombie corpse". The calling routine
* doesn't know about the "corpse" until the monster name has
* already been taken off the front, so we have to be able to
* read the name with extraneous stuff such as "corpse" stuck on
* the end.
* This causes a problem for names which prefix other names such
* as "ettin" on "ettin zombie". In this case we want the _longest_
* name which exists.
* This also permits plurals created by adding suffixes such as 's'
* or 'es'. Other plurals must still be handled explicitly.
*/
register int i;
register int mntmp = NON_PM;
register char *s, *str, *term;
char buf[BUFSZ];
int len, mgend, matchgend = -1;
size_t slen;
boolean exact_match = FALSE;
if (remainder_p)
*remainder_p = (const char *) 0;
str = strcpy(buf, in_str);
if (!strncmp(str, "a ", 2))
str += 2;
else if (!strncmp(str, "an ", 3))
str += 3;
else if (!strncmp(str, "the ", 4))
str += 4;
slen = strlen(str);
term = str + slen;
if ((s = strstri(str, "vortices")) != 0)
Strcpy(s + 4, "ex");
/* be careful with "ies"; "priest", "zombies" */
else if (slen > 3 && !strcmpi(term - 3, "ies")
&& (slen < 7 || strcmpi(term - 7, "zombies")))
Strcpy(term - 3, "y");
/* luckily no monster names end in fe or ve with ves plurals */
else if (slen > 3 && !strcmpi(term - 3, "ves"))
Strcpy(term - 3, "f");
slen = strlen(str); /* length possibly needs recomputing */
{
static const struct alt_spl names[] = {
/* Alternate spellings */
{ "grey dragon", PM_GRAY_DRAGON, NEUTRAL },
{ "baby grey dragon", PM_BABY_GRAY_DRAGON, NEUTRAL },
{ "grey unicorn", PM_GRAY_UNICORN, NEUTRAL },
{ "grey ooze", PM_GRAY_OOZE, NEUTRAL },
{ "gray-elf", PM_GREY_ELF, NEUTRAL },
{ "mindflayer", PM_MIND_FLAYER, NEUTRAL },
{ "master mindflayer", PM_MASTER_MIND_FLAYER, NEUTRAL },
/* More alternates; priest and priestess are separate monster
types but that isn't the case for {aligned,high} priests */
{ "aligned priest", PM_ALIGNED_CLERIC, MALE },
{ "aligned priestess", PM_ALIGNED_CLERIC, FEMALE },
{ "high priest", PM_HIGH_CLERIC, MALE },
{ "high priestess", PM_HIGH_CLERIC, FEMALE },
/* Inappropriate singularization by -ves check above */
{ "master of thief", PM_MASTER_OF_THIEVES, NEUTRAL },
/* Potential misspellings where we want to avoid falling back
to the rank title prefix (input has been singularized) */
{ "master thief", PM_MASTER_OF_THIEVES, NEUTRAL },
{ "master of assassin", PM_MASTER_ASSASSIN, NEUTRAL },
/* Outdated names */
{ "invisible stalker", PM_STALKER, NEUTRAL },
{ "high-elf", PM_ELVEN_MONARCH, NEUTRAL }, /* PM_HIGH_ELF is
* obsolete */
/* other misspellings or incorrect words */
{ "wood-elf", PM_WOODLAND_ELF, NEUTRAL },
{ "wood elf", PM_WOODLAND_ELF, NEUTRAL },
{ "woodland nymph", PM_WOOD_NYMPH, NEUTRAL },
{ "halfling", PM_HOBBIT, NEUTRAL }, /* potential guess for
* polyself */
{ "genie", PM_DJINNI, NEUTRAL }, /* potential guess for
* ^G/#wizgenesis */
/* prefix used to workaround duplicate monster names for
monsters with alternate forms */
{ "human wererat", PM_HUMAN_WERERAT, NEUTRAL },
{ "human werejackal", PM_HUMAN_WEREJACKAL, NEUTRAL },
{ "human werewolf", PM_HUMAN_WEREWOLF, NEUTRAL },
/* for completeness */
{ "rat wererat", PM_WERERAT, NEUTRAL },
{ "jackal werejackal", PM_WEREJACKAL, NEUTRAL },
{ "wolf werewolf", PM_WEREWOLF, NEUTRAL },
/* Hyphenated names -- it would be nice to handle these via
fuzzymatch() but it isn't able to ignore trailing stuff */
{ "ki rin", PM_KI_RIN, NEUTRAL },
{ "kirin", PM_KI_RIN, NEUTRAL },
{ "uruk hai", PM_URUK_HAI, NEUTRAL },
{ "orc captain", PM_ORC_CAPTAIN, NEUTRAL },
{ "woodland elf", PM_WOODLAND_ELF, NEUTRAL },
{ "green elf", PM_GREEN_ELF, NEUTRAL },
{ "grey elf", PM_GREY_ELF, NEUTRAL },
{ "gray elf", PM_GREY_ELF, NEUTRAL },
{ "elf lady", PM_ELF_NOBLE, FEMALE },
{ "elf lord", PM_ELF_NOBLE, MALE },
{ "elf noble", PM_ELF_NOBLE, NEUTRAL },
{ "olog hai", PM_OLOG_HAI, NEUTRAL },
{ "arch lich", PM_ARCH_LICH, NEUTRAL },
{ "archlich", PM_ARCH_LICH, NEUTRAL },
/* Some irregular plurals */
{ "incubi", PM_AMOROUS_DEMON, MALE },
{ "succubi", PM_AMOROUS_DEMON, FEMALE },
{ "violet fungi", PM_VIOLET_FUNGUS, NEUTRAL },
{ "homunculi", PM_HOMUNCULUS, NEUTRAL },
{ "baluchitheria", PM_BALUCHITHERIUM, NEUTRAL },
{ "lurkers above", PM_LURKER_ABOVE, NEUTRAL },
{ "cavemen", PM_CAVE_DWELLER, MALE },
{ "cavewomen", PM_CAVE_DWELLER, FEMALE },
{ "watchmen", PM_WATCHMAN, NEUTRAL },
{ "djinn", PM_DJINNI, NEUTRAL },
{ "mumakil", PM_MUMAK, NEUTRAL },
{ "erinyes", PM_ERINYS, NEUTRAL },
/* end of list */
{ 0, NON_PM, NEUTRAL }
};
register const struct alt_spl *namep;
for (namep = names; namep->name; namep++) {
len = (int) strlen(namep->name);
if (!strncmpi(str, namep->name, len)
/* force full word (which could conceivably be possessive) */
&& (!str[len] || str[len] == ' ' || str[len] == '\'')) {
if (remainder_p)
*remainder_p = in_str + (&str[len] - buf);
if (gender_name_var)
*gender_name_var = namep->genderhint;
return namep->pm_val;
}
}
}
for (len = 0, i = LOW_PM; i < NUMMONS; i++) {
for (mgend = MALE; mgend < NUM_MGENDERS; mgend++) {
size_t m_i_len;
if (!mons[i].pmnames[mgend])
continue;
m_i_len = strlen(mons[i].pmnames[mgend]);
if (m_i_len > (size_t) len
&& !strncmpi(mons[i].pmnames[mgend], str, (int) m_i_len)) {
if (m_i_len == slen) {
mntmp = i;
len = (int) m_i_len;
matchgend = mgend;
exact_match = TRUE;
break; /* exact match */
} else if (slen > m_i_len
&& (str[m_i_len] == ' '
|| !strcmpi(&str[m_i_len], "s")
|| !strncmpi(&str[m_i_len], "s ", 2)
|| !strcmpi(&str[m_i_len], "'")
|| !strncmpi(&str[m_i_len], "' ", 2)
|| !strcmpi(&str[m_i_len], "'s")
|| !strncmpi(&str[m_i_len], "'s ", 3)
|| !strcmpi(&str[m_i_len], "es")
|| !strncmpi(&str[m_i_len], "es ", 3))) {
mntmp = i;
len = (int) m_i_len;
matchgend = mgend;
}
}
}
if (exact_match)
break;
}
/* FIXME: some titles have gender; title_to_mon() doesn't propagate it */
if (mntmp == NON_PM)
mntmp = title_to_mon(str, (int *) 0, &len);
if (len && remainder_p)
*remainder_p = in_str + (&str[len] - buf);
if (gender_name_var && matchgend != -1) {
/* don't override with neuter if caller has already specified male
or female and we've matched the neuter name */
if (*gender_name_var == -1 || matchgend != NEUTRAL)
*gender_name_var = matchgend;
}
return mntmp;
}
/* monster class from user input; used for genocide and controlled polymorph;
returns 0 rather than MAXMCLASSES if no match is found */
int
name_to_monclass(const char *in_str, int * mndx_p)
{
/* Single letters are matched against def_monsyms[].sym; words
or phrases are first matched against def_monsyms[].explain
to check class description; if not found there, then against
mons[].pmnames[] to test individual monster types. Input can be a
substring of the full description or pmname, but to be accepted,
such partial matches must start at beginning of a word. Some
class descriptions include "foo or bar" and "foo or other foo"
so we don't want to accept "or", "other", "or other" there. */
static NEARDATA const char *const falsematch[] = {
/* multiple-letter input which matches any of these gets rejected */