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 $ */
6 extern struct permonst li_dog, dog, la_dog;
7 extern char *exclam(), *xname();
8 extern struct obj *mkobj_at();
10 static boolean far_noise;
11 static long noisetime;
13 /* hitmm returns 0 (miss), 1 (hit), or 2 (kill) */
14 hitmm(magr,mdef) struct monst *magr,*mdef; {
15 struct permonst *pa = magr->data, *pd = mdef->data;
19 if(index("Eauy", pa->mlet)) return(0);
20 if(magr->mfroz) return(0); /* riv05!a3 */
21 tmp = pd->ac + pa->mlevel;
22 if(mdef->mconf || mdef->mfroz || mdef->msleep){
24 if(mdef->msleep) mdef->msleep = 0;
26 hit = (tmp > rnd(20));
27 if(hit) mdef->msleep = 0;
28 vis = (cansee(magr->mx,magr->my) && cansee(mdef->mx,mdef->my));
31 if(mdef->mimic) seemimic(mdef);
32 if(magr->mimic) seemimic(magr);
33 (void) sprintf(buf,"%s %s", Monnam(magr),
34 hit ? "hits" : "misses");
35 pline("%s %s.", buf, monnam(mdef));
37 boolean far = (dist(magr->mx, magr->my) > 15);
38 if(far != far_noise || moves-noisetime > 10) {
41 pline("You hear some noises%s.",
42 far ? " in the distance" : "");
46 if(magr->data->mlet == 'c' && !magr->cham) {
48 if(vis) pline("%s is turned to stone!", Monnam(mdef));
50 pline("You have a peculiarly sad feeling for a moment, then it passes.");
54 if((mdef->mhp -= d(pa->damn,pa->damd)) < 1) {
55 magr->mhpmax += 1 + rn2(pd->mlevel+1);
56 if(magr->mtame && magr->mhpmax > 8*pa->mlevel){
57 if(pa == &li_dog) magr->data = pa = &dog;
58 else if(pa == &dog) magr->data = pa = &la_dog;
60 if(vis) pline("%s is killed!", Monnam(mdef));
62 pline("You have a sad feeling for a moment, then it passes.");
70 /* drop (perhaps) a cadaver and remove monster */
71 mondied(mdef) struct monst *mdef; {
72 struct permonst *pd = mdef->data;
73 if(letter(pd->mlet) && rn2(3)){
74 (void) mkobj_at(pd->mlet,mdef->mx,mdef->my);
75 if(cansee(mdef->mx,mdef->my)){
77 atl(mdef->mx,mdef->my,fobj->olet);
84 /* drop a rock and remove monster */
85 monstone(mdef) struct monst *mdef; {
87 if(index(mlarge, mdef->data->mlet))
88 mksobj_at(ENORMOUS_ROCK, mdef->mx, mdef->my);
90 mksobj_at(ROCK, mdef->mx, mdef->my);
91 if(cansee(mdef->mx, mdef->my)){
93 atl(mdef->mx,mdef->my,fobj->olet);
99 fightm(mtmp) struct monst *mtmp; {
101 for(mon = fmon; mon; mon = mon->nmon) if(mon != mtmp) {
102 if(DIST(mon->mx,mon->my,mtmp->mx,mtmp->my) < 3)
104 return(hitmm(mtmp,mon));
109 /* u is hit by sth, but not a monster */
116 if(u.uac + tlev <= rnd(20)) {
117 if(Blind) pline("It misses.");
118 else pline("You are almost hit by %s!", buf);
121 if(Blind) pline("You are hit!");
122 else pline("You are hit by %s!", buf);
128 char mlarge[] = "bCDdegIlmnoPSsTUwY',&";
131 hmon(mon,obj,thrown) /* return TRUE if mon still alive */
137 boolean hittxt = FALSE;
140 tmp = rnd(2); /* attack with bare hands */
141 if(mon->data->mlet == 'c' && !uarmg){
142 pline("You hit the cockatrice with your bare hands.");
143 pline("You turn to stone ...");
146 } else if(obj->olet == WEAPON_SYM || obj->otyp == PICK_AXE) {
147 if(obj == uwep && (obj->otyp > SPEAR || obj->otyp < BOOMERANG))
150 if(index(mlarge, mon->data->mlet)) {
151 tmp = rnd(objects[obj->otyp].wldam);
152 if(obj->otyp == TWO_HANDED_SWORD) tmp += d(2,6);
153 else if(obj->otyp == FLAIL) tmp += rnd(4);
155 tmp = rnd(objects[obj->otyp].wsdam);
158 if(!thrown && obj == uwep && obj->otyp == BOOMERANG
160 pline("As you hit %s, the boomerang breaks into splinters.",
163 setworn((struct obj *) 0, obj->owornmask);
164 obfree(obj, (struct obj *) 0);
168 if(mon->data->mlet == 'O' && obj->otyp == TWO_HANDED_SWORD &&
169 !strcmp(ONAME(obj), "Orcrist"))
171 } else switch(obj->otyp) {
172 case HEAVY_IRON_BALL:
173 tmp = rnd(25); break;
174 case EXPENSIVE_CAMERA:
175 pline("You succeed in destroying your camera. Congratulations!");
178 setworn((struct obj *) 0, obj->owornmask);
179 obfree(obj, (struct obj *) 0);
181 case DEAD_COCKATRICE:
182 pline("You hit %s with the cockatrice corpse.",
184 if(mon->data->mlet == 'c') {
189 pline("%s is turned to stone!", Monnam(mon));
192 case CLOVE_OF_GARLIC: /* no effect against demons */
193 if(index(UNDEAD, mon->data->mlet))
198 /* non-weapons can damage because of their weight */
199 /* (but not too much) */
206 /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) */
208 tmp += u.udaminc + dbon();
210 if((tmp -= u.uswldtim) <= 0) {
211 pline("Your arms are no longer able to hit.");
221 if(mon->mtame && (!mon->mflee || mon->mfleetim)) {
222 mon->mflee = 1; /* Rick Richardson */
223 mon->mfleetim += 10*rnd(tmp);
228 /* this assumes that we cannot throw plural things */
229 hit( xname(obj) /* or: objects[obj->otyp].oc_name */,
232 pline("You hit it.");
234 pline("You hit %s%s", monnam(mon), exclam(tmp));
237 if(u.umconf && !thrown) {
239 pline("Your hands stop glowing blue.");
240 if(!mon->mfroz && !mon->msleep)
241 pline("%s appears confused.",Monnam(mon));
246 return(TRUE); /* mon still alive */
249 /* try to attack; return FALSE if monster evaded */
250 /* u.dx and u.dy must be set */
255 boolean malive = TRUE;
256 struct permonst *mdat;
259 u_wipe_engr(3); /* andrew@orca: prevent unlimited pick-axe attacks */
261 if(mdat->mlet == 'L' && !mtmp->mfroz && !mtmp->msleep &&
262 !mtmp->mconf && mtmp->mcansee && !rn2(7) &&
263 (m_move(mtmp, 0) == 2 /* he died */ || /* he moved: */
264 mtmp->mx != u.ux+u.dx || mtmp->my != u.uy+u.dy))
268 if(!u.ustuck && !mtmp->mflee) u.ustuck = mtmp;
269 switch(levl[u.ux+u.dx][u.uy+u.dy].scrsym){
271 pline("The door actually was a Mimic.");
274 pline("The chest was a Mimic!");
277 pline("Wait! That's a Mimic!");
279 wakeup(mtmp); /* clears mtmp->mimic */
285 if(mtmp->mhide && mtmp->mundetected){
288 mtmp->mundetected = 0;
289 if((obj = o_at(mtmp->mx,mtmp->my)) && !Blind)
290 pline("Wait! There's a %s hiding under %s!",
291 mdat->mname, doname(obj));
295 tmp = u.uluck + u.ulevel + mdat->ac + abon();
297 if(uwep->olet == WEAPON_SYM || uwep->otyp == PICK_AXE)
299 if(uwep->otyp == TWO_HANDED_SWORD) tmp -= 1;
300 else if(uwep->otyp == DAGGER) tmp += 2;
301 else if(uwep->otyp == CRYSKNIFE) tmp += 3;
302 else if(uwep->otyp == SPEAR &&
303 index("XDne", mdat->mlet)) tmp += 2;
311 if(!rn2(10)) mtmp->mfroz = 0;
313 if(mtmp->mflee) tmp += 2;
314 if(u.utrap) tmp -= 3;
316 /* with a lot of luggage, your agility diminishes */
317 tmp -= (inv_weight() + 40)/20;
319 if(tmp <= rnd(20) && !u.uswallow){
320 if(Blind) pline("You miss it.");
321 else pline("You miss %s.",monnam(mtmp));
323 /* we hit the monster; be careful: it might die! */
325 if((malive = hmon(mtmp,uwep,0)) == TRUE) {
326 /* monster still alive */
327 if(!rn2(25) && mtmp->mhp < mtmp->mhpmax/2) {
329 if(!rn2(3)) mtmp->mfleetim = rnd(100);
330 if(u.ustuck == mtmp && !u.uswallow)
335 cutworm(mtmp, u.ux+u.dx, u.uy+u.dy,
336 uwep ? uwep->otyp : 0);
339 if(mdat->mlet == 'a') {
341 pline("You are splashed by the blob's acid!");
342 losehp_m(rnd(6), mtmp);
343 if(!rn2(30)) corrode_armor();
345 if(!rn2(6)) corrode_weapon();
348 if(malive && mdat->mlet == 'E' && canseemon(mtmp)
349 && !mtmp->mcan && rn2(3)) {
351 pline("You are frozen by the floating eye's gaze!");
352 nomul((u.ulevel > 6 || rn2(4)) ? rn1(20,-21) : -200);
354 pline("The blinded floating eye cannot defend itself.");
355 if(!rn2(500)) if((int)u.uluck > LUCKMIN) u.uluck--;