* Validates the throwing range. * @param action Pointer to throw action. * @param origin Position to throw from. * @param target Tile to throw to. * @return True when the range is valid. */
| 605 | * @return True when the range is valid. |
| 606 | */ |
| 607 | bool ProjectileFlyBState::validThrowRange(BattleAction *action, Position origin, Tile *target) |
| 608 | { |
| 609 | // note that all coordinates and thus also distances below are in number of tiles (not in voxels). |
| 610 | if (action->type != BA_THROW) |
| 611 | { |
| 612 | return true; |
| 613 | } |
| 614 | int offset = 2; |
| 615 | int zd = (origin.z)-((action->target.z * 24 + offset) - target->getTerrainLevel()); |
| 616 | int weight = action->weapon->getRules()->getWeight(); |
| 617 | if (action->weapon->getAmmoItem() && action->weapon->getAmmoItem() != action->weapon) |
| 618 | { |
| 619 | weight += action->weapon->getAmmoItem()->getRules()->getWeight(); |
| 620 | } |
| 621 | double maxDistance = (getMaxThrowDistance(weight, action->actor->getStats()->strength, zd) + 8) / 16.0; |
| 622 | int xdiff = action->target.x - action->actor->getPosition().x; |
| 623 | int ydiff = action->target.y - action->actor->getPosition().y; |
| 624 | double realDistance = sqrt((double)(xdiff*xdiff)+(double)(ydiff*ydiff)); |
| 625 | |
| 626 | return realDistance <= maxDistance; |
| 627 | } |
| 628 | |
| 629 | /** |
| 630 | * Validates the throwing range. |
nothing calls this directly
no test coverage detected