| 841 | } |
| 842 | |
| 843 | void AEquipment::throwItem(GameState &state, Vec3<int> targetPosition, float velocityXY, |
| 844 | float velocityZ, bool launch) |
| 845 | { |
| 846 | auto &unit = *ownerUnit; |
| 847 | Vec3<float> position = unit.getThrownItemLocation(); |
| 848 | if (state.battle_common_sample_list->throwSounds.size() > 0) |
| 849 | { |
| 850 | fw().soundBackend->playSample( |
| 851 | pickRandom(state.rng, state.battle_common_sample_list->throwSounds), position); |
| 852 | } |
| 853 | |
| 854 | // This will be modified by the accuracy algorithm |
| 855 | Vec3<float> targetLocationModified = |
| 856 | Vec3<float>(targetPosition) + Vec3<float>{0.5f, 0.5f, 0.0f}; |
| 857 | // This is proper target vector, stored to get difference later |
| 858 | Vec3<float> targetVector = targetLocationModified - position; |
| 859 | // Apply accuracy (if launching apply normal, narrower spread) |
| 860 | Battle::accuracyAlgorithmBattle(state, position, targetLocationModified, |
| 861 | getAccuracy(unit.current_body_state, |
| 862 | unit.current_movement_state, unit.fire_aiming_mode, |
| 863 | true), |
| 864 | false, !launch); |
| 865 | Vec3<float> targetVectorModified = targetLocationModified - position; |
| 866 | // Calculate difference in lengths to modify velocity |
| 867 | float targetVectorDifference = glm::length(targetVectorModified) / glm::length(targetVector); |
| 868 | |
| 869 | velocityXY *= targetVectorDifference; |
| 870 | velocityZ *= targetVectorDifference; |
| 871 | |
| 872 | auto bi = state.current_battle->placeItem(state, shared_from_this(), position); |
| 873 | // prevent normalizing of 0 vector throwing exception |
| 874 | Vec3<float> norm = {0.0f, 0.0f, 0.0f}; |
| 875 | if (targetVectorModified.x != 0.0f && targetVectorModified.y != 0.0f) |
| 876 | { |
| 877 | norm = glm::normalize(Vec3<float>{targetVectorModified.x, targetVectorModified.y, 0.0f}); |
| 878 | } |
| 879 | bi->velocity = (norm * velocityXY + Vec3<float>{0.0f, 0.0f, velocityZ}) * VELOCITY_SCALE_BATTLE; |
| 880 | bi->falling = true; |
| 881 | // 36 / (velocity length) = enough ticks to pass 1 whole tile |
| 882 | bi->ownerInvulnerableTicks = |
| 883 | (int)ceilf(36.0f / glm::length(bi->velocity / VELOCITY_SCALE_BATTLE)) + 1; |
| 884 | } |
| 885 | |
| 886 | StateRef<AEquipmentType> AEquipment::getPayloadType() const |
| 887 | { |
no test coverage detected