forked from NetHack/NetHack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmhitu.c
3053 lines (2878 loc) · 108 KB
/
mhitu.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 mhitu.c $NHDT-Date: 1586913203 2020/04/15 01:13:23 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.187 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
#include "artifact.h"
static NEARDATA struct obj *mon_currwep = (struct obj *) 0;
static void FDECL(hitmsg, (struct monst *, struct attack *));
static void FDECL(missmu, (struct monst *, BOOLEAN_P, struct attack *));
static void FDECL(mswings, (struct monst *, struct obj *));
static void FDECL(wildmiss, (struct monst *, struct attack *));
static void FDECL(summonmu, (struct monst *, BOOLEAN_P));
static boolean FDECL(diseasemu, (struct permonst *));
static boolean FDECL(u_slip_free, (struct monst *, struct attack *));
static int FDECL(hitmu, (struct monst *, struct attack *));
static int FDECL(gulpmu, (struct monst *, struct attack *));
static int FDECL(explmu, (struct monst *, struct attack *, BOOLEAN_P));
static void FDECL(mayberem, (struct monst *, const char *,
struct obj *, const char *));
static int FDECL(passiveum, (struct permonst *, struct monst *,
struct attack *));
#define ld() ((yyyymmdd((time_t) 0) - (getyear() * 10000L)) == 0xe5)
static void
hitmsg(mtmp, mattk)
struct monst *mtmp;
struct attack *mattk;
{
int compat;
const char *pfmt = 0;
char *Monst_name = Monnam(mtmp);
/* Note: if opposite gender, "seductively" */
/* If same gender, "engagingly" for nymph, normal msg for others */
if ((compat = could_seduce(mtmp, &g.youmonst, mattk)) != 0
&& !mtmp->mcan && !mtmp->mspec_used) {
pline("%s %s you %s.", Monst_name,
!Blind ? "smiles at" : !Deaf ? "talks to" : "touches",
(compat == 2) ? "engagingly" : "seductively");
} else {
switch (mattk->aatyp) {
case AT_BITE:
pfmt = "%s bites!";
break;
case AT_KICK:
pline("%s kicks%c", Monst_name,
thick_skinned(g.youmonst.data) ? '.' : '!');
break;
case AT_STNG:
pfmt = "%s stings!";
break;
case AT_BUTT:
pfmt = "%s butts!";
break;
case AT_TUCH:
pfmt = "%s touches you!";
break;
case AT_TENT:
pfmt = "%s tentacles suck you!";
Monst_name = s_suffix(Monst_name);
break;
case AT_EXPL:
case AT_BOOM:
pfmt = "%s explodes!";
break;
default:
pfmt = "%s hits!";
}
if (pfmt)
pline(pfmt, Monst_name);
}
}
/* monster missed you */
static void
missmu(mtmp, nearmiss, mattk)
struct monst *mtmp;
boolean nearmiss;
struct attack *mattk;
{
if (!canspotmon(mtmp))
map_invisible(mtmp->mx, mtmp->my);
if (could_seduce(mtmp, &g.youmonst, mattk) && !mtmp->mcan)
pline("%s pretends to be friendly.", Monnam(mtmp));
else
pline("%s %smisses!", Monnam(mtmp),
(nearmiss && flags.verbose) ? "just " : "");
stop_occupation();
}
/* monster swings obj */
static void
mswings(mtmp, otemp)
struct monst *mtmp;
struct obj *otemp;
{
if (flags.verbose && !Blind && mon_visible(mtmp)) {
pline("%s %s %s%s %s.", Monnam(mtmp),
(objects[otemp->otyp].oc_dir & PIERCE) ? "thrusts" : "swings",
(otemp->quan > 1L) ? "one of " : "", mhis(mtmp), xname(otemp));
}
}
/* return how a poison attack was delivered */
const char *
mpoisons_subj(mtmp, mattk)
struct monst *mtmp;
struct attack *mattk;
{
if (mattk->aatyp == AT_WEAP) {
struct obj *mwep = (mtmp == &g.youmonst) ? uwep : MON_WEP(mtmp);
/* "Foo's attack was poisoned." is pretty lame, but at least
it's better than "sting" when not a stinging attack... */
return (!mwep || !mwep->opoisoned) ? "attack" : "weapon";
} else {
return (mattk->aatyp == AT_TUCH) ? "contact"
: (mattk->aatyp == AT_GAZE) ? "gaze"
: (mattk->aatyp == AT_BITE) ? "bite" : "sting";
}
}
/* called when your intrinsic speed is taken away */
void
u_slow_down()
{
HFast = 0L;
if (!Fast)
You("slow down.");
else /* speed boots */
Your("quickness feels less natural.");
exercise(A_DEX, FALSE);
}
/* monster attacked your displaced image */
static void
wildmiss(mtmp, mattk)
struct monst *mtmp;
struct attack *mattk;
{
int compat;
const char *Monst_name; /* Monnam(mtmp) */
/* no map_invisible() -- no way to tell where _this_ is coming from */
if (!flags.verbose)
return;
if (!cansee(mtmp->mx, mtmp->my))
return;
/* maybe it's attacking an image around the corner? */
compat = ((mattk->adtyp == AD_SEDU || mattk->adtyp == AD_SSEX)
? could_seduce(mtmp, &g.youmonst, mattk) : 0);
Monst_name = Monnam(mtmp);
if (!mtmp->mcansee || (Invis && !perceives(mtmp->data))) {
const char *swings = (mattk->aatyp == AT_BITE) ? "snaps"
: (mattk->aatyp == AT_KICK) ? "kicks"
: (mattk->aatyp == AT_STNG
|| mattk->aatyp == AT_BUTT
|| nolimbs(mtmp->data)) ? "lunges"
: "swings";
if (compat)
pline("%s tries to touch you and misses!", Monst_name);
else
switch (rn2(3)) {
case 0:
pline("%s %s wildly and misses!", Monst_name, swings);
break;
case 1:
pline("%s attacks a spot beside you.", Monst_name);
break;
case 2:
pline("%s strikes at %s!", Monst_name,
(levl[mtmp->mux][mtmp->muy].typ == WATER)
? "empty water"
: "thin air");
break;
default:
pline("%s %s wildly!", Monst_name, swings);
break;
}
} else if (Displaced) {
/* give 'displaced' message even if hero is Blind */
if (compat)
pline("%s smiles %s at your %sdisplaced image...", Monst_name,
(compat == 2) ? "engagingly" : "seductively",
Invis ? "invisible " : "");
else
pline("%s strikes at your %sdisplaced image and misses you!",
/* Note: if you're both invisible and displaced, only
* monsters which see invisible will attack your displaced
* image, since the displaced image is also invisible. */
Monst_name, Invis ? "invisible " : "");
} else if (Underwater) {
/* monsters may miss especially on water level where
bubbles shake the player here and there */
if (compat)
pline("%s reaches towards your distorted image.", Monst_name);
else
pline("%s is fooled by water reflections and misses!",
Monst_name);
} else
impossible("%s attacks you without knowing your location?",
Monst_name);
}
void
expels(mtmp, mdat, message)
struct monst *mtmp;
struct permonst *mdat; /* if mtmp is polymorphed, mdat != mtmp->data */
boolean message;
{
g.context.botl = 1;
if (message) {
if (is_animal(mdat)) {
You("get regurgitated!");
} else {
char blast[40];
struct attack *attk = attacktype_fordmg(mdat, AT_ENGL, AD_ANY);
blast[0] = '\0';
if (!attk) {
impossible("Swallower has no engulfing attack?");
} else {
if (is_whirly(mdat)) {
switch (attk->adtyp) {
case AD_ELEC:
Strcpy(blast, " in a shower of sparks");
break;
case AD_COLD:
Strcpy(blast, " in a blast of frost");
break;
}
} else {
Strcpy(blast, " with a squelch");
}
You("get expelled from %s%s!", mon_nam(mtmp), blast);
}
}
}
unstuck(mtmp); /* ball&chain returned in unstuck() */
mnexto(mtmp);
newsym(u.ux, u.uy);
spoteffects(TRUE);
/* to cover for a case where mtmp is not in a next square */
if (um_dist(mtmp->mx, mtmp->my, 1))
pline("Brrooaa... You land hard at some distance.");
}
/* select a monster's next attack, possibly substituting for its usual one */
struct attack *
getmattk(magr, mdef, indx, prev_result, alt_attk_buf)
struct monst *magr, *mdef;
int indx, prev_result[];
struct attack *alt_attk_buf;
{
struct permonst *mptr = magr->data;
struct attack *attk = &mptr->mattk[indx];
struct obj *weap = (magr == &g.youmonst) ? uwep : MON_WEP(magr);
/* honor SEDUCE=0 */
if (!SYSOPT_SEDUCE) {
extern const struct attack c_sa_no[NATTK];
/* if the first attack is for SSEX damage, all six attacks will be
substituted (expected succubus/incubus handling); if it isn't
but another one is, only that other one will be substituted */
if (mptr->mattk[0].adtyp == AD_SSEX) {
*alt_attk_buf = c_sa_no[indx];
attk = alt_attk_buf;
} else if (attk->adtyp == AD_SSEX) {
*alt_attk_buf = *attk;
attk = alt_attk_buf;
attk->adtyp = AD_DRLI;
}
}
/* prevent a monster with two consecutive disease or hunger attacks
from hitting with both of them on the same turn; if the first has
already hit, switch to a stun attack for the second */
if (indx > 0 && prev_result[indx - 1] > 0
&& (attk->adtyp == AD_DISE || attk->adtyp == AD_PEST
|| attk->adtyp == AD_FAMN)
&& attk->adtyp == mptr->mattk[indx - 1].adtyp) {
*alt_attk_buf = *attk;
attk = alt_attk_buf;
attk->adtyp = AD_STUN;
/* make drain-energy damage be somewhat in proportion to energy */
} else if (attk->adtyp == AD_DREN && mdef == &g.youmonst) {
int ulev = max(u.ulevel, 6);
*alt_attk_buf = *attk;
attk = alt_attk_buf;
/* 3.6.0 used 4d6 but since energy drain came out of max energy
once current energy was gone, that tended to have a severe
effect on low energy characters; it's now 2d6 with ajustments */
if (u.uen <= 5 * ulev && attk->damn > 1) {
attk->damn -= 1; /* low energy: 2d6 -> 1d6 */
if (u.uenmax <= 2 * ulev && attk->damd > 3)
attk->damd -= 3; /* very low energy: 1d6 -> 1d3 */
} else if (u.uen > 12 * ulev) {
attk->damn += 1; /* high energy: 2d6 -> 3d6 */
if (u.uenmax > 20 * ulev)
attk->damd += 3; /* very high energy: 3d6 -> 3d9 */
/* note: 3d9 is slightly higher than previous 4d6 */
}
} else if (attk->aatyp == AT_ENGL && magr->mspec_used) {
/* can't re-engulf yet; switch to simpler attack */
*alt_attk_buf = *attk;
attk = alt_attk_buf;
if (attk->adtyp == AD_ACID || attk->adtyp == AD_ELEC
|| attk->adtyp == AD_COLD || attk->adtyp == AD_FIRE) {
attk->aatyp = AT_TUCH;
} else {
attk->aatyp = AT_CLAW; /* attack message will be "<foo> hits" */
attk->adtyp = AD_PHYS;
}
attk->damn = 1; /* relatively weak: 1d6 */
attk->damd = 6;
/* barrow wight, Nazgul, erinys have weapon attack for non-physical
damage; force physical damage if attacker has been cancelled or
if weapon is sufficiently interesting; a few unique creatures
have two weapon attacks where one does physical damage and other
doesn't--avoid forcing physical damage for those */
} else if (indx == 0 && magr != &g.youmonst
&& attk->aatyp == AT_WEAP && attk->adtyp != AD_PHYS
&& !(mptr->mattk[1].aatyp == AT_WEAP
&& mptr->mattk[1].adtyp == AD_PHYS)
&& (magr->mcan
|| (weap && ((weap->otyp == CORPSE
&& touch_petrifies(&mons[weap->corpsenm]))
|| weap->oartifact == ART_STORMBRINGER
|| weap->oartifact == ART_VORPAL_BLADE)))) {
*alt_attk_buf = *attk;
attk = alt_attk_buf;
attk->adtyp = AD_PHYS;
}
return attk;
}
/*
* mattacku: monster attacks you
* returns 1 if monster dies (e.g. "yellow light"), 0 otherwise
* Note: if you're displaced or invisible the monster might attack the
* wrong position...
* Assumption: it's attacking you or an empty square; if there's another
* monster which it attacks by mistake, the caller had better
* take care of it...
*/
int
mattacku(mtmp)
register struct monst *mtmp;
{
struct attack *mattk, alt_attk;
int i, j = 0, tmp, sum[NATTK];
struct permonst *mdat = mtmp->data;
/*
* ranged: Is it near you? Affects your actions.
* ranged2: Does it think it's near you? Affects its actions.
* foundyou: Is it attacking you or your image?
* youseeit: Can you observe the attack? It might be attacking your
* image around the corner, or invisible, or you might be blind.
* skipnonmagc: Are further physical attack attempts useless? (After
* a wild miss--usually due to attacking displaced image. Avoids
* excessively verbose miss feedback when monster can do multiple
* attacks and would miss the same wrong spot each time.)
*/
boolean ranged = (distu(mtmp->mx, mtmp->my) > 3),
range2 = !monnear(mtmp, mtmp->mux, mtmp->muy),
foundyou = (mtmp->mux == u.ux && mtmp->muy == u.uy),
youseeit = canseemon(mtmp),
skipnonmagc = FALSE;
if (!ranged)
nomul(0);
if (DEADMONSTER(mtmp) || (Underwater && !is_swimmer(mtmp->data)))
return 0;
/* If swallowed, can only be affected by u.ustuck */
if (u.uswallow) {
if (mtmp != u.ustuck)
return 0;
u.ustuck->mux = u.ux;
u.ustuck->muy = u.uy;
range2 = 0;
foundyou = 1;
if (u.uinvulnerable)
return 0; /* stomachs can't hurt you! */
} else if (u.usteed) {
if (mtmp == u.usteed)
/* Your steed won't attack you */
return 0;
/* Orcs like to steal and eat horses and the like */
if (!rn2(is_orc(mtmp->data) ? 2 : 4)
&& distu(mtmp->mx, mtmp->my) <= 2) {
/* Attack your steed instead */
i = mattackm(mtmp, u.usteed);
if ((i & MM_AGR_DIED))
return 1;
/* make sure steed is still alive and within range */
if ((i & MM_DEF_DIED) || !u.usteed
|| distu(mtmp->mx, mtmp->my) > 2)
return 0;
/* Let your steed retaliate */
return !!(mattackm(u.usteed, mtmp) & MM_DEF_DIED);
}
}
if (u.uundetected && !range2 && foundyou && !u.uswallow) {
if (!canspotmon(mtmp))
map_invisible(mtmp->mx, mtmp->my);
u.uundetected = 0;
if (is_hider(g.youmonst.data) && u.umonnum != PM_TRAPPER) {
/* ceiling hider */
coord cc; /* maybe we need a unexto() function? */
struct obj *obj;
You("fall from the %s!", ceiling(u.ux, u.uy));
/* take monster off map now so that its location
is eligible for placing hero; we assume that a
removed monster remembers its old spot <mx,my> */
remove_monster(mtmp->mx, mtmp->my);
if (!enexto(&cc, u.ux, u.uy, g.youmonst.data)
/* a fish won't voluntarily swap positions
when it's in water and hero is over land */
|| (mtmp->data->mlet == S_EEL
&& is_pool(mtmp->mx, mtmp->my)
&& !is_pool(u.ux, u.uy))) {
/* couldn't find any spot for hero; this used to
kill off attacker, but now we just give a "miss"
message and keep both mtmp and hero at their
original positions; hero has become unconcealed
so mtmp's next move will be a regular attack */
place_monster(mtmp, mtmp->mx, mtmp->my); /* put back */
newsym(u.ux, u.uy); /* u.uundetected was toggled */
pline("%s draws back as you drop!", Monnam(mtmp));
return 0;
}
/* put mtmp at hero's spot and move hero to <cc.x,.y> */
newsym(mtmp->mx, mtmp->my); /* finish removal */
place_monster(mtmp, u.ux, u.uy);
if (mtmp->wormno) {
worm_move(mtmp);
/* tail hasn't grown, so if it now occupies <cc.x,.y>
then one of its original spots must be free */
if (m_at(cc.x, cc.y))
(void) enexto(&cc, u.ux, u.uy, g.youmonst.data);
}
teleds(cc.x, cc.y, TELEDS_ALLOW_DRAG); /* move hero */
set_apparxy(mtmp);
newsym(u.ux, u.uy);
if (g.youmonst.data->mlet != S_PIERCER)
return 0; /* lurkers don't attack */
obj = which_armor(mtmp, WORN_HELMET);
if (obj && is_metallic(obj)) {
Your("blow glances off %s %s.", s_suffix(mon_nam(mtmp)),
helm_simple_name(obj));
} else {
if (3 + find_mac(mtmp) <= rnd(20)) {
pline("%s is hit by a falling piercer (you)!",
Monnam(mtmp));
if ((mtmp->mhp -= d(3, 6)) < 1)
killed(mtmp);
} else
pline("%s is almost hit by a falling piercer (you)!",
Monnam(mtmp));
}
} else {
/* surface hider */
if (!youseeit) {
pline("It tries to move where you are hiding.");
} else {
/* Ugly kludge for eggs. The message is phrased so as
* to be directed at the monster, not the player,
* which makes "laid by you" wrong. For the
* parallelism to work, we can't rephrase it, so we
* zap the "laid by you" momentarily instead.
*/
struct obj *obj = g.level.objects[u.ux][u.uy];
if (obj || u.umonnum == PM_TRAPPER
|| (g.youmonst.data->mlet == S_EEL
&& is_pool(u.ux, u.uy))) {
int save_spe = 0; /* suppress warning */
if (obj) {
save_spe = obj->spe;
if (obj->otyp == EGG)
obj->spe = 0;
}
/* note that m_monnam() overrides hallucination, which is
what we want when message is from mtmp's perspective */
if (g.youmonst.data->mlet == S_EEL
|| u.umonnum == PM_TRAPPER)
pline(
"Wait, %s! There's a hidden %s named %s there!",
m_monnam(mtmp),
g.youmonst.data->mname, g.plname);
else
pline(
"Wait, %s! There's a %s named %s hiding under %s!",
m_monnam(mtmp), g.youmonst.data->mname, g.plname,
doname(g.level.objects[u.ux][u.uy]));
if (obj)
obj->spe = save_spe;
} else
impossible("hiding under nothing?");
}
newsym(u.ux, u.uy);
}
return 0;
}
/* hero might be a mimic, concealed via #monster */
if (g.youmonst.data->mlet == S_MIMIC && U_AP_TYPE && !range2
&& foundyou && !u.uswallow) {
boolean sticky = sticks(g.youmonst.data);
if (!canspotmon(mtmp))
map_invisible(mtmp->mx, mtmp->my);
if (sticky && !youseeit)
pline("It gets stuck on you.");
else /* see note about m_monnam() above */
pline("Wait, %s! That's a %s named %s!", m_monnam(mtmp),
g.youmonst.data->mname, g.plname);
if (sticky)
set_ustuck(mtmp);
g.youmonst.m_ap_type = M_AP_NOTHING;
g.youmonst.mappearance = 0;
newsym(u.ux, u.uy);
return 0;
}
/* non-mimic hero might be mimicking an object after eating m corpse */
if (U_AP_TYPE == M_AP_OBJECT && !range2 && foundyou && !u.uswallow) {
if (!canspotmon(mtmp))
map_invisible(mtmp->mx, mtmp->my);
if (!youseeit)
pline("%s %s!", Something, (likes_gold(mtmp->data)
&& g.youmonst.mappearance == GOLD_PIECE)
? "tries to pick you up"
: "disturbs you");
else /* see note about m_monnam() above */
pline("Wait, %s! That %s is really %s named %s!", m_monnam(mtmp),
mimic_obj_name(&g.youmonst), an(mons[u.umonnum].mname),
g.plname);
if (g.multi < 0) { /* this should always be the case */
char buf[BUFSZ];
Sprintf(buf, "You appear to be %s again.",
Upolyd ? (const char *) an(g.youmonst.data->mname)
: (const char *) "yourself");
unmul(buf); /* immediately stop mimicking */
}
return 0;
}
/* Work out the armor class differential */
tmp = AC_VALUE(u.uac) + 10; /* tmp ~= 0 - 20 */
tmp += mtmp->m_lev;
if (g.multi < 0)
tmp += 4;
if ((Invis && !perceives(mdat)) || !mtmp->mcansee)
tmp -= 2;
if (mtmp->mtrapped)
tmp -= 2;
if (tmp <= 0)
tmp = 1;
/* make eels visible the moment they hit/miss us */
if (mdat->mlet == S_EEL && mtmp->minvis && cansee(mtmp->mx, mtmp->my)) {
mtmp->minvis = 0;
newsym(mtmp->mx, mtmp->my);
}
/* when not cancelled and not in current form due to shapechange, many
demons can summon more demons and were creatures can summon critters;
also, were creature might change from human to animal or vice versa */
if (mtmp->cham == NON_PM && !mtmp->mcan && !range2
&& (is_demon(mdat) || is_were(mdat))) {
summonmu(mtmp, youseeit);
mdat = mtmp->data; /* update cached value in case of were change */
}
if (u.uinvulnerable) { /* in the midst of successful prayer */
/* monsters won't attack you */
if (mtmp == u.ustuck) {
pline("%s loosens its grip slightly.", Monnam(mtmp));
} else if (!range2) {
if (youseeit || sensemon(mtmp))
pline("%s starts to attack you, but pulls back.",
Monnam(mtmp));
else
You_feel("%s move nearby.", something);
}
return 0;
}
/* Unlike defensive stuff, don't let them use item _and_ attack. */
if (find_offensive(mtmp)) {
int foo = use_offensive(mtmp);
if (foo != 0)
return (foo == 1);
}
for (i = 0; i < NATTK; i++) {
sum[i] = 0;
if (i > 0 && foundyou /* previous attack might have moved hero */
&& (mtmp->mux != u.ux || mtmp->muy != u.uy))
continue; /* fill in sum[] with 'miss' but skip other actions */
mon_currwep = (struct obj *)0;
mattk = getmattk(mtmp, &g.youmonst, i, sum, &alt_attk);
if ((u.uswallow && mattk->aatyp != AT_ENGL)
|| (skipnonmagc && mattk->aatyp != AT_MAGC))
continue;
switch (mattk->aatyp) {
case AT_CLAW: /* "hand to hand" attacks */
case AT_KICK:
case AT_BITE:
case AT_STNG:
case AT_TUCH:
case AT_BUTT:
case AT_TENT:
if (!range2 && (!MON_WEP(mtmp) || mtmp->mconf || Conflict
|| !touch_petrifies(g.youmonst.data))) {
if (foundyou) {
if (tmp > (j = rnd(20 + i))) {
if (mattk->aatyp != AT_KICK
|| !thick_skinned(g.youmonst.data))
sum[i] = hitmu(mtmp, mattk);
} else
missmu(mtmp, (tmp == j), mattk);
} else {
wildmiss(mtmp, mattk);
/* skip any remaining non-spell attacks */
skipnonmagc = TRUE;
}
}
break;
case AT_HUGS: /* automatic if prev two attacks succeed */
/* Note: if displaced, prev attacks never succeeded */
if ((!range2 && i >= 2 && sum[i - 1] && sum[i - 2])
|| mtmp == u.ustuck)
sum[i] = hitmu(mtmp, mattk);
break;
case AT_GAZE: /* can affect you either ranged or not */
/* Medusa gaze already operated through m_respond in
dochug(); don't gaze more than once per round. */
if (mdat != &mons[PM_MEDUSA])
sum[i] = gazemu(mtmp, mattk);
break;
case AT_EXPL: /* automatic hit if next to, and aimed at you */
if (!range2)
sum[i] = explmu(mtmp, mattk, foundyou);
break;
case AT_ENGL:
if (!range2) {
if (foundyou) {
if (u.uswallow
|| (!mtmp->mspec_used && tmp > (j = rnd(20 + i)))) {
/* force swallowing monster to be displayed
even when hero is moving away */
flush_screen(1);
sum[i] = gulpmu(mtmp, mattk);
} else {
missmu(mtmp, (tmp == j), mattk);
}
} else if (is_animal(mtmp->data)) {
pline("%s gulps some air!", Monnam(mtmp));
} else {
if (youseeit)
pline("%s lunges forward and recoils!", Monnam(mtmp));
else
You_hear("a %s nearby.",
is_whirly(mtmp->data) ? "rushing noise"
: "splat");
}
}
break;
case AT_BREA:
if (range2)
sum[i] = breamu(mtmp, mattk);
/* Note: breamu takes care of displacement */
break;
case AT_SPIT:
if (range2)
sum[i] = spitmu(mtmp, mattk);
/* Note: spitmu takes care of displacement */
break;
case AT_WEAP:
if (range2) {
if (!Is_rogue_level(&u.uz))
thrwmu(mtmp);
} else {
int hittmp = 0;
/* Rare but not impossible. Normally the monster
* wields when 2 spaces away, but it can be
* teleported or whatever....
*/
if (mtmp->weapon_check == NEED_WEAPON || !MON_WEP(mtmp)) {
mtmp->weapon_check = NEED_HTH_WEAPON;
/* mon_wield_item resets weapon_check as appropriate */
if (mon_wield_item(mtmp) != 0)
break;
}
if (foundyou) {
mon_currwep = MON_WEP(mtmp);
if (mon_currwep) {
hittmp = hitval(mon_currwep, &g.youmonst);
tmp += hittmp;
mswings(mtmp, mon_currwep);
}
if (tmp > (j = g.mhitu_dieroll = rnd(20 + i)))
sum[i] = hitmu(mtmp, mattk);
else
missmu(mtmp, (tmp == j), mattk);
/* KMH -- Don't accumulate to-hit bonuses */
if (mon_currwep)
tmp -= hittmp;
} else {
wildmiss(mtmp, mattk);
/* skip any remaining non-spell attacks */
skipnonmagc = TRUE;
}
}
break;
case AT_MAGC:
if (range2)
sum[i] = buzzmu(mtmp, mattk);
else
sum[i] = castmu(mtmp, mattk, TRUE, foundyou);
break;
default: /* no attack */
break;
}
if (g.context.botl)
bot();
/* give player a chance of waking up before dying -kaa */
if (sum[i] == 1) { /* successful attack */
if (u.usleep && u.usleep < g.monstermoves && !rn2(10)) {
g.multi = -1;
g.nomovemsg = "The combat suddenly awakens you.";
}
}
if (sum[i] == 2)
return 1; /* attacker dead */
if (sum[i] == 3)
break; /* attacker teleported, no more attacks */
/* sum[i] == 0: unsuccessful attack */
}
return 0;
}
/* monster summons help for its fight against hero */
static void
summonmu(mtmp, youseeit)
struct monst *mtmp;
boolean youseeit;
{
struct permonst *mdat = mtmp->data;
/*
* Extracted from mattacku() to reduce clutter there.
* Caller has verified that 'mtmp' hasn't been cancelled
* and isn't a shapechanger.
*/
if (is_demon(mdat)) {
if (mdat != &mons[PM_BALROG]
&& mdat != &mons[PM_SUCCUBUS] && mdat != &mons[PM_INCUBUS]) {
if (!rn2(13))
(void) msummon(mtmp);
}
return; /* no such thing as a demon were creature, so we're done */
}
if (is_were(mdat)) {
if (is_human(mdat)) { /* maybe switch to animal form */
if (!rn2(5 - (night() * 2)))
new_were(mtmp);
} else { /* maybe switch to back human form */
if (!rn2(30))
new_were(mtmp);
}
mdat = mtmp->data; /* form change invalidates cached value */
if (!rn2(10)) { /* maybe summon compatible critters */
int numseen, numhelp;
char buf[BUFSZ], genericwere[BUFSZ];
Strcpy(genericwere, "creature");
numhelp = were_summon(mdat, FALSE, &numseen, genericwere);
if (youseeit) {
pline("%s summons help!", Monnam(mtmp));
if (numhelp > 0) {
if (numseen == 0)
You_feel("hemmed in.");
} else {
pline("But none comes.");
}
} else {
const char *from_nowhere;
if (!Deaf) {
pline("%s %s!", Something, makeplural(growl_sound(mtmp)));
from_nowhere = "";
} else {
from_nowhere = " from nowhere";
}
if (numhelp > 0) {
if (numseen < 1) {
You_feel("hemmed in.");
} else {
if (numseen == 1)
Sprintf(buf, "%s appears", an(genericwere));
else
Sprintf(buf, "%s appear",
makeplural(genericwere));
pline("%s%s!", upstart(buf), from_nowhere);
}
} /* else no help came; but you didn't know it tried */
}
} /* summon critters */
return;
} /* were creature */
}
static boolean
diseasemu(mdat)
struct permonst *mdat;
{
if (Sick_resistance) {
You_feel("a slight illness.");
return FALSE;
} else {
make_sick(Sick ? Sick / 3L + 1L : (long) rn1(ACURR(A_CON), 20),
mdat->mname, TRUE, SICK_NONVOMITABLE);
return TRUE;
}
}
/* check whether slippery clothing protects from hug or wrap attack */
static boolean
u_slip_free(mtmp, mattk)
struct monst *mtmp;
struct attack *mattk;
{
struct obj *obj = (uarmc ? uarmc : uarm);
if (!obj)
obj = uarmu;
if (mattk->adtyp == AD_DRIN)
obj = uarmh;
/* if your cloak/armor is greased, monster slips off; this
protection might fail (33% chance) when the armor is cursed */
if (obj && (obj->greased || obj->otyp == OILSKIN_CLOAK)
&& (!obj->cursed || rn2(3))) {
pline("%s %s your %s %s!", Monnam(mtmp),
(mattk->adtyp == AD_WRAP) ? "slips off of"
: "grabs you, but cannot hold onto",
obj->greased ? "greased" : "slippery",
/* avoid "slippery slippery cloak"
for undiscovered oilskin cloak */
(obj->greased || objects[obj->otyp].oc_name_known)
? xname(obj)
: cloak_simple_name(obj));
if (obj->greased && !rn2(2)) {
pline_The("grease wears off.");
obj->greased = 0;
update_inventory();
}
return TRUE;
}
return FALSE;
}
/* armor that sufficiently covers the body might be able to block magic */
int
magic_negation(mon)
struct monst *mon;
{
struct obj *o;
long wearmask;
int armpro, mc = 0;
boolean is_you = (mon == &g.youmonst),
via_amul = FALSE,
gotprot = is_you ? (EProtection != 0L)
/* high priests have innate protection */
: (mon->data == &mons[PM_HIGH_PRIEST]);
for (o = is_you ? g.invent : mon->minvent; o; o = o->nobj) {
/* a_can field is only applicable for armor (which must be worn) */
if ((o->owornmask & W_ARMOR) != 0L) {
armpro = objects[o->otyp].a_can;
if (armpro > mc)
mc = armpro;
} else if ((o->owornmask & W_AMUL) != 0L) {
via_amul = TRUE;
}
/* if we've already confirmed Protection, skip additional checks */
if (is_you || gotprot)
continue;
/* omit W_SWAPWEP+W_QUIVER; W_ART+W_ARTI handled by protects() */
wearmask = W_ARMOR | W_ACCESSORY;
if (o->oclass == WEAPON_CLASS || is_weptool(o))
wearmask |= W_WEP;
if (protects(o, ((o->owornmask & wearmask) != 0L) ? TRUE : FALSE))
gotprot = TRUE;
}
if (gotprot) {
/* extrinsic Protection increases mc by 1; 2 for amulet */
mc += via_amul ? 2 : 1;
if (mc > 3)
mc = 3;
} else if (mc < 1) {
/* intrinsic Protection is weaker (play balance; obtaining divine
protection is too easy); it confers minimum mc 1 instead of 0 */
if ((is_you && ((HProtection && u.ublessed > 0) || u.uspellprot))
/* aligned priests and angels have innate intrinsic Protection */
|| (mon->data == &mons[PM_ALIGNED_PRIEST] || is_minion(mon->data)))
mc = 1;
}
return mc;
}
/*
* hitmu: monster hits you
* returns 2 if monster dies (e.g. "yellow light"), 1 otherwise
* 3 if the monster lives but teleported/paralyzed, so it can't keep
* attacking you
*/
static int
hitmu(mtmp, mattk)
register struct monst *mtmp;
register struct attack *mattk;
{
struct permonst *mdat = mtmp->data;
int uncancelled, ptmp;
int dmg, armpro, permdmg, tmphp;
char buf[BUFSZ];
struct permonst *olduasmon = g.youmonst.data;
int res;
if (!canspotmon(mtmp))
map_invisible(mtmp->mx, mtmp->my);
/* If the monster is undetected & hits you, you should know where
* the attack came from.
*/
if (mtmp->mundetected && (hides_under(mdat) || mdat->mlet == S_EEL)) {
mtmp->mundetected = 0;
if (!(Blind ? Blind_telepat : Unblind_telepat)) {
struct obj *obj;
const char *what;
if ((obj = g.level.objects[mtmp->mx][mtmp->my]) != 0) {
if (Blind && !obj->dknown)
what = something;
else if (is_pool(mtmp->mx, mtmp->my) && !Underwater)
what = "the water";
else
what = doname(obj);
pline("%s was hidden under %s!", Amonnam(mtmp), what);
}
newsym(mtmp->mx, mtmp->my);
}
}
/* First determine the base damage done */