ScriptName "";

PRIVATE ["_unit","_markerziel","_typename","_fcDialog","_mapCtrl","_mapFocus","_cannon","_cannonvar","_cannonvarz","_cannonvarx","_cannonvary","_unitdir","_unitpos","_Rakettetyp"];
disableSerialization;
_unit =_this select 0;
_range=3000;
_typename = gettext(configFile >> "CfgVehicles" >> (typeof (vehicle _unit)) >> "displayName");
x=0;
y=0;
if (_unit iskindOf "MLRS") then
	{
      _cannon= "MLRS";
      _Rakettetyp= "R_MLRS";
      _markerziel = createMarkerLocal [format["ziel%1",west],[0,0]];
	_markerziel setMarkerTypeLocal "selector_selectedMission";
	_markerziel setMarkerColorLocal "Colorblue";
	_markerziel setMarkerSizeLocal [0.8, 0.8];
	_markerziel setmarkertextlocal format ["%1 (%2)",name player,_typename];
      };
      
if (_unit iskindOf "GRAD_RU") then
	{
      _cannon= "GRAD";
      _Rakettetyp= "R_GRAD";
      _markerziel = createMarkerLocal [format["ziel%1",east],[0,0]];
	_markerziel setMarkerTypeLocal "selector_selectedMission";
	_markerziel setMarkerColorLocal "Colorblue";
	_markerziel setMarkerSizeLocal [0.8, 0.8];
	_markerziel setmarkertextlocal format ["%1 (%2)",name player,_typename];
      };           
_unit addeventHandler ["Fired", {_this execVM "RaketeM270GARD.sqf"}];
while {Player in _unit} do
	{
	waitUntil {sleep 0.4;((Player == Gunner _unit) || !(Player in _unit))};	 
	1 cutRsc ["ALRscArtyDialog", "plain"];
	_fcDialog = uiNamespace getVariable "RakArtyDisplay";
	_mapCtrl = _fcDialog displayCtrl 81002;
	_txtElev = _fcDialog displayCtrl 81003;
	_txtAzi = _fcDialog displayCtrl  81004;	
	while {Player == Gunner _unit} do
	 	{ 
		_cannonvar =_unit weaponDirection _cannon;
		_cannonvarz =_cannonvar select 2;
		_cannonvarx =_cannonvar select 0;
		_cannonvary =_cannonvar select 1;
		_unitdir=(360-(Deg (_unit AnimationPhase "mainturret")));
		_unitpos=getpos _unit;
		z=_cannonvarz;
		_z=100+(_cannonvarz*_range);
		x=((_unitpos select 0)-_z*sin(_unitdir));
		y=((_unitpos select 1)-_z*cos(_unitdir));
		_markerziel setmarkerposlocal [x,y];
		_txtElev ctrlSetText format ["%1",x];
        	_txtAzi ctrlSetText format ["%1",y];
		_mapFocus=[x,y];
		_mapCtrl ctrlMapAnimAdd [0.1, 0.1, _mapFocus];
        	ctrlMapAnimCommit _mapCtrl;
        	sleep 0.1;
        	ctrlMapAnimClear _mapCtrl;
		//player sidechat format["x:%1 y:%2 z:%3",x,y,z];	
		};
	sleep 0.1;
	_fcDialog closeDisplay 0;	
	};
_unit removeAllEventHandlers "Fired";   	
deleteMarkerLocal _markerziel; 			