//=============================================================================
// Xmas Cake Slice entity
// Author: GeckoN
//=============================================================================

namespace PointCakeSlice
{

const string ENTITY_NAME = "point_cake_slice";
const string ITEM_MODEL = "models/anniv/cake_slice.mdl";

class CPointCakeSlice : ScriptBaseAnimating
{
	// If youre gonna use this in your script, make sure you don't try
	// to access invalid animations. -zode
	void SetAnim( int animIndex ) 
	{
		pev.sequence = animIndex;
		pev.frame = 0;
		self.ResetSequenceInfo();
	}
	
	int GetAnim()
	{
		return self.pev.sequence;
	}
	
	void Precache()
	{
		BaseClass.Precache();
		
		PrecacheGlobal();
	}
	
	void Spawn()
	{
		Precache();
		
		self.pev.movetype 		= MOVETYPE_TOSS;
		self.pev.solid 			= SOLID_TRIGGER;
		
		self.pev.framerate 		= 1.0f;
		self.pev.health			= 1.0f;
		
		g_EntityFuncs.SetModel( self, ITEM_MODEL );

		self.pev.movetype = MOVETYPE_TOSS;
		self.pev.solid = SOLID_TRIGGER;
		
		g_EntityFuncs.SetSize( self.pev, self.pev.mins, self.pev.maxs);
		g_EntityFuncs.SetOrigin( self, self.pev.origin );
		
		// Yaw variance
		const float fAngleVar = 180.0;
		self.pev.angles[1] += Math.RandomFloat( -fAngleVar, +fAngleVar );
		
		SetAnim( 0 ); // set sequence to 0 aka idle
	}
	
	void Use( CBaseEntity@ pActivator, CBaseEntity@ pCaller, USE_TYPE useType, float value )
	{
		if ( useType == USE_TOGGLE )
		{
			self.SUB_UseTargets( pActivator, USE_TOGGLE, 0 );
			
			self.pev.effects |= EF_NODRAW;
			pev.nextthink = g_Engine.time + 0.1;
			
			//SetThink( ThinkFunction( ThinkRemove ) );
		}
	}
	
	void ThinkRemove( void )
	{
		self.SUB_Remove();
	}
}

void PrecacheGlobal()
{
	g_Game.PrecacheModel( ITEM_MODEL );
}

void Register()
{
	g_CustomEntityFuncs.RegisterCustomEntity( "PointCakeSlice::CPointCakeSlice", ENTITY_NAME );
}

} // end of PointCakeSlice namespace 
