From fa8161bc03c939c94f8ccb6ff4e7d557ace780bc Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Tue, 2 Apr 2024 15:21:28 +0200 Subject: [PATCH] Separate assembly mod and ammo handling more They aren't entirely separate. If you enable advanced assembly, you need ammo handling to be enabled. --- addons/csw/XEH_postInit.sqf | 18 +++++++++ .../fnc_aceRearmGetCarryMagazines.sqf | 3 +- .../fnc_assemble_canPickupWeapon.sqf | 4 +- .../functions/fnc_assemble_deployTripod.sqf | 5 +-- .../functions/fnc_assemble_deployWeapon.sqf | 5 +-- addons/csw/functions/fnc_initVehicle.sqf | 40 +++++++++---------- .../fnc_staticWeaponInit_unloadExtraMags.sqf | 7 ++-- 7 files changed, 45 insertions(+), 37 deletions(-) diff --git a/addons/csw/XEH_postInit.sqf b/addons/csw/XEH_postInit.sqf index 87196f3377..69d1b244b3 100644 --- a/addons/csw/XEH_postInit.sqf +++ b/addons/csw/XEH_postInit.sqf @@ -4,6 +4,24 @@ GVAR(vehicleMagCache) = createHashMap; ["CBA_settingsInitialized", { TRACE_3("settingsInit",GVAR(defaultAssemblyMode),GVAR(handleExtraMagazines),GVAR(ammoHandling)); + + // Do not allow no ammo handling when advanced assembly is enabled + if (GVAR(defaultAssemblyMode) && GVAR(ammoHandling) == 0) then { + if (isServer) then { + [QGVAR(ammoHandling), 2, 2, "server"] call CBA_settings_fnc_set; + }; + + // Notify everyone about change + [QEGVAR(common,displayTextStructured), [composeText [ + lineBreak, + parseText format [ + "%1", format ["%1 requires %2 to be set higher than 0.", QGVAR(defaultAssemblyMode), QGVAR(ammoHandling)] + ], + lineBreak, + parseText format ["%1", "No mission restart is required."] + ], 4]] call CBA_fnc_localEvent; + }; + ["StaticWeapon", "Init", { // needs a small delay for network syncing, or we end up with duplicate mags with ammo handling [LINKFUNC(initVehicle), _this, 1] call CBA_fnc_waitAndExecute; diff --git a/addons/csw/functions/fnc_aceRearmGetCarryMagazines.sqf b/addons/csw/functions/fnc_aceRearmGetCarryMagazines.sqf index 5230fccf52..e08e96ab27 100644 --- a/addons/csw/functions/fnc_aceRearmGetCarryMagazines.sqf +++ b/addons/csw/functions/fnc_aceRearmGetCarryMagazines.sqf @@ -21,8 +21,7 @@ params ["_vehicle", ["_targetTurret", true, [[], true]]]; private _return = [[], []]; if !(_vehicle isKindOf "StaticWeapon") exitWith {_return}; // limit to statics for now -// Assembly mode: [0=disabled, 1=enabled, 2=enabled&unload, 3=default] -if ((GVAR(ammoHandling) == 0) && {!([false, true, true, GVAR(defaultAssemblyMode)] select (_vehicle getVariable [QGVAR(assemblyMode), 3]))}) exitWith {_return}; +if (GVAR(ammoHandling) == 0) exitWith {_return}; private _turretMagsCSW = _return select 0; private _allCarryMags = _return select 1; diff --git a/addons/csw/functions/fnc_assemble_canPickupWeapon.sqf b/addons/csw/functions/fnc_assemble_canPickupWeapon.sqf index 40c6b527d3..21e4089137 100644 --- a/addons/csw/functions/fnc_assemble_canPickupWeapon.sqf +++ b/addons/csw/functions/fnc_assemble_canPickupWeapon.sqf @@ -17,9 +17,7 @@ params ["_staticWeapon"]; -// Assembly mode: [0=disabled, 1=enabled, 2=enabled&unload, 3=default] -private _assemblyMode = [false, true, true, GVAR(defaultAssemblyMode)] select (_staticWeapon getVariable [QGVAR(assemblyMode), 3]); private _notCrewed = (crew _staticWeapon) isEqualTo []; private _deadCrew = !(alive (gunner _staticWeapon)); // need to eject body??? -_assemblyMode && {_notCrewed || _deadCrew} +GVAR(defaultAssemblyMode) && {_notCrewed || _deadCrew} diff --git a/addons/csw/functions/fnc_assemble_deployTripod.sqf b/addons/csw/functions/fnc_assemble_deployTripod.sqf index 9c2f3ef725..801072c148 100644 --- a/addons/csw/functions/fnc_assemble_deployTripod.sqf +++ b/addons/csw/functions/fnc_assemble_deployTripod.sqf @@ -34,12 +34,11 @@ // 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 + _cswTripod setVariable [QGVAR(assembled), true, true]; if (_secondaryWeaponMagazine isNotEqualTo "") then { _cswTripod setVariable [QGVAR(secondaryWeaponMagazine), _secondaryWeaponMagazine]; }; - if (!GVAR(defaultAssemblyMode)) then { + if (GVAR(defaultAssemblyMode)) then { [_cswTripod, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); }; diff --git a/addons/csw/functions/fnc_assemble_deployWeapon.sqf b/addons/csw/functions/fnc_assemble_deployWeapon.sqf index 772cad65d4..09d6df935d 100644 --- a/addons/csw/functions/fnc_assemble_deployWeapon.sqf +++ b/addons/csw/functions/fnc_assemble_deployWeapon.sqf @@ -43,9 +43,8 @@ [{ params ["_assembledClassname", "_tripodDir", "_tripodPos"]; private _csw = createVehicle [_assembledClassname, [0, 0, 0], [], 0, "NONE"]; - // Assembly mode: [0=disabled, 1=enabled, 2=enabled&unload, 3=default] - _csw setVariable [QGVAR(assemblyMode), 2, true]; // Explicitly set advanced assembly mode + unload, and broadcast - if (!GVAR(defaultAssemblyMode)) then { + _csw setVariable [QGVAR(assembled), true, true]; + if (GVAR(defaultAssemblyMode)) then { [_csw, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); }; _csw setDir _tripodDir; diff --git a/addons/csw/functions/fnc_initVehicle.sqf b/addons/csw/functions/fnc_initVehicle.sqf index ed882e435c..60f3aa4ffc 100644 --- a/addons/csw/functions/fnc_initVehicle.sqf +++ b/addons/csw/functions/fnc_initVehicle.sqf @@ -35,31 +35,29 @@ 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]; - 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 + TRACE_2("turretLocal",_vehicle,GVAR(defaultAssemblyMode)); + + // If the weapon was assembled by players, remove all magazines that spawn with the weapon + private _emptyWeapon = _csw getVariable [QGVAR(assembled), false]; + + [_vehicle, [0], GVAR(defaultAssemblyMode), _emptyWeapon] call FUNC(proxyWeapon); + + // If magazine handling is disabled, do not unload magazines + if (GVAR(ammoHandling) == 0) exitWith {}; + + [_vehicle, _emptyWeapon] call FUNC(staticWeaponInit_unloadExtraMags); }; 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]); - 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 + TRACE_2("assemblyConfig present",_vehicle,GVAR(defaultAssemblyMode)); + if (GVAR(defaultAssemblyMode)) then { // Disable vanilla assembly if assemblyMode enabled + [_vehicle, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); + }; }; +// If magazine handling is disabled, don't enable ammo handling +if (GVAR(ammoHandling) == 0) exitWith {}; + // Add interactions for players if (hasInterface && {!(_typeOf in GVAR(initializedStaticTypes))}) then { GVAR(initializedStaticTypes) pushBack _typeOf; @@ -74,8 +72,6 @@ if (hasInterface && {!(_typeOf in GVAR(initializedStaticTypes))}) then { private _ammoActionPath = []; private _magazineLocation = getText (_configOf >> QUOTE(ADDON) >> "magazineLocation"); private _condition = { //IGNORE_PRIVATE_WARNING ["_target", "_player"]; - // If magazine handling is enabled or weapon assembly/disassembly is enabled we enable ammo handling - if ((GVAR(ammoHandling) == 0) && {!([false, true, true, GVAR(defaultAssemblyMode)] select (_target getVariable [QGVAR(assemblyMode), 3]))}) exitWith { false }; [_player, _target, ["isNotSwimming", "isNotSitting"]] call EFUNC(common,canInteractWith) }; private _childenCode = { diff --git a/addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf b/addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf index 23155ead0b..d4e21b9ad3 100644 --- a/addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf +++ b/addons/csw/functions/fnc_staticWeaponInit_unloadExtraMags.sqf @@ -5,7 +5,7 @@ * * Arguments: * 0: Weapon - * 1: Using advanced assembly + * 1: Empty the weapon? * * Return Value: * None @@ -16,9 +16,8 @@ * Public: No */ -params ["_staticWeapon", "_assemblyMode", "_emptyWeapon"]; -TRACE_3("staticWeaponInit_unloadExtraMags",_staticWeapon,_assemblyMode,_emptyWeapon); -if (!_assemblyMode) exitWith {}; +params ["_staticWeapon", "_emptyWeapon"]; +TRACE_2("staticWeaponInit_unloadExtraMags",_staticWeapon,_emptyWeapon); private _desiredAmmo = getNumber (configOf _staticWeapon >> QUOTE(ADDON) >> "desiredAmmo"); private _storeExtraMagazines = GVAR(handleExtraMagazines);