Skip to content

Commit

Permalink
Cookoff - Mini-Rewrite (acemod#9758)
Browse files Browse the repository at this point in the history
* Cook-off improvements

* More changes

* Update fnc_getVehicleAmmo.sqf

* Better engine fire placement

* Update fnc_detonateAmmunition.sqf

* Update XEH_postInit.sqf

* Update fnc_getVehicleAmmo.sqf

* Update events-framework.md

* Various improvements

* Separate effect handling

* Tweaks

* Update XEH_postInit.sqf

* Prevent double ammo detonation

* Fixed objects not being able to cook-off again

* Added incendiary rounds as source of box cookoff

* Converted enable setting to bool

* Fixed brackets

* Update fnc_cookOff.sqf

* Update CfgEden.hpp

* Removed GVAR(enable), added GVAR(enableFire) back

* Update initSettings.inc.sqf

* Update events-framework.md

* Update addons/cookoff/functions/fnc_cookOffEffect.sqf

* Restructured, redid API events

* Fix effect for JIP, minor optimisations

* Removed `cbaSettings_settingChanged`

* Renamed variables, tweaked string table entries

* Update fire damage acemod#9991

* Capitalize comments again

* Fix cookoff for very short durations and fix effect removal being too quick
  • Loading branch information
johnb432 authored and blake8090 committed Aug 18, 2024
1 parent bb6c12d commit aa48274
Show file tree
Hide file tree
Showing 40 changed files with 1,186 additions and 1,132 deletions.
1 change: 1 addition & 0 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ if (isServer) then {
[QGVAR(switchMove), {(_this select 0) switchMove (_this select 1)}] call CBA_fnc_addEventHandler;
[QGVAR(setVectorDirAndUp), {(_this select 0) setVectorDirAndUp (_this select 1)}] call CBA_fnc_addEventHandler;
[QGVAR(addWeaponItem), {(_this select 0) addWeaponItem [(_this select 1), (_this select 2)]}] call CBA_fnc_addEventHandler;
[QGVAR(removeMagazinesTurret), {(_this select 0) removeMagazinesTurret [_this select 1, _this select 2]}] call CBA_fnc_addEventHandler;

[QGVAR(setVanillaHitPointDamage), {
params ["_object", "_hitPointAnddamage"];
Expand Down
6 changes: 1 addition & 5 deletions addons/cookoff/ACE_Settings.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@

class ACE_Settings {
class GVAR(enable) {
movedToSqf = 1;
};
class GVAR(enableAmmobox) {
movedToSQF = 1;
};
class GVAR(enableAmmoCookoff) { // For CBA Setting Switch: we can eliminate and just use (ammoCookoffDuration == 0)
class GVAR(enableAmmoCookoff) {
movedToSQF = 1;
};
class GVAR(ammoCookoffDuration) {
Expand Down
1 change: 0 additions & 1 deletion addons/cookoff/CfgCloudlets.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class CfgCloudlets {
class GVAR(CookOff) {
interval = 0.004;
Expand Down
17 changes: 8 additions & 9 deletions addons/cookoff/CfgEden.hpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@

class Cfg3DEN {
class Object {
class AttributeCategories {
class ace_attributes {
class Attributes {
class GVAR(enable) {
property = QGVAR(enable);
class GVAR(enable) { // setting was previously GVAR(enable), so maintain for backwards compatiblity with missions
property = QGVAR(enable); // same as above
control = "Checkbox";
displayName = CSTRING(enable_hd_name);
tooltip = CSTRING(enable_hd_tooltip);
expression = QUOTE(if !(_value) then {_this setVariable [ARR_3('%s',_value,true)];};);
displayName = CSTRING(enableFire_name);
tooltip = CSTRING(enableFire_tooltip);
expression = QUOTE(if (!_value) then {_this setVariable [ARR_3('%s',_value,true)]});
typeName = "BOOL";
condition = "objectVehicle";
defaultValue = QUOTE((GETMVAR(QGVAR(enable),0)) in [ARR_2(1,2)]);
defaultValue = QUOTE(GETMVAR(QGVAR(enableFire),true));
};
class GVAR(enableAmmoCookoff) {
property = QGVAR(enableAmmoCookoff);
control = "Checkbox";
displayName = CSTRING(enableAmmoCookoff_name);
tooltip = CSTRING(enableAmmoCookoff_tooltip);
expression = QUOTE(if !(_value) then {_this setVariable [ARR_3('%s',_value,true)];};);
expression = QUOTE(if (!_value) then {_this setVariable [ARR_3('%s',_value,true)]});
typeName = "BOOL";
condition = "objectHasInventoryCargo";
defaultValue = QUOTE(if (_this isKindOf 'ReammoBox_F') then { GETMVAR(QGVAR(enableAmmobox),true) } else { GETMVAR(QGVAR(enableAmmoCookoff),true) };);
defaultValue = QUOTE(if (_this isKindOf 'ReammoBox_F') then {GETMVAR(QGVAR(enableAmmobox),true)} else {GETMVAR(QGVAR(enableAmmoCookoff),true)});
};
};
};
Expand Down
1 change: 0 additions & 1 deletion addons/cookoff/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
Expand Down
1 change: 0 additions & 1 deletion addons/cookoff/CfgSFX.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class CfgSFX {
class GVAR(CookOff_low) {
name = QGVAR(cookoff_low);
Expand Down
37 changes: 1 addition & 36 deletions addons/cookoff/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class CfgVehicles {
class Sound;
class GVAR(Sound_low): Sound {
Expand All @@ -7,7 +6,6 @@ class CfgVehicles {
scope = 1;
sound = QGVAR(CookOff_low);
};

class GVAR(Sound_mid): GVAR(Sound_low) {
sound = QGVAR(CookOff_mid);
};
Expand All @@ -17,47 +15,14 @@ class CfgVehicles {

class Tank;
class Tank_F: Tank {
GVAR(ammoLocation) = "HitHull";
GVAR(cookoffSelections)[] = {"poklop_gunner","poklop_commander"};
GVAR(probability) = 0.5;
};
class MBT_02_base_F: Tank_F {
GVAR(ammoLocation) = "HitTurret";
};

class Car_F;
class Wheeled_APC_F: Car_F {
GVAR(ammoLocation) = "HitHull";
GVAR(cookoffSelections)[] = {"poklop_gunner","poklop_commander"};
GVAR(probability) = 0.8;

// big explosions for wheeled APCs (same as for tanks)
// Big explosions for wheeled APCs (same as for tanks)
explosionEffect = "FuelExplosionBig";
};


class MRAP_01_base_F: Car_F {
GVAR(engineSmokeOffset)[] = {0,-2,0};
};

class MRAP_02_base_F: Car_F {
GVAR(engineSmokeOffset)[] = {0,-2,0};
};

class MRAP_03_base_F: Car_F {
GVAR(engineSmokeOffset)[] = {0,-2,0};
};

class Quadbike_01_base_F: Car_F {
GVAR(engineSmokeOffset)[] = {0,1,0};
};

class Truck_F;
class Truck_02_base_F: Truck_F {
GVAR(engineSmokeOffset)[] = {0,-2.6,-0.1};
};

class Truck_02_MRL_base_F: Truck_02_base_F {
GVAR(engineSmokeOffset)[] = {0,0.3,-0.1};
};
};
18 changes: 10 additions & 8 deletions addons/cookoff/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

PREP(handleDamageBox);
PREP(engineFire);
PREP(cookOff);
PREP(smoke);
PREP(cookOffEffect);
PREP(cookOffBox);
PREP(detonateAmmunition);
PREP(cookOffBoxLocal);
PREP(cookOffBoxServer);
PREP(cookOffLocal);
PREP(cookOffServer);
PREP(detonateAmmunitionServer);
PREP(detonateAmmunitionServerLoop);
PREP(engineFireLocal);
PREP(engineFireServer);
PREP(getVehicleAmmo);
PREP(handleDamageBox);
PREP(isMagazineFlare);
PREP(smoke);
95 changes: 48 additions & 47 deletions addons/cookoff/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,63 +1,64 @@
#include "script_component.hpp"

[QGVAR(engineFire), LINKFUNC(engineFire)] call CBA_fnc_addEventHandler;
[QGVAR(cookOff), {
params ["_vehicle"];
if (local _vehicle) then {
_this call FUNC(cookOff);
};
}] call CBA_fnc_addEventHandler;
[QGVAR(cookOffEffect), LINKFUNC(cookOffEffect)] call CBA_fnc_addEventHandler;
[QGVAR(cookOffBoxLocal), LINKFUNC(cookOffBoxLocal)] call CBA_fnc_addEventHandler;
[QGVAR(cookOffLocal), LINKFUNC(cookOffLocal)] call CBA_fnc_addEventHandler;
[QGVAR(engineFireLocal), LINKFUNC(engineFireLocal)] call CBA_fnc_addEventHandler;
[QGVAR(smoke), LINKFUNC(smoke)] call CBA_fnc_addEventHandler;
[QGVAR(cookOffBox), LINKFUNC(cookOffBox)] call CBA_fnc_addEventHandler;

// handle cleaning up effects when vehicle is deleted mid-cookoff
[QGVAR(addCleanupHandlers), {
params ["_vehicle"];

// Don't add a new EH if cookoff is run multiple times
if ((_vehicle getVariable [QGVAR(deletedEH), -1]) == -1) then {
private _deletedEH = _vehicle addEventHandler ["Deleted", {
params ["_vehicle"];
if (isServer) then {
[QGVAR(cookOffBoxServer), LINKFUNC(cookOffBoxServer)] call CBA_fnc_addEventHandler;
[QGVAR(cookOffServer), LINKFUNC(cookOffServer)] call CBA_fnc_addEventHandler;
[QGVAR(detonateAmmunitionServer), LINKFUNC(detonateAmmunitionServer)] call CBA_fnc_addEventHandler;
[QGVAR(engineFireServer), LINKFUNC(engineFire)] call CBA_fnc_addEventHandler;
};

[QGVAR(cleanupEffects), [_vehicle]] call CBA_fnc_localEvent;
}];
// Handle cleaning up effects when objects are deleted mid cook-off
["AllVehicles", "Deleted", {
{
deleteVehicle _x;
} forEach ((_this select 0) getVariable [QGVAR(effects), []]);
}, true, ["CAManBase", "StaticWeapon"], true] call CBA_fnc_addClassEventHandler;

_vehicle setVariable [QGVAR(deletedEH), _deletedEH];
};
}] call CBA_fnc_addEventHandler;
["ReammoBox_F", "Deleted", {
{
deleteVehicle _x;
} forEach ((_this select 0) getVariable [QGVAR(effects), []]);
}, true, [], true] call CBA_fnc_addClassEventHandler;

// Raised when the flames have subsided or after the ammo of a box has finished cooking off
[QGVAR(cleanupEffects), {
params ["_vehicle", ["_effects", []]];
params ["_object"];

_effects = _effects + (_vehicle getVariable [QGVAR(effects), []]);
if (_effects isNotEqualTo []) then {
{ deleteVehicle _x } count _effects;
};
{
deleteVehicle _x;
} forEach (_object getVariable [QGVAR(effects), []]);

_object setVariable [QGVAR(effects), nil];
}] call CBA_fnc_addEventHandler;

// Ammo box damage handling
["ReammoBox_F", "init", {
(_this select 0) addEventHandler ["HandleDamage", {
if ((_this select 0) getVariable [QGVAR(enableAmmoCookoff), GVAR(enableAmmobox)]) then {
_this call FUNC(handleDamageBox);
};
}];
}, nil, nil, true] call CBA_fnc_addClassEventHandler;
// Calling this function inside curly brackets allows the usage of "exitWith", which would be broken with "HandleDamage" otherwise
(_this select 0) addEventHandler ["HandleDamage", {_this call FUNC(handleDamageBox)}];
}, true, [], true] call CBA_fnc_addClassEventHandler;

// Vehicle ammo cook-off (secondary explosions)
["AllVehicles", "Killed", {
if (!GVAR(enableAmmoCookoff) || {GVAR(ammoCookoffDuration) == 0}) exitWith {};

// secondary explosions
["AllVehicles", "killed", {
params ["_vehicle", "", "", "_useEffects"];
if (
_useEffects &&
_vehicle getVariable [QGVAR(enableAmmoCookoff), GVAR(enableAmmoCookoff)]
) then {
if (GVAR(ammoCookoffDuration) == 0) exitWith {};
([_vehicle] call FUNC(getVehicleAmmo)) params ["_mags", "_total"];

private _delay = (random MAX_AMMO_DETONATION_START_DELAY) max MIN_AMMO_DETONATION_START_DELAY;
[FUNC(detonateAmmunition), [_vehicle, _mags, _total], _delay] call CBA_fnc_waitAndExecute;

if (_useEffects && {_vehicle getVariable [QGVAR(enableAmmoCookoff), true]}) then {
// We don't need to pass source and instigator, as vehicle is already dead
[QGVAR(detonateAmmunitionServer), [
_vehicle,
false,
objNull,
objNull,
random [MIN_AMMO_DETONATION_START_DELAY, (MIN_AMMO_DETONATION_START_DELAY + MAX_AMMO_DETONATION_START_DELAY) / 2, MAX_AMMO_DETONATION_START_DELAY]
]] call CBA_fnc_serverEvent;
};
}, nil, ["Man","StaticWeapon"]] call CBA_fnc_addClassEventHandler;
}, true, ["CAManBase", "StaticWeapon"], true] call CBA_fnc_addClassEventHandler;

if (hasInterface) then {
// Plays a sound locally, so that different sounds can be used for various distances
Expand All @@ -68,7 +69,7 @@ if (hasInterface) then {

private _distance = _object distance (positionCameraToWorld [0, 0, 0]);

TRACE_3("",_object,_sound,_maxDistance);
TRACE_2("",_object,_sound);

// 3 classes of distances: close, mid and far, each having different sound files
private _classDistance = switch (true) do {
Expand All @@ -94,6 +95,6 @@ if (hasInterface) then {
if (!fileExists _sound) exitWith {};

// Obeys speed of sound and takes doppler effects into account
playSound3D [_sound, objNull, insideBuilding _object >= 0.5, getPosASL _object, _volume, _pitch + (random 0.2) - 0.1, _maxDistance, 0, true];
playSound3D [_sound, objNull, false, getPosASL _object, _volume, _pitch + (random 0.2) - 0.1, _maxDistance, 0, true];
}] call CBA_fnc_addEventHandler;
};
Loading

0 comments on commit aa48274

Please sign in to comment.