Distance attacks by pole-weapons */
| 3423 | |
| 3424 | /* Distance attacks by pole-weapons */ |
| 3425 | int |
| 3426 | use_pole(struct obj *obj, boolean autohit) |
| 3427 | { |
| 3428 | const char thump[] = "Thump! Your blow bounces harmlessly off the %s."; |
| 3429 | int res = ECMD_OK, max_range, min_range, glyph; |
| 3430 | coord cc; |
| 3431 | struct monst *mtmp; |
| 3432 | struct monst *hitm = svc.context.polearm.hitmon; |
| 3433 | boolean freehit = FALSE; |
| 3434 | |
| 3435 | /* Are you allowed to use the pole? */ |
| 3436 | if (u.uswallow) { |
| 3437 | pline(not_enough_room); |
| 3438 | return ECMD_OK; |
| 3439 | } |
| 3440 | if (obj != uwep) { |
| 3441 | if (wield_tool(obj, "swing")) { |
| 3442 | cmdq_add_ec(CQ_CANNED, doapply); |
| 3443 | cmdq_add_key(CQ_CANNED, obj->invlet); |
| 3444 | return ECMD_TIME; |
| 3445 | } |
| 3446 | return ECMD_OK; |
| 3447 | } |
| 3448 | /* assert(obj == uwep); */ |
| 3449 | |
| 3450 | calc_pole_range(&min_range, &max_range); |
| 3451 | |
| 3452 | /* Prompt for a location */ |
| 3453 | if (!autohit) |
| 3454 | pline(where_to_hit); |
| 3455 | cc.x = u.ux; |
| 3456 | cc.y = u.uy; |
| 3457 | if (!find_poleable_mon(&cc) && hitm |
| 3458 | && !DEADMONSTER(hitm) && sensemon(hitm) |
| 3459 | && mdistu(hitm) <= max_range && mdistu(hitm) >= min_range) { |
| 3460 | cc.x = hitm->mx; |
| 3461 | cc.y = hitm->my; |
| 3462 | } |
| 3463 | if (!autohit) { |
| 3464 | getpos_sethilite(display_polearm_positions, |
| 3465 | get_valid_polearm_position); |
| 3466 | if (getpos(&cc, TRUE, "the spot to hit") < 0) |
| 3467 | /* ESC; uses turn iff polearm became wielded */ |
| 3468 | return (res | ECMD_CANCEL); |
| 3469 | } |
| 3470 | |
| 3471 | glyph = glyph_at(cc.x, cc.y); |
| 3472 | if (distu(cc.x, cc.y) > max_range) { |
| 3473 | pline("Too far!"); |
| 3474 | return ECMD_FAIL; |
| 3475 | } else if (distu(cc.x, cc.y) < min_range) { |
| 3476 | if (autohit && u_at(cc.x, cc.y)) |
| 3477 | pline("Don't know what to hit."); |
| 3478 | else |
| 3479 | pline("Too close!"); |
| 3480 | return ECMD_FAIL; |
| 3481 | } else if (!cansee(cc.x, cc.y) && !glyph_is_poleable(glyph)) { |
| 3482 | You(cant_see_spot); |
no test coverage detected