#ifndef __HOVERWEAP_H__
#define __HOVERWEAP_H__

#include "g_local.h"
#include "entity.h"
#include "item.h"
#include "weapon.h"
#include "specialfx.h"
#include "hoverbike.h"
#include "sentient.h"


class HoverWeap : public Weapon
{
private:
	qboolean damagedtarget;
	qboolean attached;
	HoverbikePtr bike;

protected:
	virtual void AttachGun(void);
	virtual void DetachGun(void);

public:
	int side; // for alternating the firing side
	int rockets; // rocket ammo count
	int bullets; // bullet ammo count
	int mines; // mine ammo count

	CLASS_PROTOTYPE(HoverWeap);
		
	HoverWeap();
	void Fire(void);
	virtual void Shoot(Event *ev);
	virtual qboolean Drop(void);

	virtual void TraceAttack( Vector start, Vector end, int damage, trace_t *trace, int numricochets, int kick, int dflags, int meansofdeath, qboolean server_effects );
	virtual void FireBullets( Vector src, Vector dir, int numbullets, Vector spread, int mindamage, int maxdamage, int dflags, int meansofdeath, qboolean server_effects );

	virtual void Archive(Archiver &arc);
	virtual void Unarchive(Archiver &arc);
};

inline void HoverWeap::Archive (Archiver &arc)
{
	Weapon::Archive( arc );

	arc.WriteBoolean(damagedtarget);
	arc.WriteBoolean(attached);
	arc.WriteSafePointer(bike);

	arc.WriteInteger(side);
	arc.WriteInteger(rockets);
	arc.WriteInteger(bullets);
	arc.WriteInteger(mines);
}

inline void HoverWeap::Unarchive (Archiver &arc)
{
	Weapon::Unarchive( arc );

	damagedtarget = arc.ReadBoolean();
	attached = arc.ReadBoolean();
	arc.ReadSafePointer(&bike);

	side = arc.ReadInteger();
	rockets = arc.ReadInteger();
	bullets = arc.ReadInteger();
	mines = arc.ReadInteger();
}

class HBRocket : public Projectile
{
private:
	float speed;
	int owner;
	int bike;
	int frontbox;
	int backbox;

public:
	CLASS_PROTOTYPE( HBRocket );

	void Explode( Event *ev );
	void Setup( Entity *owner, Vector pos, Vector dir );

	virtual void Archive(Archiver &arc);
	virtual void Unarchive(Archiver &arc);
};

inline void HBRocket::Archive (Archiver &arc)
{
	Projectile::Archive( arc );

	arc.WriteFloat(speed);
	arc.WriteInteger(owner);
	arc.WriteInteger(bike);
	arc.WriteInteger(frontbox);
	arc.WriteInteger(backbox);
}

inline void HBRocket::Unarchive (Archiver &arc)
{
	Projectile::Unarchive( arc );

	speed = arc.ReadFloat();
	owner = arc.ReadInteger();
	bike = arc.ReadInteger();
	frontbox = arc.ReadInteger();
	backbox = arc.ReadInteger();
}

class HBMine : public Projectile
{
private:
	int owner;
	float detonate_time;

public:
	CLASS_PROTOTYPE(HBMine);

	void Explode(Event *ev);
	void Detect(Event *ev);
	void Setup(Entity *owner, Vector pos, Vector dir);

	virtual void Archive(Archiver &arc);
	virtual void Unarchive(Archiver &arc);
};

inline void HBMine::Archive (Archiver &arc)
{
	Projectile::Archive( arc );

	arc.WriteInteger(owner);
	arc.WriteFloat(detonate_time);
}

inline void HBMine::Unarchive (Archiver &arc)
{
	Projectile::Unarchive( arc );

	owner = arc.ReadInteger();
	detonate_time = arc.ReadFloat();
}

#endif /* hoverweap.h */
