-
Notifications
You must be signed in to change notification settings - Fork 739
/
fnc_cookOff.sqf
129 lines (104 loc) · 5.6 KB
/
fnc_cookOff.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "..\script_component.hpp"
/*
* Author: tcvm
* Start a cook-off in the given vehicle.
*
* Arguments:
* 0: Vehicle <Object>
* 1: Intensity of fire <Number>
*
* Return Value:
* None
*
* Example:
* [(vehicle player), 3] call ace_cookoff_fnc_cookOff
*
* Public: No
*/
params ["_vehicle", "_intensity", ["_instigator", objNull], ["_smokeDelayEnabled", true], ["_ammoDetonationChance", 0], ["_detonateAfterCookoff", false], ["_fireSource", ""], ["_canRing", true], ["_maxIntensity", MAX_COOKOFF_INTENSITY, [0]], ["_canJet", true, [true]]];
if (GVAR(enable) == 0) exitWith {};
if !(GVAR(enableFire)) exitWith {};
if (_vehicle getVariable [QGVAR(enable), GVAR(enable)] in [0, false]) exitWith {};
// 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 {};
TRACE_2("cooking off",_vehicle,_intensity);
TRACE_8("",_instigator,_smokeDelayEnabled,_ammoDetonationChance,_detonateAfterCookoff,_fireSource,_canRing,_maxIntensity,_canJet);
if (_vehicle getVariable [QGVAR(isCookingOff), false]) exitWith {};
_vehicle setVariable [QGVAR(isCookingOff), true, true];
[QGVAR(addCleanupHandlers), [_vehicle]] call CBA_fnc_globalEvent;
// limit maximum value of intensity to prevent very long cook-off times
_intensity = _intensity min _maxIntensity;
private _config = configOf _vehicle;
private _positions = getArray (_config >> QGVAR(cookoffSelections)) select {(_vehicle selectionPosition _x) isNotEqualTo [0,0,0]};
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;
if (_positions isEqualTo []) then {
_positions pushBack "#noselection";
};
};
private _delay = 0;
if (_smokeDelayEnabled) then {
_delay = SMOKE_TIME + random SMOKE_TIME;
};
[QGVAR(smoke), [_vehicle, _positions]] call CBA_fnc_globalEvent;
[{
params ["_vehicle", "_positions", "_intensity", "_ammoDetonationChance", "_detonateAfterCookoff", "_instigator", "_fireSource", "_canRing", "_canJet"];
_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"];
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;
if (GVAR(destroyVehicleAfterCookoff) || _detonateAfterCookoff) then {
_vehicle setDamage [1, true];
};
};
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 {
private _ring = (0.2 > random 1);
if (!_ring && _intensity >= 2) then {
_ring = (0.7 > random 1);
};
if !(_canRing) then {
_ring = false;
};
private _time = linearConversion [0, 10, _intensity, 3, 20] + random COOKOFF_TIME;
if (_fireSource isEqualTo "") then {
_fireSource = selectRandom _positions;
};
[QGVAR(cookOffEffect), [_vehicle, _canJet, _ring, _time, _fireSource, _intensity]] call CBA_fnc_globalEvent;
_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)];
{
[QEGVAR(fire,burn), [_x, _intensity * 1.5, _instigator]] call CBA_fnc_globalEvent;
} forEach crew _vehicle
};
if (_ammoDetonationChance > random 1) then {
private _lastExplosiveDetonationTime = _vehicle getVariable [QGVAR(lastExplosiveDetonation), 0];
private _nextExplosiveDetonation = _vehicle getVariable [QGVAR(nextExplosiveDetonation), 0];
if ((CBA_missionTime - _lastExplosiveDetonationTime) > _nextExplosiveDetonation) then {
if (_fireSource isEqualTo "") then {
_fireSource = selectRandom _positions;
};
createVehicle ["ACE_ammoExplosionLarge", (_vehicle modelToWorld (_vehicle selectionPosition _fireSource)), [], 0 , "CAN_COLLIDE"];
_vehicle setVariable [QGVAR(lastExplosiveDetonation), CBA_missionTime];
_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;