2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2016-07-14 14:16:53 +00:00
|
|
|
/*
|
2022-01-30 17:54:30 +00:00
|
|
|
* Author: Dani (TCVM)
|
2016-07-14 14:16:53 +00:00
|
|
|
* Start a cook-off in the given vehicle.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Vehicle <Object>
|
2021-10-14 15:49:27 +00:00
|
|
|
* 1: Intensity of fire <Number>
|
2016-07-14 14:16:53 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2021-10-14 15:49:27 +00:00
|
|
|
* [(vehicle player), 3] call ace_cookoff_fnc_cookOff
|
2016-07-14 14:16:53 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2021-11-11 11:43:41 +00:00
|
|
|
params ["_vehicle", "_intensity", ["_instigator", objNull], ["_smokeDelayEnabled", true], ["_ammoDetonationChance", 0], ["_detonateAfterCookoff", false], ["_fireSource", ""], ["_canRing", true], ["_maxIntensity", MAX_COOKOFF_INTENSITY, [0]]];
|
2016-07-14 14:16:53 +00:00
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
if (GVAR(enable) == 0) exitWith {};
|
|
|
|
if !(GVAR(enableFire)) exitWith {};
|
2021-10-27 18:05:55 +00:00
|
|
|
if (_vehicle getVariable [QGVAR(enable), GVAR(enable)] in [0, false]) exitWith {};
|
2021-10-29 22:20:02 +00:00
|
|
|
// exit if cook-off enabled only for players and no players in vehicle crew found
|
|
|
|
if (_vehicle getVariable [QGVAR(enable), GVAR(enable)] isEqualTo 1 && {fullCrew [_vehicle, "", false] findIf {isPlayer (_x select 0)} == -1}) exitWith {};
|
2021-10-27 18:05:55 +00:00
|
|
|
|
2016-07-14 14:16:53 +00:00
|
|
|
|
2021-11-11 11:43:41 +00:00
|
|
|
TRACE_9("cooking off",_vehicle,_intensity,_instigator,_smokeDelayEnabled,_ammoDetonationChance,_detonateAfterCookoff,_fireSource,_canRing,_maxIntensity);
|
2016-07-14 14:16:53 +00:00
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
if (_vehicle getVariable [QGVAR(isCookingOff), false]) exitWith {};
|
|
|
|
_vehicle setVariable [QGVAR(isCookingOff), true, true];
|
2016-07-14 14:16:53 +00:00
|
|
|
|
2022-08-20 21:38:06 +00:00
|
|
|
[QGVAR(addCleanupHandlers), [_vehicle]] call CBA_fnc_globalEvent;
|
2022-07-15 14:59:49 +00:00
|
|
|
|
2021-11-11 11:43:41 +00:00
|
|
|
// limit maximum value of intensity to prevent very long cook-off times
|
|
|
|
_intensity = _intensity min _maxIntensity;
|
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
private _config = _vehicle call CBA_fnc_getObjectConfig;
|
2021-12-18 23:15:32 +00:00
|
|
|
private _positions = getArray (_config >> QGVAR(cookoffSelections)) select {(_vehicle selectionPosition _x) isNotEqualTo [0,0,0]};
|
2016-07-14 14:16:53 +00:00
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
if (_positions isEqualTo []) then {
|
|
|
|
WARNING_1("no valid selection for cookoff found. %1",typeOf _vehicle);
|
|
|
|
{
|
|
|
|
private _pos = _vehicle selectionPosition _x;
|
|
|
|
if (_pos isEqualTo [0, 0, 0]) exitWith {};
|
|
|
|
_positions pushBack _x;
|
|
|
|
} forEach DEFAULT_COMMANDER_HATCHES;
|
2021-10-29 22:20:02 +00:00
|
|
|
|
2016-07-14 14:16:53 +00:00
|
|
|
if (_positions isEqualTo []) then {
|
|
|
|
_positions pushBack "#noselection";
|
|
|
|
};
|
2021-10-14 15:49:27 +00:00
|
|
|
};
|
2016-07-14 14:16:53 +00:00
|
|
|
|
2022-07-01 16:20:31 +00:00
|
|
|
// default fire jet to enabled when not set in configs
|
|
|
|
private _canJet = ([_config >> QGVAR(canHaveFireJet), "number", 1] call CBA_fnc_getConfigEntry) == 1;
|
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
private _delay = 0;
|
|
|
|
if (_smokeDelayEnabled) then {
|
|
|
|
_delay = SMOKE_TIME + random SMOKE_TIME;
|
|
|
|
};
|
|
|
|
[QGVAR(smoke), [_vehicle, _positions]] call CBA_fnc_globalEvent;
|
2016-07-14 14:16:53 +00:00
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
[{
|
2022-07-01 16:20:31 +00:00
|
|
|
params ["_vehicle", "_positions", "_intensity", "_ammoDetonationChance", "_detonateAfterCookoff", "_instigator", "_fireSource", "_canRing", "_canJet"];
|
2021-10-14 15:49:27 +00:00
|
|
|
_vehicle setVariable [QGVAR(intensity), _intensity];
|
|
|
|
private _smokeEffects = _vehicle getVariable [QGVAR(effects), []];
|
2016-07-14 14:16:53 +00:00
|
|
|
|
|
|
|
[{
|
2021-10-14 15:49:27 +00:00
|
|
|
params ["_args", "_pfh"];
|
2022-07-01 16:20:31 +00:00
|
|
|
_args params ["_vehicle", "_positions", "_ammoDetonationChance", "_detonateAfterCookoff", "_instigator", "_fireSource", "_canRing", "_canJet", "_smokeEffects"];
|
2021-10-14 15:49:27 +00:00
|
|
|
private _intensity = _vehicle getVariable [QGVAR(intensity), 0];
|
|
|
|
if (isNull _vehicle || {_intensity <= 1}) exitWith {
|
|
|
|
[QGVAR(cleanupEffects), [_vehicle, _smokeEffects]] call CBA_fnc_globalEvent;
|
|
|
|
_vehicle setVariable [QGVAR(isCookingOff), false, true];
|
|
|
|
[_pfh] call CBA_fnc_removePerFrameHandler;
|
2021-10-29 22:20:02 +00:00
|
|
|
|
2022-05-31 13:50:55 +00:00
|
|
|
if (GVAR(destroyVehicleAfterCookoff) || _detonateAfterCookoff) then {
|
2023-06-25 04:06:26 +00:00
|
|
|
_vehicle setDamage [1, true];
|
2016-07-14 14:16:53 +00:00
|
|
|
};
|
|
|
|
};
|
2021-10-29 22:20:02 +00:00
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
private _lastFlameTime = _vehicle getVariable [QGVAR(lastFlame), 0];
|
|
|
|
private _nextFlameTime = _vehicle getVariable [QGVAR(nextFlame), 0];
|
2021-10-29 22:20:02 +00:00
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
// Wait until we are ready for the next flame
|
|
|
|
// dt = Tcurrent - Tlast
|
|
|
|
// dt >= Tnext
|
|
|
|
if ((CBA_missionTime - _lastFlameTime) >= _nextFlameTime) then {
|
|
|
|
private _ring = (0.2 > random 1);
|
|
|
|
if (!_ring && _intensity >= 2) then {
|
|
|
|
_ring = (0.7 > random 1);
|
2016-07-14 14:16:53 +00:00
|
|
|
};
|
2021-10-29 22:20:02 +00:00
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
if !(_canRing) then {
|
|
|
|
_ring = false;
|
2016-07-14 14:16:53 +00:00
|
|
|
};
|
2021-10-29 22:20:02 +00:00
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
private _time = linearConversion [0, 10, _intensity, 3, 20] + random COOKOFF_TIME;
|
2021-10-29 22:20:02 +00:00
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
if (_fireSource isEqualTo "") then {
|
|
|
|
_fireSource = selectRandom _positions;
|
2016-08-14 11:51:33 +00:00
|
|
|
};
|
2021-10-29 22:20:02 +00:00
|
|
|
|
2022-07-01 16:20:31 +00:00
|
|
|
[QGVAR(cookOffEffect), [_vehicle, _canJet, _ring, _time, _fireSource, _intensity]] call CBA_fnc_globalEvent;
|
2021-10-29 22:20:02 +00:00
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
_intensity = _intensity - (0.5 max random 1);
|
|
|
|
_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)];
|
2021-10-29 22:20:02 +00:00
|
|
|
|
2016-07-14 14:16:53 +00:00
|
|
|
{
|
2021-10-14 15:49:27 +00:00
|
|
|
[QEGVAR(fire,burn), [_x, _intensity * 1.5, _instigator]] call CBA_fnc_globalEvent;
|
|
|
|
} forEach crew _vehicle
|
|
|
|
};
|
2021-10-29 22:20:02 +00:00
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
if (_ammoDetonationChance > random 1) then {
|
|
|
|
private _lastExplosiveDetonationTime = _vehicle getVariable [QGVAR(lastExplosiveDetonation), 0];
|
|
|
|
private _nextExplosiveDetonation = _vehicle getVariable [QGVAR(nextExplosiveDetonation), 0];
|
2021-10-29 22:20:02 +00:00
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
if ((CBA_missionTime - _lastExplosiveDetonationTime) > _nextExplosiveDetonation) then {
|
|
|
|
if (_fireSource isEqualTo "") then {
|
|
|
|
_fireSource = selectRandom _positions;
|
|
|
|
};
|
|
|
|
createVehicle ["ACE_ammoExplosionLarge", (_vehicle modelToWorld (_vehicle selectionPosition _fireSource)), [], 0 , "CAN_COLLIDE"];
|
2021-10-29 22:20:02 +00:00
|
|
|
|
2021-10-14 15:49:27 +00:00
|
|
|
_vehicle setVariable [QGVAR(lastExplosiveDetonation), CBA_missionTime];
|
|
|
|
_vehicle setVariable [QGVAR(nextExplosiveDetonation), random 60];
|
2016-07-14 14:16:53 +00:00
|
|
|
};
|
2021-10-14 15:49:27 +00:00
|
|
|
};
|
2022-07-01 16:20:31 +00:00
|
|
|
}, 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;
|