2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-03-06 04:32:47 +00:00
|
|
|
/*
|
2023-08-28 17:26:24 +00:00
|
|
|
* Author: commy2, esteldunedain
|
2015-03-06 04:32:47 +00:00
|
|
|
* Display the ammo of the currently loaded magazine of the target or count rifle grenades.
|
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Arguments:
|
2023-08-28 17:26:24 +00:00
|
|
|
* 0: Unit equipped with the weapon <OBJECT>
|
2015-03-06 04:32:47 +00:00
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Return Value:
|
2017-06-08 13:31:51 +00:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2023-08-28 17:26:24 +00:00
|
|
|
* [player] call ace_reload_fnc_displayAmmo
|
2017-06-08 13:31:51 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
2015-03-06 04:32:47 +00:00
|
|
|
*/
|
2017-06-08 13:31:51 +00:00
|
|
|
|
2015-03-06 04:32:47 +00:00
|
|
|
#define COUNT_BARS 12
|
|
|
|
|
2016-01-06 21:49:22 +00:00
|
|
|
params ["_target"];
|
2015-03-06 04:32:47 +00:00
|
|
|
|
2020-06-13 20:54:06 +00:00
|
|
|
private _isStaticWeapon = _target isKindOf "StaticWeapon";
|
|
|
|
|
2023-08-28 17:26:24 +00:00
|
|
|
// currentWeapon, currentMagazine and weaponState return "" for static weapons before they have been entered once
|
|
|
|
(if (_isStaticWeapon) then {
|
|
|
|
private _weapon = currentWeapon _target;
|
2015-03-06 04:32:47 +00:00
|
|
|
|
2015-04-22 00:35:04 +00:00
|
|
|
if (_weapon == "") then {
|
2023-08-28 17:26:24 +00:00
|
|
|
private _weapons = weapons _target;
|
|
|
|
|
|
|
|
if (count _weapons == 1) then {
|
|
|
|
_weapon = _weapons select 0;
|
2015-03-24 03:57:03 +00:00
|
|
|
};
|
2015-04-22 00:35:04 +00:00
|
|
|
};
|
|
|
|
|
2023-08-28 17:26:24 +00:00
|
|
|
private _magazine = currentMagazine _target;
|
|
|
|
|
2015-04-22 00:35:04 +00:00
|
|
|
if (_magazine == "") then {
|
|
|
|
// Try to get magazine using magazinesAmmoFull
|
|
|
|
{
|
|
|
|
if (_x select 2) exitWith {
|
|
|
|
_magazine = _x select 0;
|
|
|
|
};
|
2023-08-28 17:26:24 +00:00
|
|
|
} forEach magazinesAmmoFull _target;
|
2015-04-22 00:35:04 +00:00
|
|
|
};
|
2020-04-10 20:13:55 +00:00
|
|
|
|
2023-08-28 17:26:24 +00:00
|
|
|
// currentMuzzle always returns ""
|
|
|
|
[_weapon, _weapon, "", _magazine]
|
|
|
|
} else {
|
|
|
|
weaponState _target
|
|
|
|
}) params ["_weapon", "_muzzle", "", "_magazine"];
|
2015-03-06 04:32:47 +00:00
|
|
|
|
2020-06-13 20:54:06 +00:00
|
|
|
TRACE_3("",_weapon,_muzzle,_magazine);
|
2015-03-06 04:32:47 +00:00
|
|
|
|
2023-08-28 17:26:24 +00:00
|
|
|
if ("" == _weapon) exitWith {};
|
2020-06-13 20:54:06 +00:00
|
|
|
|
|
|
|
private _ammo = _target ammo _muzzle;
|
2023-08-28 17:26:24 +00:00
|
|
|
private _magazineCfg = configFile >> "CfgMagazines" >> _magazine;
|
|
|
|
private _maxRounds = getNumber (_magazineCfg >> "count") max 1;
|
2020-04-10 20:13:55 +00:00
|
|
|
private _count = -1; // Show a count instead of ammo bars (ignore if -1)
|
2015-03-06 04:32:47 +00:00
|
|
|
|
2023-08-28 17:26:24 +00:00
|
|
|
// If secondary muzzle is selected or no magazine in current muzzle
|
|
|
|
if (_muzzle != _weapon || {_magazine == ""}) then {
|
|
|
|
// Check if no or empty magazine; If true, just show count of compatible magazines
|
|
|
|
if (_ammo == 0) exitWith {
|
|
|
|
_magazine = ""; // Make sure, as it could also be secondary muzzle being selected
|
|
|
|
|
|
|
|
private _compatibleMagazines = compatibleMagazines [_weapon, _muzzle];
|
|
|
|
|
|
|
|
_count = {_x in _compatibleMagazines} count (magazines _target);
|
|
|
|
};
|
|
|
|
|
|
|
|
// singleShot, so show count of identical mags available instead of ammo bars
|
|
|
|
if (_ammo > 0 && {_maxRounds == 1}) exitWith {
|
|
|
|
_count = 1 + ({_x == _magazine} count (magazines _target));
|
2020-04-10 20:13:55 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
private _ammoBarsStructuredText = if (_count >= 0) then {
|
|
|
|
parseText format ["<t align='center' >%1x</t>", _count]
|
|
|
|
} else {
|
2015-04-22 00:35:04 +00:00
|
|
|
if (_maxRounds >= COUNT_BARS) then {
|
|
|
|
_count = round (COUNT_BARS * _ammo / _maxRounds);
|
2015-03-06 04:32:47 +00:00
|
|
|
|
2023-08-28 17:26:24 +00:00
|
|
|
if (_ammo > 0) then {
|
|
|
|
_count = _count max 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_ammo < _maxRounds) then {
|
|
|
|
_count = _count min (COUNT_BARS - 1);
|
|
|
|
};
|
2015-04-22 00:35:04 +00:00
|
|
|
} else {
|
|
|
|
_count = _ammo;
|
|
|
|
};
|
2015-03-06 04:32:47 +00:00
|
|
|
|
2023-08-28 17:26:24 +00:00
|
|
|
private _color = [(2 * (1 - _ammo / _maxRounds)) min 1, (2 * _ammo / _maxRounds) min 1, 0];
|
2015-04-22 00:35:04 +00:00
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
private _string = "";
|
2023-08-28 17:26:24 +00:00
|
|
|
|
2015-04-22 00:35:04 +00:00
|
|
|
for "_a" from 1 to _count do {
|
|
|
|
_string = _string + "|";
|
|
|
|
};
|
2023-08-28 17:26:24 +00:00
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
private _text = [_string, _color] call EFUNC(common,stringToColoredText);
|
2015-04-22 00:35:04 +00:00
|
|
|
|
|
|
|
_string = "";
|
2023-08-28 17:26:24 +00:00
|
|
|
|
2015-04-22 00:35:04 +00:00
|
|
|
for "_a" from (_count + 1) to (_maxRounds min COUNT_BARS) do {
|
|
|
|
_string = _string + "|";
|
|
|
|
};
|
|
|
|
|
2018-04-09 15:20:03 +00:00
|
|
|
composeText [_text, [_string, "#808080"] call EFUNC(common,stringToColoredText)];
|
2015-03-06 04:32:47 +00:00
|
|
|
};
|
|
|
|
|
2020-06-13 20:54:06 +00:00
|
|
|
if (_isStaticWeapon) then {
|
2023-08-28 17:26:24 +00:00
|
|
|
// Vehicle mags usually don't have pictures, so just show the text above ammo count
|
|
|
|
private _loadedName = getText (_magazineCfg >> "displayNameShort");
|
|
|
|
|
|
|
|
if (_loadedName == "") then {
|
|
|
|
_loadedName = getText (_magazineCfg >> "displayName");
|
|
|
|
};
|
|
|
|
|
2015-04-22 00:35:04 +00:00
|
|
|
_loadedName = parseText format ["<t align='center' >%1</t>", _loadedName];
|
2023-08-28 17:26:24 +00:00
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
private _text = composeText [_loadedName, linebreak, _ammoBarsStructuredText];
|
2015-04-22 00:35:04 +00:00
|
|
|
[_text] call EFUNC(common,displayTextStructured);
|
|
|
|
} else {
|
2020-04-10 20:13:55 +00:00
|
|
|
if (_magazine != "") then {
|
2023-08-28 17:26:24 +00:00
|
|
|
private _picture = getText (_magazineCfg >> "picture");
|
2020-04-10 20:13:55 +00:00
|
|
|
[_ammoBarsStructuredText, _picture] call EFUNC(common,displayTextPicture);
|
|
|
|
} else {
|
|
|
|
[_ammoBarsStructuredText, 1] call EFUNC(common,displayTextStructured);
|
|
|
|
};
|
2015-04-22 00:35:04 +00:00
|
|
|
};
|