2023-09-12 18:58:10 +00:00
#include "..\script_component.hpp"
2015-01-12 09:48:26 +00:00
/*
2015-02-02 08:35:17 +00:00
* Author: Garth 'L-H' de Wet
* Opens the UI for explosive detonation selection
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Trigger classname <STRING>
*
* Return Value:
* None
*
* Example:
2015-04-01 17:09:19 +00:00
* [player, "ACE_M26_Clacker"] call ACE_Explosives_fnc_addDetonateActions;
2015-02-02 08:35:17 +00:00
*
* Public: No
*/
2015-08-15 19:35:33 +00:00
params ["_unit", "_detonator"];
TRACE_2("params",_unit,_detonator);
2017-10-10 14:39:59 +00:00
private _range = getNumber (ConfigFile >> "CfgWeapons" >> _detonator >> QGVAR(Range));
2015-04-10 03:46:19 +00:00
2017-10-10 14:39:59 +00:00
private _result = [_unit] call FUNC(getPlacedExplosives);
private _children = [];
private _explosivesList = [];
2015-01-12 09:48:26 +00:00
{
2015-04-06 20:20:11 +00:00
if (!isNull(_x select 0)) then {
2017-10-10 14:39:59 +00:00
private _required = getArray (ConfigFile >> "ACE_Triggers" >> (_x select 4) >> "requires");
2015-04-06 20:20:11 +00:00
if (_detonator in _required) then {
2017-10-10 14:39:59 +00:00
private _item = ConfigFile >> "CfgMagazines" >> (_x select 3);
2015-03-31 21:20:32 +00:00
2016-01-05 22:40:27 +00:00
_explosivesList pushBack _x;
2015-04-06 20:20:11 +00:00
_children pushBack
[
[
format ["Explosive_%1", _forEachIndex],
_x select 2,
getText(_item >> "picture"),
{(_this select 2) call FUNC(detonateExplosive);},
{true},
{},
2017-05-10 16:28:44 +00:00
[_unit,_range,_x,_detonator]
2015-04-06 20:20:11 +00:00
] call EFUNC(interact_menu,createAction),
[],
2016-01-06 17:05:06 +00:00
_unit
2015-04-06 20:20:11 +00:00
];
};
};
2015-08-15 19:35:33 +00:00
} forEach _result;
2024-02-07 20:47:01 +00:00
// If the detonator is not active, is a clacker and has assigned explosives, generate an interaction to make it the active detonator for use with the "trigger all" keybind
if (
_detonator != GVAR(activeTrigger) &&
2024-06-18 14:08:03 +00:00
{_detonator != "Cellphone"} &&
2024-02-07 20:47:01 +00:00
{
_explosivesList isNotEqualTo [] ||
{_detonator == "ACE_DeadManSwitch" && {_unit getVariable [QGVAR(deadmanInvExplosive), ""] != ""}}
}
) then {
_children pushBack [
2016-01-05 22:40:27 +00:00
[
2024-02-07 20:47:01 +00:00
QGVAR(setActiveTrigger),
LLSTRING(SetActiveTrigger),
"",
{GVAR(activeTrigger) = (_this select 2) select 0;},
2016-01-05 22:40:27 +00:00
{true},
{},
2024-02-07 20:47:01 +00:00
[_detonator]
] call EFUNC(interact_menu,createAction),
[],
_unit
];
};
if (_detonator != "ACE_DeadManSwitch") then {
// Add action to detonate all explosives tied to the detonator
if (count _explosivesList > 1) then {
_children pushBack [
[
"Explosive_All",
LLSTRING(DetonateAll),
getText (configFile >> "CfgWeapons" >> _detonator >> "picture"),
{(_this select 2) call FUNC(detonateExplosiveAll);},
{true},
{},
[_unit, _range, _explosivesList, _detonator]
2016-02-05 05:55:29 +00:00
] call EFUNC(interact_menu,createAction),
[],
_unit
];
};
} else {
//Adds actions for the explosives you can connect to the deadman switch.
private _connectedInventoryExplosive = _unit getVariable [QGVAR(deadmanInvExplosive), ""];
if ((_connectedInventoryExplosive != "") && {!(_connectedInventoryExplosive in (magazines _unit))}) then {
TRACE_1("set, but missing in inventory",_connectedInventoryExplosive);
_unit setVariable [QGVAR(deadmanInvExplosive), "", true];
};
_connectedInventoryExplosive = _unit getVariable [QGVAR(deadmanInvExplosive), ""];
2024-07-25 18:34:26 +00:00
//Add action to detonate all explosives (including the inventory explosive):
if (_connectedInventoryExplosive != "" || {count _explosivesList > 1}) then {
_children pushBack [
[
"Explosive_All_Deadman",
LLSTRING(DetonateAll),
getText (configFile >> "CfgWeapons" >> _detonator >> "picture"),
{[_player] call FUNC(onIncapacitated)},
{true}
] call EFUNC(interact_menu,createAction),
[],
_unit
];
};
2016-02-05 05:55:29 +00:00
if (_connectedInventoryExplosive != "") then {
2024-02-07 20:47:01 +00:00
//Add the disconnect action
2016-02-05 05:55:29 +00:00
private _magConfig = configFile >> "CfgMagazines" >> _connectedInventoryExplosive;
2024-08-17 07:30:32 +00:00
private _name = getText (_magConfig >> "displayName");
2016-02-05 05:55:29 +00:00
private _picture = getText (_magConfig >> "picture");
_children pushBack [
2024-02-07 20:47:01 +00:00
([
"Deadman_disconnect",
format ["%1 %2", localize "str_disp_disconnect", _name],
_picture,
{
params ["_player"];
TRACE_1("clear",_player);
_player setVariable [QGVAR(deadmanInvExplosive), "", true];
},
{true}
] call EFUNC(interact_menu,createAction)),
[],
_unit
];
2016-02-05 05:55:29 +00:00
} else {
//Add all magazines that would work with the deadman switch
private _procressedMags = [];
{
private _mag = _x;
2024-06-18 14:08:03 +00:00
if !(_mag in _procressedMags) then {
2016-02-05 05:55:29 +00:00
_procressedMags pushBack _x;
private _magConfig = configFile >> "CfgMagazines" >> _mag;
private _supportedTriggers = getArray (_magConfig >> "ACE_Triggers" >> "SupportedTriggers");
if (({_x == "DeadmanSwitch"} count _supportedTriggers) == 1) then { //case insensitive search
2024-08-17 07:30:32 +00:00
private _name = getText (_magConfig >> "displayName");
2016-02-05 05:55:29 +00:00
private _picture = getText (_magConfig >> "picture");
_children pushBack [
([
format ["Deadman_exp_%1", _mag],
format [localize LSTRING(connectInventoryExplosiveToDeadman), _name],
_picture,
{
params ["_player", "", "_mag"];
TRACE_2("set new",_player,_mag);
_player setVariable [QGVAR(deadmanInvExplosive), _mag, true];
},
{(_this select 2) in (magazines _player)},
{},
(_mag)
] call EFUNC(interact_menu,createAction)), [], _unit];
};
};
} forEach (magazines _unit);
};
2016-01-05 22:40:27 +00:00
};
2015-03-31 21:20:32 +00:00
_children