1 /* $NetBSD: hack.mhitu.c,v 1.6 2003/04/02 18:36:37 jsm Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.mhitu.c,v 1.6 2003/04/02 18:36:37 jsm Exp $");
73 * mhitu: monster hits you
74 * returns 1 if monster dies (e.g. 'y', 'F'), 0 otherwise
77 mhitu(struct monst
*mtmp
)
79 const struct permonst
*mdat
= mtmp
->data
;
84 /* If swallowed, can only be affected by hissers and by u.ustuck */
86 if (mtmp
!= u
.ustuck
) {
87 if (mdat
->mlet
== 'c' && !rn2(13)) {
88 pline("Outside, you hear %s's hissing!",
90 pline("%s gets turned to stone!",
92 pline("And the same fate befalls you.");
94 /* "notreached": not return(1); */
98 switch (mdat
->mlet
) { /* now mtmp == u.ustuck */
100 youswld(mtmp
, (u
.uac
> 0) ? u
.uac
+ 4 : 4,
104 youswld(mtmp
, rnd(6), 7, "The lurker above");
107 youswld(mtmp
, d(2, 4), 12, "The purple worm");
110 /* This is not impossible! */
111 pline("The mysterious monster totally digests you.");
118 if (mdat
->mlet
== 'c' && Stoned
)
121 /* make eels visible the moment they hit/miss us */
122 if (mdat
->mlet
== ';' && mtmp
->minvis
&& cansee(mtmp
->mx
, mtmp
->my
)) {
126 if (!strchr("1&DuxynNF", mdat
->mlet
))
127 tmp
= hitu(mtmp
, d(mdat
->damn
, mdat
->damd
));
130 if (strchr(UNDEAD
, mdat
->mlet
) && midnight())
131 tmp
+= hitu(mtmp
, d(mdat
->damn
, mdat
->damd
));
133 ctmp
= tmp
&& !mtmp
->mcan
&&
134 (!uarm
|| objects
[uarm
->otyp
].a_can
< rnd(3) || !rn2(50));
135 switch (mdat
->mlet
) {
138 return (1); /* he disappeared */
141 if (!mtmp
->cham
&& !mtmp
->mcan
&& !rn2(13)) {
142 (void) makemon(PM_DEMON
, u
.ux
, u
.uy
);
144 (void) hitu(mtmp
, d(2, 6));
145 (void) hitu(mtmp
, d(2, 6));
146 (void) hitu(mtmp
, rnd(3));
147 (void) hitu(mtmp
, rnd(3));
148 (void) hitu(mtmp
, rn1(4, 2));
153 justswld(mtmp
, "The trapper");
157 justswld(mtmp
, "The lurker above");
161 if (!u
.ustuck
&& !rn2(10)) {
162 pline("%s swings itself around you!",
165 } else if (u
.ustuck
== mtmp
&&
166 levl
[mtmp
->mx
][mtmp
->my
].typ
== POOL
) {
167 pline("%s drowns you ...", Monnam(mtmp
));
173 if (ctmp
&& rn2(2)) {
174 if (Poison_resistance
)
175 pline("The sting doesn't seem to affect you.");
177 pline("You feel weaker!");
183 (void) hitu(mtmp
, rnd(6));
187 pline("You hear %s's hissing!", monnam(mtmp
));
188 if (ctmp
|| !rn2(20) || (flags
.moonphase
== NEW_MOON
189 && !carrying(DEAD_LIZARD
))) {
191 /* pline("You get turned to stone!"); */
192 /* done_in_by(mtmp); */
197 if (rn2(6) || mtmp
->mcan
) {
198 (void) hitu(mtmp
, d(3, 10));
199 (void) hitu(mtmp
, rnd(8));
200 (void) hitu(mtmp
, rnd(8));
203 kludge("%s breathes fire!", "The dragon");
204 buzz(-1, mtmp
->mx
, mtmp
->my
, u
.ux
- mtmp
->mx
, u
.uy
- mtmp
->my
);
207 (void) hitu(mtmp
, d(2, (flags
.moonphase
== FULL_MOON
) ? 3 : 4));
210 (void) hitu(mtmp
, d(3, 6));
215 kludge("%s explodes!", "The freezing sphere");
217 pline("You don't seem affected by it.");
220 if (17 - (u
.ulevel
/ 2) > rnd(20)) {
221 pline("You get blasted!");
224 pline("You duck the blast...");
227 losehp_m(d(dn
, 6), mtmp
);
232 if (ctmp
&& multi
>= 0 && !rn2(3)) {
233 kludge("You are frozen by %ss juices", "the cube'");
238 if (ctmp
&& multi
>= 0 && !rn2(5)) {
240 kludge("You are put to sleep by %ss bite!",
245 tmp
= hitu(mtmp
, rnd(3));
246 tmp
&= hitu(mtmp
, rnd(3));
248 (void) hitu(mtmp
, rnd(4));
249 (void) hitu(mtmp
, rnd(4));
253 if ((hitu(mtmp
, rnd(4)) || !rn2(3)) && ctmp
) {
254 poisoned("bee's sting", mdat
->mname
);
262 if (mtmp
->mcan
&& !Blind
) {
263 pline("%s tries to seduce you, but you seem not interested.",
264 Amonnam(mtmp
, "plain"));
267 } else if (steal(mtmp
)) {
273 if (!uwep
&& !uarm
&& !uarmh
&& !uarms
&& !uarmg
) {
274 pline("%s hits! (I hope you don't mind)",
279 if (u
.uhp
> u
.uhpmax
)
285 (void) hitu(mtmp
, d(2, 6));
286 (void) hitu(mtmp
, d(2, 6));
290 tmp
= hitu(mtmp
, rnd(6));
291 if (hitu(mtmp
, rnd(6)) && tmp
&& /* hits with both paws */
292 !u
.ustuck
&& rn2(2)) {
294 kludge("%s has grabbed you!", "The owlbear");
296 } else if (u
.ustuck
== mtmp
) {
298 pline("You are being crushed.");
303 justswld(mtmp
, "The purple worm");
305 (void) hitu(mtmp
, d(2, 4));
308 (void) hitu(mtmp
, rnd(2));
309 (void) hitu(mtmp
, rnd(2));
312 if (tmp
&& uarmh
&& !uarmh
->rustfree
&&
313 (int) uarmh
->spe
>= -1) {
314 pline("Your helmet rusts!");
316 } else if (ctmp
&& uarm
&& !uarm
->rustfree
&& /* Mike Newton */
317 uarm
->otyp
< STUDDED_LEATHER_ARMOR
&&
318 (int) uarm
->spe
>= -1) {
319 pline("Your armor rusts!");
324 if (ctmp
&& !rn2(8)) {
325 poisoned("snake's bite", mdat
->mname
);
329 if (tmp
&& !rn2(8)) {
330 poisoned("scorpion's sting", mdat
->mname
);
332 (void) hitu(mtmp
, rnd(8));
333 (void) hitu(mtmp
, rnd(8));
336 (void) hitu(mtmp
, rnd(6));
337 (void) hitu(mtmp
, rnd(6));
347 (void) hitu(mtmp
, d(3, 4));
348 (void) hitu(mtmp
, d(3, 4));
351 if (ctmp
&& !u
.ustuck
)
371 (void) hitu(mtmp
, rnd(5));
372 (void) hitu(mtmp
, rnd(5));
373 (void) hitu(mtmp
, rnd(5));
377 long side
= rn2(2) ? RIGHT_SIDE
: LEFT_SIDE
;
378 pline("%s pricks in your %s leg!",
379 Monnam(mtmp
), (side
== RIGHT_SIDE
) ? "right" : "left");
380 set_wounded_legs(side
, rnd(50));
389 pline("You are blinded by a blast of light!");
395 (void) hitu(mtmp
, rnd(6));
404 hitu(struct monst
*mtmp
, int dam
)
412 if (mtmp
->mhide
&& mtmp
->mundetected
) {
413 mtmp
->mundetected
= 0;
416 if ((obj
= o_at(mtmp
->mx
, mtmp
->my
)) != NULL
)
417 pline("%s was hidden under %s!",
418 Xmonnam(mtmp
), doname(obj
));
422 /* give people with Ac = -10 at least some vulnerability */
424 dam
+= tmp
; /* decrease damage */
429 tmp
+= mtmp
->data
->mlevel
;
432 if ((Invis
&& mtmp
->data
->mlet
!= 'I') || !mtmp
->mcansee
)
436 if (tmp
<= rnd(20)) {
440 pline("%s misses.", Monnam(mtmp
));
446 pline("%s hits!", Monnam(mtmp
));