#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "effects.h"
#include "aura.h"
#include "classes.h"
#include "magicattack.h"
#include "explodingattack.h"
#include "player.h"
#include "gamerules.h"
#include "magicattack.h"
#include "explodingattack.h"
#include "beamattack.h"
#include "guidedattack.h"
#include "controlledbeam.h"

/**
 * Mouthblast Weapon
 * @version redo: 13-7-2001
 * @author Herwin 'harSens' van Welbergen
 */
class CMouthblast:public CControlledBeam
{	
public:
	/**
	 * Init function
	 */
	void Spawn( void );

	/**
	 * Precaches sprites and sounds
	 */
	void Precache( void );

	/**
	 * Get mouthblast slot
	 * return int: the slot, is 4 for mouthblast
	 */
	int iItemSlot( void ) { return 4; }

	/**
	 * Get mouthblast item info
	 * @param ItemInfo *p: The ItemInfo gets stored here
	 * @return int: Always returns 1 (why???)
	 */
	int GetItemInfo(ItemInfo *p);

private:
	CSprite *m_pChargeSprite;		//the sprites wich appears after charging
	
	/**
	 * Emits charge sound
	 */
	virtual void EmitChargeSound();

	/**
	 * Emits shoot sound
	 */
	virtual void EmitShootSound();

	/**
	 * Inits charge sprite
	 */
	virtual void InitChargeSprite();

	/**
	 * Enable charge sprite
	 */
	virtual void EnableChargeSprite(){m_pChargeSprite->SetScale(0.015);m_pChargeSprite->TurnOn();};

	/**
	 * Disable charge sprite
	 */
	virtual void DisableChargeSprite(){m_pChargeSprite->TurnOff();};

	/**
	 * Grow charge sprite
	 */
	virtual void GrowChargeSprite(){m_pChargeSprite->SetScale((float)m_iCharge * 0.015);};

	/**
	 * Remove charge sprite
	 */
	virtual void RemoveChargeSprite(){UTIL_Remove(m_pChargeSprite);};
};

LINK_ENTITY_TO_CLASS( weapon_mouthblast, CMouthblast );

void CMouthblast::Spawn( void )
{	Precache();
	m_eAttackState = ATTACK_IDLE; //not firing
	m_iCharge = 0;
	m_pMagic = NULL;
	m_iId = WEAPON_MOUTHBLAST;
	m_iDefaultAmmo = 0;
	m_iClip = -1;	

	m_iMaxCharge = MOUTHBLAST_MAXCHARGETIME;
	m_iSpeed = MOUTHBLAST_SPEED;
	m_iKiCost = MOUTHBLAST_KI_COST;
	m_iDamage = MOUTHBLAST_DAMAGE;
	m_iRadius = MOUTHBLAST_RADIUS;
	m_flPlayerSlowdown = MOUTHBLAST_PLAYERSLOWDOWN;
	strcpy(m_pAttackName,"mouthblast");
	m_flRateOfTurn = MOUTHBLAST_ROT;

	//explosion color
	m_iExplosionColor = PURPLE_EXPLOSION;
	m_iAttachment = 3;

	FallInit();// get ready to fall down.
}

void CMouthblast::Precache( void )
{	m_sFlareA = PRECACHE_MODEL("sprites/mouthblasta.spr");
	m_sFlareB = PRECACHE_MODEL("sprites/mouthblastb.spr");
	m_sStartA = PRECACHE_MODEL("sprites/mouthblastastart.spr");
	m_sStartB = PRECACHE_MODEL("sprites/mouthblastbstart.spr");
	m_sTrail = PRECACHE_MODEL("sprites/mouthblasttrail.spr");
	PRECACHE_MODEL("sprites/mouthblastcharge.spr");
	PRECACHE_SOUND("buu/mouthbeam.wav");
	PRECACHE_SOUND("fatbuu/mouthbeam.wav");
	PRECACHE_SOUND("buu/mouthbeam_charge.wav");
	PRECACHE_SOUND("fatbuu/mouthbeam_charge.wav");

	CControlledBeam::Precache();
}

int CMouthblast::GetItemInfo(ItemInfo *p)
{	p->pszName = STRING(pev->classname);
	p->pszAmmo1 = "ki";
	p->iMaxAmmo1 = -1;	//max ammo is weapon independent
	p->pszAmmo2 = NULL;
	p->iMaxAmmo2 = -1;
	p->iMaxClip = WEAPON_NOCLIP;
	p->iSlot = 3;
	p->iPosition = 5;
	p->iId = m_iId = WEAPON_MOUTHBLAST;
	p->iWeight = MOUTHBLAST_WEIGHT;
	p->iFlags = 0;
	return 1;
}

void CMouthblast::InitChargeSprite( void )
{	m_pChargeSprite = CSprite::SpriteCreate( "sprites/mouthblastcharge.spr", m_pPlayer->pev->origin, true);
	m_pChargeSprite->SetAttachment(m_pPlayer->edict(),m_iAttachment);
	m_pChargeSprite->SetTransparency( kRenderTransAdd, 255, 255, 255, 254, kRenderFxGlowShell );
	m_pChargeSprite->SetScale(0.1);
	m_pChargeSprite->pev->framerate = 10;
	m_pChargeSprite->TurnOff();	
}

void CMouthblast::EmitShootSound()
{	m_pPlayer->EmitClassSound("mouthbeam.wav");
}

void CMouthblast::EmitChargeSound()
{	m_pPlayer->EmitClassSound("mouthbeam_charge.wav");
}