#ifndef BUDDY_WEAPONS_H
#define BUDDY_WEAPONS_H

#define ATTACK_NONE			0
#define ATTACK_PRIMARY		1
#define ATTACK_SECONDARY	2

class CGuidedAttack;

class CBaseBuddyWeapon
{
protected:
	float m_fShootDelay;
	CBuddy *m_pOwner;
	bool m_bActive;

	friend class CBuddy;

public:

	float	m_flNextPrimaryAttack;								// soonest time ItemPostFrame will call PrimaryAttack
	float	m_flNextSecondaryAttack;							// soonest time ItemPostFrame will call SecondaryAttack
	float	m_flTimeWeaponIdle; // when to play another weapon idle animation.	

	CBaseBuddyWeapon(CBuddy *pOwner) : m_fShootDelay(0.0f), m_pOwner(pOwner), m_bActive(false) {};

	virtual void ShootPrimary(void) = 0;
	virtual void ShootSecondary(void) {};
	virtual void WeaponIdle(void) {};
	virtual BOOL Deploy(void) {return true;};
	virtual char *GetWeaponName(void) = 0;
	virtual void Activate(void) = 0;
	virtual BOOL WeaponThink(CBasePlayer *pBuddyOwner) {return true;};
	float GetPowerRatio(void);
	
	// ask our current weapon if we can change our targetted enemy
	virtual BOOL CanSetEnemy(CBaseEntity *NewEnemy) {return true;};

	// our weapon handles whether it wants to control our buddies aim
	// 
	// for a beam we might "lock on" to a target so we shouldn't just look where our owner tells us too
	// the beam would have to "look" from the beam heads location
	virtual bool LookAndAim() {return true;};
};

class CBuddyMelee: public CBaseBuddyWeapon
{
public:
	virtual void ShootPrimary(void) {};
	virtual void ShootSecondary(void);
	virtual char *GetWeaponName(void) { return "melee"; };
	virtual void Activate(void) { strcpy(m_pOwner->m_szAnimExtention, "kiblast"); m_bActive = true; };

	CBuddyMelee(CBuddy *pOwner) : CBaseBuddyWeapon(pOwner) {};
};

class CBuddyKiblast: public CBaseBuddyWeapon
{
	short m_sFlareA, m_sFlareB, m_sTrail;
	bool m_bShootLeft;

public:
	virtual void ShootPrimary(void);
	virtual void ShootSecondary(void);
	virtual char *GetWeaponName(void) { return "kiblast"; };
	virtual void Activate(void) { strcpy(m_pOwner->m_szAnimExtention, "kiblast"); m_bActive = true; };
	virtual BOOL WeaponThink(CBasePlayer *pBuddyOwner);

	CBuddyKiblast(CBuddy *pOwner);
};

class CBuddyGenericBeam: public CBaseBuddyWeapon
{
protected:
	enum {ATTACK_IDLE,ATTACK_CHARGE,ATTACK_AIM}m_eAttackState;
	CGuidedAttack *m_pMagic;		//the magic attack created after firing
	CSprite *m_pChargeSprite;		//the sprites wich appears after charging
	short m_sTrail;					//trail sprite
	short m_sFlareA;				//flare sprite 
	short m_sFlareB;				
	short m_sStartA;				//start sprite
	short m_sStartB;				
	bool m_fChargeBall;	
	short m_sTrails[5];
	short m_sFlareAs[5];
	short m_sFlareBs[5];
	short m_sStartAs[5];
	short m_sStartBs[5];

	int m_iCharge;					//how far is it charged
	int m_iMaxCharge;				//max charge for this attack
	int m_iSpeed;					//the speed of the attack
	int m_iKiCost;					//ki needed for 1 chargepoint
	int m_iDamage;					//damage for 1 chargepoint
	int m_iRadius;					//radius for the attack
	float m_flPlayerSlowdown;		//speed of the player when charging
	char m_pAttackName[255];		//name of the attack
	float m_flRateOfTurn;			//how fast the attacks reacts on the crosshair
	int m_iAttachment;				//attachment for the beam
	int m_iExplosionColor;			//explosioncolor of the attack
	int m_iOldMoveType;				//movetype before beamjump
	int m_fBeamJump;				
	int m_fBeamJumping;

	int m_iAttack;					// 1 == primary attack, 2 == secondary attack
	EHANDLE m_pTarget;


public:
	virtual void ShootPrimary(void);
	virtual void ShootSecondary(void);
	virtual void WeaponIdle(void);
	virtual void Activate();
	virtual BOOL Deploy(void);
	virtual char *GetWeaponName(void) { return "genericbeam"; };
	
	virtual BOOL WeaponThink(CBasePlayer *pBuddyOwner); // {return true;};
	void InitChargeSprite();
	void Charge();
	void StopAiming();
	void EmitChargeSound();
	void EnableChargeSprite(){m_pChargeSprite->SetScale(0.015);m_pChargeSprite->TurnOn();};
	void GrowChargeSprite(){m_pChargeSprite->SetScale((float)m_iCharge * 0.015);};
	void DisableChargeSprite(){m_pChargeSprite->TurnOff();};
    void EmitControlSound(){ EMIT_SOUND(ENT(m_pOwner->pev), CHAN_BODY, "weapons/beamfire.wav", 1.0, ATTN_NORM); };
    void EmitShootSound(){	EMIT_SOUND(ENT(m_pOwner->pev), CHAN_WEAPON, "weapons/basicbeam_fire.wav", 1.0, ATTN_NORM);};
	void SilenceBodySounds(){EMIT_SOUND(ENT(m_pOwner->pev), CHAN_BODY, "common/null.wav", 1.0, ATTN_NORM);};
	void SilenceVoice(){EMIT_SOUND(ENT(m_pOwner->pev), CHAN_VOICE, "common/null.wav", 1.0, ATTN_NORM);};
	void SilenceWeaponSounds(){EMIT_SOUND(ENT(m_pOwner->pev), CHAN_WEAPON, "common/null.wav", 1.0, ATTN_NORM);};
	void StopBeamJump();
	void Shoot();
	void CreateBeam(Vector vecSrc, Vector vecThrow, float flSize);
	void ReleaseAttack();
	void ShootBall();

	CBuddyGenericBeam(CBuddy *pOwner);


};

#endif