From 91c6341bc85b7ee41455ac3f2a3d25be39bd8dad Mon Sep 17 00:00:00 2001 From: Githawk Date: Sat, 27 Feb 2016 20:31:07 +0100 Subject: [PATCH] Implementation --- addons/rearm/ACE_Settings.hpp | 2 +- addons/rearm/CfgVehicles.hpp | 50 +++++++++++ addons/rearm/XEH_PREP.hpp | 12 +++ .../functions/fnc_addMagazineToSupply.sqf | 64 ++++++++++++++ .../rearm/functions/fnc_addRearmActions.sqf | 39 +++++---- .../fnc_addVehicleMagazinesToSupply.sqf | 42 +++++++++ .../functions/fnc_canReadSupplyCounter.sqf | 26 ++++++ .../rearm/functions/fnc_canRearmVehicle.sqf | 26 ++++++ addons/rearm/functions/fnc_canTakeAmmo.sqf | 3 +- addons/rearm/functions/fnc_createDummy.sqf | 7 +- addons/rearm/functions/fnc_dropAmmo.sqf | 6 +- addons/rearm/functions/fnc_getCaliber.sqf | 48 +++++++++++ .../functions/fnc_getConfigMagazines.sqf | 14 +-- .../rearm/functions/fnc_getMaxMagazines.sqf | 3 +- .../functions/fnc_getNeedRearmMagazines.sqf | 7 +- addons/rearm/functions/fnc_getSupplyCount.sqf | 27 ++++++ .../functions/fnc_getVehicleMagazines.sqf | 23 +++++ .../rearm/functions/fnc_hasEnoughSupply.sqf | 39 +++++++++ .../rearm/functions/fnc_magazineInSupply.sqf | 39 +++++++++ addons/rearm/functions/fnc_pickUpAmmo.sqf | 5 +- .../rearm/functions/fnc_readSupplyCounter.sqf | 75 ++++++++++++++++ addons/rearm/functions/fnc_rearm.sqf | 35 ++------ .../functions/fnc_rearmEntireVehicle.sqf | 5 +- .../fnc_rearmEntireVehicleSuccess.sqf | 14 +-- .../fnc_rearmEntireVehicleSuccessLocal.sqf | 47 ++++++---- addons/rearm/functions/fnc_rearmSuccess.sqf | 3 +- .../rearm/functions/fnc_rearmSuccessLocal.sqf | 12 ++- .../fnc_removeMagazineFromSupply.sqf | 86 +++++++++++++++++++ addons/rearm/functions/fnc_setSupplyCount.sqf | 23 +++++ addons/rearm/functions/fnc_storeAmmo.sqf | 12 ++- addons/rearm/functions/fnc_takeAmmo.sqf | 26 +----- addons/rearm/functions/fnc_takeSuccess.sqf | 15 ++-- addons/rearm/stringtable.xml | 24 ++++++ 33 files changed, 719 insertions(+), 140 deletions(-) create mode 100644 addons/rearm/functions/fnc_addMagazineToSupply.sqf create mode 100644 addons/rearm/functions/fnc_addVehicleMagazinesToSupply.sqf create mode 100644 addons/rearm/functions/fnc_canReadSupplyCounter.sqf create mode 100644 addons/rearm/functions/fnc_canRearmVehicle.sqf create mode 100644 addons/rearm/functions/fnc_getCaliber.sqf create mode 100644 addons/rearm/functions/fnc_getSupplyCount.sqf create mode 100644 addons/rearm/functions/fnc_getVehicleMagazines.sqf create mode 100644 addons/rearm/functions/fnc_hasEnoughSupply.sqf create mode 100644 addons/rearm/functions/fnc_magazineInSupply.sqf create mode 100644 addons/rearm/functions/fnc_readSupplyCounter.sqf create mode 100644 addons/rearm/functions/fnc_removeMagazineFromSupply.sqf create mode 100644 addons/rearm/functions/fnc_setSupplyCount.sqf diff --git a/addons/rearm/ACE_Settings.hpp b/addons/rearm/ACE_Settings.hpp index 0d15701c06..fb69018436 100644 --- a/addons/rearm/ACE_Settings.hpp +++ b/addons/rearm/ACE_Settings.hpp @@ -11,6 +11,6 @@ class ACE_Settings { description = CSTRING(RearmSettings_supply_Description); value = 0; typeName = "SCALAR"; - values[] = {CSTRING(RearmSettings_unlimited), CSTRING(RearmSettings_caliber), CSTRING(RearmSettings_magazineSupply)}; + values[] = {CSTRING(RearmSettings_unlimited), CSTRING(RearmSettings_limited), CSTRING(RearmSettings_magazineSupply)}; }; }; diff --git a/addons/rearm/CfgVehicles.hpp b/addons/rearm/CfgVehicles.hpp index 30548aed76..acd8ab62a1 100644 --- a/addons/rearm/CfgVehicles.hpp +++ b/addons/rearm/CfgVehicles.hpp @@ -15,6 +15,26 @@ #define MACRO_REARM_TRUCK_ACTIONS \ class ACE_Actions : ACE_Actions { \ class ACE_MainActions : ACE_MainActions { \ + class GVAR(ReadSupplyCounter) { \ + displayName = CSTRING(ReadSupplyCounter); \ + distance = REARM_ACTION_DISTANCE; \ + condition = QUOTE(_this call FUNC(canReadSupplyCounter)); \ + statement = QUOTE(_this call FUNC(readSupplyCounter)); \ + exceptions[] = {"isNotInside"}; \ + showDisabled = 0; \ + priority = 2; \ + icon = PATHTOF(ui\icon_rearm_interact.paa); \ + }; \ + class GVAR(Rearm) { \ + displayName = CSTRING(Rearm); \ + distance = REARM_ACTION_DISTANCE; \ + condition = QUOTE(_this call FUNC(canRearmVehicle)); \ + insertChildren = QUOTE(_target call FUNC(addRearmActions)); \ + exceptions[] = {"isNotInside"}; \ + showDisabled = 0; \ + priority = 2; \ + icon = PATHTOF(ui\icon_rearm_interact.paa); \ + }; \ class GVAR(TakeAmmo) { \ displayName = CSTRING(TakeAmmo); \ distance = REARM_ACTION_DISTANCE; \ @@ -36,6 +56,9 @@ }; \ }; +#define MACRO_REARM_DEFAULT_SUPPLY \ + GVAR(defaultSupply) = 1200; + class CfgVehicles { class ACE_Module; class ACE_moduleRearmSettings : ACE_Module { @@ -69,6 +92,26 @@ class CfgVehicles { }; }; }; + class supply { + displayName = CSTRING(RearmSettings_supply_DisplayName); + description = CSTRING(RearmSettings_supply_Description); + typeName = "NUMBER"; + class values { + class unlimited { + name = CSTRING(RearmSettings_unlimited); + value = 0; + default = 1; + }; + class magazine { + name = CSTRING(RearmSettings_limited); + value = 1; + }; + class caliber { + name = CSTRING(RearmSettings_magazineSupply); + value = 2; + }; + }; + }; }; class ModuleDescription { description = CSTRING(RearmSettings_Module_Description); @@ -110,6 +153,7 @@ class CfgVehicles { class Truck_03_base_F : Truck_F {}; class O_Truck_03_ammo_F : Truck_03_base_F { transportAmmo = 0; + MACRO_REARM_DEFAULT_SUPPLY MACRO_REARM_TRUCK_ACTIONS }; @@ -117,10 +161,12 @@ class CfgVehicles { class Truck_02_Ammo_base_F : Truck_02_base_F {}; class I_Truck_02_ammo_F : Truck_02_Ammo_base_F { transportAmmo = 0; + MACRO_REARM_DEFAULT_SUPPLY MACRO_REARM_TRUCK_ACTIONS }; class O_Truck_02_Ammo_F : Truck_02_Ammo_base_F { transportAmmo = 0; + MACRO_REARM_DEFAULT_SUPPLY MACRO_REARM_TRUCK_ACTIONS }; @@ -129,6 +175,7 @@ class CfgVehicles { class B_Truck_01_mover_F : B_Truck_01_transport_F {}; class B_Truck_01_ammo_F : B_Truck_01_mover_F { transportAmmo = 0; + MACRO_REARM_DEFAULT_SUPPLY MACRO_REARM_TRUCK_ACTIONS }; @@ -137,12 +184,14 @@ class CfgVehicles { class Heli_Transport_04_base_F : Helicopter_Base_H {}; class O_Heli_Transport_04_ammo_F : Heli_Transport_04_base_F { transportAmmo = 0; + MACRO_REARM_DEFAULT_SUPPLY MACRO_REARM_TRUCK_ACTIONS }; class Pod_Heli_Transport_04_base_F: StaticWeapon {}; class Land_Pod_Heli_Transport_04_ammo_F: Pod_Heli_Transport_04_base_F { transportAmmo = 0; + MACRO_REARM_DEFAULT_SUPPLY MACRO_REARM_TRUCK_ACTIONS }; @@ -161,6 +210,7 @@ class CfgVehicles { class B_Slingload_01_Ammo_F : Slingload_01_Base_F { XEH_ENABLED; transportAmmo = 0; + MACRO_REARM_DEFAULT_SUPPLY MACRO_REARM_TRUCK_ACTIONS }; diff --git a/addons/rearm/XEH_PREP.hpp b/addons/rearm/XEH_PREP.hpp index 8e3c10cd2c..03e08fd4b0 100644 --- a/addons/rearm/XEH_PREP.hpp +++ b/addons/rearm/XEH_PREP.hpp @@ -1,26 +1,38 @@ +PREP(addMagazineToSupply); PREP(addRearmActions); +PREP(addVehicleMagazinesToSupply); +PREP(canReadSupplyCounter); PREP(canRearm); +PREP(canRearmVehicle); PREP(canStoreAmmo); PREP(canTakeAmmo); PREP(createDummy); PREP(disable); PREP(dropAmmo); +PREP(getCaliber); PREP(getConfigMagazines); PREP(getMaxMagazines); PREP(getNeedRearmMagazines); +PREP(getSupplyCount); +PREP(getVehicleMagazines); PREP(grabAmmo); PREP(handleKilled); PREP(handleUnconscious); +PREP(hasEnoughSupply); +PREP(magazineInSupply); PREP(makeDummy); PREP(moduleRearmSettings); PREP(pickUpAmmo); +PREP(readSupplyCounter); PREP(rearm); PREP(rearmEntireVehicle); PREP(rearmEntireVehicleSuccess); PREP(rearmEntireVehicleSuccessLocal); PREP(rearmSuccess); PREP(rearmSuccessLocal); +PREP(removeMagazineFromSupply); +PREP(setSupplyCount); PREP(storeAmmo); PREP(takeAmmo); PREP(takeSuccess); diff --git a/addons/rearm/functions/fnc_addMagazineToSupply.sqf b/addons/rearm/functions/fnc_addMagazineToSupply.sqf new file mode 100644 index 0000000000..781af9e2f4 --- /dev/null +++ b/addons/rearm/functions/fnc_addMagazineToSupply.sqf @@ -0,0 +1,64 @@ +/* + * Author: GitHawk + * Adds magazines to the supply. + * + * Argument: + * 0: Target + * 1: Magazine Classname + * 2: Only partial + * + * Return value: + * None + * + * Example: + * [ammo_truck, "32Rnd_155mm_Mo_shells"] call ace_rearm_fnc_addMagazineToSupply + * + * Public: Yes + */ +#include "script_component.hpp" + +params [["_target", objNull, [objNull]], ["_magazineClass", "", [""]], ["_partial", false, [false]]]; + +if (isNull _target || + {_magazineClass isEqualTo ""} || + {GVAR(supply) == 0}) exitWith {}; + +// With limited supply, we add the caliber to the supply count +if (GVAR(supply) == 1) then { + private _supply = [_target] call FUNC(getSupplyCount); + ([_magazineClass] call FUNC(getCaliber)) params ["_cal", "_idx"]; + if (!_partial || {GVAR(level) == 1}) then { + [_target, _supply + _cal] call FUNC(setSupplyCount); + } else { + private _magazinePart = ((REARM_COUNT select _idx) / (getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count"))) min 1; + [_target, (_supply + (_cal * _magazinePart))] call FUNC(setSupplyCount); + }; +}; + +// With magazine specific supply, we add or update the magazineSupply array +if (GVAR(supply) == 2) then { + private _magazineSupply = _target getVariable [QGVAR(magazineSupply), []]; + private _magazineIdx = -1; + { + _x params ["_magazine", "_rounds"]; + if ((_magazine isEqualTo _magazineClass)) exitWith { + _magazineIdx = _forEachIndex; + }; + } forEach _magazineSupply; + + private _roundsPerTransaction = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count"); + if (_partial) then { + _roundsPerTransaction = _roundsPerTransaction min (REARM_COUNT select _idx); + }; + if (_magazineIdx == -1) then { + if (count _magazineSupply == 0) then { + _magazineSupply = [[_magazineClass, _roundsPerTransaction]]; + } else { + _magazineSupply append [[_magazineClass, _roundsPerTransaction]]; + } + } else { + (_magazineSupply select _magazineIdx) params ["", "_rounds"]; + _magazineSupply set [_magazineIdx, [_magazineClass, (_rounds + _roundsPerTransaction)]]; + }; + _target setVariable [QGVAR(magazineSupply), _magazineSupply, true]; +}; diff --git a/addons/rearm/functions/fnc_addRearmActions.sqf b/addons/rearm/functions/fnc_addRearmActions.sqf index 6040fd6fc5..b2b388a3fd 100644 --- a/addons/rearm/functions/fnc_addRearmActions.sqf +++ b/addons/rearm/functions/fnc_addRearmActions.sqf @@ -15,25 +15,24 @@ */ #include "script_component.hpp" -private ["_vehicleActions", "_actions", "_action", "_vehicles", "_vehicle", "_needToAdd", "_magazineHelper", "_turretPath", "_magazines", "_magazine", "_icon", "_cnt"]; params [["_target", objNull, [objNull]]]; -_vehicles = nearestObjects [_target, ["AllVehicles"], 20]; +private _vehicles = nearestObjects [_target, ["AllVehicles"], 20]; if (count _vehicles < 2) exitWith {false}; // Rearming needs at least 2 vehicles -_vehicleActions = []; +private _vehicleActions = []; { - _actions = []; - _vehicle = _x; - _needToAdd = false; - _action = []; + private _actions = []; + private _vehicle = _x; + private _needToAdd = false; + private _action = []; if !((_vehicle == _target) || (_vehicle isKindOf "CAManBase")) then { - _magazineHelper = []; + private _magazineHelper = []; { - _turretPath = _x; - _magazines = [_vehicle, _turretPath] call FUNC(getConfigMagazines); + private _turretPath = _x; + private _magazines = [_vehicle, _turretPath] call FUNC(getVehicleMagazines); { - _magazine = _x; + private _magazine = _x; _currentMagazines = { _x == _magazine } count (_vehicle magazinesTurret _turretPath); if ((_currentMagazines < ([_vehicle, _turretPath, _magazine] call FUNC(getMaxMagazines))) && !(_magazine in _magazineHelper)) then { _action = [_magazine, @@ -43,9 +42,11 @@ _vehicleActions = []; {true}, {}, [_magazine, _vehicle]] call EFUNC(interact_menu,createAction); - _actions pushBack [_action, [], _target]; - _magazineHelper pushBack _magazine; - _needToAdd = true; + if (GVAR(supply) == 0 || {(GVAR(supply) == 1) && ([_target, _magazine] call FUNC(hasEnoughSupply))} || {(GVAR(supply) == 2) && ([_target, _magazine] call FUNC(magazineInSupply))}) then { + _actions pushBack [_action, [], _target]; + _magazineHelper pushBack _magazine; + _needToAdd = true; + }; } else { if (((_vehicle magazineTurretAmmo [_magazine, _turretPath]) < getNumber (configFile >> "CfgMagazines" >> _magazine >> "count")) && !(_magazine in _magazineHelper)) then { _action = [_magazine, @@ -55,16 +56,18 @@ _vehicleActions = []; {true}, {}, [_magazine, _vehicle]] call EFUNC(interact_menu,createAction); - _actions pushBack [_action, [], _target]; - _magazineHelper pushBack _magazine; - _needToAdd = true; + if (GVAR(supply) == 0 || {(GVAR(supply) == 1) && ([_target, _magazine] call FUNC(hasEnoughSupply))} || {(GVAR(supply) == 2) && ([_target, _magazine] call FUNC(magazineInSupply))}) then { + _actions pushBack [_action, [], _target]; + _magazineHelper pushBack _magazine; + _needToAdd = true; + }; }; }; } forEach _magazines; } forEach REARM_TURRET_PATHS; }; if (_needToAdd && !(_vehicle getVariable [QGVAR(disabled), false])) then { - _icon = getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "Icon"); + private _icon = getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "Icon"); if !((_icon select [0, 1]) == "\") then { _icon = ""; }; diff --git a/addons/rearm/functions/fnc_addVehicleMagazinesToSupply.sqf b/addons/rearm/functions/fnc_addVehicleMagazinesToSupply.sqf new file mode 100644 index 0000000000..17ec5494d1 --- /dev/null +++ b/addons/rearm/functions/fnc_addVehicleMagazinesToSupply.sqf @@ -0,0 +1,42 @@ +/* + * Author: GitHawk + * Adds all magazines of a vehicle to the supply. + * + * Argument: + * 0: Ammo Truck + * 1: Vehicle + * or + * 0: Ammo Truck + * 1: Vehicle class + * + * Return value: + * None + * + * Example: + * [ammo_truck, tank] call ace_rearm_fnc_addVehicleMagazinesToSupply + * [ammo_truck, "B_MBT_01_arty_F"] call ace_rearm_fnc_addVehicleMagazinesToSupply + * + * Public: Yes + */ +#include "script_component.hpp" + +params [["_ammoTruck", objNull, [objNull]], ["_vehicle", objNull, [objNull, ""]]]; + +if (isNull _ammoTruck || + {typeName _vehicle == "OBJECT" && {isNull _vehicle}}) exitWith {}; + +private _string = ""; +if (typeName _vehicle == "OBJECT") then { + _string = typeOf _vehicle; +}; +if (typeName _vehicle == "STRING") then { + _string = _vehicle; +}; +if (_string == "") exitWith {[]}; +{ + private _turretPath = _x; + private _magazines = [_string, _turretPath] call FUNC(getConfigMagazines); + { + [_ammoTruck, _x] call FUNC(addMagazineToSupply); + } forEach _magazines; +} forEach REARM_TURRET_PATHS; diff --git a/addons/rearm/functions/fnc_canReadSupplyCounter.sqf b/addons/rearm/functions/fnc_canReadSupplyCounter.sqf new file mode 100644 index 0000000000..f6991c1c27 --- /dev/null +++ b/addons/rearm/functions/fnc_canReadSupplyCounter.sqf @@ -0,0 +1,26 @@ +/* + * Author: GitHawk + * Checks if unit can read supply counter. + * + * Arguments: + * 0: Ammo Truck + * 1: Unit + * + * Return Value: + * Can read supply counter + * + * Example: + * [truck, player] call ace_rearm_fnc_canReadSupplyCounter + * + * Public: No + */ +#include "script_component.hpp" + +params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]]]; + +!(isNull _unit || + {!(_unit isKindOf "CAManBase")} || + {!local _unit} || + {!alive _target} || + {(_target distance _unit) > REARM_ACTION_DISTANCE} || + {GVAR(supply) == 0}) diff --git a/addons/rearm/functions/fnc_canRearmVehicle.sqf b/addons/rearm/functions/fnc_canRearmVehicle.sqf new file mode 100644 index 0000000000..29de8b2a2c --- /dev/null +++ b/addons/rearm/functions/fnc_canRearmVehicle.sqf @@ -0,0 +1,26 @@ +/* + * Author: GitHawk + * Check if a unit can rearm a vehicle. + * + * Arguments: + * 0: Target + * 1: Unit + * + * Return Value: + * Can Pick Up Ammo + * + * Example: + * [player, tank] call ace_rearm_fnc_canRearmVehicle + * + * Public: No + */ +#include "script_component.hpp" + +params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]]]; + +!(isNull _unit || + {!(_unit isKindOf "CAManBase")} || + {!local _unit} || + {(_target distance _unit) > REARM_ACTION_DISTANCE} || + {!isNull (_unit getVariable [QGVAR(dummy), objNull])} || + {GVAR(level) > 0}) diff --git a/addons/rearm/functions/fnc_canTakeAmmo.sqf b/addons/rearm/functions/fnc_canTakeAmmo.sqf index 496e7a12a4..2bb4676c4f 100644 --- a/addons/rearm/functions/fnc_canTakeAmmo.sqf +++ b/addons/rearm/functions/fnc_canTakeAmmo.sqf @@ -22,4 +22,5 @@ params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]]]; {!(_unit isKindOf "CAManBase")} || {!local _unit} || {(_target distance _unit) > REARM_ACTION_DISTANCE} || - {!isNull (_unit getVariable [QGVAR(dummy), objNull])}) + {!isNull (_unit getVariable [QGVAR(dummy), objNull])} || + {GVAR(level) == 0}) diff --git a/addons/rearm/functions/fnc_createDummy.sqf b/addons/rearm/functions/fnc_createDummy.sqf index 38955fb806..d2fbdec4c0 100644 --- a/addons/rearm/functions/fnc_createDummy.sqf +++ b/addons/rearm/functions/fnc_createDummy.sqf @@ -16,12 +16,11 @@ */ #include "script_component.hpp" -private ["_ammo", "_dummyName", "_dummy"]; params [["_unit", objNull, [objNull]], ["_magazineClass", "", [""]]]; -_ammo = getText (configFile >> "CfgMagazines" >> _magazineClass >> "ammo"); -_dummyName = getText (configFile >> "CfgAmmo" >> _ammo >> QGVAR(dummy)); -_dummy = objNull; +private _ammo = getText (configFile >> "CfgMagazines" >> _magazineClass >> "ammo"); +private _dummyName = getText (configFile >> "CfgAmmo" >> _ammo >> QGVAR(dummy)); +private _dummy = objNull; if !(_dummyName == "") then { _dummy = _dummyName createVehicle (position _unit); } else { diff --git a/addons/rearm/functions/fnc_dropAmmo.sqf b/addons/rearm/functions/fnc_dropAmmo.sqf index 48433c2f4a..1634a76c00 100644 --- a/addons/rearm/functions/fnc_dropAmmo.sqf +++ b/addons/rearm/functions/fnc_dropAmmo.sqf @@ -17,10 +17,9 @@ */ #include "script_component.hpp" -private ["_dummy", "_actionID"]; params [["_unit", objNull, [objNull]], ["_delete", false, [false]], ["_unholster", true, [true]]]; -_dummy = _unit getVariable [QGVAR(dummy), objNull]; +private _dummy = _unit getVariable [QGVAR(dummy), objNull]; if !(isNull _dummy) then { detach _dummy; if (_delete) then { @@ -29,9 +28,8 @@ if !(isNull _dummy) then { _dummy setVelocity [0,0,-0.1]; }; _unit setVariable [QGVAR(dummy), objNull]; - //_unit setVariable [QEGVAR(dragging,isCarrying), false, true]; // breaks things, since it hides interact menu on _target }; -_actionID = _unit getVariable [QGVAR(ReleaseActionID), -1]; +private _actionID = _unit getVariable [QGVAR(ReleaseActionID), -1]; if (_actionID != -1) then { _unit removeAction _actionID; _unit setVariable [QGVAR(ReleaseActionID), nil]; diff --git a/addons/rearm/functions/fnc_getCaliber.sqf b/addons/rearm/functions/fnc_getCaliber.sqf new file mode 100644 index 0000000000..fad222a571 --- /dev/null +++ b/addons/rearm/functions/fnc_getCaliber.sqf @@ -0,0 +1,48 @@ +/* + * Author: GitHawk + * Check whether enough supply is left to take the magazine. + * + * Argument: + * 0: Magazine Classname + * + * Return value: + * 0: Caliber information + * 0: Rounded caliber + * 1: Caliber index + * + * Example: + * ["500Rnd_127x99_mag_Tracer_Red"] call ace_rearm_fnc_hasEnoughSupply + * + * Public: No + */ +#include "script_component.hpp" + +params [["_magazineClass", "", [""]]]; + +if (_magazineClass isEqualTo "") exitWith {[8, 2]}; + +private _ammo = getText (configFile >> "CfgMagazines" >> _magazineClass >> "ammo"); +private _tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ace_caliber"); +private _cal = 8; +if (_tmpCal > 0) then { + _cal = _tmpCal; +} else { + _tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(caliber)); + if (_tmpCal > 0) then { + _cal = _tmpCal; + } else { + diag_log format ["[ACE] ERROR: Undefined Ammo [%1 : %2]", _ammo, inheritsFrom (configFile >> "CfgAmmo" >> _ammo)]; + if (_ammo isKindOf "BulletBase") then { + _cal = 8; + } else { + _cal = 100; + }; + }; +}; +_cal = round _cal; +private _idx = REARM_CALIBERS find _cal; +if (_idx == -1 ) then { + _idx = 2; +}; + +[_cal, _idx] diff --git a/addons/rearm/functions/fnc_getConfigMagazines.sqf b/addons/rearm/functions/fnc_getConfigMagazines.sqf index dce6c5da64..6fb9dcebfe 100644 --- a/addons/rearm/functions/fnc_getConfigMagazines.sqf +++ b/addons/rearm/functions/fnc_getConfigMagazines.sqf @@ -3,30 +3,32 @@ * Returns all magazines a turret can hold according to config. * * Arguments: - * 0: Target + * 0: Vehicle class * 1: Turret Path * * Return Value: * Magazine classes in TurretPath * * Example: - * [vehicle, [0]] call ace_rearm_fnc_getConfigMagazines + * ["B_MBT_01_arty_F", [0]] call ace_rearm_fnc_getVehicleMagazines * * Public: No */ #include "script_component.hpp" -params [["_target", objNull, [objNull]], ["_turretPath", [], [[]]]]; +params [["_cfgString", "", [""]], ["_turretPath", [], [[]]]]; -if (isNull _target) exitWith {[]}; +if (_cfgString == "") exitWith {[]}; -_cfg = configFile >> "CfgVehicles" >> (typeOf _target) >> "Turrets"; +private _cfg = configFile >> "CfgVehicles" >> _cfgString >> "Turrets"; + +if !(isClass _cfg) exitWith {[]}; if (count _turretPath == 1) then { _turretPath params ["_subPath"]; if (_subPath == -1) exitWith { - _cfg = configFile >> "CfgVehicles" >> (typeOf _target); + _cfg = configFile >> "CfgVehicles" >> _cfgString; }; if (count _cfg > _subPath) then { diff --git a/addons/rearm/functions/fnc_getMaxMagazines.sqf b/addons/rearm/functions/fnc_getMaxMagazines.sqf index b6211333f0..729f9e405a 100644 --- a/addons/rearm/functions/fnc_getMaxMagazines.sqf +++ b/addons/rearm/functions/fnc_getMaxMagazines.sqf @@ -17,10 +17,9 @@ */ #include "script_component.hpp" -private ["_count", "_cfg"]; params [["_target", objNull, [objNull]], ["_turretPath", [], [[]]], ["_magazineClass", "", [""]]]; if (isNull _target) exitWith {0}; -_count = {_x == _magazineClass} count ([_target, _turretPath] call FUNC(getConfigMagazines)); +private _count = {_x == _magazineClass} count ([_target, _turretPath] call FUNC(getVehicleMagazines)); _count diff --git a/addons/rearm/functions/fnc_getNeedRearmMagazines.sqf b/addons/rearm/functions/fnc_getNeedRearmMagazines.sqf index f56b437708..ee4c3d4876 100644 --- a/addons/rearm/functions/fnc_getNeedRearmMagazines.sqf +++ b/addons/rearm/functions/fnc_getNeedRearmMagazines.sqf @@ -19,15 +19,14 @@ */ #include "script_component.hpp" -private ["_return", "_magazines", "_currentMagazines"]; params ["_target", "_magazineClass"]; -_return = [false, [], 0]; +private _return = [false, [], 0]; { - _magazines = [_target, _x] call FUNC(getConfigMagazines); + private _magazines = [_target, _x] call FUNC(getVehicleMagazines); if (_magazineClass in _magazines) then { - _currentMagazines = {_x == _magazineClass} count (_target magazinesTurret _x); + private _currentMagazines = {_x == _magazineClass} count (_target magazinesTurret _x); if ((_target magazineTurretAmmo [_magazineClass, _x]) < getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count")) exitWith { _return = [true, _x, _currentMagazines]; diff --git a/addons/rearm/functions/fnc_getSupplyCount.sqf b/addons/rearm/functions/fnc_getSupplyCount.sqf new file mode 100644 index 0000000000..e2f881380e --- /dev/null +++ b/addons/rearm/functions/fnc_getSupplyCount.sqf @@ -0,0 +1,27 @@ +/* + * Author: GitHawk + * Get the supply count. + * + * Argument: + * 0: Target + * + * Return value: + * Supply count + * + * Example: + * [ammo_truck] call ace_rearm_fnc_getSupplyCount + * + * Public: Yes + */ +#include "script_component.hpp" + +params [["_target", objNull, [objNull]]]; + +private _supply = _target getVariable QGVAR(currentSupply); + +if (isNil "_supply") then { + _supply = getNumber (configFile >> "CfgVehicles" >> typeOf _target >> QGVAR(defaultSupply)); + _target setVariable [QGVAR(currentSupply), _supply, true]; +}; + +_supply diff --git a/addons/rearm/functions/fnc_getVehicleMagazines.sqf b/addons/rearm/functions/fnc_getVehicleMagazines.sqf new file mode 100644 index 0000000000..abc0a761a7 --- /dev/null +++ b/addons/rearm/functions/fnc_getVehicleMagazines.sqf @@ -0,0 +1,23 @@ +/* + * Author: GitHawk, Jonpas + * Returns all magazines a turret can hold according to config. + * + * Arguments: + * 0: Target + * 1: Turret Path + * + * Return Value: + * Magazine classes in TurretPath + * + * Example: + * [vehicle, [0]] call ace_rearm_fnc_getVehicleMagazines + * + * Public: No + */ +#include "script_component.hpp" + +params [["_target", objNull, [objNull]], ["_turretPath", [], [[]]]]; + +if (isNull _target) exitWith {[]}; + +([typeOf _target, _turretPath] call FUNC(getConfigMagazines)) diff --git a/addons/rearm/functions/fnc_hasEnoughSupply.sqf b/addons/rearm/functions/fnc_hasEnoughSupply.sqf new file mode 100644 index 0000000000..8caf0f3f45 --- /dev/null +++ b/addons/rearm/functions/fnc_hasEnoughSupply.sqf @@ -0,0 +1,39 @@ +/* + * Author: GitHawk + * Check whether enough supply is left to take the magazine. + * + * Argument: + * 0: Target + * 1: Magazine Classname + * + * Return value: + * Enough supply + * + * Example: + * [ammo_truck, "500Rnd_127x99_mag_Tracer_Red"] call ace_rearm_fnc_hasEnoughSupply + * + * Public: No + */ +#include "script_component.hpp" + +params [["_target", objNull, [objNull]], ["_magazineClass", "", [""]]]; + +if (isNull _target || + {_magazineClass isEqualTo ""}) exitWith {false}; + +// With infinite supply, there is always enough +if (GVAR(supply) == 0) exitWith {true}; +// With magazine specific supply, we need to check stored magazines +if (GVAR(supply) == 2) exitWith {_this call FUNC(magazineInSupply)}; + +private _supply = [_target] call FUNC(getSupplyCount); +([_magazineClass] call FUNC(getCaliber)) params ["_cal", "_idx"]; + +// With caliber based rearming, we only need partial supply +if (GVAR(level) == 2) exitWith { + // If REARM_COUNT is bigger than the magazine size, we might get a bigger number than 1 + private _magazinePart = ((REARM_COUNT select _idx) / (getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count"))) min 1; + (_cal * _magazinePart <= _supply) +}; + +(_cal <= _supply) diff --git a/addons/rearm/functions/fnc_magazineInSupply.sqf b/addons/rearm/functions/fnc_magazineInSupply.sqf new file mode 100644 index 0000000000..a11ab8c25e --- /dev/null +++ b/addons/rearm/functions/fnc_magazineInSupply.sqf @@ -0,0 +1,39 @@ +/* + * Author: GitHawk + * Returns true if the magazine is in the current supply + * + * Argument: + * 0: Target + * 1: Magazine Classname + * + * Return value: + * Magazine in supply + * + * Example: + * [ammo_truck, "500Rnd_127x99_mag_Tracer_Red"] call ace_rearm_fnc_magazineInSupply + * + * Public: No + */ +#include "script_component.hpp" + +params [["_target", objNull, [objNull]], ["_magazineClass", "", [""]]]; + +if (isNull _target || + {_magazineClass isEqualTo ""}) exitWith {false}; + +// With limited supply, we need to check supply +if (GVAR(supply) == 1) exitWith {_this call FUNC(hasEnoughSupply)}; +// With magazine specific supply, we need to check them +if (GVAR(supply) == 2) exitWith { + private _magazineSupply = _target getVariable [QGVAR(magazineSupply), []]; + private _magazinePresent = false; + { + _x params ["_magazine", "_rounds"]; + if ((_magazine isEqualTo _magazineClass) && (_rounds > 0)) exitWith {_magazinePresent = true; }; + false + } count _magazineSupply; + _magazinePresent +}; + +// With infinite supply, the is always one left +true diff --git a/addons/rearm/functions/fnc_pickUpAmmo.sqf b/addons/rearm/functions/fnc_pickUpAmmo.sqf index 546fc318b7..ac1ab0a00a 100644 --- a/addons/rearm/functions/fnc_pickUpAmmo.sqf +++ b/addons/rearm/functions/fnc_pickUpAmmo.sqf @@ -16,16 +16,13 @@ */ #include "script_component.hpp" -private ["_magazineClass"]; params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]]]; -_dummy = _unit getVariable [QGVAR(dummy), objNull]; +private _dummy = _unit getVariable [QGVAR(dummy), objNull]; if !(isNull _dummy) exitWith {}; -//_target attachTo [_unit, [0,0.7,0], "pelvis"]; _target attachTo [_unit, [0,1,0], "pelvis"]; { [[_target, [[-1,0,0],[0,0,1]]], QFUNC(makeDummy), _x] call EFUNC(common,execRemoteFnc); } count (position _unit nearObjects ["CAManBase", 100]); _unit setVariable [QGVAR(dummy), _target]; -//_unit setVariable [QEGVAR(dragging,isCarrying), true, true]; // breaks things, since it hides interact menu on _target diff --git a/addons/rearm/functions/fnc_readSupplyCounter.sqf b/addons/rearm/functions/fnc_readSupplyCounter.sqf new file mode 100644 index 0000000000..4c96e926c6 --- /dev/null +++ b/addons/rearm/functions/fnc_readSupplyCounter.sqf @@ -0,0 +1,75 @@ +/* + * Author: GitHawk + * Get the remaining fuel amount + * + * Arguments: + * 0: Ammo Truck + * 1: Unit + * + * Return Value: + * None + * + * Example: + * [ammo_truck, player] call ace_rearm_fnc_readSupplyCounter + * + * Public: No + */ +#include "script_component.hpp" + +params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]]]; + +if (GVAR(supply) == 0) exitWith {}; + +if (GVAR(supply) == 1) then { + [ + 5, + [_unit, _target, [_target] call FUNC(getSupplyCount)], + { + params ["_args"]; + _args params [["_unit", objNull, [objNull]], ["_target", objNull, [objNull]], ["_supplyCount", 0, [0]]]; + if (_supplyCount > 0 ) then { + ["displayTextStructured", [_unit], [[LSTRING(Hint_RemainingSupplyPoints), _supplyCount], 2, _unit]] call EFUNC(common,targetEvent); + } else { + ["displayTextStructured", [_unit], [LSTRING(Hint_EmptySupplyPoints), 2, _unit]] call EFUNC(common,targetEvent); + }; + true + }, + {true}, + localize LSTRING(ReadSupplyCounterAction), + {true}, + ["isnotinside"] + ] call EFUNC(common,progressBar); +} else { + [ + 5, + [_unit, _target], + { + params ["_args"]; + _args params [["_unit", objNull, [objNull]], ["_target", objNull, [objNull]]]; + private _supply = 1.5; + private _numChars = count (localize LSTRING(Hint_RemainingAmmo)); + private _text = ""; + private _magazines = _target getVariable QGVAR(magazineSupply); + if !(isNil "_magazines") then { + { + _x params ["_magazineClass", "_rounds"]; + private _line = format ["%1: %2", getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"), _rounds]; + _numChars = _numChars max (count _line); + _text = format ["%1
%2", _text, _line]; + _supply = _supply + 0.5; + } forEach _magazines; + diag_log _text; + }; + if (_supply > 1.5) then { + ["displayTextStructured", [_unit], [[LSTRING(Hint_RemainingAmmo), _text], _supply, _unit, (_numChars/2.9)]] call EFUNC(common,targetEvent); + } else { + ["displayTextStructured", [_unit], [LSTRING(Hint_Empty), 2, _unit]] call EFUNC(common,targetEvent); + }; + true + }, + {true}, + localize LSTRING(ReadSupplyCounterAction), + {true}, + ["isnotinside"] + ] call EFUNC(common,progressBar); +}; diff --git a/addons/rearm/functions/fnc_rearm.sqf b/addons/rearm/functions/fnc_rearm.sqf index 61009b085d..7ea08596e5 100644 --- a/addons/rearm/functions/fnc_rearm.sqf +++ b/addons/rearm/functions/fnc_rearm.sqf @@ -15,40 +15,17 @@ */ #include "script_component.hpp" -private ["_magazineClass", "_ammo", "_tmpCal", "_cal", "_idx", "_needRearmMags", "_magazineDisplayName"]; params [["_unit", objNull, [objNull]]]; -_dummy = _unit getVariable [QGVAR(dummy), objNull]; +private _dummy = _unit getVariable [QGVAR(dummy), objNull]; if (isNull _dummy) exitwith {false}; -_magazineClass = _dummy getVariable QGVAR(magazineClass); +private _magazineClass = _dummy getVariable QGVAR(magazineClass); if (isNil "_magazineClass") exitWith {false}; -_ammo = getText (configFile >> "CfgMagazines" >> _magazineClass >> "ammo"); -_tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ace_caliber"); -_cal = 8; -if (_tmpCal > 0) then { - _cal = _tmpCal; -} else { - _tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(caliber)); - if (_tmpCal > 0) then { - _cal = _tmpCal; - } else { - diag_log format ["[ACE] ERROR: Undefined Ammo [%1 : %2]", _ammo, inheritsFrom (configFile >> "CfgAmmo" >> _ammo)]; - if (_ammo isKindOf "BulletBase") then { - _cal = 8; - } else { - _cal = 100; - }; - }; -}; -_cal = round _cal; -_idx = REARM_CALIBERS find _cal; -if (_idx == -1) then { - _idx = 2; -}; +([_magazineClass] call FUNC(getCaliber)) params ["_cal", "_idx"]; // Get magazines that can be rearmed -_needRearmMags = [_target, _magazineClass] call FUNC(getNeedRearmMagazines); +private _needRearmMags = [_target, _magazineClass] call FUNC(getNeedRearmMagazines); _needRearmMags params ["_needRearm", "_turretPath", "_cnt"]; // Exit if no magazines need rearming @@ -56,9 +33,7 @@ if (!_needRearm) exitWith { diag_log format ["[ACE] ERROR: Could not find turret for %1 in %2", _magazineClass, typeOf _target]; }; -//hint format ["Magazine: %1\nAmmo: %2\nCaliber: %3\nIndex: %4\nTurretPath: %5\nREARM_DURATION_REARM: %6\nCount: %7", _magazine, _ammo, _cal, _idx, _turretPath, (REARM_DURATION_REARM select _idx), (REARM_COUNT select _idx)]; - -_magazineDisplayName = getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"); +private _magazineDisplayName = getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"); if (_magazineDisplayName == "") then { _magazineDisplayName = _magazineClass; diag_log format ["[ACE] ERROR: Magazine is missing display name [%1]", _magazineClass]; diff --git a/addons/rearm/functions/fnc_rearmEntireVehicle.sqf b/addons/rearm/functions/fnc_rearmEntireVehicle.sqf index 27fd20c528..4c8076f5f8 100644 --- a/addons/rearm/functions/fnc_rearmEntireVehicle.sqf +++ b/addons/rearm/functions/fnc_rearmEntireVehicle.sqf @@ -16,11 +16,12 @@ * Public: No */ #include "script_component.hpp" -params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]], ["_vehicle", objNull, [objNull]]]; // _target is for future possible finite ammo, _unit placeholder + +params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]], ["_vehicle", objNull, [objNull]]]; [ 10, - _vehicle, + [_target, _vehicle], FUNC(rearmEntireVehicleSuccess), "", format [localize LSTRING(BasicRearmAction), getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], diff --git a/addons/rearm/functions/fnc_rearmEntireVehicleSuccess.sqf b/addons/rearm/functions/fnc_rearmEntireVehicleSuccess.sqf index c12286516c..1e1e58c86a 100644 --- a/addons/rearm/functions/fnc_rearmEntireVehicleSuccess.sqf +++ b/addons/rearm/functions/fnc_rearmEntireVehicleSuccess.sqf @@ -3,28 +3,30 @@ * Rearm an entire vehicle. * * Arguments: - * 0: Vehicle + * 0: Rearm information + * 0: Target + * 1: Vehicle - * 1: TurretPath + * 0: Target + * 1: Vehicle + * 2: TurretPath * * Return Value: * None * * Example: - * [tank, [0]] call ace_rearm_fnc_rearmEntireVehicleSuccessLocal + * [ammo_truck, tank, [0]] call ace_rearm_fnc_rearmEntireVehicleSuccessLocal * * Public: No */ #include "script_component.hpp" -private ["_magazines", "_magazine", "_currentMagazines", "_maxMagazines", "_maxRounds", "_currentRounds"]; -params [["_vehicle", objNull, [objNull]], ["_turretPath", [], [[]]]]; +params [["_target", objNull, [objNull]], ["_vehicle", objNull, [objNull]], ["_turretPath", [], [[]]]]; -_magazines = [_vehicle, _turretPath] call FUNC(getConfigMagazines); +private _magazines = [_vehicle, _turretPath] call FUNC(getVehicleMagazines); +if (isNil "_magazines") exitWith {}; { - _magazine = _x; - _currentMagazines = { _x == _magazine } count (_vehicle magazinesTurret _turretPath); - _maxMagazines = [_vehicle, _turretPath, _magazine] call FUNC(getMaxMagazines); - _maxRounds = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count"); - _currentRounds = _vehicle magazineTurretAmmo [_magazine, _turretPath]; + private _magazine = _x; + private _currentMagazines = { _x == _magazine } count (_vehicle magazinesTurret _turretPath); + private _maxMagazines = [_vehicle, _turretPath, _magazine] call FUNC(getMaxMagazines); + private _maxRounds = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count"); + private _currentRounds = _vehicle magazineTurretAmmo [_magazine, _turretPath]; TRACE_7("Rearmed Turret",_vehicle,_turretPath,_currentMagazines,_maxMagazines,_currentRounds,_maxRounds,_magazine); @@ -34,11 +35,27 @@ _magazines = [_vehicle, _turretPath] call FUNC(getConfigMagazines); _currentMagazines = _currentMagazines + 1; }; if (_currentMagazines < _maxMagazines) then { - _vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath]; - for "_idx" from 1 to (_maxMagazines - _currentMagazines) do { - _vehicle addMagazineTurret [_magazine, _turretPath]; + private _success = true; + if (GVAR(supply) > 0) then { + _success = [_target, _magazine, (_maxRounds - _currentRounds)] call FUNC(removeMagazineFromSupply); + }; + if (_success) then { + _vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath]; + for "_idx" from 1 to (_maxMagazines - _currentMagazines) do { + _success = true; + if (GVAR(supply) > 0) then { + _success = [_target, _magazine, _maxRounds] call FUNC(removeMagazineFromSupply); + }; + _vehicle addMagazineTurret [_magazine, _turretPath]; + }; }; } else { - _vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath]; + private _success = true; + if (GVAR(supply) > 0) then { + _success = [_target, _magazine, (_maxRounds - _currentRounds)] call FUNC(removeMagazineFromSupply); + }; + if (_success) then { + _vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath]; + }; }; } foreach _magazines; diff --git a/addons/rearm/functions/fnc_rearmSuccess.sqf b/addons/rearm/functions/fnc_rearmSuccess.sqf index 81cda9f262..79341a99e5 100644 --- a/addons/rearm/functions/fnc_rearmSuccess.sqf +++ b/addons/rearm/functions/fnc_rearmSuccess.sqf @@ -21,7 +21,6 @@ */ #include "script_component.hpp" -private ["_dummy", "_weaponSelect", "_turretOwnerID"]; params [["_args", [objNull, objNull, [], 0, "", 0], [[]], [6]]]; _args params ["_target", "_unit", "_turretPath", "_numMagazines", "_magazineClass", "_numRounds"]; @@ -32,7 +31,7 @@ if (local _unit) then { }; if (isServer) then { - _turretOwnerID = _target turretOwner _turretPath; + private _turretOwnerID = _target turretOwner _turretPath; if (_turretOwnerID == 0) then { [_this, QFUNC(rearmSuccessLocal), _target] call EFUNC(common,execRemoteFnc); } else { diff --git a/addons/rearm/functions/fnc_rearmSuccessLocal.sqf b/addons/rearm/functions/fnc_rearmSuccessLocal.sqf index 1789767cfd..22923d5452 100644 --- a/addons/rearm/functions/fnc_rearmSuccessLocal.sqf +++ b/addons/rearm/functions/fnc_rearmSuccessLocal.sqf @@ -21,21 +21,19 @@ */ #include "script_component.hpp" -private ["_rounds", "_currentRounds", "_maxMagazines", "_currentMagazines", "_dummy", "_weaponSelect"]; params [["_args", [objNull, objNull, [], 0, "", 0], [[]], [6]]]; _args params ["_target", "_unit", "_turretPath", "_numMagazines", "_magazineClass", "_numRounds"]; -//hint format ["Target: %1\nTurretPath: %2\nNumMagazines: %3\nMagazine: %4\nNumRounds: %5\nUnit: %6", _target, _turretPath, _numMagazines, _magazineClass, _numRounds, _unit]; +private _rounds = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count"); +private _currentRounds = 0; +private _maxMagazines = [_target, _turretPath, _magazineClass] call FUNC(getMaxMagazines); -_rounds = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count"); -_currentRounds = 0; - -_maxMagazines = [_target, _turretPath, _magazineClass] call FUNC(getMaxMagazines); if (_maxMagazines == 1) then { - _currentMagazines = { _x == _magazineClass } count (_target magazinesTurret _turretPath); + private _currentMagazines = { _x == _magazineClass } count (_target magazinesTurret _turretPath); if (_currentMagazines == 0 && {!(_turretPath isEqualTo [-1])}) then { // Driver gun will always retain it's magazines _target addMagazineTurret [_magazineClass, _turretPath]; + _target setMagazineTurretAmmo [_magazineClass, 0, _turretPath]; }; if (GVAR(level) == 1) then { // Fill magazine completely diff --git a/addons/rearm/functions/fnc_removeMagazineFromSupply.sqf b/addons/rearm/functions/fnc_removeMagazineFromSupply.sqf new file mode 100644 index 0000000000..5c59221f7a --- /dev/null +++ b/addons/rearm/functions/fnc_removeMagazineFromSupply.sqf @@ -0,0 +1,86 @@ +/* + * Author: GitHawk + * Removes a magazine from the supply. + * + * Argument: + * 0: Target + * 1: Magazine Classname + * 2: Number of Rounds to withdraw + * + * Return value: + * Magazine was removed + * + * Example: + * [ammo_truck, "500Rnd_127x99_mag_Tracer_Red"] call ace_rearm_fnc_removeMagazineFromSupply + * + * Public: Yes + */ +#include "script_component.hpp" + +params [["_target", objNull, [objNull]], ["_magazineClass", "", [""]], ["_numRounds", -1, [0]]]; + +if (isNull _target || + {_magazineClass isEqualTo ""}) exitWith {false}; + +private _return = false; +([_magazineClass] call FUNC(getCaliber)) params ["_cal", "_idx"]; + +if (GVAR(supply) == 1) then { + private _supply = [_target] call FUNC(getSupplyCount); + if (GVAR(level) == 2) then { + // Remove partial magazine supply count + private _rearmAmount = (REARM_COUNT select _idx); + if (_numRounds > 0) then { + _rearmAmount = _numRounds; + }; + private _magazinePart = (_rearmAmount / (getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count"))) min 1; + if (_supply >= (_cal * _magazinePart)) then { + [_target, (_supply - (_cal * _magazinePart))] call FUNC(setSupplyCount); + _return = true; + }; + } else { + // Remove entire magazine supply count + if (_supply >= _cal) then { + [_target, (_supply - _cal)] call FUNC(setSupplyCount); + _return = true; + }; + }; +}; +if (GVAR(supply) == 2) then { + private _magazineSupply = _target getVariable [QGVAR(magazineSupply), []]; + private _magazineIdx = -1; + { + _x params ["_magazine"]; + if ((_magazine isEqualTo _magazineClass)) exitWith { + _magazineIdx = _forEachIndex; + }; + } forEach _magazineSupply; + if (_magazineIdx == -1) exitWith {false}; + + (_magazineSupply select _magazineIdx) params ["", "_rounds"]; + + private _configRounds = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count"); + if (GVAR(level) == 2) then { + // With caliber based rearming, we need to remove the correct amount + private _rearmAmount = (REARM_COUNT select _idx); + if (_numRounds > 0) then { + if (_numRounds > _rearmAmount) then { + _rearmAmount = ceil (_numRounds / _rearmAmount); + }; + }; + private _roundsPerTransaction = _rearmAmount min _configRounds; + if (_rounds >= _roundsPerTransaction) then { + _magazineSupply set [_magazineIdx, [_magazineClass, (_rounds - _roundsPerTransaction)]]; + _target setVariable [QGVAR(magazineSupply), _magazineSupply, true]; + _return = true; + }; + } else { + // Remove entire magazine + if (_rounds >= _configRounds) then { + _magazineSupply set [_magazineIdx, [_magazineClass, (_rounds - _configRounds)]]; + _target setVariable [QGVAR(magazineSupply), _magazineSupply, true]; + _return = true; + }; + }; +}; +_return diff --git a/addons/rearm/functions/fnc_setSupplyCount.sqf b/addons/rearm/functions/fnc_setSupplyCount.sqf new file mode 100644 index 0000000000..846ec98ea2 --- /dev/null +++ b/addons/rearm/functions/fnc_setSupplyCount.sqf @@ -0,0 +1,23 @@ +/* + * Author: GitHawk + * Sets the supply count. + * + * Argument: + * 0: Target + * 1: Supply Count + * + * Return value: + * None + * + * Example: + * [ammo_truck, 1000] call ace_rearm_fnc_setSupplyCount + * + * Public: Yes + */ +#include "script_component.hpp" + +params [["_target", objNull, [objNull]], ["_supply", 0, [0]]]; + +if (isNull _target) exitWith {}; + +_target setVariable [QGVAR(currentSupply), (_supply max 0), true]; diff --git a/addons/rearm/functions/fnc_storeAmmo.sqf b/addons/rearm/functions/fnc_storeAmmo.sqf index 262affb1ef..7026c9429a 100644 --- a/addons/rearm/functions/fnc_storeAmmo.sqf +++ b/addons/rearm/functions/fnc_storeAmmo.sqf @@ -16,16 +16,20 @@ */ #include "script_component.hpp" -private "_dummy"; params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]]]; -_dummy = _unit getVariable [QGVAR(dummy), objNull]; +private _dummy = _unit getVariable [QGVAR(dummy), objNull]; if (isNull _dummy) exitwith {}; [ 5, - _unit, - {params ["_unit"]; [_unit, true, true] call FUNC(dropAmmo)}, + [_unit, _target, _dummy], + { + params ["_args"]; + _args params ["_unit", "_target", "_dummy"]; + [_target, (_dummy getVariable [QGVAR(magazineClass), ""]), true] call FUNC(addMagazineToSupply); + [_unit, true, true] call FUNC(dropAmmo); + }, "", format [localize LSTRING(StoreAmmoAction), getText(configFile >> "CfgMagazines" >> (_dummy getVariable QGVAR(magazineClass)) >> "displayName"), getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")], {true}, diff --git a/addons/rearm/functions/fnc_takeAmmo.sqf b/addons/rearm/functions/fnc_takeAmmo.sqf index d2de1e1b59..776d88fc66 100644 --- a/addons/rearm/functions/fnc_takeAmmo.sqf +++ b/addons/rearm/functions/fnc_takeAmmo.sqf @@ -19,34 +19,10 @@ */ #include "script_component.hpp" -private ["_ammo", "_tmpCal", "_cal", "_idx"]; - params [["_target", objNull, [objNull]], ["_unit", objNull, [objNull]], ["_args", ["", objNull], [[]]]]; _args params ["_magazineClass", "_vehicle"]; -_ammo = getText (configFile >> "CfgMagazines" >> _magazineClass >> "ammo"); -_tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ace_caliber"); -_cal = 8; -if (_tmpCal > 0) then { - _cal = _tmpCal; -} else { - _tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(caliber)); - if (_tmpCal > 0) then { - _cal = _tmpCal; - } else { - diag_log format ["[ACE] ERROR: Undefined Ammo [%1 : %2]", _ammo, inheritsFrom (configFile >> "CfgAmmo" >> _ammo)]; - if (_ammo isKindOf "BulletBase") then { - _cal = 8; - } else { - _cal = 100; - }; - }; -}; -_cal = round _cal; -_idx = REARM_CALIBERS find _cal; -if (_idx == -1 ) then { - _idx = 2; -}; +([_magazineClass] call FUNC(getCaliber)) params ["_cal", "_idx"]; REARM_HOLSTER_WEAPON diff --git a/addons/rearm/functions/fnc_takeSuccess.sqf b/addons/rearm/functions/fnc_takeSuccess.sqf index 6d5966c9f9..b83f82aa2a 100644 --- a/addons/rearm/functions/fnc_takeSuccess.sqf +++ b/addons/rearm/functions/fnc_takeSuccess.sqf @@ -18,15 +18,20 @@ */ #include "script_component.hpp" -private ["_ammo", "_dummyName", "_dummy", "_actionID"]; -params [["_args", [objNull, "", objNull], [[]]]]; -_args params ["_unit", "_magazineClass", "_target"]; // _target is for future possible finite ammo +params [["_args", [objNull, "", objNull], [[]], 3]]; +_args params ["_unit", "_magazineClass", "_target"]; + +private _success = true; +if (GVAR(supply) > 0) then { + _success = [_target, _magazineClass] call FUNC(removeMagazineFromSupply); +}; +if !(_success) exitWith {}; [_unit, "forceWalk", QGVAR(vehRearm), true] call EFUNC(common,statusEffect_set); -_dummy = [_unit, _magazineClass] call FUNC(createDummy); +private _dummy = [_unit, _magazineClass] call FUNC(createDummy); [_dummy, _unit] call FUNC(pickUpAmmo); -_actionID = _unit addAction [ +private _actionID = _unit addAction [ format ["%1", localize ELSTRING(dragging,Drop)], '(_this select 0) call FUNC(dropAmmo)', nil, diff --git a/addons/rearm/stringtable.xml b/addons/rearm/stringtable.xml index 0b4fe1c90f..97ae997dd9 100644 --- a/addons/rearm/stringtable.xml +++ b/addons/rearm/stringtable.xml @@ -83,10 +83,34 @@ Unlimited ammo supply Unbegrenzter Munitionsvorat + + Limited ammo supply based on caliber + Begrenzter, kaliberabhängiger Munitionsvorat + Only specific Magazines Nur bestimmte Magazine + + Check remaining ammunition + Verbleibende Munition prüfen + + + Checking remaining ammunition... + Überprüfe verbleibende Munition... + + + There is ammunition worth %1 points left. + Es ist noch Munition für %1 Punkte übrig. + + + The following ammunition is left:%1 + Folgende Munition ist übrig:%1 + + + There is no ammunition left. + Es ist keine Munition übrig. + Rearm Aufmunitionieren