#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"

#define GALLITGUN_MAXCHARGETIME			36
#define GALLITGUN_KI_COST				20
#define GALLITGUN_SPEED					1200
#define GALLITGUN_ROT					0.1
#define GALLITGUN_PLAYERSLOWDOWN		0.5
#define GALLITGUN_DAMAGE				4
#define GALLITGUN_RADIUS				4	

/**
* Gallit Gun Weapon
* @version : 22-7-2001
* @author Herwin 'harSens' van Welbergen
*/
class CGallitGun:public CControlledBeam
{	
public:
	/**
	* Init function
	*/
	void Spawn( void );

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

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

	/**
	* Get gallit gun 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 shoot sound
	*/
	virtual void EmitShootSound();

	/**
	* Emits charge sound
	*/
	virtual void EmitChargeSound();

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

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

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

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

LINK_ENTITY_TO_CLASS( weapon_gallitgun, CGallitGun );

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

	m_iMaxCharge = GALLITGUN_MAXCHARGETIME;
	m_iSpeed = GALLITGUN_SPEED;
	m_iKiCost = GALLITGUN_KI_COST;
	m_iDamage = GALLITGUN_DAMAGE;
	m_iRadius = GALLITGUN_RADIUS;
	m_flPlayerSlowdown = GALLITGUN_PLAYERSLOWDOWN;
	strcpy(m_pAttackName,"gallitgun");
	m_flRateOfTurn = GALLITGUN_ROT;

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

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

void CGallitGun::Precache( void )
{	m_sFlareA = PRECACHE_MODEL("sprites/gallitguna.spr");
	m_sFlareB = PRECACHE_MODEL("sprites/gallitgunb.spr");
	m_sStartA = PRECACHE_MODEL("sprites/gallitgunastart.spr");
	m_sStartB = PRECACHE_MODEL("sprites/gallitgunbstart.spr");
	
	PRECACHE_MODEL("sprites/ggunaura.spr");
	PRECACHE_SOUND("cell/gallitgun.wav");	
	PRECACHE_SOUND("cell2/gallitgun.wav");	
	PRECACHE_SOUND("vegeta/gallitgun.wav");
	PRECACHE_SOUND("cell/gallitgunfire.wav");	
	PRECACHE_SOUND("cell2/gallitgunfire.wav");
	PRECACHE_SOUND("vegeta/gallitgunfire.wav");
	m_sTrail = PRECACHE_MODEL("sprites/gallitguntrail.spr");

	CControlledBeam::Precache();
}

int CGallitGun::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 = 0;
	p->iId = m_iId = WEAPON_GALLITGUN;
	p->iWeight = GALLITGUN_WEIGHT;
	p->iFlags = 0;
	return 1;
}

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

void CGallitGun::EmitShootSound()
{	m_pPlayer->EmitClassSound("gallitgunfire.wav");	
}

void CGallitGun::EmitChargeSound()
{	m_pPlayer->EmitClassSound("gallitgun.wav");	
}