* Validates a throw action. * @param action The action to validate. * @param originVoxel The origin point of the action. * @param targetVoxel The target point of the action. * @param curve The curvature of the throw. * @param voxelType The type of voxel at which this parabola terminates. * @return Validity of action. */
| 2675 | * @return Validity of action. |
| 2676 | */ |
| 2677 | bool TileEngine::validateThrow(BattleAction &action, Position originVoxel, Position targetVoxel, double *curve, int *voxelType) |
| 2678 | { |
| 2679 | bool foundCurve = false; |
| 2680 | double curvature = 0.5; |
| 2681 | if (action.type == BA_THROW) |
| 2682 | { |
| 2683 | curvature = std::max(0.48, 1.73 / sqrt(sqrt((double)(action.actor->getStats()->strength) / (double)(action.weapon->getRules()->getWeight()))) + (action.actor->isKneeled()? 0.1 : 0.0)); |
| 2684 | } |
| 2685 | Tile *targetTile = _save->getTile(action.target); |
| 2686 | // object blocking - can't throw here |
| 2687 | if ((action.type == BA_THROW |
| 2688 | && targetTile |
| 2689 | && targetTile->getMapData(MapData::O_OBJECT) |
| 2690 | && targetTile->getMapData(MapData::O_OBJECT)->getTUCost(MT_WALK) == 255) |
| 2691 | || ProjectileFlyBState::validThrowRange(&action, originVoxel, targetTile) == false) |
| 2692 | { |
| 2693 | return false; |
| 2694 | } |
| 2695 | |
| 2696 | // we try 8 different curvatures to try and reach our goal. |
| 2697 | int test = V_OUTOFBOUNDS; |
| 2698 | while (!foundCurve && curvature < 5.0) |
| 2699 | { |
| 2700 | std::vector<Position> trajectory; |
| 2701 | test = calculateParabola(originVoxel, targetVoxel, false, &trajectory, action.actor, curvature, Position(0,0,0)); |
| 2702 | if (test != V_OUTOFBOUNDS && (trajectory.at(0) / Position(16, 16, 24)) == (targetVoxel / Position(16, 16, 24))) |
| 2703 | { |
| 2704 | if (voxelType) |
| 2705 | { |
| 2706 | *voxelType = test; |
| 2707 | } |
| 2708 | foundCurve = true; |
| 2709 | } |
| 2710 | else |
| 2711 | { |
| 2712 | curvature += 0.5; |
| 2713 | } |
| 2714 | } |
| 2715 | if (curvature >= 5.0) |
| 2716 | { |
| 2717 | return false; |
| 2718 | } |
| 2719 | if (curve) |
| 2720 | { |
| 2721 | *curve = curvature; |
| 2722 | } |
| 2723 | |
| 2724 | return true; |
| 2725 | } |
| 2726 | |
| 2727 | /** |
| 2728 | * Recalculates FOV of all units in-game. |