/*

milsim_triageIcons_fnc_draw3D

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"

if (!hasInterface) exitWith {};


// adds codeblock to common array to be processed per frame
private _code = {
	// if disabled, skip processing
	if (!GVAR(setting_enabled)) 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;
	
		// 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
		];
		
		true;
	} count (
		(localNamespace getVariable [QEGVAR(client,nearMen), []]) select {
			// is unconscious and is NOT in vehicle and is within draw range
			(_x getVariable ["ACE_isUnconscious", false]) &&
			isNull (objectParent _x) &&
			player distance _x <= GVAR(setting_drawRange)
		}
	);
};

// add codeblock to common array
[_code] call EFUNC(client,registerPFHCode);