#include "..\script_component.hpp" GVAR(maxBrightDelay) = 3.25; GVAR(zapSounds) = createHashMap; { private _cfg = missionConfigFile >> "CfgSounds" >> _x; private _dataArr = getArray(_cfg >> "sound"); GVAR(zapSounds) set [_x, createHashMapFromArray [ ["filename", _dataArr#0], ["volume", _dataArr#1], ["pitch", _dataArr#2] ]]; true; } count [QGVAR(sound_zap1),QGVAR(sound_zap2),QGVAR(sound_zap3),QGVAR(sound_zap4)]; GVAR(echoSounds) = createHashMap; { private _cfg = missionConfigFile >> "CfgSounds" >> _x; private _dataArr = getArray(_cfg >> "sound"); GVAR(echoSounds) set [_x, createHashMapFromArray [ ["filename", _dataArr#0], ["volume", _dataArr#1], ["pitch", _dataArr#2] ]]; true; } count [QGVAR(sound_ecou),QGVAR(sound_echo3)]; private _lgExplosionCfg = missionConfigFile >> "CfgSounds" >> QGVAR(sound_electric_explsion_impact_large); private _lgExplosionDataArray = getArray(_lgExplosionCfg >> "sound"); GVAR(sound_electric_explsion_impact_large) = createHashMapFromArray [ ["filename", _lgExplosionDataArray#0], ["volume", _lgExplosionDataArray#1], ["pitch", _lgExplosionDataArray#2] ]; if (hasInterface) then { call FUNC(addACEActions); }; GVAR(activeEMPs) = createHashMap; // this precheck is sent to all clients from FUNC(deploy) // machines will precache affected objects and signal they're ready in return [QGVAR(event_empDeployedPreCheck), { params ["_id", "_origin", "_radius"]; ([_origin, _radius] call FUNC(getObjectsAndGroupsToAffect)) params ["_affectedObjects", "_affectedLocalGroups"]; GVAR(activeEMPs) set [_id, createHashMapFromArray [ ["origin", _origin], ["radius", _radius], ["objects", _affectedObjects], ["localGroups", _affectedLocalGroups], ["machinesReady", []] ]]; [ LEVEL_DEBUG, QUOTE(COMPONENT), "EMP deployed precheck", [ ["id", _id], ["origin", _origin], ["radius", _radius], ["affectedObjects", count _affectedObjects], ["affectedLocalGroups", count _affectedLocalGroups] ] ] call EFUNC(common,log); // notify the server we're ready to play effects [QGVAR(event_readyForEmpEffects), [_id, clientOwner]] call CBA_fnc_serverEvent; if (isServer) then { // on the server, create a waiter for all machines to be ready [{ _this params ["_id"]; private _empData = GVAR(activeEMPs) get _id; count (_empData get "machinesReady") isEqualTo (count allUsers); }, { // when all machines are ready, play effects _this params ["_id"]; private _empData = GVAR(activeEMPs) get _id; [ LEVEL_DEBUG, QUOTE(COMPONENT), "Initiating EMP effects", [ ["id", _id], ["readyCount", count (_empData get "machinesReady")], ["allUsers", count allUsers] ] ] call EFUNC(common,log); [QGVAR(event_initiateEMPEffects), [_id]] call CBA_fnc_globalEvent; }, [_id]] call CBA_fnc_waitUntilAndExecute; }; }] call CBA_fnc_addEventHandler; // when a machine is ready to play effects, they'll trigger this on the server if (isServer) then { [QGVAR(event_readyForEmpEffects), { params ["_id", "_machineID"]; private _empData = GVAR(activeEMPs) get _id; private _machinesReady = _empData get "machinesReady"; if (!(_machineID in _machinesReady)) then { _machinesReady pushBack _machineID; _empData set ["machinesReady", _machinesReady]; [ LEVEL_DEBUG, QUOTE(COMPONENT), "Machine ready for EMP effects", [ ["id", _id], ["machineID", _machineID], ["readyCount", count _machinesReady] ] ] call EFUNC(common,log); }; }] call CBA_fnc_addEventHandler; }; // when all machines are ready, the server will trigger this on all machines to start effects [QGVAR(event_initiateEMPEffects), { params ["_id"]; private _empData = GVAR(activeEMPs) get _id; private _origin = _empData get "origin"; private _affectedObjects = _empData get "objects"; private _affectedLocalGroups = _empData get "localGroups"; if (hasInterface) then { [ LEVEL_DEBUG, QUOTE(COMPONENT), "Initiating EMP effects", [ ["id", _id], ["origin", _origin], ["affectedObjects", count _affectedObjects], ["affectedLocalGroups", count _affectedLocalGroups] ] ] call EFUNC(common,log); [_origin] call FUNC(playLocalEffects); // when emp effects reach max brightness, execute object effects [{ params ["_affectedObjects", "_affectedLocalGroups"]; private _countLocalObjectEffectsPlayed = { // play effects on this machine try { [_x] call FUNC(playLocalEffectsForObject); } catch { [ LEVEL_WARNING, QUOTE(COMPONENT), "Failed to play local EMP effects for object", [ ["object", typeOf _x], ["error", _exception] ] ] call EFUNC(common,log); }; true; } count _affectedObjects; [ LEVEL_DEBUG, QUOTE(COMPONENT), "Played EMP effects", [ ["localObjectEffectsPlayed", _countLocalObjectEffectsPlayed] ] ] call EFUNC(common,log); }, [_affectedObjects, _affectedLocalGroups], GVAR(maxBrightDelay)] call CBA_fnc_waitAndExecute; }; // around peak brightness [{ params ["_affectedObjects", "_affectedLocalGroups"]; private _countLocalObjectEffectsApplied = { // apply affects to objects owned by this machine, start propagation to other machines try { [_x] call FUNC(applyLocalObjectEffects); } catch { [ LEVEL_WARNING, QUOTE(COMPONENT), "Failed to apply local EMP effects for object", [ ["object", typeOf _x], ["error", _exception] ] ] call EFUNC(common,log); }; true; } count (_affectedObjects select {local _x}); private _countLocalGroupEffectsApplied = { // apply affects to groups owned by this machine, start propagation to other machines try { [_x] call FUNC(applyLocalGroupEffects); } catch { [ LEVEL_WARNING, QUOTE(COMPONENT), "Failed to apply local EMP effects for group", [ ["group", _x], ["error", _exception] ] ] call EFUNC(common,log); }; true; } count _affectedLocalGroups; if (isServer) then { private _countServerObjectEffectsApplied = { try { [_x] call FUNC(applyServerObjectEffects); } catch { [ LEVEL_WARNING, QUOTE(COMPONENT), "Failed to apply server EMP effects for object", [ ["object", typeOf _x], ["error", _exception] ] ] call EFUNC(common,log); }; true; } count _affectedObjects; }; private _countGlobalObjectEffectsApplied = { try { [_x] call FUNC(applyGlobalObjectEffects); } catch { [ LEVEL_WARNING, QUOTE(COMPONENT), "Failed to apply global EMP effects for object", [ ["object", typeOf _x], ["error", _exception] ] ] call EFUNC(common,log); }; true; } count _affectedObjects; [ LEVEL_DEBUG, QUOTE(COMPONENT), "Applied EMP effects", [ ["localObjectEffects", _countLocalObjectEffectsApplied], ["localGroupEffects", _countLocalGroupEffectsApplied], ["serverObjectEffects", _countServerObjectEffectsApplied], ["globalObjectEffects", _countGlobalObjectEffectsApplied] ] ] call EFUNC(common,log); }, [_affectedObjects, _affectedLocalGroups], GVAR(maxBrightDelay)] call CBA_fnc_waitAndExecute; // clear EMP data after 30 seconds [{ params ["_id"]; private _empData = GVAR(activeEMPs) get _id; [ LEVEL_DEBUG, QUOTE(COMPONENT), "EMP effects finished", [ ["id", _id], ["affectedObjects", count (_empData get "objects")], ["affectedLocalGroups", count (_empData get "localGroups")] ] ] call EFUNC(common,log); GVAR(activeEMPs) deleteAt _id; }, [_id], 30] call CBA_fnc_waitAndExecute; }] call CBA_fnc_addEventHandler;