2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2019-06-08 04:47:39 +00:00
|
|
|
/*
|
2023-08-16 23:18:01 +00:00
|
|
|
* Author:tcvm
|
2019-06-08 04:47:39 +00:00
|
|
|
* Handles removing ammo from a turret
|
|
|
|
* Called from a global event but only runs where turret is local
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Static Weapon <OBJECT>
|
|
|
|
* 1: Turret Path <ARRAY>
|
|
|
|
* 2: Magainze Unit Can Carry <STRING>
|
|
|
|
* 3: Magazine To Remove From Static <STRING>
|
2022-03-07 18:29:19 +00:00
|
|
|
* 4: Unit or container to unload to <OBJECT>
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [cursorTarget, [0], "ACE_csw_100Rnd_127x99_mag_red", "500Rnd_127x99_mag_Tracer_Green", player] call ace_csw_fnc_reload_handleRemoveTurretMag
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2022-03-07 18:29:19 +00:00
|
|
|
params ["_vehicle", "_turretPath", "_carryMag", "_vehMag", "_unloadTo"];
|
|
|
|
TRACE_5("removeTurretMag EH",_vehicle,_turretPath,_carryMag,_vehMag,_unloadTo);
|
2019-06-08 04:47:39 +00:00
|
|
|
|
2022-03-07 18:29:19 +00:00
|
|
|
TRACE_3("",local _vehicle, _vehicle turretLocal _turretPath,local _unloadTo);
|
2019-06-08 04:47:39 +00:00
|
|
|
if (!(_vehicle turretLocal _turretPath)) exitWith {};
|
|
|
|
|
|
|
|
private _magsInWeapon = []; // Check how much ammo it has now:
|
|
|
|
{
|
|
|
|
_x params ["_xMag", "_xTurret", "_xAmmo"];
|
|
|
|
if ((_xMag == _vehMag) && {_xTurret isEqualTo _turretPath}) then {
|
|
|
|
_magsInWeapon pushBack _xAmmo;
|
|
|
|
};
|
|
|
|
} forEach (magazinesAllTurrets _vehicle);
|
|
|
|
TRACE_1("",_magsInWeapon);
|
|
|
|
|
|
|
|
// Remove any empty mags from start:
|
|
|
|
private _ammoInFirstMag = 0;
|
2021-02-27 17:05:05 +00:00
|
|
|
while {(_magsInWeapon isNotEqualTo []) && {_ammoInFirstMag = _magsInWeapon deleteAt 0; (_ammoInFirstMag == 0)}} do {
|
2019-06-08 04:47:39 +00:00
|
|
|
TRACE_1("Removing empty mag",_ammoInFirstMag);
|
|
|
|
_vehicle removeMagazineTurret [_vehMag, _turretPath];
|
|
|
|
};
|
|
|
|
TRACE_2("",_magsInWeapon,_ammoInFirstMag);
|
|
|
|
if ((_magsInWeapon isEqualTo []) && {_ammoInFirstMag == 0}) exitWith {};
|
|
|
|
|
|
|
|
private _maxAmmo = getNumber (configFile >> "CfgMagazines" >> _carryMag >> "count");
|
|
|
|
private _ammoRemoved = _ammoInFirstMag min _maxAmmo;
|
|
|
|
private _ammoLeft = _ammoInFirstMag - _ammoRemoved;
|
|
|
|
|
|
|
|
if ((_magsInWeapon isEqualTo []) && {_ammoInFirstMag > _ammoRemoved}) then {
|
|
|
|
// Only one mag in gun, and we're just taking out a partial ammount (unlinking)
|
|
|
|
TRACE_2("Setting mag ammo",_ammoRemoved,_ammoLeft);
|
|
|
|
// _vehicle setMagazineTurretAmmo [_vehMag, _ammoLeft, _turretPath];
|
|
|
|
|
|
|
|
// setMagazineTurretAmmo is broken on split locality, use setAmmo for now
|
|
|
|
private _weapon = (_vehicle weaponsTurret _turretPath) param [0, ""];
|
|
|
|
TRACE_3("setAmmo",_vehicle,_weapon, _ammoLeft);
|
|
|
|
_vehicle setAmmo [_weapon, _ammoLeft];
|
|
|
|
private _currentAmmo = _vehicle magazineTurretAmmo [_vehMag, _turretPath];
|
|
|
|
if ((_weapon == "") || {_currentAmmo != _ammoLeft}) then { ERROR_1("failed to setAmmo - %1", _this); };
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Because of command limitations, we need to remove mags to change their ammo
|
|
|
|
// This will cause the gun to need to be reloaded if more than one is loaded (only a problem for non-assembly mode guns)
|
|
|
|
TRACE_2("Removing magazine",_ammoRemoved,_ammoLeft);
|
|
|
|
_vehicle removeMagazinesTurret [_vehMag, _turretPath];
|
|
|
|
if (_ammoLeft > 0) then {
|
|
|
|
_magsInWeapon pushBack _ammoLeft;
|
|
|
|
TRACE_1("Re-adding partial",_ammoLeft);
|
|
|
|
};
|
|
|
|
{
|
|
|
|
if (_x > 0) then { _vehicle addMagazineTurret [_vehMag, _turretPath, _x]; };
|
|
|
|
} forEach _magsInWeapon;
|
|
|
|
};
|
|
|
|
|
2022-03-07 18:29:19 +00:00
|
|
|
TRACE_3("Returning ammo",_unloadTo,_carryMag,_ammoRemoved);
|
|
|
|
[QGVAR(returnAmmo), [_unloadTo, _carryMag, _ammoRemoved], _unloadTo] call CBA_fnc_targetEvent;
|