diff --git a/addons/pylons/XEH_postInit.sqf b/addons/pylons/XEH_postInit.sqf index 6a8f781469..0fdcaee056 100644 --- a/addons/pylons/XEH_postInit.sqf +++ b/addons/pylons/XEH_postInit.sqf @@ -15,10 +15,14 @@ GVAR(aircraftWithPylons) = (_filter configClasses (configFile >> "CfgVehicles")) if (!GVAR(enabledFromAmmoTrucks)) exitWith {false}; private _vehicles = nearestObjects [_target, ["Air", "LandVehicle", "Slingload_base_F", "ReammoBox_F"], GVAR(searchDistance) + 10]; - private _filter = ["transportAmmo", QEGVAR(rearm,defaultSupply)] select (["ace_rearm"] call EFUNC(common,isModLoaded)); - private _rearmVehicles = {(getNumber (configFile >> "CfgVehicles" >> typeOf _x >> _filter)) > 0} count _vehicles; - - (_rearmVehicles > 0 && {[ace_player, _target] call FUNC(canConfigurePylons)}) + private _isRearmVehicle = if (["ace_rearm"] call EFUNC(common,isModLoaded)) then { + _vehicles findIf {[_x] call EFUNC(rearm,isSource)} != -1; + } else { + private _cfgVehicle = configFile >> "CfgVehicles"; + _vehicles findIf {getNumber (_cfgVehicle >> typeOf _x >> "transportAmmo") > 0} != -1; + }; + + (_isRearmVehicle && {[ace_player, _target] call FUNC(canConfigurePylons)}) } ] call EFUNC(interact_menu,createAction); diff --git a/addons/rearm/Cfg3DEN.hpp b/addons/rearm/Cfg3DEN.hpp new file mode 100644 index 0000000000..05eb3c05ff --- /dev/null +++ b/addons/rearm/Cfg3DEN.hpp @@ -0,0 +1,25 @@ +#define GET_NUMBER(config,default) (if (isNumber (config)) then {getNumber (config)} else {default}) +#define DEFAULT_REARMCARGO GET_NUMBER(configFile >> 'CfgVehicles' >> typeOf _this >> QQGVAR(defaultSupply),-1) + + +class Cfg3DEN { + class Object { + class AttributeCategories { + class ace_attributes { + class Attributes { + class GVAR(rearmCargo) { + displayName = CSTRING(rearmCargo_edenName); + tooltip = CSTRING(rearmCargo_edenDesc); + property = QGVAR(rearmCargo); + control = "EditShort"; + expression = QUOTE(if (_value != DEFAULT_REARMCARGO) then {[ARR_2(_this,_value)] call DFUNC(makeSource)}); + defaultValue = QUOTE(DEFAULT_REARMCARGO); + validate = "number"; + condition = "(1-objectBrain)*(1-objectAgent)"; + typeName = "NUMBER"; + }; + }; + }; + }; + }; +}; diff --git a/addons/rearm/XEH_PREP.hpp b/addons/rearm/XEH_PREP.hpp index dc34fbd9e9..9ce5329144 100644 --- a/addons/rearm/XEH_PREP.hpp +++ b/addons/rearm/XEH_PREP.hpp @@ -21,7 +21,9 @@ PREP(handleRespawn); PREP(handleUnconscious); PREP(hasEnoughSupply); PREP(initSupplyVehicle); +PREP(isSource); PREP(makeDummy); +PREP(makeSource); PREP(moduleRearmSettings); PREP(pickUpAmmo); PREP(readSupplyCounter); diff --git a/addons/rearm/XEH_postInit.sqf b/addons/rearm/XEH_postInit.sqf index 1fd9462df8..e78f12e9f7 100644 --- a/addons/rearm/XEH_postInit.sqf +++ b/addons/rearm/XEH_postInit.sqf @@ -9,6 +9,11 @@ GVAR(configTypesAdded) = []; }] call CBA_fnc_addEventHandler; ["ace_unconscious", LINKFUNC(handleUnconscious)] call CBA_fnc_addEventHandler; +[QGVAR(initSupplyVehicle), { + TRACE_1("initSupplyVehicle EH",_this); // Warning: this can run before settings are init + [FUNC(initSupplyVehicle), _this] call EFUNC(common,runAfterSettingsInit); +}] call CBA_fnc_addEventHandler; + ["vehicle", { params ["_unit"]; [_unit] call FUNC(dropAmmo); diff --git a/addons/rearm/config.cpp b/addons/rearm/config.cpp index 8addee89d5..0a250d0ff9 100644 --- a/addons/rearm/config.cpp +++ b/addons/rearm/config.cpp @@ -17,7 +17,7 @@ class CfgPatches { #include "ACE_Settings.hpp" #include "ACE_ZeusActions.hpp" #include "CfgEventHandlers.hpp" - +#include "Cfg3DEN.hpp" #include "CfgAmmo.hpp" #include "CfgMagazines.hpp" #include "CfgVehicles.hpp" diff --git a/addons/rearm/functions/fnc_canReadSupplyCounter.sqf b/addons/rearm/functions/fnc_canReadSupplyCounter.sqf index 66ab8534bd..824eb07f78 100644 --- a/addons/rearm/functions/fnc_canReadSupplyCounter.sqf +++ b/addons/rearm/functions/fnc_canReadSupplyCounter.sqf @@ -19,10 +19,8 @@ params ["_truck", "_unit"]; (alive _unit) -&& {_unit isKindOf "CAManBase"} -&& {local _unit} && {alive _truck} && {(_truck distance _unit) < REARM_ACTION_DISTANCE} && {GVAR(supply) > 0} && {[_unit, _truck, ["IsNotInside"]] call EFUNC(common,canInteractWith)} // manually added actions need this - +&& {(_truck getVariable [QGVAR(currentSupply), 0]) >= 0} diff --git a/addons/rearm/functions/fnc_canStoreAmmo.sqf b/addons/rearm/functions/fnc_canStoreAmmo.sqf index 24d1901690..b0f22b6e07 100644 --- a/addons/rearm/functions/fnc_canStoreAmmo.sqf +++ b/addons/rearm/functions/fnc_canStoreAmmo.sqf @@ -19,9 +19,8 @@ params ["_truck", "_unit"]; (alive _unit) -&& {_unit isKindOf "CAManBase"} -&& {local _unit} && {!isNull (_unit getVariable [QGVAR(dummy), objNull])} && {alive _truck} && {(_truck distance _unit) < REARM_ACTION_DISTANCE} && {[_unit, _truck, ["IsNotInside"]] call EFUNC(common,canInteractWith)} // manually added actions need this +&& {(_truck getVariable [QGVAR(currentSupply), 0]) >= 0} diff --git a/addons/rearm/functions/fnc_canTakeAmmo.sqf b/addons/rearm/functions/fnc_canTakeAmmo.sqf index 911ffc8834..5b0a41f9b2 100644 --- a/addons/rearm/functions/fnc_canTakeAmmo.sqf +++ b/addons/rearm/functions/fnc_canTakeAmmo.sqf @@ -19,9 +19,8 @@ params ["_truck", "_unit"]; (alive _unit) -&& {_unit isKindOf "CAManBase"} -&& {local _unit} && {alive _truck} && {(_truck distance _unit) < REARM_ACTION_DISTANCE} && {isNull (_unit getVariable [QGVAR(dummy), objNull])} && {[_unit, _truck, ["IsNotInside"]] call EFUNC(common,canInteractWith)} // manually added actions need this +&& {(_truck getVariable [QGVAR(currentSupply), 0]) >= 0} diff --git a/addons/rearm/functions/fnc_initSupplyVehicle.sqf b/addons/rearm/functions/fnc_initSupplyVehicle.sqf index 9ca8728833..72b807d810 100644 --- a/addons/rearm/functions/fnc_initSupplyVehicle.sqf +++ b/addons/rearm/functions/fnc_initSupplyVehicle.sqf @@ -68,6 +68,8 @@ if (_oldRearmConfig || {_configSupply > 0}) then { WARNING_1("Actions already present on [%1]. Old Compat PBO?",_typeOf); }; } else { + if (_vehicle getVariable [QGVAR(objectActionsAdded), false]) exitWith {TRACE_1("Actions already added to object",_vehicle);}; + _vehicle setVariable [QGVAR(objectActionsAdded), true]; 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); diff --git a/addons/rearm/functions/fnc_isSource.sqf b/addons/rearm/functions/fnc_isSource.sqf new file mode 100644 index 0000000000..175ab60f8e --- /dev/null +++ b/addons/rearm/functions/fnc_isSource.sqf @@ -0,0 +1,30 @@ +#include "script_component.hpp" +/* + * Author: shukari + * Returns if vehicle or object is a rearm source. + * + * Arguments: + * 0: target + * 1: check for vanilla rearm vehicle (default: false) + * + * Return Value: + * None + * + * Example: + * [cursorObject] call ace_rearm_fnc_isSource + * + * Public: Yes + */ +params [ + ["_target", objNull, [objNull]], + ["_testVanillaRearm", false, [false]] + ]; + +if ((_target getVariable [QGVAR(currentSupply), 0]) < 0) exitWith {false}; + +private _vehCfg = configFile >> "CfgVehicles" >> typeOf _target; +private _vanillaCargoConfig = getNumber (_vehCfg >> "transportAmmo"); +private _rearmCargoConfig = getNumber (_vehCfg >> QGVAR(defaultSupply)); +private _supplyVehicle = _target getVariable [QGVAR(isSupplyVehicle), false]; + +_rearmCargoConfig > 0 || {_supplyVehicle} || {_testVanillaRearm && _vanillaCargoConfig > 0} diff --git a/addons/rearm/functions/fnc_makeSource.sqf b/addons/rearm/functions/fnc_makeSource.sqf new file mode 100644 index 0000000000..c96c3a214a --- /dev/null +++ b/addons/rearm/functions/fnc_makeSource.sqf @@ -0,0 +1,56 @@ +#include "script_component.hpp" +/* + * Author: shukari (template from refuel makeSource) + * Makes an object into a rearm source. + * Run on server only. + * + * Arguments: + * 0: Rearm Source + * 1: Rearm amount (default: 0) + * 2: add rearm amount instead of set (default: false) + * + * Return Value: + * None + * + * Example: + * [cursorObject, 1200] call ace_rearm_fnc_makeSource + * + * Public: Yes + */ +if (!isServer) exitWith {}; + +// Only run this after the settings are initialized +if !(EGVAR(common,settingsInitFinished)) exitWith { + EGVAR(common,runAtSettingsInitialized) pushBack [FUNC(makeSource), _this]; +}; + +params [ + ["_source", objNull, [objNull]], + ["_rearmCargo", 0, [0]], + ["_addToCurrent", false, [false]] + ]; +TRACE_3("makeSource",_source,_rearmCargo,_addToCurrent); + +if (isNull _source) exitWith {}; + +private _currentSupply = if (_addToCurrent) then { + _source getVariable [QGVAR(currentSupply), 0] +} else { + 0 +}; + +_source setVariable [QGVAR(currentSupply), _currentSupply + _rearmCargo, true]; + +private _rearmCargoConfig = getNumber (configFile >> "CfgVehicles" >> typeOf _source >> QGVAR(defaultSupply)); + +// already initialized because this is a config rearm vehicle +if (_rearmCargoConfig > 0 || _source getVariable [QGVAR(isSupplyVehicle), false]) exitWith {}; + +_source setVariable [QGVAR(isSupplyVehicle), true, true]; + +// check if menu already exists +if (!isNil {_source getVariable QGVAR(initSupplyVehicle_jipID)}) exitWith {}; + +private _jipID = [QGVAR(initSupplyVehicle), [_source]] call CBA_fnc_globalEventJIP; +[_jipID, _source] call CBA_fnc_removeGlobalEventJIP; +_source setVariable [QGVAR(initSupplyVehicle_jipID), _jipID]; diff --git a/addons/rearm/stringtable.xml b/addons/rearm/stringtable.xml index 9b5b19d16a..1a5c9f218f 100644 --- a/addons/rearm/stringtable.xml +++ b/addons/rearm/stringtable.xml @@ -584,5 +584,13 @@ FAB-250M-54 FAB-250M-54 + + Rearm Cargo + Munitionsvorrat + + + The cargo for rearming (-1 disable) + Der Munitionsvorrat, zum Aufmunitionieren von Fahrzeugen (-1 deaktiviert) +