Rearm - Use non-ambigious magazine names (#6761)

* Rearm - Use non-ambigious magazine names

Close #6414
Also fix missing caliber for B_20mm_AP

* Update fnc_getMagazineName.sqf
This commit is contained in:
PabstMirror 2019-01-30 18:31:01 -06:00 committed by GitHub
parent 32ffe3243c
commit 6bee6d5cd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 67 additions and 16 deletions

View File

@ -60,6 +60,9 @@ class CfgAmmo {
class B_20mm : BulletBase { class B_20mm : BulletBase {
GVAR(caliber) = 20; GVAR(caliber) = 20;
}; };
class B_20mm_AP: BulletBase {
GVAR(caliber) = 20;
};
class B_25mm : BulletBase { class B_25mm : BulletBase {
GVAR(caliber) = 25; GVAR(caliber) = 25;

View File

@ -10,6 +10,7 @@ PREP(disable);
PREP(dropAmmo); PREP(dropAmmo);
PREP(getAllRearmTurrets); PREP(getAllRearmTurrets);
PREP(getCaliber); PREP(getCaliber);
PREP(getMagazineName);
PREP(getMaxMagazines); PREP(getMaxMagazines);
PREP(getNeedRearmMagazines); PREP(getNeedRearmMagazines);
PREP(getSupplyCount); PREP(getSupplyCount);

View File

@ -29,3 +29,6 @@ if (isServer) then {
[QGVAR(rearmSuccessEH), LINKFUNC(rearmSuccess)] call CBA_fnc_addEventHandler; [QGVAR(rearmSuccessEH), LINKFUNC(rearmSuccess)] call CBA_fnc_addEventHandler;
[QGVAR(rearmSuccessLocalEH), LINKFUNC(rearmSuccessLocal)] call CBA_fnc_addEventHandler; [QGVAR(rearmSuccessLocalEH), LINKFUNC(rearmSuccessLocal)] call CBA_fnc_addEventHandler;
GVAR(magazineNameCache) = [] call CBA_fnc_createNamespace;
GVAR(originalMagazineNames) = [];

View File

@ -60,7 +60,7 @@ private _vehicleActions = [];
{ {
private _action = [ private _action = [
_x, _x,
getText(configFile >> "CfgMagazines" >> _x >> "displayName"), _x call FUNC(getMagazineName),
getText(configFile >> "CfgMagazines" >> _x >> "picture"), getText(configFile >> "CfgMagazines" >> _x >> "picture"),
{_this call FUNC(takeAmmo)}, {_this call FUNC(takeAmmo)},
{true}, {true},

View File

@ -33,7 +33,7 @@ if (_tmpCal > 0) then {
if (_tmpCal > 0) then { if (_tmpCal > 0) then {
_cal = _tmpCal; _cal = _tmpCal;
} else { } 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 { if (_ammo isKindOf "BulletBase") then {
_cal = 8; _cal = 8;
} else { } else {

View File

@ -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 <STRING>
*
* Return Value:
* Display Name <STRING>
*
* 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

View File

@ -54,7 +54,7 @@ if (GVAR(supply) == 1) then {
if !(isNil "_magazines") then { if !(isNil "_magazines") then {
{ {
_x params ["_magazineClass", "_rounds"]; _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); _numChars = _numChars max (count _line);
_text = format ["%1<br/>%2", _text, _line]; _text = format ["%1<br/>%2", _text, _line];
_supply = _supply + 0.5; _supply = _supply + 0.5;

View File

@ -36,11 +36,7 @@ if ((count _needRearmMagsOfClass) == 0) exitWith {ERROR_2("Could not find turret
private _currentRearmableMag = _needRearmMagsOfClass select 0; private _currentRearmableMag = _needRearmMagsOfClass select 0;
_currentRearmableMag params ["", "_turretPath", "", "_pylon", "", "_magazineCount"]; _currentRearmableMag params ["", "_turretPath", "", "_pylon", "", "_magazineCount"];
private _magazineDisplayName = getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"); private _magazineDisplayName = _magazineClass call FUNC(getMagazineName);
if (_magazineDisplayName == "") then {
_magazineDisplayName = _magazineClass;
ERROR_1("Magazine is missing display name [%1]",_magazineClass);
};
[ [
TIME_PROGRESSBAR(REARM_DURATION_REARM select _idx), TIME_PROGRESSBAR(REARM_DURATION_REARM select _idx),

View File

@ -33,7 +33,7 @@ if (_pylon > 0) exitWith {
TRACE_2("",_pylon,_magazineClass,_rounds); TRACE_2("",_pylon,_magazineClass,_rounds);
_vehicle setPylonLoadOut [_pylon, _magazineClass, true, _turretPath]; _vehicle setPylonLoadOut [_pylon, _magazineClass, true, _turretPath];
[QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _rounds, [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; getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit], [_unit]] call CBA_fnc_targetEvent;
} else { } else {
// Fill only at most _numRounds // Fill only at most _numRounds
@ -44,7 +44,7 @@ if (_pylon > 0) exitWith {
_vehicle setPylonLoadOut [_pylon, _magazineClass, true, _turretPath]; _vehicle setPylonLoadOut [_pylon, _magazineClass, true, _turretPath];
_vehicle setAmmoOnPylon [_pylon, _newCount]; _vehicle setAmmoOnPylon [_pylon, _newCount];
[QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _numRounds, [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; 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]; _vehicle setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath];
[QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _rounds, [QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _rounds,
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"), 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 { } else {
// Fill only at most _numRounds // Fill only at most _numRounds
_vehicle setMagazineTurretAmmo [_magazineClass, ((_vehicle magazineTurretAmmo [_magazineClass, _turretPath]) + _numRounds) min _rounds, _turretPath]; _vehicle setMagazineTurretAmmo [_magazineClass, ((_vehicle magazineTurretAmmo [_magazineClass, _turretPath]) + _numRounds) min _rounds, _turretPath];
[QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _numRounds, [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; getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit], [_unit]] call CBA_fnc_targetEvent;
}; };
} else { } else {
@ -92,7 +92,7 @@ if (_maxMagazines == 1) then {
_vehicle setMagazineTurretAmmo [_magazineClass, _currentRounds + _numRounds, _turretPath]; _vehicle setMagazineTurretAmmo [_magazineClass, _currentRounds + _numRounds, _turretPath];
}; };
[QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _numRounds, [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; getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit], [_unit]] call CBA_fnc_targetEvent;
} else { } else {
// Fill current magazine completely and fill next magazine partially // Fill current magazine completely and fill next magazine partially
@ -102,7 +102,7 @@ if (_maxMagazines == 1) then {
_vehicle setMagazineTurretAmmo [_magazineClass, _currentRounds, _turretPath]; _vehicle setMagazineTurretAmmo [_magazineClass, _currentRounds, _turretPath];
}; };
[QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _rounds, [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; getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit], [_unit]] call CBA_fnc_targetEvent;
}; };
}; };

View File

@ -21,6 +21,8 @@ params ["_truck", "_unit"];
private _attachedDummy = _unit getVariable [QGVAR(dummy), objNull]; private _attachedDummy = _unit getVariable [QGVAR(dummy), objNull];
if (isNull _attachedDummy) exitwith {}; if (isNull _attachedDummy) exitwith {};
private _magazineClass = _attachedDummy getVariable [QGVAR(magazineClass), "#noVar"];
[ [
TIME_PROGRESSBAR(5), TIME_PROGRESSBAR(5),
[_unit, _truck, _attachedDummy], [_unit, _truck, _attachedDummy],
@ -31,7 +33,7 @@ if (isNull _attachedDummy) exitwith {};
[_unit, true, true] call FUNC(dropAmmo); [_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}, {true},
["isnotinside"] ["isnotinside"]
] call EFUNC(common,progressBar); ] call EFUNC(common,progressBar);

View File

@ -32,7 +32,7 @@ REARM_HOLSTER_WEAPON;
[_unit, _magazineClass, _truck], [_unit, _magazineClass, _truck],
FUNC(takeSuccess), 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}, {true},
["isnotinside"] ["isnotinside"]
] call EFUNC(common,progressBar); ] call EFUNC(common,progressBar);