diff --git a/addons/cockpit_interaction/$PBOPREFIX$ b/addons/cockpit_interaction/$PBOPREFIX$ new file mode 100644 index 0000000000..56f155f1dd --- /dev/null +++ b/addons/cockpit_interaction/$PBOPREFIX$ @@ -0,0 +1 @@ +z\ace\addons\cockpit_interaction \ No newline at end of file diff --git a/addons/cockpit_interaction/CfgActions.hpp b/addons/cockpit_interaction/CfgActions.hpp new file mode 100644 index 0000000000..8c12c27d3f --- /dev/null +++ b/addons/cockpit_interaction/CfgActions.hpp @@ -0,0 +1,9 @@ +class CfgActions { + class None; + class EngineOn: None { + show = 0; + }; + class EngineOff: None { + show = 0; + }; +}; diff --git a/addons/cockpit_interaction/CfgEventHandlers.hpp b/addons/cockpit_interaction/CfgEventHandlers.hpp new file mode 100644 index 0000000000..1836d3bdc9 --- /dev/null +++ b/addons/cockpit_interaction/CfgEventHandlers.hpp @@ -0,0 +1,41 @@ +class Extended_PreStart_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preStart)); + }; +}; + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; + +class Extended_Init_EventHandlers { + class Air { + class ADDON { + init = QUOTE([ARR_2(_this select 0,local (_this select 0))] call FUNC(onLocal)); + }; + }; +}; + +class Extended_Engine_EventHandlers { + class Air { + class ADDON { + engine = QUOTE(_this call FUNC(onEngine)); + }; + }; +}; + +class Extended_Local_EventHandlers { + class Air { + class ADDON { + local = QUOTE(_this call FUNC(onLocal)); + }; + }; +}; diff --git a/addons/cockpit_interaction/CfgVehicles.hpp b/addons/cockpit_interaction/CfgVehicles.hpp new file mode 100644 index 0000000000..87ea4c3ade --- /dev/null +++ b/addons/cockpit_interaction/CfgVehicles.hpp @@ -0,0 +1,117 @@ +class CfgVehicles { + class Helicopter_Base_H; + class Heli_Light_01_base_F: Helicopter_Base_H { + GVAR(enabled) = 1; + + class ACE_SelfSpatialActions { + class GVAR(StarterOn) { + icon = QUOTE(PATHTOF(UI\StarterOff.paa)); + displayName = ""; + selection = ""; + position = "[0.057,1.725,-0.24]"; + distance = 1.5; + condition = QUOTE(!(_target getVariable [ARR_2(QUOTE(QGVAR(starterOn)),false)])); + statement = QUOTE([_target] call FUNC(switchStarter)); + }; + class GVAR(StarterOff) { + icon = QUOTE(PATHTOF(UI\StarterOn.paa)); + displayName = ""; + selection = ""; + position = "[0.057,1.725,-0.24]"; + distance = 1.5; + condition = QUOTE((_target getVariable [ARR_2(QUOTE(QGVAR(starterOn)),false)])); + statement = QUOTE([_target] call FUNC(switchStarter)); + }; + class GVAR(BatteryOn) { + icon = QUOTE(PATHTOF(UI\BatteryOff.paa)); + displayName = ""; + selection = ""; + position = "[-0.08,1.74,-0.01]"; + distance = 1.5; + condition = QUOTE(!(_target getVariable [ARR_2(QUOTE(QGVAR(batteryOn)),false)])); + statement = QUOTE([_target] call FUNC(switchBattery)); + }; + class GVAR(BatteryOff) { + icon = QUOTE(PATHTOF(UI\BatteryOn.paa)); + displayName = ""; + selection = ""; + position = "[-0.08,1.74,-0.01]"; + distance = 1.5; + condition = QUOTE((_target getVariable [ARR_2(QUOTE(QGVAR(batteryOn)),false)])); + statement = QUOTE([_target] call FUNC(switchBattery)); + }; + class GVAR(GeneratorOn) { + icon = QUOTE(PATHTOF(UI\GeneratorOff.paa)); + displayName = ""; + selection = ""; + position = "[-0.08,1.735,-0.05]"; + distance = 1.5; + condition = QUOTE(!(_target getVariable [ARR_2(QUOTE(QGVAR(generatorOn)),false)])); + statement = QUOTE([_target] call FUNC(switchGenerator)); + }; + class GVAR(GeneratorOff) { + icon = QUOTE(PATHTOF(UI\GeneratorOn.paa)); + displayName = ""; + selection = ""; + position = "[-0.08,1.735,-0.05]"; + distance = 1.5; + condition = QUOTE((_target getVariable [ARR_2(QUOTE(QGVAR(generatorOn)),false)])); + statement = QUOTE([_target] call FUNC(switchGenerator)); + }; + class GVAR(FuelPumpsOn) { + icon = QUOTE(PATHTOF(UI\FuelPumpsOff.paa)); + displayName = ""; + selection = ""; + position = "[-0.055,1.74,-0.015]"; + distance = 1.5; + condition = QUOTE(!(_target getVariable [ARR_2(QUOTE(QGVAR(fuelPumpsOn)),false)])); + statement = QUOTE([_target] call FUNC(switchFuelPumps)); + }; + class GVAR(FuelPumpsOff) { + icon = QUOTE(PATHTOF(UI\FuelPumpsOn.paa)); + displayName = ""; + selection = ""; + position = "[-0.055,1.74,-0.015]"; + distance = 1.5; + condition = QUOTE((_target getVariable [ARR_2(QUOTE(QGVAR(fuelPumpsOn)),false)])); + statement = QUOTE([_target] call FUNC(switchFuelPumps)); + }; + class GVAR(CollisionLightsOn) { + icon = QUOTE(PATHTOF(UI\CollisionLightsOff.paa)); + displayName = ""; + selection = ""; + position = "[-0.008,1.74,-0.015]"; + distance = 1.5; + condition = QUOTE(!(_target getVariable [ARR_2(QUOTE(QGVAR(collisionLightsOn)),false)])); + statement = QUOTE([_target] call FUNC(switchCollisionLight)); + }; + class GVAR(CollisionLightsOff) { + icon = QUOTE(PATHTOF(UI\CollisionLightsOn.paa)); + displayName = ""; + selection = ""; + position = "[-0.008,1.74,-0.015]"; + distance = 1.5; + condition = QUOTE((_target getVariable [ARR_2(QUOTE(QGVAR(collisionLightsOn)),false)])); + statement = QUOTE([_target] call FUNC(switchCollisionLight)); + }; + class GVAR(MainLightsOn) { + icon = QUOTE(PATHTOF(UI\MainLightsOff.paa)); + displayName = ""; + selection = ""; + position = "[0.054,1.735,-0.05]"; + distance = 1.5; + condition = QUOTE(!(_target getVariable [ARR_2(QUOTE(QGVAR(mainLightsOn)),false)])); + statement = QUOTE([_target] call FUNC(switchMainLight)); + }; + class GVAR(MainLightsOff) { + icon = QUOTE(PATHTOF(UI\MainLightsOn.paa)); + displayName = ""; + selection = ""; + position = "[0.054,1.735,-0.05]"; + distance = 1.5; + condition = QUOTE((_target getVariable [ARR_2(QUOTE(QGVAR(mainLightsOn)),false)])); + statement = QUOTE([_target] call FUNC(switchMainLight)); + }; + }; + }; +}; diff --git a/addons/cockpit_interaction/UI/BatteryOff.paa b/addons/cockpit_interaction/UI/BatteryOff.paa new file mode 100644 index 0000000000..15cc098f12 Binary files /dev/null and b/addons/cockpit_interaction/UI/BatteryOff.paa differ diff --git a/addons/cockpit_interaction/UI/BatteryOn.paa b/addons/cockpit_interaction/UI/BatteryOn.paa new file mode 100644 index 0000000000..4beabc7718 Binary files /dev/null and b/addons/cockpit_interaction/UI/BatteryOn.paa differ diff --git a/addons/cockpit_interaction/UI/CollisionLightsOff.paa b/addons/cockpit_interaction/UI/CollisionLightsOff.paa new file mode 100644 index 0000000000..12f4960df9 Binary files /dev/null and b/addons/cockpit_interaction/UI/CollisionLightsOff.paa differ diff --git a/addons/cockpit_interaction/UI/CollisionLightsOn.paa b/addons/cockpit_interaction/UI/CollisionLightsOn.paa new file mode 100644 index 0000000000..e9756a4e50 Binary files /dev/null and b/addons/cockpit_interaction/UI/CollisionLightsOn.paa differ diff --git a/addons/cockpit_interaction/UI/FuelPumpsOff.paa b/addons/cockpit_interaction/UI/FuelPumpsOff.paa new file mode 100644 index 0000000000..956d9346fe Binary files /dev/null and b/addons/cockpit_interaction/UI/FuelPumpsOff.paa differ diff --git a/addons/cockpit_interaction/UI/FuelPumpsOn.paa b/addons/cockpit_interaction/UI/FuelPumpsOn.paa new file mode 100644 index 0000000000..6ffd4975cd Binary files /dev/null and b/addons/cockpit_interaction/UI/FuelPumpsOn.paa differ diff --git a/addons/cockpit_interaction/UI/GeneratorOff.paa b/addons/cockpit_interaction/UI/GeneratorOff.paa new file mode 100644 index 0000000000..56a70408c9 Binary files /dev/null and b/addons/cockpit_interaction/UI/GeneratorOff.paa differ diff --git a/addons/cockpit_interaction/UI/GeneratorOn.paa b/addons/cockpit_interaction/UI/GeneratorOn.paa new file mode 100644 index 0000000000..d2bed4a1cc Binary files /dev/null and b/addons/cockpit_interaction/UI/GeneratorOn.paa differ diff --git a/addons/cockpit_interaction/UI/MainLightsOff.paa b/addons/cockpit_interaction/UI/MainLightsOff.paa new file mode 100644 index 0000000000..89db264afc Binary files /dev/null and b/addons/cockpit_interaction/UI/MainLightsOff.paa differ diff --git a/addons/cockpit_interaction/UI/MainLightsOn.paa b/addons/cockpit_interaction/UI/MainLightsOn.paa new file mode 100644 index 0000000000..34f9fa280e Binary files /dev/null and b/addons/cockpit_interaction/UI/MainLightsOn.paa differ diff --git a/addons/cockpit_interaction/UI/StarterOff.paa b/addons/cockpit_interaction/UI/StarterOff.paa new file mode 100644 index 0000000000..6c9c0e6fd8 Binary files /dev/null and b/addons/cockpit_interaction/UI/StarterOff.paa differ diff --git a/addons/cockpit_interaction/UI/StarterOn.paa b/addons/cockpit_interaction/UI/StarterOn.paa new file mode 100644 index 0000000000..347dd81af7 Binary files /dev/null and b/addons/cockpit_interaction/UI/StarterOn.paa differ diff --git a/addons/cockpit_interaction/XEH_PREP.hpp b/addons/cockpit_interaction/XEH_PREP.hpp new file mode 100644 index 0000000000..f56bca3cb6 --- /dev/null +++ b/addons/cockpit_interaction/XEH_PREP.hpp @@ -0,0 +1,11 @@ +PREP(handleActionsPFH); +PREP(onEngine); +PREP(onLocal); +PREP(switchBattery); +PREP(switchCollisionLight); +PREP(switchFuelPumps); +PREP(switchGenerator); +PREP(switchMainLight); +PREP(switchStarter); +PREP(switchStarterInternal); +PREP(updateElectricalPower); diff --git a/addons/cockpit_interaction/XEH_postInit.sqf b/addons/cockpit_interaction/XEH_postInit.sqf new file mode 100644 index 0000000000..6d9c8cd04f --- /dev/null +++ b/addons/cockpit_interaction/XEH_postInit.sqf @@ -0,0 +1,25 @@ +#include "script_component.hpp" + +[QGVAR(setEngineOn), { + params ["_vehicle", "_state"]; + _vehicle setVariable [QGVAR(engineOn), _state, true]; + _vehicle engineOn _state; +}] call EFUNC(common,addEventHandler); + +[QGVAR(setPilotLight), { + params ["_vehicle", "_state"]; + _vehicle setPilotLight _state; +}] call EFUNC(common,addEventHandler); + +[QGVAR(setCollisionLight), { + params ["_vehicle", "_state"]; + _vehicle setCollisionLight _state; +}] call EFUNC(common,addEventHandler); + +[QGVAR(simulatePowerLoss), { + params ["_vehicle"]; + _vehicle setVariable [QGVAR(engineOn), false, true]; + _vehicle engineOn false; + _vehicle setPilotLight false; + _vehicle setCollisionLight false; +}] call EFUNC(common,addEventHandler); diff --git a/addons/cockpit_interaction/XEH_preInit.sqf b/addons/cockpit_interaction/XEH_preInit.sqf new file mode 100644 index 0000000000..a7feade1c3 --- /dev/null +++ b/addons/cockpit_interaction/XEH_preInit.sqf @@ -0,0 +1,7 @@ +#include "script_component.hpp" + +ADDON = false; + +#include "XEH_PREP.hpp" + +ADDON = true; diff --git a/addons/cockpit_interaction/XEH_preStart.sqf b/addons/cockpit_interaction/XEH_preStart.sqf new file mode 100644 index 0000000000..022888575e --- /dev/null +++ b/addons/cockpit_interaction/XEH_preStart.sqf @@ -0,0 +1,3 @@ +#include "script_component.hpp" + +#include "XEH_PREP.hpp" diff --git a/addons/cockpit_interaction/config.cpp b/addons/cockpit_interaction/config.cpp new file mode 100644 index 0000000000..e4e200b74e --- /dev/null +++ b/addons/cockpit_interaction/config.cpp @@ -0,0 +1,17 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"ace_interaction"}; + author[] = {""}; + authorUrl = ""; + VERSION_CONFIG; + }; +}; + +#include "CfgActions.hpp" +#include "CfgEventHandlers.hpp" +#include "CfgVehicles.hpp" diff --git a/addons/cockpit_interaction/functions/fnc_handleActionsPFH.sqf b/addons/cockpit_interaction/functions/fnc_handleActionsPFH.sqf new file mode 100644 index 0000000000..86ecf908fa --- /dev/null +++ b/addons/cockpit_interaction/functions/fnc_handleActionsPFH.sqf @@ -0,0 +1,31 @@ +/* + * Author: BaerMitUmlaut + * PFH for handling vehicle actions. + * + * Arguments: + * 0: Aircraft + * + * Return Value: + * None + * + * Example: + * [_helo] call ace_cockpit_interaction_fnc_handleActionsPFH + * + * Public: No + */ + +#include "script_component.hpp" +params ["_arguments", "_pfhHandle"]; +_arguments params ["_vehicle"]; + +if (_vehicle getVariable [QGVAR(hasElectricalPower), false]) then { + if !((isCollisionLightOn _vehicle) isEqualTo (_vehicle getVariable [QGVAR(collisionLightsOn), false])) then { + [_vehicle] call FUNC(switchCollisionLight); + }; + if !((isLightOn _vehicle) isEqualTo (_vehicle getVariable [QGVAR(mainLightsOn), false])) then { + [_vehicle] call FUNC(switchMainLight); + }; +} else { + _vehicle setCollisionLight false; + _vehicle setPilotLight false; +}; diff --git a/addons/cockpit_interaction/functions/fnc_onEngine.sqf b/addons/cockpit_interaction/functions/fnc_onEngine.sqf new file mode 100644 index 0000000000..87fe5b6bbc --- /dev/null +++ b/addons/cockpit_interaction/functions/fnc_onEngine.sqf @@ -0,0 +1,34 @@ +/* + * Author: BaerMitUmlaut + * Disables the engine or switches the switches for AI pilots. + * + * Arguments: + * 0: Aircraft + * 1: Engine state + * + * Return Value: + * None + * + * Example: + * [_helo, true] call ace_cockpit_interaction_fnc_onEngine + * + * Public: No + */ + +#include "script_component.hpp" +params ["_vehicle", "_engineOn"]; + +if !(local _vehicle) exitWith {}; + +if (isPlayer driver _vehicle) then { + if !(_vehicle getVariable [QGVAR(engineOn), false]) then { + _vehicle engineOn false; + }; +} else { + // Flip the switches for AI pilots + _vehicle setVariable [QGVAR(engineOn), _engineOn, true]; + _vehicle setVariable [QGVAR(batteryOn), _engineOn, true]; + _vehicle setVariable [QGVAR(fuelPumpsOn), _engineOn, true]; + _vehicle setVariable [QGVAR(generatorOn), _engineOn, true]; + _vehicle setVariable [QGVAR(hasElectricalPower), _engineOn, true]; +}; diff --git a/addons/cockpit_interaction/functions/fnc_onLocal.sqf b/addons/cockpit_interaction/functions/fnc_onLocal.sqf new file mode 100644 index 0000000000..a8074f2b02 --- /dev/null +++ b/addons/cockpit_interaction/functions/fnc_onLocal.sqf @@ -0,0 +1,29 @@ +/* + * Author: BaerMitUmlaut + * Adds/removes the handleActionsPFH where the vehicle is/was local. + * + * Arguments: + * 0: Aircraft + * 1: Local + * + * Return Value: + * None + * + * Example: + * [_helo, true] call ace_cockpit_interaction_fnc_onLocal + * + * Public: No + */ + +#include "script_component.hpp" +params ["_vehicle", "_local"]; + +if !(getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> QGVAR(enabled)) == 1) exitWith {}; + +if (_local) then { + private _pfh = [FUNC(handleActionsPFH), 0, _vehicle] call CBA_fnc_addPerFrameHandler; + _vehicle setVariable [QGVAR(handleActionsPFH), _pfh]; +} else { + private _pfh = _vehicle getVariable [QGVAR(handleActionsPFH), -1]; + [_pfh] call CBA_fnc_removePerFrameHandler; +}; diff --git a/addons/cockpit_interaction/functions/fnc_switchBattery.sqf b/addons/cockpit_interaction/functions/fnc_switchBattery.sqf new file mode 100644 index 0000000000..6eb79ef011 --- /dev/null +++ b/addons/cockpit_interaction/functions/fnc_switchBattery.sqf @@ -0,0 +1,21 @@ +/* + * Author: BaerMitUmlaut + * Switches the battery of any aircraft on or off. + * + * Arguments: + * 0: Aircraft + * + * Return Value: + * None + * + * Example: + * [_helo] call ace_cockpit_interaction_fnc_switchBattery + * + * Public: No + */ + +#include "script_component.hpp" +params ["_vehicle"]; + +_vehicle setVariable [QGVAR(batteryOn), !(_vehicle getVariable [QGVAR(batteryOn), false]), true]; +[_vehicle] call FUNC(updateElectricalPower); diff --git a/addons/cockpit_interaction/functions/fnc_switchCollisionLight.sqf b/addons/cockpit_interaction/functions/fnc_switchCollisionLight.sqf new file mode 100644 index 0000000000..06c847d1fe --- /dev/null +++ b/addons/cockpit_interaction/functions/fnc_switchCollisionLight.sqf @@ -0,0 +1,24 @@ +/* + * Author: BaerMitUmlaut + * Switches the anti collision lights of any aircraft on or off. + * + * Arguments: + * 0: Aircraft + * + * Return Value: + * None + * + * Example: + * [_helo] call ace_cockpit_interaction_fnc_switchCollisionLight + * + * Public: No + */ + +#include "script_component.hpp" +params ["_vehicle"]; + +private _collisionLightsOn = _vehicle getVariable [QGVAR(collisionLightsOn), false]; +private _hasElectricalPower = _vehicle getVariable [QGVAR(hasElectricalPower), false]; + +_vehicle setVariable [QGVAR(collisionLightsOn), !_collisionLightsOn, true]; +[QGVAR(setCollisionLight), _vehicle, [_vehicle, _hasElectricalPower && !_collisionLightsOn]] call EFUNC(common,objectEvent); diff --git a/addons/cockpit_interaction/functions/fnc_switchFuelPumps.sqf b/addons/cockpit_interaction/functions/fnc_switchFuelPumps.sqf new file mode 100644 index 0000000000..82bc9f2ee0 --- /dev/null +++ b/addons/cockpit_interaction/functions/fnc_switchFuelPumps.sqf @@ -0,0 +1,29 @@ +/* + * Author: BaerMitUmlaut + * Switches the fuel pumps of any aircraft on or off. + * + * Arguments: + * 0: Aircraft + * + * Return Value: + * None + * + * Example: + * [_helo] call ace_cockpit_interaction_fnc_switchFuelPumps + * + * Public: No + */ + +#include "script_component.hpp" +params ["_vehicle"]; + +if (_vehicle getVariable [QGVAR(fuelPumpsOn), false]) then { + if (isEngineOn _vehicle) then { + [QGVAR(setEngineOn), _vehicle, [_vehicle, false]] call EFUNC(common,objectEvent); + [_vehicle] call FUNC(updateElectricalPower); + // TODO: add engine damage? + }; + _vehicle setVariable [QGVAR(fuelPumpsOn), false, true]; +} else { + _vehicle setVariable [QGVAR(fuelPumpsOn), true, true]; +}; diff --git a/addons/cockpit_interaction/functions/fnc_switchGenerator.sqf b/addons/cockpit_interaction/functions/fnc_switchGenerator.sqf new file mode 100644 index 0000000000..e2b8ed9f50 --- /dev/null +++ b/addons/cockpit_interaction/functions/fnc_switchGenerator.sqf @@ -0,0 +1,21 @@ +/* + * Author: BaerMitUmlaut + * Switches the generator of any aircraft on or off. + * + * Arguments: + * 0: Aircraft + * + * Return Value: + * None + * + * Example: + * [_helo] call ace_cockpit_interaction_fnc_switchGenerator + * + * Public: No + */ + +#include "script_component.hpp" +params ["_vehicle"]; + +_vehicle setVariable [QGVAR(generatorOn), !(_vehicle getVariable [QGVAR(generatorOn), false]), true]; +[_vehicle] call FUNC(updateElectricalPower); diff --git a/addons/cockpit_interaction/functions/fnc_switchMainLight.sqf b/addons/cockpit_interaction/functions/fnc_switchMainLight.sqf new file mode 100644 index 0000000000..f744598a15 --- /dev/null +++ b/addons/cockpit_interaction/functions/fnc_switchMainLight.sqf @@ -0,0 +1,24 @@ +/* + * Author: BaerMitUmlaut + * Switches the main lights of any aircraft on or off. + * + * Arguments: + * 0: Aircraft + * + * Return Value: + * None + * + * Example: + * [_helo] call ace_cockpit_interaction_fnc_switchMainLights + * + * Public: No + */ + +#include "script_component.hpp" +params ["_vehicle"]; + +private _mainLightsOn = _vehicle getVariable [QGVAR(mainLightsOn), false]; +private _hasElectricalPower = _vehicle getVariable [QGVAR(hasElectricalPower), false]; + +_vehicle setVariable [QGVAR(mainLightsOn), !_mainLightsOn, true]; +[QGVAR(setPilotLight), _vehicle, [_vehicle, _hasElectricalPower && !_mainLightsOn]] call EFUNC(common,objectEvent); diff --git a/addons/cockpit_interaction/functions/fnc_switchStarter.sqf b/addons/cockpit_interaction/functions/fnc_switchStarter.sqf new file mode 100644 index 0000000000..2b94b63b9d --- /dev/null +++ b/addons/cockpit_interaction/functions/fnc_switchStarter.sqf @@ -0,0 +1,24 @@ +/* + * Author: BaerMitUmlaut + * Switches the turbine starter switch of any aircraft on or off. + * + * Arguments: + * 0: Aircraft + * + * Return Value: + * None + * + * Example: + * [_helo] call ace_cockpit_interaction_fnc_switchStarter + * + * Public: No + */ + +#include "script_component.hpp" +params ["_vehicle"]; + +private _starterOn = _vehicle getVariable [QGVAR(starterOn), false]; +if (!_starterOn && {_vehicle getVariable [QGVAR(hasElectricalPower), false]}) then { + [_vehicle] call FUNC(switchStarterInternal); +}; +_vehicle setVariable [QGVAR(starterOn), !_starterOn, true]; diff --git a/addons/cockpit_interaction/functions/fnc_switchStarterInternal.sqf b/addons/cockpit_interaction/functions/fnc_switchStarterInternal.sqf new file mode 100644 index 0000000000..c45d580363 --- /dev/null +++ b/addons/cockpit_interaction/functions/fnc_switchStarterInternal.sqf @@ -0,0 +1,32 @@ +/* + * Author: BaerMitUmlaut + * Switches the turbine starter of any aircraft on or off. Internal function, disconnected from the switch. + * + * Arguments: + * 0: Aircraft + * + * Return Value: + * None + * + * Example: + * [_helo] call ace_cockpit_interaction_fnc_switchStarterInternal + * + * Public: No + */ + +#include "script_component.hpp" +params ["_vehicle"]; + +[{ + params ["_args", "_pfhID"]; + _args params ["_vehicle", "_startTime"]; + + if !(_vehicle getVariable [QGVAR(hasElectricalPower), false] && {_vehicle getVariable [QGVAR(starterOn), false]}) exitWith { + [_pfhID] call CBA_fnc_removePerFrameHandler; + }; + + if ((ACE_time - _startTime) > (5 + random 3)) exitWith { + [QGVAR(setEngineOn), _vehicle, [_vehicle, true]] call EFUNC(common,objectEvent); + [_pfhID] call CBA_fnc_removePerFrameHandler; + }; +}, 0, [_vehicle, ACE_time]] call CBA_fnc_addPerFrameHandler; diff --git a/addons/cockpit_interaction/functions/fnc_updateElectricalPower.sqf b/addons/cockpit_interaction/functions/fnc_updateElectricalPower.sqf new file mode 100644 index 0000000000..a004ce98c5 --- /dev/null +++ b/addons/cockpit_interaction/functions/fnc_updateElectricalPower.sqf @@ -0,0 +1,38 @@ +/* + * Author: BaerMitUmlaut + * Turns the electrical power of any aircraft on or off, depending on the state of + * the battery, engine and generator. + * + * Arguments: + * 0: Aircraft + * + * Return Value: + * None + * + * Example: + * [_helo] call ace_cockpit_interaction_fnc_updateElectricalPower + * + * Public: No + */ + +#include "script_component.hpp" +params ["_vehicle"]; + +if (_vehicle getVariable [QGVAR(batteryOn), false] || {(isEngineOn _vehicle) && {_vehicle getVariable [QGVAR(generatorOn), false]}}) then { + _vehicle setVariable [QGVAR(hasElectricalPower), true, true]; + if (_vehicle getVariable [QGVAR(collisionLightsOn), false]) then { + [QGVAR(setCollisionLight), _vehicle, [_vehicle, true]] call EFUNC(common,objectEvent); + }; + if (_vehicle getVariable [QGVAR(mainLightsOn), false]) then { + [QGVAR(setPilotLight), _vehicle, [_vehicle, true]] call EFUNC(common,objectEvent); + }; + if (_vehicle getVariable [QGVAR(starterOn), false]) then { + [_vehicle] call FUNC(switchStarterInternal); + }; +} else { + _vehicle setVariable [QGVAR(hasElectricalPower), false, true]; + [QGVAR(simulatePowerLoss), _vehicle, [_vehicle]] call EFUNC(common,objectEvent); + if (_vehicle getVariable [QGVAR(starterOn), false]) then { + [_vehicle] call FUNC(switchStarterInternal); + }; +}; diff --git a/addons/cockpit_interaction/functions/script_component.hpp b/addons/cockpit_interaction/functions/script_component.hpp new file mode 100644 index 0000000000..0ecb06784d --- /dev/null +++ b/addons/cockpit_interaction/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\ace\addons\cockpit_interaction\script_component.hpp" \ No newline at end of file diff --git a/addons/cockpit_interaction/script_component.hpp b/addons/cockpit_interaction/script_component.hpp new file mode 100644 index 0000000000..25349ee294 --- /dev/null +++ b/addons/cockpit_interaction/script_component.hpp @@ -0,0 +1,13 @@ +#define COMPONENT cockpit_interaction +#include "\z\ace\addons\main\script_mod.hpp" +#define DISABLE_COMPILE_CACHE + +#ifdef DEBUG_ENABLED_COCKPIT_INTERACTION + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_COCKPIT_INTERACTION + #define DEBUG_SETTINGS DEBUG_SETTINGS_COCKPIT_INTERACTION +#endif + +#include "\z\ace\addons\main\script_macros.hpp"