diff --git a/addons/repair/ACE_Settings.hpp b/addons/repair/ACE_Settings.hpp index e956e853de..b4be91d1c3 100644 --- a/addons/repair/ACE_Settings.hpp +++ b/addons/repair/ACE_Settings.hpp @@ -61,4 +61,11 @@ class ACE_Settings { values[] = {CSTRING(engineerSetting_anyone), CSTRING(engineerSetting_EngineerOnly), CSTRING(engineerSetting_RepairSpecialistOnly)}; category = CSTRING(categoryName); }; + class GVAR(addSpareParts) { + displayName = CSTRING(addSpareParts_name); + description = CSTRING(addSpareParts_description); + typeName = "BOOL"; + value = 1; + category = CSTRING(categoryName); + }; }; diff --git a/addons/repair/CfgEventHandlers.hpp b/addons/repair/CfgEventHandlers.hpp index 27e14937cf..8a2d3e728c 100644 --- a/addons/repair/CfgEventHandlers.hpp +++ b/addons/repair/CfgEventHandlers.hpp @@ -13,31 +13,31 @@ class Extended_PostInit_EventHandlers { class Extended_Init_EventHandlers { class Car { class ADDON { - init = QUOTE(_this call DFUNC(addRepairActions)); + init = QUOTE(_this call DFUNC(addRepairActions); _this call DFUNC(addSpareParts)); }; }; class Tank { class ADDON { - init = QUOTE(_this call DFUNC(addRepairActions)); + init = QUOTE(_this call DFUNC(addRepairActions); _this call DFUNC(addSpareParts)); }; }; class Helicopter { class ADDON { - init = QUOTE(_this call DFUNC(addRepairActions)); + init = QUOTE(_this call DFUNC(addRepairActions); _this call DFUNC(addSpareParts)); }; }; class Plane { class ADDON { - init = QUOTE(_this call DFUNC(addRepairActions)); + init = QUOTE(_this call DFUNC(addRepairActions); _this call DFUNC(addSpareParts)); }; }; class Ship_F { class ADDON { - init = QUOTE(_this call DFUNC(addRepairActions)); + init = QUOTE(_this call DFUNC(addRepairActions); _this call DFUNC(addSpareParts)); }; }; class ACE_RepairItem_Base { diff --git a/addons/repair/CfgVehicles.hpp b/addons/repair/CfgVehicles.hpp index f24cd9bc9a..47cca3387b 100644 --- a/addons/repair/CfgVehicles.hpp +++ b/addons/repair/CfgVehicles.hpp @@ -91,6 +91,12 @@ class CfgVehicles { class Special { name = CSTRING(engineerSetting_RepairSpecialistOnly); value = 2; default = 1;}; }; }; + class addSpareParts { + displayName = CSTRING(addSpareParts_name); + description = CSTRING(addSpareParts_description); + typeName = "BOOL"; + defaultValue = 1; + }; }; class ModuleDescription { description = CSTRING(moduleDescription); @@ -215,19 +221,57 @@ class CfgVehicles { sync[] = {}; }; }; + class ACE_moduleAddSpareParts: Module_F { + scope = 2; + displayName = CSTRING(AddSpareParts_Module_DisplayName); + icon = QUOTE(PATHTOF(ui\Icon_Module_Repair_ca.paa)); + category = "ACE"; + function = QFUNC(moduleAddSpareParts); + functionPriority = 10; + isGlobal = 0; + isTriggerActivated = 0; + isDisposable = 0; + author = ECSTRING(common,ACETeam); + class Arguments { + class List { + displayName = CSTRING(AddSpareParts_List_DisplayName); + description = CSTRING(AddSpareParts_List_Description); + defaultValue = ""; + typeName = "STRING"; + }; + class Part { + displayName = CSTRING(AddSpareParts_Part_DisplayName); + description = CSTRING(AddSpareParts_Part_Description); + typeName = "STRING"; + class values { + class Wheel { + name = CSTRING(SpareWheel); + value = "ACE_Wheel"; + default = 1; + }; + class Track { + name = CSTRING(SpareTrack); + value = "ACE_Track"; + }; + }; + }; + class Amount { + displayName = CSTRING(AddSpareParts_Amount_DisplayName); + description = CSTRING(AddSpareParts_Amount_Description); + typeName = "NUMBER"; + defaultValue = 1; + }; + }; + class ModuleDescription { + description = CSTRING(AddSpareParts_Module_Description); + sync[] = {}; + }; + }; class LandVehicle; class Car: LandVehicle { MACRO_REPAIRVEHICLE - class ACE_Cargo { - class Cargo { - class ACE_Wheel { - type = "ACE_Wheel"; - amount = 1; - }; - }; - }; }; class Tank: LandVehicle { diff --git a/addons/repair/XEH_postInit.sqf b/addons/repair/XEH_postInit.sqf index 44ca157b0c..d61f20a31e 100644 --- a/addons/repair/XEH_postInit.sqf +++ b/addons/repair/XEH_postInit.sqf @@ -5,3 +5,17 @@ // wheels ["setWheelHitPointDamage", {(_this select 0) setHitPointDamage [_this select 1, _this select 2]}] call EFUNC(common,addEventHandler); + +if (isServer) then { + ["SettingsInitialized", { + GVAR(settingInitted) = true; // Stop collecting in FUNC(addSpareParts) + + // Exit if adding spare parts disabled + if (!GVAR(addSpareParts)) exitWith {GVAR(addSparePartsCollection) = nil}; + + // Add spare parts to vehicles in collection + { + [_x] call FUNC(addSpareParts); + } forEach GVAR(addSparePartsCollection); + }] call EFUNC(common,addEventHandler); +}; diff --git a/addons/repair/XEH_preInit.sqf b/addons/repair/XEH_preInit.sqf index ebf4c87537..28078d1b9c 100644 --- a/addons/repair/XEH_preInit.sqf +++ b/addons/repair/XEH_preInit.sqf @@ -3,6 +3,7 @@ ADDON = false; PREP(addRepairActions); +PREP(addSpareParts); PREP(canRemove); PREP(canRepair); PREP(canRepairTrack); @@ -22,6 +23,7 @@ PREP(isEngineer); PREP(isInRepairFacility); PREP(isNearRepairVehicle); PREP(isRepairVehicle); +PREP(moduleAddSpareParts); PREP(moduleAssignEngineer); PREP(moduleAssignRepairVehicle); PREP(moduleAssignRepairFacility); @@ -36,4 +38,6 @@ PREP(spawnObject); PREP(useItem); PREP(useItems); +GVAR(addSparePartsCollection) = []; + ADDON = true; diff --git a/addons/repair/functions/fnc_addSpareParts.sqf b/addons/repair/functions/fnc_addSpareParts.sqf new file mode 100644 index 0000000000..dd6588b485 --- /dev/null +++ b/addons/repair/functions/fnc_addSpareParts.sqf @@ -0,0 +1,46 @@ +/* + * Author: Jonpas + * Adds spare parts to the vehicle. Before SettingsInitialized only collect for later execution. + * + * Arguments: + * 0: Vehicle + * 1: Amount (default: 1) + * 2: Spare Part Classname (default: "") + * 3: Force (add even if setting is disabled) (default: false) + * + * Return Value: + * None + * + * Example: + * _added = [vehicle] call ace_repair_fnc_addSpareParts + * + * Public: No + */ +#include "script_component.hpp" + +private ["_part"]; +params ["_vehicle", ["_amount", 1], ["_part", ""], ["_force", false]]; +TRACE_2("params",_vehicle,_amount); + +// Exit if ace_cargo is not loaded +if !(["ace_cargo"] call EFUNC(common,isModLoaded)) exitWith {}; + +// Collect until SettingsInitialized +if (isNil QGVAR(settingInitted)) exitWith { + GVAR(addSparePartsCollection) pushBack _vehicle; +}; + +// Exit if not forced and add spare parts is disabled (after settings initted to make sure it really is) +if (!_force && !GVAR(addSpareParts)) exitWith {}; + +// Select appropriate part +if (_part == "") then { + if (_vehicle isKindOf "Car") then { _part = "ACE_Wheel" }; + if (_vehicle isKindOf "Tank") then { _part = "ACE_Track" }; +}; +// Exit if no appropriate part +if (_part == "") exitWith {}; + +// Load +//["LoadItem", [_part, _vehicle]] call EFUNC(cargo,loadItem); +[_part, _vehicle, _amount] call EFUNC(cargo,addItem); // Change to above event diff --git a/addons/repair/functions/fnc_moduleAddSpareParts.sqf b/addons/repair/functions/fnc_moduleAddSpareParts.sqf new file mode 100644 index 0000000000..46689951a7 --- /dev/null +++ b/addons/repair/functions/fnc_moduleAddSpareParts.sqf @@ -0,0 +1,61 @@ +/* + * Author: Jonpas + * Adds spare parts to a vehicle. + * + * Arguments: + * 0: The module logic + * 1: Synchronized units + * 2: Activated + * + * Return Value: + * None + * + * Example: + * function = "ace_repair_fnc_moduleAssignRepairVehicle" + * + * Public: No + */ +#define DEBUG_MODE_FULL +#include "script_component.hpp" + +params ["_logic"]; + +if (!isNull _logic) then { + private ["_list", "_part", "_amount", "_nilCheckPassedList"]; + // Module settings + _list = _logic getVariable ["List", ""]; + _part = _logic getVariable ["Part", 0]; + _amount = _logic getVariable ["Amount", 1]; + + // Parse list + _nilCheckPassedList = ""; + { + _x = [_x] call EFUNC(common,stringRemoveWhiteSpace); + if !(isnil _x) then { + if (_nilCheckPassedList == "") then { + _nilCheckPassedList = _x; + } else { + _nilCheckPassedList = _nilCheckPassedList + "," + _x; + }; + }; + } forEach ([_list, ","] call BIS_fnc_splitString); + _list = "[" + _nilCheckPassedList + "]"; + _list = [] call compile _list; + + // Add synchronized objects to list + { + _list pushBack _x; + } forEach (synchronizedObjects _logic); + + if (_list isEqualTo []) exitWith {}; + + TRACE_3("module info parsed",_list,_part,_amount); + // Add spare parts + { + if (!isNil "_x" && {typeName _x == typeName objNull}) then { + [_x, _amount, _part, true] call FUNC(addSpareParts); + }; + } forEach _list; +}; + +true diff --git a/addons/repair/functions/fnc_moduleRepairSettings.sqf b/addons/repair/functions/fnc_moduleRepairSettings.sqf index 3b97d2f168..2c7e406490 100644 --- a/addons/repair/functions/fnc_moduleRepairSettings.sqf +++ b/addons/repair/functions/fnc_moduleRepairSettings.sqf @@ -31,4 +31,6 @@ if (!isServer) exitWith {}; [_logic, QGVAR(fullRepairLocation), "fullRepairLocation"] call EFUNC(common,readSettingFromModule); [_logic, QGVAR(engineerSetting_fullRepair), "engineerSetting_fullRepair"] call EFUNC(common,readSettingFromModule); +[_logic, QGVAR(addSpareParts), "addSpareParts"] call EFUNC(common,readSettingFromModule); + diag_log text "[ACE]: Repair Module Initialized."; diff --git a/addons/repair/stringtable.xml b/addons/repair/stringtable.xml index ffafc56683..ce53e79c6d 100644 --- a/addons/repair/stringtable.xml +++ b/addons/repair/stringtable.xml @@ -104,6 +104,12 @@ Who can perform a full repair on a vehicle? + + Add Spare Parts + + + Add spare parts to vehicles (requires Cargo component)? + Repair %1 Reparieren %1 @@ -635,6 +641,32 @@ Assign one or multiple objects as a repair Facility + + + Add Spare Parts + + + Add spare parts to one or multiple objects + + + List + + + List of objects that will get spare parts added, separated by commas. + + + Part + + + Spare part. + + + Amount + + + Number of selected spare parts. + + Vehicle Repair