Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookoff - Delay full vehicle destruction #9061

Merged
merged 10 commits into from
May 24, 2024
36 changes: 30 additions & 6 deletions addons/cookoff/functions/fnc_cookOff.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Public: No
*/

params ["_vehicle", "_intensity", ["_instigator", objNull], ["_smokeDelayEnabled", true], ["_ammoDetonationChance", 0], ["_detonateAfterCookoff", false], ["_fireSource", ""], ["_canRing", true], ["_maxIntensity", MAX_COOKOFF_INTENSITY, [0]], ["_canJet", true, [true]]];
params ["_vehicle", "_intensity", ["_instigator", objNull], ["_smokeDelayEnabled", true], ["_ammoDetonationChance", 0], ["_detonateAfterCookoff", false], ["_fireSource", ""], ["_canRing", true], ["_canJet", true], ["_canFinale", true], ["_maxIntensity", MAX_COOKOFF_INTENSITY, [0]]];

if (GVAR(enable) == 0) exitWith {};
if !(GVAR(enableFire)) exitWith {};
Expand Down Expand Up @@ -59,13 +59,13 @@ if (_smokeDelayEnabled) then {
[QGVAR(smoke), [_vehicle, _positions]] call CBA_fnc_globalEvent;

[{
params ["_vehicle", "_positions", "_intensity", "_ammoDetonationChance", "_detonateAfterCookoff", "_instigator", "_fireSource", "_canRing", "_canJet"];
params ["_vehicle", "_positions", "_intensity", "_ammoDetonationChance", "_detonateAfterCookoff", "_instigator", "_fireSource", "_canRing", "_canJet", "_canFinale"];
_vehicle setVariable [QGVAR(intensity), _intensity];
private _smokeEffects = _vehicle getVariable [QGVAR(effects), []];

[{
params ["_args", "_pfh"];
_args params ["_vehicle", "_positions", "_ammoDetonationChance", "_detonateAfterCookoff", "_instigator", "_fireSource", "_canRing", "_canJet", "_smokeEffects"];
_args params ["_vehicle", "_positions", "_ammoDetonationChance", "_detonateAfterCookoff", "_instigator", "_fireSource", "_canRing", "_canJet", "_canFinale", "_smokeEffects"];
private _intensity = _vehicle getVariable [QGVAR(intensity), 0];
if (isNull _vehicle || {_intensity <= 1}) exitWith {
[QGVAR(cleanupEffects), [_vehicle, _smokeEffects]] call CBA_fnc_globalEvent;
Expand All @@ -77,13 +77,14 @@ if (_smokeDelayEnabled) then {
};
};

private _stage = _vehicle getVariable [QGVAR(stage), 1];
private _lastFlameTime = _vehicle getVariable [QGVAR(lastFlame), 0];
private _nextFlameTime = _vehicle getVariable [QGVAR(nextFlame), 0];

// Wait until we are ready for the next flame
// dt = Tcurrent - Tlast
// dt >= Tnext
if ((CBA_missionTime - _lastFlameTime) >= _nextFlameTime) then {
if (_stage <= COOKOFF_FLAME_STAGE && {(CBA_missionTime - _lastFlameTime) >= _nextFlameTime}) then {
private _ring = (0.2 > random 1);
if (!_ring && _intensity >= 2) then {
_ring = (0.7 > random 1);
Expand All @@ -105,6 +106,7 @@ if (_smokeDelayEnabled) then {
_vehicle setVariable [QGVAR(intensity), _intensity];
_vehicle setVariable [QGVAR(lastFlame), CBA_missionTime];
_vehicle setVariable [QGVAR(nextFlame), _time + (MIN_TIME_BETWEEN_FLAMES max random MAX_TIME_BETWEEN_FLAMES)];
_vehicle setVariable [QGVAR(stage), _stage + 1];

{
[QEGVAR(fire,burn), [_x, _intensity * 1.5, _instigator]] call CBA_fnc_globalEvent;
Expand All @@ -125,5 +127,27 @@ if (_smokeDelayEnabled) then {
_vehicle setVariable [QGVAR(nextExplosiveDetonation), random 60];
};
};
}, 0.25, [_vehicle, _positions, _ammoDetonationChance, _detonateAfterCookoff, _instigator, _fireSource, _canRing, _canJet, _smokeEffects]] call CBA_fnc_addPerFrameHandler
}, [_vehicle, _positions, _intensity, _ammoDetonationChance, _detonateAfterCookoff, _instigator, _fireSource, _canRing, _canJet], _delay] call CBA_fnc_waitAndExecute;

if (_canFinale) then {
// wait until next flame timer
if (_stage == COOKOFF_FINALE_STAGE && {(CBA_missionTime - _lastFlameTime) >= _nextFlameTime}) then {

// Random chance of full destruction
if (GVAR(finaleChance) >= random 1) then {
if (_fireSource isEqualTo "") then {
_fireSource = selectRandom _positions;
};

createVehicle ["ACE_ammoExplosionLarge", (_vehicle modelToWorld (_vehicle selectionPosition _fireSource)), [], 0 , "CAN_COLLIDE"];

_vehicle setDamage [1, true];

_intensity = _intensity - (0.5 max random 1);
_vehicle setVariable [QGVAR(intensity), _intensity];
};

_vehicle setVariable [QGVAR(stage), _stage + 1];
};
};
}, 0.25, [_vehicle, _positions, _ammoDetonationChance, _detonateAfterCookoff, _instigator, _fireSource, _canRing, _canJet, _canFinale, _smokeEffects]] call CBA_fnc_addPerFrameHandler
}, [_vehicle, _positions, _intensity, _ammoDetonationChance, _detonateAfterCookoff, _instigator, _fireSource, _canRing, _canJet, _canFinale], _delay] call CBA_fnc_waitAndExecute;
10 changes: 10 additions & 0 deletions addons/cookoff/initSettings.inc.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,13 @@
{[QGVAR(probabilityCoef), _this] call EFUNC(common,cbaSettings_settingChanged)},
true // Needs mission restart
] call CBA_fnc_addSetting;

[
QGVAR(finaleChance), "SLIDER",
[LSTRING(finaleChance_name), LSTRING(finaleChance_tooltip)],
LSTRING(category_displayName),
[0,1,0.5,2,true], // [min, max, default value, trailing decimals (-1 for whole numbers only)]
Mike-MF marked this conversation as resolved.
Show resolved Hide resolved
true, // isGlobal
{[QGVAR(finaleChance), _this] call EFUNC(common,cbaSettings_settingChanged)},
false // Needs mission restart
] call CBA_fnc_addSetting;
3 changes: 3 additions & 0 deletions addons/cookoff/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#define MAX_TIME_BETWEEN_AMMO_DET 25
#define MAX_COOKOFF_INTENSITY 10

#define COOKOFF_FLAME_STAGE 1 // How many flame executions to allow
#define COOKOFF_FINALE_STAGE 2 // When to trigger finale stage

johnb432 marked this conversation as resolved.
Show resolved Hide resolved
#define MIN_AMMO_DETONATION_START_DELAY 1 // Min time to wait before a vehicle's ammo starts to cookoff
#define MAX_AMMO_DETONATION_START_DELAY 6 // Max time to wait before a vehicle's ammo starts to cookoff

Expand Down
6 changes: 6 additions & 0 deletions addons/cookoff/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@
<Czech>Multiplikátor pro pravděpodobnost vznícení munice. Vyšší hodnota znamená vyšší šanci vznícení munice.</Czech>
<Korean>쿡오프가 일어날 확률에 계수를 곱합니다. 더 큰 숫자는 더 높은 확률의 쿡오프를 일으킵니다.</Korean>
</Key>
<Key ID="STR_ACE_CookOff_finaleChance_name">
<English>Destruction Finale Chance</English>
</Key>
<Key ID="STR_ACE_CookOff_finaleChance_tooltip">
<English>Probability of full vehicle destruction during cookoff. Higher value results in higher probability</English>
</Key>
<Key ID="STR_ACE_CookOff_destroyVehicleAfterCookoff_name">
<English>Destroy Vehicles After Cook-off</English>
<Korean>쿡오프 후 차량 파괴</Korean>
Expand Down
9 changes: 6 additions & 3 deletions addons/vehicle_damage/functions/fnc_handleCookoff.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Public: No
*/

params ["_vehicle", "_chanceOfFire", "_intensity", ["_injurer", objNull], ["_hitPart", ""], ["_canRing", false], ["_canJet", true]];
params ["_vehicle", "_chanceOfFire", "_intensity", ["_injurer", objNull], ["_hitPart", ""], ["_canRing", false], ["_canJet", true], ["_canFinale", true]];

private _alreadyCookingOff = _vehicle getVariable [QGVAR(cookingOff), false];

Expand All @@ -36,6 +36,10 @@ if (!_alreadyCookingOff && { _chanceOfFire >= random 1 }) exitWith {
_canJet = ([_configOf >> QEGVAR(cookoff,canHaveFireJet), "number", 1] call CBA_fnc_getConfigEntry) == 1;
};

if (_canFinale) then {
_canFinale = ([_configOf >> QGVAR(canHaveFinale), "number", 1] call CBA_fnc_getConfigEntry) == 1;
};

private _delayWithSmoke = _chanceOfFire < random 1;
private _detonateAfterCookoff = (_fireDetonateChance / 4) > random 1;

Expand All @@ -44,8 +48,7 @@ if (!_alreadyCookingOff && { _chanceOfFire >= random 1 }) exitWith {
_source = ["hit_engine_point", "HitPoints"];
};

// sending nil for _maxIntensity (9th param) to use default value in ace_cookoff_fnc_cookOff
[QEGVAR(cookOff,cookOff), [_vehicle, _intensity, _injurer, _delayWithSmoke, _fireDetonateChance, _detonateAfterCookoff, _source, _canRing, nil, _canJet]] call CBA_fnc_localEvent;
[QEGVAR(cookOff,cookOff), [_vehicle, _intensity, _injurer, _delayWithSmoke, _fireDetonateChance, _detonateAfterCookoff, _source, _canRing, _canJet, _canFinale]] call CBA_fnc_localEvent;
_vehicle setVariable [QGVAR(cookingOff), true];
LOG_4("Cooking-off [%1] with a chance-of-fire [%2] - Delayed Smoke | Detonate after cookoff [%3 | %4]",_vehicle,_chanceOfFire,_delayWithSmoke,_detonateAfterCookoff);
[_vehicle] spawn FUNC(abandon);
Expand Down