From 90647c5495b65362e079810c0a41c9ec6c6002c6 Mon Sep 17 00:00:00 2001 From: Dystopian Date: Mon, 18 Sep 2017 00:24:14 +0200 Subject: [PATCH] Replace Helicopter eject configs with universal scripted action (#5384) * Remove eject config entries * Add scripted Eject action * Fix engine stop on driver eject * Clean up * Use config instead object for CBA_fnc_getTurret * Optimize, add commander turret init * Restore role in var name * Use single qoutes instead QUOTE macro --- addons/aircraft/CfgEventHandlers.hpp | 17 +++++++ addons/aircraft/CfgVehicles.hpp | 44 ----------------- addons/aircraft/Heli_Attack_01_base_F.hpp | 1 - addons/aircraft/XEH_PREP.hpp | 2 + addons/aircraft/XEH_postInitClient.sqf | 29 +++++++++++ addons/aircraft/XEH_preInit.sqf | 9 ++++ addons/aircraft/XEH_preStart.sqf | 3 ++ addons/aircraft/config.cpp | 1 + .../aircraft/functions/fnc_canShowEject.sqf | 34 +++++++++++++ .../functions/fnc_initEjectAction.sqf | 48 +++++++++++++++++++ .../aircraft/functions/script_component.hpp | 1 + 11 files changed, 144 insertions(+), 45 deletions(-) create mode 100644 addons/aircraft/CfgEventHandlers.hpp create mode 100644 addons/aircraft/XEH_PREP.hpp create mode 100644 addons/aircraft/XEH_postInitClient.sqf create mode 100644 addons/aircraft/XEH_preInit.sqf create mode 100644 addons/aircraft/XEH_preStart.sqf create mode 100644 addons/aircraft/functions/fnc_canShowEject.sqf create mode 100644 addons/aircraft/functions/fnc_initEjectAction.sqf create mode 100644 addons/aircraft/functions/script_component.hpp diff --git a/addons/aircraft/CfgEventHandlers.hpp b/addons/aircraft/CfgEventHandlers.hpp new file mode 100644 index 0000000000..9426fa861e --- /dev/null +++ b/addons/aircraft/CfgEventHandlers.hpp @@ -0,0 +1,17 @@ +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 { + clientInit = QUOTE(call COMPILE_FILE(XEH_postInitClient)); + }; +}; diff --git a/addons/aircraft/CfgVehicles.hpp b/addons/aircraft/CfgVehicles.hpp index 3279d35f71..5d3d705db6 100644 --- a/addons/aircraft/CfgVehicles.hpp +++ b/addons/aircraft/CfgVehicles.hpp @@ -37,11 +37,9 @@ class CfgVehicles { class Heli_Light_01_base_F: Helicopter_Base_H { incomingMissileDetectionSystem = 16; // Vanilla: 0 - driverCanEject = 1; class Turrets: Turrets { class CopilotTurret: CopilotTurret { - canEject = 1; showHMD = 1; }; }; @@ -49,22 +47,13 @@ class CfgVehicles { class Heli_Light_01_armed_base_F: Heli_Light_01_base_F { incomingMissileDetectionSystem = 16; // Vanilla: 0 - driverCanEject = 1; - - class Turrets: Turrets { - class CopilotTurret: CopilotTurret { - canEject = 1; - }; - }; }; class Heli_Light_02_base_F: Helicopter_Base_H { - driverCanEject = 1; incomingMissileDetectionSystem = 16; // Vanilla: 24 magazines[] = {"2000Rnd_762x51_Belt_T_Green", "12Rnd_PG_missiles", "168Rnd_CMFlare_Chaff_Magazine"}; // Switch gun magazine to 7.62mm from 6.5mm class Turrets: Turrets { class CopilotTurret: CopilotTurret { - canEject = 1; showHMD = 1; }; }; @@ -80,44 +69,31 @@ class CfgVehicles { class Heli_Attack_02_base_F: Helicopter_Base_F { incomingMissileDetectionSystem = 16; // Vanilla: 24 - driverCanEject = 1; - - class Turrets: Turrets { - class MainTurret: MainTurret { - canEject = 1; - }; - }; }; class Heli_Transport_01_base_F: Helicopter_Base_H { incomingMissileDetectionSystem = 16; // Vanilla: 24 - driverCanEject = 1; class Turrets: Turrets { class CopilotTurret: CopilotTurret { - canEject = 1; showHMD = 1; }; class MainTurret: MainTurret { magazines[] = {"2000Rnd_762x51_Belt_T_Red"}; // Switch gun magazine to 7.62mm from 6.5mm - canEject = 1; }; class RightDoorGun: MainTurret { magazines[] = {"2000Rnd_762x51_Belt_T_Red"}; // Switch gun magazine to 7.62mm from 6.5mm - canEject = 1; }; }; }; class Heli_Transport_02_base_F: Helicopter_Base_H { incomingMissileDetectionSystem = 16; // Vanilla: 24 - driverCanEject = 1; class Turrets: Turrets { class CopilotTurret: CopilotTurret { - canEject = 1; showHMD = 1; }; }; @@ -126,11 +102,9 @@ class CfgVehicles { class Heli_light_03_base_F: Helicopter_Base_F { lockDetectionSystem = 0; // Vanilla: 12 incomingMissileDetectionSystem = 16; // Vanilla: 24 - driverCanEject = 1; class Turrets: Turrets { class MainTurret: MainTurret { - canEject = 1; showHMD = 1; weapons[] = {"Laserdesignator_mounted"}; // Add Laser Designator magazines[] = {"Laserbatteries"}; @@ -166,26 +140,8 @@ class CfgVehicles { class Heli_Transport_03_base_F: Helicopter_Base_H { incomingMissileDetectionSystem = 16; // Vanilla: 24 - driverCanEject = 1; - - class Turrets: Turrets { - class CopilotTurret: CopilotTurret { - canEject = 1; - }; - }; }; class Heli_Transport_04_base_F: Helicopter_Base_H { incomingMissileDetectionSystem = 16; // Vanilla: 24 - driverCanEject = 1; - - class Turrets: Turrets { - class CopilotTurret: CopilotTurret { - canEject = 1; - }; - - class LoadmasterTurret: MainTurret { - canEject = 1; - }; - }; }; }; diff --git a/addons/aircraft/Heli_Attack_01_base_F.hpp b/addons/aircraft/Heli_Attack_01_base_F.hpp index 90a417000a..7e59abad48 100644 --- a/addons/aircraft/Heli_Attack_01_base_F.hpp +++ b/addons/aircraft/Heli_Attack_01_base_F.hpp @@ -1,6 +1,5 @@ class Heli_Attack_01_base_F: Helicopter_Base_F { incomingMissileDetectionSystem = 16; // Vanilla: 24 - driverCanEject = 1; class Turrets: Turrets { class MainTurret: MainTurret { diff --git a/addons/aircraft/XEH_PREP.hpp b/addons/aircraft/XEH_PREP.hpp new file mode 100644 index 0000000000..65407a32f0 --- /dev/null +++ b/addons/aircraft/XEH_PREP.hpp @@ -0,0 +1,2 @@ +PREP(initEjectAction); +PREP(canShowEject); diff --git a/addons/aircraft/XEH_postInitClient.sqf b/addons/aircraft/XEH_postInitClient.sqf new file mode 100644 index 0000000000..e468602dbc --- /dev/null +++ b/addons/aircraft/XEH_postInitClient.sqf @@ -0,0 +1,29 @@ +#include "script_component.hpp" + +if (!hasInterface) exitWith {}; + +private _cfgAction = configFile >> "CfgActions" >> "Eject"; +GVAR(ejectActionParams) = [ + [ + "", // will be set with setUserActionText + { + params ["_vehicle", "_unit"]; + private _preserveEngineOn = (_unit == driver _vehicle) && {isEngineOn _vehicle}; + moveOut _unit; + if (_preserveEngineOn) then { + // vehicle is local to last driver, no need to care + _vehicle engineOn true; + }; + }, + nil, + getNumber (_cfgAction >> "priority"), + false, + true, + getText (_cfgAction >> "shortcut"), + '[_this, _target] call DFUNC(canShowEject)' + ], + getText (_cfgAction >> "text"), + getText (_cfgAction >> "textDefault") +]; + +["Helicopter", "initPost", LINKFUNC(initEjectAction)] call CBA_fnc_addClassEventHandler; diff --git a/addons/aircraft/XEH_preInit.sqf b/addons/aircraft/XEH_preInit.sqf new file mode 100644 index 0000000000..b47cf6628d --- /dev/null +++ b/addons/aircraft/XEH_preInit.sqf @@ -0,0 +1,9 @@ +#include "script_component.hpp" + +ADDON = false; + +PREP_RECOMPILE_START; +#include "XEH_PREP.hpp" +PREP_RECOMPILE_END; + +ADDON = true; diff --git a/addons/aircraft/XEH_preStart.sqf b/addons/aircraft/XEH_preStart.sqf new file mode 100644 index 0000000000..022888575e --- /dev/null +++ b/addons/aircraft/XEH_preStart.sqf @@ -0,0 +1,3 @@ +#include "script_component.hpp" + +#include "XEH_PREP.hpp" diff --git a/addons/aircraft/config.cpp b/addons/aircraft/config.cpp index 48bf2c054e..21b8d9b3c9 100644 --- a/addons/aircraft/config.cpp +++ b/addons/aircraft/config.cpp @@ -18,6 +18,7 @@ class CfgPatches { }; #include "CfgAmmo.hpp" +#include "CfgEventHandlers.hpp" #include "CfgMagazines.hpp" #include "CfgVehicles.hpp" #include "CfgWeapons.hpp" diff --git a/addons/aircraft/functions/fnc_canShowEject.sqf b/addons/aircraft/functions/fnc_canShowEject.sqf new file mode 100644 index 0000000000..095a787cb7 --- /dev/null +++ b/addons/aircraft/functions/fnc_canShowEject.sqf @@ -0,0 +1,34 @@ +/* + * Author: Dystopian + * Check if Eject action can be shown. + * + * Arguments: + * 0: Unit who calls action + * 1: Vehicle which action is attached to + * + * Return Value: + * Can show + * + * Example: + * [player, vehicle player] call ace_aircraft_fnc_canShowEject + * + * Public: No + */ +#include "script_component.hpp" + +#define FULLCREW_UNIT 0 +#define FULLCREW_ROLE 1 +#define FULLCREW_TURRETPATH 3 + +params ["_unit", "_vehicle"]; + +_vehicle == vehicle _unit +&& { + private _ejectVarName = ""; + { + if (_unit == _x select FULLCREW_UNIT) exitWith { + _ejectVarName = format [QGVAR(ejectAction_%1_%2), _x select FULLCREW_ROLE, _x select FULLCREW_TURRETPATH]; + }; + } count fullCrew _vehicle; + _vehicle getVariable [_ejectVarName, false] +} diff --git a/addons/aircraft/functions/fnc_initEjectAction.sqf b/addons/aircraft/functions/fnc_initEjectAction.sqf new file mode 100644 index 0000000000..94b72099ee --- /dev/null +++ b/addons/aircraft/functions/fnc_initEjectAction.sqf @@ -0,0 +1,48 @@ +/* + * Author: Dystopian + * Add Eject action to vehicle if needed. + * + * Arguments: + * 0: Vehicle + * + * Return Value: + * None + * + * Example: + * [cursorObject] call ace_aircraft_fnc_initEjectAction + * + * Public: No + */ +#include "script_component.hpp" + +params ["_vehicle"]; + +if (unitIsUAV _vehicle) exitWith {}; + +private _config = configFile >> "CfgVehicles" >> typeOf _vehicle; + +private _addAction = false; + +if (0 == getNumber (_config >> "driverCanEject")) then { + TRACE_2("eject action",typeOf _vehicle,"driver"); + _vehicle setVariable [QGVAR(ejectAction_driver_[]), true]; + _addAction = true; +}; + +{ + { + _x params ["", "_role", "", "_turretPath"]; + if (0 == getNumber (([_config, _turretPath] call CBA_fnc_getTurret) >> "canEject")) then { + TRACE_2("eject action",typeOf _vehicle,_turretPath); + _vehicle setVariable [format [QGVAR(ejectAction_%1_%2), _role, _turretPath], true]; + _addAction = true; + }; + } forEach fullCrew [_vehicle, _x, true]; +} forEach ["gunner", "commander", "turret"]; + +if (!_addAction) exitWith {}; + +GVAR(ejectActionParams) params ["_params", "_text", "_picture"]; +private _actionID = _vehicle addAction _params; +_vehicle setUserActionText [_actionID, _text, "", _picture]; +_vehicle setVariable [QGVAR(ejectAction), _actionID]; diff --git a/addons/aircraft/functions/script_component.hpp b/addons/aircraft/functions/script_component.hpp new file mode 100644 index 0000000000..8614d199c3 --- /dev/null +++ b/addons/aircraft/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\ace\addons\aircraft\script_component.hpp"