2015-01-13 17:05:05 +00:00
|
|
|
/**
|
|
|
|
* fnc HandleFired.
|
|
|
|
* Handles wind deflection for projectiles.
|
|
|
|
* Is expected to be triggered by the fired eventhandler from BI.
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* 1. unit: Object - Object the event handler is assigned to
|
|
|
|
* 2. weapon: String - Fired weapon
|
|
|
|
* 3. muzzle: String - Muzzle that was used
|
|
|
|
* 4. mode: String - Current mode of the fired weapon
|
|
|
|
* 5. ammo: String - Ammo used
|
|
|
|
* 6. magazine: String - magazine name which was used
|
|
|
|
* 7. projectile: Object - Object of the projectile that was shot (Arma 2: OA and onwards)
|
|
|
|
*
|
|
|
|
* Author: Glowbal, Ruthberg
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-01-28 16:36:47 +00:00
|
|
|
if (isNil QGVAR(EnableForAI)) exitWith {false}; // means that the module has not yet initialized
|
2015-01-13 17:05:05 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
if (!GVAR(EnableForAI) && !(isPlayer _unit)) exitWith {false};
|
|
|
|
_bullet = _this select 6;
|
|
|
|
|
|
|
|
if (_bullet isKindOf "BulletBase") then {
|
|
|
|
_weapon = _this select 1;
|
|
|
|
_ammo = _this select 4;
|
|
|
|
|
|
|
|
_airFriction = getNumber(configFile >> "cfgAmmo" >> _ammo >> "airFriction");
|
|
|
|
|
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-28 16:58:28 +00:00
|
|
|
_drag = _deltaT * _airFriction * _trueSpeed * _trueSpeed;
|
|
|
|
_accel = (vectorNormalized _trueVelocity) vectorMultiply (_drag);
|
|
|
|
_bulletVelocity = _bulletVelocity vectorAdd _accel;
|
|
|
|
};
|
|
|
|
_bullet setVelocity _bulletVelocity;
|
|
|
|
// TODO expand with advanced ballistics functionality.
|
2015-01-13 17:05:05 +00:00
|
|
|
|
2015-01-28 16:58:28 +00:00
|
|
|
}, 0, [_bullet, _airFriction, time]] call CBA_fnc_addPerFrameHandler;
|
2015-01-13 17:05:05 +00:00
|
|
|
};
|
|
|
|
true;
|