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

#include "cbase.h"
#include "c_rts_globalresource.h"
#include "hl2wars/rts_shareddefs.h"

class C_RTSFogGenerator : public C_BaseEntity
{
public:
	DECLARE_CLASS( C_RTSFogGenerator , C_BaseEntity );
	DECLARE_CLIENTCLASS();

	// Constructor
	C_RTSFogGenerator( void );
	void	UpdateOnRemove();

	virtual void	ReceiveMessage( int classID, bf_read &msg );

private:
	int m_iID;
	float m_fRadius;
	float m_fDelay;
};

IMPLEMENT_CLIENTCLASS_DT( C_RTSFogGenerator, DT_RTSFogGenerator, CRTSFogGenerator )
	RecvPropFloat( RECVINFO( m_fRadius ) ),
	RecvPropFloat( RECVINFO( m_fDelay ) ),
END_RECV_TABLE()

C_RTSFogGenerator::C_RTSFogGenerator()
{
	m_iID = -1;
}

void C_RTSFogGenerator::UpdateOnRemove()
{
	if( g_RTSR && g_RTSR->m_utlFogInfo.IsValidIndex(m_iID) )
	{
		g_RTSR->m_utlFogInfo.Remove( m_iID );
	}

	BaseClass::UpdateOnRemove();
}

void C_RTSFogGenerator::ReceiveMessage( int classID, bf_read &msg )
{
	if ( classID != GetClientClass()->m_ClassID )
	{
		// message is for subclass
		BaseClass::ReceiveMessage( classID, msg );
		return;
	}

	changefogofwar_t update;

	int fogType = msg.ReadByte();
	if( fogType == FOW_CLEAR || fogType == FOW_ADD )
	{
		if( g_RTSR && g_RTSR->m_utlFogInfo.IsValidIndex(m_iID) )
		{
			g_RTSR->m_utlFogInfo.Remove( m_iID );
		}
	}

	update.position = Vector2D( GetAbsOrigin().x, GetAbsOrigin().y );
	update.radius = m_fRadius;
	update.type = fogType;
	update.delay = gpGlobals->curtime + m_fDelay;

	m_iID = g_RTSR->m_utlFogInfo.AddToTail( update );

}