/* ***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/LGPL 2.1/GPL 2.0

The contents of this file are subject to the Mozilla Public License Version 
1.1 (the "License"); you may not use this file except in compliance with
...
for the specific language governing rights and limitations under the
License.

The Original Code is for Luminous Forts.

The Initial Developer of the Original Code is Hekar Khani.
Portions created by the Hekar Khani are Copyright (C) 2010
Hekar Khani. All Rights Reserved.

Contributor(s):
  Hekar Khani <hekark@gmail.com>

Alternatively, the contents of this file may be used under the terms of
either of the GNU General Public License Version 2 or later (the "GPL"),
...
the terms of any one of the MPL, the GPL or the LGPL.

***** END LICENSE BLOCK ***** */


/*===============================================================
	Client
	HUD Element

	Sets a marker on top of players' heads that can be
	seen by teammates

	Last Updated April 1, 2010
=================================================================*/


#include "cbase.h"
#if 0
#include <vgui/ISurface.h>
#include "c_sdk_player.h"
#include "c_team.h"
#include "c_playerresource.h"

#include "ClassicGameRules.h"
#include "Hud_FlagPos.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

//
//	Name: CHudPlayerMarkers
//	Author: Hekar Khani
//	Description: Displays locations of flags on the HUD
//				(as a marker translating from a 3D pos to 2D pos)
//	Notes: 
//
DECLARE_HUDELEMENT( CHudPlayerMarkers );

CHudPlayerMarkers::CHudPlayerMarkers( const char *pElementName ) : 
	CModHudElement( pElementName, HUDELEM_PLAYERMARKER ), BaseClass( NULL, "HudFlagLocations" )
{
	SetHiddenBits( HIDEHUD_HEALTH | HIDEHUD_PLAYERDEAD | HIDEHUD_NEEDSUIT | HIDEHUD_BUILDPHASE );
	vgui::Panel *pParent = g_pClientMode->GetViewport();
	SetParent( pParent );

	SetVisible( true );
	SetEnabled( true );

	m_bNeedsUpdate = false;
}

void CHudPlayerMarkers::Init( void )
{
	m_BlueTexture = NULL;
	m_RedTexture = NULL;
}

bool CHudPlayerMarkers::ShouldDraw()
{
	C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer();
	if ( !pPlayer )
		return false;
	if ( pPlayer->State_Get() != STATE_ACTIVE )
		return false;
	if ( g_pGameRules->GetGameModeMask() & GAMEMODE_CLASSIC )
	{
		if ( ClassicGameRules()->GetCurrentPhaseID() == PHASE_BUILD )
		{
			return false;
		}
	}

	return CModHudElement::ShouldDraw();
}

void CHudPlayerMarkers::ApplySchemeSettings( vgui::IScheme* scheme )
{
	BaseClass::ApplySchemeSettings( scheme );
	SetPaintBackgroundEnabled( false );
	m_hFont = scheme->GetFont( "HudFlagLocations", true );
}

void CHudPlayerMarkers::Paint()
{
	C_SDKPlayer *pLocalPlayer = C_SDKPlayer::GetLocalSDKPlayer();

	if ( !pLocalPlayer )
		return;

	if ( !m_BlueTexture )
	{
		m_BlueTexture = gHUD.GetIcon( "crosshair_default" );
		if ( !m_BlueTexture )
		{
			Warning( "Failed to load flag_maker_blue\n" );
		}
	}

	if ( !m_RedTexture )
	{
		m_RedTexture = gHUD.GetIcon( "crosshair_default" );
		if ( !m_RedTexture )
		{
			Warning( "Failed to load flag_maker_red\n" );
		}
	}

	for ( int teamnumber = SDK_TEAM_BLUE; teamnumber <= SDK_TEAM_RED; teamnumber++ )
	{
	}
}

PrivateMethod bool CHudPlayerMarkers::InView( C_BasePlayer *pLocalPlayer, Vector pos )
{
	// Clip text that is far away
	if ( ( pLocalPlayer->GetAbsOrigin() - pos ).LengthSqr() > 90000000 ) 
	{
		return false;
	}

	// Clip text that is behind the client
	Vector clientForward;
	pLocalPlayer->EyeVectors( &clientForward );

	Vector toText = pos - pLocalPlayer->GetAbsOrigin();
	float  dotPr = DotProduct( clientForward, toText );

	if ( dotPr < 0 ) 
	{
		return false;
	}

	return true;
}

#endif // 0