diff --git a/addons/rearm/XEH_preInit.sqf b/addons/rearm/XEH_preInit.sqf index 70dd9327ac..e78fa316cc 100644 --- a/addons/rearm/XEH_preInit.sqf +++ b/addons/rearm/XEH_preInit.sqf @@ -9,6 +9,8 @@ PREP(getMaxMagazines); PREP(pickUpAmmo); PREP(pickUpSuccess); PREP(rearm); +PREP(rearmEntireVehicle); +PREP(rearmEntireVehicleSuccess); PREP(rearmSuccess); PREP(moduleRearmSettings); diff --git a/addons/rearm/functions/fnc_addRearmActions.sqf b/addons/rearm/functions/fnc_addRearmActions.sqf index 1bd9b064f2..987bc473b1 100644 --- a/addons/rearm/functions/fnc_addRearmActions.sqf +++ b/addons/rearm/functions/fnc_addRearmActions.sqf @@ -37,13 +37,25 @@ _vehicleActions = []; _magazine = _x; _cnt = { _x == _magazine } count (_vehicle magazinesTurret _turretPath); if ((_cnt < ([_vehicle, _turretPath, _magazine] call FUNC(getMaxMagazines))) && !(_magazine in _magazineHelper)) then { - _action = [_magazine, getText(configFile >> "CfgMagazines" >> _magazine >> "displayName"), getText(configFile >> "CfgMagazines" >> _magazine >> "picture"), {_this call FUNC(pickUpAmmo)}, {true}, {}, [_magazine, _vehicle]] call EFUNC(interact_menu,createAction); + _action = [_magazine, + getText(configFile >> "CfgMagazines" >> _magazine >> "displayName"), + getText(configFile >> "CfgMagazines" >> _magazine >> "picture"), + {_this call FUNC(pickUpAmmo)}, + {true}, + {}, + [_magazine, _vehicle]] call EFUNC(interact_menu,createAction); _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, getText(configFile >> "CfgMagazines" >> _magazine >> "displayName"), getText(configFile >> "CfgMagazines" >> _magazine >> "picture"), {_this call FUNC(pickUpAmmo)}, {true}, {}, [_magazine, _vehicle]] call EFUNC(interact_menu,createAction); + _action = [_magazine, + getText(configFile >> "CfgMagazines" >> _magazine >> "displayName"), + getText(configFile >> "CfgMagazines" >> _magazine >> "picture"), + {_this call FUNC(pickUpAmmo)}, + {true}, + {}, + [_magazine, _vehicle]] call EFUNC(interact_menu,createAction); _actions pushBack [_action, [], _target]; _magazineHelper pushBack _magazine; _needToAdd = true; @@ -57,9 +69,27 @@ _vehicleActions = []; if !((_icon select [0, 1]) == "\") then { _icon = ""; }; - _action = [_vehicle, getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName"), _icon, "", {true}, {}, []] call EFUNC(interact_menu,createAction); - _vehicleActions pushBack [_action, _actions, _target]; + if (GVAR(level) == 0) then { + _action = [_vehicle, + getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName"), + _icon, + {_this call FUNC(rearmEntireVehicle)}, + {true}, + {}, + _vehicle] call EFUNC(interact_menu,createAction); + _vehicleActions pushBack [_action, [], _target]; + } else { + _action = [_vehicle, + getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName"), + _icon, + {}, + {true}, + {}, + []] call EFUNC(interact_menu,createAction); + _vehicleActions pushBack [_action, _actions, _target]; + }; }; } foreach _vehicles; + _vehicleActions diff --git a/addons/rearm/functions/fnc_canPickUpAmmo.sqf b/addons/rearm/functions/fnc_canPickUpAmmo.sqf index 1089e28eb4..16ff092a60 100644 --- a/addons/rearm/functions/fnc_canPickUpAmmo.sqf +++ b/addons/rearm/functions/fnc_canPickUpAmmo.sqf @@ -10,7 +10,7 @@ * Can rearm * * Example: - * [tank] call ace_rearm_fnc_canPickUpAmmo + * [player, tank] call ace_rearm_fnc_canPickUpAmmo * * Public: No */ diff --git a/addons/rearm/functions/fnc_canRearm.sqf b/addons/rearm/functions/fnc_canRearm.sqf index 1e0e75cc0c..689f01b0e9 100644 --- a/addons/rearm/functions/fnc_canRearm.sqf +++ b/addons/rearm/functions/fnc_canRearm.sqf @@ -16,7 +16,7 @@ */ #include "script_component.hpp" -private ["_vehicles", "_magazine", "_magazines", "_path", "_return", "_cnt"]; +private ["_magazine", "_return", "_magazines", "_path", "_cnt"]; params ["_unit", "_vehicle"]; #define GETRETURNVALUE \ @@ -29,13 +29,11 @@ if ((_vehicle magazineTurretAmmo [_magazine, _path]) < getNumber (configFile >> }; \ }; -if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || { (_vehicle distance _unit) > 7}) exitWith {false}; +if (isNull _unit || {!(_unit isKindOf "CAManBase")} || {!local _unit} || { (_vehicle distance _unit) > 7} || {GVAR(level) == 0}) exitWith {false}; _magazine = _unit getVariable QGVAR(carriedMagazine); if (isNil "_magazine") exitWith {false}; -// TODO move into loop - _return = false; _magazines = _vehicle magazinesTurret [-1]; if (_magazine in _magazines) then { diff --git a/addons/rearm/functions/fnc_rearm.sqf b/addons/rearm/functions/fnc_rearm.sqf index 70df22b1aa..d86e4df493 100644 --- a/addons/rearm/functions/fnc_rearm.sqf +++ b/addons/rearm/functions/fnc_rearm.sqf @@ -27,7 +27,7 @@ if ((_target magazineTurretAmmo [_magazine, _path]) < getNumber (configFile >> " }; \ }; -private ["_ammo", "_tmpCal", "_cal", "_idx", "_cnt","_return"]; +private ["_ammo", "_tmpCal", "_cal", "_idx", "_return", "_cnt", "_magazineDisplayName"]; params ["_unit", "_vehicle"]; _magazine = _unit getVariable QGVAR(carriedMagazine); @@ -98,18 +98,24 @@ if (!_return) then { _path = [2]; GETRETURNVALUE } else { - diag_log format ["ACE_Rearm: Could not find turret for %1 in %2", _magazine, (typeOf _target)]; + diag_log format ["ACE_Rearm: Could not find turret for %1 in %2", _magazine, typeOf _target]; }; }; //hint format ["Magazine: %1\nAmmo: %2\nCaliber: %3\nIndex: %4\nTurretPath: %5\nDURATION_REARM: %6\nCount: %7", _magazine, _ammo, _cal, _idx, _turretPath, (DURATION_REARM select _idx), (COUNT select _idx)]; +_magazineDisplayName = getText(configFile >> "CfgMagazines" >> _magazine >> "displayName"); +if (_magazineDisplayName == "") then { + _magazineDisplayName = _magazine; + diag_log format ["ACE_Rearm: Magazine is missing display name [%1]", _magazine]; +}; + [ (DURATION_REARM select _idx), [_target, _unit, _turretPath, _cnt, _magazine, (COUNT select _idx)], FUNC(rearmSuccess), "", - format [localize LSTRING(RearmAction), getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName"), getText(configFile >> "CfgMagazines" >> _magazine >> "displayName")], + format [localize LSTRING(RearmAction), getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName"), _magazineDisplayName], {true}, ["isnotinside"] ] call EFUNC(common,progressBar); \ No newline at end of file diff --git a/addons/rearm/functions/fnc_rearmEntireVehicle.sqf b/addons/rearm/functions/fnc_rearmEntireVehicle.sqf new file mode 100644 index 0000000000..59713d7263 --- /dev/null +++ b/addons/rearm/functions/fnc_rearmEntireVehicle.sqf @@ -0,0 +1,31 @@ +/* + * Author: GitHawk + * Rearms an entire vehicle + * + * Arguments: + * 0: The Ammo Truck + * 1: The Player + * 2: The Vehicle to be armed + * + * Return Value: + * None + * + * Example: + * [ammo_truck, player, tank] call ace_rearm_fnc_rearmEntireVehicle + * + * Public: No + */ +#include "script_component.hpp" + +private ["_ammo", "_tmpCal", "_cal"]; +params ["_target","_unit","_vehicle"]; + +[ + 10, + _vehicle, + FUNC(rearmEntireVehicleSuccess), + "", + format [localize LSTRING(BasicRearmAction), getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], + {true}, + ["isnotinside"] +] call EFUNC(common,progressBar); \ No newline at end of file diff --git a/addons/rearm/functions/fnc_rearmEntireVehicleSuccess.sqf b/addons/rearm/functions/fnc_rearmEntireVehicleSuccess.sqf new file mode 100644 index 0000000000..f0d8d32cac --- /dev/null +++ b/addons/rearm/functions/fnc_rearmEntireVehicleSuccess.sqf @@ -0,0 +1,49 @@ +/* + * Author: GitHawk + * Rearm an entire vehicle + * + * Arguments: + * 0: The Vehicle + * + * Return Value: + * None + * + * Example: + * [tank] call ace_rearm_fnc_rearmEntireVehicleSuccess + * + * Public: No + */ +#include "script_component.hpp" + +private ["_turretPath", "_magazines", "_magazine", "_currentMagazines", "_maxMagazines", "_rounds"]; +params ["_vehicle"]; + +if !(local _vehicle) exitWith { + [_this, QUOTE(DFUNC(rearmEntireVehicleSuccess)), _vehicle] call EFUNC(common,execRemoteFnc); +}; + +{ + _turretPath = _x; + _magazines = _vehicle magazinesTurret _turretPath; + { + _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]; + + //diag_log format ["Target: %1\nTurretPath: %2\nNumMagazines: %3\nMaxMagazines %4\nNumRounds: %5\nMaxRounds: %6\nMagazine: %7", _vehicle, _turretPath, _currentMagazines, _maxMagazines, _currentRounds, _maxRounds, _magazine]; + if (_currentMagazines < _maxMagazines) then { + _vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath]; + for "_idx" from 1 to (_maxMagazines - _currentMagazines) do { + _vehicle addMagazineTurret [_magazine, _turretPath]; + }; + } else { + if (_currentRounds > 0) then { + _vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath]; + } else { + _vehicle removeMagazineTurret [_magazine, _turretPath]; + }; + }; + } foreach _magazines; +} foreach [[-1], [0], [0,0], [0,1], [1], [2]]; \ No newline at end of file diff --git a/addons/rearm/functions/fnc_rearmSuccess.sqf b/addons/rearm/functions/fnc_rearmSuccess.sqf index 1a308c6791..76047c583b 100644 --- a/addons/rearm/functions/fnc_rearmSuccess.sqf +++ b/addons/rearm/functions/fnc_rearmSuccess.sqf @@ -23,7 +23,7 @@ private ["_rounds", "_currentRounds", "_maxMagazines"]; params ["_args"]; -_args params ["_target", "_caller", "_turretPath", "_numMagazines", "_magazine", "_numRounds"]; +_args params ["_target", "_unit", "_turretPath", "_numMagazines", "_magazine", "_numRounds"]; //hint format ["Target: %1\nTurretPath: %2\nNumMagazines: %3\nMagazine: %4\nNumRounds: %5", _target, _turretPath, _numMagazines, _magazine, _numRounds]; @@ -36,23 +36,41 @@ _currentRounds = 0; _maxMagazines = [_target, _turretPath, _magazine] call FUNC(getMaxMagazines); if (_maxMagazines == 1) then { - _target setMagazineTurretAmmo [_magazine, ((_target magazineTurretAmmo [_magazine, _turretPath]) + _numRounds) min _rounds, _turretPath]; - ace_player setVariable [QGVAR(carriedMagazine), nil]; // TODO replace by item + if (GVAR(level) == 1) then { + // Fill magazine completely + _target setMagazineTurretAmmo [_magazine, _rounds, _turretPath]; + } else { + // Fill only at most _numRounds + _target setMagazineTurretAmmo [_magazine, ((_target magazineTurretAmmo [_magazine, _turretPath]) + _numRounds) min _rounds, _turretPath]; + }; + _unit setVariable [QGVAR(carriedMagazine), nil]; // TODO replace by item } else { for "_idx" from 1 to _maxMagazines do { _currentRounds = _target magazineTurretAmmo [_magazine, _turretPath]; if (_currentRounds > 0) exitWith { - if ((_currentRounds + _numRounds) > _rounds) then { + if (GVAR(level) == 2) then { + //hint format ["Target: %1\nTurretPath: %2\nNumMagazines: %3\nMaxMagazines %4\nMagazine: %5\nNumRounds: %6\nMagazine: %7", _target, _turretPath, _numMagazines, _maxMagazines, _currentRounds, _numRounds, _magazine]; + // Fill only at most _numRounds + if ((_currentRounds + _numRounds) > _rounds) then { + _target setMagazineTurretAmmo [_magazine, _rounds, _turretPath]; + if (_numMagazines < _maxMagazines) then { + _target addMagazineTurret [_magazine, _turretPath]; + _target setMagazineTurretAmmo [_magazine, _currentRounds + _numRounds - _rounds, _turretPath]; + }; + } else { + _target setMagazineTurretAmmo [_magazine, _currentRounds + _numRounds, _turretPath]; + }; + } else { + // Fill current magazine completely and fill next magazine partially _target setMagazineTurretAmmo [_magazine, _rounds, _turretPath]; if (_numMagazines < _maxMagazines) then { _target addMagazineTurret [_magazine, _turretPath]; - _target setMagazineTurretAmmo [_magazine, _currentRounds + _numRounds - _rounds, _turretPath]; + _target setMagazineTurretAmmo [_magazine, _currentRounds, _turretPath]; }; - } else { - _target setMagazineTurretAmmo [_magazine, _currentRounds + _numRounds, _turretPath]; }; - ace_player setVariable [QGVAR(carriedMagazine), nil]; // TODO replace by item + _unit setVariable [QGVAR(carriedMagazine), nil]; // TODO replace by item }; _target removeMagazineTurret [_magazine, _turretPath]; + _numMagazines = _numMagazines - 1; }; }; \ No newline at end of file diff --git a/addons/rearm/stringtable.xml b/addons/rearm/stringtable.xml index 906bca12d1..85523c0e30 100644 --- a/addons/rearm/stringtable.xml +++ b/addons/rearm/stringtable.xml @@ -5,11 +5,11 @@ Rearm Settings Aufmunitioniereinstellungen - - Rearm speed - Aufmunitioniergeschwindigkeit + + Rearm amount + Aufmunitioniermenge - + How fast should a vehicle be rearmed? Wie schnell soll ein Fahrzeug aufmunitioniert werden? @@ -33,6 +33,10 @@ Rearming %1 with %2 Munitioniere %1 auf mit %2 + + Rearming %1 + Munitioniere %1 auf + Taking %1 for %2 Nehme %1 für %2