2015-08-24 18:58:54 +00:00
|
|
|
/*
|
|
|
|
* Author: Jonpas
|
2015-08-26 20:44:30 +00:00
|
|
|
* Finds the localized string of the given hitpoint name or uses default text if none found.
|
2015-08-24 18:58:54 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Hitpoint <STRING>
|
|
|
|
* 1: Localized Text <STRING>
|
|
|
|
* 2: Default Text <STRING>
|
|
|
|
* 3: Track Added Hitpoints <BOOL> (default: false)
|
|
|
|
*
|
|
|
|
* Return Value:
|
2017-06-08 13:31:51 +00:00
|
|
|
* 0: Text <STRING>
|
|
|
|
* 1: Added Hitpoint <NUMBER> (default: [])
|
2015-08-24 18:58:54 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2015-11-10 02:11:48 +00:00
|
|
|
* ["HitFuel", "Repairing %1 ...", "Repairing HitFuel"] call ace_repair_fnc_getHitPointString
|
2015-08-24 18:58:54 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
params ["_hitPoint", "_textLocalized", "_textDefault", ["_trackArray", []]];
|
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
private ["_track", "_trackNames", "_trackStrings", "_trackAmount", "_text", "_toFind", "_trackIndex", "_combinedString"];
|
|
|
|
|
2015-08-24 18:58:54 +00:00
|
|
|
_track = if (count _trackArray > 0) then {true} else {false};
|
|
|
|
_trackNames = [];
|
|
|
|
_trackStrings = [];
|
|
|
|
_trackAmount = [];
|
|
|
|
|
|
|
|
if (_track) then {
|
|
|
|
_trackNames = _trackArray select 0;
|
|
|
|
_trackStrings = _trackArray select 1;
|
|
|
|
_trackAmount = _trackArray select 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Prepare first part of the string from stringtable
|
|
|
|
_text = LSTRING(Hit);
|
|
|
|
|
|
|
|
// Remove "Hit" from hitpoint name if one exists
|
2015-11-10 02:11:48 +00:00
|
|
|
_toFind = if ((toLower _hitPoint) find "hit" == 0) then {
|
2015-08-24 18:58:54 +00:00
|
|
|
[_hitPoint, 3] call CBA_fnc_substr
|
|
|
|
} else {
|
|
|
|
_hitPoint
|
|
|
|
};
|
|
|
|
|
|
|
|
// Loop through always shorter part of the hitpoint name to find the string from stringtable
|
|
|
|
for "_i" from 0 to (count _hitPoint) do {
|
|
|
|
if (_track) then {
|
|
|
|
// Loop through already added hitpoints and save index
|
|
|
|
_trackIndex = -1;
|
|
|
|
{
|
|
|
|
if (_x == _toFind) exitWith {
|
|
|
|
_trackIndex = _forEachIndex;
|
|
|
|
};
|
|
|
|
} forEach _trackNames;
|
|
|
|
|
|
|
|
// Use already added hitpoint if one found above and numerize
|
|
|
|
if (_trackIndex != -1) exitWith {
|
|
|
|
_text = localize (_trackStrings select _trackIndex) + " " + str(_trackAmount select _trackIndex);
|
|
|
|
_trackAmount set [_trackIndex, (_trackAmount select _trackIndex) + 1]; // Set amount
|
|
|
|
TRACE_2("Same hitpoint found",_toFind,_trackNames);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Localize if localization found
|
|
|
|
_combinedString = _text + _toFind;
|
|
|
|
if (isLocalized _combinedString) exitWith {
|
|
|
|
_text = format [_textLocalized, localize _combinedString];
|
|
|
|
TRACE_1("Hitpoint localized",_toFind);
|
|
|
|
|
|
|
|
if (_track) then {
|
|
|
|
// Add hitpoint to the list
|
|
|
|
_trackNames pushBack _toFind;
|
|
|
|
_trackStrings pushBack _combinedString;
|
|
|
|
_trackAmount pushBack 2;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Cut off one character
|
|
|
|
_toFind = [_toFind, 0, count _toFind - 1] call CBA_fnc_substr;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Don't display part name if no string is found in stringtable
|
|
|
|
if (_text == LSTRING(Hit)) then {
|
2016-10-28 17:16:23 +00:00
|
|
|
if (_hitPoint != "") then { LOG_1("Hitpoint [%1] - could not be localized", _hitPoint); };
|
2015-08-24 18:58:54 +00:00
|
|
|
_text = _textDefault;
|
|
|
|
};
|
|
|
|
|
|
|
|
[_text, [_trackNames, _trackStrings, _trackAmount]]
|