//=========================================================================================
// Project : UT2004 HackBase
// Version : 1.0
// Coder   : CheatatOr
// Website : http://cT.cheatz.to
//
// File    : cRadar.cpp
// ++      : The radar class with 3D Radar, 2D Radar and Healthbars
// Credits : Please read the readme.html for getting the credits
//=========================================================================================

#include "hook.h"
#include "cRadar.h"

cRadar::cRadar(){
};
cRadar::~cRadar(){
};

//=====================================================================================
// Healthbar drawing:
//=====================================================================================

void cRadar::DrawHealthBar (UCanvas* Canvas, float PosX, float PosY, int Health)
{
	Canvas->pCanvasUtil->DrawTile(PosX - 20, PosY - 20, PosX + 20, PosY - 14,0.0,0.0,92.0,92.0,0.0,Global::WhiteTex,ColorBlack);
	Canvas->pCanvasUtil->DrawTile(PosX - 19, PosY - 19, PosX + 19, PosY - 15,0.0,0.0,92.0,92.0,0.0,Global::WhiteTex,ColorDarkGrey);

	int Tmp = Min(int(Health * 2.55), 255);
	Canvas->DrawColor = FColor(255 - Tmp,Tmp,0, 200);
	Tmp = Min(int(Health * 0.38), 38);

	Canvas->pCanvasUtil->DrawTile(PosX - 19, PosY - 19, PosX - 19 + Tmp, PosY - 15,0.0,0.0,92.0,92.0,0.0,Global::WhiteTex,Canvas->DrawColor);
}

//=====================================================================================
// Bounding Box drawing by r00t aka Daru:
//=====================================================================================

void cRadar::DrawBoundingBox (UCanvas* Canvas,APawn* Target)
{
	FVector X,Y,Z,D,E,top,bottom;;
	float width, Left, Right, Top, Bot;

	GetAxes(Global::MyCameraRotation,X,Y,Z);

	D = Target->Location - Global::MyCameraLocation;
	E = D /= D.Size();

	if(Dot(E,X) <= cos(90 * PI / 180))
		return;

	top = Target->Location;
	top.Z += Target->CollisionHeight;
	top = WorldToScreen(Canvas,top);

	bottom = Target->Location;
	bottom.Z -= Target->CollisionHeight;
	bottom = WorldToScreen(Canvas,bottom);

	width = ((top.Y - bottom.Y) / 4);

	Left  = top.X + width;
	Right = top.X - width;
	Top   = top.Y;
	Bot   = bottom.Y;

	Target->bNoTeamBeacon = 1;
	Canvas->pCanvasUtil->DrawLine(Left,  Top, Left,  Bot, Canvas->DrawColor);
	Canvas->pCanvasUtil->DrawLine(Left,  Bot, Right, Bot, Canvas->DrawColor);
	Canvas->pCanvasUtil->DrawLine(Right, Bot, Right, Top, Canvas->DrawColor);
	Canvas->pCanvasUtil->DrawLine(Right, Top, Left,  Top, Canvas->DrawColor);
	Canvas->pCanvasUtil->DrawLine(Top, Top, Top,  Top, Canvas->DrawColor);

	FVector F = Target->Location - Global::MyCameraLocation;
	static TCHAR StrTemp[MAX_PATH];

	appSprintf(StrTemp,L"%s",Target->PlayerReplicationInfo->PlayerName);
	DrawShadowedText(Canvas,StrTemp,Right + 3,Top,Canvas->DrawColor);

	appSprintf(StrTemp,L"H:%d",Target->Health);
	DrawShadowedText(Canvas,StrTemp,Right + 3,Top + 8,Canvas->DrawColor);

	appSprintf(StrTemp, TEXT("D:%.0f"),F.Size() / 48);
	DrawShadowedText(Canvas,StrTemp,Right + 3,Top + 16,Canvas->DrawColor);

	if (Global::bHealthbars)
	{
		DrawHealthBar(Canvas, top.X, Top + 10, Target->Health);
	}
}

//=====================================================================================
// 2D Radar background box drawing:
//=====================================================================================

void cRadar::Draw2DRadarBox (UCanvas* Canvas)
{
	//Box
	Draw(Canvas,Global::RadarPosX + 2, Global::RadarPosY + 12, Global::RadarWidth - 3, Global::RadarHeight - 2, ColorBlack);
	Draw(Canvas,Global::RadarPosX + 2, Global::RadarPosY + 12, Global::RadarWidth - 3, Global::RadarHeight - 3, FColor(20,20,20,255)); 
	Draw(Canvas,Global::RadarPosX + 7, Global::RadarPosY + 17, Global::RadarWidth - 14, Global::RadarHeight - 13, ColorBlack); 
	Draw(Canvas,Global::RadarPosX + 8, Global::RadarPosY + 18, Global::RadarWidth - 16, Global::RadarHeight - 15, ColorBlack);

	//Cross
	Draw(Canvas,Global::RadarPosX + Global::RadarWidth / 2 + 2, Global::RadarPosY + 18, 1, Global::RadarHeight - 15, ColorDarkGrey);
	Draw(Canvas,Global::RadarPosX + 8, Global::RadarPosY + Global::RadarHeight / 2 + 12, Global::RadarWidth - 16, 1, ColorDarkGrey);  
}

//=====================================================================================
// 2D Radar player drawing:
//=====================================================================================

void cRadar::DrawPlayer2DRadar (UCanvas* Canvas, APawn* Target)
{
	FVector X,Y,Z,D;
	FRotator R	= Global::MyCameraRotation + FRotator(0,16384,0);
	R.Roll		= 0;
	R.Pitch		= 0;
	GetAxes(R, X, Y, Z);
	D = (Target->Location - Global::MyCameraLocation);
	D.Z = 0;

	int origPosX = Global::RadarPosX + Global::RadarWidth / 2 + 2, 
		origPosY = Global::RadarPosY + Global::RadarHeight / 2 + 12;

	int PosX = origPosX + Dot(D, X) / ((Global::RadarDistance * 48) / 60),
	    PosY = origPosY + Dot(D, Y) / ((Global::RadarDistance * 48) / 60);

	if (PosX < Global::RadarPosX + 7)
		PosX = Global::RadarPosX + 7;
	if (PosX > Global::RadarPosX + Global::RadarWidth - 10)
		PosX = Global::RadarPosX + Global::RadarWidth - 10;
	if (PosY < Global::RadarPosY + 16)
		PosY = Global::RadarPosY + 16;
	if (PosY > Global::RadarPosY + Global::RadarHeight)
		PosY = Global::RadarPosY + Global::RadarHeight;

	Draw(Canvas, PosX, PosY, 4, 4, ColorBlack);
	Draw(Canvas, PosX + 1, PosY + 1, 2, 2, Canvas->DrawColor);
}
