#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "effects.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 "../engine/shake.h"

/**
* Solarflare
* @version redo: 16-2-2001
* @author Herwin 'harSens' van Welbergen
*/
class CSolarFlare:public CBasePlayerWeapon
{	
public:
	/**
	* Init function
	*/
	void Spawn( void );

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

	/*
	* Holsters solarflare
	*/
	void Holster(int skiplocal = 0);

	/*
	* Deploys solarflare
	*/
	BOOL Deploy( void );

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

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

	void PrimaryAttack(void);
private:
	void EmitShootSound();
	int m_fUsed;
};

LINK_ENTITY_TO_CLASS( weapon_solarflare, CSolarFlare );

void CSolarFlare::Spawn( void )
{	Precache();
	m_iId = WEAPON_SOLARFLARE;
	m_iDefaultAmmo = 0;
	m_iClip = -1;
	FallInit();// get ready to fall down.
}

BOOL  CSolarFlare::Deploy()
{	m_fUsed = false;
	return DefaultDeploy("solarflare");
}

void CSolarFlare::Precache( void )
{	PRECACHE_SOUND("goku/solarflare.wav");
	PRECACHE_SOUND("cell/solarflare.wav");
	PRECACHE_SOUND("cell2/solarflare.wav");
	PRECACHE_SOUND("krillin/solarflare.wav");
	PRECACHE_SOUND("weapons/solarflare.wav");
}

int CSolarFlare::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 = 5;
	p->iPosition = 0;
	p->iId = m_iId = WEAPON_SOLARFLARE;
	p->iWeight = SOLARFLARE_WEIGHT;
	p->iFlags = 0;
	return 1;
}

void CSolarFlare::EmitShootSound()
{	m_pPlayer->EmitClassSound("solarflare.wav");	
	EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/solarflare.wav", 1.0, ATTN_NORM);
}
	
void CSolarFlare::Holster(int skiplocal)
{		
}

void CSolarFlare::PrimaryAttack()	
{	if(!m_fUsed)
	{	if(m_pPlayer->pev->fuser4>SOLARFLARE_KI_COST)
		{	
			int iKiUse = SOLARFLARE_MAX_KI_COST;
			if(m_pPlayer->pev->fuser4<SOLARFLARE_MAX_KI_COST)
			{	iKiUse = m_pPlayer->pev->fuser4;
			}
			float flKiRatio = (float)iKiUse/(float)SOLARFLARE_MAX_KI_COST;
			m_pPlayer->UseKi(iKiUse);
		
			//set the right animation
			m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
	
			//emit sound
			EmitShootSound();

			//do flash damage
			UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
			float radius = SOLARFLARE_RADIUS * flKiRatio;
			RadiusDamage( m_pPlayer->pev->origin + gpGlobals->v_forward * (radius/2 + 40), m_pPlayer->pev, m_pPlayer->pev, 0, radius, CLASS_NONE, DMG_FLASH );

			/*
			//fade the screen to white for a short time if not already blinded
			if (!m_pPlayer->m_fBlinded)
			{	UTIL_ScreenFade	( m_pPlayer, Vector (255,255,255), 1.0 , 0.5 , 255, FFADE_IN );			
			}
			*/
		}
	}
}