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, PabstMirror
|
2024-07-27 17:42:31 +00:00
|
|
|
* Dumps ammo to container.
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2024-07-27 17:42:31 +00:00
|
|
|
* 0: CSW <OBJECT>
|
2019-07-05 22:57:22 +00:00
|
|
|
* 1: Using advanced assembly <BOOL>
|
2024-07-27 17:42:31 +00:00
|
|
|
* 2: Empty weapon <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
|
|
|
|
*/
|
|
|
|
|
2024-07-27 17:42:31 +00:00
|
|
|
params ["_vehicle", "_assemblyMode", "_emptyWeapon"];
|
|
|
|
TRACE_3("staticWeaponInit_unloadExtraMags",_vehicle,_assemblyMode,_emptyWeapon);
|
2019-06-08 04:47:39 +00:00
|
|
|
if (!_assemblyMode) exitWith {};
|
|
|
|
|
2024-07-27 17:42:31 +00:00
|
|
|
private _desiredAmmo = getNumber (configOf _vehicle >> 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-05-02 23:54:04 +00:00
|
|
|
private _carryMag = _xMag call FUNC(getCarryMagazine);
|
2019-06-08 04:47:39 +00:00
|
|
|
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); };
|
|
|
|
};
|
2024-07-27 17:42:31 +00:00
|
|
|
} forEach (magazinesAllTurrets _vehicle);
|
2019-06-08 04:47:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
TRACE_1("Remove all loaded magazines",_magsToRemove);
|
|
|
|
{
|
2024-07-27 17:42:31 +00:00
|
|
|
_vehicle removeMagazinesTurret _x;
|
2019-06-08 04:47:39 +00:00
|
|
|
if ((_loadedMagazineInfo select [0,2]) isEqualTo _x) then {
|
|
|
|
TRACE_1("Re-add the starting mag",_loadedMagazineInfo);
|
2024-07-27 17:42:31 +00:00
|
|
|
_vehicle addMagazineTurret _loadedMagazineInfo;
|
2019-06-08 04:47:39 +00:00
|
|
|
};
|
|
|
|
} forEach _magsToRemove;
|
|
|
|
|
2024-07-27 17:42:31 +00:00
|
|
|
private _secondaryWeaponMagazines = _vehicle getVariable [QGVAR(secondaryWeaponMagazines), []];
|
2024-06-22 17:03:32 +00:00
|
|
|
|
|
|
|
if (_secondaryWeaponMagazines isNotEqualTo []) then {
|
|
|
|
// Check if the static weapon can take magazines
|
2024-07-27 17:42:31 +00:00
|
|
|
private _turret = (allTurrets _vehicle) param [0, []];
|
|
|
|
private _compatibleMagazinesTurret = flatten ((_vehicle weaponsTurret _turret) apply {compatibleMagazines _x});
|
2024-06-22 17:03:32 +00:00
|
|
|
private _container = objNull;
|
|
|
|
|
|
|
|
{
|
2024-07-27 17:42:31 +00:00
|
|
|
private _vehicleMag = [_vehicle, _turret, _x select 0] call FUNC(reload_getVehicleMagazine);
|
2024-06-22 17:03:32 +00:00
|
|
|
TRACE_3("Re-add previous mag",_x select 0,_turret,_vehicleMag);
|
|
|
|
|
|
|
|
// If the magazine can be added to the static weapon, do it now
|
|
|
|
if (_vehicleMag in _compatibleMagazinesTurret) then {
|
2024-07-27 17:42:31 +00:00
|
|
|
_vehicle addMagazineTurret [_vehicleMag, _turret, _x select 1];
|
2024-06-22 17:03:32 +00:00
|
|
|
} else {
|
|
|
|
// Find a suitable container to place items in if necessary
|
|
|
|
if (isNull _container) then {
|
2024-07-27 17:42:31 +00:00
|
|
|
_container = (nearestObjects [_vehicle, ["GroundWeaponHolder"], 10]) param [0, objNull];
|
2024-06-22 17:03:32 +00:00
|
|
|
|
|
|
|
// Create ammo storage container
|
|
|
|
if (isNull _container) then {
|
2024-07-27 17:42:31 +00:00
|
|
|
_container = createVehicle ["GroundWeaponHolder", getPosATL _vehicle, [], 0, "NONE"];
|
2024-06-22 17:03:32 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// If the mag can't be added to the static weapon, add it to the ground holder
|
|
|
|
_container addMagazineAmmoCargo [_x select 0, 1, _x select 1];
|
|
|
|
};
|
|
|
|
} forEach _secondaryWeaponMagazines;
|
|
|
|
|
2024-07-27 17:42:31 +00:00
|
|
|
_vehicle setVariable [QGVAR(secondaryWeaponMagazines), nil, true];
|
2022-05-04 22:28:58 +00:00
|
|
|
};
|
2019-06-08 04:47:39 +00:00
|
|
|
|
|
|
|
if (_storeExtraMagazines) then {
|
|
|
|
TRACE_1("saving extra mags to container",_containerMagazineCount);
|
|
|
|
{
|
2024-07-27 17:42:31 +00:00
|
|
|
[_vehicle, _x, _containerMagazineCount select _forEachIndex] call FUNC(reload_handleReturnAmmo);
|
2019-06-08 04:47:39 +00:00
|
|
|
} forEach _containerMagazineClassnames;
|
|
|
|
};
|