From 8ba81c53a3c0992f120e8f9a75af9b9ca39bf696 Mon Sep 17 00:00:00 2001 From: Mark Ruffner Date: Mon, 22 Jan 2018 17:31:44 -0600 Subject: [PATCH] Add spectator handling of grenades (#6012) * Handle non-local vanilla grenade tosses * handle advanced throwing grenades * Track through events * Add missing calls --- .../spectator/functions/fnc_handleFired.sqf | 21 ++++----- addons/spectator/functions/fnc_ui.sqf | 45 +++++++++++++++++++ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/addons/spectator/functions/fnc_handleFired.sqf b/addons/spectator/functions/fnc_handleFired.sqf index b9258cbd02..4b0d640585 100644 --- a/addons/spectator/functions/fnc_handleFired.sqf +++ b/addons/spectator/functions/fnc_handleFired.sqf @@ -21,7 +21,7 @@ params [ ["_weapon", "", [""]], "", // Muzzle "", // Mode - "", // Ammo + ["_ammo", "", [""]], // Ammo "", // Magazine ["_projectile", objNull, [objNull]] ]; @@ -36,13 +36,14 @@ if (isNil QGVAR(entitiesToDraw) || {!(_unit in GVAR(entitiesToDraw))}) exitWith // Fire time used for unit icon highlighting _unit setVariable [QGVAR(highlightTime), time + FIRE_HIGHLIGHT_TIME]; -// Store projectiles / grenades for drawing -if (GVAR(drawProjectiles) && {!isNull _projectile}) then { - if (_weapon == "Throw") then { - if (count GVAR(grenadesToDraw) > MAX_GRENADES) then { GVAR(grenadesToDraw) deleteAt 0; }; - GVAR(grenadesToDraw) pushBack _projectile; - } else { - if (count GVAR(projectilesToDraw) > MAX_PROJECTILES) then { GVAR(projectilesToDraw) deleteAt 0; }; - GVAR(projectilesToDraw) pushBack [_projectile, [[getPosVisual _projectile, [1,0,0,0]]]]; - }; +// expensive, but any non local units might have this as null for 'global' projectiles (like grenades) +if (isNull _projectile) then { + _projectile = nearestObject [_unit, _ammo]; +}; + +// Store projectiles / grenades for drawing +if (_weapon == "Throw") then { + [QGVAR(addToGrenadeTracking), [_projectile]] call CBA_fnc_localEvent; +} else { + [QGVAR(addToProjectileTracking), [_projectile]] call CBA_fnc_localEvent; }; diff --git a/addons/spectator/functions/fnc_ui.sqf b/addons/spectator/functions/fnc_ui.sqf index 8fe9339153..ac8f1fd361 100644 --- a/addons/spectator/functions/fnc_ui.sqf +++ b/addons/spectator/functions/fnc_ui.sqf @@ -103,6 +103,39 @@ if (_init) then { [] call FUNC(ui_updateListEntities); [] call FUNC(ui_updateWidget); }, 5] call CBA_fnc_addPerFrameHandler; + + // register grenade track EH + GVAR(grenadeTrackingEH) = [ + QGVAR(addToGrenadeTracking), { + params [["_projectile", objNull, [objNull]]]; + if (GVAR(drawProjectiles) && {!isNull _projectile}) then { + if (count GVAR(grenadesToDraw) > MAX_GRENADES) then { GVAR(grenadesToDraw) deleteAt 0; }; + GVAR(grenadesToDraw) pushBack _projectile; + }; + } + ] call CBA_fnc_addEventHandler; + + // register projectile track EH + GVAR(projectileTrackingEH) = [ + QGVAR(addToProjectileTracking), { + params [["_projectile", objNull, [objNull]]]; + if (GVAR(drawProjectiles) && {!isNull _projectile}) then { + if (count GVAR(projectilesToDraw) > MAX_PROJECTILES) then { GVAR(projectilesToDraw) deleteAt 0; }; + GVAR(projectilesToDraw) pushBack [_projectile, [[getPosVisual _projectile, [1,0,0,0]]]]; + }; + } + ] call CBA_fnc_addEventHandler; + + // register advanced throwing EH + GVAR(advancedThrowingEH) = [ + QEGVAR(advanced_throwing,throwFiredXEH), { + // Fire time used for unit icon highlighting + (_this select 0) setVariable [QGVAR(highlightTime), time + FIRE_HIGHLIGHT_TIME]; + + // add grenade to tracking + [QGVAR(addToGrenadeTracking), [_this select 6]] CBA_fnc_localEvent; + } + ] call CBA_fnc_addEventHandler; } else { // Stop updating the list and focus widget [GVAR(uiPFH)] call CBA_fnc_removePerFrameHandler; @@ -116,6 +149,18 @@ if (_init) then { [GVAR(collectPFH)] call CBA_fnc_removePerFrameHandler; GVAR(collectPFH) = nil; + // remove advanced throwing EH + [QEGVAR(advanced_throwing,throwFiredXEH), GVAR(advancedThrowingEH)] call CBA_fnc_removeEventHandler; + GVAR(advancedThrowingEH) = nil; + + // remove projectile track EH + [QGVAR(addToProjectileTracking), GVAR(projectileTrackingEH)] call CBA_fnc_removeEventHandler; + GVAR(projectileTrackingEH) = nil; + + // remove grenade track EH + [QGVAR(addToGrenadeTracking), GVAR(grenadeTrackingEH)] call CBA_fnc_removeEventHandler; + GVAR(grenadeTrackingEH) = nil; + // Destroy the display SPEC_DISPLAY closeDisplay 1;