clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hack.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.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 <stdio.h> |
| 65 | #ifdef QUEST |
| 66 | #include <stdlib.h> |
| 67 | #endif |
| 68 | |
| 69 | #include "hack.h" |
| 70 | |
| 71 | extern char *nomovemsg; |
| 72 | extern char *exclam(); |
| 73 | |
| 74 | static void movobj(struct obj *, int, int); |
| 75 | #ifdef QUEST |
| 76 | static int rroom(int, int); |
| 77 | #endif |
| 78 | static int inv_cnt(void); |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | void |
| 86 | unsee(void) |
| 87 | { |
| 88 | int x,y; |
| 89 | struct rm *lev; |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | #ifndef QUEST |
| 98 | if(seehx){ |
| 99 | seehx = 0; |
| 100 | } else |
| 101 | #endif /* QUEST */ |
| 102 | for(x = u.ux-1; x < u.ux+2; x++) |
| 103 | for(y = u.uy-1; y < u.uy+2; y++) { |
| 104 | if(!isok(x, y)) continue; |
| 105 | lev = &levl[x][y]; |
| 106 | if(!lev->lit && lev->scrsym == '.') { |
| 107 | lev->scrsym =' '; |
| 108 | lev->new = 1; |
| 109 | on_scr(x,y); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | void |
| 123 | seeoff(int mode) |
| 124 | { |
| 125 | int x,y; |
| 126 | struct rm *lev; |
| 127 | |
| 128 | if(u.udispl && mode){ |
| 129 | u.udispl = 0; |
| 130 | levl[(int)u.udisx][(int)u.udisy].scrsym = news0(u.udisx,u.udisy); |
| 131 | } |
| 132 | #ifndef QUEST |
| 133 | if(seehx) { |
| 134 | seehx = 0; |
| 135 | } else |
| 136 | #endif /* QUEST */ |
| 137 | if(!mode) { |
| 138 | for(x = u.ux-1; x < u.ux+2; x++) |
| 139 | for(y = u.uy-1; y < u.uy+2; y++) { |
| 140 | if(!isok(x, y)) continue; |
| 141 | lev = &levl[x][y]; |
| 142 | if(!lev->lit && lev->scrsym == '.') |
| 143 | lev->seen = 0; |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | void |
| 149 | domove(void) |
| 150 | { |
| 151 | xchar oldx,oldy; |
| 152 | struct monst *mtmp; |
| 153 | struct rm *tmpr,*ust; |
| 154 | struct trap *trap; |
| 155 | struct obj *otmp; |
| 156 | |
| 157 | u_wipe_engr(rnd(5)); |
| 158 | |
| 159 | if(inv_weight() > 0){ |
| 160 | pline("You collapse under your load."); |
| 161 | nomul(0); |
| 162 | return; |
| 163 | } |
| 164 | if(u.uswallow) { |
| 165 | u.dx = u.dy = 0; |
| 166 | u.ux = u.ustuck->mx; |
| 167 | u.uy = u.ustuck->my; |
| 168 | } else { |
| 169 | if(Confusion) { |
| 170 | do { |
| 171 | confdir(); |
| 172 | } while(!isok(u.ux+u.dx, u.uy+u.dy) || |
| 173 | IS_ROCK(levl[u.ux+u.dx][u.uy+u.dy].typ)); |
| 174 | } |
| 175 | if(!isok(u.ux+u.dx, u.uy+u.dy)){ |
| 176 | nomul(0); |
| 177 | return; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | ust = &levl[(int)u.ux][(int)u.uy]; |
| 182 | oldx = u.ux; |
| 183 | oldy = u.uy; |
| 184 | if(!u.uswallow && (trap = t_at(u.ux+u.dx, u.uy+u.dy)) && trap->tseen) |
| 185 | nomul(0); |
| 186 | if(u.ustuck && !u.uswallow && (u.ux+u.dx != u.ustuck->mx || |
| 187 | u.uy+u.dy != u.ustuck->my)) { |
| 188 | if(dist(u.ustuck->mx, u.ustuck->my) > 2){ |
| 189 | |
| 190 | u.ustuck = 0; |
| 191 | } else { |
| 192 | if(Blind) pline("You cannot escape from it!"); |
| 193 | else pline("You cannot escape from %s!", |
| 194 | monnam(u.ustuck)); |
| 195 | nomul(0); |
| 196 | return; |
| 197 | } |
| 198 | } |
| 199 | if(u.uswallow || (mtmp = m_at(u.ux+u.dx,u.uy+u.dy))) { |
| 200 | |
| 201 | |
| 202 | nomul(0); |
| 203 | gethungry(); |
| 204 | if(multi < 0) return; |
| 205 | |
| 206 | |
| 207 | if(attack(u.uswallow ? u.ustuck : mtmp)) |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | if(u.utrap) { |
| 212 | if(u.utraptype == TT_PIT) { |
| 213 | pline("You are still in a pit."); |
| 214 | u.utrap--; |
| 215 | } else { |
| 216 | pline("You are caught in a beartrap."); |
| 217 | if((u.dx && u.dy) || !rn2(5)) u.utrap--; |
| 218 | } |
| 219 | return; |
| 220 | } |
| 221 | tmpr = &levl[u.ux+u.dx][u.uy+u.dy]; |
| 222 | if(IS_ROCK(tmpr->typ) || |
| 223 | (u.dx && u.dy && (tmpr->typ == DOOR || ust->typ == DOOR))){ |
| 224 | flags.move = 0; |
| 225 | nomul(0); |
| 226 | return; |
| 227 | } |
| 228 | while ((otmp = sobj_at(ENORMOUS_ROCK, u.ux+u.dx, u.uy+u.dy))) { |
| 229 | xchar rx = u.ux+2*u.dx, ry = u.uy+2*u.dy; |
| 230 | struct trap *ttmp; |
| 231 | nomul(0); |
| 232 | if (isok(rx,ry) && !IS_ROCK(levl[(int)rx][(int)ry].typ) && |
| 233 | (levl[(int)rx][(int)ry].typ != DOOR || !(u.dx && u.dy)) && |
| 234 | !sobj_at(ENORMOUS_ROCK, rx, ry)) { |
| 235 | if(m_at(rx,ry)) { |
| 236 | pline("You hear a monster behind the rock."); |
| 237 | pline("Perhaps that's why you cannot move it."); |
| 238 | goto cannot_push; |
| 239 | } |
| 240 | if ((ttmp = t_at(rx,ry))) |
| 241 | switch(ttmp->ttyp) { |
| 242 | case PIT: |
| 243 | pline("You push the rock into a pit!"); |
| 244 | deltrap(ttmp); |
| 245 | delobj(otmp); |
| 246 | pline("It completely fills the pit!"); |
| 247 | continue; |
| 248 | case TELEP_TRAP: |
| 249 | pline("You push the rock and suddenly it disappears!"); |
| 250 | delobj(otmp); |
| 251 | continue; |
| 252 | } |
| 253 | if (levl[(int)rx][(int)ry].typ == POOL) { |
| 254 | levl[(int)rx][(int)ry].typ = ROOM; |
| 255 | mnewsym(rx,ry); |
| 256 | prl(rx,ry); |
| 257 | pline("You push the rock into the water."); |
| 258 | pline("Now you can cross the water!"); |
| 259 | delobj(otmp); |
| 260 | continue; |
| 261 | } |
| 262 | otmp->ox = rx; |
| 263 | otmp->oy = ry; |
| 264 | |
| 265 | if(cansee(rx,ry)) atl(rx,ry,otmp->olet); |
| 266 | if(Invisible) newsym(u.ux+u.dx, u.uy+u.dy); |
| 267 | |
| 268 | { static long lastmovetime; |
| 269 | |
| 270 | |
| 271 | if(moves > lastmovetime+2 || moves < lastmovetime) |
| 272 | pline("With great effort you move the enormous rock."); |
| 273 | lastmovetime = moves; |
| 274 | } |
| 275 | } else { |
| 276 | pline("You try to move the enormous rock, but in vain."); |
| 277 | cannot_push: |
| 278 | if((!invent || inv_weight()+90 <= 0) && |
| 279 | (!u.dx || !u.dy || (IS_ROCK(levl[(int)u.ux][u.uy+u.dy].typ) |
| 280 | && IS_ROCK(levl[u.ux+u.dx][(int)u.uy].typ)))){ |
| 281 | pline("However, you can squeeze yourself into a small opening."); |
| 282 | break; |
| 283 | } else |
| 284 | return; |
| 285 | } |
| 286 | } |
| 287 | if(u.dx && u.dy && IS_ROCK(levl[(int)u.ux][u.uy+u.dy].typ) && |
| 288 | IS_ROCK(levl[u.ux+u.dx][(int)u.uy].typ) && |
| 289 | invent && inv_weight()+40 > 0) { |
| 290 | pline("You are carrying too much to get through."); |
| 291 | nomul(0); |
| 292 | return; |
| 293 | } |
| 294 | if(Punished && |
| 295 | DIST(u.ux+u.dx, u.uy+u.dy, uchain->ox, uchain->oy) > 2){ |
| 296 | if(carried(uball)) { |
| 297 | movobj(uchain, u.ux, u.uy); |
| 298 | goto nodrag; |
| 299 | } |
| 300 | |
| 301 | if(DIST(u.ux+u.dx, u.uy+u.dy, uball->ox, uball->oy) < 3){ |
| 302 | |
| 303 | movobj(uchain, uball->ox, uball->oy); |
| 304 | goto nodrag; |
| 305 | } |
| 306 | |
| 307 | if(inv_weight() + (int) uball->owt/2 > 0) { |
| 308 | pline("You cannot %sdrag the heavy iron ball.", |
| 309 | invent ? "carry all that and also " : ""); |
| 310 | nomul(0); |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | movobj(uball, uchain->ox, uchain->oy); |
| 315 | unpobj(uball); |
| 316 | uchain->ox = u.ux; |
| 317 | uchain->oy = u.uy; |
| 318 | nomul(-2); |
| 319 | nomovemsg = ""; |
| 320 | nodrag: ; |
| 321 | } |
| 322 | u.ux += u.dx; |
| 323 | u.uy += u.dy; |
| 324 | if(flags.run) { |
| 325 | if(tmpr->typ == DOOR || |
| 326 | (xupstair == u.ux && yupstair == u.uy) || |
| 327 | (xdnstair == u.ux && ydnstair == u.uy)) |
| 328 | nomul(0); |
| 329 | } |
| 330 | |
| 331 | if(tmpr->typ == POOL && !Levitation) |
| 332 | drown(); |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | if(!Blind) { |
| 341 | #ifdef QUEST |
| 342 | setsee(); |
| 343 | #else |
| 344 | if(ust->lit) { |
| 345 | if(tmpr->lit) { |
| 346 | if(tmpr->typ == DOOR) |
| 347 | prl1(u.ux+u.dx,u.uy+u.dy); |
| 348 | else if(ust->typ == DOOR) |
| 349 | nose1(oldx-u.dx,oldy-u.dy); |
| 350 | } else { |
| 351 | unsee(); |
| 352 | prl1(u.ux+u.dx,u.uy+u.dy); |
| 353 | } |
| 354 | } else { |
| 355 | if(tmpr->lit) setsee(); |
| 356 | else { |
| 357 | prl1(u.ux+u.dx,u.uy+u.dy); |
| 358 | if(tmpr->typ == DOOR) { |
| 359 | if(u.dy) { |
| 360 | prl(u.ux-1,u.uy); |
| 361 | prl(u.ux+1,u.uy); |
| 362 | } else { |
| 363 | prl(u.ux,u.uy-1); |
| 364 | prl(u.ux,u.uy+1); |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | nose1(oldx-u.dx,oldy-u.dy); |
| 369 | } |
| 370 | #endif /* QUEST */ |
| 371 | } else { |
| 372 | pru(); |
| 373 | } |
| 374 | if(!flags.nopick) pickup(1); |
| 375 | if(trap) dotrap(trap); |
| 376 | (void) inshop(); |
| 377 | if(!Blind) read_engr_at(u.ux,u.uy); |
| 378 | } |
| 379 | |
| 380 | static void |
| 381 | movobj(struct obj *obj, int ox, int oy) |
| 382 | { |
| 383 | |
| 384 | freeobj(obj); |
| 385 | unpobj(obj); |
| 386 | obj->nobj = fobj; |
| 387 | fobj = obj; |
| 388 | obj->ox = ox; |
| 389 | obj->oy = oy; |
| 390 | } |
| 391 | |
| 392 | int |
| 393 | dopickup(void) |
| 394 | { |
| 395 | if(!g_at(u.ux,u.uy) && !o_at(u.ux,u.uy)) { |
| 396 | pline("There is nothing here to pick up."); |
| 397 | return(0); |
| 398 | } |
| 399 | if(Levitation) { |
| 400 | pline("You cannot reach the floor."); |
| 401 | return(1); |
| 402 | } |
| 403 | pickup(0); |
| 404 | return(1); |
| 405 | } |
| 406 | |
| 407 | void |
| 408 | pickup(int all) |
| 409 | { |
| 410 | struct gold *gold; |
| 411 | struct obj *obj, *obj2; |
| 412 | int wt; |
| 413 | |
| 414 | if (Levitation) |
| 415 | return; |
| 416 | while ((gold = g_at(u.ux,u.uy))) { |
| 417 | pline("%ld gold piece%s.", gold->amount, plur(gold->amount)); |
| 418 | u.ugold += gold->amount; |
| 419 | flags.botl = 1; |
| 420 | freegold(gold); |
| 421 | if(flags.run) nomul(0); |
| 422 | if(Invisible) newsym(u.ux,u.uy); |
| 423 | } |
| 424 | |
| 425 | |
| 426 | if(!all) { |
| 427 | int ct = 0; |
| 428 | |
| 429 | for(obj = fobj; obj; obj = obj->nobj) |
| 430 | if(obj->ox == u.ux && obj->oy == u.uy) |
| 431 | if(!Punished || obj != uchain) |
| 432 | ct++; |
| 433 | if(ct < 2) |
| 434 | all++; |
| 435 | else |
| 436 | pline("There are several objects here."); |
| 437 | } |
| 438 | |
| 439 | for(obj = fobj; obj; obj = obj2) { |
| 440 | obj2 = obj->nobj; |
| 441 | if(obj->ox == u.ux && obj->oy == u.uy) { |
| 442 | if(flags.run) nomul(0); |
| 443 | |
| 444 | |
| 445 | if(Punished && obj == uchain) |
| 446 | continue; |
| 447 | |
| 448 | if(!all) { |
| 449 | char c; |
| 450 | |
| 451 | pline("Pick up %s ? [ynaq]", doname(obj)); |
| 452 | while(!strchr("ynaq ", (c = readchar()))) |
| 453 | hackbell(); |
| 454 | if(c == 'q') return; |
| 455 | if(c == 'n') continue; |
| 456 | if(c == 'a') all = 1; |
| 457 | } |
| 458 | |
| 459 | if(obj->otyp == DEAD_COCKATRICE && !uarmg){ |
| 460 | pline("Touching the dead cockatrice is a fatal mistake."); |
| 461 | pline("You turn to stone."); |
| 462 | killer = "cockatrice cadaver"; |
| 463 | done("died"); |
| 464 | } |
| 465 | |
| 466 | if(obj->otyp == SCR_SCARE_MONSTER){ |
| 467 | if(!obj->spe) obj->spe = 1; |
| 468 | else { |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | pline("The scroll turns to dust as you pick it up."); |
| 474 | delobj(obj); |
| 475 | continue; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | wt = inv_weight() + obj->owt; |
| 480 | if(wt > 0) { |
| 481 | if(obj->quan > 1) { |
| 482 | |
| 483 | int savequan = obj->quan; |
| 484 | int iw = inv_weight(); |
| 485 | int qq; |
| 486 | for(qq = 1; qq < savequan; qq++){ |
| 487 | obj->quan = qq; |
| 488 | if(iw + weight(obj) > 0) |
| 489 | break; |
| 490 | } |
| 491 | obj->quan = savequan; |
| 492 | qq--; |
| 493 | |
| 494 | if(!qq) goto too_heavy; |
| 495 | pline("You can only carry %s of the %s lying here.", |
| 496 | (qq == 1) ? "one" : "some", |
| 497 | doname(obj)); |
| 498 | (void) splitobj(obj, qq); |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | goto lift_some; |
| 505 | } |
| 506 | too_heavy: |
| 507 | pline("There %s %s here, but %s.", |
| 508 | (obj->quan == 1) ? "is" : "are", |
| 509 | doname(obj), |
| 510 | !invent ? "it is too heavy for you to lift" |
| 511 | : "you cannot carry anymore"); |
| 512 | break; |
| 513 | } |
| 514 | lift_some: |
| 515 | if(inv_cnt() >= 52) { |
| 516 | pline("Your knapsack cannot accommodate anymore items."); |
| 517 | break; |
| 518 | } |
| 519 | if(wt > -5) pline("You have a little trouble lifting"); |
| 520 | freeobj(obj); |
| 521 | if(Invisible) newsym(u.ux,u.uy); |
| 522 | addtobill(obj); |
| 523 | { int pickquan = obj->quan; |
| 524 | int mergquan; |
| 525 | if(!Blind) obj->dknown = 1; |
| 526 | |
| 527 | obj = addinv(obj); |
| 528 | mergquan = obj->quan; |
| 529 | obj->quan = pickquan; |
| 530 | prinv(obj); |
| 531 | obj->quan = mergquan; |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | void |
| 541 | lookaround(void) |
| 542 | { |
| 543 | int x, y, i, x0, y0, m0, i0 = 9; |
| 1 | 'm0' declared without an initial value | |
|
| 544 | int corrct = 0, noturn = 0; |
| 545 | struct monst *mtmp; |
| 546 | |
| 547 | if (Blind || flags.run == 0) return; |
| 2 | | Assuming field 'p_flgs' is 0 | |
|
| 3 | | Assuming field 'run' is not equal to 0 | |
|
| |
| 548 | if (flags.run == 1 && levl[(int)u.ux][(int)u.uy].typ == ROOM) |
| 5 | | Assuming field 'run' is not equal to 1 | |
|
| 549 | return; |
| 550 | #ifdef QUEST |
| 551 | if(u.ux0 == u.ux+u.dx && u.uy0 == u.uy+u.dy) goto stop; |
| 552 | #endif /* QUEST */ |
| 553 | for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++){ |
| 6 | | Assuming the condition is false | |
|
| 7 | | Loop condition is false. Execution continues on line 603 | |
|
| 554 | if(x == u.ux && y == u.uy) continue; |
| 555 | if(!levl[x][y].typ) continue; |
| 556 | if((mtmp = m_at(x,y)) && !mtmp->mimic && |
| 557 | (!mtmp->minvis || See_invisible)){ |
| 558 | if(!mtmp->mtame || (x == u.ux+u.dx && y == u.uy+u.dy)) |
| 559 | goto stop; |
| 560 | } else mtmp = 0; |
| 561 | if(x == u.ux-u.dx && y == u.uy-u.dy) continue; |
| 562 | switch(levl[x][y].scrsym){ |
| 563 | case '|': |
| 564 | case '-': |
| 565 | case '.': |
| 566 | case ' ': |
| 567 | break; |
| 568 | case '+': |
| 569 | if(x != u.ux && y != u.uy) break; |
| 570 | if(flags.run != 1) goto stop; |
| 571 | |
| 572 | case CORR_SYM: |
| 573 | corr: |
| 574 | if(flags.run == 1 || flags.run == 3) { |
| 575 | i = DIST(x,y,u.ux+u.dx,u.uy+u.dy); |
| 576 | if(i > 2) break; |
| 577 | if(corrct == 1 && DIST(x,y,x0,y0) != 1) |
| 578 | noturn = 1; |
| 579 | if(i < i0) { |
| 580 | i0 = i; |
| 581 | x0 = x; |
| 582 | y0 = y; |
| 583 | m0 = mtmp ? 1 : 0; |
| 584 | } |
| 585 | } |
| 586 | corrct++; |
| 587 | break; |
| 588 | case '^': |
| 589 | if(flags.run == 1) goto corr; |
| 590 | if(x == u.ux+u.dx && y == u.uy+u.dy) goto stop; |
| 591 | break; |
| 592 | default: |
| 593 | if(flags.run == 1) goto corr; |
| 594 | if(mtmp) break; |
| 595 | stop: |
| 596 | nomul(0); |
| 597 | return; |
| 598 | } |
| 599 | } |
| 600 | #ifdef QUEST |
| 601 | if(corrct > 0 && (flags.run == 4 || flags.run == 5)) goto stop; |
| 602 | #endif /* QUEST */ |
| 603 | if(corrct > 1 && flags.run == 2) goto stop; |
| 604 | if((flags.run == 1 || flags.run == 3) && !noturn && !m0 && i0 && |
| 8 | | Assuming field 'run' is equal to 3 | |
|
| 9 | | Branch condition evaluates to a garbage value |
|
| 605 | (corrct == 1 || (corrct == 2 && i0 == 1))) { |
| 606 | |
| 607 | if(i0 == 2) { |
| 608 | if(u.dx == y0-u.uy && u.dy == u.ux-x0) |
| 609 | i = 2; |
| 610 | else |
| 611 | i = -2; |
| 612 | } else if(u.dx && u.dy) { |
| 613 | if((u.dx == u.dy && y0 == u.uy) || |
| 614 | (u.dx != u.dy && y0 != u.uy)) |
| 615 | i = -1; |
| 616 | else |
| 617 | i = 1; |
| 618 | } else { |
| 619 | if((x0-u.ux == y0-u.uy && !u.dy) || |
| 620 | (x0-u.ux != y0-u.uy && u.dy)) |
| 621 | i = 1; |
| 622 | else |
| 623 | i = -1; |
| 624 | } |
| 625 | i += u.last_str_turn; |
| 626 | if(i <= 2 && i >= -2) { |
| 627 | u.last_str_turn = i; |
| 628 | u.dx = x0-u.ux, u.dy = y0-u.uy; |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | |
| 634 | |
| 635 | int |
| 636 | monster_nearby(void) |
| 637 | { |
| 638 | int x,y; |
| 639 | struct monst *mtmp; |
| 640 | |
| 641 | if(!Blind) |
| 642 | for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++){ |
| 643 | if(x == u.ux && y == u.uy) continue; |
| 644 | if((mtmp = m_at(x,y)) && !mtmp->mimic && !mtmp->mtame && |
| 645 | !mtmp->mpeaceful && !strchr("Ea", mtmp->data->mlet) && |
| 646 | !mtmp->mfroz && !mtmp->msleep && |
| 647 | (!mtmp->minvis || See_invisible)) |
| 648 | return(1); |
| 649 | } |
| 650 | return(0); |
| 651 | } |
| 652 | |
| 653 | #ifdef QUEST |
| 654 | int |
| 655 | cansee(xchar x, xchar y) |
| 656 | { |
| 657 | int dx,dy,adx,ady,sdx,sdy,dmax,d; |
| 658 | |
| 659 | if(Blind) return(0); |
| 660 | if(!isok(x,y)) return(0); |
| 661 | d = dist(x,y); |
| 662 | if(d < 3) return(1); |
| 663 | if(d > u.uhorizon*u.uhorizon) return(0); |
| 664 | if(!levl[x][y].lit) |
| 665 | return(0); |
| 666 | dx = x - u.ux; adx = abs(dx); sdx = sgn(dx); |
| 667 | dy = y - u.uy; ady = abs(dy); sdy = sgn(dy); |
| 668 | if(dx == 0 || dy == 0 || adx == ady){ |
| 669 | dmax = (dx == 0) ? ady : adx; |
| 670 | for(d = 1; d <= dmax; d++) |
| 671 | if(!rroom(sdx*d,sdy*d)) |
| 672 | return(0); |
| 673 | return(1); |
| 674 | } else if(ady > adx){ |
| 675 | for(d = 1; d <= ady; d++){ |
| 676 | if(!rroom(sdx*( (d*adx)/ady ), sdy*d) || |
| 677 | !rroom(sdx*( (d*adx-1)/ady+1 ), sdy*d)) |
| 678 | return(0); |
| 679 | } |
| 680 | return(1); |
| 681 | } else { |
| 682 | for(d = 1; d <= adx; d++){ |
| 683 | if(!rroom(sdx*d, sdy*( (d*ady)/adx )) || |
| 684 | !rroom(sdx*d, sdy*( (d*ady-1)/adx+1 ))) |
| 685 | return(0); |
| 686 | } |
| 687 | return(1); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | static int |
| 692 | rroom(int x, int y) |
| 693 | { |
| 694 | return(IS_ROOM(levl[u.ux+x][u.uy+y].typ)); |
| 695 | } |
| 696 | |
| 697 | #else |
| 698 | |
| 699 | int |
| 700 | cansee(xchar x, xchar y) |
| 701 | { |
| 702 | if (Blind || u.uswallow) |
| 703 | return(0); |
| 704 | if (dist(x,y) < 3) |
| 705 | return(1); |
| 706 | if (levl[(int)x][(int)y].lit && seelx <= x && x <= seehx && |
| 707 | seely <= y && y <= seehy) |
| 708 | return(1); |
| 709 | return(0); |
| 710 | } |
| 711 | #endif /* QUEST */ |
| 712 | |
| 713 | int |
| 714 | sgn(int a) |
| 715 | { |
| 716 | return((a > 0) ? 1 : (a == 0) ? 0 : -1); |
| 717 | } |
| 718 | |
| 719 | #ifdef QUEST |
| 720 | void |
| 721 | setsee(void) |
| 722 | { |
| 723 | int x,y; |
| 724 | |
| 725 | if(Blind) { |
| 726 | pru(); |
| 727 | return; |
| 728 | } |
| 729 | for(y = u.uy-u.uhorizon; y <= u.uy+u.uhorizon; y++) |
| 730 | for(x = u.ux-u.uhorizon; x <= u.ux+u.uhorizon; x++) { |
| 731 | if(cansee(x,y)) |
| 732 | prl(x,y); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | #else |
| 737 | void |
| 738 | setsee(void) |
| 739 | { |
| 740 | int x,y; |
| 741 | |
| 742 | if (Blind) { |
| 743 | pru(); |
| 744 | return; |
| 745 | } |
| 746 | if (!levl[(int)u.ux][(int)u.uy].lit) { |
| 747 | seelx = u.ux-1; |
| 748 | seehx = u.ux+1; |
| 749 | seely = u.uy-1; |
| 750 | seehy = u.uy+1; |
| 751 | } else { |
| 752 | for(seelx = u.ux; levl[seelx-1][(int)u.uy].lit; seelx--); |
| 753 | for(seehx = u.ux; levl[seehx+1][(int)u.uy].lit; seehx++); |
| 754 | for(seely = u.uy; levl[(int)u.ux][seely-1].lit; seely--); |
| 755 | for(seehy = u.uy; levl[(int)u.ux][seehy+1].lit; seehy++); |
| 756 | } |
| 757 | for (y = seely; y <= seehy; y++) |
| 758 | for (x = seelx; x <= seehx; x++) { |
| 759 | prl(x,y); |
| 760 | } |
| 761 | if (!levl[(int)u.ux][(int)u.uy].lit) |
| 762 | seehx = 0; |
| 763 | else { |
| 764 | if(seely == u.uy) for(x = u.ux-1; x <= u.ux+1; x++) prl(x,seely-1); |
| 765 | if(seehy == u.uy) for(x = u.ux-1; x <= u.ux+1; x++) prl(x,seehy+1); |
| 766 | if(seelx == u.ux) for(y = u.uy-1; y <= u.uy+1; y++) prl(seelx-1,y); |
| 767 | if(seehx == u.ux) for(y = u.uy-1; y <= u.uy+1; y++) prl(seehx+1,y); |
| 768 | } |
| 769 | } |
| 770 | #endif /* QUEST */ |
| 771 | |
| 772 | void |
| 773 | nomul(int nval) |
| 774 | { |
| 775 | if(multi < 0) return; |
| 776 | multi = nval; |
| 777 | flags.mv = flags.run = 0; |
| 778 | } |
| 779 | |
| 780 | int |
| 781 | abon(void) |
| 782 | { |
| 783 | if(u.ustr == 3) return(-3); |
| 784 | else if(u.ustr < 6) return(-2); |
| 785 | else if(u.ustr < 8) return(-1); |
| 786 | else if(u.ustr < 17) return(0); |
| 787 | else if(u.ustr < 69) return(1); |
| 788 | else if(u.ustr < 118) return(2); |
| 789 | else return(3); |
| 790 | } |
| 791 | |
| 792 | int |
| 793 | dbon(void) |
| 794 | { |
| 795 | if(u.ustr < 6) return(-1); |
| 796 | else if(u.ustr < 16) return(0); |
| 797 | else if(u.ustr < 18) return(1); |
| 798 | else if(u.ustr == 18) return(2); |
| 799 | else if(u.ustr < 94) return(3); |
| 800 | else if(u.ustr < 109) return(4); |
| 801 | else if(u.ustr < 118) return(5); |
| 802 | else return(6); |
| 803 | } |
| 804 | |
| 805 | void |
| 806 | losestr(int num) |
| 807 | { |
| 808 | u.ustr -= num; |
| 809 | while(u.ustr < 3) { |
| 810 | u.ustr++; |
| 811 | u.uhp -= 6; |
| 812 | u.uhpmax -= 6; |
| 813 | } |
| 814 | flags.botl = 1; |
| 815 | } |
| 816 | |
| 817 | void |
| 818 | losehp(int n, char *knam) |
| 819 | { |
| 820 | u.uhp -= n; |
| 821 | if(u.uhp > u.uhpmax) |
| 822 | u.uhpmax = u.uhp; |
| 823 | flags.botl = 1; |
| 824 | if(u.uhp < 1) { |
| 825 | killer = knam; |
| 826 | done("died"); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | void |
| 831 | losehp_m(int n, struct monst *mtmp) |
| 832 | { |
| 833 | u.uhp -= n; |
| 834 | flags.botl = 1; |
| 835 | if(u.uhp < 1) |
| 836 | done_in_by(mtmp); |
| 837 | } |
| 838 | |
| 839 | |
| 840 | void |
| 841 | losexp(void) |
| 842 | { |
| 843 | int num; |
| 844 | |
| 845 | if(u.ulevel > 1) |
| 846 | pline("Goodbye level %u.", u.ulevel--); |
| 847 | else |
| 848 | u.uhp = -1; |
| 849 | num = rnd(10); |
| 850 | u.uhp -= num; |
| 851 | u.uhpmax -= num; |
| 852 | u.uexp = newuexp(); |
| 853 | flags.botl = 1; |
| 854 | } |
| 855 | |
| 856 | int |
| 857 | inv_weight(void) |
| 858 | { |
| 859 | struct obj *otmp = invent; |
| 860 | int wt = (u.ugold + 500)/1000; |
| 861 | int carrcap; |
| 862 | |
| 863 | if(Levitation) |
| 864 | carrcap = MAX_CARR_CAP; |
| 865 | else { |
| 866 | carrcap = 5*(((u.ustr > 18) ? 20 : u.ustr) + u.ulevel); |
| 867 | if(carrcap > MAX_CARR_CAP) carrcap = MAX_CARR_CAP; |
| 868 | if(Wounded_legs & LEFT_SIDE) carrcap -= 10; |
| 869 | if(Wounded_legs & RIGHT_SIDE) carrcap -= 10; |
| 870 | } |
| 871 | while(otmp){ |
| 872 | wt += otmp->owt; |
| 873 | otmp = otmp->nobj; |
| 874 | } |
| 875 | return(wt - carrcap); |
| 876 | } |
| 877 | |
| 878 | static int |
| 879 | inv_cnt(void) |
| 880 | { |
| 881 | struct obj *otmp = invent; |
| 882 | int ct = 0; |
| 883 | |
| 884 | while(otmp){ |
| 885 | ct++; |
| 886 | otmp = otmp->nobj; |
| 887 | } |
| 888 | return(ct); |
| 889 | } |
| 890 | |
| 891 | long |
| 892 | newuexp(void) |
| 893 | { |
| 894 | return(10*(1L << (u.ulevel-1))); |
| 895 | } |