/*

milsim_fnc_addMedicalOverlayPFH

Author: IndigoFox

Description:
    Affects players with medical permissions. Will see a 3D colored dot over nearby (5-10m)
	unconscious players who are not in a vehicle
	which indicates their current ACE Triage Card status.
	Designed to increase efficiency of CCPs.

*/

#include "..\script_component.hpp"


// Per-frame handler to draw icons
// cleanup
if (!isNil QGVAR(drawIconsPfh)) then {
	[GVAR(drawIconsPfh)] call CBA_fnc_removePerFrameHandler;
};
// add pfh
GVAR(drawIconsPfh) = [{
	// if disabled, skip processing
	if (!GVAR(setting_enabled)) exitWith {false};
	// if no targets, skip processing
	if (count GVAR(drawTargets) == 0) exitWith {false};
	// if the player doesn't have medical perms, skip processing
	if !([player] call ace_medical_treatment_fnc_isMedic) exitWith {false};
	{
		private _unit = _x;
		// distance within X meters
		if (player distance _unit > GVAR(setting_drawRange)) then {continue};
		// check unit not null, not conscious, and not in a vehicle
		if (
			!(_unit getVariable ["ACE_isUnconscious", false]) ||
			!isNull (objectParent _unit)
		) then {continue};

		// color based on triage level
		private _triageLevel = _unit getVariable ["ace_medical_triageLevel", 4];
		if (_triageLevel == -1) then {continue};
		private _color = GVAR(colors) select (_triageLevel - 1);
		_color set [3, 0.9]; // set alpha
		// draw position, slightly above the prone unit
		private _drawPos = (visiblePosition _unit) vectorAdd [0, 0, 0.5];
		// draw icon
		drawIcon3D [
			"\A3\ui_f\data\map\markers\military\dot_CA.paa", // icon texture
			_color, // color
			_drawPos, // position AGL
			1, // width
			1, // height
			0, // angle
			"", // text
			true // outline
			// further params optional, omitted
		];
	} forEach GVAR(drawTargets);
}, 0, []] call CBA_fnc_addPerFrameHandler;

