//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//
//=============================================================================//
#if !defined( C_HL2WARS_PLAYER_H )
#define C_HL2WARS_PLAYER_H
#ifdef _WIN32
#pragma once
#endif

class C_HL2Wars_Player;
class C_BuildingBrush;

#include "c_basehlplayer.h"
#include "hl2wars/rts_shareddefs.h"
#include "vgui/mousecode.h"
#include "hl2wars/c_rts_playerlocaldata.h"

/*#ifdef HL2MP
	#include "c_hl2mp_player.h"
#endif*/

namespace vgui 
{

class Panel;

}

//=============================================================================
// >> HL2Wars_Player
//=============================================================================
class C_HL2Wars_Player : public C_BaseHLPlayer
{
public:
	DECLARE_CLASS( C_HL2Wars_Player, C_BaseHLPlayer );

	DECLARE_CLIENTCLASS();
	DECLARE_PREDICTABLE();
	//DECLARE_INTERPOLATION();

	C_HL2Wars_Player();
	~C_HL2Wars_Player( void );

	void ClientThink( void );

	void UpdateSelected();

	// prediction
	void ClearSelection();
	void AddToSelection( C_AI_BaseNPC *pNPC );

	static C_HL2Wars_Player* GetLocalHL2WarsPlayer();

	bool IsPlayerInRTSMode( void ) { return m_Local.m_bRTSMode; };
	bool CreateMove( float flInputSampleTime, CUserCmd *pCmd );
	int *GetRTSCommands( void ) { return &m_nNewRTSCommands; };
	int *GetRTSCommands2( void ) { return &m_nNewRTSCommands2; };
	int GetLevelRTS( void ) { return m_HLWLocal.m_iLevelRTS; };

	int GetSlot( void ) { return m_iSlot; }		// gameroom specific

	void ClearLeftPressed();
	void ClearRightPressed();

	bool IsActivePanel( vgui::Panel *panel );
	bool ReleaseActivePanel( vgui::MouseCode code );
	void SetActivePanel( vgui::Panel *panel);

	// selection management
	int GetSelectionType();
	int GetHighLightedUnit();
	int GetSelectedAbility();
	CBaseEntity *GetSelectedBuilding();

	// direct move
	void SetDirectMove( Vector position );
	void InvalidateDirectMove();
	bool IsDirectMoveValid();
	Vector GetDirectMovePosition();

	// mouse postion updating
	void UpdatePressedPosition();
	void UpdateReleasedPosition();
	void UpdateCurPosition();

	Vector GetPressedPosition() { return m_vPressedPosition; }
	Vector GetPressedNormal() { return m_vPressedNormal; }
	Vector GetReleasedPosition() { return m_vReleasedPosition; }
	Vector GetReleasedNormal() { return m_vReleasedNormal; }
	Vector GetCurPosition() { return m_vCurPosition; }
	Vector GetCurNormal() { return m_vCurNormal; }

private:	// rts data
	int m_nNewRTSCommands;
	int m_nNewRTSCommands2;

	// mouse stuff
	vgui::Panel				*m_pActivePanel;

	int						m_iSlot;			// gameroom specific

	// selection, for comparing changes.
	CHandle<C_AI_BaseNPC>	m_hSelectedUnitsOld[MAXSELECTED];
	EHANDLE					m_pSelectionBOld;

public:
	C_HLWPlayerLocalData		m_HLWLocal;		// our local data

	float m_fScrollBackwardsTimeOut;
	float m_fScrollForwardTimeOut;

	// button/mouse stuff
	Vector					m_vecPickingRayMouse;

	int						m_iMouse_x_pressed_left;
	int						m_iMouse_y_pressed_left;
	int						m_iMouse_x_pressed_right;
	int						m_iMouse_y_pressed_right;

public:
	// the the buttonstate for the cmd
	int m_nMouseButtons;

private:
	bool m_bDirectMove;
	Vector m_vDirectMove;

private:
	Vector m_vPressedPosition;
	Vector m_vPressedNormal;
	Vector m_vReleasedPosition;
	Vector m_vReleasedNormal;
	Vector m_vCurPosition;
	Vector m_vCurNormal;
};

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
inline bool C_HL2Wars_Player::IsActivePanel( vgui::Panel *panel )
{
	return ( m_pActivePanel == panel );
}

// selection management
inline int C_HL2Wars_Player::GetSelectionType() 
{ 
	return m_HLWLocal.m_iSelectionType; 
}
inline int C_HL2Wars_Player::GetHighLightedUnit() 
{ 
	return m_HLWLocal.m_iHighLightedUnit; 
}
inline int C_HL2Wars_Player::GetSelectedAbility() 
{ 
	return m_HLWLocal.m_iSelectedAbility; 
}
inline CBaseEntity *C_HL2Wars_Player::GetSelectedBuilding() 
{ 
	return m_HLWLocal.m_hSelected.Get(); 
}

// direct move
inline bool C_HL2Wars_Player::IsDirectMoveValid() 
{ 
	return m_bDirectMove; 
}

inline Vector C_HL2Wars_Player::GetDirectMovePosition() 
{ 
	return m_vDirectMove; 

}

inline C_HL2Wars_Player *ToHL2WarsPlayer( CBaseEntity *pEntity )
{
	if ( !pEntity || !pEntity->IsPlayer() )
		return NULL;

	return dynamic_cast<C_HL2Wars_Player*>( pEntity );
}

#endif //C_HL2WARS_PLAYER_H
	