#ifndef __GUIDEDMISSILE_H__
#define __GUIDEDMISSILE_H__

#include "g_local.h"
#include "item.h"
#include "weapon.h"
//#include "camera.h"
#include "misc.h"
#include "player.h"

#define MISSILE_SPEED 450

class MissileView : public Entity
{
private:
	EntityPtr missile;
	EntityPtr owner;
	viewmode_t oldviewmode;
	float removetime;
	float starttime;

public:
	CLASS_PROTOTYPE( MissileView );

	MissileView();
	~MissileView();

	virtual void Setup( Entity *missile, int owner, viewmode_t oldvmode );
	virtual void SetupMissile( void );

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

inline void MissileView::Archive( Archiver &arc )
{
	Entity::Archive( arc );

	arc.WriteSafePointer( missile );
	arc.WriteSafePointer( owner );
	arc.WriteInteger( oldviewmode );
	arc.WriteFloat( removetime );
	arc.WriteFloat( starttime );
}

inline void MissileView::Unarchive( Archiver &arc )
{
	int temp;

	Entity::Unarchive( arc );

	arc.ReadSafePointer( &missile );
	arc.ReadSafePointer( &owner );
	temp = arc.ReadInteger();
	oldviewmode = ( viewmode_t )temp;
	removetime = arc.ReadFloat();
	starttime = arc.ReadFloat();
}

/*template class SafePtr<MissileView>;*/
typedef SafePtr<MissileView> MissileViewPtr;

class Missile : public Projectile
{
private:
	float speed;
	MissileViewPtr missileview;

public:
	CLASS_PROTOTYPE( Missile );

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

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

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

	arc.WriteFloat( speed );
	arc.WriteSafePointer( missileview );
}

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

	speed = arc.ReadFloat();
	arc.ReadSafePointer( &missileview );
}

class MissileLauncher : public Weapon
{
public:
	CLASS_PROTOTYPE( MissileLauncher );

	MissileLauncher();
	virtual void Shoot( Event *ev );
	virtual void SecondaryUse( Event *ev );
};

#endif /* guidedmissile.h */
