Skip to content

Commit

Permalink
CSW - Fix missing magazine on assembling (#8880)
Browse files Browse the repository at this point in the history
* Fix missing magazine on assembling

* Fix adding mag when csw is empty

* Fix missing magazine when player has launcher
  • Loading branch information
Dystopian authored May 4, 2022
1 parent e2a822c commit 89badcc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
18 changes: 13 additions & 5 deletions addons/csw/functions/fnc_assemble_deployTripod.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@

// 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");

// Create a tripod
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;
Expand Down Expand Up @@ -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;
21 changes: 18 additions & 3 deletions addons/csw/functions/fnc_assemble_pickupWeapon.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions addons/csw/functions/fnc_reload_getVehicleMagazine.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* Finds the best vehicle magazines to create from a carryable magazine for a given weapon.
*
* Arguments:
* 0: Weapon <STRING>
* 1: Magazine that is carryable <STRING>
* 0: Vehicle <OBJECT>
* 1: Turret <ARRAY>
* 2: Magazine that is carryable <STRING>
*
* Return Value:
* Vehicle Magazine <STRING>
Expand Down
9 changes: 9 additions & 0 deletions addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 89badcc

Please sign in to comment.