diff --git a/addons/grenades/XEH_PREP.hpp b/addons/grenades/XEH_PREP.hpp index 6b5fb57801..6feaff3a69 100644 --- a/addons/grenades/XEH_PREP.hpp +++ b/addons/grenades/XEH_PREP.hpp @@ -1,4 +1,4 @@ - +PREP(damageEngineAndWheels); PREP(flare); PREP(flashbangExplosionEH); PREP(flashbangThrownFuze); diff --git a/addons/grenades/XEH_postInit.sqf b/addons/grenades/XEH_postInit.sqf index 21282ab1ce..312e22fa6e 100644 --- a/addons/grenades/XEH_postInit.sqf +++ b/addons/grenades/XEH_postInit.sqf @@ -3,6 +3,7 @@ #include "script_component.hpp" ["ace_flashbangExploded", LINKFUNC(flashbangExplosionEH)] call CBA_fnc_addEventHandler; +[QGVAR(damageEngineAndWheels), LINKFUNC(damageEngineAndWheels)] call CBA_fnc_addEventHandler; // Register fired event handlers ["ace_firedPlayer", LINKFUNC(throwGrenade)] call CBA_fnc_addEventHandler; diff --git a/addons/grenades/functions/fnc_damageEngineAndWheels.sqf b/addons/grenades/functions/fnc_damageEngineAndWheels.sqf new file mode 100644 index 0000000000..fa0032e87e --- /dev/null +++ b/addons/grenades/functions/fnc_damageEngineAndWheels.sqf @@ -0,0 +1,60 @@ +#include "..\script_component.hpp" +/* + * Author: commy2, johnb43 + * Damage a vehicle's wheels and engine. + * + * Arguments: + * 0: Vehicle + * 1: Incendiary position AGL + * + * Return Value: + * None + * + * Example: + * [cursorObject, position cursorObject] call ace_grenades_fnc_damageEngineAndWheels + * + * Public: No + */ + +params ["_vehicle", "_position"]; +TRACE_1("damageWheelsAndEngine",_vehicle); + +// Vehicle needs to be local and vulnerable +if !(local _vehicle && {isDamageAllowed _vehicle}) exitWith {}; + +// Burn tires +private _fnc_isWheelHitPoint = { + params ["_selectionName"]; + // Wheels must use a selection named "wheel_X_Y_steering" for PhysX to work + _selectionName select [0, 6] == "wheel_" && { + _selectionName select [count _selectionName - 9] == "_steering" + } // return +}; + +private _config = configOf _vehicle >> "HitPoints"; + +{ + private _wheelSelection = getText (_config >> _x >> "name"); + + if (_wheelSelection call _fnc_isWheelHitPoint) then { + private _wheelPosition = _vehicle modelToWorld (_vehicle selectionPosition _wheelSelection); + + if (_position distance _wheelPosition < EFFECT_SIZE * 2) then { + _vehicle setHit [_wheelSelection, 1]; + }; + }; +} forEach (getAllHitPointsDamage _vehicle param [0, []]); + +// Burn car engines only +if (_vehicle isKindOf "Wheeled_APC_F") exitWith {}; + +private _engineSelection = getText (_config >> "HitEngine" >> "name"); +private _enginePosition = _vehicle modelToWorld (_vehicle selectionPosition _engineSelection); + +if (_position distance _enginePosition < EFFECT_SIZE * 2) then { + _vehicle setHit [_engineSelection, 1]; + + if (["ace_cookoff"] call EFUNC(common,isModLoaded)) then { + [QEGVAR(cookoff,engineFireServer), _vehicle] call CBA_fnc_serverEvent; + }; +}; diff --git a/addons/grenades/functions/fnc_incendiary.sqf b/addons/grenades/functions/fnc_incendiary.sqf index c59d463511..337065cae3 100644 --- a/addons/grenades/functions/fnc_incendiary.sqf +++ b/addons/grenades/functions/fnc_incendiary.sqf @@ -30,11 +30,11 @@ #define PARTICLE_SMOKE_LIFTING 1 #define PARTICLE_SMOKE_WIND_EFFECT 1 -#define EFFECT_SIZE 1 #define ORIENTATION 5.4 #define EXPANSION 1 #define DESTRUCTION_RADIUS 1.8 +#define SEARCH_RADIUS 5 params ["_projectile", "_timeToLive", "_center"]; @@ -157,7 +157,24 @@ if (isServer) then { _sound = createSoundSource ["Sound_Fire", _position, [], 0]; private _radius = 1.5 * getNumber (configOf _projectile >> "indirectHitRange"); private _intensity = getNumber (configOf _projectile >> "hit"); - [QEGVAR(fire,addFireSource), [_projectile, _radius, _intensity, _projectile, {CBA_missionTime < _this}, CBA_missionTime + _timeToLive]] call CBA_fnc_serverEvent; + [QEGVAR(fire,addFireSource), [_projectile, _radius, _intensity, _projectile, { + params ["_endTime", "_projectile"]; + + // If incendiary no longer exists, exit + if (isNull _projectile) exitWith { + false + }; + + // Need to get the position every time, as grenade might have been moved + private _position = position _projectile; + + { + // Damage vehicles + [QGVAR(damageEngineAndWheels), [_x, _position], _x] call CBA_fnc_targetEvent; + } forEach (_position nearEntities ["Car", SEARCH_RADIUS]); + + CBA_missionTime < _endTime // return + }, [CBA_missionTime + _timeToLive, _projectile]]] call CBA_fnc_serverEvent; }; [{ @@ -196,45 +213,7 @@ if (isServer) then { }; } forEach (_position nearObjects DESTRUCTION_RADIUS); -// --- damage local vehicle -private _vehicle = _position nearestObject "Car"; - -if (!local _vehicle) exitWith {}; - -private _config = configOf _vehicle; - -// --- burn tyres -private _fnc_isWheelHitPoint = { - params ["_selectionName"]; - - // wheels must use a selection named "wheel_X_Y_steering" for PhysX to work - _selectionName select [0, 6] == "wheel_" && { - _selectionName select [count _selectionName - 9] == "_steering" - } // return -}; - { - private _wheelSelection = getText (_config >> "HitPoints" >> _x >> "name"); - - if (_wheelSelection call _fnc_isWheelHitPoint) then { - private _wheelPosition = _vehicle modelToWorld (_vehicle selectionPosition _wheelSelection); - - if (_position distance _wheelPosition < EFFECT_SIZE * 2) then { - _vehicle setHit [_wheelSelection, 1]; - }; - }; -} forEach (getAllHitPointsDamage _vehicle param [0, []]); - -// --- burn car engine -if (_vehicle isKindOf "Wheeled_APC_F") exitWith {}; - -private _engineSelection = getText (_config >> "HitPoints" >> "HitEngine" >> "name"); -private _enginePosition = _vehicle modelToWorld (_vehicle selectionPosition _engineSelection); - -if (_position distance _enginePosition < EFFECT_SIZE * 2) then { - _vehicle setHit [_engineSelection, 1]; - - if (["ace_cookoff"] call EFUNC(common,isModLoaded)) then { - [QEGVAR(cookoff,engineFireServer), _vehicle] call CBA_fnc_serverEvent; - }; -}; + // Damage vehicles (locality is checked in FUNC(damageEngineAndWheels)) + [_x, _position] call FUNC(damageEngineAndWheels); +} forEach (_position nearEntities ["Car", SEARCH_RADIUS]); diff --git a/addons/grenades/script_component.hpp b/addons/grenades/script_component.hpp index 3da453de6f..ba673d0f33 100644 --- a/addons/grenades/script_component.hpp +++ b/addons/grenades/script_component.hpp @@ -21,4 +21,6 @@ #define EFFECT_STAGE_PARTIALRECOVERY 2 #define EFFECT_STAGE_FULLRECOVERY 3 +#define EFFECT_SIZE 1 + #define MIN_EXPLOSION_TIME_FOR_ROLL 1