ACE3/addons/rearm/functions/fnc_rearm.sqf

76 lines
2.4 KiB
Plaintext
Raw Normal View History

2015-08-15 16:43:13 +00:00
/*
* Author: GitHawk
* Starts progress bar for rearming a vehicle.
2015-08-15 16:43:13 +00:00
*
* Arguments:
* 0: Unit <OBJECT>
2015-08-15 16:43:13 +00:00
*
* Return Value:
* None
*
* Example:
2015-08-21 20:57:14 +00:00
* [player] call ace_rearm_fnc_rearm
2015-08-15 16:43:13 +00:00
*
* Public: No
*/
#include "script_component.hpp"
private ["_magazineClass", "_ammo", "_tmpCal", "_cal", "_idx", "_needRearmMags", "_magazineDisplayName"];
2016-02-01 19:05:53 +00:00
params [["_unit", objNull, [objNull]]];
2015-08-15 16:43:13 +00:00
_dummy = _unit getVariable [QGVAR(dummy), objNull];
if (isNull _dummy) exitwith {false};
_magazineClass = _dummy getVariable QGVAR(magazineClass);
if (isNil "_magazineClass") exitWith {false};
2015-08-15 16:43:13 +00:00
_ammo = getText (configFile >> "CfgMagazines" >> _magazineClass >> "ammo");
2015-08-15 16:43:13 +00:00
_tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ace_caliber");
_cal = 8;
if (_tmpCal > 0) then {
_cal = _tmpCal;
} else {
2015-08-15 17:00:28 +00:00
_tmpCal = getNumber (configFile >> "CfgAmmo" >> _ammo >> QGVAR(caliber));
2015-08-15 16:43:13 +00:00
if (_tmpCal > 0) then {
_cal = _tmpCal;
} else {
diag_log format ["[ACE] ERROR: Undefined Ammo [%1 : %2]", _ammo, inheritsFrom (configFile >> "CfgAmmo" >> _ammo)];
2015-08-15 16:43:13 +00:00
if (_ammo isKindOf "BulletBase") then {
_cal = 8;
} else {
_cal = 100;
};
};
};
_cal = round _cal;
_idx = REARM_CALIBERS find _cal;
if (_idx == -1) then {
2015-08-15 16:43:13 +00:00
_idx = 2;
};
// Get magazines that can be rearmed
2015-08-18 14:20:11 +00:00
_needRearmMags = [_target, _magazineClass] call FUNC(getNeedRearmMagazines);
_needRearmMags params ["_needRearm", "_turretPath", "_cnt"];
// Exit if no magazines need rearming
if (!_needRearm) exitWith {
diag_log format ["[ACE] ERROR: Could not find turret for %1 in %2", _magazineClass, typeOf _target];
2015-08-15 16:43:13 +00:00
};
//hint format ["Magazine: %1\nAmmo: %2\nCaliber: %3\nIndex: %4\nTurretPath: %5\nREARM_DURATION_REARM: %6\nCount: %7", _magazine, _ammo, _cal, _idx, _turretPath, (REARM_DURATION_REARM select _idx), (REARM_COUNT select _idx)];
2015-08-15 16:43:13 +00:00
_magazineDisplayName = getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName");
2015-08-16 00:18:53 +00:00
if (_magazineDisplayName == "") then {
_magazineDisplayName = _magazineClass;
diag_log format ["[ACE] ERROR: Magazine is missing display name [%1]", _magazineClass];
2015-08-16 00:18:53 +00:00
};
2015-08-15 16:43:13 +00:00
[
(REARM_DURATION_REARM select _idx),
[_target, _unit, _turretPath, _cnt, _magazineClass, (REARM_COUNT select _idx)],
2015-08-15 16:43:13 +00:00
FUNC(rearmSuccess),
"",
2015-08-16 00:18:53 +00:00
format [localize LSTRING(RearmAction), getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName"), _magazineDisplayName],
2015-08-15 16:43:13 +00:00
{true},
["isnotinside"]
] call EFUNC(common,progressBar);