2019-06-08 04:47:39 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
/*
|
2022-01-30 17:54:30 +00:00
|
|
|
* Author: Dani (TCVM), PabstMirror
|
2019-06-08 04:47:39 +00:00
|
|
|
* Dumps ammo to container
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Weapon <OBJECT>
|
2019-07-05 22:57:22 +00:00
|
|
|
* 1: Using advanced assembly <BOOL>
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2019-07-05 22:57:22 +00:00
|
|
|
* [cursorObject, false] call ace_csw_fnc_staticWeaponInit_unloadExtraMags
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2019-07-05 22:57:22 +00:00
|
|
|
params ["_staticWeapon", "_assemblyMode", "_emptyWeapon"];
|
|
|
|
TRACE_3("staticWeaponInit_unloadExtraMags",_staticWeapon,_assemblyMode,_emptyWeapon);
|
2019-06-08 04:47:39 +00:00
|
|
|
if (!_assemblyMode) exitWith {};
|
|
|
|
|
2021-02-18 18:58:08 +00:00
|
|
|
private _desiredAmmo = getNumber (configOf _staticWeapon >> QUOTE(ADDON) >> "desiredAmmo");
|
2019-06-08 04:47:39 +00:00
|
|
|
private _storeExtraMagazines = GVAR(handleExtraMagazines);
|
|
|
|
if (_emptyWeapon) then {
|
|
|
|
_desiredAmmo = 0;
|
|
|
|
_storeExtraMagazines = false;
|
|
|
|
};
|
2019-07-05 22:57:22 +00:00
|
|
|
TRACE_3("settings",_emptyWeapon,_desiredAmmo,_storeExtraMagazines);
|
2019-06-08 04:47:39 +00:00
|
|
|
|
|
|
|
private _magsToRemove = [];
|
|
|
|
private _loadedMagazineInfo = [];
|
|
|
|
private _containerMagazineClassnames = [];
|
|
|
|
private _containerMagazineCount = [];
|
|
|
|
|
|
|
|
{
|
|
|
|
_x params ["_xMag", "_xTurret", "_xAmmo"];
|
|
|
|
|
2022-03-07 18:29:19 +00:00
|
|
|
private _carryMag = GVAR(vehicleMagCache) get _xMag;
|
2019-06-08 04:47:39 +00:00
|
|
|
if (isNil "_carryMag") then {
|
2020-03-11 23:42:21 +00:00
|
|
|
private _groups = "getNumber (_x >> _xMag) == 1 && {isClass (configFile >> 'CfgMagazines' >> configName _x)}" configClasses (configFile >> QGVAR(groups));
|
2019-06-08 04:47:39 +00:00
|
|
|
_carryMag = configName (_groups param [0, configNull]);
|
2022-03-07 18:29:19 +00:00
|
|
|
GVAR(vehicleMagCache) set [_xMag, _carryMag];
|
2019-06-08 04:47:39 +00:00
|
|
|
TRACE_2("setting cache",_xMag,_carryMag);
|
|
|
|
};
|
|
|
|
if (_carryMag != "") then {
|
|
|
|
if ((_desiredAmmo > 0) && {_loadedMagazineInfo isEqualTo []}) then {
|
|
|
|
private _loadedMagAmmo = _desiredAmmo min _xAmmo;
|
|
|
|
_loadedMagazineInfo = [_xMag, _xTurret, _loadedMagAmmo];
|
|
|
|
_xAmmo = _xAmmo - _loadedMagAmmo;
|
|
|
|
TRACE_1("",_loadedMagAmmo);
|
|
|
|
};
|
|
|
|
if (_xAmmo > 0) then {
|
|
|
|
_magsToRemove pushBackUnique [_xMag, _xTurret];
|
|
|
|
private _index = _containerMagazineClassnames find _carryMag;
|
|
|
|
if (_index < 0) then {
|
|
|
|
_index = _containerMagazineClassnames pushBack _carryMag;
|
|
|
|
_containerMagazineCount pushBack 0;
|
|
|
|
};
|
|
|
|
_containerMagazineCount set [_index, (_containerMagazineCount select _index) + _xAmmo];
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
if ((_xMag select [0,4]) != "fake") then { WARNING_1("Unable to unload [%1] - No matching carry mag",_xMag); };
|
|
|
|
};
|
|
|
|
} forEach (magazinesAllTurrets _staticWeapon);
|
|
|
|
|
|
|
|
|
|
|
|
TRACE_1("Remove all loaded magazines",_magsToRemove);
|
|
|
|
{
|
|
|
|
_staticWeapon removeMagazinesTurret _x;
|
|
|
|
if ((_loadedMagazineInfo select [0,2]) isEqualTo _x) then {
|
|
|
|
TRACE_1("Re-add the starting mag",_loadedMagazineInfo);
|
|
|
|
_staticWeapon addMagazineTurret _loadedMagazineInfo;
|
|
|
|
};
|
|
|
|
} forEach _magsToRemove;
|
|
|
|
|
|
|
|
|
|
|
|
if (_storeExtraMagazines) then {
|
|
|
|
TRACE_1("saving extra mags to container",_containerMagazineCount);
|
|
|
|
{
|
|
|
|
[_staticWeapon, _x, _containerMagazineCount select _forEachIndex] call FUNC(reload_handleReturnAmmo);
|
|
|
|
} forEach _containerMagazineClassnames;
|
|
|
|
};
|