From 4b1672eaa01123b9f79b3e8d2a43bd2a238fce14 Mon Sep 17 00:00:00 2001 From: Will Date: Mon, 9 Jul 2018 19:20:55 +0200 Subject: [PATCH 1/2] its now possible to set rearm vehicles in the editor && pylons now look also for non-config rearm vehicles --- addons/pylons/XEH_postInit.sqf | 12 +++-- addons/rearm/Cfg3DEN.hpp | 25 +++++++++++ addons/rearm/XEH_PREP.hpp | 2 + addons/rearm/XEH_postInit.sqf | 2 + addons/rearm/config.cpp | 2 +- addons/rearm/functions/fnc_isSource.sqf | 28 ++++++++++++ addons/rearm/functions/fnc_makeSource.sqf | 55 +++++++++++++++++++++++ addons/rearm/stringtable.xml | 8 ++++ 8 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 addons/rearm/Cfg3DEN.hpp create mode 100644 addons/rearm/functions/fnc_isSource.sqf create mode 100644 addons/rearm/functions/fnc_makeSource.sqf 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..a2deaa5595 100644 --- a/addons/rearm/XEH_postInit.sqf +++ b/addons/rearm/XEH_postInit.sqf @@ -9,6 +9,8 @@ GVAR(configTypesAdded) = []; }] call CBA_fnc_addEventHandler; ["ace_unconscious", LINKFUNC(handleUnconscious)] call CBA_fnc_addEventHandler; +[QGVAR(initSupplyVehicle), LINKFUNC(initSupplyVehicle)] call CBA_fnc_addEventHandler; + ["vehicle", { params ["_unit"]; [_unit] call FUNC(dropAmmo); diff --git a/addons/rearm/config.cpp b/addons/rearm/config.cpp index 348ca8751b..5f2f5094e7 100644 --- a/addons/rearm/config.cpp +++ b/addons/rearm/config.cpp @@ -16,7 +16,7 @@ class CfgPatches { #include "ACE_Settings.hpp" #include "CfgEventHandlers.hpp" - +#include "Cfg3DEN.hpp" #include "CfgAmmo.hpp" #include "CfgMagazines.hpp" #include "CfgVehicles.hpp" diff --git a/addons/rearm/functions/fnc_isSource.sqf b/addons/rearm/functions/fnc_isSource.sqf new file mode 100644 index 0000000000..b1aa73233b --- /dev/null +++ b/addons/rearm/functions/fnc_isSource.sqf @@ -0,0 +1,28 @@ +#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]] + ]; + +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..e1c45b5b96 --- /dev/null +++ b/addons/rearm/functions/fnc_makeSource.sqf @@ -0,0 +1,55 @@ +#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]] + ]; + +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 086ed40eaf..65f5a47213 100644 --- a/addons/rearm/stringtable.xml +++ b/addons/rearm/stringtable.xml @@ -573,5 +573,13 @@ FAB-250M-54 FAB-250M-54 + + Rearm Cargo + Munitionsvorrat + + + The cargo for rearming (-1 disable) + Der Munitionsvorrat, zum Aufmunitionieren von Fahrzeugen (-1 deaktiviert) + From d5b3696c02b82116c330f26a181fdab70fce9f5a Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 2 Nov 2018 16:56:16 -0500 Subject: [PATCH 2/2] Fix -1//disabled and JIP issues --- addons/rearm/XEH_postInit.sqf | 5 ++++- addons/rearm/functions/fnc_canReadSupplyCounter.sqf | 4 +--- addons/rearm/functions/fnc_canStoreAmmo.sqf | 3 +-- addons/rearm/functions/fnc_canTakeAmmo.sqf | 3 +-- addons/rearm/functions/fnc_initSupplyVehicle.sqf | 2 ++ addons/rearm/functions/fnc_isSource.sqf | 2 ++ addons/rearm/functions/fnc_makeSource.sqf | 1 + 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/addons/rearm/XEH_postInit.sqf b/addons/rearm/XEH_postInit.sqf index a2deaa5595..e78f12e9f7 100644 --- a/addons/rearm/XEH_postInit.sqf +++ b/addons/rearm/XEH_postInit.sqf @@ -9,7 +9,10 @@ GVAR(configTypesAdded) = []; }] call CBA_fnc_addEventHandler; ["ace_unconscious", LINKFUNC(handleUnconscious)] call CBA_fnc_addEventHandler; -[QGVAR(initSupplyVehicle), LINKFUNC(initSupplyVehicle)] 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"]; diff --git a/addons/rearm/functions/fnc_canReadSupplyCounter.sqf b/addons/rearm/functions/fnc_canReadSupplyCounter.sqf index 60ca21b3f5..7644a04bb3 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 4c4989b1d7..17e646a03d 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 c508df378d..101fb2ec0c 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 ad1b914328..cd39660b42 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 index b1aa73233b..175ab60f8e 100644 --- a/addons/rearm/functions/fnc_isSource.sqf +++ b/addons/rearm/functions/fnc_isSource.sqf @@ -20,6 +20,8 @@ params [ ["_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)); diff --git a/addons/rearm/functions/fnc_makeSource.sqf b/addons/rearm/functions/fnc_makeSource.sqf index e1c45b5b96..c96c3a214a 100644 --- a/addons/rearm/functions/fnc_makeSource.sqf +++ b/addons/rearm/functions/fnc_makeSource.sqf @@ -29,6 +29,7 @@ params [ ["_rearmCargo", 0, [0]], ["_addToCurrent", false, [false]] ]; +TRACE_3("makeSource",_source,_rearmCargo,_addToCurrent); if (isNull _source) exitWith {};