Skip to content

Commit

Permalink
counter,respawntickets,drawicon for entities
Browse files Browse the repository at this point in the history
OCAP2/OCAP#37
- adds remote-controlled unit detection if firer was >50m away from initial projectile position

OCAP2/OCAP#9
- adds setting for optional BIS_fnc_respawnTickets tracking, will automatically track missionNamespace + faction score counts every 30th frame
- adds system for optional custom score tracking by a set of sides, a custom counter separate from BIS_fnc_respawnTickets

- pending testing of debug drawIcon for units being recorded
  • Loading branch information
indig0fox committed Apr 11, 2022
1 parent e55ac6d commit e5bb87c
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 13 deletions.
14 changes: 14 additions & 0 deletions x/ocap2/addons/recorder/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ GVAR(allSettings) = [
false // requires restart to apply
],

[
QEGVAR(settings,trackTickets),
"CHECKBOX", // setting type
[
"Enable Ticket Tracking", // Pretty name shown inside the ingame settings menu. Can be stringtable entry.
"Will track respawn ticket counts for missionNamespace and each playable faction every 30th frame. Default: true"
],
[COMPONENT_NAME, "Recording Settings"], // Pretty name of the category where the setting can be found. Can be stringtable entry.
true, // default enabled
true, // "_isGlobal" flag. Set this to true to always have this setting synchronized between all clients in multiplayer
{}, // function that will be executed once on mission start and every time the setting is changed.
true // requires restart to apply
],

[
QEGVAR(settings,trackTimes),
"CHECKBOX", // setting type
Expand Down
2 changes: 2 additions & 0 deletions x/ocap2/addons/recorder/XEH_prep.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ PREP(getAmmoMarkerData);
PREP(getWeaponDisplayData);

PREP(projectileMonitors);
PREP(entityMonitors);

PREP(aceThrowing);
PREP(aceExplosives);

Expand Down
28 changes: 28 additions & 0 deletions x/ocap2/addons/recorder/fnc_addEventMission.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,34 @@ if (isNil QEGVAR(listener,customEvent)) then {
OCAPEXTLOG(["Initialized customEvent listener"]);
};

// Custom event handler with key "ocap2_counterInit"
// Used for tracking scores or counts per side
if (isNil QEGVAR(listener,counterInit)) then {
EGVAR(listener,counterInit) = [QGVARMAIN(counterInit), {
EGVAR(counter,sides) = _this apply {_x#0};
[QGVARMAIN(customEvent), ["counterInit", EGVAR(counter,sides)]] call CBA_fnc_localEvent;
{
[QGVARMAIN(counterEvent), _x] call CBA_fnc_serverEvent;
} forEach _this;
[_thisType, _thisId] call CBA_fnc_removeEventHandler;
}] call CBA_fnc_addEventHandlerArgs;
OCAPEXTLOG(["Initialized counterInit listener"]);
};
if (isNil QEGVAR(listener,counterEvent)) then {
EGVAR(listener,counterEvent) = [QGVARMAIN(counterEvent), {
if (isNil QEGVAR(counter,sides)) exitWith {};
if (typeName (_this#0) != "SIDE") exitWith {};
if !((_this#0) in EGVAR(counter,sides)) exitWith {};

private _scores = [];
{
if ((_this#0) isEqualTo _x) then {_scores pushBack (_this#1)} else {_scores pushBack -1};
} forEach EGVAR(counter,sides);
[QGVARMAIN(customEvent), ["counterSet", _scores]] call CBA_fnc_localEvent;
}] call CBA_fnc_addEventHandler;
OCAPEXTLOG(["Initialized counterEvent listener"]);
};

// Custom event handler with key "ocap2_record"
// This will START OR RESUME recording if not already.
if (isNil QEGVAR(listener,record)) then {
Expand Down
21 changes: 15 additions & 6 deletions x/ocap2/addons/recorder/fnc_captureLoop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ GVAR(PFHObject) = [
[] call FUNC(updateTime);
};

// every 15 frames of recording check respawn ticket state of each of three sides
if (GVAR(captureFrameNo) % (30 / GVAR(frameCaptureDelay)) == 0 && EGVAR(settings,trackTickets)) then {
private _scores = [];
{
_scores pushBack ([_x] call BIS_fnc_respawnTickets);
} forEach [missionNamespace, east, west, independent];
["ocap2_customEvent", ["respawnTickets", _scores]] call CBA_fnc_localEvent;
};

// update diary record every 320 frames
if (GVAR(captureFrameNo) % (320 / GVAR(frameCaptureDelay)) == 0) then {
publicVariable QGVAR(captureFrameNo);
Expand All @@ -63,8 +72,8 @@ GVAR(PFHObject) = [
{
if !(_x getVariable [QGVARMAIN(isInitialized), false]) then {
if (_x isKindOf "Logic") exitWith {
_x setVariable [QGVARMAIN(exclude), true];
_x setVariable [QGVARMAIN(isInitialized), true];
_x setVariable [QGVARMAIN(exclude), true, true];
_x setVariable [QGVARMAIN(isInitialized), true, true];
};
_x setVariable [QGVARMAIN(id), GVAR(nextId)];
[":NEW:UNIT:", [
Expand All @@ -78,7 +87,7 @@ GVAR(PFHObject) = [
]] call EFUNC(extension,sendData);
[_x] spawn FUNC(addUnitEventHandlers);
GVAR(nextId) = GVAR(nextId) + 1;
_x setVariable [QGVARMAIN(isInitialized), true];
_x setVariable [QGVARMAIN(isInitialized), true, true];
};
if !(_x getVariable [QGVARMAIN(exclude), false]) then {
private _unitRole = _x getVariable [QGVARMAIN(unitType), ""];
Expand Down Expand Up @@ -126,8 +135,8 @@ GVAR(PFHObject) = [
};
if ((_class isEqualTo "unknown") || (_vehType in (parseSimpleArray EGVAR(settings,excludeClassFromRecord))) || _toExcludeKind) exitWith {
LOG(ARR2("WARNING: vehicle is defined as 'unknown' or exclude:", _vehType));
_x setVariable [QGVARMAIN(isInitialized), true];
_x setVariable [QGVARMAIN(exclude), true];
_x setVariable [QGVARMAIN(isInitialized), true, true];
_x setVariable [QGVARMAIN(exclude), true, true];
};

_x setVariable [QGVARMAIN(id), GVAR(nextId)];
Expand All @@ -139,7 +148,7 @@ GVAR(PFHObject) = [
]] call EFUNC(extension,sendData);
[_x] spawn FUNC(addUnitEventHandlers);
GVAR(nextId) = GVAR(nextId) + 1;
_x setVariable [QGVARMAIN(isInitialized), true];
_x setVariable [QGVARMAIN(isInitialized), true, true];
};
if !(_x getVariable [QGVARMAIN(exclude), false]) then {
private _crew = [];
Expand Down
16 changes: 9 additions & 7 deletions x/ocap2/addons/recorder/fnc_eh_firedMan.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ if (!SHOULDSAVEEVENTS) exitWith {};

params ["_firer", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_vehicle"];

private "_who";
{
if (_firer == _x getVariable ["BIS_fnc_moduleRemoteControl_owner", objNull]) then {
_who = _x;
};
} forEach (allUnits select {!isNull (_firer getVariable ["BIS_fnc_moduleRemoteControl_owner", objNull])});
if (!isNil "_who") then {_firer = _who};
private _initialProjPos = getPos _projectile;
if (getPos _firer distance _initialProjPos > 50) then {
// if projectile in unscheduled environment is > 50m from FiredMan then likely remote controlled
// we should find the actual firing entity
_nearest = [_initialProjPos, allUnits select {!isPlayer _x}, 5] call CBA_fnc_getNearest;
_firer = _nearest#0;
};
// missionNamespace getVariable ["bis_fnc_moduleRemoteControl_unit", _firer];
// _unit getVariable ["BIS_fnc_moduleRemoteControl_owner", objNull];

// not sent in ACE Throwing events
if (isNil "_vehicle") then {_vehicle = objNull};
Expand Down
36 changes: 36 additions & 0 deletions x/ocap2/addons/recorder/fnc_entityMonitors.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "script_component.hpp"

// DEBUG draws on clients
{
if (!hasInterface) exitWith {};
[] spawn {
waitUntil {!isNull (findDisplay 12)};
GVAR(liveDebugBullets) = [];
disableSerialization;
(findDisplay 12 displayCtrl 51) ctrlAddEventHandler ["Draw", {
if (GVARMAIN(isDebug)) then {
{
// _x params ["_startPos", "_endPos", "_color", "_timeHit"];
(_this#0) drawIcon [
["iconMan"] call BIS_fnc_textureVehicleIcon, // Custom images can also be used: getMissionPath "\myFolder\myIcon.paa"
[side group _x] call BIS_fnc_sideColor,
getPos _x,
1,
1,
getDir _x,
name _x,
0,
0.03,
"PuristaLight",
"center"
];
} forEach (allUnits + vehicles) select {
_x getVariable [QGVARMAIN(isInitialized), false] &&
_x getVariable [QGVARMAIN(exclude), true]
};
};
}];
};
} remoteExec ["call", [0, -2] select isDedicated, true];

GVAR(entityMonitorsInitialized) = true;
4 changes: 4 additions & 0 deletions x/ocap2/addons/recorder/fnc_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,7 @@ if (GVAR(missionName) == "") then {
if (isNil QGVAR(projectileMonitorsInitialized)) then {
call FUNC(projectileMonitors);
};

if (isNil QGVAR(entityMonitorsInitialized)) then {
call FUNC(entityMonitors);
};

0 comments on commit e5bb87c

Please sign in to comment.