]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.fight.c
merge with Lite, new RCS id conventions, etc.
[bsdgames-darwin.git] / hack / hack.fight.c
1 /*
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
3 */
4
5 #ifndef lint
6 static char rcsid[] = "$NetBSD: hack.fight.c,v 1.3 1995/03/23 08:30:12 cgd Exp $";
7 #endif /* not lint */
8
9 #include "hack.h"
10 extern struct permonst li_dog, dog, la_dog;
11 extern char *exclam(), *xname();
12 extern struct obj *mkobj_at();
13
14 static boolean far_noise;
15 static long noisetime;
16
17 /* hitmm returns 0 (miss), 1 (hit), or 2 (kill) */
18 hitmm(magr,mdef) register struct monst *magr,*mdef; {
19 register struct permonst *pa = magr->data, *pd = mdef->data;
20 int hit;
21 schar tmp;
22 boolean vis;
23 if(index("Eauy", pa->mlet)) return(0);
24 if(magr->mfroz) return(0); /* riv05!a3 */
25 tmp = pd->ac + pa->mlevel;
26 if(mdef->mconf || mdef->mfroz || mdef->msleep){
27 tmp += 4;
28 if(mdef->msleep) mdef->msleep = 0;
29 }
30 hit = (tmp > rnd(20));
31 if(hit) mdef->msleep = 0;
32 vis = (cansee(magr->mx,magr->my) && cansee(mdef->mx,mdef->my));
33 if(vis){
34 char buf[BUFSZ];
35 if(mdef->mimic) seemimic(mdef);
36 if(magr->mimic) seemimic(magr);
37 (void) sprintf(buf,"%s %s", Monnam(magr),
38 hit ? "hits" : "misses");
39 pline("%s %s.", buf, monnam(mdef));
40 } else {
41 boolean far = (dist(magr->mx, magr->my) > 15);
42 if(far != far_noise || moves-noisetime > 10) {
43 far_noise = far;
44 noisetime = moves;
45 pline("You hear some noises%s.",
46 far ? " in the distance" : "");
47 }
48 }
49 if(hit){
50 if(magr->data->mlet == 'c' && !magr->cham) {
51 magr->mhpmax += 3;
52 if(vis) pline("%s is turned to stone!", Monnam(mdef));
53 else if(mdef->mtame)
54 pline("You have a peculiarly sad feeling for a moment, then it passes.");
55 monstone(mdef);
56 hit = 2;
57 } else
58 if((mdef->mhp -= d(pa->damn,pa->damd)) < 1) {
59 magr->mhpmax += 1 + rn2(pd->mlevel+1);
60 if(magr->mtame && magr->mhpmax > 8*pa->mlevel){
61 if(pa == &li_dog) magr->data = pa = &dog;
62 else if(pa == &dog) magr->data = pa = &la_dog;
63 }
64 if(vis) pline("%s is killed!", Monnam(mdef));
65 else if(mdef->mtame)
66 pline("You have a sad feeling for a moment, then it passes.");
67 mondied(mdef);
68 hit = 2;
69 }
70 }
71 return(hit);
72 }
73
74 /* drop (perhaps) a cadaver and remove monster */
75 mondied(mdef) register struct monst *mdef; {
76 register struct permonst *pd = mdef->data;
77 if(letter(pd->mlet) && rn2(3)){
78 (void) mkobj_at(pd->mlet,mdef->mx,mdef->my);
79 if(cansee(mdef->mx,mdef->my)){
80 unpmon(mdef);
81 atl(mdef->mx,mdef->my,fobj->olet);
82 }
83 stackobj(fobj);
84 }
85 mondead(mdef);
86 }
87
88 /* drop a rock and remove monster */
89 monstone(mdef) register struct monst *mdef; {
90 extern char mlarge[];
91 if(index(mlarge, mdef->data->mlet))
92 mksobj_at(ENORMOUS_ROCK, mdef->mx, mdef->my);
93 else
94 mksobj_at(ROCK, mdef->mx, mdef->my);
95 if(cansee(mdef->mx, mdef->my)){
96 unpmon(mdef);
97 atl(mdef->mx,mdef->my,fobj->olet);
98 }
99 mondead(mdef);
100 }
101
102
103 fightm(mtmp) register struct monst *mtmp; {
104 register struct monst *mon;
105 for(mon = fmon; mon; mon = mon->nmon) if(mon != mtmp) {
106 if(DIST(mon->mx,mon->my,mtmp->mx,mtmp->my) < 3)
107 if(rn2(4))
108 return(hitmm(mtmp,mon));
109 }
110 return(-1);
111 }
112
113 /* u is hit by sth, but not a monster */
114 thitu(tlev,dam,name)
115 register tlev,dam;
116 register char *name;
117 {
118 char buf[BUFSZ];
119 setan(name,buf);
120 if(u.uac + tlev <= rnd(20)) {
121 if(Blind) pline("It misses.");
122 else pline("You are almost hit by %s!", buf);
123 return(0);
124 } else {
125 if(Blind) pline("You are hit!");
126 else pline("You are hit by %s!", buf);
127 losehp(dam,name);
128 return(1);
129 }
130 }
131
132 char mlarge[] = "bCDdegIlmnoPSsTUwY',&";
133
134 boolean
135 hmon(mon,obj,thrown) /* return TRUE if mon still alive */
136 register struct monst *mon;
137 register struct obj *obj;
138 register thrown;
139 {
140 register tmp;
141 boolean hittxt = FALSE;
142
143 if(!obj){
144 tmp = rnd(2); /* attack with bare hands */
145 if(mon->data->mlet == 'c' && !uarmg){
146 pline("You hit the cockatrice with your bare hands.");
147 pline("You turn to stone ...");
148 done_in_by(mon);
149 }
150 } else if(obj->olet == WEAPON_SYM || obj->otyp == PICK_AXE) {
151 if(obj == uwep && (obj->otyp > SPEAR || obj->otyp < BOOMERANG))
152 tmp = rnd(2);
153 else {
154 if(index(mlarge, mon->data->mlet)) {
155 tmp = rnd(objects[obj->otyp].wldam);
156 if(obj->otyp == TWO_HANDED_SWORD) tmp += d(2,6);
157 else if(obj->otyp == FLAIL) tmp += rnd(4);
158 } else {
159 tmp = rnd(objects[obj->otyp].wsdam);
160 }
161 tmp += obj->spe;
162 if(!thrown && obj == uwep && obj->otyp == BOOMERANG
163 && !rn2(3)){
164 pline("As you hit %s, the boomerang breaks into splinters.",
165 monnam(mon));
166 freeinv(obj);
167 setworn((struct obj *) 0, obj->owornmask);
168 obfree(obj, (struct obj *) 0);
169 tmp++;
170 }
171 }
172 if(mon->data->mlet == 'O' && obj->otyp == TWO_HANDED_SWORD &&
173 !strcmp(ONAME(obj), "Orcrist"))
174 tmp += rnd(10);
175 } else switch(obj->otyp) {
176 case HEAVY_IRON_BALL:
177 tmp = rnd(25); break;
178 case EXPENSIVE_CAMERA:
179 pline("You succeed in destroying your camera. Congratulations!");
180 freeinv(obj);
181 if(obj->owornmask)
182 setworn((struct obj *) 0, obj->owornmask);
183 obfree(obj, (struct obj *) 0);
184 return(TRUE);
185 case DEAD_COCKATRICE:
186 pline("You hit %s with the cockatrice corpse.",
187 monnam(mon));
188 if(mon->data->mlet == 'c') {
189 tmp = 1;
190 hittxt = TRUE;
191 break;
192 }
193 pline("%s is turned to stone!", Monnam(mon));
194 killed(mon);
195 return(FALSE);
196 case CLOVE_OF_GARLIC: /* no effect against demons */
197 if(index(UNDEAD, mon->data->mlet))
198 mon->mflee = 1;
199 tmp = 1;
200 break;
201 default:
202 /* non-weapons can damage because of their weight */
203 /* (but not too much) */
204 tmp = obj->owt/10;
205 if(tmp < 1) tmp = 1;
206 else tmp = rnd(tmp);
207 if(tmp > 6) tmp = 6;
208 }
209
210 /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) */
211
212 tmp += u.udaminc + dbon();
213 if(u.uswallow) {
214 if((tmp -= u.uswldtim) <= 0) {
215 pline("Your arms are no longer able to hit.");
216 return(TRUE);
217 }
218 }
219 if(tmp < 1) tmp = 1;
220 mon->mhp -= tmp;
221 if(mon->mhp < 1) {
222 killed(mon);
223 return(FALSE);
224 }
225 if(mon->mtame && (!mon->mflee || mon->mfleetim)) {
226 mon->mflee = 1; /* Rick Richardson */
227 mon->mfleetim += 10*rnd(tmp);
228 }
229
230 if(!hittxt) {
231 if(thrown)
232 /* this assumes that we cannot throw plural things */
233 hit( xname(obj) /* or: objects[obj->otyp].oc_name */,
234 mon, exclam(tmp) );
235 else if(Blind)
236 pline("You hit it.");
237 else
238 pline("You hit %s%s", monnam(mon), exclam(tmp));
239 }
240
241 if(u.umconf && !thrown) {
242 if(!Blind) {
243 pline("Your hands stop glowing blue.");
244 if(!mon->mfroz && !mon->msleep)
245 pline("%s appears confused.",Monnam(mon));
246 }
247 mon->mconf = 1;
248 u.umconf = 0;
249 }
250 return(TRUE); /* mon still alive */
251 }
252
253 /* try to attack; return FALSE if monster evaded */
254 /* u.dx and u.dy must be set */
255 attack(mtmp)
256 register struct monst *mtmp;
257 {
258 schar tmp;
259 boolean malive = TRUE;
260 register struct permonst *mdat;
261 mdat = mtmp->data;
262
263 u_wipe_engr(3); /* andrew@orca: prevent unlimited pick-axe attacks */
264
265 if(mdat->mlet == 'L' && !mtmp->mfroz && !mtmp->msleep &&
266 !mtmp->mconf && mtmp->mcansee && !rn2(7) &&
267 (m_move(mtmp, 0) == 2 /* he died */ || /* he moved: */
268 mtmp->mx != u.ux+u.dx || mtmp->my != u.uy+u.dy))
269 return(FALSE);
270
271 if(mtmp->mimic){
272 if(!u.ustuck && !mtmp->mflee) u.ustuck = mtmp;
273 switch(levl[u.ux+u.dx][u.uy+u.dy].scrsym){
274 case '+':
275 pline("The door actually was a Mimic.");
276 break;
277 case '$':
278 pline("The chest was a Mimic!");
279 break;
280 default:
281 pline("Wait! That's a Mimic!");
282 }
283 wakeup(mtmp); /* clears mtmp->mimic */
284 return(TRUE);
285 }
286
287 wakeup(mtmp);
288
289 if(mtmp->mhide && mtmp->mundetected){
290 register struct obj *obj;
291
292 mtmp->mundetected = 0;
293 if((obj = o_at(mtmp->mx,mtmp->my)) && !Blind)
294 pline("Wait! There's a %s hiding under %s!",
295 mdat->mname, doname(obj));
296 return(TRUE);
297 }
298
299 tmp = u.uluck + u.ulevel + mdat->ac + abon();
300 if(uwep) {
301 if(uwep->olet == WEAPON_SYM || uwep->otyp == PICK_AXE)
302 tmp += uwep->spe;
303 if(uwep->otyp == TWO_HANDED_SWORD) tmp -= 1;
304 else if(uwep->otyp == DAGGER) tmp += 2;
305 else if(uwep->otyp == CRYSKNIFE) tmp += 3;
306 else if(uwep->otyp == SPEAR &&
307 index("XDne", mdat->mlet)) tmp += 2;
308 }
309 if(mtmp->msleep) {
310 mtmp->msleep = 0;
311 tmp += 2;
312 }
313 if(mtmp->mfroz) {
314 tmp += 4;
315 if(!rn2(10)) mtmp->mfroz = 0;
316 }
317 if(mtmp->mflee) tmp += 2;
318 if(u.utrap) tmp -= 3;
319
320 /* with a lot of luggage, your agility diminishes */
321 tmp -= (inv_weight() + 40)/20;
322
323 if(tmp <= rnd(20) && !u.uswallow){
324 if(Blind) pline("You miss it.");
325 else pline("You miss %s.",monnam(mtmp));
326 } else {
327 /* we hit the monster; be careful: it might die! */
328
329 if((malive = hmon(mtmp,uwep,0)) == TRUE) {
330 /* monster still alive */
331 if(!rn2(25) && mtmp->mhp < mtmp->mhpmax/2) {
332 mtmp->mflee = 1;
333 if(!rn2(3)) mtmp->mfleetim = rnd(100);
334 if(u.ustuck == mtmp && !u.uswallow)
335 u.ustuck = 0;
336 }
337 #ifndef NOWORM
338 if(mtmp->wormno)
339 cutworm(mtmp, u.ux+u.dx, u.uy+u.dy,
340 uwep ? uwep->otyp : 0);
341 #endif NOWORM
342 }
343 if(mdat->mlet == 'a') {
344 if(rn2(2)) {
345 pline("You are splashed by the blob's acid!");
346 losehp_m(rnd(6), mtmp);
347 if(!rn2(30)) corrode_armor();
348 }
349 if(!rn2(6)) corrode_weapon();
350 }
351 }
352 if(malive && mdat->mlet == 'E' && canseemon(mtmp)
353 && !mtmp->mcan && rn2(3)) {
354 if(mtmp->mcansee) {
355 pline("You are frozen by the floating eye's gaze!");
356 nomul((u.ulevel > 6 || rn2(4)) ? rn1(20,-21) : -200);
357 } else {
358 pline("The blinded floating eye cannot defend itself.");
359 if(!rn2(500)) if((int)u.uluck > LUCKMIN) u.uluck--;
360 }
361 }
362 return(TRUE);
363 }