Skip to content

Commit

Permalink
CSW - Improve "disableWeaponAssembly" status effect usage (#10273)
Browse files Browse the repository at this point in the history
Improve disableWeaponAssembly status effect usage in CSW
  • Loading branch information
johnb432 authored Aug 30, 2024
1 parent f1b0703 commit c80d623
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
5 changes: 2 additions & 3 deletions addons/csw/functions/fnc_assemble_deployTripod.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@
_cswTripod setVariable [QGVAR(secondaryWeaponMagazines), _secondaryWeaponMagazines, true];
};

if (!GVAR(defaultAssemblyMode)) then {
[_cswTripod, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);
};
// Disable vanilla assembly until FUNC(initVehicle) runs and sets the definite value
[_cswTripod, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);

private _posATL = _player getRelPos [2, 0];
_posATL set [2, ((getPosATL _player) select 2) + 0.5];
Expand Down
6 changes: 3 additions & 3 deletions addons/csw/functions/fnc_assemble_deployWeapon.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
_csw setVariable [QGVAR(secondaryWeaponMagazines), _secondaryWeaponMagazines, true];
};

if (!GVAR(defaultAssemblyMode)) then {
[_csw, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);
};
// Disable vanilla assembly until FUNC(initVehicle) runs and sets the definite value
[_csw, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);

_csw setDir _tripodDir;
_csw setPosATL _tripodPos;
if ((_tripodPos select 2) < 0.5) then {
Expand Down
43 changes: 23 additions & 20 deletions addons/csw/functions/fnc_initVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,33 @@ if (_configEnabled && {GVAR(ammoHandling) == 2}) then {
};

TRACE_2("",local _vehicle,_vehicle turretLocal [0]);
if (_configEnabled && {_vehicle turretLocal [0]}) then { // if turret is local to us, then handle mags/weapon
[{
params ["_vehicle"];
if (!alive _vehicle) exitWith { TRACE_1("dead/deleted",_vehicle); };
// Assembly mode: [0=disabled, 1=enabled, 2=enabled&unload, 3=default]
private _assemblyModeIndex = _vehicle getVariable [QGVAR(assemblyMode), 3];

if (_vehicle turretLocal [0]) then {
// Assembly mode: [0=disabled, 1=enabled, 2=enabled&unload, 3=default]
private _assemblyModeIndex = _vehicle getVariable [QGVAR(assemblyMode), 3];
private _assemblyMode = [false, true, true, GVAR(defaultAssemblyMode)] select _assemblyModeIndex;

TRACE_2("turretLocal",_vehicle,_assemblyMode);

// If turret is local, handle unloading mags and proxy weapons
if (_configEnabled) then {
TRACE_2("config enabled",_vehicle,_assemblyMode);

private _emptyWeapon = _assemblyModeIndex isEqualTo 2;
private _assemblyMode = [false, true, true, GVAR(defaultAssemblyMode)] select _assemblyModeIndex;
TRACE_2("turretLocal",_vehicle,_assemblyMode);

[_vehicle, [0], _assemblyMode, _emptyWeapon] call FUNC(proxyWeapon);
[_vehicle, _assemblyMode, _emptyWeapon] call FUNC(staticWeaponInit_unloadExtraMags);
}, [_vehicle]] call CBA_fnc_execNextFrame; // need to wait a frame to allow setting object vars during assembly
};

if (_assemblyConfig) then {
[{
params ["_vehicle"];
if (!alive _vehicle) exitWith { TRACE_1("dead/deleted",_vehicle); };
private _assemblyMode = [false, true, true, GVAR(defaultAssemblyMode)] select (_vehicle getVariable [QGVAR(assemblyMode), 3]);
if (!_assemblyMode) exitWith {};

[_vehicle, _emptyWeapon] call FUNC(staticWeaponInit_unloadExtraMags);
};

if (_assemblyConfig) then {
TRACE_2("assemblyConfig present",_vehicle,_assemblyMode);
if (_assemblyMode) then { // Disable vanilla assembly if assemblyMode enabled
[_vehicle, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);
};
}, [_vehicle]] call CBA_fnc_execNextFrame; // need to wait a frame to allow setting object vars during assembly
// Disable vanilla assembly if assemblyMode enabled
// Need to wait to allow setting object vars during assembly, but since this function runs 1 second after vehicle init, it can run immediately
[_vehicle, "disableWeaponAssembly", QUOTE(ADDON), _assemblyMode] call EFUNC(common,statusEffect_set);
};
};

// Add interactions for players
Expand Down
8 changes: 3 additions & 5 deletions addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
*
* Arguments:
* 0: CSW <OBJECT>
* 1: Using advanced assembly <BOOL>
* 2: Empty weapon <BOOL>
* 1: Empty weapon <BOOL>
*
* Return Value:
* None
Expand All @@ -17,9 +16,8 @@
* Public: No
*/

params ["_vehicle", "_assemblyMode", "_emptyWeapon"];
TRACE_3("staticWeaponInit_unloadExtraMags",_vehicle,_assemblyMode,_emptyWeapon);
if (!_assemblyMode) exitWith {};
params ["_vehicle", "_emptyWeapon"];
TRACE_2("staticWeaponInit_unloadExtraMags",_vehicle,_emptyWeapon);

private _desiredAmmo = getNumber (configOf _vehicle >> QUOTE(ADDON) >> "desiredAmmo");
private _storeExtraMagazines = GVAR(handleExtraMagazines);
Expand Down

0 comments on commit c80d623

Please sign in to comment.