From d8b54a8ef04ff8a078f66d6c28c60342f0268b05 Mon Sep 17 00:00:00 2001 From: Dystopian Date: Fri, 17 Aug 2018 04:52:13 +0300 Subject: [PATCH] Fix switching non-local portable light on (#6522) --- addons/interaction/CfgVehicles.hpp | 8 ++--- addons/interaction/XEH_PREP.hpp | 1 - addons/interaction/XEH_postInit.sqf | 29 +++++++++------ .../interaction/functions/fnc_switchLamp.sqf | 35 ------------------- addons/interaction/script_component.hpp | 2 ++ 5 files changed, 24 insertions(+), 51 deletions(-) delete mode 100644 addons/interaction/functions/fnc_switchLamp.sqf diff --git a/addons/interaction/CfgVehicles.hpp b/addons/interaction/CfgVehicles.hpp index 06cf266b78c..ed208b04351 100644 --- a/addons/interaction/CfgVehicles.hpp +++ b/addons/interaction/CfgVehicles.hpp @@ -665,14 +665,14 @@ class CfgVehicles { class GVAR(TurnOn) { displayName = CSTRING(TurnOn); icon = "\A3\Ui_f\data\IGUI\Cfg\VehicleToggles\LightsIconOn_ca.paa"; - condition = QUOTE(alive _target && !(_target getVariable [ARR_2('ACE_lampOn',true)])); - statement = QUOTE(_target call DFUNC(switchLamp)); + condition = QUOTE(alive _target && !(_target getVariable [ARR_2(QQGVAR(isLightOn),true)])); + statement = QUOTE([ARR_3(QQGVAR(setLight),[ARR_2(_target,true)],_target)] call CBA_fnc_targetEvent); }; class GVAR(TurnOff) { displayName = CSTRING(TurnOff); icon = "\A3\ui_f\data\igui\cfg\actions\ico_cpt_land_OFF_ca.paa"; - condition = QUOTE(alive _target && _target getVariable [ARR_2('ACE_lampOn',true)]); - statement = QUOTE(_target call DFUNC(switchLamp)); + condition = QUOTE(alive _target && _target getVariable [ARR_2(QQGVAR(isLightOn),true)]); + statement = QUOTE([ARR_3(QQGVAR(setLight),[ARR_2(_target,false)],_target)] call CBA_fnc_targetEvent); }; }; }; diff --git a/addons/interaction/XEH_PREP.hpp b/addons/interaction/XEH_PREP.hpp index 06dd7acbe0f..ea6c275f365 100644 --- a/addons/interaction/XEH_PREP.hpp +++ b/addons/interaction/XEH_PREP.hpp @@ -43,4 +43,3 @@ PREP(canPush); PREP(push); PREP(canFlip); -PREP(switchLamp); diff --git a/addons/interaction/XEH_postInit.sqf b/addons/interaction/XEH_postInit.sqf index 3604f945116..4b97c408aae 100644 --- a/addons/interaction/XEH_postInit.sqf +++ b/addons/interaction/XEH_postInit.sqf @@ -18,17 +18,6 @@ ACE_Modifier = 0; _unit doMove _position; }] call CBA_fnc_addEventHandler; -[QGVAR(setLampOn), { - params ["_lamp", "_hitPointsDamage", "_disabledLampDMG"]; - {if((_x select 1) == _disabledLampDMG) then {_lamp setHit [_x select 0, 0];};nil} count _hitPointsDamage; -}] call CBA_fnc_addEventHandler; - -[QGVAR(setLampOff), { - params ["_lamp", "_hitPointsDamage", "_disabledLampDMG"]; - {_lamp setHit [_x select 0, (_x select 1) max _disabledLampDMG];nil} count _hitPointsDamage; -}] call CBA_fnc_addEventHandler; - - [QGVAR(flip), { params ["_vehicle"]; private _position = getPosATL _vehicle; @@ -36,6 +25,24 @@ ACE_Modifier = 0; _vehicle setPosATL _position; }] call CBA_fnc_addEventHandler; +[QGVAR(setLight), { + params ["_lamp", "_state"]; + private _hitpoints = _lamp call EFUNC(common,getReflectorsWithSelections) select 1; + { + private _damage = _lamp getHit _x; + if (_state) then { + if (_damage == DISABLED_LAMP_DAMAGE) then { + _lamp setHit [_x, 0]; + }; + } else { + if (_damage < DISABLED_LAMP_DAMAGE) then { + _lamp setHit [_x, DISABLED_LAMP_DAMAGE]; + }; + }; + } forEach _hitpoints; + _lamp setVariable [QGVAR(isLightOn), _state, true]; +}] call CBA_fnc_addEventHandler; + [QGVAR(setCollisionLight), { (_this select 0) setCollisionLight (_this select 1); }] call CBA_fnc_addEventHandler; diff --git a/addons/interaction/functions/fnc_switchLamp.sqf b/addons/interaction/functions/fnc_switchLamp.sqf deleted file mode 100644 index f1d9509de85..00000000000 --- a/addons/interaction/functions/fnc_switchLamp.sqf +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Author: SzwedzikPL - * Turn on/off lamp - * - * Arguments: - * 0: Lamp - * - * Return Value: - * None - * - * Example: - * lamp call ace_interaction_fnc_switchLamp - * - * Public: No - */ -#include "script_component.hpp" - -#define DISABLED_LAMP_DMG 0.95 - -params ["_lamp"]; - -_isOn = _lamp getVariable ["ACE_lampOn", true]; -private _reflectors = "true" configClasses (configfile >> "CfgVehicles" >> (typeof _lamp) >> "Reflectors"); -private _hitPointsDamage = []; -{ - private _hitPoint = getText (_x >> "hitpoint"); - _hitPointsDamage pushback [_hitPoint, _lamp getHit _hitPoint]; - nil -} count _reflectors; - -//if lamp is on turn it off -private _eventName = [QGVAR(setLampOn), QGVAR(setLampOff)] select _isOn; -[_eventName, [_lamp, _hitPointsDamage, DISABLED_LAMP_DMG], [_lamp]] call CBA_fnc_targetEvent; - -_lamp setVariable ["ACE_lampOn", !_isOn, true]; diff --git a/addons/interaction/script_component.hpp b/addons/interaction/script_component.hpp index bd5484992f5..e94733c456e 100644 --- a/addons/interaction/script_component.hpp +++ b/addons/interaction/script_component.hpp @@ -17,3 +17,5 @@ #include "\z\ace\addons\main\script_macros.hpp" #define MACRO_DOOR_REACH_DISTANCE (AGLToASL positionCameraToWorld [0,0,0] vectorDistance AGLToASL (ACE_player modelToWorld (ACE_player selectionPosition "Head"))) + 2 + +#define DISABLED_LAMP_DAMAGE 0.95