]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.fight.c
1 /* $NetBSD: hack.fight.c,v 1.5 2001/03/25 20:44:00 jsm Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.fight.c,v 1.5 2001/03/25 20:44:00 jsm Exp $");
15 static boolean far_noise
;
16 static long noisetime
;
18 /* hitmm returns 0 (miss), 1 (hit), or 2 (kill) */
21 struct monst
*magr
, *mdef
;
23 const struct permonst
*pa
= magr
->data
, *pd
= mdef
->data
;
27 if (strchr("Eauy", pa
->mlet
))
30 return (0); /* riv05!a3 */
31 tmp
= pd
->ac
+ pa
->mlevel
;
32 if (mdef
->mconf
|| mdef
->mfroz
|| mdef
->msleep
) {
37 hit
= (tmp
> rnd(20));
40 vis
= (cansee(magr
->mx
, magr
->my
) && cansee(mdef
->mx
, mdef
->my
));
47 (void) sprintf(buf
, "%s %s", Monnam(magr
),
48 hit
? "hits" : "misses");
49 pline("%s %s.", buf
, monnam(mdef
));
51 boolean far
= (dist(magr
->mx
, magr
->my
) > 15);
52 if (far
!= far_noise
|| moves
- noisetime
> 10) {
55 pline("You hear some noises%s.",
56 far
? " in the distance" : "");
60 if (magr
->data
->mlet
== 'c' && !magr
->cham
) {
63 pline("%s is turned to stone!", Monnam(mdef
));
65 pline("You have a peculiarly sad feeling for a moment, then it passes.");
68 } else if ((mdef
->mhp
-= d(pa
->damn
, pa
->damd
)) < 1) {
69 magr
->mhpmax
+= 1 + rn2(pd
->mlevel
+ 1);
70 if (magr
->mtame
&& magr
->mhpmax
> 8 * pa
->mlevel
) {
72 magr
->data
= pa
= &dog
;
74 magr
->data
= pa
= &la_dog
;
77 pline("%s is killed!", Monnam(mdef
));
79 pline("You have a sad feeling for a moment, then it passes.");
87 /* drop (perhaps) a cadaver and remove monster */
92 const struct permonst
*pd
= mdef
->data
;
93 if (letter(pd
->mlet
) && rn2(3)) {
94 (void) mkobj_at(pd
->mlet
, mdef
->mx
, mdef
->my
);
95 if (cansee(mdef
->mx
, mdef
->my
)) {
97 atl(mdef
->mx
, mdef
->my
, fobj
->olet
);
104 /* drop a rock and remove monster */
109 if (strchr(mlarge
, mdef
->data
->mlet
))
110 mksobj_at(ENORMOUS_ROCK
, mdef
->mx
, mdef
->my
);
112 mksobj_at(ROCK
, mdef
->mx
, mdef
->my
);
113 if (cansee(mdef
->mx
, mdef
->my
)) {
115 atl(mdef
->mx
, mdef
->my
, fobj
->olet
);
126 for (mon
= fmon
; mon
; mon
= mon
->nmon
)
128 if (DIST(mon
->mx
, mon
->my
, mtmp
->mx
, mtmp
->my
) < 3)
130 return (hitmm(mtmp
, mon
));
135 /* u is hit by sth, but not a monster */
137 thitu(tlev
, dam
, name
)
143 if (u
.uac
+ tlev
<= rnd(20)) {
147 pline("You are almost hit by %s!", buf
);
151 pline("You are hit!");
153 pline("You are hit by %s!", buf
);
159 char mlarge
[] = "bCDdegIlmnoPSsTUwY',&";
162 hmon(mon
, obj
, thrown
) /* return TRUE if mon still alive */
168 boolean hittxt
= FALSE
;
171 tmp
= rnd(2); /* attack with bare hands */
172 if (mon
->data
->mlet
== 'c' && !uarmg
) {
173 pline("You hit the cockatrice with your bare hands.");
174 pline("You turn to stone ...");
177 } else if (obj
->olet
== WEAPON_SYM
|| obj
->otyp
== PICK_AXE
) {
178 if (obj
== uwep
&& (obj
->otyp
> SPEAR
|| obj
->otyp
< BOOMERANG
))
181 if (strchr(mlarge
, mon
->data
->mlet
)) {
182 tmp
= rnd(objects
[obj
->otyp
].wldam
);
183 if (obj
->otyp
== TWO_HANDED_SWORD
)
185 else if (obj
->otyp
== FLAIL
)
188 tmp
= rnd(objects
[obj
->otyp
].wsdam
);
191 if (!thrown
&& obj
== uwep
&& obj
->otyp
== BOOMERANG
193 pline("As you hit %s, the boomerang breaks into splinters.",
196 setworn((struct obj
*) 0, obj
->owornmask
);
197 obfree(obj
, (struct obj
*) 0);
201 if (mon
->data
->mlet
== 'O' && obj
->otyp
== TWO_HANDED_SWORD
&&
202 !strcmp(ONAME(obj
), "Orcrist"))
206 case HEAVY_IRON_BALL
:
209 case EXPENSIVE_CAMERA
:
210 pline("You succeed in destroying your camera. Congratulations!");
213 setworn((struct obj
*) 0, obj
->owornmask
);
214 obfree(obj
, (struct obj
*) 0);
216 case DEAD_COCKATRICE
:
217 pline("You hit %s with the cockatrice corpse.",
219 if (mon
->data
->mlet
== 'c') {
224 pline("%s is turned to stone!", Monnam(mon
));
227 case CLOVE_OF_GARLIC
: /* no effect against demons */
228 if (strchr(UNDEAD
, mon
->data
->mlet
))
233 /* non-weapons can damage because of their weight */
234 /* (but not too much) */
244 /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) */
246 tmp
+= u
.udaminc
+ dbon();
248 if ((tmp
-= u
.uswldtim
) <= 0) {
249 pline("Your arms are no longer able to hit.");
260 if (mon
->mtame
&& (!mon
->mflee
|| mon
->mfleetim
)) {
261 mon
->mflee
= 1; /* Rick Richardson */
262 mon
->mfleetim
+= 10 * rnd(tmp
);
266 /* this assumes that we cannot throw plural things */
267 hit(xname(obj
) /* or: objects[obj->otyp].oc_name */ ,
270 pline("You hit it.");
272 pline("You hit %s%s", monnam(mon
), exclam(tmp
));
274 if (u
.umconf
&& !thrown
) {
276 pline("Your hands stop glowing blue.");
277 if (!mon
->mfroz
&& !mon
->msleep
)
278 pline("%s appears confused.", Monnam(mon
));
283 return (TRUE
); /* mon still alive */
286 /* try to attack; return FALSE if monster evaded */
287 /* u.dx and u.dy must be set */
293 boolean malive
= TRUE
;
294 const struct permonst
*mdat
;
297 u_wipe_engr(3); /* andrew@orca: prevent unlimited pick-axe
300 if (mdat
->mlet
== 'L' && !mtmp
->mfroz
&& !mtmp
->msleep
&&
301 !mtmp
->mconf
&& mtmp
->mcansee
&& !rn2(7) &&
302 (m_move(mtmp
, 0) == 2 /* he died */ || /* he moved: */
303 mtmp
->mx
!= u
.ux
+ u
.dx
|| mtmp
->my
!= u
.uy
+ u
.dy
))
307 if (!u
.ustuck
&& !mtmp
->mflee
)
309 switch (levl
[u
.ux
+ u
.dx
][u
.uy
+ u
.dy
].scrsym
) {
311 pline("The door actually was a Mimic.");
314 pline("The chest was a Mimic!");
317 pline("Wait! That's a Mimic!");
319 wakeup(mtmp
); /* clears mtmp->mimic */
324 if (mtmp
->mhide
&& mtmp
->mundetected
) {
327 mtmp
->mundetected
= 0;
328 if ((obj
= o_at(mtmp
->mx
, mtmp
->my
)) && !Blind
)
329 pline("Wait! There's a %s hiding under %s!",
330 mdat
->mname
, doname(obj
));
333 tmp
= u
.uluck
+ u
.ulevel
+ mdat
->ac
+ abon();
335 if (uwep
->olet
== WEAPON_SYM
|| uwep
->otyp
== PICK_AXE
)
337 if (uwep
->otyp
== TWO_HANDED_SWORD
)
339 else if (uwep
->otyp
== DAGGER
)
341 else if (uwep
->otyp
== CRYSKNIFE
)
343 else if (uwep
->otyp
== SPEAR
&&
344 strchr("XDne", mdat
->mlet
))
361 /* with a lot of luggage, your agility diminishes */
362 tmp
-= (inv_weight() + 40) / 20;
364 if (tmp
<= rnd(20) && !u
.uswallow
) {
366 pline("You miss it.");
368 pline("You miss %s.", monnam(mtmp
));
370 /* we hit the monster; be careful: it might die! */
372 if ((malive
= hmon(mtmp
, uwep
, 0)) == TRUE
) {
373 /* monster still alive */
374 if (!rn2(25) && mtmp
->mhp
< mtmp
->mhpmax
/ 2) {
377 mtmp
->mfleetim
= rnd(100);
378 if (u
.ustuck
== mtmp
&& !u
.uswallow
)
383 cutworm(mtmp
, u
.ux
+ u
.dx
, u
.uy
+ u
.dy
,
384 uwep
? uwep
->otyp
: 0);
387 if (mdat
->mlet
== 'a') {
389 pline("You are splashed by the blob's acid!");
390 losehp_m(rnd(6), mtmp
);
398 if (malive
&& mdat
->mlet
== 'E' && canseemon(mtmp
)
399 && !mtmp
->mcan
&& rn2(3)) {
401 pline("You are frozen by the floating eye's gaze!");
402 nomul((u
.ulevel
> 6 || rn2(4)) ? rn1(20, -21) : -200);
404 pline("The blinded floating eye cannot defend itself.");
406 if ((int) u
.uluck
> LUCKMIN
)