1*41242Sbostic /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2*41242Sbostic /* hack.mhitu.c - version 1.0.3 */
3*41242Sbostic
4*41242Sbostic #include "hack.h"
5*41242Sbostic extern struct monst *makemon();
6*41242Sbostic
7*41242Sbostic /*
8*41242Sbostic * mhitu: monster hits you
9*41242Sbostic * returns 1 if monster dies (e.g. 'y', 'F'), 0 otherwise
10*41242Sbostic */
mhitu(mtmp)11*41242Sbostic mhitu(mtmp)
12*41242Sbostic register struct monst *mtmp;
13*41242Sbostic {
14*41242Sbostic register struct permonst *mdat = mtmp->data;
15*41242Sbostic register int tmp, ctmp;
16*41242Sbostic
17*41242Sbostic nomul(0);
18*41242Sbostic
19*41242Sbostic /* If swallowed, can only be affected by hissers and by u.ustuck */
20*41242Sbostic if(u.uswallow) {
21*41242Sbostic if(mtmp != u.ustuck) {
22*41242Sbostic if(mdat->mlet == 'c' && !rn2(13)) {
23*41242Sbostic pline("Outside, you hear %s's hissing!",
24*41242Sbostic monnam(mtmp));
25*41242Sbostic pline("%s gets turned to stone!",
26*41242Sbostic Monnam(u.ustuck));
27*41242Sbostic pline("And the same fate befalls you.");
28*41242Sbostic done_in_by(mtmp);
29*41242Sbostic /* "notreached": not return(1); */
30*41242Sbostic }
31*41242Sbostic return(0);
32*41242Sbostic }
33*41242Sbostic switch(mdat->mlet) { /* now mtmp == u.ustuck */
34*41242Sbostic case ',':
35*41242Sbostic youswld(mtmp, (u.uac > 0) ? u.uac+4 : 4,
36*41242Sbostic 5, "The trapper");
37*41242Sbostic break;
38*41242Sbostic case '\'':
39*41242Sbostic youswld(mtmp,rnd(6),7,"The lurker above");
40*41242Sbostic break;
41*41242Sbostic case 'P':
42*41242Sbostic youswld(mtmp,d(2,4),12,"The purple worm");
43*41242Sbostic break;
44*41242Sbostic default:
45*41242Sbostic /* This is not impossible! */
46*41242Sbostic pline("The mysterious monster totally digests you.");
47*41242Sbostic u.uhp = 0;
48*41242Sbostic }
49*41242Sbostic if(u.uhp < 1) done_in_by(mtmp);
50*41242Sbostic return(0);
51*41242Sbostic }
52*41242Sbostic
53*41242Sbostic if(mdat->mlet == 'c' && Stoned)
54*41242Sbostic return(0);
55*41242Sbostic
56*41242Sbostic /* make eels visible the moment they hit/miss us */
57*41242Sbostic if(mdat->mlet == ';' && mtmp->minvis && cansee(mtmp->mx,mtmp->my)){
58*41242Sbostic mtmp->minvis = 0;
59*41242Sbostic pmon(mtmp);
60*41242Sbostic }
61*41242Sbostic if(!index("1&DuxynNF",mdat->mlet))
62*41242Sbostic tmp = hitu(mtmp,d(mdat->damn,mdat->damd));
63*41242Sbostic else
64*41242Sbostic tmp = 0;
65*41242Sbostic if(index(UNDEAD, mdat->mlet) && midnight())
66*41242Sbostic tmp += hitu(mtmp,d(mdat->damn,mdat->damd));
67*41242Sbostic
68*41242Sbostic ctmp = tmp && !mtmp->mcan &&
69*41242Sbostic (!uarm || objects[uarm->otyp].a_can < rnd(3) || !rn2(50));
70*41242Sbostic switch(mdat->mlet) {
71*41242Sbostic case '1':
72*41242Sbostic if(wiz_hit(mtmp)) return(1); /* he disappeared */
73*41242Sbostic break;
74*41242Sbostic case '&':
75*41242Sbostic if(!mtmp->cham && !mtmp->mcan && !rn2(13)) {
76*41242Sbostic (void) makemon(PM_DEMON,u.ux,u.uy);
77*41242Sbostic } else {
78*41242Sbostic (void) hitu(mtmp,d(2,6));
79*41242Sbostic (void) hitu(mtmp,d(2,6));
80*41242Sbostic (void) hitu(mtmp,rnd(3));
81*41242Sbostic (void) hitu(mtmp,rnd(3));
82*41242Sbostic (void) hitu(mtmp,rn1(4,2));
83*41242Sbostic }
84*41242Sbostic break;
85*41242Sbostic case ',':
86*41242Sbostic if(tmp) justswld(mtmp,"The trapper");
87*41242Sbostic break;
88*41242Sbostic case '\'':
89*41242Sbostic if(tmp) justswld(mtmp, "The lurker above");
90*41242Sbostic break;
91*41242Sbostic case ';':
92*41242Sbostic if(ctmp) {
93*41242Sbostic if(!u.ustuck && !rn2(10)) {
94*41242Sbostic pline("%s swings itself around you!",
95*41242Sbostic Monnam(mtmp));
96*41242Sbostic u.ustuck = mtmp;
97*41242Sbostic } else if(u.ustuck == mtmp &&
98*41242Sbostic levl[mtmp->mx][mtmp->my].typ == POOL) {
99*41242Sbostic pline("%s drowns you ...", Monnam(mtmp));
100*41242Sbostic done("drowned");
101*41242Sbostic }
102*41242Sbostic }
103*41242Sbostic break;
104*41242Sbostic case 'A':
105*41242Sbostic if(ctmp && rn2(2)) {
106*41242Sbostic if(Poison_resistance)
107*41242Sbostic pline("The sting doesn't seem to affect you.");
108*41242Sbostic else {
109*41242Sbostic pline("You feel weaker!");
110*41242Sbostic losestr(1);
111*41242Sbostic }
112*41242Sbostic }
113*41242Sbostic break;
114*41242Sbostic case 'C':
115*41242Sbostic (void) hitu(mtmp,rnd(6));
116*41242Sbostic break;
117*41242Sbostic case 'c':
118*41242Sbostic if(!rn2(5)) {
119*41242Sbostic pline("You hear %s's hissing!", monnam(mtmp));
120*41242Sbostic if(ctmp || !rn2(20) || (flags.moonphase == NEW_MOON
121*41242Sbostic && !carrying(DEAD_LIZARD))) {
122*41242Sbostic Stoned = 5;
123*41242Sbostic /* pline("You get turned to stone!"); */
124*41242Sbostic /* done_in_by(mtmp); */
125*41242Sbostic }
126*41242Sbostic }
127*41242Sbostic break;
128*41242Sbostic case 'D':
129*41242Sbostic if(rn2(6) || mtmp->mcan) {
130*41242Sbostic (void) hitu(mtmp,d(3,10));
131*41242Sbostic (void) hitu(mtmp,rnd(8));
132*41242Sbostic (void) hitu(mtmp,rnd(8));
133*41242Sbostic break;
134*41242Sbostic }
135*41242Sbostic kludge("%s breathes fire!","The dragon");
136*41242Sbostic buzz(-1,mtmp->mx,mtmp->my,u.ux-mtmp->mx,u.uy-mtmp->my);
137*41242Sbostic break;
138*41242Sbostic case 'd':
139*41242Sbostic (void) hitu(mtmp,d(2, (flags.moonphase == FULL_MOON) ? 3 : 4));
140*41242Sbostic break;
141*41242Sbostic case 'e':
142*41242Sbostic (void) hitu(mtmp,d(3,6));
143*41242Sbostic break;
144*41242Sbostic case 'F':
145*41242Sbostic if(mtmp->mcan) break;
146*41242Sbostic kludge("%s explodes!","The freezing sphere");
147*41242Sbostic if(Cold_resistance) pline("You don't seem affected by it.");
148*41242Sbostic else {
149*41242Sbostic xchar dn;
150*41242Sbostic if(17-(u.ulevel/2) > rnd(20)) {
151*41242Sbostic pline("You get blasted!");
152*41242Sbostic dn = 6;
153*41242Sbostic } else {
154*41242Sbostic pline("You duck the blast...");
155*41242Sbostic dn = 3;
156*41242Sbostic }
157*41242Sbostic losehp_m(d(dn,6), mtmp);
158*41242Sbostic }
159*41242Sbostic mondead(mtmp);
160*41242Sbostic return(1);
161*41242Sbostic case 'g':
162*41242Sbostic if(ctmp && multi >= 0 && !rn2(3)) {
163*41242Sbostic kludge("You are frozen by %ss juices","the cube'");
164*41242Sbostic nomul(-rnd(10));
165*41242Sbostic }
166*41242Sbostic break;
167*41242Sbostic case 'h':
168*41242Sbostic if(ctmp && multi >= 0 && !rn2(5)) {
169*41242Sbostic nomul(-rnd(10));
170*41242Sbostic kludge("You are put to sleep by %ss bite!",
171*41242Sbostic "the homunculus'");
172*41242Sbostic }
173*41242Sbostic break;
174*41242Sbostic case 'j':
175*41242Sbostic tmp = hitu(mtmp,rnd(3));
176*41242Sbostic tmp &= hitu(mtmp,rnd(3));
177*41242Sbostic if(tmp){
178*41242Sbostic (void) hitu(mtmp,rnd(4));
179*41242Sbostic (void) hitu(mtmp,rnd(4));
180*41242Sbostic }
181*41242Sbostic break;
182*41242Sbostic case 'k':
183*41242Sbostic if((hitu(mtmp,rnd(4)) || !rn2(3)) && ctmp){
184*41242Sbostic poisoned("bee's sting",mdat->mname);
185*41242Sbostic }
186*41242Sbostic break;
187*41242Sbostic case 'L':
188*41242Sbostic if(tmp) stealgold(mtmp);
189*41242Sbostic break;
190*41242Sbostic case 'N':
191*41242Sbostic if(mtmp->mcan && !Blind) {
192*41242Sbostic pline("%s tries to seduce you, but you seem not interested.",
193*41242Sbostic Amonnam(mtmp, "plain"));
194*41242Sbostic if(rn2(3)) rloc(mtmp);
195*41242Sbostic } else if(steal(mtmp)) {
196*41242Sbostic rloc(mtmp);
197*41242Sbostic mtmp->mflee = 1;
198*41242Sbostic }
199*41242Sbostic break;
200*41242Sbostic case 'n':
201*41242Sbostic if(!uwep && !uarm && !uarmh && !uarms && !uarmg) {
202*41242Sbostic pline("%s hits! (I hope you don't mind)",
203*41242Sbostic Monnam(mtmp));
204*41242Sbostic u.uhp += rnd(7);
205*41242Sbostic if(!rn2(7)) u.uhpmax++;
206*41242Sbostic if(u.uhp > u.uhpmax) u.uhp = u.uhpmax;
207*41242Sbostic flags.botl = 1;
208*41242Sbostic if(!rn2(50)) rloc(mtmp);
209*41242Sbostic } else {
210*41242Sbostic (void) hitu(mtmp,d(2,6));
211*41242Sbostic (void) hitu(mtmp,d(2,6));
212*41242Sbostic }
213*41242Sbostic break;
214*41242Sbostic case 'o':
215*41242Sbostic tmp = hitu(mtmp,rnd(6));
216*41242Sbostic if(hitu(mtmp,rnd(6)) && tmp && /* hits with both paws */
217*41242Sbostic !u.ustuck && rn2(2)) {
218*41242Sbostic u.ustuck = mtmp;
219*41242Sbostic kludge("%s has grabbed you!","The owlbear");
220*41242Sbostic u.uhp -= d(2,8);
221*41242Sbostic } else if(u.ustuck == mtmp) {
222*41242Sbostic u.uhp -= d(2,8);
223*41242Sbostic pline("You are being crushed.");
224*41242Sbostic }
225*41242Sbostic break;
226*41242Sbostic case 'P':
227*41242Sbostic if(ctmp && !rn2(4))
228*41242Sbostic justswld(mtmp,"The purple worm");
229*41242Sbostic else
230*41242Sbostic (void) hitu(mtmp,d(2,4));
231*41242Sbostic break;
232*41242Sbostic case 'Q':
233*41242Sbostic (void) hitu(mtmp,rnd(2));
234*41242Sbostic (void) hitu(mtmp,rnd(2));
235*41242Sbostic break;
236*41242Sbostic case 'R':
237*41242Sbostic if(tmp && uarmh && !uarmh->rustfree &&
238*41242Sbostic (int) uarmh->spe >= -1) {
239*41242Sbostic pline("Your helmet rusts!");
240*41242Sbostic uarmh->spe--;
241*41242Sbostic } else
242*41242Sbostic if(ctmp && uarm && !uarm->rustfree && /* Mike Newton */
243*41242Sbostic uarm->otyp < STUDDED_LEATHER_ARMOR &&
244*41242Sbostic (int) uarm->spe >= -1) {
245*41242Sbostic pline("Your armor rusts!");
246*41242Sbostic uarm->spe--;
247*41242Sbostic }
248*41242Sbostic break;
249*41242Sbostic case 'S':
250*41242Sbostic if(ctmp && !rn2(8)) {
251*41242Sbostic poisoned("snake's bite",mdat->mname);
252*41242Sbostic }
253*41242Sbostic break;
254*41242Sbostic case 's':
255*41242Sbostic if(tmp && !rn2(8)) {
256*41242Sbostic poisoned("scorpion's sting",mdat->mname);
257*41242Sbostic }
258*41242Sbostic (void) hitu(mtmp,rnd(8));
259*41242Sbostic (void) hitu(mtmp,rnd(8));
260*41242Sbostic break;
261*41242Sbostic case 'T':
262*41242Sbostic (void) hitu(mtmp,rnd(6));
263*41242Sbostic (void) hitu(mtmp,rnd(6));
264*41242Sbostic break;
265*41242Sbostic case 't':
266*41242Sbostic if(!rn2(5)) rloc(mtmp);
267*41242Sbostic break;
268*41242Sbostic case 'u':
269*41242Sbostic mtmp->mflee = 1;
270*41242Sbostic break;
271*41242Sbostic case 'U':
272*41242Sbostic (void) hitu(mtmp,d(3,4));
273*41242Sbostic (void) hitu(mtmp,d(3,4));
274*41242Sbostic break;
275*41242Sbostic case 'v':
276*41242Sbostic if(ctmp && !u.ustuck) u.ustuck = mtmp;
277*41242Sbostic break;
278*41242Sbostic case 'V':
279*41242Sbostic if(tmp) u.uhp -= 4;
280*41242Sbostic if(ctmp) losexp();
281*41242Sbostic break;
282*41242Sbostic case 'W':
283*41242Sbostic if(ctmp) losexp();
284*41242Sbostic break;
285*41242Sbostic #ifndef NOWORM
286*41242Sbostic case 'w':
287*41242Sbostic if(tmp) wormhit(mtmp);
288*41242Sbostic #endif NOWORM
289*41242Sbostic break;
290*41242Sbostic case 'X':
291*41242Sbostic (void) hitu(mtmp,rnd(5));
292*41242Sbostic (void) hitu(mtmp,rnd(5));
293*41242Sbostic (void) hitu(mtmp,rnd(5));
294*41242Sbostic break;
295*41242Sbostic case 'x':
296*41242Sbostic { register long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE;
297*41242Sbostic pline("%s pricks in your %s leg!",
298*41242Sbostic Monnam(mtmp), (side == RIGHT_SIDE) ? "right" : "left");
299*41242Sbostic set_wounded_legs(side, rnd(50));
300*41242Sbostic losehp_m(2, mtmp);
301*41242Sbostic break;
302*41242Sbostic }
303*41242Sbostic case 'y':
304*41242Sbostic if(mtmp->mcan) break;
305*41242Sbostic mondead(mtmp);
306*41242Sbostic if(!Blind) {
307*41242Sbostic pline("You are blinded by a blast of light!");
308*41242Sbostic Blind = d(4,12);
309*41242Sbostic seeoff(0);
310*41242Sbostic }
311*41242Sbostic return(1);
312*41242Sbostic case 'Y':
313*41242Sbostic (void) hitu(mtmp,rnd(6));
314*41242Sbostic break;
315*41242Sbostic }
316*41242Sbostic if(u.uhp < 1) done_in_by(mtmp);
317*41242Sbostic return(0);
318*41242Sbostic }
319*41242Sbostic
hitu(mtmp,dam)320*41242Sbostic hitu(mtmp,dam)
321*41242Sbostic register struct monst *mtmp;
322*41242Sbostic register dam;
323*41242Sbostic {
324*41242Sbostic register tmp, res;
325*41242Sbostic
326*41242Sbostic nomul(0);
327*41242Sbostic if(u.uswallow) return(0);
328*41242Sbostic
329*41242Sbostic if(mtmp->mhide && mtmp->mundetected) {
330*41242Sbostic mtmp->mundetected = 0;
331*41242Sbostic if(!Blind) {
332*41242Sbostic register struct obj *obj;
333*41242Sbostic extern char * Xmonnam();
334*41242Sbostic if(obj = o_at(mtmp->mx,mtmp->my))
335*41242Sbostic pline("%s was hidden under %s!",
336*41242Sbostic Xmonnam(mtmp), doname(obj));
337*41242Sbostic }
338*41242Sbostic }
339*41242Sbostic
340*41242Sbostic tmp = u.uac;
341*41242Sbostic /* give people with Ac = -10 at least some vulnerability */
342*41242Sbostic if(tmp < 0) {
343*41242Sbostic dam += tmp; /* decrease damage */
344*41242Sbostic if(dam <= 0) dam = 1;
345*41242Sbostic tmp = -rn2(-tmp);
346*41242Sbostic }
347*41242Sbostic tmp += mtmp->data->mlevel;
348*41242Sbostic if(multi < 0) tmp += 4;
349*41242Sbostic if((Invis && mtmp->data->mlet != 'I') || !mtmp->mcansee) tmp -= 2;
350*41242Sbostic if(mtmp->mtrapped) tmp -= 2;
351*41242Sbostic if(tmp <= rnd(20)) {
352*41242Sbostic if(Blind) pline("It misses.");
353*41242Sbostic else pline("%s misses.",Monnam(mtmp));
354*41242Sbostic res = 0;
355*41242Sbostic } else {
356*41242Sbostic if(Blind) pline("It hits!");
357*41242Sbostic else pline("%s hits!",Monnam(mtmp));
358*41242Sbostic losehp_m(dam, mtmp);
359*41242Sbostic res = 1;
360*41242Sbostic }
361*41242Sbostic stop_occupation();
362*41242Sbostic return(res);
363*41242Sbostic }
364