ACE3/addons/rearm/functions/fnc_rearmEntireVehicleSuccessLocal.sqf

62 lines
2.3 KiB
Plaintext
Raw Normal View History

2015-08-18 16:09:37 +00:00
/*
* Author: GitHawk
* Rearm an entire turret locally.
*
* Arguments:
2016-02-27 19:31:07 +00:00
* 0: Target <OBJECT>
* 1: Vehicle <OBJECT>
* 2: TurretPath <ARRAY>
2015-08-18 16:09:37 +00:00
*
* Return Value:
* None
*
* Example:
2016-02-27 19:31:07 +00:00
* [ammo_truck, tank, [0]] call ace_rearm_fnc_rearmEntireVehicleSuccessLocal
2015-08-18 16:09:37 +00:00
*
* Public: No
*/
#include "script_component.hpp"
2016-02-27 19:31:07 +00:00
params [["_target", objNull, [objNull]], ["_vehicle", objNull, [objNull]], ["_turretPath", [], [[]]]];
2015-08-18 16:09:37 +00:00
2016-02-27 19:31:07 +00:00
private _magazines = [_vehicle, _turretPath] call FUNC(getVehicleMagazines);
if (isNil "_magazines") exitWith {};
2015-08-18 16:09:37 +00:00
{
2016-02-27 19:31:07 +00:00
private _magazine = _x;
private _currentMagazines = { _x == _magazine } count (_vehicle magazinesTurret _turretPath);
private _maxMagazines = [_vehicle, _turretPath, _magazine] call FUNC(getMaxMagazines);
private _maxRounds = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count");
private _currentRounds = _vehicle magazineTurretAmmo [_magazine, _turretPath];
2015-08-18 16:09:37 +00:00
TRACE_7("Rearmed Turret",_vehicle,_turretPath,_currentMagazines,_maxMagazines,_currentRounds,_maxRounds,_magazine);
if (_turretPath isEqualTo [-1] && _currentMagazines == 0) then {
// On driver, the empty magazine is still there, but is not returned by magazinesTurret
_currentMagazines = _currentMagazines + 1;
};
2015-08-18 16:09:37 +00:00
if (_currentMagazines < _maxMagazines) then {
2016-02-27 19:31:07 +00:00
private _success = true;
if (GVAR(supply) > 0) then {
_success = [_target, _magazine, (_maxRounds - _currentRounds)] call FUNC(removeMagazineFromSupply);
};
if (_success) then {
_vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath];
for "_idx" from 1 to (_maxMagazines - _currentMagazines) do {
_success = true;
if (GVAR(supply) > 0) then {
_success = [_target, _magazine, _maxRounds] call FUNC(removeMagazineFromSupply);
};
_vehicle addMagazineTurret [_magazine, _turretPath];
};
2015-08-18 16:09:37 +00:00
};
} else {
2016-02-27 19:31:07 +00:00
private _success = true;
if (GVAR(supply) > 0) then {
_success = [_target, _magazine, (_maxRounds - _currentRounds)] call FUNC(removeMagazineFromSupply);
};
if (_success) then {
_vehicle setMagazineTurretAmmo [_magazine, _maxRounds, _turretPath];
};
2015-08-18 16:09:37 +00:00
};
} foreach _magazines;