1 /* $NetBSD: hack.fight.c,v 1.11 2009/06/07 20:31:10 dholland 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.fight.c,v 1.11 2009/06/07 20:31:10 dholland Exp $");
72 static boolean far_noise
;
73 static long noisetime
;
75 static void monstone(struct monst
*);
77 /* hitmm returns 0 (miss), 1 (hit), or 2 (kill) */
79 hitmm(struct monst
*magr
, struct monst
*mdef
)
81 const struct permonst
*pa
= magr
->data
, *pd
= mdef
->data
;
86 if (strchr("Eauy", pa
->mlet
))
89 return (0); /* riv05!a3 */
90 tmp
= pd
->ac
+ pa
->mlevel
;
91 if (mdef
->mconf
|| mdef
->mfroz
|| mdef
->msleep
) {
96 didhit
= (tmp
> rnd(20));
99 vis
= (cansee(magr
->mx
, magr
->my
) && cansee(mdef
->mx
, mdef
->my
));
106 (void) snprintf(buf
, sizeof(buf
), "%s %s", Monnam(magr
),
107 didhit
? "hits" : "misses");
108 pline("%s %s.", buf
, monnam(mdef
));
110 boolean far
= (dist(magr
->mx
, magr
->my
) > 15);
111 if (far
!= far_noise
|| moves
- noisetime
> 10) {
114 pline("You hear some noises%s.",
115 far
? " in the distance" : "");
119 if (magr
->data
->mlet
== 'c' && !magr
->cham
) {
122 pline("%s is turned to stone!", Monnam(mdef
));
123 else if (mdef
->mtame
)
124 pline("You have a peculiarly sad feeling for a moment, then it passes.");
127 } else if ((mdef
->mhp
-= d(pa
->damn
, pa
->damd
)) < 1) {
128 magr
->mhpmax
+= 1 + rn2(pd
->mlevel
+ 1);
129 if (magr
->mtame
&& magr
->mhpmax
> 8 * pa
->mlevel
) {
131 magr
->data
= pa
= &dog
;
133 magr
->data
= pa
= &la_dog
;
136 pline("%s is killed!", Monnam(mdef
));
137 else if (mdef
->mtame
)
138 pline("You have a sad feeling for a moment, then it passes.");
146 /* drop (perhaps) a cadaver and remove monster */
148 mondied(struct monst
*mdef
)
150 const struct permonst
*pd
= mdef
->data
;
151 if (letter(pd
->mlet
) && rn2(3)) {
152 (void) mkobj_at(pd
->mlet
, mdef
->mx
, mdef
->my
);
153 if (cansee(mdef
->mx
, mdef
->my
)) {
155 atl(mdef
->mx
, mdef
->my
, fobj
->olet
);
162 /* drop a rock and remove monster */
164 monstone(struct monst
*mdef
)
166 if (strchr(mlarge
, mdef
->data
->mlet
))
167 mksobj_at(ENORMOUS_ROCK
, mdef
->mx
, mdef
->my
);
169 mksobj_at(ROCK
, mdef
->mx
, mdef
->my
);
170 if (cansee(mdef
->mx
, mdef
->my
)) {
172 atl(mdef
->mx
, mdef
->my
, fobj
->olet
);
179 fightm(struct monst
*mtmp
)
182 for (mon
= fmon
; mon
; mon
= mon
->nmon
)
184 if (DIST(mon
->mx
, mon
->my
, mtmp
->mx
, mtmp
->my
) < 3)
186 return (hitmm(mtmp
, mon
));
191 /* u is hit by sth, but not a monster */
193 thitu(int tlev
, int dam
, const char *name
)
197 setan(name
, buf
, sizeof(buf
));
198 if (u
.uac
+ tlev
<= rnd(20)) {
202 pline("You are almost hit by %s!", buf
);
206 pline("You are hit!");
208 pline("You are hit by %s!", buf
);
214 const char mlarge
[] = "bCDdegIlmnoPSsTUwY',&";
216 /* return TRUE if mon still alive */
218 hmon(struct monst
*mon
, struct obj
*obj
, int thrown
)
221 boolean hittxt
= FALSE
;
224 tmp
= rnd(2); /* attack with bare hands */
225 if (mon
->data
->mlet
== 'c' && !uarmg
) {
226 pline("You hit the cockatrice with your bare hands.");
227 pline("You turn to stone ...");
230 } else if (obj
->olet
== WEAPON_SYM
|| obj
->otyp
== PICK_AXE
) {
231 if (obj
== uwep
&& (obj
->otyp
> SPEAR
|| obj
->otyp
< BOOMERANG
))
234 if (strchr(mlarge
, mon
->data
->mlet
)) {
235 tmp
= rnd(objects
[obj
->otyp
].wldam
);
236 if (obj
->otyp
== TWO_HANDED_SWORD
)
238 else if (obj
->otyp
== FLAIL
)
241 tmp
= rnd(objects
[obj
->otyp
].wsdam
);
244 if (!thrown
&& obj
== uwep
&& obj
->otyp
== BOOMERANG
246 pline("As you hit %s, the boomerang breaks into splinters.",
249 setworn((struct obj
*) 0, obj
->owornmask
);
250 obfree(obj
, (struct obj
*) 0);
255 if (mon
->data
->mlet
== 'O' && obj
!= NULL
&&
256 obj
->otyp
== TWO_HANDED_SWORD
&&
257 !strcmp(ONAME(obj
), "Orcrist"))
261 case HEAVY_IRON_BALL
:
264 case EXPENSIVE_CAMERA
:
265 pline("You succeed in destroying your camera. Congratulations!");
268 setworn((struct obj
*) 0, obj
->owornmask
);
269 obfree(obj
, (struct obj
*) 0);
271 case DEAD_COCKATRICE
:
272 pline("You hit %s with the cockatrice corpse.",
274 if (mon
->data
->mlet
== 'c') {
279 pline("%s is turned to stone!", Monnam(mon
));
282 case CLOVE_OF_GARLIC
: /* no effect against demons */
283 if (strchr(UNDEAD
, mon
->data
->mlet
))
288 /* non-weapons can damage because of their weight */
289 /* (but not too much) */
299 /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) */
301 tmp
+= u
.udaminc
+ dbon();
303 if ((tmp
-= u
.uswldtim
) <= 0) {
304 pline("Your arms are no longer able to hit.");
315 if (mon
->mtame
&& (!mon
->mflee
|| mon
->mfleetim
)) {
316 mon
->mflee
= 1; /* Rick Richardson */
317 mon
->mfleetim
+= 10 * rnd(tmp
);
321 /* this assumes that we cannot throw plural things */
323 panic("thrown non-object");
324 hit(xname(obj
) /* or: objects[obj->otyp].oc_name */ ,
327 pline("You hit it.");
329 pline("You hit %s%s", monnam(mon
), exclam(tmp
));
331 if (u
.umconf
&& !thrown
) {
333 pline("Your hands stop glowing blue.");
334 if (!mon
->mfroz
&& !mon
->msleep
)
335 pline("%s appears confused.", Monnam(mon
));
340 return (TRUE
); /* mon still alive */
343 /* try to attack; return FALSE if monster evaded */
344 /* u.dx and u.dy must be set */
346 attack(struct monst
*mtmp
)
349 boolean malive
= TRUE
;
350 const struct permonst
*mdat
;
353 u_wipe_engr(3); /* andrew@orca: prevent unlimited pick-axe
356 if (mdat
->mlet
== 'L' && !mtmp
->mfroz
&& !mtmp
->msleep
&&
357 !mtmp
->mconf
&& mtmp
->mcansee
&& !rn2(7) &&
358 (m_move(mtmp
, 0) == 2 /* he died */ || /* he moved: */
359 mtmp
->mx
!= u
.ux
+ u
.dx
|| mtmp
->my
!= u
.uy
+ u
.dy
))
363 if (!u
.ustuck
&& !mtmp
->mflee
)
365 switch (levl
[u
.ux
+ u
.dx
][u
.uy
+ u
.dy
].scrsym
) {
367 pline("The door actually was a Mimic.");
370 pline("The chest was a Mimic!");
373 pline("Wait! That's a Mimic!");
375 wakeup(mtmp
); /* clears mtmp->mimic */
380 if (mtmp
->mhide
&& mtmp
->mundetected
) {
383 mtmp
->mundetected
= 0;
384 if ((obj
= o_at(mtmp
->mx
, mtmp
->my
)) && !Blind
)
385 pline("Wait! There's a %s hiding under %s!",
386 mdat
->mname
, doname(obj
));
389 tmp
= u
.uluck
+ u
.ulevel
+ mdat
->ac
+ abon();
391 if (uwep
->olet
== WEAPON_SYM
|| uwep
->otyp
== PICK_AXE
)
393 if (uwep
->otyp
== TWO_HANDED_SWORD
)
395 else if (uwep
->otyp
== DAGGER
)
397 else if (uwep
->otyp
== CRYSKNIFE
)
399 else if (uwep
->otyp
== SPEAR
&&
400 strchr("XDne", mdat
->mlet
))
417 /* with a lot of luggage, your agility diminishes */
418 tmp
-= (inv_weight() + 40) / 20;
420 if (tmp
<= rnd(20) && !u
.uswallow
) {
422 pline("You miss it.");
424 pline("You miss %s.", monnam(mtmp
));
426 /* we hit the monster; be careful: it might die! */
428 if ((malive
= hmon(mtmp
, uwep
, 0)) == TRUE
) {
429 /* monster still alive */
430 if (!rn2(25) && mtmp
->mhp
< mtmp
->mhpmax
/ 2) {
433 mtmp
->mfleetim
= rnd(100);
434 if (u
.ustuck
== mtmp
&& !u
.uswallow
)
439 cutworm(mtmp
, u
.ux
+ u
.dx
, u
.uy
+ u
.dy
,
440 uwep
? uwep
->otyp
: 0);
443 if (mdat
->mlet
== 'a') {
445 pline("You are splashed by the blob's acid!");
446 losehp_m(rnd(6), mtmp
);
454 if (malive
&& mdat
->mlet
== 'E' && canseemon(mtmp
)
455 && !mtmp
->mcan
&& rn2(3)) {
457 pline("You are frozen by the floating eye's gaze!");
458 nomul((u
.ulevel
> 6 || rn2(4)) ? rn1(20, -21) : -200);
460 pline("The blinded floating eye cannot defend itself.");
462 if ((int) u
.uluck
> LUCKMIN
)