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

Add Vehicle Damage (ACE2 port) & Enhance Cook-Off #7565

Merged
merged 60 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
a690d6a
Initital port of ACE2 Vehicle Damage
TheCandianVendingMachine Feb 20, 2020
145824b
Add fire damage and burning people
TheCandianVendingMachine Feb 22, 2020
7f6c166
Migrate vehicle damge stuff from cookoff. Change cookoff function to …
TheCandianVendingMachine Feb 29, 2020
133cdd0
Minor tweaks
TheCandianVendingMachine Feb 29, 2020
a436ecf
Add incendiary values to all applicable ammunition. Add engine fire/s…
TheCandianVendingMachine Mar 1, 2020
9e2bebb
Handle car damage more elegantly.
TheCandianVendingMachine Mar 1, 2020
b9e0ceb
Added ability to create fire sources arbitrarily
TheCandianVendingMachine Mar 1, 2020
8f04572
tweaks
TheCandianVendingMachine Mar 1, 2020
42099d7
Add chance to detonate after cookoff
TheCandianVendingMachine Mar 1, 2020
9441f30
disable compile cache
TheCandianVendingMachine Mar 3, 2020
6cfe07d
Move blown-off turret config to vehicle damage. Add settings initital…
TheCandianVendingMachine Mar 3, 2020
b685334
tabs->spaces
TheCandianVendingMachine Mar 3, 2020
62db7cd
Various code improvements
TheCandianVendingMachine Mar 3, 2020
f22f0c0
Change to count loop for deleting effects
TheCandianVendingMachine Mar 3, 2020
3f032a5
update addon requirements
TheCandianVendingMachine Mar 3, 2020
c2c63e5
remove vanilla config requirements
TheCandianVendingMachine Mar 4, 2020
310932b
Add RHS compatability
TheCandianVendingMachine Mar 5, 2020
67cc592
RHS compat. Various QOL fixes/changes
TheCandianVendingMachine Mar 6, 2020
b665217
Various tweaks to compats and code.
TheCandianVendingMachine Mar 6, 2020
b0548e9
High-Explosive damage tweak
TheCandianVendingMachine Mar 6, 2020
132a4ca
Change how penetration is calculated for parts
TheCandianVendingMachine Mar 6, 2020
89dffc7
Fix RHS compat
TheCandianVendingMachine Mar 6, 2020
083a0f8
Create setting for flare effect
TheCandianVendingMachine Mar 6, 2020
8788697
increase burning scream sounds
TheCandianVendingMachine Mar 11, 2020
2aba117
swap out file name for snake_case
TheCandianVendingMachine Mar 12, 2020
ec8d512
move incendiary values out of vehicle damage. remove medical dependency
TheCandianVendingMachine Mar 12, 2020
1f3053f
Merge branch 'master' into pr/7565
PabstMirror May 7, 2020
aa0ef14
vehicle_dammage - update all refs to snake
PabstMirror May 7, 2020
66a23fc
sqf fixes
PabstMirror May 7, 2020
aef1d81
fix fire string package caps
PabstMirror May 7, 2020
18870d7
fix pboprefix
PabstMirror May 7, 2020
ea446c3
Default setting to on
TheCandianVendingMachine May 14, 2020
628f84c
Add variables to enable/disable ring fire to avoid goofy looking vehi…
TheCandianVendingMachine May 14, 2020
fee9d04
Fix bug where event handler wasn't giving the damage last.
TheCandianVendingMachine May 14, 2020
e89d488
change to snake
TheCandianVendingMachine May 14, 2020
635f272
fix build errors
TheCandianVendingMachine May 14, 2020
1cd4291
Fix UBC
PabstMirror May 15, 2020
887527e
Fix Order of Operations
TheCandianVendingMachine May 15, 2020
c64624d
Merge branch 'VehicleDamage' of https://github.com/TheCandianVendingM…
TheCandianVendingMachine May 15, 2020
c820de4
avoid O^2 events
TheCandianVendingMachine May 15, 2020
7f43efb
Make sure that no damage processing happens on dead units
TheCandianVendingMachine Jul 6, 2020
0a8916d
Change some if statements
TheCandianVendingMachine Jul 6, 2020
9ae7709
Keep track of player's death to stop various things
TheCandianVendingMachine Sep 10, 2020
743f117
add quotes to right middle wheen
TheCandianVendingMachine Dec 5, 2020
93f7543
Add VD documentation
TheCandianVendingMachine Dec 13, 2020
afd137a
fire docs
TheCandianVendingMachine Dec 13, 2020
d45219a
Code quality fixes
TheCandianVendingMachine Dec 13, 2020
af7f641
Clarify documentation
TheCandianVendingMachine Dec 13, 2020
22a39ad
define IDD
TheCandianVendingMachine Dec 13, 2020
e9a6180
switch global -> server
TheCandianVendingMachine Dec 13, 2020
78cec40
Add newline between header and first code statement
TheCandianVendingMachine Dec 13, 2020
382a08a
stop the dead from suffering
TheCandianVendingMachine Mar 4, 2021
49a31a0
Add settings to disable cook-off effects
TheCandianVendingMachine Apr 7, 2021
8eaaf28
Delete effects if vehicle is deleted before cookoff occurs. Don't coo…
TheCandianVendingMachine Apr 20, 2021
611e6cd
Move fire into own PR
TheCandianVendingMachine May 6, 2021
d33448c
Merge branch 'VehicleDamage' of https://github.com/TheCandianVendingM…
PabstMirror Jul 2, 2021
28ebdc0
fix tabs and macro
PabstMirror Jul 2, 2021
7451836
Shuffle crew indices so that a random person is first on the list to …
TheCandianVendingMachine Jul 12, 2021
d77cb5f
Merge branch 'VehicleDamage' of https://github.com/TheCandianVendingM…
TheCandianVendingMachine Jul 12, 2021
13444cf
fix effects not clearing
TheCandianVendingMachine Aug 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions addons/cookoff/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,6 @@ class CfgVehicles {
sound = QGVAR(CookOff_high);
};

class ThingX;
class GVAR(Turret_MBT_01): ThingX {
author = ECSTRING(common,ACETeam);
_generalMacro = QGVAR(Turret_MBT_01);
scope = 1;
displayName = CSTRING(generic_turret_wreck);
model = "\A3\Structures_F\Wrecks\Wreck_Slammer_turret_F.p3d";
icon = "\A3\armor_f_gamma\MBT_01\Data\ui\map_slammer_mk4_ca.paa";
};
class GVAR(Turret_MBT_02): ThingX {
author = ECSTRING(common,ACETeam);
_generalMacro = QGVAR(Turret_MBT_02);
scope = 1;
displayName = CSTRING(generic_turret_wreck);
model = "\A3\Structures_F\Wrecks\Wreck_T72_turret_F.p3d";
icon = "\A3\armor_f_gamma\MBT_02\Data\UI\map_MBT_02_ca.paa";
};

class Tank;
class Tank_F: Tank {
GVAR(ammoLocation) = "HitHull";
Expand Down Expand Up @@ -62,7 +44,7 @@ class CfgVehicles {

class B_MBT_01_base_F;
class B_MBT_01_cannon_F: B_MBT_01_base_F {
GVAR(turret)[] = {QGVAR(Turret_MBT_01),{0,-1,0.5}};
TheCandianVendingMachine marked this conversation as resolved.
Show resolved Hide resolved

};

class O_MBT_02_base_F;
Expand Down
5 changes: 3 additions & 2 deletions addons/cookoff/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
PREP(handleDamage);
PREP(engineFire);
PREP(cookOff);
PREP(smoke);
PREP(cookOffEffect);
PREP(cookOffBox);
PREP(blowOffTurret);
PREP(detonateAmmunition);
PREP(getVehicleAmmo);
PREP(handleDamageEjectIfDestroyed);

101 changes: 14 additions & 87 deletions addons/cookoff/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,72 +1,29 @@
#include "script_component.hpp"

[QGVAR(engineFire), FUNC(engineFire)] call CBA_fnc_addEventHandler;
[QGVAR(cookOff), FUNC(cookOff)] call CBA_fnc_addEventHandler;
[QGVAR(cookOffBox), FUNC(cookOffBox)] call CBA_fnc_addEventHandler;

GVAR(cacheTankDuplicates) = call CBA_fnc_createNamespace;

// cookoff and burning engine
["Tank", "init", {
params ["_vehicle"];

private _typeOf = typeOf _vehicle;

if (isNil {GVAR(cacheTankDuplicates) getVariable _typeOf}) then {
private _hitpoints = (getAllHitPointsDamage _vehicle param [0, []]) apply {toLower _x};
private _duplicateHitpoints = [];

{
if ((_x != "") && {_x in (_hitpoints select [0,_forEachIndex])}) then {
_duplicateHitpoints pushBack _forEachIndex;
};
} forEach _hitpoints;

TRACE_2("dupes",_typeOf,_duplicateHitpoints);
GVAR(cacheTankDuplicates) setVariable [_typeOf, _duplicateHitpoints];
};

_vehicle addEventHandler ["HandleDamage", {
["tank", _this] call FUNC(handleDamage);
}];
}, nil, nil, true] call CBA_fnc_addClassEventHandler;

["Wheeled_APC_F", "init", {
[QGVAR(cookOff), {
params ["_vehicle"];

private _typeOf = typeOf _vehicle;

if (isNil {GVAR(cacheTankDuplicates) getVariable _typeOf}) then {
private _hitpoints = (getAllHitPointsDamage _vehicle param [0, []]) apply {toLower _x};
private _duplicateHitpoints = [];

{
if ((_x != "") && {_x in (_hitpoints select [0,_forEachIndex])}) then {
_duplicateHitpoints pushBack _forEachIndex;
};
} forEach _hitpoints;

TRACE_2("dupes",_typeOf,_duplicateHitpoints);
GVAR(cacheTankDuplicates) setVariable [_typeOf, _duplicateHitpoints];
if (local _vehicle) then {
_this call FUNC(cookOff);
jonpas marked this conversation as resolved.
Show resolved Hide resolved
};
}] call CBA_fnc_addEventHandler;
[QGVAR(cookOffEffect), FUNC(cookOffEffect)] call CBA_fnc_addEventHandler;
[QGVAR(smoke), FUNC(smoke)] call CBA_fnc_addEventHandler;
[QGVAR(cookOffBox), FUNC(cookOffBox)] call CBA_fnc_addEventHandler;

_vehicle addEventHandler ["HandleDamage", {
["tank", _this] call FUNC(handleDamage);
}];
}, nil, nil, true] call CBA_fnc_addClassEventHandler;

["Car", "init", {
[QGVAR(cleanupEffects), {
params ["_vehicle"];

private _effects = _vehicle getVariable [QGVAR(effects), []];
_effects count {deleteVehicle _x };
}] call CBA_fnc_addEventHandler;

_vehicle addEventHandler ["HandleDamage", {
["car", _this] call FUNC(handleDamage);
}];
}, nil, ["Wheeled_APC_F"], true] call CBA_fnc_addClassEventHandler;
GVAR(cacheTankDuplicates) = call CBA_fnc_createNamespace;

["ReammoBox_F", "init", {
(_this select 0) addEventHandler ["HandleDamage", {
if ((_this select 0) getVariable [QGVAR(enableAmmoCookoff), GVAR(enableAmmobox)]) then {
["box", _this] call FUNC(handleDamage);
_this call FUNC(handleDamage);
};
}];
}, nil, nil, true] call CBA_fnc_addClassEventHandler;
Expand All @@ -81,34 +38,4 @@ GVAR(cacheTankDuplicates) = call CBA_fnc_createNamespace;
};
}, nil, ["Man","StaticWeapon"]] call CBA_fnc_addClassEventHandler;

// blow off turret effect
["Tank", "killed", {
if ((_this select 0) getVariable [QGVAR(enable), GVAR(enable)] in [1, 2, true]) then {
if (random 1 < 0.15) then {
(_this select 0) call FUNC(blowOffTurret);
};
};
}] call CBA_fnc_addClassEventHandler;

// event to add a turret to a curator if the vehicle already belonged to that curator
if (isServer) then {
[QGVAR(addTurretToEditable), {
params ["_vehicle", "_turret"];

{
if (_vehicle in curatorEditableObjects _x) then {
_x addCuratorEditableObjects [[_turret], false];
};
} forEach allCurators;
}] call CBA_fnc_addEventHandler;
};

// init eject from destroyed vehicle
{
[_x, "init", {
params ["_vehicle"];
if (!alive _vehicle) exitWith {};
TRACE_2("ejectIfDestroyed init",_vehicle,typeOf _vehicle);
_vehicle addEventHandler ["HandleDamage", {call FUNC(handleDamageEjectIfDestroyed)}];
}, true, [], true] call CBA_fnc_addClassEventHandler;
} forEach EJECT_IF_DESTROYED_VEHICLES;
175 changes: 66 additions & 109 deletions addons/cookoff/functions/fnc_cookOff.sqf
Original file line number Diff line number Diff line change
@@ -1,140 +1,97 @@
#include "script_component.hpp"
/*
* Author: KoffeinFlummi, commy2
* Author: Brandon (TCVM)
* Start a cook-off in the given vehicle.
*
* Arguments:
* 0: Vehicle <Object>
* 1: Intensity of fire <Number>
*
* Return Value:
* None
*
* Example:
* [(vehicle player)] call ace_cookoff_fnc_cookOff
* [(vehicle player), 3] call ace_cookoff_fnc_cookOff
*
* Public: No
*/

params ["_vehicle"];
params ["_vehicle", "_intensity", ["_instigator", objNull], ["_smokeDelayEnabled", true], ["_ammoDetonationChance", 0], ["_detonateAfterCookoff", false]];

if (_vehicle getVariable [QGVAR(isCookingOff), false]) exitWith {};
_vehicle setVariable [QGVAR(isCookingOff), true];
_vehicle setVariable [QGVAR(isCookingOff), true, true];

if (local _vehicle) then {
[QGVAR(cookOff), _vehicle] call CBA_fnc_globalEvent;
};

[{
params ["_vehicle"];

private _config = _vehicle call CBA_fnc_getObjectConfig;
private _positions = getArray (_config >> QGVAR(cookoffSelections)) select {!((_vehicle selectionPosition _x) isEqualTo [0,0,0])};
private _config = _vehicle call CBA_fnc_getObjectConfig;
private _positions = getArray (_config >> QGVAR(cookoffSelections)) select {!((_vehicle selectionPosition _x) isEqualTo [0,0,0])};

if (_positions isEqualTo []) then {
WARNING_1("no valid selection for cookoff found. %1", typeOf _vehicle);
TheCandianVendingMachine marked this conversation as resolved.
Show resolved Hide resolved
{
private _pos = _vehicle selectionPosition _x;
if (_pos isEqualTo [0, 0, 0]) exitWith {};
_positions pushBack _x;
} forEach DEFAULT_COMMANDER_HATCHES;

if (_positions isEqualTo []) then {
WARNING_1("no valid selection for cookoff found. %1", typeOf _vehicle);
_positions pushBack "#noselection";
};
};

private _turretConfig = [_vehicle, [0]] call CBA_fnc_getTurret;
private _positionBarrelEnd = getText (_turretConfig >> "gunBeg");

// smoke out of cannon and hatches
private _smokeBarrel = "#particlesource" createVehicleLocal [0,0,0];
_smokeBarrel setParticleClass "MediumDestructionSmoke";
_smokeBarrel attachTo [_vehicle, [0,0,0], _positionBarrelEnd];

private _effects = [_smokeBarrel];

{
private _position = [0,-2,0];

if !(_x isEqualTo "#noselection") then {
_position = _vehicle selectionPosition _x;
};

private _smoke = "#particlesource" createVehicleLocal [0,0,0];
_smoke setParticleClass "ObjectDestructionSmoke1_2Smallx";
_smoke attachTo [_vehicle, _position];
private _delay = 0;
if (_smokeDelayEnabled) then {
_delay = SMOKE_TIME + random SMOKE_TIME;
};
[QGVAR(smoke), [_vehicle, _positions]] call CBA_fnc_globalEvent;

_effects pushBack _smoke;
} forEach _positions;
[{
params ["_vehicle", "_positions", "_intensity", "_ammoDetonationChance", "_detonateAfterCookoff", "_instigator"];
_vehicle setVariable [QGVAR(intensity), _intensity];

[{
params ["_vehicle", "_effects", "_positions"];

// this shit is busy being on fire, can't go driving around all over the place
if (local _vehicle) then {
_vehicle setFuel 0;
};

private _light = "#lightpoint" createVehicleLocal [0,0,0];
_light setLightBrightness 0.7;
_light setLightAmbient [1,0.4,0.15];
_light setLightColor [1,0.4,0.15];
_light lightAttachObject [_vehicle, [0,0,4]];

_effects pushBack _light;

// cookoffs
{
private _position = [0,-2,0];

if !(_x isEqualTo "#noselection") then {
_position = _vehicle selectionPosition _x;
};

private _fire = "#particlesource" createVehicleLocal [0,0,0];
_fire setParticleClass QGVAR(CookOff);
_fire attachTo [_vehicle, _position];

_effects pushBack _fire;
} forEach _positions;

if (isServer) then {
private _soundName = selectRandomWeighted [QGVAR(Sound_low), 0.1, QGVAR(Sound_mid), 0.25, QGVAR(Sound_high), 0.65];
// TODO - Players in the vehicle hear no sound (even after exiting the vehicle)
private _sound = createSoundSource [_soundName, position _vehicle, [], 0];

_effects pushBack _sound;
};

// indicator for the crew - yo, your shit's on fire
private _fnc_FlameEffect = {
params ["_vehicle", "_fnc_FlameEffect", "_counter"];

if (_vehicle == cameraOn) then {
[] call BIS_fnc_flamesEffect;
};

DEC(_counter);

if (_counter > 0) then {
[_fnc_FlameEffect, [_vehicle, _fnc_FlameEffect, _counter], FLAME_EFFECT_DELAY] call CBA_fnc_waitAndExecute
params ["_args", "_pfh"];
_args params ["_vehicle", "_positions", "_ammoDetonationChance", "_detonateAfterCookoff", "_instigator"];
private _intensity = _vehicle getVariable [QGVAR(intensity), 0];
if (_intensity <= 1) exitWith {
[QGVAR(cleanupEffects), _vehicle] call CBA_fnc_globalEvent;
_vehicle setVariable [QGVAR(isCookingOff), false, true];
[_pfh] call CBA_fnc_removePerFrameHandler;

if (_detonateAfterCookoff) then {
_vehicle setDamage 1;
};
};

// Recursive function, occurs for duration of cookoff
[_vehicle, _fnc_FlameEffect, ceil(COOKOFF_TIME/FLAME_EFFECT_DELAY)] call _fnc_FlameEffect;

private _randomPosition = _vehicle getPos [100, random 360];

{
if (local _x && {!(_x call EFUNC(common,isPlayer))}) then {
_x leaveVehicle _vehicle;
_x doMove _randomPosition;

private _lastFlameTime = _vehicle getVariable [QGVAR(lastFlame), 0];
private _nextFlameTime = _vehicle getVariable [QGVAR(nextFlame), 0];
if ((CBA_missionTime - _lastFlameTime) >= _nextFlameTime) then {
private _ring = (0.2 > random 1);
if (!_ring && _intensity >= 2) then {
_ring = (0.7 > random 1);
TheCandianVendingMachine marked this conversation as resolved.
Show resolved Hide resolved
};
} forEach crew _vehicle;

[{
params ["_vehicle", "_effects"];


private _time = linearConversion [0, 10, _intensity, 5, 20] + random COOKOFF_TIME;
[QGVAR(cookOffEffect), [_vehicle, true, _ring, _time, selectRandom _positions]] 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)];

{
deleteVehicle _x;
} forEach _effects;

if (local _vehicle) then {
_vehicle setDamage 1;
[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 {
createVehicle ["ACE_ammoExplosionLarge", (_vehicle modelToWorld (_vehicle selectionPosition selectRandom _positions)), [], 0 , "CAN_COLLIDE"];

_vehicle setVariable [QGVAR(lastExplosiveDetonation), CBA_missionTime];
_vehicle setVariable [QGVAR(nextExplosiveDetonation), random 60];
};
}, [_vehicle, _effects], COOKOFF_TIME] call CBA_fnc_waitAndExecute; // TODO: Randomise cook off time with locality in mind
}, [_vehicle, _effects, _positions], SMOKE_TIME] call CBA_fnc_waitAndExecute;
}, _vehicle, IGNITE_TIME] call CBA_fnc_waitAndExecute;
};
}, 0.25, [_vehicle, _positions, _ammoDetonationChance, _detonateAfterCookoff, _instigator]] call CBA_fnc_addPerFrameHandler
}, [_vehicle, _positions, _intensity, _ammoDetonationChance, _detonateAfterCookoff, _instigator], _delay] call CBA_fnc_waitAndExecute;
Loading