/*
*	Client speed control
*	With special thanks to Adrian "Fireball" LaVallee
*/

#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"

// Removed by Pcjoe
//DECLARE_MESSAGE(m_Speed, Speed);

int CHudSpeed::Init(void)
{	// Removed by Pcjoe
//	HOOK_MESSAGE(Speed);

	// Added by Pcjoe
	m_iSpeed = 0;
	m_iFlags |= HUD_ACTIVE;

	gHUD.AddHudElem(this);

	return 1;
}

void CHudSpeed::SetSpeed( void )
{
	char cmd[50];

	sprintf(cmd, "cl_forwardspeed %d\n", m_iSpeed );
	ClientCmd(cmd);
	sprintf(cmd, "cl_backspeed %d\n", m_iSpeed );
	ClientCmd(cmd);
	sprintf(cmd, "cl_sidespeed %d\n", m_iSpeed );
	ClientCmd(cmd);
	sprintf(cmd, "cl_movespeedkey %f\n", 0.5);
	ClientCmd(cmd);
}

// Added by Pcjoe
void CHudSpeed::Think( void )
{	cl_entity_t *pPlayer = gEngfuncs.GetLocalPlayer();
	if(pPlayer)
	{	if(pPlayer->curstate.fuser1 != m_iSpeed)
		{	m_iSpeed = (int)pPlayer->curstate.fuser1;
			SetSpeed();
		}
	}
}

/* Removed by Pcjoe
int CHudSpeed:: MsgFunc_Speed(const char *pszName,  int iSize, void *pbuf )
{
	BEGIN_READ( pbuf, iSize );
	int x = READ_SHORT();

	SetSpeed(x);

	return 1;
}*/