| 530 | } |
| 531 | |
| 532 | staticfn void |
| 533 | distfleeck( |
| 534 | struct monst *mtmp, |
| 535 | int *inrange, int *nearby, int *scared) /* output */ |
| 536 | { |
| 537 | int seescaryx, seescaryy; |
| 538 | boolean sawscary = FALSE, bravegremlin = (rn2(5) == 0); |
| 539 | |
| 540 | *inrange = (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) |
| 541 | <= (BOLT_LIM * BOLT_LIM)); |
| 542 | *nearby = *inrange && monnear(mtmp, mtmp->mux, mtmp->muy); |
| 543 | |
| 544 | /* Note: if your image is displaced, the monster sees the Elbereth |
| 545 | * at your displaced position, thus never attacking your displaced |
| 546 | * position, but possibly attacking you by accident. If you are |
| 547 | * invisible, it sees the Elbereth at your real position, thus never |
| 548 | * running into you by accident but possibly attacking the spot |
| 549 | * where it guesses you are. |
| 550 | */ |
| 551 | if (!mtmp->mcansee || (Invis && !perceives(mtmp->data))) { |
| 552 | seescaryx = mtmp->mux; |
| 553 | seescaryy = mtmp->muy; |
| 554 | } else { |
| 555 | seescaryx = u.ux; |
| 556 | seescaryy = u.uy; |
| 557 | } |
| 558 | |
| 559 | sawscary = onscary(seescaryx, seescaryy, mtmp); |
| 560 | if (*nearby && (sawscary |
| 561 | || (flees_light(mtmp) && !bravegremlin) |
| 562 | || (!mtmp->mpeaceful && in_your_sanctuary(mtmp, 0, 0)))) { |
| 563 | *scared = 1; |
| 564 | monflee(mtmp, rnd(rn2(7) ? 10 : 100), TRUE, TRUE); |
| 565 | } else |
| 566 | *scared = 0; |
| 567 | } |
| 568 | |
| 569 | #undef flees_light |
| 570 | |