mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
80b2fa9a05
* 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 * Vehicle damage fixes * Made hitpoint hash common * Update fnc_addEventHandler.sqf * Update fnc_medicalDamage.sqf * Update fnc_handleBail.sqf * Changed API * Remove `CBA_fnc_getConfigEntry` as much as possible, as it's 2x slower * More cleanup * More cleanup * Fix merging issues, remove turret tossing * Update translations * More cleanup * Reverted some logic back to original, minor tweaks & fixes * Fix undefined variable * Cleanup * Fixed bad logic * Update addons/vehicle_damage/script_macros.hpp Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> * Update addons/vehicle_damage/functions/fnc_handleDamage.sqf * Update addons/vehicle_damage/stringtable.xml Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> * Update addons/vehicle_damage/stringtable.xml Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> * Update addons/vehicle_damage/XEH_postInit.sqf Co-authored-by: PabstMirror <pabstmirror@gmail.com> --------- Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com> Co-authored-by: PabstMirror <pabstmirror@gmail.com>
138 lines
4.2 KiB
Plaintext
138 lines
4.2 KiB
Plaintext
#include "..\script_component.hpp"
|
|
/*
|
|
* Author: tcvm, johnb43
|
|
* Adds the event handler to a vehicle.
|
|
*
|
|
* Arguments:
|
|
* 0: Vehicle <OBJECT>
|
|
*
|
|
* Return Value:
|
|
* None
|
|
*
|
|
* Example:
|
|
* cursorObject call ace_vehicle_damage_fnc_addEventHandler
|
|
*
|
|
* Public: No
|
|
*/
|
|
|
|
params ["_vehicle"];
|
|
TRACE_2("addEventHandler",_vehicle,GVAR(enabled));
|
|
|
|
if (!GVAR(enabled)) exitWith {
|
|
#ifdef DEBUG_MODE_FULL
|
|
[CBA_fnc_notify, ["Warning: Vehicle Damage not enabled", 2], 5] call CBA_fnc_waitAndExecute;
|
|
#endif
|
|
};
|
|
|
|
if (!isNil {_vehicle getVariable QGVAR(handleDamage)}) exitWith {};
|
|
|
|
_vehicle allowCrewInImmobile true;
|
|
|
|
// No clue why, but for some reason this needs to be exec'd next frame or else it isn't the last event handler in the system.
|
|
// Maybe its overridden somewhere else, but this makes sure it is the last one
|
|
[{
|
|
params ["_vehicle"];
|
|
|
|
if (!isNil {_vehicle getVariable QGVAR(handleDamage)}) exitWith {};
|
|
|
|
TRACE_1("added eh",_vehicle);
|
|
|
|
_vehicle setVariable [QGVAR(hitHash), createHashMap];
|
|
_vehicle setVariable [QGVAR(handleDamage), _vehicle addEventHandler ["HandleDamage", {_this call FUNC(handleDamage)}]];
|
|
}, _vehicle] call CBA_fnc_execNextFrame;
|
|
|
|
private _typeOf = typeOf _vehicle;
|
|
|
|
if (_typeOf in GVAR(vehicleClassesHitPointHash)) exitWith {};
|
|
|
|
private _hitPointHash = createHashMap;
|
|
private _vehicleConfig = configOf _vehicle;
|
|
private _hitPointsConfig = _vehicleConfig >> "HitPoints";
|
|
|
|
// Add hitpoint names to config for quick lookup
|
|
{
|
|
_x params ["_hitPoints", "_hitArea"];
|
|
|
|
{
|
|
_hitPointHash set [toLowerANSI _x, [_hitArea, abs getNumber (_hitPointsConfig >> _x >> "minimalHit")]];
|
|
} forEach _hitPoints;
|
|
} forEach ALL_HITPOINTS;
|
|
|
|
// Gun and turret hitpoints aren't hardcoded anymore - dig through config to find correct names
|
|
private _fnc_iterateThroughConfig = {
|
|
params ["_config"];
|
|
TRACE_1("checking config",_config);
|
|
|
|
private _configName = toLowerANSI configName _config;
|
|
private _isGun = getNumber (_config >> "isGun") == 1;
|
|
private _isTurret = getNumber (_config >> "isTurret") == 1;
|
|
private _isEra = _configName in _eraHitpoints;
|
|
private _isSlat = _configName in _slatHitpoints;
|
|
private _isMisc = false;
|
|
|
|
// Prevent incompatibilites with old mods
|
|
if (_configName == "hitturret") then {
|
|
_isTurret = true;
|
|
};
|
|
|
|
if (_configName == "hitgun") then {
|
|
_isGun = true;
|
|
};
|
|
|
|
{
|
|
_x params ["_hitArea", "_hitPoints"];
|
|
|
|
if (_configName in _hitPoints) then {
|
|
_hitPointHash set [_configName, [_hitArea, abs getNumber (_config >> "minimalHit")]];
|
|
_isMisc = true;
|
|
};
|
|
} forEach _hitPointAliases;
|
|
|
|
if (_isGun || _isTurret || _isEra || _isSlat || _isMisc) then {
|
|
if (_isGun) then {
|
|
_hitPointHash set [_configName, ["gun", abs getNumber (_config >> "minimalHit")]];
|
|
};
|
|
if (_isTurret) then {
|
|
_hitPointHash set [_configName, ["turret", abs getNumber (_config >> "minimalHit")]];
|
|
};
|
|
if (_isEra) then {
|
|
_hitPointHash set [_configName, ["era", abs getNumber (_config >> "minimalHit")]];
|
|
};
|
|
if (_isSlat) then {
|
|
_hitPointHash set [_configName, ["slat", abs getNumber (_config >> "minimalHit")]];
|
|
};
|
|
|
|
TRACE_6("found gun/turret/era/slat/misc",_isGun,_isTurret,_isEra,_isSlat,_isMisc,_hash);
|
|
} else {
|
|
{
|
|
_x call _fnc_iterateThroughConfig;
|
|
} forEach configProperties [_config, "isClass _x", true];
|
|
};
|
|
};
|
|
|
|
private _turretConfig = _vehicleConfig >> "Turrets";
|
|
private _eraHitpoints = (getArray (_vehicleConfig >> QGVAR(eraHitpoints))) apply {toLowerANSI _x};
|
|
private _slatHitpoints = (getArray (_vehicleConfig >> QGVAR(slatHitpoints))) apply {toLowerANSI _x};
|
|
|
|
private _fnc_toLowerCase = {
|
|
_this apply {
|
|
if (_x isEqualType []) then {
|
|
_x call _fnc_toLowerCase
|
|
} else {
|
|
toLowerANSI _x
|
|
};
|
|
};
|
|
};
|
|
|
|
// Convert areas to lower case
|
|
private _hitPointAliases = (getArray (_vehicleConfig >> QGVAR(hitpointAlias))) call _fnc_toLowerCase;
|
|
|
|
TRACE_1("hitpoint alias",_hitPointAliases);
|
|
|
|
_hitPointsConfig call _fnc_iterateThroughConfig;
|
|
_turretConfig call _fnc_iterateThroughConfig;
|
|
|
|
GVAR(vehicleClassesHitPointHash) set [_typeOf, _hitPointHash];
|
|
|
|
nil
|