//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#ifndef CHUDTRACEFIlTERRTS_H
#define CHUDTRACEFIlTERRTS_H

#include "cbase.h"

#include "engine/IEngineTrace.h"
//#include "util_shared.cpp"
#include "hl2wars/util_hl2wars_shared.h"

#ifndef CLIENT_DLL
	#include "hl2wars/rts_client_brush.h"
	#include "hl2wars/hl2wars_player.h"
#else
	#include "hl2wars/c_rts_client_brush.h"
	#include "hl2wars/c_hl2wars_player.h"
#endif

class CTraceFilterRTS : public CTraceFilter
{
public:
	// It does have a base, but we'll never network anything below here..
	DECLARE_CLASS_NOBASE( CTraceFilterRTS );

	CTraceFilterRTS( const CBaseEntity *pEntity ) { m_pIgnore = pEntity; }

	virtual bool ShouldHitEntity( IHandleEntity *pHandleEntity, int contentsMask )
	{
		#ifndef CLIENT_DLL
			CBaseEntity *pEntity = EntityFromEntityHandle( pHandleEntity );
			//CBaseEntity *pEntity = gEntList.GetBaseEntity( pHandleEntity->GetRefEHandle() );
			//Msg("Filtering entity %s\n", pEntity->GetClassName() );
		#else
			C_BaseEntity *pEntity = EntityFromEntityHandle( pHandleEntity );
		#endif

		//if ( !StandardFilterRules( pHandleEntity, contentsMask ) )
		//	return false;

		if ( m_pIgnore )
		{
			if ( !PassServerEntityFilter( pHandleEntity, m_pIgnore ) )
			{
				return false;
			}
		}
		
		if ( UTIL_IsRTSClientBrush( pEntity ) ) {
			if( m_pIgnore->IsPlayer() ) {
				#ifndef CLIENT_DLL
					const CHL2Wars_Player *pPlayer = (CHL2Wars_Player *)m_pIgnore;
				#else
					const C_HL2Wars_Player *pPlayer = (C_HL2Wars_Player *)m_pIgnore;
				#endif

				m_iLevelPlayerRTS = pPlayer->m_HLWLocal.m_iLevelRTS;
			}
			else 
				m_iLevelPlayerRTS = 100;

			#ifndef CLIENT_DLL
				CRTSClientBrush *pRTSClientBrush = dynamic_cast<CRTSClientBrush *>(pEntity);
				if( pRTSClientBrush->GetLevel() > m_iLevelPlayerRTS ) {
					return false;
				}
			#else
				C_RTSClientBrush *pRTSClientBrush = dynamic_cast<C_RTSClientBrush *>(pEntity);
				if( pRTSClientBrush->GetLevel() > m_iLevelPlayerRTS ) {
					return false;
				}
			#endif
		}
		
		return true;
	}
private:
	int m_iLevelPlayerRTS;
	const CBaseEntity		*m_pIgnore;
};

#endif  // CHUDTRACEFIlTERRTS_H