From b70ae9207c9ac6b14bce17023d1f38bce8ed19b4 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Sat, 6 Feb 2016 17:12:28 -0300 Subject: [PATCH] Apply the ufeh to ACE_Frag --- addons/frag/CfgEventhandlers.hpp | 6 ----- addons/frag/XEH_postInit.sqf | 16 ++++++++++++- addons/frag/functions/fnc_fired.sqf | 35 ++++++++++++++--------------- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/addons/frag/CfgEventhandlers.hpp b/addons/frag/CfgEventhandlers.hpp index df7eaeacd1..3b3f4898e5 100644 --- a/addons/frag/CfgEventhandlers.hpp +++ b/addons/frag/CfgEventhandlers.hpp @@ -9,9 +9,3 @@ class Extended_PostInit_EventHandlers { init = QUOTE(call COMPILE_FILE(XEH_postInit)); }; }; - -class Extended_FiredBIS_EventHandlers { - class AllVehicles { - ADDON = QUOTE(_this call FUNC(fired)); - }; -}; diff --git a/addons/frag/XEH_postInit.sqf b/addons/frag/XEH_postInit.sqf index f49e5d1e3e..46910c519d 100644 --- a/addons/frag/XEH_postInit.sqf +++ b/addons/frag/XEH_postInit.sqf @@ -9,7 +9,21 @@ if(isServer) then { [QGVAR(frag_eh), { _this call FUNC(frago); }] call EFUNC(common,addEventHandler); }; -[FUNC(masterPFH), 0, []] call CBA_fnc_addPerFrameHandler; +["SettingsInitialized", { + //If not enabled, exit + if (!GVAR(enabled)) exitWith {}; + + // Register fire event handler + ["firedPlayer", DFUNC(firedEH)] call EFUNC(common,addEventHandler); + ["firedPlayerNonLocal", DFUNC(firedEH)] call EFUNC(common,addEventHandler); + ["firedNonPlayer", DFUNC(firedEH)] call EFUNC(common,addEventHandler); + ["firedPlayerVehicle", DFUNC(firedEH)] call EFUNC(common,addEventHandler); + ["firedPlayerVehicleNonLocal", DFUNC(firedEH)] call EFUNC(common,addEventHandler); + ["firedNonPlayerVehicle", DFUNC(firedEH)] call EFUNC(common,addEventHandler); + + [FUNC(masterPFH), 0, []] call CBA_fnc_addPerFrameHandler; + +}] call EFUNC(common,addEventHandler); //Cache for ammo type configs GVAR(cacheRoundsTypesToTrack) = createLocation ["ACE_HashLocation", [-10000,-10000,-10000], 0, 0]; diff --git a/addons/frag/functions/fnc_fired.sqf b/addons/frag/functions/fnc_fired.sqf index 3e82544430..dbe1ab6347 100644 --- a/addons/frag/functions/fnc_fired.sqf +++ b/addons/frag/functions/fnc_fired.sqf @@ -1,12 +1,10 @@ /* * Author: nou, jaynus, PabstMirror - * Called from FiredBIS event on AllVehicles + * Called from the unified fired EH for all. * If spall is not enabled (default), then cache and only track those that will actually trigger fragmentation. * * Arguments: - * 0: gun - Object the event handler is assigned to - * 4: type - Ammo used - * 6: round - Object of the projectile that was shot + * None. Parameters inherited from EFUNC(common,firedEH) * * Return Value: * Nothing @@ -19,38 +17,39 @@ // #define DEBUG_ENABLED_FRAG #include "script_component.hpp" -params ["_gun", "", "", "", "_type", "", "_round"]; +//IGNORE_PRIVATE_WARNING ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_vehicle", "_gunner", "_turret"]; +TRACE_10("firedEH:",_unit, _weapon, _muzzle, _mode, _ammo, _magazine, _projectile, _vehicle, _gunner, _turret); -private _shouldAdd = GVAR(cacheRoundsTypesToTrack) getVariable _type; +private _shouldAdd = GVAR(cacheRoundsTypesToTrack) getVariable _ammo; if (isNil "_shouldAdd") then { - TRACE_1("no cache for round",_type); + TRACE_1("no cache for round",_ammo); if (!EGVAR(common,settingsInitFinished)) exitWith { //Just incase fired event happens before settings init, don't want to set cache wrong if spall setting changes - TRACE_1("Settings not init yet - exit without setting cache",_type); + TRACE_1("Settings not init yet - exit without setting cache",_ammo); _shouldAdd = false; }; if (GVAR(SpallEnabled)) exitWith { //Always want to run whenever spall is enabled? _shouldAdd = true; - TRACE_2("SettingCache[spallEnabled]",_type,_shouldAdd); - GVAR(cacheRoundsTypesToTrack) setVariable [_type, _shouldAdd]; + TRACE_2("SettingCache[spallEnabled]",_ammo,_shouldAdd); + GVAR(cacheRoundsTypesToTrack) setVariable [_ammo, _shouldAdd]; }; //Read configs and test if it would actually cause a frag, using same logic as FUNC(pfhRound) - private _skip = getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(skip)); - private _explosive = getNumber (configFile >> "CfgAmmo" >> _type >> "explosive"); - private _indirectRange = getNumber (configFile >> "CfgAmmo" >> _type >> "indirectHitRange"); - private _force = getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(force)); - private _fragPower = getNumber(configFile >> "CfgAmmo" >> _type >> "indirecthit")*(sqrt((getNumber (configFile >> "CfgAmmo" >> _type >> "indirectHitRange")))); + private _skip = getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(skip)); + private _explosive = getNumber (configFile >> "CfgAmmo" >> _ammo >> "explosive"); + private _indirectRange = getNumber (configFile >> "CfgAmmo" >> _ammo >> "indirectHitRange"); + private _force = getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(force)); + private _fragPower = getNumber(configFile >> "CfgAmmo" >> _ammo >> "indirecthit")*(sqrt((getNumber (configFile >> "CfgAmmo" >> _ammo >> "indirectHitRange")))); _shouldAdd = (_skip == 0) && {(_force == 1) || {_explosive > 0.5 && {_indirectRange >= 4.5} && {_fragPower >= 35}}}; TRACE_6("SettingCache[willFrag?]",_skip,_explosive,_indirectRange,_force,_fragPower,_shouldAdd); - GVAR(cacheRoundsTypesToTrack) setVariable [_type, _shouldAdd]; + GVAR(cacheRoundsTypesToTrack) setVariable [_ammo, _shouldAdd]; }; if (_shouldAdd) then { - TRACE_3("Running Frag Tracking",_gun,_type,_round); - [_gun, _type, _round] call FUNC(addPfhRound); + TRACE_3("Running Frag Tracking",_unit,_ammo,_projectile); + [_unit, _ammo, _projectile] call FUNC(addPfhRound); };