2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2019-06-08 04:47:39 +00:00
|
|
|
/*
|
2024-07-27 17:42:31 +00:00
|
|
|
* Author: PabstMirror, tcvm
|
|
|
|
* Tests if unit can load a magazine into a CSW.
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2024-07-27 17:42:31 +00:00
|
|
|
* 0: CSW <OBJECT>
|
2019-06-08 04:47:39 +00:00
|
|
|
* 1: Turret Path <ARRAY>
|
|
|
|
* 2: Carryable Magazine <STRING>
|
2024-07-27 17:42:31 +00:00
|
|
|
* 3: Supplier <OBJECT> (default: objNull)
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2024-07-27 17:42:31 +00:00
|
|
|
* [Can Load <BOOL>, Loaded Mag <STRING>, Ammo Needed <NUMBER>, Is Belt Linking <BOOL>] <ARRAY>
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [cursorObject, [0], "ACE_csw_100Rnd_127x99_mag_red", player] call ace_csw_fnc_reload_canLoadMagazine
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2022-03-07 18:29:19 +00:00
|
|
|
params ["_vehicle", "_turret", "_carryMag", ["_magSource", objNull]];
|
|
|
|
// TRACE_4("reload_canLoadMagazine",_vehicle,_turret,_carryMag,_magSource);
|
|
|
|
|
|
|
|
private _return = [false, "", -2, false];
|
2019-06-08 04:47:39 +00:00
|
|
|
|
|
|
|
// Handle disassembled or deleted
|
2022-03-07 18:29:19 +00:00
|
|
|
if (!alive _vehicle) exitWith { _return };
|
|
|
|
// Verify holder has carry magazine
|
|
|
|
if (
|
|
|
|
(!isNull _magSource) &&
|
2024-07-27 17:42:31 +00:00
|
|
|
{!((_magSource isKindOf "Bag_Base") || {_magSource isKindOf "ContainerSupply"})} && // Hacky workaround for magazines within dropped backpacks
|
2022-03-07 18:29:19 +00:00
|
|
|
{
|
|
|
|
((_vehicle distance _magSource) > 10) ||
|
|
|
|
{((magazineCargo _magSource) findIf {_x == _carryMag}) == -1}
|
|
|
|
}
|
|
|
|
) exitWith { _return };
|
|
|
|
|
|
|
|
// solve config lookups
|
|
|
|
private _cfgMagazines = configFile >> "CfgMagazines";
|
|
|
|
private _cfgMagazinesCarryMag = _cfgMagazines >> _carryMag;
|
2022-12-10 20:15:28 +00:00
|
|
|
private _cfgGroupsCarryMag = configFile >> QGVAR(groups) >> _carryMag;
|
2019-06-08 04:47:39 +00:00
|
|
|
|
2021-02-18 18:58:08 +00:00
|
|
|
private _desiredAmmo = getNumber (configOf _vehicle >> QUOTE(ADDON) >> "desiredAmmo");
|
2019-06-08 04:47:39 +00:00
|
|
|
if (_desiredAmmo == 0) then { _desiredAmmo = 100; };
|
2024-07-27 17:42:31 +00:00
|
|
|
private _ammoNeeded = _desiredAmmo min getNumber (_cfgMagazinesCarryMag >> "count"); // Assume it needs full carry mag
|
2019-06-08 04:47:39 +00:00
|
|
|
private _loadedMag = "";
|
|
|
|
private _isBeltLinking = false;
|
|
|
|
|
|
|
|
scopeName "main";
|
|
|
|
{
|
|
|
|
_x params ["_xMag", "_xTurret", "_xAmmo"];
|
|
|
|
if (_xTurret isEqualTo _turret) then {
|
|
|
|
if (_loadedMag != "") exitWith { [false, _loadedMag, -3, false] breakOut "main"; }; // Exit if static has multiple mags
|
|
|
|
_loadedMag = _xMag;
|
|
|
|
if (_xAmmo > 0) then {
|
|
|
|
// There is a magazine with ammo loaded in the turret (are there any multi-muzzle static weapons??), see if we can add to this mag
|
2022-12-10 20:15:28 +00:00
|
|
|
if (getNumber (_cfgGroupsCarryMag >> _xMag) != 1) exitWith {
|
2019-06-08 04:47:39 +00:00
|
|
|
[false, _loadedMag, -4, false] breakOut "main"; // Carry mag cannot be added to existing vehicle mag (e.g. red to green tracers)
|
|
|
|
};
|
2022-03-07 18:29:19 +00:00
|
|
|
if (getNumber (_cfgMagazinesCarryMag >> "ACE_isBelt") == 0) exitWith {
|
2019-06-08 04:47:39 +00:00
|
|
|
[false, _loadedMag, -5, false] breakOut "main"; // Non-linkable mag loaded, can't add any more
|
|
|
|
};
|
2022-03-07 18:29:19 +00:00
|
|
|
private _maxMagazineAmmo = _desiredAmmo min getNumber (_cfgMagazines >> _xMag >> "count");
|
2019-06-08 04:47:39 +00:00
|
|
|
if (_xAmmo >= _maxMagazineAmmo) exitWith {
|
2024-07-27 17:42:31 +00:00
|
|
|
[false, _loadedMag, -6, false] breakOut "main"; // Already at capacity
|
2019-06-08 04:47:39 +00:00
|
|
|
};
|
|
|
|
_ammoNeeded = _maxMagazineAmmo - _xAmmo;
|
|
|
|
_isBeltLinking = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} forEach (magazinesAllTurrets _vehicle);
|
|
|
|
|
|
|
|
[true, _loadedMag, _ammoNeeded, _isBeltLinking]
|