]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.fight.c
1 /* $NetBSD: hack.fight.c,v 1.9 2009/06/07 18:30:39 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.9 2009/06/07 18:30:39 dholland Exp $");
72 static boolean far_noise
;
73 static long noisetime
;
75 /* hitmm returns 0 (miss), 1 (hit), or 2 (kill) */
77 hitmm(struct monst
*magr
, struct monst
*mdef
)
79 const struct permonst
*pa
= magr
->data
, *pd
= mdef
->data
;
84 if (strchr("Eauy", pa
->mlet
))
87 return (0); /* riv05!a3 */
88 tmp
= pd
->ac
+ pa
->mlevel
;
89 if (mdef
->mconf
|| mdef
->mfroz
|| mdef
->msleep
) {
94 didhit
= (tmp
> rnd(20));
97 vis
= (cansee(magr
->mx
, magr
->my
) && cansee(mdef
->mx
, mdef
->my
));
104 (void) sprintf(buf
, "%s %s", Monnam(magr
),
105 didhit
? "hits" : "misses");
106 pline("%s %s.", buf
, monnam(mdef
));
108 boolean far
= (dist(magr
->mx
, magr
->my
) > 15);
109 if (far
!= far_noise
|| moves
- noisetime
> 10) {
112 pline("You hear some noises%s.",
113 far
? " in the distance" : "");
117 if (magr
->data
->mlet
== 'c' && !magr
->cham
) {
120 pline("%s is turned to stone!", Monnam(mdef
));
121 else if (mdef
->mtame
)
122 pline("You have a peculiarly sad feeling for a moment, then it passes.");
125 } else if ((mdef
->mhp
-= d(pa
->damn
, pa
->damd
)) < 1) {
126 magr
->mhpmax
+= 1 + rn2(pd
->mlevel
+ 1);
127 if (magr
->mtame
&& magr
->mhpmax
> 8 * pa
->mlevel
) {
129 magr
->data
= pa
= &dog
;
131 magr
->data
= pa
= &la_dog
;
134 pline("%s is killed!", Monnam(mdef
));
135 else if (mdef
->mtame
)
136 pline("You have a sad feeling for a moment, then it passes.");
144 /* drop (perhaps) a cadaver and remove monster */
146 mondied(struct monst
*mdef
)
148 const struct permonst
*pd
= mdef
->data
;
149 if (letter(pd
->mlet
) && rn2(3)) {
150 (void) mkobj_at(pd
->mlet
, mdef
->mx
, mdef
->my
);
151 if (cansee(mdef
->mx
, mdef
->my
)) {
153 atl(mdef
->mx
, mdef
->my
, fobj
->olet
);
160 /* drop a rock and remove monster */
162 monstone(struct monst
*mdef
)
164 if (strchr(mlarge
, mdef
->data
->mlet
))
165 mksobj_at(ENORMOUS_ROCK
, mdef
->mx
, mdef
->my
);
167 mksobj_at(ROCK
, mdef
->mx
, mdef
->my
);
168 if (cansee(mdef
->mx
, mdef
->my
)) {
170 atl(mdef
->mx
, mdef
->my
, fobj
->olet
);
177 fightm(struct monst
*mtmp
)
180 for (mon
= fmon
; mon
; mon
= mon
->nmon
)
182 if (DIST(mon
->mx
, mon
->my
, mtmp
->mx
, mtmp
->my
) < 3)
184 return (hitmm(mtmp
, mon
));
189 /* u is hit by sth, but not a monster */
191 thitu(int tlev
, int dam
, const char *name
)
195 if (u
.uac
+ tlev
<= rnd(20)) {
199 pline("You are almost hit by %s!", buf
);
203 pline("You are hit!");
205 pline("You are hit by %s!", buf
);
211 char mlarge
[] = "bCDdegIlmnoPSsTUwY',&";
213 /* return TRUE if mon still alive */
215 hmon(struct monst
*mon
, struct obj
*obj
, int thrown
)
218 boolean hittxt
= FALSE
;
221 tmp
= rnd(2); /* attack with bare hands */
222 if (mon
->data
->mlet
== 'c' && !uarmg
) {
223 pline("You hit the cockatrice with your bare hands.");
224 pline("You turn to stone ...");
227 } else if (obj
->olet
== WEAPON_SYM
|| obj
->otyp
== PICK_AXE
) {
228 if (obj
== uwep
&& (obj
->otyp
> SPEAR
|| obj
->otyp
< BOOMERANG
))
231 if (strchr(mlarge
, mon
->data
->mlet
)) {
232 tmp
= rnd(objects
[obj
->otyp
].wldam
);
233 if (obj
->otyp
== TWO_HANDED_SWORD
)
235 else if (obj
->otyp
== FLAIL
)
238 tmp
= rnd(objects
[obj
->otyp
].wsdam
);
241 if (!thrown
&& obj
== uwep
&& obj
->otyp
== BOOMERANG
243 pline("As you hit %s, the boomerang breaks into splinters.",
246 setworn((struct obj
*) 0, obj
->owornmask
);
247 obfree(obj
, (struct obj
*) 0);
252 if (mon
->data
->mlet
== 'O' && obj
!= NULL
&&
253 obj
->otyp
== TWO_HANDED_SWORD
&&
254 !strcmp(ONAME(obj
), "Orcrist"))
258 case HEAVY_IRON_BALL
:
261 case EXPENSIVE_CAMERA
:
262 pline("You succeed in destroying your camera. Congratulations!");
265 setworn((struct obj
*) 0, obj
->owornmask
);
266 obfree(obj
, (struct obj
*) 0);
268 case DEAD_COCKATRICE
:
269 pline("You hit %s with the cockatrice corpse.",
271 if (mon
->data
->mlet
== 'c') {
276 pline("%s is turned to stone!", Monnam(mon
));
279 case CLOVE_OF_GARLIC
: /* no effect against demons */
280 if (strchr(UNDEAD
, mon
->data
->mlet
))
285 /* non-weapons can damage because of their weight */
286 /* (but not too much) */
296 /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) */
298 tmp
+= u
.udaminc
+ dbon();
300 if ((tmp
-= u
.uswldtim
) <= 0) {
301 pline("Your arms are no longer able to hit.");
312 if (mon
->mtame
&& (!mon
->mflee
|| mon
->mfleetim
)) {
313 mon
->mflee
= 1; /* Rick Richardson */
314 mon
->mfleetim
+= 10 * rnd(tmp
);
318 /* this assumes that we cannot throw plural things */
320 panic("thrown non-object");
321 hit(xname(obj
) /* or: objects[obj->otyp].oc_name */ ,
324 pline("You hit it.");
326 pline("You hit %s%s", monnam(mon
), exclam(tmp
));
328 if (u
.umconf
&& !thrown
) {
330 pline("Your hands stop glowing blue.");
331 if (!mon
->mfroz
&& !mon
->msleep
)
332 pline("%s appears confused.", Monnam(mon
));
337 return (TRUE
); /* mon still alive */
340 /* try to attack; return FALSE if monster evaded */
341 /* u.dx and u.dy must be set */
343 attack(struct monst
*mtmp
)
346 boolean malive
= TRUE
;
347 const struct permonst
*mdat
;
350 u_wipe_engr(3); /* andrew@orca: prevent unlimited pick-axe
353 if (mdat
->mlet
== 'L' && !mtmp
->mfroz
&& !mtmp
->msleep
&&
354 !mtmp
->mconf
&& mtmp
->mcansee
&& !rn2(7) &&
355 (m_move(mtmp
, 0) == 2 /* he died */ || /* he moved: */
356 mtmp
->mx
!= u
.ux
+ u
.dx
|| mtmp
->my
!= u
.uy
+ u
.dy
))
360 if (!u
.ustuck
&& !mtmp
->mflee
)
362 switch (levl
[u
.ux
+ u
.dx
][u
.uy
+ u
.dy
].scrsym
) {
364 pline("The door actually was a Mimic.");
367 pline("The chest was a Mimic!");
370 pline("Wait! That's a Mimic!");
372 wakeup(mtmp
); /* clears mtmp->mimic */
377 if (mtmp
->mhide
&& mtmp
->mundetected
) {
380 mtmp
->mundetected
= 0;
381 if ((obj
= o_at(mtmp
->mx
, mtmp
->my
)) && !Blind
)
382 pline("Wait! There's a %s hiding under %s!",
383 mdat
->mname
, doname(obj
));
386 tmp
= u
.uluck
+ u
.ulevel
+ mdat
->ac
+ abon();
388 if (uwep
->olet
== WEAPON_SYM
|| uwep
->otyp
== PICK_AXE
)
390 if (uwep
->otyp
== TWO_HANDED_SWORD
)
392 else if (uwep
->otyp
== DAGGER
)
394 else if (uwep
->otyp
== CRYSKNIFE
)
396 else if (uwep
->otyp
== SPEAR
&&
397 strchr("XDne", mdat
->mlet
))
414 /* with a lot of luggage, your agility diminishes */
415 tmp
-= (inv_weight() + 40) / 20;
417 if (tmp
<= rnd(20) && !u
.uswallow
) {
419 pline("You miss it.");
421 pline("You miss %s.", monnam(mtmp
));
423 /* we hit the monster; be careful: it might die! */
425 if ((malive
= hmon(mtmp
, uwep
, 0)) == TRUE
) {
426 /* monster still alive */
427 if (!rn2(25) && mtmp
->mhp
< mtmp
->mhpmax
/ 2) {
430 mtmp
->mfleetim
= rnd(100);
431 if (u
.ustuck
== mtmp
&& !u
.uswallow
)
436 cutworm(mtmp
, u
.ux
+ u
.dx
, u
.uy
+ u
.dy
,
437 uwep
? uwep
->otyp
: 0);
440 if (mdat
->mlet
== 'a') {
442 pline("You are splashed by the blob's acid!");
443 losehp_m(rnd(6), mtmp
);
451 if (malive
&& mdat
->mlet
== 'E' && canseemon(mtmp
)
452 && !mtmp
->mcan
&& rn2(3)) {
454 pline("You are frozen by the floating eye's gaze!");
455 nomul((u
.ulevel
> 6 || rn2(4)) ? rn1(20, -21) : -200);
457 pline("The blinded floating eye cannot defend itself.");
459 if ((int) u
.uluck
> LUCKMIN
)