diff --git a/addons/csw/functions/fnc_assemble_deployTripod.sqf b/addons/csw/functions/fnc_assemble_deployTripod.sqf index 9c67750502..35c3fb70c2 100644 --- a/addons/csw/functions/fnc_assemble_deployTripod.sqf +++ b/addons/csw/functions/fnc_assemble_deployTripod.sqf @@ -21,12 +21,14 @@ // Remove the tripod from the launcher slot private _secondaryWeaponClassname = secondaryWeapon _player; + // handle loaded launchers which can become csw like CUP Metis + private _secondaryWeaponMagazine = secondaryWeaponMagazine _player param [0, ""]; _player removeWeaponGlobal (secondaryWeapon _player); private _onFinish = { params ["_args"]; - _args params ["_player", "_secondaryWeaponClassname"]; - TRACE_2("deployTripod finish",_player,_secondaryWeaponClassname); + _args params ["_player", "_secondaryWeaponClassname", "_secondaryWeaponMagazine"]; + TRACE_3("deployTripod finish",_player,_secondaryWeaponClassname,_secondaryWeaponMagazine); private _tripodClassname = getText(configFile >> "CfgWeapons" >> _secondaryWeaponClassname >> QUOTE(ADDON) >> "deploy"); @@ -34,6 +36,9 @@ private _cswTripod = createVehicle [_tripodClassname, [0, 0, 0], [], 0, "NONE"]; // Because the tripod can be a "full weapon" we disable any data that will allow it to be loaded _cswTripod setVariable [QGVAR(assemblyMode), 2, true]; // Explicitly set enabled&unload assembly mode and broadcast + if (_secondaryWeaponMagazine isNotEqualTo "") then { + _cswTripod setVariable [QGVAR(secondaryWeaponMagazine), _secondaryWeaponMagazine]; + }; if (!GVAR(defaultAssemblyMode)) then { TRACE_1("global disableVanillaAssembly event",_cswTripod); // handles it being assembled when setting is disabled [QGVAR(disableVanillaAssembly), [_cswTripod]] call CBA_fnc_globalEvent; @@ -61,12 +66,15 @@ private _onFailure = { params ["_args"]; - _args params ["_player", "_secondaryWeaponClassname"]; - TRACE_2("deployTripod failure",_player,_secondaryWeaponClassname); + _args params ["_player", "_secondaryWeaponClassname", "_secondaryWeaponMagazine"]; + TRACE_3("deployTripod failure",_player,_secondaryWeaponClassname,_secondaryWeaponMagazine); _player addWeaponGlobal _secondaryWeaponClassname; + if (_secondaryWeaponMagazine isNotEqualTo "") then { + _player addWeaponItem [_secondaryWeaponClassname, _secondaryWeaponMagazine, true]; + }; }; private _deployTime = getNumber(configFile >> "CfgWeapons" >> _secondaryWeaponClassname >> QUOTE(ADDON) >> "deployTime"); - [TIME_PROGRESSBAR(_deployTime), [_player, _secondaryWeaponClassname], _onFinish, _onFailure, localize LSTRING(PlaceTripod_progressBar)] call EFUNC(common,progressBar); + [TIME_PROGRESSBAR(_deployTime), [_player, _secondaryWeaponClassname, _secondaryWeaponMagazine], _onFinish, _onFailure, localize LSTRING(PlaceTripod_progressBar)] call EFUNC(common,progressBar); }, _this] call CBA_fnc_execNextFrame; diff --git a/addons/csw/functions/fnc_assemble_pickupWeapon.sqf b/addons/csw/functions/fnc_assemble_pickupWeapon.sqf index 51c2a5128d..9b17fcaf73 100644 --- a/addons/csw/functions/fnc_assemble_pickupWeapon.sqf +++ b/addons/csw/functions/fnc_assemble_pickupWeapon.sqf @@ -37,11 +37,19 @@ _weaponPos set [2, (_weaponPos select 2) + 0.1]; private _weaponDir = getDir _staticWeapon; + private _carryWeaponMag = ""; + private _carryWeaponMags = getArray (configFile >> "CfgWeapons" >> _carryWeaponClassname >> "magazines") apply {toLower _x}; LOG("remove ammo"); { _x params ["_xMag", "", "_xAmmo"]; + if (_xAmmo == 0) then {continue}; private _carryMag = _xMag call FUNC(getCarryMagazine); + if (_carryWeaponMag isEqualTo "" && {toLower _carryMag in _carryWeaponMags}) then { + TRACE_3("Adding mag to secondary weapon",_xMag,_xAmmo,_carryMag); + _carryWeaponMag = _carryMag; + DEC(_xAmmo); + }; if ((_xAmmo > 0) && {_carryMag != ""}) then { TRACE_2("Removing ammo",_xMag,_carryMag); [_player, _carryMag, _xAmmo] call FUNC(reload_handleReturnAmmo); @@ -62,16 +70,23 @@ }; [{ - params ["_player", "_weaponPos", "_carryWeaponClassname"]; + params ["_player", "_weaponPos", "_carryWeaponClassname", "_carryWeaponMag"]; if ((alive _player) && {(secondaryWeapon _player) == ""}) exitWith { _player addWeapon _carryWeaponClassname; + if (_carryWeaponMag isNotEqualTo "") then { + _player addWeaponItem [_carryWeaponClassname, _carryWeaponMag, true]; + }; }; private _weaponRelPos = _weaponPos getPos RELATIVE_DIRECTION(90); private _weaponHolder = createVehicle ["groundWeaponHolder", [0, 0, 0], [], 0, "NONE"]; _weaponHolder setDir random [0, 180, 360]; _weaponHolder setPosATL [_weaponRelPos select 0, _weaponRelPos select 1, _weaponPos select 2]; - _weaponHolder addWeaponCargoGlobal [_carryWeaponClassname, 1]; - }, [_player, _weaponPos, _carryWeaponClassname]] call CBA_fnc_execNextFrame; + if (_carryWeaponMag isEqualTo "") then { + _weaponHolder addWeaponCargoGlobal [_carryWeaponClassname, 1]; + } else { + _weaponHolder addWeaponWithAttachmentsCargoGlobal [[_carryWeaponClassname, "", "", "", [_carryWeaponMag, 1], [], ""], 1]; + }; + }, [_player, _weaponPos, _carryWeaponClassname, _carryWeaponMag]] call CBA_fnc_execNextFrame; LOG("delete weapon"); deleteVehicle _staticWeapon; diff --git a/addons/csw/functions/fnc_reload_getVehicleMagazine.sqf b/addons/csw/functions/fnc_reload_getVehicleMagazine.sqf index 2b28535f0a..f8053df3b9 100644 --- a/addons/csw/functions/fnc_reload_getVehicleMagazine.sqf +++ b/addons/csw/functions/fnc_reload_getVehicleMagazine.sqf @@ -4,8 +4,9 @@ * Finds the best vehicle magazines to create from a carryable magazine for a given weapon. * * Arguments: - * 0: Weapon - * 1: Magazine that is carryable + * 0: Vehicle + * 1: Turret + * 2: Magazine that is carryable * * Return Value: * Vehicle Magazine diff --git a/addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf b/addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf index a1104afd74..41845c0eb3 100644 --- a/addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf +++ b/addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf @@ -68,6 +68,15 @@ TRACE_1("Remove all loaded magazines",_magsToRemove); }; } forEach _magsToRemove; +if (_staticWeapon getVariable [QGVAR(secondaryWeaponMagazine), ""] isNotEqualTo "") then { + private _secondaryWeaponMagazine = _staticWeapon getVariable QGVAR(secondaryWeaponMagazine); + private _turret = allTurrets _staticWeapon param [0, []]; + private _vehicleMag = [_staticWeapon, _turret, _secondaryWeaponMagazine] call FUNC(reload_getVehicleMagazine); + TRACE_3("Re-add previous mag",_secondaryWeaponMagazine,_turret,_vehicleMag); + if (!isClass (configFile >> "CfgMagazines" >> _vehicleMag)) exitWith {}; + _staticWeapon addMagazineTurret [_vehicleMag, _turret, 1]; + _staticWeapon setVariable [QGVAR(secondaryWeaponMagazine), nil]; +}; if (_storeExtraMagazines) then { TRACE_1("saving extra mags to container",_containerMagazineCount);