Skip to content
Merged
Changes from all commits
Commits
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
64 changes: 27 additions & 37 deletions addons/recorder/fnc_aceExplosives.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FUNCTION: OCAP_recorder_fnc_aceExplosives

Description:
Adds marker on the mine's position to the recording timeline.
Then waits until the explosive is null (exploded) and indicates it with a 10-frame long red X before removing the marker.
Uses Explode event handler to detect detonation and indicates it with a 10-frame long red X before removing the marker.

Called by <ace_explosives_place> CBA listener.

Expand All @@ -32,83 +32,73 @@ Author:

if (!SHOULDSAVEEVENTS) exitWith {};

// TODO: Rework this to use projectile event handlers

params ["_explosive", "_dir", "_pitch", "_unit"];

private _int = random(2000);

_explType = typeOf _explosive;
_explosiveMag = getText(configFile >> "CfgAmmo" >> _explType >> "defaultMagazine");
_explosiveDisp = getText(configFile >> "CfgMagazines" >> _explosiveMag >> "displayName");
_explosivePic = getText(configFile >> "CfgMagazines" >> _explosiveMag >> "picture");
private _explType = typeOf _explosive;
private _explosiveMag = getText(configFile >> "CfgAmmo" >> _explType >> "defaultMagazine");
private _explosiveDisp = getText(configFile >> "CfgMagazines" >> _explosiveMag >> "displayName");
private _explosivePic = getText(configFile >> "CfgMagazines" >> _explosiveMag >> "picture");

_placedPos = getPosASL _explosive;
private _placedPos = getPosASL _explosive;
_unit addOwnedMine _explosive;

_markTextLocal = format["%1", _explosiveDisp];
_markName = format["%1#%2/%3", QGVARMAIN(mine), _int, _placedPos];
_markColor = "ColorRed";
_markerType = "Minefield";

private _markTextLocal = format["%1", _explosiveDisp];
private _markName = format["%1#%2/%3", QGVARMAIN(mine), _int, _placedPos];

// Signals creation of a Minefield (triangle) marker on the timeline at the location the explosive was armed.
[QGVARMAIN(handleMarker), [
"CREATED", _markName, _unit, _placedPos, _markerType, "ICON", [1,1], 0, "Solid", "ColorRed", 1, _markTextLocal, true
"CREATED", _markName, _unit, _placedPos, "Minefield", "ICON", [1,1], 0, "Solid", "ColorRed", 1, _markTextLocal, true
]] call CBA_fnc_localEvent;

if (GVARMAIN(isDebug)) then {
// add to map draw array
private _debugArr = [_explosive, _explosivePic, format["%1 %2 - %3", str side group _unit, name _unit, _markTextLocal], [side group _unit] call BIS_fnc_sideColor];
GVAR(liveDebugMagIcons) pushBack _debugArr;
publicVariable QGVAR(liveDebugMagIcons);
};

// Use Explode event handler instead of polling for null
_explosive addEventHandler ["Explode", {
params ["_explosive", "_damage", "_source", "_instigator"];

[{isNull (_this#0)}, { // wait until the mine is null (exploded), and mark this for playback
private _data = _explosive getVariable [QGVAR(explosiveData), []];
if (_data isEqualTo []) exitWith {};

params ["_explosive", "_explosiveDisp", "_unit", "_placedPos", "_markName", "_int"];
_data params ["_explosiveDisp", "_unit", "_placedPos", "_markName", "_int"];

// set unit who placed's lastFired var as the explosive so kills are registered to the explosive
_unit setVariable [
QGVARMAIN(lastFired),
_explosiveDisp
];
// Set unit who placed's lastFired var as the explosive so kills are registered to the explosive
_unit setVariable [QGVARMAIN(lastFired), _explosiveDisp];

// remove previous marker
if (GVARMAIN(isDebug)) then {
format["Removed explosive placed marker, %1, %2", _markName, _explosiveDisp] SYSCHAT;
OCAPEXTLOG(ARR3("Removed explosive placed marker",_markName,_explosiveDisp));
};


// Signals removal of the Minefield (triangle) marker when the explosive is null (exploded).
// Signals removal of the Minefield (triangle) marker when the explosive detonates
[QGVARMAIN(handleMarker), ["DELETED", _markName]] call CBA_fnc_localEvent;

_markTextLocal = format["%1", _explosiveDisp];
_markName = format["Detonation#%1", _int];
_markColor = "ColorRed";
_markerType = "waypoint";
private _detonationMarkName = format["Detonation#%1", _int];

if (GVARMAIN(isDebug)) then {
format["Created explosive explosion marker, %1, %2", _markName, _explosiveDisp] SYSCHAT;
OCAPEXTLOG(ARR3("Created explosive explosion marker",_markName,_explosiveDisp));
format["Created explosive explosion marker, %1, %2", _detonationMarkName, _explosiveDisp] SYSCHAT;
OCAPEXTLOG(ARR3("Created explosive explosion marker",_detonationMarkName,_explosiveDisp));
};


// Signals creation of a Waypoint (X) marker on the timeline at the location the explosive detonated.
// Signals creation of a Waypoint (X) marker on the timeline at the location the explosive detonated
[QGVARMAIN(handleMarker), [
"CREATED", _markName, _unit, _placedPos, _markerType, "ICON", [1,1], 0, "Solid", "ColorRed", 1, _markTextLocal, true
"CREATED", _detonationMarkName, _unit, _placedPos, "waypoint", "ICON", [1,1], 0, "Solid", "ColorRed", 1, format["%1", _explosiveDisp], true
]] call CBA_fnc_localEvent;


[{
params ["_markName", "_explosiveDisp"];
if (GVARMAIN(isDebug)) then {
format["Removed explosive explosion marker, %1, %2", _markName, _explosiveDisp] SYSCHAT;
OCAPEXTLOG(ARR3("Removed explosive explosion marker",_markName,_explosiveDisp));
};
[QGVARMAIN(handleMarker), ["DELETED", _markName]] call CBA_fnc_localEvent;
}, [_markName, _explosiveDisp], GVAR(captureFrameNo) * 10] call CBA_fnc_waitAndExecute;
}, [_detonationMarkName, _explosiveDisp], GVAR(captureFrameNo) * 10] call CBA_fnc_waitAndExecute;
}];

}, [_explosive, _explosiveDisp, _unit, _placedPos, _markName, _int]] call CBA_fnc_waitUntilAndExecute;
// Store data on the explosive for retrieval in the event handler
_explosive setVariable [QGVAR(explosiveData), [_explosiveDisp, _unit, _placedPos, _markName, _int]];
Loading