From d7dafa4d402c7c1d2b4c9e5435122c3f379115b3 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sat, 3 Feb 2024 17:48:54 +0100 Subject: [PATCH] More changes --- addons/cookoff/XEH_postInit.sqf | 5 +- addons/cookoff/functions/fnc_cookOff.sqf | 2 +- .../cookoff/functions/fnc_cookOffBoxLocal.sqf | 9 +--- .../cookoff/functions/fnc_cookOffEffect.sqf | 3 +- .../functions/fnc_detonateAmmunition.sqf | 52 +++++++++++++------ .../cookoff/functions/fnc_getVehicleAmmo.sqf | 10 ++-- addons/cookoff/initSettings.inc.sqf | 10 ++++ addons/cookoff/stringtable.xml | 17 ++++++ .../vehicle_damage/functions/fnc_detonate.sqf | 13 ++--- .../functions/fnc_handleCookoff.sqf | 18 ++----- .../functions/fnc_processHit.sqf | 10 ++-- addons/vehicle_damage/initSettings.inc.sqf | 10 ---- addons/vehicle_damage/stringtable.xml | 24 --------- 13 files changed, 86 insertions(+), 97 deletions(-) diff --git a/addons/cookoff/XEH_postInit.sqf b/addons/cookoff/XEH_postInit.sqf index 400569afd6..1546cb49f9 100644 --- a/addons/cookoff/XEH_postInit.sqf +++ b/addons/cookoff/XEH_postInit.sqf @@ -73,9 +73,6 @@ if (isServer) then { params ["_vehicle", "", "", "_useEffects"]; if (_useEffects && {_vehicle getVariable [QGVAR(enableAmmoCookoff), true]}) then { - (_vehicle call FUNC(getVehicleAmmo)) params ["_magazines", "_total"]; - - private _delay = (random MAX_AMMO_DETONATION_START_DELAY) max MIN_AMMO_DETONATION_START_DELAY; - [QGVAR(detonateAmmunition), [_vehicle, _magazines, _total, false, objNull, objNull, _delay]] call CBA_fnc_serverEvent; + [QGVAR(detonateAmmunition), [_vehicle, false, objNull, objNull, (random MAX_AMMO_DETONATION_START_DELAY) max MIN_AMMO_DETONATION_START_DELAY]] call CBA_fnc_serverEvent; }; }, nil, ["CAManBase", "StaticWeapon"]] call CBA_fnc_addClassEventHandler; diff --git a/addons/cookoff/functions/fnc_cookOff.sqf b/addons/cookoff/functions/fnc_cookOff.sqf index 048b82beb2..46fe4f9a3d 100644 --- a/addons/cookoff/functions/fnc_cookOff.sqf +++ b/addons/cookoff/functions/fnc_cookOff.sqf @@ -107,7 +107,7 @@ if (_delayBetweenSmokeAndFire) then { }; // Wait until we are ready for the next flame - if (CBA_missionTime >= _vehicle getVariable [QGVAR(nextFlame), 0]) then { + if (_vehicle getVariable [QGVAR(nextFlame), 0] <= CBA_missionTime) then { private _ring = false; if (_canRing) then { diff --git a/addons/cookoff/functions/fnc_cookOffBoxLocal.sqf b/addons/cookoff/functions/fnc_cookOffBoxLocal.sqf index 2e0dd031a1..499e5f2a70 100644 --- a/addons/cookoff/functions/fnc_cookOffBoxLocal.sqf +++ b/addons/cookoff/functions/fnc_cookOffBoxLocal.sqf @@ -70,14 +70,9 @@ if (_delay >= 0) then { _box setVariable [QGVAR(effects), _effects]; }; - // These functions are smart and do all the cooking off work + // Detonate the ammunition if (isServer) then { - (_box call FUNC(getVehicleAmmo)) params ["_magazines", "_total"]; - - [QGVAR(detonateAmmunition), [_box, _magazines, _total, true, _killer, _instigator]] call CBA_fnc_localEvent; - - // This shit is busy being on fire, magazines aren't accessible/usable - clearMagazineCargoGlobal _box; + [QGVAR(detonateAmmunition), [_box, true, _killer, _instigator]] call CBA_fnc_localEvent; }; }, _this, _delay] call CBA_fnc_waitAndExecute; }; diff --git a/addons/cookoff/functions/fnc_cookOffEffect.sqf b/addons/cookoff/functions/fnc_cookOffEffect.sqf index 1cf1e3f853..0447959a59 100644 --- a/addons/cookoff/functions/fnc_cookOffEffect.sqf +++ b/addons/cookoff/functions/fnc_cookOffEffect.sqf @@ -84,9 +84,10 @@ if (isServer) then { }; // Make flame push object into ground to make effect seem more "alive" - if (_jet && !isGamePaused && {local _vehicle}) then { + if (_jet && !isGamePaused && {local _vehicle} && {_vehicle getVariable [QGVAR(nextForceTime), 0] <= CBA_missionTime}) then { private _force = [0, 0, _factor * -(0.5 min random 1.5) * (0.3 min random 1)] vectorMultiply getMass _vehicle; _vehicle addForce [_force, vectorUpVisual _vehicle]; + _vehicle setVariable [QGVAR(nextForceTime), CBA_missionTime + 0.01]; // this prevents bad behaviour when setAccTime is small }; // Don't spawn visual effects on machines without interfaces diff --git a/addons/cookoff/functions/fnc_detonateAmmunition.sqf b/addons/cookoff/functions/fnc_detonateAmmunition.sqf index 145bb99987..3a66befa5c 100644 --- a/addons/cookoff/functions/fnc_detonateAmmunition.sqf +++ b/addons/cookoff/functions/fnc_detonateAmmunition.sqf @@ -1,34 +1,50 @@ #include "..\script_component.hpp" /* - * Author: Glowbal + * Author: Glowbal, johnb43 * Detonates ammunition from an object (e.g. vehicle or crate) until no ammo is left. * * Arguments: * 0: Object - * 1: Magazine array - * - 0: Magazine classname - * - 1: Ammo count - * 2: Total ammo count - * 3: Destroy when finished (default: false) - * 4: Killer (default: objNull) - * 5: Instigator (default: objNull) - * 6: Initial delay (default: 0) + * 1: Destroy when finished (default: false) + * 2: Killer (default: objNull) + * 3: Instigator (default: objNull) + * 4: Initial delay (default: 0) * * Return Value: * Nothing Useful * * Example: - * [cursorObject, magazinesAmmo vehicle player, 1000] call ace_cookoff_fnc_detonateAmmunition + * [cursorObject] call ace_cookoff_fnc_detonateAmmunition * * Public: No */ if (!isServer) exitWith {}; -params ["_object", "_magazines", "_totalAmmo", ["_destroyWhenFinished", false], ["_killer", objNull], ["_instigator", objNull], ["_initialDelay", 0]]; +params ["_object", ["_destroyWhenFinished", false], ["_killer", objNull], ["_instigator", objNull], ["_initialDelay", 0]]; if (isNull _object) exitWith {}; +private _vehicleAmmo = _object getVariable QGVAR(cookoffMagazines); + +if (isNil "_vehicleAmmo") then { + _vehicleAmmo = _object call FUNC(getVehicleAmmo); + + _object setVariable [QGVAR(cookoffMagazines), _vehicleAmmo]; + + // TODO: When setMagazineTurretAmmo and magazineTurretAmmo are fixed (https://feedback.bistudio.com/T79689), + // we can add gradual ammo removal during cook-off + if (GVAR(removeAmmoDuringCookoff)) then { + clearMagazineCargoGlobal _object; + + { + _object removeMagazinesTurret [_x select 0, _x select 1]; + } forEach (magazinesAllTurrets _object); + }; +}; + +_vehicleAmmo params ["_magazines", "_totalAmmo"]; + // If the cook-off has finished, clean up the effects and destroy the object if (_magazines isEqualTo [] || {_totalAmmo <= 0}) exitWith { [QGVAR(cleanupEffects), _object] call CBA_fnc_globalEvent; @@ -53,12 +69,12 @@ if (underwater _object || { // Initial delay allows for a delay for the first time this function runs in its cycle if (_initialDelay > 0) exitWith { - [FUNC(detonateAmmunition), [_object, _magazines, _totalAmmo, _destroyWhenFinished, _killer, _instigator], _initialDelay] call CBA_fnc_waitAndExecute; + [FUNC(detonateAmmunition), [_object, _destroyWhenFinished, _killer, _instigator], _initialDelay] call CBA_fnc_waitAndExecute; }; private _magazineIndex = floor random (count _magazines); private _magazine = _magazines select _magazineIndex; -_magazine params ["_magazineClassname", "_ammoCount"]; +_magazine params ["_magazineClassname", "_ammoCount", "_spawnProjectile"]; // Make sure ammo is at least 0 _ammoCount = _ammoCount max 0; @@ -78,8 +94,10 @@ private _timeBetweenAmmoDetonation = ((random 10 / sqrt _totalAmmo) min MAX_TIME TRACE_2("",_totalAmmo,_timeBetweenAmmoDetonation); _totalAmmo = _totalAmmo - _removed; +_object setVariable [QGVAR(cookoffMagazines), [_magazines, _totalAmmo]]; + // Detonate the remaining ammo after a delay -[FUNC(detonateAmmunition), [_object, _magazines, _totalAmmo, _destroyWhenFinished, _killer, _instigator], _timeBetweenAmmoDetonation] call CBA_fnc_waitAndExecute; +[FUNC(detonateAmmunition), [_object, _destroyWhenFinished, _killer, _instigator], _timeBetweenAmmoDetonation] call CBA_fnc_waitAndExecute; // Get magazine info, which is used to spawn projectiles private _configMagazine = configFile >> "CfgMagazines" >> _magazineClassname; @@ -87,12 +105,14 @@ private _ammo = getText (_configMagazine >> "ammo"); private _configAmmo = configFile >> "CfgAmmo" >> _ammo; private _simType = toLower getText (_configAmmo >> "simulation"); -private _speed = random (getNumber (_configMagazine >> "initSpeed") / 10) max 1; - +private _speed = linearConversion [0, 1, random 1, 1, 20, true]; private _effect2pos = _object selectionPosition "destructionEffect2"; // Spawns the projectiles, making them either fly in random directions or explode private _fnc_spawnProjectile = { + // If the magazines are inside of the cargo (inventory), don't let their projectiles escape the interior of the vehicle + if (!_spawnProjectile) exitWith {}; + params ["_object", "_ammo", "_speed", "_flyAway"]; private _spawnPos = _object modelToWorld [-0.2 + random 0.4, -0.2 + random 0.4, random 3]; diff --git a/addons/cookoff/functions/fnc_getVehicleAmmo.sqf b/addons/cookoff/functions/fnc_getVehicleAmmo.sqf index 5f6603c453..235e142d27 100644 --- a/addons/cookoff/functions/fnc_getVehicleAmmo.sqf +++ b/addons/cookoff/functions/fnc_getVehicleAmmo.sqf @@ -41,7 +41,7 @@ private _ammo = ""; continue; }; - _ammoToDetonate pushBack [_magazine, _count]; + _ammoToDetonate pushBack [_magazine, _count, true]; _totalAmmo = _totalAmmo + _count; }; } forEach (magazinesAllTurrets [_vehicle, true]); @@ -51,7 +51,7 @@ private _ammo = ""; _x params ["_magazine", "_count"]; if (_count > 0 && {!(_magazine call FUNC(isMagazineFlare))}) then { - _ammoToDetonate pushBack [_magazine, _count]; + _ammoToDetonate pushBack [_magazine, _count, false]; _totalAmmo = _totalAmmo + _count; }; } forEach (magazinesAmmoCargo _vehicle); @@ -63,13 +63,13 @@ private _configSupply = (getNumber (_configVehicle >> "transportAmmo")) max (get if (_vehicle getVariable [QEGVAR(rearm,isSupplyVehicle), _configSupply > 0]) then { TRACE_1("transportAmmo vehicle - adding virtual ammo",typeOf _vehicle); - _ammoToDetonate pushBack ["2000Rnd_65x39_belt", 2000]; + _ammoToDetonate pushBack ["2000Rnd_65x39_belt", 2000, false]; _totalAmmo = _totalAmmo + 2000; - _ammoToDetonate pushBack ["20Rnd_105mm_HEAT_MP", 100]; + _ammoToDetonate pushBack ["20Rnd_105mm_HEAT_MP", 100, true]; _totalAmmo = _totalAmmo + 100; - _ammoToDetonate pushBack ["SatchelCharge_Remote_Mag", 10]; + _ammoToDetonate pushBack ["SatchelCharge_Remote_Mag", 10, true]; _totalAmmo = _totalAmmo + 10; }; diff --git a/addons/cookoff/initSettings.inc.sqf b/addons/cookoff/initSettings.inc.sqf index afaaabc1b0..d06e1bdfab 100644 --- a/addons/cookoff/initSettings.inc.sqf +++ b/addons/cookoff/initSettings.inc.sqf @@ -67,3 +67,13 @@ 1, {[QGVAR(ammoCookoffDuration), _this] call EFUNC(common,cbaSettings_settingChanged)} ] call CBA_fnc_addSetting; + +[ + QGVAR(removeAmmoDuringCookoff), + "CHECKBOX", + [LSTRING(removeAmmoDuringCookoff_name), LSTRING(removeAmmoDuringCookoff_tooltip)], + LSTRING(category_displayName), + true, + 1, + {[QGVAR(removeAmmoDuringCookoff), _this] call EFUNC(common,cbaSettings_settingChanged)} +] call CBA_fnc_addSetting; diff --git a/addons/cookoff/stringtable.xml b/addons/cookoff/stringtable.xml index 5959a23782..51c67564f5 100644 --- a/addons/cookoff/stringtable.xml +++ b/addons/cookoff/stringtable.xml @@ -99,5 +99,22 @@ Contrôle si les véhicules seront toujours détruits après l'auto-inflammation. Define se os veículos serão sempre destruídos após cozinhamento. + + Enable ammo removal during cook-off + 誘爆中の弾薬除去を有効/無効にする + Retirer les munitions durant l'auto-inflammation + Aktiviert/Deaktiviert Entfernung der Munition beim Durchzünden + Abilita rimozione munizioni dopo l'esplosione + Włącz/Wyłącz usuwanie amunicji podczas samozapłonu + 启用/禁用殉爆过程中的弹药移除功能 + 쿡오프시 탄약 제거 활성화/비활성화 + Удалять боеприпасы из-за детонации + Habilita/Deshabilita ka eliminación de munición durante la detonación inducida por calor + + + Removes all ammo during cook-off. + Retire des munitions des véhicules durant une auto-inflammation. + Entfernt Munition während dem Durchzünden der Munition eines Fahrzeuges. + diff --git a/addons/vehicle_damage/functions/fnc_detonate.sqf b/addons/vehicle_damage/functions/fnc_detonate.sqf index 437570292d..dcb8080c6c 100644 --- a/addons/vehicle_damage/functions/fnc_detonate.sqf +++ b/addons/vehicle_damage/functions/fnc_detonate.sqf @@ -6,7 +6,6 @@ * Arguments: * 0: The vehicle * 1: Person who caused detonation (default: objNull) - * 2: An array of vehicle ammo in vehicle (default: []) * * Return Value: * None @@ -17,15 +16,9 @@ * Public: No */ -params ["_vehicle", ["_injurer", objNull], ["_vehicleAmmo", []]]; +params ["_vehicle", ["_injurer", objNull]]; -if (_vehicleAmmo isEqualTo []) then { - _vehicleAmmo = [_vehicle] call EFUNC(cookoff,getVehicleAmmo); -}; - -[QEGVAR(cookoff,detonateAmmunition), [_vehicle] + _vehicleAmmo] call CBA_fnc_serverEvent; - -if ((_vehicleAmmo select 1) > 0) then { +if (((_vehicle call EFUNC(cookoff,getVehicleAmmo)) select 1) > 0) then { { // random amount of injuries for "_i" from 0 to random 5 do { @@ -33,3 +26,5 @@ if ((_vehicleAmmo select 1) > 0) then { }; } forEach crew _vehicle; }; + +[QEGVAR(cookoff,detonateAmmunition), [_vehicle, false, _injurer, _injurer]] call CBA_fnc_serverEvent; diff --git a/addons/vehicle_damage/functions/fnc_handleCookoff.sqf b/addons/vehicle_damage/functions/fnc_handleCookoff.sqf index 453454d08c..26823f2493 100644 --- a/addons/vehicle_damage/functions/fnc_handleCookoff.sqf +++ b/addons/vehicle_damage/functions/fnc_handleCookoff.sqf @@ -23,11 +23,12 @@ params ["_vehicle", "_chanceOfFire", "_intensity", ["_injurer", objNull], ["_hitPart", ""], ["_canRing", false], ["_canJet", true]]; -private _alreadyCookingOff = _vehicle getVariable [QEGVAR(cookoff,isCookingOff), false]; +// Ignore if the vehicle is already cooking off +if (_vehicle getVariable [QEGVAR(cookoff,isCookingOff), false]) exitWith {true}; _chanceOfFire = _chanceOfFire * EGVAR(cookoff,probabilityCoef); -if (!_alreadyCookingOff && { _chanceOfFire >= random 1 }) exitWith { +if (_chanceOfFire >= random 1) exitWith { private _configOf = configOf _vehicle; private _fireDetonateChance = [_configOf >> QGVAR(detonationDuringFireProb), "number", 0] call CBA_fnc_getConfigEntry; if (_canRing) then { @@ -52,21 +53,8 @@ if (!_alreadyCookingOff && { _chanceOfFire >= random 1 }) exitWith { [_vehicle] spawn FUNC(abandon); LOG_1("[%1] is on fire is bailing",_vehicle); - // cant setVehicleAmmo 0 here because it removes FFV unit's ammo - if (GVAR(removeAmmoDuringCookoff)) then { - private _ammo = [_vehicle] call EFUNC(cookoff,getVehicleAmmo); - _ammo params ["_magazines"]; - TRACE_1("removing magazines",_magazines); - { - _x params ["_magazine"]; - _vehicle removeMagazines _magazine; - } forEach _magazines; - }; true }; -// Avoid RPT spam -if (_alreadyCookingOff) exitWith { true }; - LOG_2("[%1] No Cook-off - Chance of fire [%2]",_vehicle,_chanceOfFire); false diff --git a/addons/vehicle_damage/functions/fnc_processHit.sqf b/addons/vehicle_damage/functions/fnc_processHit.sqf index 48d6ec0055..ed05a171d4 100644 --- a/addons/vehicle_damage/functions/fnc_processHit.sqf +++ b/addons/vehicle_damage/functions/fnc_processHit.sqf @@ -119,12 +119,12 @@ if (_isCar) then { _ammoEffectiveness = (_ammoEffectiveness + (_ammoEffectiveness * 0.5)) min 1; }; -private _currentVehicleAmmo = [_vehicle] call EFUNC(cookoff,getVehicleAmmo); +private _currentVehicleAmmo = _vehicle call EFUNC(cookoff,getVehicleAmmo); private _chanceOfDetonation = 0; private _explosiveAmmoCount = 0; private _nonExplosiveAmmoCount = 0; -if (count (_currentVehicleAmmo select 0) isNotEqualTo 0) then { +if ((_currentVehicleAmmo select 1) > 0) then { private _magConfig = configFile >> "CfgMagazines"; private _ammoConfig = configFile >> "CfgAmmo"; private _countOfExplodableAmmo = 0; @@ -163,7 +163,7 @@ switch (_hitArea) do { _chanceOfFire = 0; // no cookoff for cars }; - if ([_vehicle, _chanceToDetonate, _currentVehicleAmmo, _explosiveAmmoCount, _nonExplosiveAmmoCount, _injurer] call FUNC(handleDetonation)) exitWith { + if ([_vehicle, _chanceToDetonate, _explosiveAmmoCount, _nonExplosiveAmmoCount, _injurer] call FUNC(handleDetonation)) exitWith { [_vehicle] call FUNC(knockOut); }; @@ -191,7 +191,7 @@ switch (_hitArea) do { _chanceOfFire = 0; // no cookoff for cars }; - if ([_vehicle, _chanceToDetonate, _currentVehicleAmmo, _explosiveAmmoCount, _nonExplosiveAmmoCount, _injurer] call FUNC(handleDetonation)) exitWith { + if ([_vehicle, _chanceToDetonate, _explosiveAmmoCount, _nonExplosiveAmmoCount, _injurer] call FUNC(handleDetonation)) exitWith { [_vehicle, _hitIndex, _hitpointName, 0.89 * _penChance] call FUNC(addDamage); [_vehicle] call FUNC(knockOut); }; @@ -265,7 +265,7 @@ switch (_hitArea) do { _chanceOfFire = 0; // no cookoff for cars }; - if ([_vehicle, _chanceToDetonate, _currentVehicleAmmo, _explosiveAmmoCount, _nonExplosiveAmmoCount, _injurer] call FUNC(handleDetonation)) exitWith { + if ([_vehicle, _chanceToDetonate, _explosiveAmmoCount, _nonExplosiveAmmoCount, _injurer] call FUNC(handleDetonation)) exitWith { [_vehicle] call FUNC(knockOut); }; diff --git a/addons/vehicle_damage/initSettings.inc.sqf b/addons/vehicle_damage/initSettings.inc.sqf index ae322a6fd8..0d3f324af2 100644 --- a/addons/vehicle_damage/initSettings.inc.sqf +++ b/addons/vehicle_damage/initSettings.inc.sqf @@ -8,16 +8,6 @@ true // Needs mission restart ] call CBA_settings_fnc_init; -[ - QGVAR(removeAmmoDuringCookoff), "CHECKBOX", - [LSTRING(removeAmmoAfterCookoff_setting_enable), LSTRING(removeAmmoAfterCookoff_setting_description)], - LSTRING(category_displayName), - true, // default value - true, // isGlobal - {[QGVAR(removeAmmoDuringCookoff), _this] call EFUNC(common,cbaSettings_settingChanged)}, - false // Needs mission restart -] call CBA_settings_fnc_init; - [ QGVAR(enableCarDamage), "CHECKBOX", [LSTRING(carDamage_setting_enable), LSTRING(carDamage_setting_description)], diff --git a/addons/vehicle_damage/stringtable.xml b/addons/vehicle_damage/stringtable.xml index 5581408f74..4a8fdb4264 100644 --- a/addons/vehicle_damage/stringtable.xml +++ b/addons/vehicle_damage/stringtable.xml @@ -49,30 +49,6 @@ Продвинутое повреждение машин Habilitar/Deshabilitar daño avanzado de coche (Experimental) - - Removes all vehicle ammo after cook-off - 誘爆後に車両から全ての弾薬を削除 - Retire toutes les munitions des véhicules après une auto-inflammation. - Entfernt die gesamte Munition nach dem Durchzünden der Munition eines Fahrzeuges. - Rimuove tutte le munizioni dal veicolo dopo l'esplosione delle stesse - Usuwa całą amunicję z pojazdu po samozapłonie - 殉爆后移除所有车辆弹药 - 쿡오프 현상 후 차량에서 모든 탄약을 제거합니다. - Удалять все боеприпасы из техники после их детонации - Elimina toda la munición del vehículo despues ser inducida a detonar por calor - - - Enable/Disable Ammo Removal During Cook-Off - 誘爆中の弾薬除去を有効/無効にする - Retirer les munitions durant l'auto-inflammation - Aktiviert/Deaktiviert Entfernung der Munition beim Durchzünden - Abilita rimozione munizioni dopo l'esplosione - Włącz/Wyłącz usuwanie amunicji podczas samozapłonu - 启用/禁用殉爆过程中的弹药移除功能 - 쿡오프시 탄약 제거 활성화/비활성화 - Удалять боеприпасы из-за детонации - Habilita/Deshabilita ka eliminación de munición durante la detonación inducida por calor - Wreck (Turret) Épave (tourelle)