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
This commit is contained in:
Dystopian 2017-09-18 00:24:14 +02:00 committed by jonpas
parent 45d9a3a1a9
commit 90647c5495
11 changed files with 144 additions and 45 deletions

View File

@ -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));
};
};

View File

@ -37,11 +37,9 @@ class CfgVehicles {
class Heli_Light_01_base_F: Helicopter_Base_H { class Heli_Light_01_base_F: Helicopter_Base_H {
incomingMissileDetectionSystem = 16; // Vanilla: 0 incomingMissileDetectionSystem = 16; // Vanilla: 0
driverCanEject = 1;
class Turrets: Turrets { class Turrets: Turrets {
class CopilotTurret: CopilotTurret { class CopilotTurret: CopilotTurret {
canEject = 1;
showHMD = 1; showHMD = 1;
}; };
}; };
@ -49,22 +47,13 @@ class CfgVehicles {
class Heli_Light_01_armed_base_F: Heli_Light_01_base_F { class Heli_Light_01_armed_base_F: Heli_Light_01_base_F {
incomingMissileDetectionSystem = 16; // Vanilla: 0 incomingMissileDetectionSystem = 16; // Vanilla: 0
driverCanEject = 1;
class Turrets: Turrets {
class CopilotTurret: CopilotTurret {
canEject = 1;
};
};
}; };
class Heli_Light_02_base_F: Helicopter_Base_H { class Heli_Light_02_base_F: Helicopter_Base_H {
driverCanEject = 1;
incomingMissileDetectionSystem = 16; // Vanilla: 24 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 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 Turrets: Turrets {
class CopilotTurret: CopilotTurret { class CopilotTurret: CopilotTurret {
canEject = 1;
showHMD = 1; showHMD = 1;
}; };
}; };
@ -80,44 +69,31 @@ class CfgVehicles {
class Heli_Attack_02_base_F: Helicopter_Base_F { class Heli_Attack_02_base_F: Helicopter_Base_F {
incomingMissileDetectionSystem = 16; // Vanilla: 24 incomingMissileDetectionSystem = 16; // Vanilla: 24
driverCanEject = 1;
class Turrets: Turrets {
class MainTurret: MainTurret {
canEject = 1;
};
};
}; };
class Heli_Transport_01_base_F: Helicopter_Base_H { class Heli_Transport_01_base_F: Helicopter_Base_H {
incomingMissileDetectionSystem = 16; // Vanilla: 24 incomingMissileDetectionSystem = 16; // Vanilla: 24
driverCanEject = 1;
class Turrets: Turrets { class Turrets: Turrets {
class CopilotTurret: CopilotTurret { class CopilotTurret: CopilotTurret {
canEject = 1;
showHMD = 1; showHMD = 1;
}; };
class MainTurret: MainTurret { class MainTurret: MainTurret {
magazines[] = {"2000Rnd_762x51_Belt_T_Red"}; // Switch gun magazine to 7.62mm from 6.5mm magazines[] = {"2000Rnd_762x51_Belt_T_Red"}; // Switch gun magazine to 7.62mm from 6.5mm
canEject = 1;
}; };
class RightDoorGun: MainTurret { class RightDoorGun: MainTurret {
magazines[] = {"2000Rnd_762x51_Belt_T_Red"}; // Switch gun magazine to 7.62mm from 6.5mm 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 { class Heli_Transport_02_base_F: Helicopter_Base_H {
incomingMissileDetectionSystem = 16; // Vanilla: 24 incomingMissileDetectionSystem = 16; // Vanilla: 24
driverCanEject = 1;
class Turrets: Turrets { class Turrets: Turrets {
class CopilotTurret: CopilotTurret { class CopilotTurret: CopilotTurret {
canEject = 1;
showHMD = 1; showHMD = 1;
}; };
}; };
@ -126,11 +102,9 @@ class CfgVehicles {
class Heli_light_03_base_F: Helicopter_Base_F { class Heli_light_03_base_F: Helicopter_Base_F {
lockDetectionSystem = 0; // Vanilla: 12 lockDetectionSystem = 0; // Vanilla: 12
incomingMissileDetectionSystem = 16; // Vanilla: 24 incomingMissileDetectionSystem = 16; // Vanilla: 24
driverCanEject = 1;
class Turrets: Turrets { class Turrets: Turrets {
class MainTurret: MainTurret { class MainTurret: MainTurret {
canEject = 1;
showHMD = 1; showHMD = 1;
weapons[] = {"Laserdesignator_mounted"}; // Add Laser Designator weapons[] = {"Laserdesignator_mounted"}; // Add Laser Designator
magazines[] = {"Laserbatteries"}; magazines[] = {"Laserbatteries"};
@ -166,26 +140,8 @@ class CfgVehicles {
class Heli_Transport_03_base_F: Helicopter_Base_H { class Heli_Transport_03_base_F: Helicopter_Base_H {
incomingMissileDetectionSystem = 16; // Vanilla: 24 incomingMissileDetectionSystem = 16; // Vanilla: 24
driverCanEject = 1;
class Turrets: Turrets {
class CopilotTurret: CopilotTurret {
canEject = 1;
};
};
}; };
class Heli_Transport_04_base_F: Helicopter_Base_H { class Heli_Transport_04_base_F: Helicopter_Base_H {
incomingMissileDetectionSystem = 16; // Vanilla: 24 incomingMissileDetectionSystem = 16; // Vanilla: 24
driverCanEject = 1;
class Turrets: Turrets {
class CopilotTurret: CopilotTurret {
canEject = 1;
};
class LoadmasterTurret: MainTurret {
canEject = 1;
};
};
}; };
}; };

View File

@ -1,6 +1,5 @@
class Heli_Attack_01_base_F: Helicopter_Base_F { class Heli_Attack_01_base_F: Helicopter_Base_F {
incomingMissileDetectionSystem = 16; // Vanilla: 24 incomingMissileDetectionSystem = 16; // Vanilla: 24
driverCanEject = 1;
class Turrets: Turrets { class Turrets: Turrets {
class MainTurret: MainTurret { class MainTurret: MainTurret {

View File

@ -0,0 +1,2 @@
PREP(initEjectAction);
PREP(canShowEject);

View File

@ -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;

View File

@ -0,0 +1,9 @@
#include "script_component.hpp"
ADDON = false;
PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;
ADDON = true;

View File

@ -0,0 +1,3 @@
#include "script_component.hpp"
#include "XEH_PREP.hpp"

View File

@ -18,6 +18,7 @@ class CfgPatches {
}; };
#include "CfgAmmo.hpp" #include "CfgAmmo.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgMagazines.hpp" #include "CfgMagazines.hpp"
#include "CfgVehicles.hpp" #include "CfgVehicles.hpp"
#include "CfgWeapons.hpp" #include "CfgWeapons.hpp"

View File

@ -0,0 +1,34 @@
/*
* Author: Dystopian
* Check if Eject action can be shown.
*
* Arguments:
* 0: Unit who calls action <OBJECT>
* 1: Vehicle which action is attached to <OBJECT>
*
* Return Value:
* Can show <BOOL>
*
* 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]
}

View File

@ -0,0 +1,48 @@
/*
* Author: Dystopian
* Add Eject action to vehicle if needed.
*
* Arguments:
* 0: Vehicle <OBJECT>
*
* 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];

View File

@ -0,0 +1 @@
#include "\z\ace\addons\aircraft\script_component.hpp"