#include "hud.h"
#include "parsemsg.h"
#include "cl_util.h"
#include "const.h"
#include "pm_shared.h"
#include "pmtrace.h"
#include "pm_defs.h"
#include "event_api.h"
// Added by Pcjoe
#include "transformfx.h"

DECLARE_MESSAGE(m_ChargeSpiritBomb, ChargeSB);
DECLARE_MESSAGE(m_ChargeSpiritBomb, StopChSB);
HSPRITE m_hsprSBCharge;

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

int CHudChargeSpiritBomb::VidInit(void)
{	m_hsprSBCharge = LoadSprite("sprites/spiritbombcharge.spr");
	return 1;
}

int CHudChargeSpiritBomb::Draw( float flTime )
{
	m_flTime = flTime;
	return 1;
}

int CHudChargeSpiritBomb::MsgFunc_ChargeSB(const char *pszName,  int iSize, void *pbuf )
{	BEGIN_READ( pbuf, iSize );
	vec3_t vecOrigin;
	vecOrigin.x = READ_COORD();
	vecOrigin.y = READ_COORD();
	vecOrigin.z = READ_COORD();
	short entindex = READ_SHORT();

	/* modified by harSens, so it doesn't use new/delete
	// Lets create a temp event, just to use for creating a FX element
	trans_event *pNewEvent = new trans_event;
	if(!pNewEvent)
	{	ConsolePrint("Error, could not allocate space!\n");
		return 1;
	}
	pNewEvent->iFlag = SPIRIT_BOMB;
	pNewEvent->flTimeStart = m_flTime;
	pNewEvent->flTimeEnd = -1;
	pNewEvent->iIndex = entindex;
	pNewEvent->pNext = NULL;

	// Lets emit some shockwaves :-)
	gHUD.m_TransformFX.Partsys.CreateParticleSystem( 200, vecOrigin, pNewEvent );
	
	// We are done with the temp event, we can delete it now
	delete pNewEvent;
	pNewEvent = NULL;
	*/
	// Lets create a temp event, just to use for creating a FX element
	trans_event pNewEvent;
	pNewEvent.iFlag = SPIRIT_BOMB;
	pNewEvent.flTimeStart = m_flTime;
	pNewEvent.flTimeEnd = -1;
	pNewEvent.iIndex = entindex;
	pNewEvent.pNext = NULL;

	// Lets emit some shockwaves :-)

	/*	HARSENS: hm... isn't m_TransformFX a rather strange name 
		for a particle/event system? Oh well, i guess that's just a
		matter of design...
	*/
	gHUD.m_TransformFX.Partsys.CreateParticleSystem( 200, vecOrigin, &pNewEvent );
	
	return 1;
}

int CHudChargeSpiritBomb::MsgFunc_StopChSB(const char *pszName,  int iSize, void *pbuf )
{	BEGIN_READ( pbuf, iSize );
	short entindex = READ_SHORT();
	int iType = SPIRIT_BOMB;
	gHUD.m_TransformFX.Partsys.SearchAndDelete( iType, entindex );
	return 1;
}