find pos of monster in range, if only one monster */
| 3281 | |
| 3282 | /* find pos of monster in range, if only one monster */ |
| 3283 | staticfn boolean |
| 3284 | find_poleable_mon(coord *pos) |
| 3285 | { |
| 3286 | struct monst *mtmp; |
| 3287 | coord mpos = { 0, 0 }; /* no candidate location yet */ |
| 3288 | boolean impaired; |
| 3289 | coordxy x, y, lo_x, hi_x, lo_y, hi_y, rt; |
| 3290 | int glyph; |
| 3291 | |
| 3292 | impaired = (Confusion || Stunned || Hallucination); |
| 3293 | rt = isqrt(gp.polearm_range_max); |
| 3294 | lo_x = max(u.ux - rt, 1), hi_x = min(u.ux + rt, COLNO - 1); |
| 3295 | lo_y = max(u.uy - rt, 0), hi_y = min(u.uy + rt, ROWNO - 1); |
| 3296 | for (x = lo_x; x <= hi_x; ++x) { |
| 3297 | for (y = lo_y; y <= hi_y; ++y) { |
| 3298 | if (!get_valid_polearm_position(x, y)) |
| 3299 | continue; |
| 3300 | glyph = glyph_at(x, y); |
| 3301 | if (!impaired |
| 3302 | && glyph_is_monster(glyph) |
| 3303 | && (mtmp = m_at(x, y)) != 0 |
| 3304 | && (mtmp->mtame || (mtmp->mpeaceful && flags.confirm))) |
| 3305 | continue; |
| 3306 | if (glyph_is_poleable(glyph) |
| 3307 | && (!glyph_is_statue(glyph) || impaired)) { |
| 3308 | if (mpos.x) |
| 3309 | return FALSE; /* more than one candidate location */ |
| 3310 | mpos.x = x, mpos.y = y; |
| 3311 | } |
| 3312 | } |
| 3313 | } |
| 3314 | if (!mpos.x) |
| 3315 | return FALSE; /* no candidate location */ |
| 3316 | *pos = mpos; |
| 3317 | return TRUE; |
| 3318 | } |
| 3319 | |
| 3320 | staticfn boolean |
| 3321 | get_valid_polearm_position(coordxy x, coordxy y) |
no test coverage detected