MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / validThrowRange

Method validThrowRange

src/Battlescape/ProjectileFlyBState.cpp:607–627  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

605 * @return True when the range is valid.
606 */
607bool 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.

Callers

nothing calls this directly

Calls 6

getTerrainLevelMethod · 0.45
getWeightMethod · 0.45
getRulesMethod · 0.45
getAmmoItemMethod · 0.45
getStatsMethod · 0.45
getPositionMethod · 0.45

Tested by

no test coverage detected