ACE3/addons/vehicle_damage/functions/fnc_addEventHandler.sqf

111 lines
4.4 KiB
Plaintext
Raw Normal View History

Add Vehicle Damage (ACE2 port) & Enhance Cook-Off (#7565) * Initital port of ACE2 Vehicle Damage * Add fire damage and burning people * Migrate vehicle damge stuff from cookoff. Change cookoff function to enhance effect. * Minor tweaks * Add incendiary values to all applicable ammunition. Add engine fire/smoke if hit enough * Handle car damage more elegantly. * Added ability to create fire sources arbitrarily * tweaks * Add chance to detonate after cookoff * disable compile cache * Move blown-off turret config to vehicle damage. Add settings inititalized EH for initializing off settings * tabs->spaces * Various code improvements * Change to count loop for deleting effects * update addon requirements * remove vanilla config requirements * Add RHS compatability * RHS compat. Various QOL fixes/changes * Various tweaks to compats and code. * High-Explosive damage tweak * Change how penetration is calculated for parts * Fix RHS compat * Create setting for flare effect * increase burning scream sounds * swap out file name for snake_case * move incendiary values out of vehicle damage. remove medical dependency * vehicle_dammage - update all refs to snake * sqf fixes * fix fire string package caps * fix pboprefix * Default setting to on * Add variables to enable/disable ring fire to avoid goofy looking vehicles. Enhance how particles are cleaned up. Remove advanced penetration simulation. Change how fire intensity is calculated. Add setting to "disable" vehicle after cookoff * Fix bug where event handler wasn't giving the damage last. * change to snake * fix build errors * Fix UBC * Fix Order of Operations * avoid O^2 events * Make sure that no damage processing happens on dead units * Change some if statements * Keep track of player's death to stop various things * add quotes to right middle wheen * Add VD documentation * fire docs * Code quality fixes * Clarify documentation * define IDD * switch global -> server * Add newline between header and first code statement * stop the dead from suffering Its hard to tell when a unit is dead or in spectator, so check the config of the unit to determine it. * Add settings to disable cook-off effects * Delete effects if vehicle is deleted before cookoff occurs. Don't cookoff player ammo. Throw weapon better * Move fire into own PR * fix tabs and macro * Shuffle crew indices so that a random person is first on the list to be injured each time * fix effects not clearing Co-authored-by: PabstMirror <pabstmirror@gmail.com>
2021-10-14 15:49:27 +00:00
#include "script_component.hpp"
/*
* Author: Brandon (TCVM)
* Adds the event handler to a vehicle.
*
* Arguments:
* 0: The vehicle in which to add the event handler to <OBJECT>
*
* Return Value:
* None
*
* Example:
* [tank2] call ace_vehicle_damage_fnc_addEventHandler;
*
* Public: No
*/
params["_vehicle"];
TRACE_2("addEventHandler",_vehicle,GVAR(enabled));
if !(GVAR(enabled)) exitWith {
#ifdef DEBUG_MODE_FULL
[{ ["Warning: Vehicle Damage not enabled...", 2] call CBA_fnc_notify; }, [], 5] call CBA_fnc_waitAndExecute;
#endif
};
private _hitpointHash = [[], nil] call CBA_fnc_hashCreate;
private _vehicleConfig = configFile >> "CfgVehicles" >> typeOf _vehicle;
private _hitpointsConfig = _vehicleConfig >> "HitPoints";
private _turretConfig = _vehicleConfig >> "Turrets";
private _eraHitpoints = [_vehicleConfig >> QGVAR(eraHitpoints), "ARRAY", []] call CBA_fnc_getConfigEntry;
private _slatHitpoints = [_vehicleConfig >> QGVAR(slatHitpoints), "ARRAY", []] call CBA_fnc_getConfigEntry;
// Add hitpoint names to config for quick lookup
{
_x params ["_hitpoints", "_type"];
{
[_hitpointHash, toLower _x, [_type, _hitpointsConfig >> _x, _x]] call CBA_fnc_hashSet;
} forEach _hitpoints;
} forEach ALL_HITPOINTS;
_vehicle setVariable [QGVAR(hitpointHash), _hitpointHash];
// gun and turret hitpoints arent hardcoded anymore - dig through config to find correct names
private _iterateThroughConfig = {
params ["_vehicle", "_config", "_iterateThroughConfig", "_hitpointAliases"];
TRACE_1("checking config",_config);
private _configName = configName _config;
private _isGun = ([_config >> "isGun", "NUMBER", 0] call CBA_fnc_getConfigEntry) == 1;
private _isTurret = ([_config >> "isTurret", "NUMBER", 0] call CBA_fnc_getConfigEntry) == 1;
private _isEra = _configName in _eraHitpoints;
private _isSlat = _configName in _slatHitpoints;
private _isMisc = false;
// prevent incompatibilites with old mods
if ((toLower _configName) isEqualTo "hitturret") then {
_isTurret = true;
};
if ((toLower _configName) isEqualTo "hitgun") then {
_isGun = true;
};
private _hash = _vehicle getVariable QGVAR(hitpointHash);
{
_x params ["_hitType", "_hitPoints"];
if ((toLower _configName) in _hitPoints) then {
[_hash, toLower _configName, [_hitType, _config, _configName]] call CBA_fnc_hashSet;
_isMisc = true;
};
} forEach _hitpointAliases;
if (_isGun || _isTurret || _isEra || _isSlat || _isMisc) then {
TRACE_6("found gun/turret/era/slat/misc",_isGun,_isTurret,_isEra,_isSlat,_isMisc,_hash);
if (_isGun) then {
[_hash, toLower _configName, ["gun", _config, _configName]] call CBA_fnc_hashSet;
};
if (_isTurret) then {
[_hash, toLower _configName, ["turret", _config, _configName]] call CBA_fnc_hashSet;
};
if (_isEra) then {
[_hash, toLower _configName, ["era", _config, _configName]] call CBA_fnc_hashSet;
};
if (_isSlat) then {
[_hash, toLower _configName, ["slat", _config, _configName]] call CBA_fnc_hashSet;
};
_vehicle setVariable [QGVAR(hitpointHash), _hash];
} else {
{
[_vehicle, _x, _iterateThroughConfig, _hitpointAliases] call _iterateThroughConfig;
} forEach configProperties [_config, "isClass _x", true];
};
};
private _hitpointAliases = [_vehicleConfig >> QGVAR(hitpointAlias), "ARRAY", []] call CBA_fnc_getConfigEntry;
TRACE_1("hitpoint alias",_hitpointAliases);
[_vehicle, _hitpointsConfig, _iterateThroughConfig, _hitpointAliases] call _iterateThroughConfig;
[_vehicle, _turretConfig, _iterateThroughConfig, _hitpointAliases] call _iterateThroughConfig;
_vehicle allowCrewInImmobile true;
private _eh = _vehicle getVariable [QGVAR(handleDamage), nil];
if (isNil "_eh") then {
// no clue why, but for some reason this needs to exec'd next frame or else it isnt the last event handler in the system.
// Maybe its overridden somewhere else, but this makes sure it is the last one
[{
params ["_vehicle"];
TRACE_1("EH not added yet - added eh now", _vehicle);
private _hd = _vehicle addEventHandler ["HandleDamage", { _this call FUNC(handleDamage) }];
_vehicle setVariable [QGVAR(handleDamage), _hd];
}, [_vehicle]] call CBA_fnc_execNextFrame;
};