//=========================================
//----------Laser-Projectile---------------
//=========================================

class ns_laserprojectile : ScriptBaseEntity
{	
		
	void Spawn()
	{
		Precache();
		pev.solid = SOLID_SLIDEBOX;
		pev.movetype = MOVETYPE_FLYMISSILE;
		g_EntityFuncs.SetModel( self, "models/ns/laserprojectile.mdl");
		
		g_SoundSystem.EmitSoundDyn( self.edict(), CHAN_VOICE, "weapons/displacer_fire.wav", 1.0, ATTN_NORM, 0, 95 + Math.RandomLong( 0, 10 ) );
	}

	void Precache()
	{
		g_Game.PrecacheModel( "models/ns/laserprojectile.mdl" ); 
	}
	
	void Touch ( CBaseEntity@ pOther )
	{
	
		g_SoundSystem.EmitSoundDyn( self.edict(), CHAN_VOICE, "weapons/displacer_impact.wav", 1.0, ATTN_NORM, 0, 95 + Math.RandomLong( 0, 10 ) );
	
		if ( ( pOther.TakeDamage ( pev, pev, 0, DMG_GENERIC ) ) != 1 )
		{
			pev.solid = SOLID_NOT;
			pev.movetype = MOVETYPE_FLY;
			pev.velocity = Vector( 0, 0, 0 );
			g_Utility.Sparks( pev.origin );

			g_Scheduler.SetTimeout( @this, "RemoveProjectile", 0.1);
			
		
		}
		else 
		{
			pOther.TakeDamage ( pev, self.pev.owner.vars, 10, DMG_ENERGYBEAM );
			g_EntityFuncs.Remove( self ); 
		}
	}
	
	void RemoveProjectile()
	{
		g_EntityFuncs.Remove( self );
	}
}


//=========================================
//----------Grenade-Projectile-------------
//=========================================

class ns_grenadeprojectile : ScriptBaseEntity
{	
		
	float explosionTime;
		
	void Spawn()
	{
		Precache();
		
		pev.solid = SOLID_BBOX;
		pev.movetype = MOVETYPE_BOUNCE;
		pev.avelocity = Vector( 300, 300, 300 );
		g_EntityFuncs.SetModel(self, "models/ns/grenadeprojectile.mdl");
		g_EntityFuncs.SetSize(pev, Vector(-0.5f, -0.5f, -0.5f), Vector(0.5f, 0.5f, 0.5f));
		
		g_SoundSystem.EmitSoundDyn( self.edict(), CHAN_VOICE, "rc/grenade_launch.wav", 1.0, ATTN_NORM, 0, 95 + Math.RandomLong( 0, 10 ) );
		
		explosionTime = g_Engine.time + 3.0;
		self.pev.nextthink	= g_Engine.time + 0.1;
		
	}

	
	void Think()
	{
		if( explosionTime <= g_Engine.time )
		{
			SetThink( ThinkFunction(this.Explode) );
		}
		
		if(self.pev.velocity.Length() <= 0.1){ self.pev.velocity = self.pev.velocity * 0.0f; }
		else { self.pev.velocity = self.pev.velocity * 0.99f; }

		self.pev.nextthink = 0.1;
		
	}


	void Precache()
	{
		g_Game.PrecacheModel( "models/ns/grenadeprojectile.mdl" );
		g_Game.PrecacheModel( "sprites/rc/rc_explosionHD.spr" );
		g_Game.PrecacheModel( "sprites/rc/rc_explosion2HD.spr" );
	}
	
	
	void Explode()
	{
		entvars_t@ pevOwner = self.pev.owner.vars;
		rc_explosion(self.pev, pevOwner, 5);
			
		g_EntityFuncs.Remove( self );
	}
	
	
	void Touch( CBaseEntity@ pOther )
	{
		g_SoundSystem.EmitSoundDyn( self.edict(), CHAN_VOICE, "weapons/grenade_hit1.wav", 1.0, ATTN_NORM, 0, 95 + Math.RandomLong( 0, 10 ) );
	}
	
}


//=========================================
//-----------Rocket-Projectile-------------
//=========================================

class ns_rocketprojectile : ScriptBaseEntity
{

	void Spawn()
	{
		Precache();
		pev.solid = SOLID_SLIDEBOX;
		pev.movetype = MOVETYPE_FLYMISSILE;
		g_EntityFuncs.SetModel( self, "models/ns/rocketprojectile.mdl");
		g_SoundSystem.EmitSoundDyn( self.edict(), CHAN_VOICE, "weapons/rocketfire1.wav", 1.0, ATTN_NORM, 0, 95 + Math.RandomLong( 0, 10 ) );
		
		SetThink( ThinkFunction(Ignite) );
		self.pev.nextthink = g_Engine.time + 0.05f;
	}
	
	
	void Precache()
	{
		g_Game.PrecacheModel( "models/ns/rocketprojectile.mdl" ); 
	}

	
	void Ignite()
	{
		g_SoundSystem.EmitSound( self.edict(), CHAN_VOICE, "weapons/rocket1.wav", 1, ATTN_NORM );
	}
	
	
	void Touch ( CBaseEntity@ pOther )
	{
		g_SoundSystem.StopSound( self.edict(), CHAN_VOICE, "weapons/rocket1.wav" );
		
		entvars_t@ pevOwner = self.pev.owner.vars;
		rc_explosion(self.pev, pevOwner, 8);
		
		g_EntityFuncs.Remove( self ); 
	}	
	
}


//=========================================
//-------------Robo-Projectile-------------
//=========================================

class ns_roboprojectile : ScriptBaseEntity
{	
		
	float deployTime;
		
	void Spawn()
	{
		Precache();
		
		pev.solid = SOLID_BBOX;
		pev.movetype = MOVETYPE_BOUNCE;
		pev.avelocity = Vector( 300, 300, 300 );
		g_EntityFuncs.SetModel(self, "models/ns/roboprojectile.mdl");
		g_EntityFuncs.SetSize(pev, Vector(-0.5f, -0.5f, -0.5f), Vector(0.5f, 0.5f, 0.5f));
		
		deployTime = g_Engine.time + 3.0;
		self.pev.nextthink	= g_Engine.time + 0.1;
		
	}

	
	void Think()
	{
		if( deployTime <= g_Engine.time )
		{
			SetThink( ThinkFunction(this.Deploy) );
		}
		
		if(self.pev.velocity.Length() <= 0.1){ self.pev.velocity = self.pev.velocity * 0.0f; }
		else { self.pev.velocity = self.pev.velocity * 0.99f; }

		self.pev.nextthink = 0.1;
		
	}


	void Precache()
	{
		g_Game.PrecacheModel( "models/ns/roboprojectile.mdl" );    
	}
	
	
	void Deploy()
	{
		CBaseEntity@ pRobo = g_EntityFuncs.Create( "monster_robo", self.pev.origin, Vector(0,0,0), false, null );
		g_EntityFuncs.Remove( self );
	}
	
	
	void Touch( CBaseEntity@ pOther )
	{
		g_SoundSystem.EmitSoundDyn( self.edict(), CHAN_VOICE, "weapons/grenade_hit1.wav", 1.0, ATTN_NORM, 0, 95 + Math.RandomLong( 0, 10 ) );
	}
	
}


//=========================================
//----------Register-----------------------
//=========================================

void RegisterProjectiles()
{
	g_CustomEntityFuncs.RegisterCustomEntity( "ns_laserprojectile", "ns_laserprojectile" );
	g_CustomEntityFuncs.RegisterCustomEntity( "ns_grenadeprojectile", "ns_grenadeprojectile" );
	g_CustomEntityFuncs.RegisterCustomEntity( "ns_rocketprojectile", "ns_rocketprojectile" );
	g_CustomEntityFuncs.RegisterCustomEntity( "ns_roboprojectile", "ns_roboprojectile" );
}