2015-03-12 05:28:33 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal, Ruthberg
|
2015-01-13 17:05:05 +00:00
|
|
|
* Handles wind deflection for projectiles.
|
|
|
|
*
|
2015-03-12 05:28:33 +00:00
|
|
|
* Arguments:
|
|
|
|
* 0: unit - Object the event handler is assigned to <OBJECT>
|
|
|
|
* 1: weapon - Fired weapon <STRING>
|
|
|
|
* 2: muzzle - Muzzle that was used <STRING>
|
|
|
|
* 3: mode - Current mode of the fired weapon <STRING>
|
|
|
|
* 4: ammo - Ammo used <STRING>
|
|
|
|
* 5: magazine - magazine name which was used <STRING>
|
|
|
|
* 6: projectile - Object of the projectile that was shot <OBJECT>
|
2015-01-13 17:05:05 +00:00
|
|
|
*
|
2015-03-12 05:28:33 +00:00
|
|
|
* Return Value:
|
|
|
|
* Nothing
|
2015-01-13 17:05:05 +00:00
|
|
|
*
|
2015-03-12 05:28:33 +00:00
|
|
|
* Example:
|
|
|
|
* [clientFiredBIS-XEH] call ace_winddeflection_fnc_handleFired
|
|
|
|
*
|
|
|
|
* Public: No
|
2015-01-13 17:05:05 +00:00
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
private ["_unit", "_weapon", "_ammo", "_bullet", "_airFriction", "_index"];
|
|
|
|
_unit = _this select 0;
|
|
|
|
|
|
|
|
if (_unit distance ACE_player > 3000) exitWith {false}; // Large enough distance to not simulate any wind deflection.
|
2015-01-28 17:02:49 +00:00
|
|
|
if (!GVAR(EnableForAI) && !([_unit] call EFUNC(common,isPlayer))) exitWith {false};
|
2015-01-13 17:05:05 +00:00
|
|
|
_bullet = _this select 6;
|
|
|
|
|
|
|
|
if (_bullet isKindOf "BulletBase") then {
|
2015-01-28 16:58:28 +00:00
|
|
|
[{
|
|
|
|
private ["_bullet", "_airFriction", "_args", "_deltaT", "_bulletVelocity", "_bulletSpeed", "_trueVelocity", "_trueVelocity", "_dragRef", "_drag", "_accelRef", "_accel"];
|
2015-01-13 17:05:05 +00:00
|
|
|
|
2015-01-28 16:58:28 +00:00
|
|
|
_args = _this select 0;
|
|
|
|
_bullet = _args select 0;
|
|
|
|
_airFriction = _args select 1;
|
|
|
|
_time = _args select 2;
|
2015-01-13 17:05:05 +00:00
|
|
|
|
2015-01-28 16:58:28 +00:00
|
|
|
if (!alive _bullet) exitwith {
|
|
|
|
[_this select 1] call cba_fnc_removePerFrameHandler;
|
|
|
|
};
|
2015-01-13 17:05:05 +00:00
|
|
|
|
2015-01-28 16:58:28 +00:00
|
|
|
_deltaT = time - _time;
|
|
|
|
_args set[2, time];
|
2015-01-13 17:05:05 +00:00
|
|
|
|
2015-01-28 16:58:28 +00:00
|
|
|
_bulletVelocity = velocity _bullet;
|
|
|
|
_bulletSpeed = vectorMagnitude _bulletVelocity;
|
2015-01-13 17:05:05 +00:00
|
|
|
|
2015-01-28 16:58:28 +00:00
|
|
|
if (vectorMagnitude ACE_wind > 0) then {
|
|
|
|
_trueVelocity = _bulletVelocity vectorDiff ACE_wind;
|
|
|
|
_trueSpeed = vectorMagnitude _trueVelocity;
|
2015-01-13 17:05:05 +00:00
|
|
|
|
2015-01-28 16:58:28 +00:00
|
|
|
_dragRef = _deltaT * _airFriction * _bulletSpeed * _bulletSpeed;
|
|
|
|
_accelRef = (vectorNormalized _bulletVelocity) vectorMultiply (_dragRef);
|
|
|
|
_bulletVelocity = _bulletVelocity vectorDiff _accelRef;
|
2015-01-13 17:05:05 +00:00
|
|
|
|
2015-01-29 12:58:22 +00:00
|
|
|
_drag = _deltaT * _airFriction * _trueSpeed;
|
|
|
|
_accel = _trueVelocity vectorMultiply (_drag);
|
2015-01-28 16:58:28 +00:00
|
|
|
_bulletVelocity = _bulletVelocity vectorAdd _accel;
|
|
|
|
};
|
|
|
|
_bullet setVelocity _bulletVelocity;
|
|
|
|
// TODO expand with advanced ballistics functionality.
|
2015-01-13 17:05:05 +00:00
|
|
|
|
2015-01-29 12:58:22 +00:00
|
|
|
}, 0, [_bullet, getNumber(configFile >> "cfgAmmo" >> (_this select 4) >> "airFriction"), time]] call CBA_fnc_addPerFrameHandler;
|
2015-01-13 17:05:05 +00:00
|
|
|
};
|
|
|
|
true;
|