diff --git a/addons/rearm/CfgAmmo.hpp b/addons/rearm/CfgAmmo.hpp index 54ff37e279..78151796c0 100644 --- a/addons/rearm/CfgAmmo.hpp +++ b/addons/rearm/CfgAmmo.hpp @@ -60,6 +60,9 @@ class CfgAmmo { class B_20mm : BulletBase { GVAR(caliber) = 20; }; + class B_20mm_AP: BulletBase { + GVAR(caliber) = 20; + }; class B_25mm : BulletBase { GVAR(caliber) = 25; diff --git a/addons/rearm/XEH_PREP.hpp b/addons/rearm/XEH_PREP.hpp index 9ce5329144..79bd6c737f 100644 --- a/addons/rearm/XEH_PREP.hpp +++ b/addons/rearm/XEH_PREP.hpp @@ -10,6 +10,7 @@ PREP(disable); PREP(dropAmmo); PREP(getAllRearmTurrets); PREP(getCaliber); +PREP(getMagazineName); PREP(getMaxMagazines); PREP(getNeedRearmMagazines); PREP(getSupplyCount); diff --git a/addons/rearm/XEH_postInit.sqf b/addons/rearm/XEH_postInit.sqf index e78f12e9f7..3da59af9bd 100644 --- a/addons/rearm/XEH_postInit.sqf +++ b/addons/rearm/XEH_postInit.sqf @@ -29,3 +29,6 @@ if (isServer) then { [QGVAR(rearmSuccessEH), LINKFUNC(rearmSuccess)] call CBA_fnc_addEventHandler; [QGVAR(rearmSuccessLocalEH), LINKFUNC(rearmSuccessLocal)] call CBA_fnc_addEventHandler; + +GVAR(magazineNameCache) = [] call CBA_fnc_createNamespace; +GVAR(originalMagazineNames) = []; diff --git a/addons/rearm/functions/fnc_addRearmActions.sqf b/addons/rearm/functions/fnc_addRearmActions.sqf index fdf1fe7e02..79b976f322 100644 --- a/addons/rearm/functions/fnc_addRearmActions.sqf +++ b/addons/rearm/functions/fnc_addRearmActions.sqf @@ -60,7 +60,7 @@ private _vehicleActions = []; { private _action = [ _x, - getText(configFile >> "CfgMagazines" >> _x >> "displayName"), + _x call FUNC(getMagazineName), getText(configFile >> "CfgMagazines" >> _x >> "picture"), {_this call FUNC(takeAmmo)}, {true}, diff --git a/addons/rearm/functions/fnc_getCaliber.sqf b/addons/rearm/functions/fnc_getCaliber.sqf index 6c37deb938..c43c0ecbf2 100644 --- a/addons/rearm/functions/fnc_getCaliber.sqf +++ b/addons/rearm/functions/fnc_getCaliber.sqf @@ -33,7 +33,7 @@ if (_tmpCal > 0) then { if (_tmpCal > 0) then { _cal = _tmpCal; } else { - diag_log format ["[ACE] ERROR: Undefined Ammo [%1 : %2]", _ammo, inheritsFrom (configFile >> "CfgAmmo" >> _ammo)]; + diag_log format ["[ACE] ERROR: Undefined Ammo [%1 : %2]", _ammo, configName inheritsFrom (configFile >> "CfgAmmo" >> _ammo)]; if (_ammo isKindOf "BulletBase") then { _cal = 8; } else { diff --git a/addons/rearm/functions/fnc_getMagazineName.sqf b/addons/rearm/functions/fnc_getMagazineName.sqf new file mode 100644 index 0000000000..1871cedbf7 --- /dev/null +++ b/addons/rearm/functions/fnc_getMagazineName.sqf @@ -0,0 +1,46 @@ +#include "script_component.hpp" +/* + * Author: PabstMirror + * Gets a non-ambigious display name for a magazine using displayNameShort (AP/HE) + * + * Arguments: + * 0: Magazine Classname + * + * Return Value: + * Display Name + * + * Example: + * ["B_20mm_AP"] call ace_rearm_fnc_getMagazineName + * + * Public: No + */ + +params ["_className"]; +TRACE_1("getMagazineName",_className); + +private _magName = GVAR(magazineNameCache) getVariable _className; +if (isNil "_magName") then { + private _displayName = getText(configFile >> "CfgMagazines" >> _className >> "displayName"); + if (_displayName == "") then { + _displayName = _className; + WARNING_1("Magazine is missing display name [%1]",_className); + }; + + GVAR(magazineNameCache) setVariable [_className, _displayName]; + GVAR(originalMagazineNames) pushBack _displayName; + TRACE_2("Adding to cache",_className,_displayName); + + // go through all existing cache entries and update if there now are duplicates + { + private _xMagName = GVAR(magazineNameCache) getVariable _x; + if ((_xMagName == _displayName) && {({_xMagName == _x} count GVAR(originalMagazineNames)) > 1}) then { + private _xMagName = format ["%1: %2", _displayName, getText(configFile >> "CfgMagazines" >> _x >> "displayNameShort")]; + GVAR(magazineNameCache) setVariable [_x, _xMagName]; + TRACE_2("Using unique name",_x,_xMagName); + }; + } forEach (allVariables GVAR(magazineNameCache)); + + _magName = GVAR(magazineNameCache) getVariable _className; +}; + +_magName diff --git a/addons/rearm/functions/fnc_readSupplyCounter.sqf b/addons/rearm/functions/fnc_readSupplyCounter.sqf index 31edaa2684..11abdc3ae8 100644 --- a/addons/rearm/functions/fnc_readSupplyCounter.sqf +++ b/addons/rearm/functions/fnc_readSupplyCounter.sqf @@ -54,7 +54,7 @@ if (GVAR(supply) == 1) then { if !(isNil "_magazines") then { { _x params ["_magazineClass", "_rounds"]; - private _line = format ["%1: %2", getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"), _rounds]; + private _line = format ["%1: %2", _magazineClass call FUNC(getMagazineName), _rounds]; _numChars = _numChars max (count _line); _text = format ["%1
%2", _text, _line]; _supply = _supply + 0.5; diff --git a/addons/rearm/functions/fnc_rearm.sqf b/addons/rearm/functions/fnc_rearm.sqf index bf703e9b6b..2556096c11 100644 --- a/addons/rearm/functions/fnc_rearm.sqf +++ b/addons/rearm/functions/fnc_rearm.sqf @@ -36,11 +36,7 @@ if ((count _needRearmMagsOfClass) == 0) exitWith {ERROR_2("Could not find turret private _currentRearmableMag = _needRearmMagsOfClass select 0; _currentRearmableMag params ["", "_turretPath", "", "_pylon", "", "_magazineCount"]; -private _magazineDisplayName = getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"); -if (_magazineDisplayName == "") then { - _magazineDisplayName = _magazineClass; - ERROR_1("Magazine is missing display name [%1]",_magazineClass); -}; +private _magazineDisplayName = _magazineClass call FUNC(getMagazineName); [ TIME_PROGRESSBAR(REARM_DURATION_REARM select _idx), diff --git a/addons/rearm/functions/fnc_rearmSuccessLocal.sqf b/addons/rearm/functions/fnc_rearmSuccessLocal.sqf index d141ca4a64..070601d0c9 100644 --- a/addons/rearm/functions/fnc_rearmSuccessLocal.sqf +++ b/addons/rearm/functions/fnc_rearmSuccessLocal.sqf @@ -33,7 +33,7 @@ if (_pylon > 0) exitWith { TRACE_2("",_pylon,_magazineClass,_rounds); _vehicle setPylonLoadOut [_pylon, _magazineClass, true, _turretPath]; [QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _rounds, - getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"), + _magazineClass call FUNC(getMagazineName), getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit], [_unit]] call CBA_fnc_targetEvent; } else { // Fill only at most _numRounds @@ -44,7 +44,7 @@ if (_pylon > 0) exitWith { _vehicle setPylonLoadOut [_pylon, _magazineClass, true, _turretPath]; _vehicle setAmmoOnPylon [_pylon, _newCount]; [QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _numRounds, - getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"), + _magazineClass call FUNC(getMagazineName), getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit], [_unit]] call CBA_fnc_targetEvent; }; }; @@ -64,12 +64,12 @@ if (_maxMagazines == 1) then { _vehicle setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath]; [QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _rounds, getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"), - getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit], [_unit]] call CBA_fnc_targetEvent; + _magazineClass call FUNC(getMagazineName)], 3, _unit], [_unit]] call CBA_fnc_targetEvent; } else { // Fill only at most _numRounds _vehicle setMagazineTurretAmmo [_magazineClass, ((_vehicle magazineTurretAmmo [_magazineClass, _turretPath]) + _numRounds) min _rounds, _turretPath]; [QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _numRounds, - getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"), + _magazineClass call FUNC(getMagazineName), getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit], [_unit]] call CBA_fnc_targetEvent; }; } else { @@ -92,7 +92,7 @@ if (_maxMagazines == 1) then { _vehicle setMagazineTurretAmmo [_magazineClass, _currentRounds + _numRounds, _turretPath]; }; [QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _numRounds, - getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"), + _magazineClass call FUNC(getMagazineName), getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit], [_unit]] call CBA_fnc_targetEvent; } else { // Fill current magazine completely and fill next magazine partially @@ -102,7 +102,7 @@ if (_maxMagazines == 1) then { _vehicle setMagazineTurretAmmo [_magazineClass, _currentRounds, _turretPath]; }; [QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _rounds, - getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"), + _magazineClass call FUNC(getMagazineName), getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit], [_unit]] call CBA_fnc_targetEvent; }; }; diff --git a/addons/rearm/functions/fnc_storeAmmo.sqf b/addons/rearm/functions/fnc_storeAmmo.sqf index 7d4427e1a2..18b316d601 100644 --- a/addons/rearm/functions/fnc_storeAmmo.sqf +++ b/addons/rearm/functions/fnc_storeAmmo.sqf @@ -21,6 +21,8 @@ params ["_truck", "_unit"]; private _attachedDummy = _unit getVariable [QGVAR(dummy), objNull]; if (isNull _attachedDummy) exitwith {}; +private _magazineClass = _attachedDummy getVariable [QGVAR(magazineClass), "#noVar"]; + [ TIME_PROGRESSBAR(5), [_unit, _truck, _attachedDummy], @@ -31,7 +33,7 @@ if (isNull _attachedDummy) exitwith {}; [_unit, true, true] call FUNC(dropAmmo); }, "", - format [localize LSTRING(StoreAmmoAction), getText(configFile >> "CfgMagazines" >> (_attachedDummy getVariable QGVAR(magazineClass)) >> "displayName"), getText(configFile >> "CfgVehicles" >> (typeOf _truck) >> "displayName")], + format [localize LSTRING(StoreAmmoAction), _magazineClass call FUNC(getMagazineName), getText(configFile >> "CfgVehicles" >> (typeOf _truck) >> "displayName")], {true}, ["isnotinside"] ] call EFUNC(common,progressBar); diff --git a/addons/rearm/functions/fnc_takeAmmo.sqf b/addons/rearm/functions/fnc_takeAmmo.sqf index 1576044eb1..f4a7339edc 100644 --- a/addons/rearm/functions/fnc_takeAmmo.sqf +++ b/addons/rearm/functions/fnc_takeAmmo.sqf @@ -32,7 +32,7 @@ REARM_HOLSTER_WEAPON; [_unit, _magazineClass, _truck], FUNC(takeSuccess), "", - format [localize LSTRING(TakeAction), getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"), getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], + format [localize LSTRING(TakeAction), _magazineClass call FUNC(getMagazineName), getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], {true}, ["isnotinside"] ] call EFUNC(common,progressBar);