#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"
#include "const.h"
#include "entity_state.h"
#include "cl_entity.h"
#include "triangleapi.h"

DECLARE_MESSAGE(m_Fog, Fog);

int CHudFog::Init(void)
{	HOOK_MESSAGE(Fog);
	
	gHUD.AddHudElem(this);
	m_iFlags |= HUD_ACTIVE;
	return 1;
}

int CHudFog::Draw(float flTime)
{	
	return 1;
}

int CHudFog::MsgFunc_Fog(const char *pszName, int iSize, void *pbuf)
{	
	BEGIN_READ( pbuf, iSize );
	int iRed = READ_BYTE();
	int iGreen = READ_BYTE();
	int iBlue = READ_BYTE();
	float flFar = (float)READ_SHORT();
	float flNear = (float)READ_SHORT();

	//flFar=<0 indicates no fog
	if(flFar>0)
	{	gEngfuncs.pTriAPI->Fog(Vector(iRed,iGreen,iBlue), flNear, flFar, TRUE ); //Works just like GL_FOG, flFogColor is r/g/b.	
	}
	else
	{	gEngfuncs.pTriAPI->Fog(Vector(iRed,iGreen,iBlue), flNear, flFar, FALSE ); //Works just like GL_FOG, flFogColor is r/g/b.	
	}
	
	return 1;
}