2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2017-06-08 16:47:52 +00:00
|
|
|
/*
|
|
|
|
* Author: Githawk, PabstMirror
|
|
|
|
* Adds rearm supply actions to a vehicle or ammo container.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Object <OBJECT>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [ammoTruck] call ace_rearm_fnc_initSupplyVehicle;
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2023-07-28 09:47:23 +00:00
|
|
|
if (!GVAR(enabled)) exitWith {};
|
2017-06-08 16:47:52 +00:00
|
|
|
|
|
|
|
params ["_vehicle"];
|
2023-07-28 09:47:23 +00:00
|
|
|
|
2017-06-08 16:47:52 +00:00
|
|
|
private _typeOf = typeOf _vehicle;
|
2022-03-09 03:41:21 +00:00
|
|
|
private _configOf = configOf _vehicle;
|
2017-06-08 16:47:52 +00:00
|
|
|
TRACE_2("initSupplyVehicle",_vehicle,_typeOf);
|
|
|
|
|
2023-07-28 09:47:23 +00:00
|
|
|
if (local _vehicle && {getAmmoCargo _vehicle > 0}) then {
|
|
|
|
_vehicle setAmmoCargo 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!hasInterface) exitWith {}; // For now we just add actions, so no need non-clients
|
|
|
|
|
2017-06-08 16:47:52 +00:00
|
|
|
if (!alive _vehicle) exitWith {};
|
|
|
|
|
2022-03-09 03:41:21 +00:00
|
|
|
private _configSupply = getNumber (_configOf >> QGVAR(defaultSupply));
|
2023-07-28 09:47:23 +00:00
|
|
|
if (_configSupply == 0) then {
|
2024-03-09 17:11:27 +00:00
|
|
|
_configSupply = getNumber (_configOf >> "transportAmmo");
|
2023-07-28 09:47:23 +00:00
|
|
|
};
|
2017-06-08 16:47:52 +00:00
|
|
|
private _isSupplyVehicle = _vehicle getVariable [QGVAR(isSupplyVehicle), false];
|
2022-03-09 03:41:21 +00:00
|
|
|
private _oldRearmConfig = isClass (_configOf >> "ACE_Actions" >> "ACE_MainActions" >> QGVAR(takeAmmo));
|
2017-06-08 16:47:52 +00:00
|
|
|
TRACE_3("",_configSupply,_isSupplyVehicle,_oldRearmConfig);
|
|
|
|
|
|
|
|
if ((_configSupply <= 0) && {!_isSupplyVehicle} && {!_oldRearmConfig}) exitWith {}; // Ignore if not enabled
|
|
|
|
if ((_oldRearmConfig || {_configSupply > 0}) && {_typeOf in GVAR(configTypesAdded)}) exitWith {}; // Only add class actions once
|
|
|
|
if (_oldRearmConfig || {_configSupply > 0}) then {GVAR(configTypesAdded) pushBack _typeOf};
|
|
|
|
|
|
|
|
|
|
|
|
private _actionReadSupplyCounter = [ // GVAR(supply) > 0
|
|
|
|
QGVAR(ReadSupplyCounter),
|
|
|
|
localize LSTRING(ReadSupplyCounter), // Check remaining ammunition
|
|
|
|
QPATHTOF(ui\icon_rearm_interact.paa),
|
|
|
|
{_this call FUNC(readSupplyCounter)},
|
|
|
|
{_this call FUNC(canReadSupplyCounter)}
|
|
|
|
] call EFUNC(interact_menu,createAction);
|
|
|
|
|
|
|
|
private _actionTakeAmmo = [
|
|
|
|
QGVAR(takeAmmo),
|
|
|
|
localize ([LSTRING(Rearm), LSTRING(TakeAmmo)] select (GVAR(level) > 0)),
|
|
|
|
QPATHTOF(ui\icon_rearm_interact.paa),
|
|
|
|
{},
|
|
|
|
{_this call FUNC(canTakeAmmo)},
|
|
|
|
{_this call FUNC(addRearmActions)}
|
|
|
|
] call EFUNC(interact_menu,createAction);
|
|
|
|
|
|
|
|
private _actionStoreAmmo = [
|
|
|
|
QGVAR(StoreAmmo),
|
|
|
|
localize LSTRING(StoreAmmo), // "Store ammo"
|
|
|
|
QPATHTOF(ui\icon_rearm_interact.paa),
|
|
|
|
{_this call FUNC(storeAmmo)},
|
|
|
|
{_this call FUNC(canStoreAmmo)}
|
|
|
|
] call EFUNC(interact_menu,createAction);
|
|
|
|
|
|
|
|
if (_oldRearmConfig || {_configSupply > 0}) then {
|
|
|
|
TRACE_1("Adding Class Actions",_typeOf);
|
|
|
|
[_typeOf, 0, ["ACE_MainActions"], _actionReadSupplyCounter] call EFUNC(interact_menu,addActionToClass);
|
|
|
|
if (!_oldRearmConfig) then {
|
|
|
|
[_typeOf, 0, ["ACE_MainActions"], _actionTakeAmmo] call EFUNC(interact_menu,addActionToClass);
|
|
|
|
[_typeOf, 0, ["ACE_MainActions"], _actionStoreAmmo] call EFUNC(interact_menu,addActionToClass);
|
|
|
|
} else {
|
|
|
|
WARNING_1("Actions already present on [%1]. Old Compat PBO?",_typeOf);
|
|
|
|
};
|
|
|
|
} else {
|
2018-11-02 21:56:16 +00:00
|
|
|
if (_vehicle getVariable [QGVAR(objectActionsAdded), false]) exitWith {TRACE_1("Actions already added to object",_vehicle);};
|
|
|
|
_vehicle setVariable [QGVAR(objectActionsAdded), true];
|
2017-06-08 16:47:52 +00:00
|
|
|
TRACE_1("Adding Object Actions",_typeOf);
|
|
|
|
[_vehicle, 0, ["ACE_MainActions"], _actionReadSupplyCounter] call EFUNC(interact_menu,addActionToObject);
|
|
|
|
[_vehicle, 0, ["ACE_MainActions"], _actionTakeAmmo] call EFUNC(interact_menu,addActionToObject);
|
|
|
|
[_vehicle, 0, ["ACE_MainActions"], _actionStoreAmmo] call EFUNC(interact_menu,addActionToObject);
|
|
|
|
};
|