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