mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #1886 from acemod/windDeflectionSinglePFEH
Wind deflection single pfeh
This commit is contained in:
commit
ffc5615abd
@ -3,7 +3,11 @@ class Extended_PreInit_EventHandlers {
|
|||||||
init = QUOTE(call COMPILE_FILE(XEH_preInit));
|
init = QUOTE(call COMPILE_FILE(XEH_preInit));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
class Extended_PostInit_EventHandlers {
|
||||||
|
class ADDON {
|
||||||
|
init = QUOTE(call COMPILE_FILE(XEH_postInit));
|
||||||
|
};
|
||||||
|
};
|
||||||
class Extended_FiredBIS_EventHandlers {
|
class Extended_FiredBIS_EventHandlers {
|
||||||
class AllVehicles {
|
class AllVehicles {
|
||||||
class ADDON {
|
class ADDON {
|
||||||
|
13
addons/winddeflection/XEH_postInit.sqf
Normal file
13
addons/winddeflection/XEH_postInit.sqf
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include "script_component.hpp"
|
||||||
|
|
||||||
|
if !(hasInterface) exitWith {};
|
||||||
|
|
||||||
|
GVAR(trackedBullets) = [];
|
||||||
|
|
||||||
|
["SettingsInitialized", {
|
||||||
|
//If not enabled, dont't add PFEH
|
||||||
|
if (!GVAR(enabled)) exitWith {};
|
||||||
|
|
||||||
|
[] call FUNC(updateTrajectoryPFH);
|
||||||
|
|
||||||
|
}] call EFUNC(common,addEventHandler);
|
@ -34,6 +34,6 @@ if (!((_bullet isKindOf "BulletBase") || (_bullet isKindOf "GrenadeBase"))) exit
|
|||||||
if (_unit distance ACE_player > GVAR(simulationRadius)) exitWith {false};
|
if (_unit distance ACE_player > GVAR(simulationRadius)) exitWith {false};
|
||||||
if (!([_unit] call EFUNC(common,isPlayer))) exitWith {false};
|
if (!([_unit] call EFUNC(common,isPlayer))) exitWith {false};
|
||||||
|
|
||||||
[_bullet, getNumber(configFile >> "cfgAmmo" >> (_this select 4) >> "airFriction")] call FUNC(updateTrajectoryPFH);
|
GVAR(trackedBullets) pushBack [_bullet, getNumber(configFile >> "cfgAmmo" >> (_this select 4) >> "airFriction")];
|
||||||
|
|
||||||
true;
|
true;
|
@ -13,38 +13,44 @@
|
|||||||
*
|
*
|
||||||
* Public: No
|
* Public: No
|
||||||
*/
|
*/
|
||||||
|
// #define ENABLE_PERFORMANCE_COUNTERS
|
||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
[{
|
[{
|
||||||
private ["_args", "_bullet", "_airFriction", "_time", "_deltaT", "_bulletVelocity", "_bulletSpeed", "_trueVelocity", "_trueSpeed", "_dragRef", "_drag", "_accelRef", "_accel"];
|
// BEGIN_COUNTER(pfeh);
|
||||||
|
private["_accel", "_accelRef", "_bulletSpeed", "_bulletVelocity", "_deleted", "_deltaT", "_drag", "_dragRef", "_isWind", "_lastTime", "_trueSpeed", "_trueVelocity"];
|
||||||
|
|
||||||
_args = _this select 0;
|
_lastTime = (_this select 0) select 0;
|
||||||
_bullet = _args select 0;
|
_deltaT = ACE_time - _lastTime;
|
||||||
_airFriction = _args select 1;
|
(_this select 0) set [0, ACE_time];
|
||||||
_time = _args select 2;
|
_deleted = 0;
|
||||||
|
_isWind = (vectorMagnitude ACE_wind > 0);
|
||||||
_bulletVelocity = velocity _bullet;
|
|
||||||
_bulletSpeed = vectorMagnitude _bulletVelocity;
|
|
||||||
|
|
||||||
if (!alive _bullet || ((_bullet isKindOf "BulletBase") && _bulletSpeed < 100)) exitwith {
|
|
||||||
[_this select 1] call cba_fnc_removePerFrameHandler;
|
|
||||||
};
|
|
||||||
|
|
||||||
_deltaT = ACE_time - _time;
|
|
||||||
_args set[2, ACE_time];
|
|
||||||
|
|
||||||
if (vectorMagnitude ACE_wind > 0) then {
|
|
||||||
_trueVelocity = _bulletVelocity vectorDiff ACE_wind;
|
|
||||||
_trueSpeed = vectorMagnitude _trueVelocity;
|
|
||||||
|
|
||||||
_dragRef = _deltaT * _airFriction * _bulletSpeed * _bulletSpeed;
|
{
|
||||||
_accelRef = (vectorNormalized _bulletVelocity) vectorMultiply (_dragRef);
|
_x params ["_bullet", "_airFriction"];
|
||||||
_bulletVelocity = _bulletVelocity vectorDiff _accelRef;
|
|
||||||
|
|
||||||
_drag = _deltaT * _airFriction * _trueSpeed;
|
_bulletVelocity = velocity _bullet;
|
||||||
_accel = _trueVelocity vectorMultiply (_drag);
|
_bulletSpeed = vectorMagnitude _bulletVelocity;
|
||||||
_bulletVelocity = _bulletVelocity vectorAdd _accel;
|
|
||||||
};
|
if ((!alive _bullet) || {(_bullet isKindOf "BulletBase") && {_bulletSpeed < 100}}) then {
|
||||||
_bullet setVelocity _bulletVelocity;
|
GVAR(trackedBullets) deleteAt (_forEachIndex - _deleted);
|
||||||
|
_deleted = _deleted + 1;
|
||||||
}, GVAR(simulationInterval), [_this select 0, _this select 1, ACE_time]] call CBA_fnc_addPerFrameHandler;
|
} else {
|
||||||
|
if (_isWind) 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
} forEach GVAR(trackedBullets);
|
||||||
|
// END_COUNTER(pfeh);
|
||||||
|
}, GVAR(simulationInterval), [ACE_time]] call CBA_fnc_addPerFrameHandler;
|
||||||
|
Loading…
Reference in New Issue
Block a user