1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.fight.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.fight.c,v 1.5 1999/11/16 10:26:36 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.fight.c,v 1.5 2006/08/21 19:45:32 pavalos Exp $ */
7 extern struct permonst li_dog
, dog
, la_dog
;
9 static boolean far_noise
;
10 static long noisetime
;
12 static void monstone(struct monst
*);
14 /* hitmm returns 0 (miss), 1 (hit), or 2 (kill) */
16 hitmm(struct monst
*magr
, struct monst
*mdef
)
18 struct permonst
*pa
= magr
->data
, *pd
= mdef
->data
;
23 if (strchr("Eauy", pa
->mlet
))
25 if (magr
->mfroz
) /* riv05!a3 */
27 tmp
= pd
->ac
+ pa
->mlevel
;
28 if (mdef
->mconf
|| mdef
->mfroz
|| mdef
->msleep
) {
36 vis
= (cansee(magr
->mx
, magr
->my
) && cansee(mdef
->mx
, mdef
->my
));
43 sprintf(buf
, "%s %s", Monnam(magr
),
44 ht
? "hits" : "misses");
45 pline("%s %s.", buf
, monnam(mdef
));
47 boolean far
= (dist(magr
->mx
, magr
->my
) > 15);
48 if (far
!= far_noise
|| moves
- noisetime
> 10) {
51 pline("You hear some noises%s.",
52 far
? " in the distance" : "");
56 if (magr
->data
->mlet
== 'c' && !magr
->cham
) {
59 pline("%s is turned to stone!", Monnam(mdef
));
61 pline("You have a peculiarly sad feeling for a moment, then it passes.");
64 } else if ((mdef
->mhp
-= d(pa
->damn
, pa
->damd
)) < 1) {
65 magr
->mhpmax
+= 1 + rn2(pd
->mlevel
+ 1);
66 if (magr
->mtame
&& magr
->mhpmax
> 8 * pa
->mlevel
) {
68 magr
->data
= pa
= &dog
;
70 magr
->data
= pa
= &la_dog
;
73 pline("%s is killed!", Monnam(mdef
));
75 pline("You have a sad feeling for a moment, then it passes.");
83 /* drop (perhaps) a cadaver and remove monster */
85 mondied(struct monst
*mdef
)
87 struct permonst
*pd
= mdef
->data
;
89 if (letter(pd
->mlet
) && rn2(3)) {
90 mkobj_at(pd
->mlet
, mdef
->mx
, mdef
->my
);
91 if (cansee(mdef
->mx
, mdef
->my
)) {
93 atl(mdef
->mx
, mdef
->my
, fobj
->olet
);
100 /* drop a rock and remove monster */
102 monstone(struct monst
*mdef
)
104 if (strchr(mlarge
, mdef
->data
->mlet
))
105 mksobj_at(ENORMOUS_ROCK
, mdef
->mx
, mdef
->my
);
107 mksobj_at(ROCK
, mdef
->mx
, mdef
->my
);
108 if (cansee(mdef
->mx
, mdef
->my
)) {
110 atl(mdef
->mx
, mdef
->my
, fobj
->olet
);
116 fightm(struct monst
*mtmp
)
120 for (mon
= fmon
; mon
; mon
= mon
->nmon
)
122 if (DIST(mon
->mx
, mon
->my
, mtmp
->mx
, mtmp
->my
) < 3)
124 return (hitmm(mtmp
, mon
));
130 /* u is hit by sth, but not a monster */
132 thitu(int tlev
, int dam
, const char *name
)
137 if (u
.uac
+ tlev
<= rnd(20)) {
141 pline("You are almost hit by %s!", buf
);
145 pline("You are hit!");
147 pline("You are hit by %s!", buf
);
153 char mlarge
[] = "bCDdegIlmnoPSsTUwY',&";
155 /* return TRUE if mon still alive */
157 hmon(struct monst
*mon
, struct obj
*obj
, int thrown
)
163 tmp
= rnd(2); /* attack with bare hands */
164 if (mon
->data
->mlet
== 'c' && !uarmg
) {
165 pline("You hit the cockatrice with your bare hands.");
166 pline("You turn to stone ...");
169 } else if (obj
->olet
== WEAPON_SYM
|| obj
->otyp
== PICK_AXE
) {
170 if (obj
== uwep
&& (obj
->otyp
> SPEAR
|| obj
->otyp
< BOOMERANG
))
173 if (strchr(mlarge
, mon
->data
->mlet
)) {
174 tmp
= rnd(objects
[obj
->otyp
].wldam
);
175 if (obj
->otyp
== TWO_HANDED_SWORD
)
177 else if (obj
->otyp
== FLAIL
)
180 tmp
= rnd(objects
[obj
->otyp
].wsdam
);
182 if (!thrown
&& obj
== uwep
&& obj
->otyp
== BOOMERANG
184 pline("As you hit %s, the boomerang breaks into splinters.",
187 setworn(NULL
, obj
->owornmask
);
192 if (mon
->data
->mlet
== 'O' && obj
->otyp
== TWO_HANDED_SWORD
&&
193 !strcmp(ONAME(obj
), "Orcrist"))
197 case HEAVY_IRON_BALL
:
200 case EXPENSIVE_CAMERA
:
201 pline("You succeed in destroying your camera. Congratulations!");
204 setworn(NULL
, obj
->owornmask
);
207 case DEAD_COCKATRICE
:
208 pline("You hit %s with the cockatrice corpse.",
210 if (mon
->data
->mlet
== 'c') {
215 pline("%s is turned to stone!", Monnam(mon
));
218 case CLOVE_OF_GARLIC
: /* no effect against demons */
219 if (strchr(UNDEAD
, mon
->data
->mlet
))
224 /* non-weapons can damage because of their weight */
225 /* (but not too much) */
235 /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) */
237 tmp
+= u
.udaminc
+ dbon();
239 if ((tmp
-= u
.uswldtim
) <= 0) {
240 pline("Your arms are no longer able to hit.");
251 if (mon
->mtame
&& (!mon
->mflee
|| mon
->mfleetim
)) {
252 mon
->mflee
= 1; /* Rick Richardson */
253 mon
->mfleetim
+= 10 * rnd(tmp
);
258 /* this assumes that we cannot throw plural things */
259 hit(xname(obj
) /* or: objects[obj->otyp].oc_name */,
262 pline("You hit it.");
264 pline("You hit %s%s", monnam(mon
), exclam(tmp
));
267 if (u
.umconf
&& !thrown
) {
269 pline("Your hands stop glowing blue.");
270 if (!mon
->mfroz
&& !mon
->msleep
)
271 pline("%s appears confused.", Monnam(mon
));
276 return (TRUE
); /* mon still alive */
279 /* try to attack; return FALSE if monster evaded */
280 /* u.dx and u.dy must be set */
282 attack(struct monst
*mtmp
)
285 boolean malive
= TRUE
;
286 struct permonst
*mdat
;
289 u_wipe_engr(3); /* andrew@orca: prevent unlimited pick-axe attacks */
291 if (mdat
->mlet
== 'L' && !mtmp
->mfroz
&& !mtmp
->msleep
&&
292 !mtmp
->mconf
&& mtmp
->mcansee
&& !rn2(7) &&
293 (m_move(mtmp
, 0) == 2 /* he died */ || /* he moved: */
294 mtmp
->mx
!= u
.ux
+ u
.dx
|| mtmp
->my
!= u
.uy
+ u
.dy
))
298 if (!u
.ustuck
&& !mtmp
->mflee
)
300 switch (levl
[u
.ux
+ u
.dx
][u
.uy
+ u
.dy
].scrsym
) {
302 pline("The door actually was a Mimic.");
305 pline("The chest was a Mimic!");
308 pline("Wait! That's a Mimic!");
310 wakeup(mtmp
); /* clears mtmp->mimic */
316 if (mtmp
->mhide
&& mtmp
->mundetected
) {
319 mtmp
->mundetected
= 0;
320 if ((obj
= o_at(mtmp
->mx
, mtmp
->my
)) && !Blind
)
321 pline("Wait! There's a %s hiding under %s!",
322 mdat
->mname
, doname(obj
));
326 tmp
= u
.uluck
+ u
.ulevel
+ mdat
->ac
+ abon();
328 if (uwep
->olet
== WEAPON_SYM
|| uwep
->otyp
== PICK_AXE
)
330 if (uwep
->otyp
== TWO_HANDED_SWORD
)
332 else if (uwep
->otyp
== DAGGER
)
334 else if (uwep
->otyp
== CRYSKNIFE
)
336 else if (uwep
->otyp
== SPEAR
&&
337 strchr("XDne", mdat
->mlet
))
354 /* with a lot of luggage, your agility diminishes */
355 tmp
-= (inv_weight() + 40) / 20;
357 if (tmp
<= rnd(20) && !u
.uswallow
) {
359 pline("You miss it.");
361 pline("You miss %s.", monnam(mtmp
));
363 /* we hit the monster; be careful: it might die! */
365 if ((malive
= hmon(mtmp
, uwep
, 0)) == TRUE
) {
366 /* monster still alive */
367 if (!rn2(25) && mtmp
->mhp
< mtmp
->mhpmax
/ 2) {
370 mtmp
->mfleetim
= rnd(100);
371 if (u
.ustuck
== mtmp
&& !u
.uswallow
)
376 cutworm(mtmp
, u
.ux
+ u
.dx
, u
.uy
+ u
.dy
,
377 uwep
? uwep
->otyp
: 0);
380 if (mdat
->mlet
== 'a') {
382 pline("You are splashed by the blob's acid!");
383 losehp_m(rnd(6), mtmp
);
391 if (malive
&& mdat
->mlet
== 'E' && canseemon(mtmp
)
392 && !mtmp
->mcan
&& rn2(3)) {
394 pline("You are frozen by the floating eye's gaze!");
395 nomul((u
.ulevel
> 6 || rn2(4)) ? rn1(20, -21) : -200);
397 pline("The blinded floating eye cannot defend itself.");
399 if ((int)u
.uluck
> LUCKMIN
)