diff --git a/addons/frag/ACE_Settings.hpp b/addons/frag/ACE_Settings.hpp index b160a127f3..6a782de2f9 100644 --- a/addons/frag/ACE_Settings.hpp +++ b/addons/frag/ACE_Settings.hpp @@ -1,7 +1,14 @@ class ACE_Settings { class GVAR(enabled) { - displayName = "Frag System"; - description = "Enables the shrapnel system for explosives"; + displayName = "$STR_ACE_frag_EnableFrag"; + description = "$STR_ACE_frag_EnableFrag_Desc"; + typeName = "BOOL"; + value = 1; + }; + + class GVAR(spallEnabled) { + displayName = "$STR_ACE_frag_EnableSpall"; + description = "$STR_ACE_frag_EnableSpall_Desc"; typeName = "BOOL"; value = 1; }; diff --git a/addons/frag/XEH_postInit.sqf b/addons/frag/XEH_postInit.sqf index 6c8d64d1fb..0c6a1845b6 100644 --- a/addons/frag/XEH_postInit.sqf +++ b/addons/frag/XEH_postInit.sqf @@ -2,4 +2,6 @@ if(isServer) then { [QGVAR(frag_eh), { _this call FUNC(frago); }] call ace_common_fnc_addEventHandler; -}; \ No newline at end of file +}; + +[FUNC(masterPFH), 0, []] call CBA_fnc_addPerFrameHandler; \ No newline at end of file diff --git a/addons/frag/XEH_preInit.sqf b/addons/frag/XEH_preInit.sqf index 906a696ebf..4d1afcc385 100644 --- a/addons/frag/XEH_preInit.sqf +++ b/addons/frag/XEH_preInit.sqf @@ -6,11 +6,9 @@ PREP(doSpall); PREP(fired); PREP(frago); PREP(spallTrack); -PREP(trackFragRound); GVAR(blackList) = []; GVAR(traceFrags) = false; -GVAR(trackedObjects) = []; GVAR(TOTALFRAGS) = 0; @@ -32,4 +30,14 @@ PREP(startTracing); PREP(stopTracing); PREP(trackTrace); +// New tracking mechanisms +PREP(masterPFH); +PREP(pfhRound); +PREP(addPfhRound); +PREP(removePfhRound); // THIS SHOULD ABE USED SPARINGLY + +GVAR(objects) = []; +GVAR(objectTypes) = []; +GVAR(arguments) = []; + ADDON = true; diff --git a/addons/frag/functions/fnc_addPfhRound.sqf b/addons/frag/functions/fnc_addPfhRound.sqf new file mode 100644 index 0000000000..81454edf97 --- /dev/null +++ b/addons/frag/functions/fnc_addPfhRound.sqf @@ -0,0 +1,71 @@ +#include "script_component.hpp" + +private ["_enabled", "_gun", "_type", "_round", "_doFragTrack", "_doSpall", "_spallTrack", "_spallTrackID"]; + +if (!GVAR(enabled)) exitWith {}; + +_gun = _this select 0; +_type = _this select 1; +_round = _this select 2; + +_enabled = getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(enabled)); +if(_enabled < 1) exitWith {}; + +if(_round in GVAR(blackList)) exitWith { + GVAR(blackList) = GVAR(blackList) - [_round]; +}; + +_doFragTrack = false; +if(_gun == ACE_player) then { + _doFragTrack = true; +} else { + if((gunner _gun) == ACE_player) then { + _doFragTrack = true; + } else { + if(local _gun && {!(isPlayer (gunner _gun))} && {!(isPlayer _gun)}) then { + _doFragTrack = true; + }; + }; +}; +if(GVAR(spallEnabled)) then { + if(GVAR(spallIsTrackingCount) <= 0) then { + GVAR(spallHPData) = []; + }; + if(GVAR(spallIsTrackingCount) > 5) then { + // ACE_player sideChat "LIMT!"; + _doSpall = false; + } else { + GVAR(spallIsTrackingCount) = GVAR(spallIsTrackingCount) + 1; + }; +}; +// ACE_player sideChat format["c: %1", GVAR(spallIsTrackingCount)]; + +#ifdef DEBUG_MODE_FULL +[ACE_player, _round, [1,0,0,1]] call FUNC(addTrack); +#endif + +// We only do the single track object check here. +if(_doFragTrack && alive _round && {!(_round in GVAR(objects))} ) then { + _spallTrack = []; + _spallTrackID = []; + + private["_args"]; + _args = [_round, (getPosASL _round), (velocity _round), _type, time, _gun, _doSpall, _spallTrack, _spallTrackID, + (getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(skip))), + (getNumber (configFile >> "CfgAmmo" >> _type >> "explosive")), + (getNumber (configFile >> "CfgAmmo" >> _type >> "indirectHitRange")), + (getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(force))), + (getNumber(configFile >> "CfgAmmo" >> _type >> "indirecthit")*(sqrt((getNumber (configFile >> "CfgAmmo" >> _type >> "indirectHitRange"))))) + ]; + + GVAR(objects) pushBack _round; + GVAR(arguments) pushBack _args; + + if(_doSpall) then { + [_round, 2, _spallTrack, _spallTrackID] call FUNC(spallTrack); + }; + // ACE_player sideChat "WTF2"; +}; + + + diff --git a/addons/frag/functions/fnc_doSpall.sqf b/addons/frag/functions/fnc_doSpall.sqf index d2e64dbbfb..717b629e53 100644 --- a/addons/frag/functions/fnc_doSpall.sqf +++ b/addons/frag/functions/fnc_doSpall.sqf @@ -124,6 +124,7 @@ if(_alive || {_caliber >= 2.5} || {(_explosive > 0 && {_idh >= 1})}) then { _fragment = (_fragTypes select _fragType) createVehicleLocal [0,0,10000]; _fragment setPosASL _spallPos; _fragment setVelocity _spallFragVect; + if(GVAR(traceFrags)) then { [ACE_player, _fragment, [1,0.5,0,1]] call FUNC(addTrack); }; @@ -145,6 +146,7 @@ if(_alive || {_caliber >= 2.5} || {(_explosive > 0 && {_idh >= 1})}) then { _fragment = (_fragTypes select _fragType) createVehicleLocal [0,0,10000]; _fragment setPosASL _spallPos; _fragment setVelocity _spallFragVect; + if(GVAR(traceFrags)) then { [ACE_player, _fragment, [1,0,0,1]] call FUNC(addTrack); }; diff --git a/addons/frag/functions/fnc_fired.sqf b/addons/frag/functions/fnc_fired.sqf index 9b89e40897..15a878d112 100644 --- a/addons/frag/functions/fnc_fired.sqf +++ b/addons/frag/functions/fnc_fired.sqf @@ -1,58 +1,9 @@ #include "script_component.hpp" - -private ["_enabled", "_gun", "_type", "_round", "_doFragTrack", "_doSpall", "_spallTrack", "_spallTrackID"]; - -if (!GVAR(enabled)) exitWith {}; +private["_gun", "_type", "_round"]; _gun = _this select 0; _type = _this select 4; _round = _this select 6; -_enabled = getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(enabled)); -if(_enabled < 1) exitWith {}; +[_gun, _type, _round] call FUNC(addPfhRound); -if(_round in GVAR(blackList)) exitWith { - GVAR(blackList) = GVAR(blackList) - [_round]; -}; - - -_doFragTrack = false; -if(_gun == ACE_player) then { - _doFragTrack = true; -} else { - if((gunner _gun) == ACE_player) then { - _doFragTrack = true; - } else { - if(local _gun && {!(isPlayer (gunner _gun))} && {!(isPlayer _gun)}) then { - _doFragTrack = true; - }; - }; -}; -_doSpall = false; -if(_doSpall) then { - if(GVAR(spallIsTrackingCount) <= 0) then { - GVAR(spallHPData) = []; - }; - if(GVAR(spallIsTrackingCount) > 5) then { - // ACE_player sideChat "LIMT!"; - _doSpall = false; - } else { - GVAR(spallIsTrackingCount) = GVAR(spallIsTrackingCount) + 1; - }; -}; -// ACE_player sideChat format["c: %1", GVAR(spallIsTrackingCount)]; - -#ifdef DEBUG_MODE_FULL -[ACE_player, _round, [1,0,0,1]] call FUNC(addTrack); -#endif - -if(_doFragTrack && alive _round) then { - GVAR(trackedObjects) pushBack _round; - _spallTrack = []; - _spallTrackID = []; - [DFUNC(trackFragRound), 0, [_round, (getPosASL _round), (velocity _round), _type, time, _gun, _doSpall, _spallTrack, _spallTrackID]] call cba_fnc_addPerFrameHandler; - if(_doSpall) then { - [_round, 2, _spallTrack, _spallTrackID] call FUNC(spallTrack); - }; - // ACE_player sideChat "WTF2"; -}; diff --git a/addons/frag/functions/fnc_masterPFH.sqf b/addons/frag/functions/fnc_masterPFH.sqf new file mode 100644 index 0000000000..d511325e15 --- /dev/null +++ b/addons/frag/functions/fnc_masterPFH.sqf @@ -0,0 +1,46 @@ +/* + * Author: jaynus + * + * Master single PFH abstraction for all rounds being tracked by frag/spall + * + * Arguments: + * + * + * Return Value: + * None + */ +#include "script_component.hpp" +PARAMS_2(_pfhArgs,_handle); + +if (!GVAR(enabled)) exitWith {}; + +private["_gcIndex"]; +_gcIndex = []; +{ + private["_object", "_args"]; + _object = _x; + if(!isNil "_object") then { + if(isNull _object) then { + _gcIndex pushBack _forEachIndex; + } else { + _args = GVAR(arguments) select _forEachIndex; + + _args call FUNC(pfhRound); + }; + + if(!alive _object) then { + _gcIndex pushBack _forEachIndex; + }; + }; +} forEach GVAR(objects); + +// clean up dead object references +private["_deletionCount", "_deleteIndex"]; +_deletionCount = 0; +{ + _deleteIndex = _gcIndex - _deletionCount; + GVAR(objects) deleteAt _deleteIndex; + GVAR(arguments) deleteAt _deleteIndex; + + _deletionCount = _deletionCount + 1; +} forEach _gcIndex; \ No newline at end of file diff --git a/addons/frag/functions/fnc_trackFragRound.sqf b/addons/frag/functions/fnc_pfhRound.sqf similarity index 54% rename from addons/frag/functions/fnc_trackFragRound.sqf rename to addons/frag/functions/fnc_pfhRound.sqf index 8db68c99e8..df6f618ac5 100644 --- a/addons/frag/functions/fnc_trackFragRound.sqf +++ b/addons/frag/functions/fnc_pfhRound.sqf @@ -1,4 +1,3 @@ -//fnc_trackFragRound.sqf #include "script_component.hpp" private ["_params", "_round", "_lastPos", "_lastVel", "_type", "_time", "_doSpall", "_spallTrack", "_foundObjectHPIds", "_skip", "_explosive", "_indirectRange", "_force", "_fragPower"]; _params = _this select 0; @@ -10,20 +9,17 @@ _time = _params select 4; _doSpall = _params select 6; _spallTrack = _params select 7; _foundObjectHPIds = _params select 8; +_skip = _params select 9; +_explosive = _params select 10; +_indirectRange = _params select 11; +_force = _params select 12; +_fragPower = _params select 13; if (!alive _round) then { - [_this select 1] call cba_fnc_removePerFrameHandler; - if(_time != time && {_round in GVAR(trackedObjects)} && {!(_round in GVAR(blackList))}) then { - GVAR(trackedObjects) = GVAR(trackedObjects) - [_round]; - _skip = getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(skip)); + if(_time != time && {!(_round in GVAR(blackList))}) then { if(_skip == 0) then { - _explosive = getNumber (configFile >> "CfgAmmo" >> _type >> "explosive"); - _indirectRange = getNumber (configFile >> "CfgAmmo" >> _type >> "indirectHitRange"); - _force = getNumber (configFile >> "CfgAmmo" >> _type >> QGVAR(force)); - _fragPower = getNumber(configFile >> "CfgAmmo" >> _type >> "indirecthit")*(sqrt(_indirectRange)); if((_explosive > 0.5 && {_indirectRange >= 4.5} && {_fragPower >= 35}) || {_force == 1} ) then { [QGVAR(frag_eh), _params] call ace_common_fnc_serverEvent; - GVAR(trackedObjects) = GVAR(trackedObjects) - [_round]; }; }; }; @@ -37,11 +33,8 @@ if (!alive _round) then { } forEach _spallTrack; }; } else { - if(!(_round in GVAR(trackedObjects)) || {_round in GVAR(blackList)}) then { - [_this select 1] call cba_fnc_removePerFrameHandler; - if(_round in GVAR(blackList)) then { - GVAR(blackList) = GVAR(blackList) - [_round]; - }; + if(_round in GVAR(blackList)) exitWith { + [_round] call FUNC(removePfhRound); }; _params set[1, (getPosASL _round)]; diff --git a/addons/frag/functions/fnc_removePfhRound.sqf b/addons/frag/functions/fnc_removePfhRound.sqf new file mode 100644 index 0000000000..7fe3994d55 --- /dev/null +++ b/addons/frag/functions/fnc_removePfhRound.sqf @@ -0,0 +1,9 @@ +#include "script_component.hpp" + +// THIS FUNCTION SHOULD NOT BE USED BECAUSE IT CAUSES AN SEARCH AND REBUILD + +if(_round in GVAR(blackList)) then { + GVAR(blackList) = GVAR(blackList) - [_round]; +}; + +GVAR(objects) = GVAR(objects) - [_round]; \ No newline at end of file diff --git a/addons/frag/stringtable.xml b/addons/frag/stringtable.xml index e7ebb7c1bf..e267685869 100644 --- a/addons/frag/stringtable.xml +++ b/addons/frag/stringtable.xml @@ -1,17 +1,21 @@  - - Disable Fragmentation - Keine Schrapnelle - Zakázat fragmentaci granátů - Desactivar fragmentación - Wyłącz fragmentację odłamków - Выключить разлёт осколков - Désactive la fragmentation - Repeszek letiltása - Disattiva la frammentazione - Desabilitar Fragmentação + + Fragmentation Simulation + + + + Enable the ACE Fragmentation Simulation + + + + Spalling Simulation + + + + Enable the ACE Spalling Simulation +