/*
	Trig Wars.
	Copyright (c) 2008, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

//=====================================================================================================================
/// @brief		Represents a wasp interceptor enemy. Wasps swarm towards the player and try to intercept the players
///				future position when up close.
//=====================================================================================================================

#include "Precompiled.h"
#include "GameObjects\EnemyWasp.h"
#include "Graphics\PrimitivesRenderer.h"
#include "Graphics\Camera2D.h"
#include "Graphics\ParticleEmitter.h"
#include "Game\GameCore.h"
#include "Game\EnemyBulletManager.h"

using namespace Game;

//=====================================================================================================================
/// Constants
//=====================================================================================================================

/// Amount of linear acceleration the enemy wasp has

const float EnemyWasp::LIN_ACCELERATION = 2000.0f;

/// Amount of angular acceleration the player ship has per second

const float EnemyWasp::ANG_ACCELERATION = 15.8f;

/// Time it takes for a wasp to fade in

const float EnemyWasp::FADE_IN_TIME = 1.0f;

/// Size of the enemy wasp

const Vec2f EnemyWasp::SIZE = Vec2f(15,15);

/// Time it takes to change from the wandering goal to another

const float EnemyWasp::GOAL_WANDER_CHANGE_TIME = 0.25f;

/// Time it takes to change from the swarm goal to another

const float EnemyWasp::GOAL_SWARM_CHANGE_TIME = 2.5f;

/// Time it takes to change from the intercept goal to another

const float EnemyWasp::GOAL_INTERCEPT_CHANGE_TIME = 4.0f;

/// Points that make up the shape of the ship;

const Vec3f EnemyWasp::SHAPE_POINTS[12] = 
{
	Vec3f( -SIZE.x			, +SIZE.y			),
	Vec3f( +SIZE.x			, +SIZE.y			),
	Vec3f( +SIZE.x			, +SIZE.y * 0.25f	),
	Vec3f( +SIZE.x	* 0.25f	, +SIZE.y * 0.25f	),
	Vec3f( +SIZE.x	* 0.25f	, -SIZE.y * 0.25f	),
	Vec3f( +SIZE.x			, -SIZE.y * 0.25f	),
	Vec3f( +SIZE.x			, -SIZE.y			),
	Vec3f( -SIZE.x			, -SIZE.y			),
	Vec3f( -SIZE.x			, -SIZE.y * 0.25f	),
	Vec3f( -SIZE.x	* 0.25f	, -SIZE.y * 0.25f	),
	Vec3f( -SIZE.x	* 0.25f	, +SIZE.y * 0.25f	),
	Vec3f( -SIZE.x			, +SIZE.y * 0.25f	)
};

/// Color of this enemy

const Color EnemyWasp::SHAPE_COLOR = Color(1.0f , 0.95f , 0.65f );

/// Distance to the player at which the wasp will try to intercept the player

const float EnemyWasp::INTERCEPT_DISTANCE = 200.0f;

/// How far the enemy looks ahead into the future when trying to intercept the player's ship and plotting players future position

const float EnemyWasp::INTERCEPT_LOOKAHEAD_TIME = 1.0f;

//=====================================================================================================================
/// @brief		Constructor: creates a wasp at position 0,0. This object is designed to be pooled, hence the 
///				lack of a more definite constructor.
/// @param		m - AIManager this wasp belongs to
//=====================================================================================================================

EnemyWasp::EnemyWasp( AIManager * m ) : AttackingEnemy(m,100)
{
	m_current_goal = GOAL_WANDER;
	
	// Attacking enemy base class settings

	m_fire_interval_min		= 0.25f;
	m_fire_view_cone_angle	= Float::PI() * 0.25f;
	m_fire_inaccuracy_max	= Float::PI() * 0.10f;	
	m_fire_chance			= 0.05f;		
}

//=====================================================================================================================
/// @brief		Annouces the type name for this object.
/// @returns	Type name of this object
//=====================================================================================================================

const char * EnemyWasp::GetTypeName() const
{
	return "EnemyWasp";
}

//=====================================================================================================================
/// @brief		Resets the state of the wasp, health, goal etc. Also randomly picks a direction for the wasp.
/// @remarks	This is is something of a default constructor after an object has been grabbed from the pool
/// @post		The picked wander point must be wrapped
//=====================================================================================================================

void EnemyWasp::ResetState()
{
	Revive();																// Restore health
	SetAngle( GameCore::GetSingleton()->GetRandom().NextFloat(0,3.147f) );	// Pick a random angle for the enemy
	m_fade_in_time_left = FADE_IN_TIME;										// Fade in
	m_current_goal = GOAL_WANDER;											// Wander initially
	m_goal_change_time_left	= GOAL_WANDER_CHANGE_TIME;						// Not onscreen yet
	m_time_till_fire = 0;													// Can fire again
	
	// Pick a random point to wander to: use the pick spawn point function because it keeps us away from the player
	
	m_wander_point = GetAIManager().PickPointAwayfrom( GetPosition() , 300 );
	
	// Make sure this is ok:
	
	ENSURE( PositionalObject::IsWrapped(m_wander_point) , "The picked wander point must be wrapped" );
}

//=====================================================================================================================
/// @brief			Draws the ship
/// @param			c - camera we are viewing from
/// @pre			Given camera cannot be null
/// @pre			Game must exist
/// @pre			Primitives renderer used by the game must not be null
/// @deprecated		Calls to OnDraw() are no longer used. Instead the much faster BufferedDraw() is used which
///					is designed for batch rendering.
//=====================================================================================================================

void EnemyWasp::OnDraw( Camera2D * c )
{
	// Make sure ok:

	ENSURE( c							, "Given camera cannot be null"		);
	ENSURE( GameCore::GetSingleton()	, "Game must exist"					);
	
	// Get the primitives renderer from the game:
	
	PrimitivesRenderer * r = GameCore::GetSingleton()->GetPrimitivesRenderer();
	
	// Make sure ok:
	
	ENSURE( r , "Primitives renderer used by the game must not be null" );

	// Do not draw if we are offscreen:

	if ( IsOnscreen(SIZE,c) == false ) return;
	
	// Makeup the points of the wasp:
	
	Vec2f points[12];
	
	// Set local positions:
	
	points[0 ] = Vec2f( -SIZE.x			, +SIZE.y			);
	points[1 ] = Vec2f( +SIZE.x			, +SIZE.y			);
	points[2 ] = Vec2f( +SIZE.x			, +SIZE.y * 0.25f	);
	points[3 ] = Vec2f( +SIZE.x	* 0.25f	, +SIZE.y * 0.25f	);
	points[4 ] = Vec2f( +SIZE.x	* 0.25f	, -SIZE.y * 0.25f	);
	points[5 ] = Vec2f( +SIZE.x			, -SIZE.y * 0.25f	);
	points[6 ] = Vec2f( +SIZE.x			, -SIZE.y			);
	points[7 ] = Vec2f( -SIZE.x			, -SIZE.y			);
	points[8 ] = Vec2f( -SIZE.x			, -SIZE.y * 0.25f	);
	points[9 ] = Vec2f( -SIZE.x	* 0.25f	, -SIZE.y * 0.25f	);
	points[10] = Vec2f( -SIZE.x	* 0.25f	, +SIZE.y * 0.25f	);
	points[11] = Vec2f( -SIZE.x			, +SIZE.y * 0.25f	);
	
	// Translate and rotate:
	
	{
		// Rotation transform:
		
		Matrix4f r = Matrix4f::RotationZ( GetAngle() );
		
		// Translation transform:
		
		Matrix4f t = Matrix4f::Translation( UnwrapCoordinates( c->GetPosition() , GetPosition() ) );
		
		// Combined transform:
		
		Matrix4f c = r * t;
		
		// Rotate and translate all:
		
		for ( int i = 0 ; i < 12 ; ++i ) points[i] = c.Transform(points[i]);
	}

	// Pick color:
	
	Color col; col.a *= ( 1.0f - m_fade_in_time_left ) / FADE_IN_TIME;

	// Convert color to unsigned integer:
	
	unsigned dxc = col.ToDxUnsigned();

	// Draw all lines bar the last:
	
	for ( int i = 0 ; i < 11 ; ++i )
	{
		// Draw this line:
	
		r->DrawLine( c , points[i] , points[i+1] , dxc );
	}
	
	// Draw the last line:
	
	r->DrawLine( c , points[11] , points[0] , dxc );
}

//=====================================================================================================================
/// @brief		Does ai for this enemy
/// @param		time_delta - time since the last frame.
/// @pre		The game must exist
/// @pre		The game must have a particle emitter
/// @pre		The AI manager for this object must have a bullet manager
//=====================================================================================================================

void EnemyWasp::OnUpdate( float time_delta )
{	
	// Make sure ok:
	
	ENSURE( GameCore::GetSingleton()							, "The game must exist"											)
	ENSURE( GameCore::GetSingleton()->GetParticleEmitter()		, "The game must have a particle emitter"						)
	ENSURE( GetAIManager().GetBulletManager()					, "The AI manager for this object must have a bullet manager"	)

	// Reduce the time left to fade in by:
	
	m_fade_in_time_left -= time_delta;
	
	// Clamp to zero
	
	if ( m_fade_in_time_left < 0 ) m_fade_in_time_left = 0;
	
	// Update the goal of the wasp
	
	UpdateGoal(time_delta);
	
	// Do the current goal
	
	switch ( m_current_goal )
	{
		case GOAL_WANDER:		DoWandering(time_delta);	break;
		case GOAL_SWARM:		DoSwarming(time_delta);		break;
		case GOAL_INTERCEPT:	DoIntercept(time_delta);	break;
	}
	
	// Do turning to avoid obstacles: this should override normal behaviour if urgent		
	
	AvoidObstacles
	(
		300						,	// Scan radius
		5000.0f					,	// Repulsion strength
		0.0002f					,	// Repulsion attenuation
		ANG_ACCELERATION * 4.0f	,	// Maximum amount of turning to do: allow for more than normal turning since this needs to override normal behavior
		time_delta					// time delta for frames
	);
	
	// Do collision with obstacles:
	
	if ( ObstacleManager * o_mgr = GetAIManager().GetObstacleManager() )
	{			
		// See if there was a collision:
	
		bool collision = ObstacleCollide( o_mgr , Float::Max( SIZE.x , SIZE.y ) );
		
		// Kill this ai if there was one:
		
		if ( collision ) 
		{
			// Kill us
		
			Kill();
		
			// Get the particle texture we will use to emit particles
			
			Texture & tex  = GetAIManager().GetBulletManager()->GetParticleTexture();
			
			// Only if valid:
			
			if ( tex.IsValid() )
			{
				// Make a particle burst:
				
				GameCore::GetSingleton()->GetParticleEmitter()->CreateBurst
				(
					512								,
					tex								,
					GetPosition()					,
					0.5f							,	// live time 1
					1.0f							,	// live time 2
					2.0f							,	// size 1
					10.0f							,	// size 2
					Color(1.0f,0.35f,0.25f,0.7f)	,	// color 1
					Color(1.0f,1.00f,0.25f,0.4f)	,	// color 2
					5.0f							,	// speed 1
					150.0f							,	// speed 2
					false								// alpha blend
				);			
			}
		}
	}	
	
	// Do base class update:
	
	AttackingEnemy::OnUpdate(time_delta);
}

//=====================================================================================================================
/// @brief		Updates the current goal of the wasp
/// @param		time_delta - amount of time in between this frame and the last
/// @pre		Game must exist
/// @pre		Game must have a valid camera
//=====================================================================================================================

void EnemyWasp::UpdateGoal( float time_delta )
{
	// Make sure ok:
	
	ENSURE( GameCore::GetSingleton()				, "Game must exist"					);
	ENSURE( GameCore::GetSingleton()->GetCamera()	, "Game must have a valid camera"	);
	
	// Determine if we are onscreen:
	
	bool onscreen = IsOnscreen( SIZE , GameCore::GetSingleton()->GetCamera() );
	
	// Get the player ship:
	
	PlayerShip * player = GetAIManager().GetPlayerShip();
	
	// NB: If the player is dead then just wander

	if ( player == 0 )
	{
		// Wander the hills: 
	
		m_current_goal			= GOAL_WANDER;
		m_goal_change_time_left	= GOAL_WANDER_CHANGE_TIME;
		
		// Done:
		
		return;
	}

	// See what our current goal is:
	
	switch ( m_current_goal )
	{
		//-------------------------------------------------------------------------------------------------------------
		// Wandering aboot:
		//-------------------------------------------------------------------------------------------------------------
		
		case GOAL_WANDER:
		{
			// See if we are onscreen:
			
			if ( onscreen )
			{
				// Onscreen: decrease time till goal change
				
				m_goal_change_time_left -= time_delta;
				
				// See if time to change behaviour:
				
				if ( m_goal_change_time_left <= 0 )
				{
					// Go into swarm mode: now chasing the player
					
					m_goal_change_time_left = GOAL_SWARM_CHANGE_TIME;
					m_current_goal			= GOAL_SWARM;
				}
			}
			else
			{
				// Not onscreen: reset the amount of time till we change goal
				
				m_goal_change_time_left = GOAL_WANDER_CHANGE_TIME;
			}
			
		}	break;
		
		//-------------------------------------------------------------------------------------------------------------
		// Swarming towards the player
		//-------------------------------------------------------------------------------------------------------------
		
		case GOAL_SWARM:
		{
			// See if we are onscreen:
			
			if ( onscreen )
			{
				// Get our distance to the player ship: see if in range for an intercept
				
				float sq_dist = GetPosition().SqDistanceTo( player->GetPosition() );
				
				// See if in range for an intercept:
				
				if ( sq_dist < INTERCEPT_DISTANCE * INTERCEPT_DISTANCE )
				{
					// In range for an intercept: decrease time till goal change
					
					m_goal_change_time_left -= time_delta;
					
					// See if time to intercept:
					
					if ( m_goal_change_time_left <= 0 )
					{
						// Intercept:
						
						m_goal_change_time_left = GOAL_INTERCEPT_CHANGE_TIME;
						m_current_goal = GOAL_INTERCEPT;
					}
				}
				else
				{			
					// Not in range: reset the amount of time till when we stop swarming
										
					m_goal_change_time_left = GOAL_SWARM_CHANGE_TIME;
				}
			}
			else
			{
				// Offscreen: decrement the amount of time till goal change
				
				m_goal_change_time_left -= time_delta;
				
				// See if time to change to wandering again:
				
				if ( m_goal_change_time_left <= 0 )
				{
					// Go into wander mode: not chasing the player any longer
					
					m_goal_change_time_left = GOAL_WANDER_CHANGE_TIME;
					m_current_goal			= GOAL_WANDER;
				}
			}
		
		}	break;
		
		
		//-------------------------------------------------------------------------------------------------------------
		// Trying to intercept the player
		//-------------------------------------------------------------------------------------------------------------
		
		case GOAL_INTERCEPT:
		{
			// Get our distance to the player
			
			float sq_dist = GetPosition().SqDistanceTo( player->GetPosition() );
			
			// See if in range for an intercept:
			
			if ( sq_dist < INTERCEPT_DISTANCE * INTERCEPT_DISTANCE )
			{
				// In range: reset the amount of time till a goal change
				
				m_goal_change_time_left = GOAL_INTERCEPT_CHANGE_TIME;
			}
			else
			{
				// Not in range for an intercept: decrease amount of time till goal change
				
				m_goal_change_time_left -= time_delta;
				
				// See if time to change goal:
				
				if ( m_goal_change_time_left <= 0 )
				{
					// Switch back to swarming
					
					m_goal_change_time_left = GOAL_SWARM_CHANGE_TIME;
					m_current_goal = GOAL_SWARM;
				}
			}
		
		}	break;
	}
}

//=====================================================================================================================
/// @brief		Does the wandering goal
/// @param		time_delta - amount of time in between this frame and the last
/// @post		If picking a wander point, the picked wander point must be wrapped.
//=====================================================================================================================

void EnemyWasp::DoWandering( float time_delta )
{
	// Calculate how much turning we should do to reach our goal point
	
	float turning = CalculateTurningToPoint(m_wander_point,25.0f,0.0001f);
	
	// Make sure the turning amount is within our allowed angular acceleration:
	
	if ( turning < - ANG_ACCELERATION ) turning = -ANG_ACCELERATION; else if ( turning > ANG_ACCELERATION ) turning = ANG_ACCELERATION;
	
	// Do the turning:
	
	AngularAcclerate( turning , time_delta );

	// Move in our current direction:
	
	SetLinearVelocity( GetLinearVelocity() + GetDirection() * LIN_ACCELERATION * time_delta ); 
	
	// See if we are within distance of the wander point:
	
	if ( WithinDistance( PositionalObject::UnwrapCoordinates(GetPosition(),m_wander_point) , 100 ) )
	{
		// Pick a new point away from our wander point
	
		m_wander_point = GetAIManager().PickPointAwayfrom( m_wander_point , 300 );
		
		// Make sure this is ok:
		
		ENSURE( PositionalObject::IsWrapped(m_wander_point) , "If picking a wander point, the picked wander point must be wrapped." );
	}
}

//=====================================================================================================================
/// @brief		Does the swarming goal
/// @param		time_delta - time between this frame and the last one
/// @pre		The game must exist
/// @pre		The player must be in the game
//=====================================================================================================================

void EnemyWasp::DoSwarming( float time_delta )
{
	// Make sure ok:
	
	ENSURE(	GameCore::GetSingleton()		, "The game must exist"					);
	ENSURE(	GetAIManager().GetPlayerShip()	, "The player must be in the game"		);
	
	// Get the player ship:
	
	PlayerShip * player = GetAIManager().GetPlayerShip();
	
	// Calculate turning for swarming

	float turning = SwarmToChase
	(
		player->GetPosition()	,		// chase pt
		50						,		// turn force
		200						,		// area of swarming
		3000.0f					,		// force of atraction
		5000.0f					,		// force of repuslion
		0.001f					,		// attraction attenuation
		0.003f					,		// repulsion attenuation
		0.0001f							// swarming influence
	);
	
	// Restrict the amount of turning:
	
	turning = Float::Clamp( turning , -ANG_ACCELERATION , ANG_ACCELERATION );
	
	// Do the turning:
	
	AngularAcclerate( turning , time_delta );
	
	// Move in our current direction:
	
	Acclerate( GetDirection() * LIN_ACCELERATION , time_delta );
	
	// Attack the player if we can
	
	DoFiring();
}

//=====================================================================================================================
/// @brief		Does the intercept goal
/// @param		time_delta - time between this frame and the last one
/// @pre		The ai manager for this manager should have a reference to the player
//=====================================================================================================================

void EnemyWasp::DoIntercept( float time_delta )
{
	// Make sure ok:

	ENSURE( GetAIManager().GetPlayerShip() , "The ai manager for this manager should have a reference to the player" );
	
	// Get the player ship:
	
	PlayerShip * player = GetAIManager().GetPlayerShip();	
	
	// Get the relative speed to the player:
	
	float rel_speed = ( player->GetLinearVelocity() - GetLinearVelocity() ).Length();
	
	// Get the distance to the player:
	
	float dist_to = DistanceTo(player);
	
	// Now calculate the future position of the player that we will chase:
	
	Vec2f future_pos = player->GetPosition();
	
	// Only do if the relative speed is over zero:
	
	if ( rel_speed > 0.00001f )
	{
		// Calculate the time required to close the gap:
		
		float t = dist_to / rel_speed;
		
		// Estimate where the player will be at this time:
		
		future_pos += player->GetLinearVelocity() * t;
	}
	
	// This position needs to be wrapped for the next function:
	
	future_pos = WrapCoordinates(future_pos);
	
	// Calculate turning for swarming, and swarm towards the player's future position

	float turning = SwarmToChase
	(
		future_pos			,		// chase pt
		50					,		// turn force
		100					,		// area of swarming
		100.0f				,		// force of atraction
		200.0f				,		// force of repuslion
		0.001f				,		// attraction attenuation
		0.007f				,		// repulsion attenuation
		0.001f						// swarming influence
	);
	
	// Restrict the amount of turning:
	
	turning = Float::Clamp( turning , -ANG_ACCELERATION , ANG_ACCELERATION );
	
	// Do the turning:
	
	AngularAcclerate( turning , time_delta );
	
	// Move in our current direction:
	
	Acclerate( GetDirection() * LIN_ACCELERATION , time_delta );
	
	// Attack the player if we can
	
	DoFiring();	
}

//=====================================================================================================================
/// @brief		This is a more optimised version of the OnDraw() function which uses the buffered line 
///				rendererer from the game. It is used for batch rendering of these enemy types.
/// @param		s - stack that the lines for the wasp should be placed on
/// @param		cam_pos - position of the camera
/// @param		z - z value that the object should be drawn at
/// @returns	The wasp should return the number of lines it has placed on the stack for rendering
//=====================================================================================================================

unsigned EnemyWasp::BufferedDraw( Stack & s , const Vec2f & cam_pos , float z )
{
	// Get our position:

	Vec3f pos = Vec3f( UnwrapCoordinates(cam_pos,GetPosition()) , z );

	// Pick color:
	
	Color col = SHAPE_COLOR; col.a *= ( 1.0f - m_fade_in_time_left ) / FADE_IN_TIME;

	// Convert to unsigned:

	unsigned col_unsigned = col.ToDxUnsigned();

	// Make a rotation matrix to rotate all our points

	Matrix2f rot = Matrix2f::Rotation( GetAngle() );

	// Put all our lines onto the stack

	Vec3f t1 = rot.Transform( SHAPE_POINTS[0] ) + pos;
	Vec3f t2 = rot.Transform( SHAPE_POINTS[1] ) + pos;

	s.Push( t1 );
	s.Push( col_unsigned );
	s.Push( t2 );
	s.Push( col_unsigned );

	t1 = rot.Transform( SHAPE_POINTS[2] ) + pos;

	s.Push( t2 );
	s.Push( col_unsigned );
	s.Push( t1 );
	s.Push( col_unsigned );

	t2 = rot.Transform( SHAPE_POINTS[3] ) + pos;

	s.Push( t1 );
	s.Push( col_unsigned );
	s.Push( t2 );
	s.Push( col_unsigned );

	t1 = rot.Transform( SHAPE_POINTS[4] ) + pos;

	s.Push( t2 );
	s.Push( col_unsigned );
	s.Push( t1 );
	s.Push( col_unsigned );

	t2 = rot.Transform( SHAPE_POINTS[5] ) + pos;

	s.Push( t1 );
	s.Push( col_unsigned );
	s.Push( t2 );
	s.Push( col_unsigned );

	t1 = rot.Transform( SHAPE_POINTS[6] ) + pos;

	s.Push( t2 );
	s.Push( col_unsigned );
	s.Push( t1 );
	s.Push( col_unsigned );

	t2 = rot.Transform( SHAPE_POINTS[7] ) + pos;

	s.Push( t1 );
	s.Push( col_unsigned );
	s.Push( t2 );
	s.Push( col_unsigned );

	t1 = rot.Transform( SHAPE_POINTS[8] ) + pos;

	s.Push( t2 );
	s.Push( col_unsigned );
	s.Push( t1 );
	s.Push( col_unsigned );

	t2 = rot.Transform( SHAPE_POINTS[9] ) + pos;

	s.Push( t1 );
	s.Push( col_unsigned );
	s.Push( t2 );
	s.Push( col_unsigned );

	t1 = rot.Transform( SHAPE_POINTS[10] ) + pos;

	s.Push( t2 );
	s.Push( col_unsigned );
	s.Push( t1 );
	s.Push( col_unsigned );

	t2 = rot.Transform( SHAPE_POINTS[11] ) + pos;

	s.Push( t1 );
	s.Push( col_unsigned );
	s.Push( t2 );
	s.Push( col_unsigned );

	t1 = rot.Transform( SHAPE_POINTS[0] ) + pos;

	s.Push( t2 );
	s.Push( col_unsigned );
	s.Push( t1 );
	s.Push( col_unsigned );

	// Drawing 12 lines

	return 12;
}
