clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hack.mon.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/games/hack/obj -resource-dir /usr/local/lib/clang/13.0.0 -I . -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/games/hack/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/games/hack/hack.mon.c
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | #include <stdlib.h> |
65 | |
66 | #include "hack.h" |
67 | #include "hack.mfndpos.h" |
68 | |
69 | int warnlevel; |
70 | long lastwarntime; |
71 | int lastwarnlev; |
72 | char *warnings[] = { |
73 | "white", "pink", "red", "ruby", "purple", "black" |
74 | }; |
75 | |
76 | static int dochugw(struct monst *); |
77 | static void mpickgold(struct monst *); |
78 | static void mpickgems(struct monst *); |
79 | static void dmonsfree(void); |
80 | static int ishuman(struct monst *); |
81 | |
82 | void |
83 | movemon(void) |
84 | { |
85 | struct monst *mtmp; |
86 | int fr; |
87 | |
88 | warnlevel = 0; |
89 | |
90 | while(1) { |
| 1 | Loop condition is true. Entering loop body | |
|
91 | |
92 | |
93 | |
94 | |
95 | for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) |
| 2 | | Loop condition is true. Entering loop body | |
|
96 | if(mtmp->mlstmv < moves) goto next_mon; |
| 3 | | Assuming 'moves' is > field 'mlstmv' | |
|
| |
| 5 | | Control jumps to line 101 | |
|
97 | |
98 | break; |
99 | |
100 | next_mon: |
101 | mtmp->mlstmv = moves; |
102 | |
103 | |
104 | { boolean inpool, iseel; |
105 | |
106 | inpool = (levl[(int)mtmp->mx][(int)mtmp->my].typ == POOL); |
107 | iseel = (mtmp->data->mlet == ';'); |
| 6 | | Assuming the condition is false | |
|
108 | if(inpool && !iseel) { |
| |
109 | if(cansee(mtmp->mx,mtmp->my)) |
110 | pline("%s drowns.", Monnam(mtmp)); |
111 | mondead(mtmp); |
112 | continue; |
113 | } |
114 | |
115 | if(iseel && !inpool) { |
116 | if(mtmp->mhp > 1) mtmp->mhp--; |
117 | mtmp->mflee = 1; |
118 | mtmp->mfleetim += 2; |
119 | } |
120 | } |
121 | if(mtmp->mblinded && !--mtmp->mblinded) |
| 8 | | Assuming field 'mblinded' is 0 | |
|
122 | mtmp->mcansee = 1; |
123 | if(mtmp->mfleetim && !--mtmp->mfleetim) |
| 9 | | Assuming field 'mfleetim' is 0 | |
|
124 | mtmp->mflee = 0; |
125 | if(mtmp->mimic) continue; |
| 10 | | Assuming field 'mimic' is 0 | |
|
| |
126 | if(mtmp->mspeed != MSLOW || !(moves%2)){ |
| 12 | | Assuming field 'mspeed' is equal to MSLOW | |
|
| 13 | | Assuming the condition is true | |
|
| |
127 | |
128 | fr = -1; |
129 | if(Conflict && cansee(mtmp->mx,mtmp->my) |
| 15 | | Assuming field 'p_flgs' is 0 | |
|
130 | && (fr = fightm(mtmp)) == 2) |
131 | continue; |
132 | if(fr<0 && dochugw(mtmp)) |
| |
133 | continue; |
134 | } |
135 | if(mtmp->mspeed == MFAST && dochugw(mtmp)) |
136 | continue; |
137 | } |
138 | |
139 | warnlevel -= u.ulevel; |
140 | if(warnlevel >= SIZE(warnings)) |
141 | warnlevel = SIZE(warnings)-1; |
142 | if(warnlevel >= 0) |
143 | if(warnlevel > lastwarnlev || moves > lastwarntime + 5){ |
144 | char *rr; |
145 | switch(Warning & (LEFT_RING | RIGHT_RING)){ |
146 | case LEFT_RING: |
147 | rr = "Your left ring glows"; |
148 | break; |
149 | case RIGHT_RING: |
150 | rr = "Your right ring glows"; |
151 | break; |
152 | case LEFT_RING | RIGHT_RING: |
153 | rr = "Both your rings glow"; |
154 | break; |
155 | default: |
156 | rr = "Your fingertips glow"; |
157 | break; |
158 | } |
159 | pline("%s %s!", rr, warnings[warnlevel]); |
160 | lastwarntime = moves; |
161 | lastwarnlev = warnlevel; |
162 | } |
163 | |
164 | dmonsfree(); |
165 | } |
166 | |
167 | void |
168 | justswld(struct monst *mtmp, char *name) |
169 | { |
170 | mtmp->mx = u.ux; |
171 | mtmp->my = u.uy; |
172 | u.ustuck = mtmp; |
173 | pmon(mtmp); |
174 | kludge("%s swallows you!",name); |
175 | more(); |
176 | seeoff(1); |
177 | u.uswallow = 1; |
178 | u.uswldtim = 0; |
179 | swallowed(); |
180 | } |
181 | |
182 | void |
183 | youswld(struct monst *mtmp, int dam, int die, char *name) |
184 | { |
185 | if(mtmp != u.ustuck) return; |
186 | kludge("%s digests you!",name); |
187 | u.uhp -= dam; |
188 | if(u.uswldtim++ >= die){ |
189 | pline("It totally digests you!"); |
190 | u.uhp = -1; |
191 | } |
192 | if(u.uhp < 1) done_in_by(mtmp); |
193 | |
194 | } |
195 | |
196 | static int |
197 | dochugw(struct monst *mtmp) |
198 | { |
199 | int x = mtmp->mx; |
200 | int y = mtmp->my; |
201 | int d = dochug(mtmp); |
| |
202 | int dd; |
203 | |
204 | if(!d) |
205 | if(Warning) |
206 | if(!mtmp->mpeaceful) |
207 | if(mtmp->data->mlevel > warnlevel) |
208 | if((dd = dist(mtmp->mx,mtmp->my)) < dist(x,y)) |
209 | if(dd < 100) |
210 | if(!canseemon(mtmp)) |
211 | warnlevel = mtmp->data->mlevel; |
212 | return(d); |
213 | } |
214 | |
215 | |
216 | int |
217 | dochug(struct monst *mtmp) |
218 | { |
219 | struct permonst *mdat; |
220 | int tmp, nearby, scared; |
| 18 | | 'tmp' declared without an initial value | |
|
221 | |
222 | if(mtmp->cham && !rn2(6)) |
| 19 | | Assuming field 'cham' is 0 | |
|
223 | (void) newcham(mtmp, &mons[dlevel+14+rn2(CMNUM-14-dlevel)]); |
224 | mdat = mtmp->data; |
225 | if(mdat->mlevel < 0) |
| 20 | | Assuming field 'mlevel' is >= 0 | |
|
| |
226 | panic("bad monster %c (%d)",mdat->mlet,mdat->mlevel); |
227 | |
228 | |
229 | if((!(moves%20) || strchr(MREGEN, mdat->mlet)) && |
| 22 | | Assuming the condition is false | |
|
| 23 | | Assuming the condition is false | |
|
230 | mtmp->mhp < mtmp->mhpmax) |
231 | mtmp->mhp++; |
232 | |
233 | if(mtmp->mfroz) return(0); |
| 24 | | Assuming field 'mfroz' is 0 | |
|
| |
234 | |
235 | if(mtmp->msleep) { |
| 26 | | Assuming field 'msleep' is 0 | |
|
| |
236 | |
237 | |
238 | |
239 | if(cansee(mtmp->mx,mtmp->my) && |
240 | (!Stealth || (mdat->mlet == 'e' && rn2(10))) && |
241 | (!strchr("NL",mdat->mlet) || !rn2(50)) && |
242 | (Aggravate_monster || strchr("d1", mdat->mlet) |
243 | || (!rn2(7) && !mtmp->mimic))) |
244 | mtmp->msleep = 0; |
245 | else return(0); |
246 | } |
247 | |
248 | |
249 | wipe_engr_at(mtmp->mx, mtmp->my, 1); |
250 | |
251 | |
252 | if(mtmp->mconf && !rn2(50)) mtmp->mconf = 0; |
| 28 | | Assuming field 'mconf' is 0 | |
|
253 | |
254 | |
255 | if(mtmp->mflee && strchr("tNL", mdat->mlet) && !rn2(40)){ |
| 29 | | Assuming field 'mflee' is 0 | |
|
256 | rloc(mtmp); |
257 | return(0); |
258 | } |
259 | if(mdat->mmove < rnd(6)) return(0); |
| 30 | | Assuming the condition is false | |
|
| |
260 | |
261 | |
262 | if(mtmp->mflee && !mtmp->mfleetim |
263 | && mtmp->mhp == mtmp->mhpmax && !rn2(25)) |
264 | mtmp->mflee = 0; |
265 | |
266 | nearby = (dist(mtmp->mx, mtmp->my) < 3); |
| 32 | | Assuming the condition is true | |
|
267 | scared = (nearby && (sengr_at("Elbereth", u.ux, u.uy) || |
| 33 | | Assuming the condition is false | |
|
268 | sobj_at(SCR_SCARE_MONSTER, u.ux, u.uy))); |
269 | if(scared && !mtmp->mflee) { |
| |
270 | mtmp->mflee = 1; |
271 | mtmp->mfleetim = (rn2(7) ? rnd(10) : rnd(100)); |
272 | } |
273 | |
274 | if(!nearby || |
| |
275 | mtmp->mflee || |
276 | mtmp->mconf || |
277 | (mtmp->minvis && !rn2(3)) || |
| 35 | | Assuming field 'minvis' is 0 | |
|
278 | (strchr("BIuy", mdat->mlet) && !rn2(4)) || |
| 36 | | Assuming the condition is false | |
|
279 | (mdat->mlet == 'L' && !u.ugold && (mtmp->mgold || rn2(2))) || |
| 37 | | Assuming the condition is false | |
|
280 | (!mtmp->mcansee && !rn2(4)) || |
| 38 | | Assuming field 'mcansee' is not equal to 0 | |
|
281 | mtmp->mpeaceful |
| 39 | | Assuming field 'mpeaceful' is 0 | |
|
282 | ) { |
283 | tmp = m_move(mtmp,0); |
284 | if(tmp == 2 || (tmp && mdat->mmove <= 12)) |
285 | return(tmp == 2); |
286 | } |
287 | |
288 | if(!strchr("Ea", mdat->mlet) && nearby && |
| 41 | | Assuming the condition is false | |
|
289 | !mtmp->mpeaceful && u.uhp > 0 && !scared) { |
290 | if(mhitu(mtmp)) |
291 | return(1); |
292 | } |
293 | |
294 | if(mdat->mmove-12 > rnd(12)) tmp = m_move(mtmp,1); |
| 42 | | Assuming the condition is false | |
|
| |
295 | return(tmp == 2); |
| 44 | | The left operand of '==' is a garbage value |
|
296 | } |
297 | |
298 | int |
299 | m_move(struct monst *mtmp, int after) |
300 | { |
301 | struct monst *mtmp2; |
302 | int nx,ny,omx,omy,appr,nearer,cnt,i,j; |
303 | xchar gx,gy,nix,niy,chcnt; |
304 | int chi; |
305 | boolean likegold, likegems, likeobjs; |
306 | char msym = mtmp->data->mlet; |
307 | schar mmoved = 0; |
308 | coord poss[9]; |
309 | int info[9]; |
310 | |
311 | if(mtmp->mfroz || mtmp->msleep) |
312 | return(0); |
313 | if(mtmp->mtrapped) { |
314 | i = mintrap(mtmp); |
315 | if(i == 2) return(2); |
316 | if(i == 1) return(0); |
317 | } |
318 | if(mtmp->mhide && o_at(mtmp->mx,mtmp->my) && rn2(10)) |
319 | return(0); |
320 | |
321 | #ifndef NOWORM |
322 | if(mtmp->wormno) |
323 | goto not_special; |
324 | #endif /* NOWORM */ |
325 | |
326 | |
327 | if(mtmp->mtame) { |
328 | return( dog_move(mtmp, after) ); |
329 | } |
330 | |
331 | |
332 | if(mtmp->isshk) { |
333 | mmoved = shk_move(mtmp); |
334 | if(mmoved >= 0) |
335 | goto postmov; |
336 | mmoved = 0; |
337 | } |
338 | |
339 | |
340 | if(mtmp->isgd) { |
341 | mmoved = gd_move(); |
342 | goto postmov; |
343 | } |
344 | |
345 | |
346 | if((msym == 't' && !rn2(5)) |
347 | || (msym == '1' && (mtmp->mhp < 7 || (!xdnstair && !rn2(5)) |
348 | || levl[(int)u.ux][(int)u.uy].typ == STAIRS))) { |
349 | if(mtmp->mhp < 7 || (msym == 't' && rn2(2))) |
350 | rloc(mtmp); |
351 | else |
352 | mnexto(mtmp); |
353 | mmoved = 1; |
354 | goto postmov; |
355 | } |
356 | |
357 | |
358 | if(strchr("D1", msym)) |
359 | inrange(mtmp); |
360 | |
361 | if(msym == 'U' && !mtmp->mcan && canseemon(mtmp) && |
362 | mtmp->mcansee && rn2(5)) { |
363 | if(!Confusion) |
364 | pline("%s's gaze has confused you!", Monnam(mtmp)); |
365 | else |
366 | pline("You are getting more and more confused."); |
367 | if(rn2(3)) mtmp->mcan = 1; |
368 | Confusion += d(3,4); |
369 | } |
370 | not_special: |
371 | if(!mtmp->mflee && u.uswallow && u.ustuck != mtmp) return(1); |
372 | appr = 1; |
373 | if(mtmp->mflee) appr = -1; |
374 | if(mtmp->mconf || Invis || !mtmp->mcansee || |
375 | (strchr("BIy", msym) && !rn2(3))) |
376 | appr = 0; |
377 | omx = mtmp->mx; |
378 | omy = mtmp->my; |
379 | gx = u.ux; |
380 | gy = u.uy; |
381 | if(msym == 'L' && appr == 1 && mtmp->mgold > u.ugold) |
382 | appr = -1; |
383 | |
384 | |
385 | |
386 | |
387 | if(msym == '@' || |
388 | ('a' <= msym && msym <= 'z')) { |
389 | coord *cp; |
390 | schar mroom; |
391 | mroom = inroom(omx,omy); |
392 | if(mroom < 0 || mroom != inroom(u.ux,u.uy)){ |
393 | cp = gettrack(omx,omy); |
394 | if(cp){ |
395 | gx = cp->x; |
396 | gy = cp->y; |
397 | } |
398 | } |
399 | } |
400 | |
401 | |
402 | likegold = (strchr("LOD", msym) != NULL); |
403 | likegems = (strchr("ODu", msym) != NULL); |
404 | likeobjs = mtmp->mhide; |
405 | #define SRCHRADIUS 25 |
406 | { xchar mind = SRCHRADIUS; |
407 | int dd; |
408 | if(likegold){ |
409 | struct gold *gold; |
410 | for(gold = fgold; gold; gold = gold->ngold) |
411 | if((dd = DIST(omx,omy,gold->gx,gold->gy)) < mind){ |
412 | mind = dd; |
413 | gx = gold->gx; |
414 | gy = gold->gy; |
415 | } |
416 | } |
417 | if(likegems || likeobjs){ |
418 | struct obj *otmp; |
419 | for(otmp = fobj; otmp; otmp = otmp->nobj) |
420 | if(likeobjs || otmp->olet == GEM_SYM) |
421 | if(msym != 'u' || |
422 | objects[otmp->otyp].g_val != 0) |
423 | if((dd = DIST(omx,omy,otmp->ox,otmp->oy)) < mind){ |
424 | mind = dd; |
425 | gx = otmp->ox; |
426 | gy = otmp->oy; |
427 | } |
428 | } |
429 | if(mind < SRCHRADIUS && appr == -1) { |
430 | if(dist(omx,omy) < 10) { |
431 | gx = u.ux; |
432 | gy = u.uy; |
433 | } else |
434 | appr = 1; |
435 | } |
436 | } |
437 | nix = omx; |
438 | niy = omy; |
439 | cnt = mfndpos(mtmp,poss,info, |
440 | msym == 'u' ? NOTONL : |
441 | (msym == '@' || msym == '1') ? (ALLOW_SSM | ALLOW_TRAPS) : |
442 | strchr(UNDEAD, msym) ? NOGARLIC : ALLOW_TRAPS); |
443 | |
444 | chcnt = 0; |
445 | chi = -1; |
446 | for(i=0; i<cnt; i++) { |
447 | nx = poss[i].x; |
448 | ny = poss[i].y; |
449 | for(j=0; j<MTSZ && j<cnt-1; j++) |
450 | if(nx == mtmp->mtrack[j].x && ny == mtmp->mtrack[j].y) |
451 | if(rn2(4*(cnt-j))) goto nxti; |
452 | #ifdef STUPID |
453 | |
454 | { int d1 = DIST(nx,ny,gx,gy); |
455 | int d2 = DIST(nix,niy,gx,gy); |
456 | nearer = (d1 < d2); |
457 | } |
458 | #else |
459 | nearer = (DIST(nx,ny,gx,gy) < DIST(nix,niy,gx,gy)); |
460 | #endif /* STUPID */ |
461 | if((appr == 1 && nearer) || (appr == -1 && !nearer) || |
462 | !mmoved || |
463 | (!appr && !rn2(++chcnt))){ |
464 | nix = nx; |
465 | niy = ny; |
466 | chi = i; |
467 | mmoved = 1; |
468 | } |
469 | nxti: ; |
470 | } |
471 | if(mmoved){ |
472 | if(info[chi] & ALLOW_M){ |
473 | mtmp2 = m_at(nix,niy); |
474 | if(hitmm(mtmp,mtmp2) == 1 && rn2(4) && |
475 | hitmm(mtmp2,mtmp) == 2) return(2); |
476 | return(0); |
477 | } |
478 | if(info[chi] & ALLOW_U){ |
479 | (void) hitu(mtmp, d(mtmp->data->damn, mtmp->data->damd)+1); |
480 | return(0); |
481 | } |
482 | mtmp->mx = nix; |
483 | mtmp->my = niy; |
484 | for(j=MTSZ-1; j>0; j--) mtmp->mtrack[j] = mtmp->mtrack[j-1]; |
485 | mtmp->mtrack[0].x = omx; |
486 | mtmp->mtrack[0].y = omy; |
487 | #ifndef NOWORM |
488 | if(mtmp->wormno) worm_move(mtmp); |
489 | #endif /* NOWORM */ |
490 | } else { |
491 | if(msym == 'u' && rn2(2)){ |
492 | rloc(mtmp); |
493 | return(0); |
494 | } |
495 | #ifndef NOWORM |
496 | if(mtmp->wormno) worm_nomove(mtmp); |
497 | #endif /* NOWORM */ |
498 | } |
499 | postmov: |
500 | if(mmoved == 1) { |
501 | if(mintrap(mtmp) == 2) |
502 | return(2); |
503 | if(likegold) mpickgold(mtmp); |
504 | if(likegems) mpickgems(mtmp); |
505 | if(mtmp->mhide) mtmp->mundetected = 1; |
506 | } |
507 | pmon(mtmp); |
508 | return(mmoved); |
509 | } |
510 | |
511 | static void |
512 | mpickgold(struct monst *mtmp) |
513 | { |
514 | struct gold *gold; |
515 | |
516 | while ((gold = g_at(mtmp->mx, mtmp->my))) { |
517 | mtmp->mgold += gold->amount; |
518 | freegold(gold); |
519 | if(levl[(int)mtmp->mx][(int)mtmp->my].scrsym == '$') |
520 | newsym(mtmp->mx, mtmp->my); |
521 | } |
522 | } |
523 | |
524 | static void |
525 | mpickgems(struct monst *mtmp) |
526 | { |
527 | struct obj *otmp; |
528 | |
529 | for (otmp = fobj; otmp; otmp = otmp->nobj) |
530 | if (otmp->olet == GEM_SYM) |
531 | if (otmp->ox == mtmp->mx && otmp->oy == mtmp->my) |
532 | if (mtmp->data->mlet != 'u' || objects[otmp->otyp].g_val != 0){ |
533 | freeobj(otmp); |
534 | mpickobj(mtmp, otmp); |
535 | if(levl[(int)mtmp->mx][(int)mtmp->my].scrsym == GEM_SYM) |
536 | newsym(mtmp->mx, mtmp->my); |
537 | return; |
538 | } |
539 | } |
540 | |
541 | |
542 | int |
543 | mfndpos(struct monst *mon, coord poss[9],int info[9], int flag) |
544 | { |
545 | int x,y,nx,ny,cnt = 0,ntyp; |
546 | struct monst *mtmp; |
547 | int nowtyp; |
548 | boolean pool; |
549 | |
550 | x = mon->mx; |
551 | y = mon->my; |
552 | nowtyp = levl[x][y].typ; |
553 | |
554 | pool = (mon->data->mlet == ';'); |
555 | nexttry: |
556 | |
557 | if(mon->mconf) { |
558 | flag |= ALLOW_ALL; |
559 | flag &= ~NOTONL; |
560 | } |
561 | for(nx = x-1; nx <= x+1; nx++) for(ny = y-1; ny <= y+1; ny++) |
562 | if(nx != x || ny != y) if(isok(nx,ny)) |
563 | if(!IS_ROCK(ntyp = levl[nx][ny].typ)) |
564 | if(!(nx != x && ny != y && (nowtyp == DOOR || ntyp == DOOR))) |
565 | if((ntyp == POOL) == pool) { |
566 | info[cnt] = 0; |
567 | if (nx == u.ux && ny == u.uy) { |
568 | if(!(flag & ALLOW_U)) continue; |
569 | info[cnt] = ALLOW_U; |
570 | } else if ((mtmp = m_at(nx,ny))) { |
571 | if (!(flag & ALLOW_M)) |
572 | continue; |
573 | info[cnt] = ALLOW_M; |
574 | if(mtmp->mtame){ |
575 | if(!(flag & ALLOW_TM)) continue; |
576 | info[cnt] |= ALLOW_TM; |
577 | } |
578 | } |
579 | if(sobj_at(CLOVE_OF_GARLIC, nx, ny)) { |
580 | if(flag & NOGARLIC) continue; |
581 | info[cnt] |= NOGARLIC; |
582 | } |
583 | if(sobj_at(SCR_SCARE_MONSTER, nx, ny) || |
584 | (!mon->mpeaceful && sengr_at("Elbereth", nx, ny))) { |
585 | if(!(flag & ALLOW_SSM)) continue; |
586 | info[cnt] |= ALLOW_SSM; |
587 | } |
588 | if(sobj_at(ENORMOUS_ROCK, nx, ny)) { |
589 | if(!(flag & ALLOW_ROCK)) continue; |
590 | info[cnt] |= ALLOW_ROCK; |
591 | } |
592 | if(!Invis && online(nx,ny)){ |
593 | if(flag & NOTONL) continue; |
594 | info[cnt] |= NOTONL; |
595 | } |
596 | |
597 | { struct trap *ttmp = t_at(nx, ny); |
598 | int tt; |
599 | if(ttmp) { |
600 | tt = 1 << ttmp->ttyp; |
601 | if(mon->mtrapseen & tt){ |
602 | if(!(flag & tt)) continue; |
603 | info[cnt] |= tt; |
604 | } |
605 | } |
606 | } |
607 | poss[cnt].x = nx; |
608 | poss[cnt].y = ny; |
609 | cnt++; |
610 | } |
611 | if(!cnt && pool && nowtyp != POOL) { |
612 | pool = FALSE; |
613 | goto nexttry; |
614 | } |
615 | return(cnt); |
616 | } |
617 | |
618 | int |
619 | dist(int x, int y) |
620 | { |
621 | return((x-u.ux)*(x-u.ux) + (y-u.uy)*(y-u.uy)); |
622 | } |
623 | |
624 | void |
625 | poisoned(char *string, char *pname) |
626 | { |
627 | int i; |
628 | |
629 | if(Blind) pline("It was poisoned."); |
630 | else pline("The %s was poisoned!",string); |
631 | if(Poison_resistance) { |
632 | pline("The poison doesn't seem to affect you."); |
633 | return; |
634 | } |
635 | i = rn2(10); |
636 | if(i == 0) { |
637 | u.uhp = -1; |
638 | pline("I am afraid the poison was deadly ..."); |
639 | } else if(i <= 5) { |
640 | losestr(rn1(3,3)); |
641 | } else { |
642 | losehp(rn1(10,6), pname); |
643 | } |
644 | if(u.uhp < 1) { |
645 | killer = pname; |
646 | done("died"); |
647 | } |
648 | } |
649 | |
650 | void |
651 | mondead(struct monst *mtmp) |
652 | { |
653 | relobj(mtmp,1); |
654 | unpmon(mtmp); |
655 | relmon(mtmp); |
656 | unstuck(mtmp); |
657 | if(mtmp->isshk) shkdead(mtmp); |
658 | if(mtmp->isgd) gddead(); |
659 | #ifndef NOWORM |
660 | if(mtmp->wormno) wormdead(mtmp); |
661 | #endif /* NOWORM */ |
662 | monfree(mtmp); |
663 | } |
664 | |
665 | |
666 | void |
667 | replmon(struct monst *mtmp, struct monst *mtmp2) |
668 | { |
669 | relmon(mtmp); |
670 | monfree(mtmp); |
671 | mtmp2->nmon = fmon; |
672 | fmon = mtmp2; |
673 | if(u.ustuck == mtmp) u.ustuck = mtmp2; |
674 | if(mtmp2->isshk) replshk(mtmp,mtmp2); |
675 | if(mtmp2->isgd) replgd(mtmp,mtmp2); |
676 | } |
677 | |
678 | void |
679 | relmon(struct monst *mon) |
680 | { |
681 | struct monst *mtmp; |
682 | |
683 | if(mon == fmon) fmon = fmon->nmon; |
684 | else { |
685 | for(mtmp = fmon; mtmp->nmon != mon; mtmp = mtmp->nmon) ; |
686 | mtmp->nmon = mon->nmon; |
687 | } |
688 | } |
689 | |
690 | |
691 | |
692 | struct monst *fdmon; |
693 | |
694 | void |
695 | monfree(struct monst *mtmp) |
696 | { |
697 | mtmp->nmon = fdmon; |
698 | fdmon = mtmp; |
699 | } |
700 | |
701 | static void |
702 | dmonsfree(void) |
703 | { |
704 | struct monst *mtmp; |
705 | |
706 | while ((mtmp = fdmon)) { |
707 | fdmon = mtmp->nmon; |
708 | free(mtmp); |
709 | } |
710 | } |
711 | |
712 | void |
713 | unstuck(struct monst *mtmp) |
714 | { |
715 | if(u.ustuck == mtmp) { |
716 | if(u.uswallow){ |
717 | u.ux = mtmp->mx; |
718 | u.uy = mtmp->my; |
719 | u.uswallow = 0; |
720 | setsee(); |
721 | docrt(); |
722 | } |
723 | u.ustuck = 0; |
724 | } |
725 | } |
726 | |
727 | void |
728 | killed(struct monst *mtmp) |
729 | { |
730 | int tmp, nk, x, y; |
731 | struct permonst *mdat; |
732 | |
733 | if(mtmp->cham) mtmp->data = PM_CHAMELEON; |
734 | mdat = mtmp->data; |
735 | if(Blind) pline("You destroy it!"); |
736 | else { |
737 | pline("You destroy %s!", |
738 | mtmp->mtame ? amonnam(mtmp, "poor") : monnam(mtmp)); |
739 | } |
740 | if(u.umconf) { |
741 | if(!Blind) pline("Your hands stop glowing blue."); |
742 | u.umconf = 0; |
743 | } |
744 | |
745 | |
746 | #define MAXMONNO 100 |
747 | nk = 1; |
748 | tmp = mdat - mons; |
749 | if(tmp >= 0 && tmp < CMNUM+2) { |
750 | extern char fut_geno[]; |
751 | u.nr_killed[tmp]++; |
752 | if((nk = u.nr_killed[tmp]) > MAXMONNO && |
753 | !strchr(fut_geno, mdat->mlet)) |
754 | charcat(fut_geno, mdat->mlet); |
755 | } |
756 | |
757 | |
758 | if(mdat->mlet == '@') Telepat = 0, u.uluck -= 2; |
759 | if(mtmp->mpeaceful || mtmp->mtame) u.uluck--; |
760 | if(mdat->mlet == 'u') u.uluck -= 5; |
761 | if((int)u.uluck < LUCKMIN) u.uluck = LUCKMIN; |
762 | |
763 | |
764 | tmp = 1 + mdat->mlevel * mdat->mlevel; |
765 | if(mdat->ac < 3) tmp += 2*(7 - mdat->ac); |
766 | if(strchr("AcsSDXaeRTVWU&In:P", mdat->mlet)) |
767 | tmp += 2*mdat->mlevel; |
768 | if(strchr("DeV&P",mdat->mlet)) tmp += (7*mdat->mlevel); |
769 | if(mdat->mlevel > 6) tmp += 50; |
770 | if(mdat->mlet == ';') tmp += 1000; |
771 | |
772 | #ifdef NEW_SCORING |
773 | |
774 | |
775 | { int ul = u.ulevel; |
776 | int ml = mdat->mlevel; |
777 | int tmp2; |
778 | |
779 | if(ul < 14) |
780 | for(tmp2 = 0; !tmp2 || ul + tmp2 <= ml; tmp2++) |
781 | if(u.uexp + 1 + (tmp + ((tmp2 <= 0) ? 0 : 4<<(tmp2-1)))/nk |
782 | >= 10*pow((unsigned)(ul-1))) |
783 | if(++ul == 14) break; |
784 | |
785 | tmp2 = ml - ul -1; |
786 | tmp = (tmp + ((tmp2 < 0) ? 0 : 4<<tmp2))/nk; |
787 | if(!tmp) tmp = 1; |
788 | } |
789 | |
790 | |
791 | #endif /* NEW_SCORING */ |
792 | |
793 | more_experienced(tmp,0); |
794 | flags.botl = 1; |
795 | while(u.ulevel < 14 && u.uexp >= newuexp()){ |
796 | pline("Welcome to experience level %u.", ++u.ulevel); |
797 | tmp = rnd(10); |
798 | if(tmp < 3) tmp = rnd(10); |
799 | u.uhpmax += tmp; |
800 | u.uhp += tmp; |
801 | flags.botl = 1; |
802 | } |
803 | |
804 | |
805 | x = mtmp->mx; y = mtmp->my; |
806 | mondead(mtmp); |
807 | tmp = mdat->mlet; |
808 | if(tmp == 'm') { |
809 | |
810 | mksobj_at(WAN_DIGGING, x, y); |
811 | |
812 | stackobj(fobj); |
813 | } else |
814 | #ifndef NOWORM |
815 | if(tmp == 'w') { |
816 | mksobj_at(WORM_TOOTH, x, y); |
817 | stackobj(fobj); |
818 | } else |
819 | #endif /* NOWORM */ |
820 | if(!letter(tmp) || (!strchr("mw", tmp) && !rn2(3))) tmp = 0; |
821 | |
822 | if(ACCESSIBLE(levl[x][y].typ)) |
823 | if(x != u.ux || y != u.uy) |
824 | if(strchr("NTVm&",mdat->mlet) || rn2(5)) { |
825 | struct obj *obj2 = mkobj_at(tmp,x,y); |
826 | if(cansee(x,y)) |
827 | atl(x,y,obj2->olet); |
828 | stackobj(obj2); |
829 | } |
830 | } |
831 | |
832 | void |
833 | kludge(char *str, char *arg) |
834 | { |
835 | if(Blind) { |
836 | if(*str == '%') pline(str,"It"); |
837 | else pline(str,"it"); |
838 | } else pline(str,arg); |
839 | } |
840 | |
841 | void |
842 | rescham(void) |
843 | { |
844 | struct monst *mtmp; |
845 | |
846 | for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) |
847 | if(mtmp->cham) { |
848 | mtmp->cham = 0; |
849 | (void) newcham(mtmp, PM_CHAMELEON); |
850 | } |
851 | } |
852 | |
853 | |
854 | |
855 | int |
856 | newcham(struct monst *mtmp, struct permonst *mdat) |
857 | { |
858 | int mhp, hpn, hpd; |
859 | |
860 | if(mdat == mtmp->data) return(0); |
861 | #ifndef NOWORM |
862 | if(mtmp->wormno) wormdead(mtmp); |
863 | #endif /* NOWORM */ |
864 | if (u.ustuck == mtmp) { |
865 | if (u.uswallow) { |
866 | u.uswallow = 0; |
867 | u.uswldtim = 0; |
868 | mnexto (mtmp); |
869 | docrt(); |
870 | prme(); |
871 | } |
872 | u.ustuck = 0; |
873 | } |
874 | hpn = mtmp->mhp; |
875 | hpd = (mtmp->data->mlevel)*8; |
876 | if(!hpd) hpd = 4; |
877 | mtmp->data = mdat; |
878 | mhp = (mdat->mlevel)*8; |
879 | |
880 | mtmp->mhp = 2 + (hpn*mhp)/hpd; |
881 | hpn = mtmp->mhpmax; |
882 | mtmp->mhpmax = 2 + (hpn*mhp)/hpd; |
883 | mtmp->minvis = (mdat->mlet == 'I') ? 1 : 0; |
884 | #ifndef NOWORM |
885 | if(mdat->mlet == 'w' && getwn(mtmp)) initworm(mtmp); |
886 | |
887 | #endif /* NOWORM */ |
888 | unpmon(mtmp); |
889 | pmon(mtmp); |
890 | return(1); |
891 | } |
892 | |
893 | |
894 | void |
895 | mnexto(struct monst *mtmp) |
896 | { |
897 | coord mm; |
898 | mm = enexto(u.ux, u.uy); |
899 | mtmp->mx = mm.x; |
900 | mtmp->my = mm.y; |
901 | pmon(mtmp); |
902 | } |
903 | |
904 | static int |
905 | ishuman(struct monst *mtmp) |
906 | { |
907 | return(mtmp->data->mlet == '@'); |
908 | } |
909 | |
910 | void |
911 | setmangry(struct monst *mtmp) |
912 | { |
913 | if(!mtmp->mpeaceful) return; |
914 | if(mtmp->mtame) return; |
915 | mtmp->mpeaceful = 0; |
916 | if(ishuman(mtmp)) pline("%s gets angry!", Monnam(mtmp)); |
917 | } |
918 | |
919 | |
920 | |
921 | int |
922 | canseemon(struct monst *mtmp) |
923 | { |
924 | return((!mtmp->minvis || See_invisible) |
925 | && (!mtmp->mhide || !o_at(mtmp->mx,mtmp->my)) |
926 | && cansee(mtmp->mx, mtmp->my)); |
927 | } |