* Move for priests and shopkeepers. Called from shk_move() and pri_move(). * Valid returns are 1: moved 0: didn't -1: let m_move do it -2: died. */
| 39 | * Valid returns are 1: moved 0: didn't -1: let m_move do it -2: died. |
| 40 | */ |
| 41 | int |
| 42 | move_special(struct monst *mtmp, boolean in_his_shop, schar appr, |
| 43 | boolean uondoor, boolean avoid, |
| 44 | coordxy omx, coordxy omy, coordxy ggx, coordxy ggy) |
| 45 | { |
| 46 | coordxy nx, ny, nix, niy; |
| 47 | schar i; |
| 48 | schar chcnt, cnt; |
| 49 | struct mfndposdata mfp; |
| 50 | long ninfo = 0; |
| 51 | long allowflags; |
| 52 | #if 0 /* dead code; see below */ |
| 53 | struct obj *ib = (struct obj *) 0; |
| 54 | #endif |
| 55 | |
| 56 | if (omx == ggx && omy == ggy) |
| 57 | return 0; |
| 58 | if (mtmp->mconf) { |
| 59 | avoid = FALSE; |
| 60 | appr = 0; |
| 61 | } |
| 62 | |
| 63 | nix = omx; |
| 64 | niy = omy; |
| 65 | allowflags = mon_allowflags(mtmp); |
| 66 | cnt = mfndpos(mtmp, &mfp, allowflags); |
| 67 | |
| 68 | if (mtmp->isshk && avoid && uondoor) { /* perhaps we cannot avoid him */ |
| 69 | for (i = 0; i < cnt; i++) |
| 70 | if (!(mfp.info[i] & NOTONL)) |
| 71 | goto pick_move; |
| 72 | avoid = FALSE; |
| 73 | } |
| 74 | |
| 75 | #define GDIST(x, y) (dist2(x, y, ggx, ggy)) |
| 76 | pick_move: |
| 77 | chcnt = 0; |
| 78 | for (i = 0; i < cnt; i++) { |
| 79 | nx = mfp.poss[i].x; |
| 80 | ny = mfp.poss[i].y; |
| 81 | if (IS_ROOM(levl[nx][ny].typ) |
| 82 | || (mtmp->isshk && (!in_his_shop || ESHK(mtmp)->following))) { |
| 83 | if (avoid && (mfp.info[i] & NOTONL) && !(mfp.info[i] & ALLOW_M)) |
| 84 | continue; |
| 85 | if ((!appr && !rn2(++chcnt)) |
| 86 | || (appr && GDIST(nx, ny) < GDIST(nix, niy)) |
| 87 | || (mfp.info[i] & ALLOW_M)) { |
| 88 | nix = nx; |
| 89 | niy = ny; |
| 90 | ninfo = mfp.info[i]; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | #undef GDIST |
| 95 | if (mtmp->ispriest && avoid && nix == omx && niy == omy |
| 96 | && onlineu(omx, omy)) { |
| 97 | /* might as well move closer as long it's going to stay |
| 98 | * lined up */ |
no test coverage detected