2015-08-15 16:43:13 +00:00
|
|
|
/*
|
|
|
|
* Author: GitHawk
|
2015-08-18 00:32:10 +00:00
|
|
|
* Rearms a vehicle.
|
2015-08-15 16:43:13 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-08-18 00:32:10 +00:00
|
|
|
* 0: Params <ARRAY>
|
|
|
|
* 0: Target <OBJECT>
|
|
|
|
* 1: Unit <OBJECT>
|
|
|
|
* 2: Turret Path <ARRAY>
|
|
|
|
* 3: Number of magazines <NUMBER>
|
|
|
|
* 4: Magazine Classname <STRING>
|
|
|
|
* 5: Number of rounds <NUMBER>
|
2015-08-15 16:43:13 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2015-08-18 15:38:50 +00:00
|
|
|
* [[vehicle, player, [-1], 2, "5000Rnd_762x51_Belt", 500]] call ace_rearm_fnc_rearmSuccess
|
2015-08-15 16:43:13 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-08-18 00:32:10 +00:00
|
|
|
private ["_rounds", "_currentRounds", "_maxMagazines", "_dummy", "_weaponSelect"];
|
2015-08-15 16:43:13 +00:00
|
|
|
params ["_args"];
|
2015-08-18 00:32:10 +00:00
|
|
|
_args params ["_target", "_unit", "_turretPath", "_numMagazines", "_magazineClass", "_numRounds"];
|
2015-08-15 16:43:13 +00:00
|
|
|
|
2015-08-18 00:32:10 +00:00
|
|
|
//hint format ["Target: %1\nTurretPath: %2\nNumMagazines: %3\nMagazine: %4\nNumRounds: %5", _target, _turretPath, _numMagazines, _magazineClass, _numRounds];
|
2015-08-15 16:43:13 +00:00
|
|
|
|
2015-08-16 21:52:37 +00:00
|
|
|
if (local _unit) then {
|
|
|
|
[_unit, QGVAR(vehRearm), false] call EFUNC(common,setForceWalkStatus);
|
|
|
|
_dummy = _unit getVariable [QGVAR(dummy), objNull];
|
|
|
|
if !(isNull _dummy) then {
|
|
|
|
detach _dummy;
|
|
|
|
deleteVehicle _dummy;
|
|
|
|
};
|
|
|
|
_unit setVariable [QGVAR(carriedMagazine), nil, true];
|
|
|
|
_weaponSelect = _unit getVariable QGVAR(selectedWeaponOnRearm);
|
|
|
|
_unit selectWeapon _weaponSelect;
|
|
|
|
_unit setVariable [QGVAR(selectedWeaponOnRearm), nil];
|
|
|
|
};
|
|
|
|
|
2015-08-18 15:38:50 +00:00
|
|
|
if !(local _target) exitWith { // TODO if there are players inside the turrets they will not be rearmed due to locality issues
|
2015-08-15 16:43:13 +00:00
|
|
|
[_this, QUOTE(DFUNC(rearmSuccess)), _target] call EFUNC(common,execRemoteFnc);
|
|
|
|
};
|
|
|
|
|
2015-08-18 00:32:10 +00:00
|
|
|
_rounds = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count");
|
2015-08-15 16:43:13 +00:00
|
|
|
_currentRounds = 0;
|
|
|
|
|
2015-08-18 00:32:10 +00:00
|
|
|
_maxMagazines = [_target, _turretPath, _magazineClass] call FUNC(getMaxMagazines);
|
2015-08-15 16:43:13 +00:00
|
|
|
if (_maxMagazines == 1) then {
|
2015-08-16 00:18:53 +00:00
|
|
|
if (GVAR(level) == 1) then {
|
|
|
|
// Fill magazine completely
|
2015-08-18 00:32:10 +00:00
|
|
|
_target setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath];
|
2015-08-18 15:38:50 +00:00
|
|
|
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _rounds,
|
|
|
|
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
|
|
|
getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
2015-08-16 00:18:53 +00:00
|
|
|
} else {
|
|
|
|
// Fill only at most _numRounds
|
2015-08-18 00:32:10 +00:00
|
|
|
_target setMagazineTurretAmmo [_magazineClass, ((_target magazineTurretAmmo [_magazineClass, _turretPath]) + _numRounds) min _rounds, _turretPath];
|
2015-08-18 15:38:50 +00:00
|
|
|
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _numRounds,
|
|
|
|
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
|
|
|
getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
2015-08-16 00:18:53 +00:00
|
|
|
};
|
2015-08-15 16:43:13 +00:00
|
|
|
} else {
|
|
|
|
for "_idx" from 1 to _maxMagazines do {
|
2015-08-18 00:32:10 +00:00
|
|
|
_currentRounds = _target magazineTurretAmmo [_magazineClass, _turretPath];
|
2015-08-15 16:43:13 +00:00
|
|
|
if (_currentRounds > 0) exitWith {
|
2015-08-16 00:18:53 +00:00
|
|
|
if (GVAR(level) == 2) then {
|
2015-08-18 00:32:10 +00:00
|
|
|
//hint format ["Target: %1\nTurretPath: %2\nNumMagazines: %3\nMaxMagazines %4\nMagazine: %5\nNumRounds: %6\nMagazine: %7", _target, _turretPath, _numMagazines, _maxMagazines, _currentRounds, _numRounds, _magazineClass];
|
2015-08-16 00:18:53 +00:00
|
|
|
// Fill only at most _numRounds
|
|
|
|
if ((_currentRounds + _numRounds) > _rounds) then {
|
2015-08-18 00:32:10 +00:00
|
|
|
_target setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath];
|
2015-08-16 00:18:53 +00:00
|
|
|
if (_numMagazines < _maxMagazines) then {
|
2015-08-18 00:32:10 +00:00
|
|
|
_target addMagazineTurret [_magazineClass, _turretPath];
|
|
|
|
_target setMagazineTurretAmmo [_magazineClass, _currentRounds + _numRounds - _rounds, _turretPath];
|
2015-08-16 00:18:53 +00:00
|
|
|
};
|
|
|
|
} else {
|
2015-08-18 00:32:10 +00:00
|
|
|
_target setMagazineTurretAmmo [_magazineClass, _currentRounds + _numRounds, _turretPath];
|
2015-08-16 00:18:53 +00:00
|
|
|
};
|
2015-08-18 15:38:50 +00:00
|
|
|
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _numRounds,
|
|
|
|
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
|
|
|
getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
2015-08-16 00:18:53 +00:00
|
|
|
} else {
|
|
|
|
// Fill current magazine completely and fill next magazine partially
|
2015-08-18 00:32:10 +00:00
|
|
|
_target setMagazineTurretAmmo [_magazineClass, _rounds, _turretPath];
|
2015-08-15 16:43:13 +00:00
|
|
|
if (_numMagazines < _maxMagazines) then {
|
2015-08-18 00:32:10 +00:00
|
|
|
_target addMagazineTurret [_magazineClass, _turretPath];
|
|
|
|
_target setMagazineTurretAmmo [_magazineClass, _currentRounds, _turretPath];
|
2015-08-15 16:43:13 +00:00
|
|
|
};
|
2015-08-18 15:38:50 +00:00
|
|
|
["displayTextStructured", [_unit], [[LSTRING(Hint_RearmedTriple), _rounds,
|
|
|
|
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
|
|
|
getText(configFile >> "CfgVehicles" >> (typeOf _target) >> "displayName")], 3, _unit]] call EFUNC(common,targetEvent);
|
2015-08-15 16:43:13 +00:00
|
|
|
};
|
|
|
|
};
|
2015-08-18 00:32:10 +00:00
|
|
|
_target removeMagazineTurret [_magazineClass, _turretPath];
|
2015-08-16 00:18:53 +00:00
|
|
|
_numMagazines = _numMagazines - 1;
|
2015-08-15 16:43:13 +00:00
|
|
|
};
|
2015-08-18 00:32:10 +00:00
|
|
|
};
|