2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-08-18 16:09:37 +00:00
|
|
|
/*
|
|
|
|
* Author: GitHawk
|
|
|
|
* Rearms a vehicle on the turret owner.
|
|
|
|
*
|
|
|
|
* Arguments:
|
2017-06-08 16:47:52 +00:00
|
|
|
* 0: Vehicle <OBJECT>
|
|
|
|
* 1: Unit <OBJECT>
|
|
|
|
* 2: Turret Path <ARRAY>
|
|
|
|
* 3: Number of magazines <NUMBER>
|
|
|
|
* 4: Magazine Classname <STRING>
|
|
|
|
* 5: Number of rounds <NUMBER>
|
|
|
|
* 6: Pylon Index <NUMBER>
|
2015-08-18 16:09:37 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2017-06-08 16:47:52 +00:00
|
|
|
* [vehicle, player, [-1], 2, "5000Rnd_762x51_Belt", 500, ""] call ace_rearm_fnc_rearmSuccessLocal
|
2015-08-18 16:09:37 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2017-06-08 16:47:52 +00:00
|
|
|
params ["_vehicle", "_unit", "_turretPath", "_numMagazines", "_magazineClass", "_numRounds", "_pylon"];
|
|
|
|
TRACE_7("rearmSuccessLocal",_vehicle,_unit,_turretPath,_numMagazines,_magazineClass,_numRounds,_pylon);
|
2015-08-18 16:09:37 +00:00
|
|
|
|
2016-02-27 19:31:07 +00:00
|
|
|
private _rounds = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "count");
|
2017-06-08 16:47:52 +00:00
|
|
|
|
|
|
|
if (_pylon > 0) exitWith {
|
2018-07-19 23:40:04 +00:00
|
|
|
if (GVAR(level) == 1) then {
|
|
|
|
// Fill magazine completely
|
|
|
|
if (_turretPath isEqualTo [-1]) then {_turretPath = [];}; // Convert back to pylon turret format
|
2019-03-21 13:52:32 +00:00
|
|
|
TRACE_3("",_pylon,_magazineClass,_rounds);
|
2018-07-19 23:40:04 +00:00
|
|
|
_vehicle setPylonLoadOut [_pylon, _magazineClass, true, _turretPath];
|
|
|
|
[QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _rounds,
|
2019-01-31 00:48:40 +00:00
|
|
|
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
2021-02-18 18:58:08 +00:00
|
|
|
getText(configOf _vehicle >> "displayName")], 3, _unit], [_unit]] call CBA_fnc_targetEvent;
|
2018-07-19 23:40:04 +00:00
|
|
|
} else {
|
|
|
|
// Fill only at most _numRounds
|
|
|
|
if (_turretPath isEqualTo [-1]) then {_turretPath = [];}; // Convert back to pylon turret format
|
|
|
|
private _currentCount = _vehicle ammoOnPylon _pylon;
|
|
|
|
private _newCount = ((_currentCount max 0) + _numRounds) min _rounds;
|
2019-03-21 13:52:32 +00:00
|
|
|
TRACE_3("",_pylon,_magazineClass,_newCount);
|
2018-07-19 23:40:04 +00:00
|
|
|
_vehicle setPylonLoadOut [_pylon, _magazineClass, true, _turretPath];
|
|
|
|
_vehicle setAmmoOnPylon [_pylon, _newCount];
|
|
|
|
[QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _numRounds,
|
2019-01-31 00:48:40 +00:00
|
|
|
getText(configFile >> "CfgMagazines" >> _magazineClass >> "displayName"),
|
2021-02-18 18:58:08 +00:00
|
|
|
getText(configOf _vehicle >> "displayName")], 3, _unit], [_unit]] call CBA_fnc_targetEvent;
|
2018-07-19 23:40:04 +00:00
|
|
|
};
|
2017-06-08 16:47:52 +00:00
|
|
|
};
|
|
|
|
|
2016-02-27 19:31:07 +00:00
|
|
|
private _currentRounds = 0;
|
2016-02-27 20:05:19 +00:00
|
|
|
private _maxMagazines = [_vehicle, _turretPath, _magazineClass] call FUNC(getMaxMagazines);
|
2019-01-31 00:48:40 +00:00
|
|
|
private _ammoCounts = [_vehicle, _turretPath, _magazineClass] call FUNC(getTurretMagazineAmmo);
|
|
|
|
TRACE_3("start",_magazineClass,_maxMagazines,_ammoCounts);
|
2015-08-18 16:09:37 +00:00
|
|
|
|
2024-02-04 17:50:24 +00:00
|
|
|
private _ammoToAdd = [_rounds, _numRounds] select (GVAR(level) == 2);
|
2019-01-31 00:48:40 +00:00
|
|
|
private _ammoAdded = 0;
|
|
|
|
private _arrayModified = false; // skip needing to remove and re-add mags, if we are only adding new ones
|
|
|
|
|
|
|
|
{
|
|
|
|
if (_x < _rounds) then {
|
|
|
|
private _xAdd = _ammoToAdd min (_rounds - _x);
|
|
|
|
_ammoToAdd = _ammoToAdd - _xAdd;
|
|
|
|
_ammoAdded = _ammoAdded + _xAdd;
|
|
|
|
TRACE_3("adding to existing mag",_forEachIndex,_x,_xAdd);
|
|
|
|
_ammoCounts set [_forEachIndex, _x + _xAdd];
|
|
|
|
_arrayModified = true;
|
2016-02-01 19:05:53 +00:00
|
|
|
};
|
2019-01-31 00:48:40 +00:00
|
|
|
} forEach _ammoCounts;
|
|
|
|
|
|
|
|
while {((count _ammoCounts) < _maxMagazines) && {_ammoToAdd > 0}} do {
|
|
|
|
private _xAdd = _ammoToAdd min _rounds;
|
|
|
|
_ammoToAdd = _ammoToAdd - _xAdd;
|
|
|
|
_ammoAdded = _ammoAdded + _xAdd;
|
|
|
|
_ammoCounts pushBack _xAdd;
|
2021-07-24 05:20:17 +00:00
|
|
|
if (_arrayModified) then {
|
2019-01-31 00:48:40 +00:00
|
|
|
TRACE_1("adding new mag to array",_xAdd);
|
2015-08-18 16:09:37 +00:00
|
|
|
} else {
|
2019-01-31 00:48:40 +00:00
|
|
|
TRACE_1("adding new mag directly",_xAdd);
|
|
|
|
_vehicle addMagazineTurret [_magazineClass, _turretPath, _xAdd];
|
2015-08-18 16:09:37 +00:00
|
|
|
};
|
|
|
|
};
|
2019-01-31 00:48:40 +00:00
|
|
|
TRACE_3("finish",_ammoToAdd,_ammoAdded,_arrayModified);
|
|
|
|
if (_arrayModified) then { // only need to call this if we modified the array, otherwise they are already added
|
|
|
|
[_vehicle, _turretPath, _magazineClass, _ammoCounts] call FUNC(setTurretMagazineAmmo);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_ammoAdded == 0) exitWith {ERROR_1("could not load any ammo - %1",_this);};
|
|
|
|
|
|
|
|
[QEGVAR(common,displayTextStructured), [[LSTRING(Hint_RearmedTriple), _ammoAdded,
|
|
|
|
_magazineClass call FUNC(getMagazineName),
|
2021-02-18 18:58:08 +00:00
|
|
|
getText(configOf _vehicle >> "displayName")], 3, _unit], [_unit]] call CBA_fnc_targetEvent;
|