ACE3/addons/winddeflection/functions/fnc_updateTrajectoryPFH.sqf
ulteq 5ff54f7d1c Implemented a new logic that decides when to use AB.
*Added a new global variable ace_advanced_ballistics_enabled
*Added an updateTrajectoryPFH to the winddeflection (WD) module
*WD is now automatically disabled when AB is enabled
*The new updateTrajectoryPFH is called whenever AB aborts

-> Wind deflection is now always present (either through AB or WD)
-> AB no longer runs for non local units (unless they use high power optics)
2015-04-09 20:27:10 +02:00

50 lines
1.5 KiB
Plaintext

/*
* Author: Glowbal, Ruthberg
* Handles wind deflection for projectiles.
*
* Arguments:
* 0: bullet - Object the event handler is assigned to <OBJECT>
* 1: airFriction - air friction of the bullet <NUMBER>
*
* Return Value:
* Nothing
*
* Example:
*
* Public: No
*/
#include "script_component.hpp"
[{
private ["_bullet", "_airFriction", "_args", "_deltaT", "_bulletVelocity", "_bulletSpeed", "_trueVelocity", "_trueVelocity", "_dragRef", "_drag", "_accelRef", "_accel"];
_args = _this select 0;
_bullet = _args select 0;
_airFriction = _args select 1;
_time = _args select 2;
if (!alive _bullet) exitwith {
[_this select 1] call cba_fnc_removePerFrameHandler;
};
_deltaT = time - _time;
_args set[2, time];
_bulletVelocity = velocity _bullet;
_bulletSpeed = vectorMagnitude _bulletVelocity;
if (vectorMagnitude ACE_wind > 0) then {
_trueVelocity = _bulletVelocity vectorDiff ACE_wind;
_trueSpeed = vectorMagnitude _trueVelocity;
_dragRef = _deltaT * _airFriction * _bulletSpeed * _bulletSpeed;
_accelRef = (vectorNormalized _bulletVelocity) vectorMultiply (_dragRef);
_bulletVelocity = _bulletVelocity vectorDiff _accelRef;
_drag = _deltaT * _airFriction * _trueSpeed;
_accel = _trueVelocity vectorMultiply (_drag);
_bulletVelocity = _bulletVelocity vectorAdd _accel;
};
_bullet setVelocity _bulletVelocity;
}, 0, [_this select 0, _this select 1, time]] call CBA_fnc_addPerFrameHandler;