diff --git a/addons/assignGear/XEH_PREP.hpp b/addons/assignGear/XEH_PREP.hpp index 8dbfc5f3..5861213e 100644 --- a/addons/assignGear/XEH_PREP.hpp +++ b/addons/assignGear/XEH_PREP.hpp @@ -3,13 +3,13 @@ TRACE_1("",QUOTE(ADDON)); PREP(addItemsToContainer); PREP(addSupplyBoxActions); PREP(assignGearMan); -PREP(assignGearSupplyBox); PREP(assignGearPotatoBox); -PREP(assignGearVehicle); +PREP(assignGearSupplyBox); PREP(assignGearVehicle_asBoxes); -PREP(cleanPrefix); +PREP(assignGearVehicle); PREP(changeableOptics_getChildren); PREP(changeableOptics_setOptic); +PREP(cleanPrefix); PREP(getContainerInfo); PREP(getDisposableInfo); // temp?? for cba change to disposable hash maps PREP(getLinkedIndex); @@ -18,4 +18,5 @@ PREP(getWeaponArray); PREP(isOpticMagnified); PREP(requestPlayerGear); PREP(setBoxContentsFromConfig); +PREP(setContainerContentsFromConfig); PREP(setWeaponAttachment); diff --git a/addons/assignGear/functions/fnc_assignGearSupplyBox.sqf b/addons/assignGear/functions/fnc_assignGearSupplyBox.sqf index ef118d4a..9869a273 100644 --- a/addons/assignGear/functions/fnc_assignGearSupplyBox.sqf +++ b/addons/assignGear/functions/fnc_assignGearSupplyBox.sqf @@ -60,7 +60,7 @@ if (_subBoxes isNotEqualTo []) then { private _subBox = createVehicle [_subBoxType, [0, 0, 0], [], 0, "CAN_COLLIDE"]; [_subBox, _x, ["%1", "%1 " + str _i] select (_boxCount > 1)] call FUNC(setBoxContentsFromConfig); [_subBox, 1] call ACEFUNC(cargo,setSize); - if !([_subBox, _theBox, true] call ace_cargo_fnc_loadItem) exitWith { + if !([_subBox, _theBox, true] call ACEFUNC(cargo,loadItem)) exitWith { diag_log formatText [ "[POTATO-assignGear] - Failed to create %1 %2 supply box(es) for %3 - out of space ", _subBoxType, diff --git a/addons/assignGear/functions/fnc_assignGearVehicle.sqf b/addons/assignGear/functions/fnc_assignGearVehicle.sqf index 1119876f..607ad3ab 100644 --- a/addons/assignGear/functions/fnc_assignGearVehicle.sqf +++ b/addons/assignGear/functions/fnc_assignGearVehicle.sqf @@ -2,6 +2,8 @@ /* * Author: PabstMirror * Applies a loadout to a vehicle + * Edited by Bailed to add option 2 + * Edited by Lambda.Tier to add option 3 and move some common code to functions * * Arguments: * 0: Vehicle @@ -27,7 +29,7 @@ TRACE_2("",GVAR(setVehicleLoadouts),_loadout); //Leave default gear when "F_Gear" is "Default" or GVAR(setVehicleLoadouts) is 0 if ((GVAR(setVehicleLoadouts) == 0) || {_loadout == "Default"}) exitWith { if (GVAR(alwaysAddToolkits)) then { _theVehicle addItemCargoGlobal ["Toolkit", 1]; }; - if (GVAR(alwaysAddLandRopes) && {(_theVehicle isKindOf "Car") || {_theVehicle isKindOf "Tank"}}) then { + if (GVAR(alwaysAddLandRopes) && {(_theVehicle isKindOf "Car") || {_theVehicle isKindOf "Tank"}}) then { _theVehicle addItemCargoGlobal ["ACE_rope15", 1]; // note: this rope is probably too short to fastrope with, so don't add to air }; }; @@ -40,7 +42,7 @@ if ((GVAR(setVehicleLoadouts) == -1) || {_loadout == "Empty"}) exitWith { clearBackpackCargoGlobal _theVehicle; //Add a Toolkit if (GVAR(alwaysAddToolkits)) then { _theVehicle addItemCargoGlobal ["Toolkit", 1]; }; - if (GVAR(alwaysAddLandRopes) && {(_theVehicle isKindOf "Car") || {_theVehicle isKindOf "Tank"}}) then { + if (GVAR(alwaysAddLandRopes) && {(_theVehicle isKindOf "Car") || {_theVehicle isKindOf "Tank"}}) then { _theVehicle addItemCargoGlobal ["ACE_rope15", 1]; }; }; @@ -74,58 +76,54 @@ if (!isClass _path) exitWith { diag_log text format ["[POTATO-assignGear] - No loadout found for %1 (typeOf %2) (kindOf %3) (defaultLoadout: %4)", _theVehicle, typeOf _theVehicle, _loadout, _defaultLoadout]; }; -//Clean out starting inventory (even if there is no class) -clearWeaponCargoGlobal _theVehicle; -clearMagazineCargoGlobal _theVehicle; -clearItemCargoGlobal _theVehicle; -clearBackpackCargoGlobal _theVehicle; -//Add a Toolkit -if (GVAR(alwaysAddToolkits)) then { _theVehicle addItemCargoGlobal ["Toolkit", 1]; }; -if (GVAR(alwaysAddLandRopes) && {(_theVehicle isKindOf "Car") || {_theVehicle isKindOf "Tank"}}) then { - _theVehicle addItemCargoGlobal ["ACE_rope15", 1]; -}; - -private _transportMagazines = getArray(_path >> "TransportMagazines"); -private _transportItems = getArray(_path >> "TransportItems"); -private _transportWeapons = getArray(_path >> "TransportWeapons"); -private _transportBackpacks = getArray(_path >> "TransportBackpacks"); - switch (GVAR(setVehicleLoadouts)) do { case 1: { // ammo in vehicle inventory - // transportMagazines - { - (_x splitString ":") params ["_classname", ["_amount", "1", [""]]]; - _theVehicle addMagazineCargoGlobal [_classname, parseNumber _amount]; - nil - } count _transportMagazines; // count used here for speed, make sure nil is above this line - - // transportItems - { - (_x splitString ":") params ["_classname", ["_amount", "1", [""]]]; - _theVehicle addItemCargoGlobal [_classname, parseNumber _amount]; - nil - } count _transportItems; // count used here for speed, make sure nil is above this line - - // transportWeapons - { - (_x splitString ":") params ["_classname", ["_amount", "1", [""]]]; - private _disposableName = [cba_disposable_LoadedLaunchers, _classname, "get", ""] call FUNC(getDisposableInfo); - if (_disposableName != "") then { - TRACE_2("cba_disposable_LoadedLaunchers replace",_classname,_disposableName); - _classname = _disposableName; - }; - _theVehicle addWeaponCargoGlobal [_classname, parseNumber _amount]; - nil - } count _transportWeapons; // count used here for speed, make sure nil is above this line - - // transportBackpacks - { - (_x splitString ":") params ["_classname", ["_amount", "1", [""]]]; - _theVehicle addBackpackCargoGlobal [_classname, parseNumber _amount]; - nil - } count _transportBackpacks; // count used here for speed, make sure nil is above this line + [_theVehicle, _path] call FUNC(setContainerContentsFromConfig); }; case 2: { // ammo in boxes in vehicle - [_theVehicle, _path, _transportMagazines, _transportItems, _transportWeapons, _transportBackpacks] call FUNC(assignGearVehicle_asBoxes); + clearWeaponCargoGlobal _theVehicle; + clearMagazineCargoGlobal _theVehicle; + clearItemCargoGlobal _theVehicle; + clearBackpackCargoGlobal _theVehicle; + [_theVehicle, _path, + getArray(_path >> "TransportMagazines"), + getArray(_path >> "TransportItems"), + getArray(_path >> "TransportWeapons"), + getArray(_path >> "TransportBackpacks")] call FUNC(assignGearVehicle_asBoxes); + }; + case 3: { // ammo in boxes in vehicle from config + clearWeaponCargoGlobal _theVehicle; + clearMagazineCargoGlobal _theVehicle; + clearItemCargoGlobal _theVehicle; + clearBackpackCargoGlobal _theVehicle; + private _boxes = "true" configClasses _path; + private _vehicleSpace = getNumber (_path >> "minVehicleBoxSpace"); + if (_vehicleSpace > 0) then { + private _currentVehicleSpace = _theVehicle getVariable [ + QACEGVAR(cargo,hasCargo), + getNumber (configOf _theVehicle >> QACEGVAR(cargo,space)) + ]; + [_theVehicle, _vehicleSpace max _currentVehicleSpace] call ACEFUNC(cargo,setSpace); + }; + { + private _boxType = configName _x; + private _boxCount = (getNumber (_x >> "boxCount")) max 1; + for "_i" from 1 to _boxCount do { + private _box = createVehicle [_boxType, [0, 0, 0], [], 0, "CAN_COLLIDE"]; + [_box, _x, ["%1", "%1 " + str _i] select (_boxCount > 1)] call FUNC(setBoxContentsFromConfig); + [_box, 1] call ACEFUNC(cargo,setSize); + if !([_box, _theVehicle, true] call ACEFUNC(cargo,loadItem)) exitWith { + diag_log text format ["[POTATO-assignGear] - Failed to create %1 supply box(es) for %2 - out of space ", _boxType, typeOf _theVehicle]; + deleteVehicle _box; + }; + _box setVariable [QGVAR(initialized), true]; + }; + } forEach _boxes; }; }; + +//Add a Toolkit +if (GVAR(alwaysAddToolkits)) then { _theVehicle addItemCargoGlobal ["Toolkit", 1]; }; +if (GVAR(alwaysAddLandRopes) && {(_theVehicle isKindOf "Car") || {_theVehicle isKindOf "Tank"}}) then { + _theVehicle addItemCargoGlobal ["ACE_rope15", 1]; +}; diff --git a/addons/assignGear/functions/fnc_setBoxContentsFromConfig.sqf b/addons/assignGear/functions/fnc_setBoxContentsFromConfig.sqf index a40f6e50..d02f336b 100644 --- a/addons/assignGear/functions/fnc_setBoxContentsFromConfig.sqf +++ b/addons/assignGear/functions/fnc_setBoxContentsFromConfig.sqf @@ -1,73 +1,33 @@ #include "script_component.hpp" /* - * Author: Bailey + * Author: Lambda.Tiger * Fills box with gear from a config - * Edited by Lambda.Tiger to add box names * * Arguments: * 0: Box - * 1: missionConfigFile path for the box's loadout + * 1: Config path for the box's loadout * 2: Optional format string for box name, must contain "%1" * * Return Value: * None * * Example: - * [cursorObject, missionConfigFile >> "CfgLoadouts" >> "SupplyBoxes" >> (typeOf cursorObject)] call potato_assignGear_fnc_setBoxContentsFromConfig + * [cursorObject, missionConfigFile >> "CfgLoadouts" >> "SupplyBoxes" >> (typeOf cursorObject), missionConfigFile >> "CfgLoadouts" >> "SupplyBox" >> (typeOf cursorObject)] call potato_assignGear_fnc_setBoxContentsFromConfig * * Public: No */ params ["_theBox", "_path", ["_nameFormatString", "%1", [""]]]; -clearWeaponCargoGlobal _theBox; -clearMagazineCargoGlobal _theBox; -clearItemCargoGlobal _theBox; -clearBackpackCargoGlobal _theBox; - -private _transportMagazines = getArray(_path >> "TransportMagazines"); -private _transportItems = getArray(_path >> "TransportItems"); -private _transportWeapons = getArray(_path >> "TransportWeapons"); -private _transportBackpacks = getArray(_path >> "TransportBackpacks"); - -// transportMagazines -{ - (_x splitString ":") params ["_classname", ["_amount", "1", [""]]]; - _theBox addMagazineCargoGlobal [_classname, parseNumber _amount]; - nil -} count _transportMagazines; // count used here for speed, make sure nil is above this line - -// transportItems -{ - (_x splitString ":") params ["_classname", ["_amount", "1", [""]]]; - _theBox addItemCargoGlobal [_classname, parseNumber _amount]; - nil -} count _transportItems; // count used here for speed, make sure nil is above this line - -// transportWeapons -{ - (_x splitString ":") params ["_classname", ["_amount", "1", [""]]]; - private _disposableName = [cba_disposable_LoadedLaunchers, _classname, "get", ""] call FUNC(getDisposableInfo); - if (_disposableName != "") then { - _classname = _disposableName; - }; - _theBox addWeaponCargoGlobal [_classname, parseNumber _amount]; - nil -} count _transportWeapons; // count used here for speed, make sure nil is above this line - -// transportBackpacks -{ - (_x splitString ":") params ["_classname", ["_amount", "1", [""]]]; - _theBox addBackpackCargoGlobal [_classname, parseNumber _amount]; - nil -} count _transportBackpacks; // count used here for speed, make sure nil is above this line +[_theBox, _path] call FUNC(setContainerContentsFromConfig); private _boxName = getText (_path >> "boxCustomName"); if (_boxName isNotEqualTo "") then { _theBox setVariable [QACEGVAR(cargo,customName), format [_nameFormatString, _boxName], true]; + _theBox setVariable [QACEGVAR(cargo,customName), format [_nameFormatString, _boxName], true]; }; private _overrideCarryWeight = 1 == (getNumber (_path >> "forceAllowCarry")); private _overrideDragWeight = 1 == (getNumber (_path >> "forceAllowDrag")); _theBox setVariable [QACEGVAR(cargo,ignoreWeightCarry), _overrideCarryWeight, true]; -_theBox setVariable [QACEGVAR(cargo,ignoreWeightDrag), _overrideCarryWeight || _overrideDragWeight, true]; \ No newline at end of file +_theBox setVariable [QACEGVAR(cargo,ignoreWeightDrag), _overrideCarryWeight || _overrideDragWeight, true]; diff --git a/addons/assignGear/functions/fnc_setContainerContentsFromConfig.sqf b/addons/assignGear/functions/fnc_setContainerContentsFromConfig.sqf new file mode 100644 index 00000000..a3fce4e9 --- /dev/null +++ b/addons/assignGear/functions/fnc_setContainerContentsFromConfig.sqf @@ -0,0 +1,61 @@ +#include "script_component.hpp" +/* + * Author: Pabst + * Fills box with gear from a config + * + * Arguments: + * 0: The container to be filled such as a vehicle or supply box + * 1: Config path for the box's loadout + * + * Return Value: + * None + * + * Example: + * [cursorObject, missionConfigFile >> "CfgLoadouts" >> "SupplyBox" >> (typeOf cursorObject)] call potato_assignGear_fnc_setContainerContentsFromConfig + * + * Public: No + */ + +params ["_theContainer", "_path"]; + +clearWeaponCargoGlobal _theContainer; +clearMagazineCargoGlobal _theContainer; +clearItemCargoGlobal _theContainer; +clearBackpackCargoGlobal _theContainer; + +private _transportMagazines = getArray(_path >> "TransportMagazines"); +private _transportItems = getArray(_path >> "TransportItems"); +private _transportWeapons = getArray(_path >> "TransportWeapons"); +private _transportBackpacks = getArray(_path >> "TransportBackpacks"); + +// transportMagazines +{ + (_x splitString ":") params ["_classname", ["_amount", "1", [""]]]; + _theContainer addMagazineCargoGlobal [_classname, parseNumber _amount]; + nil +} count _transportMagazines; // count used here for speed, make sure nil is above this line + +// transportItems +{ + (_x splitString ":") params ["_classname", ["_amount", "1", [""]]]; + _theContainer addItemCargoGlobal [_classname, parseNumber _amount]; + nil +} count _transportItems; // count used here for speed, make sure nil is above this line + +// transportWeapons +{ + (_x splitString ":") params ["_classname", ["_amount", "1", [""]]]; + private _disposableName = [cba_disposable_LoadedLaunchers, _classname, "get", ""] call FUNC(getDisposableInfo); + if (_disposableName != "") then { + _classname = _disposableName; + }; + _theContainer addWeaponCargoGlobal [_classname, parseNumber _amount]; + nil +} count _transportWeapons; // count used here for speed, make sure nil is above this line + +// transportBackpacks +{ + (_x splitString ":") params ["_classname", ["_amount", "1", [""]]]; + _theContainer addBackpackCargoGlobal [_classname, parseNumber _amount]; + nil +} count _transportBackpacks; // count used here for speed, make sure nil is above this line