2015-08-18 16:09:37 +00:00
|
|
|
/*
|
|
|
|
* Author: GitHawk
|
|
|
|
* Rearms a vehicle on the turret owner.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Params <ARRAY>
|
2016-02-27 20:05:19 +00:00
|
|
|
* 0: Vehicle <OBJECT>
|
2015-08-18 16:09:37 +00:00
|
|
|
* 1: Unit <OBJECT>
|
|
|
|
* 2: Turret Path <ARRAY>
|
|
|
|
* 3: Number of magazines <NUMBER>
|
|
|
|
* 4: Magazine Classname <STRING>
|
|
|
|
* 5: Number of rounds <NUMBER>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [[vehicle, player, [-1], 2, "5000Rnd_762x51_Belt", 500]] call ace_rearm_fnc_rearmSuccess
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2016-02-01 19:21:20 +00:00
|
|
|
params [["_args", [objNull, objNull, [], 0, "", 0], [[]], [6]]];
|
2016-02-27 20:05:19 +00:00
|
|
|
_args params ["_vehicle", "_unit", "_turretPath", "_numMagazines", "_magazineClass", "_numRounds"];
|
2015-08-18 16:09:37 +00:00
|
|
|
|
2016-02-27 19:31:07 +00:00
|
|
|
private _rounds = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count");
|
|
|
|
private _currentRounds = 0;
|
2016-02-27 20:05:19 +00:00
|
|
|
private _maxMagazines = [_vehicle, _turretPath, _magazineClass] call FUNC(getMaxMagazines);
|
2015-08-18 16:09:37 +00:00
|
|
|
|
|
|
|
if (_maxMagazines == 1) then {
|
2016-02-27 20:05:19 +00:00
|
|
|
private _currentMagazines = { _x == _magazineClass } count (_vehicle magazinesTurret _turretPath);
|
2016-02-11 18:06:37 +00:00
|
|
|
if (_currentMagazines == 0 && {!(_turretPath isEqualTo [-1])}) then {
|
|
|
|
// Driver gun will always retain it's magazines
|
2016-02-27 20:05:19 +00:00
|
|
|
_vehicle addMagazineTurret [_magazineClass, _turretPath];
|
|
|
|
_vehicle setMagazineTurretAmmo [_magazineClass, 0, _turretPath];
|
2016-02-01 19:05:53 +00:00
|
|
|
};
|
2015-08-18 16:09:37 +00:00
|
|
|
if (GVAR(level) == 1) then {
|
|
|
|
// Fill magazine completely
|
2016-02-27 20:05:19 +00:00
|
|
|
_vehicle setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath];
|
2015-08-18 16:09:37 +00:00
|
|
|
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _rounds,
|
|
|
|
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
2016-02-27 20:05:19 +00:00
|
|
|
getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
2015-08-18 16:09:37 +00:00
|
|
|
} else {
|
|
|
|
// Fill only at most _numRounds
|
2016-02-27 20:05:19 +00:00
|
|
|
_vehicle setMagazineTurretAmmo [_magazineClass, ((_vehicle magazineTurretAmmo [_magazineClass, _turretPath]) + _numRounds) min _rounds, _turretPath];
|
2015-08-18 16:09:37 +00:00
|
|
|
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _numRounds,
|
|
|
|
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
2016-02-27 20:05:19 +00:00
|
|
|
getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
2015-08-18 16:09:37 +00:00
|
|
|
};
|
|
|
|
} else {
|
2016-02-01 19:05:53 +00:00
|
|
|
for "_idx" from 1 to (_maxMagazines+1) do {
|
2016-02-27 20:05:19 +00:00
|
|
|
_currentRounds = _vehicle magazineTurretAmmo [_magazineClass, _turretPath];
|
2016-02-01 19:05:53 +00:00
|
|
|
if (_currentRounds > 0 || {_idx == (_maxMagazines+1)}) exitWith {
|
2016-02-11 18:06:37 +00:00
|
|
|
if (_idx == (_maxMagazines+1) && {!(_turretPath isEqualTo [-1])}) then {
|
2016-02-27 20:05:19 +00:00
|
|
|
_vehicle addMagazineTurret [_magazineClass, _turretPath];
|
2016-02-01 19:05:53 +00:00
|
|
|
};
|
2015-08-18 16:09:37 +00:00
|
|
|
if (GVAR(level) == 2) then {
|
2016-02-27 20:05:19 +00:00
|
|
|
//hint format ["Target: %1\nTurretPath: %2\nNumMagazines: %3\nMaxMagazines %4\nMagazine: %5\nNumRounds: %6\nMagazine: %7", _vehicle, _turretPath, _numMagazines, _maxMagazines, _currentRounds, _numRounds, _magazineClass];
|
2015-08-18 16:09:37 +00:00
|
|
|
// Fill only at most _numRounds
|
|
|
|
if ((_currentRounds + _numRounds) > _rounds) then {
|
2016-02-27 20:05:19 +00:00
|
|
|
_vehicle setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath];
|
2015-08-18 16:09:37 +00:00
|
|
|
if (_numMagazines < _maxMagazines) then {
|
2016-02-27 20:05:19 +00:00
|
|
|
_vehicle addMagazineTurret [_magazineClass, _turretPath];
|
|
|
|
_vehicle setMagazineTurretAmmo [_magazineClass, _currentRounds + _numRounds - _rounds, _turretPath];
|
2015-08-18 16:09:37 +00:00
|
|
|
};
|
|
|
|
} else {
|
2016-02-27 20:05:19 +00:00
|
|
|
_vehicle setMagazineTurretAmmo [_magazineClass, _currentRounds + _numRounds, _turretPath];
|
2015-08-18 16:09:37 +00:00
|
|
|
};
|
|
|
|
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _numRounds,
|
|
|
|
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
2016-02-27 20:05:19 +00:00
|
|
|
getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
2015-08-18 16:09:37 +00:00
|
|
|
} else {
|
|
|
|
// Fill current magazine completely and fill next magazine partially
|
2016-02-27 20:05:19 +00:00
|
|
|
_vehicle setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath];
|
2015-08-18 16:09:37 +00:00
|
|
|
if (_numMagazines < _maxMagazines) then {
|
2016-02-27 20:05:19 +00:00
|
|
|
_vehicle addMagazineTurret [_magazineClass, _turretPath];
|
|
|
|
_vehicle setMagazineTurretAmmo [_magazineClass, _currentRounds, _turretPath];
|
2015-08-18 16:09:37 +00:00
|
|
|
};
|
|
|
|
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _rounds,
|
|
|
|
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
2016-02-27 20:05:19 +00:00
|
|
|
getText(configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
2015-08-18 16:09:37 +00:00
|
|
|
};
|
|
|
|
};
|
2016-02-27 20:05:19 +00:00
|
|
|
_vehicle removeMagazineTurret [_magazineClass, _turretPath];
|
2015-08-18 16:09:37 +00:00
|
|
|
_numMagazines = _numMagazines - 1;
|
|
|
|
};
|
|
|
|
};
|