//////////////////////////////////////////////////////////////////////////////
//
// Tools_Entity_StartPoint.cpp
//
// Copyright (c) 2005 Rebellion. All rights reserved.
//
// Description:
//
//     Tools start point entity
//
//////////////////////////////////////////////////////////////////////////////

// I N C L U D E S ///////////////////////////////////////////////////////////

#include "Core/Asura.h"

// This file's header.
#include "Entity/Tools_Entity_StartPoint.h"

#include "Camera/Asura_Camera.h"
#include "Entity/Asura_Entity_Classification.h"
#include "Entity/Spawners/Asura_ServerEntity_StartPoint.h"
#include "Interface/Asura_Dialog.h"
#include "Interface/Asura_Overlay.h"
#include "Mesh/Asura_Mesh_System.h"
#include "Network/Asura_Message.h"
#include "Rendering/Asura_Render.h"
#include "Rendering/Asura_Text_Output.h"

#include "Entity/Tools_Entity_Data.h"
#include "Load&Save/Tools_SaveAsura.h"
#include "Misc/Tools_Timed_Messages.h"
#include "Movement/Tools_Movement.h"
#include "Objects/Tools_Object_System.h"

Tools_Entity_StartPoint::Tools_Entity_StartPoint(Asura_Entity* pxEntity)
:Tools_Entity_Object(pxEntity)
{
	Type = TOT_Entity_StartPoint;
	
	Asura_ServerEntity_StartPoint* pxAsuraEntity = (Asura_ServerEntity_StartPoint*) pxEntity;
	Position = pxAsuraEntity->m_xPosition;
	Orientation = pxAsuraEntity->m_xOrientation;

	Asura_String mesh_name = "ToolsShape_CutsceneActor";
	Mesh = Asura_Mesh_System::GetMesh(mesh_name);
}

Tools_Entity_StartPoint* Tools_Entity_StartPoint::CreateAndReturn()
{
	// Get a new GUID
	const Asura_Guid uGuid = Asura_Entity_System::GetCreatedByToolsGuid();

	// Set up tools data and auto-create a unique name (prompt for new name if there is a clash).
	Tools_Entity_Data* pxToolsData = CreateToolsDataWithDefaultName( "Start Point", "Start Point", uGuid, GetNamePrefix() );
	if(pxToolsData == NULL)
	{
		Asura_Assert( pxToolsData, "Tools_Entity_StartPoint::Create - no tools data" );
		return(NULL);
	}
	else
	{
		// Create the game specfic server object and set its data.
		Asura_ServerEntity_StartPoint* pxServerObject = new Asura_ServerEntity_StartPoint(uGuid);

		Asura_Assert( pxServerObject, "Tools_Entity_StartPoint::Create - no server object" );
		if ( pxServerObject )
		{
			pxServerObject->ToolsData = pxToolsData;
		}

		// Create the game specific tools object and select it.
		Tools_Entity_StartPoint* pxToolsObject = new Tools_Entity_StartPoint(pxServerObject);

		Asura_Assert( pxToolsObject, "Tools_Entity_StartPoint::Create - no RT tools object" );
		Tools_Object_System::SelectObject( pxToolsObject );

		pxToolsObject->Position = *Asura_Camera::GetPosition();
		pxToolsObject->Orientation = *Asura_Camera::GetOrientation();

		pxServerObject->m_xPosition = pxToolsObject->Position;
		pxServerObject->m_xOrientation = pxToolsObject->Orientation;

		Tools_Timed_Message_System::AddMessage( 0xffffff, "Created new Start Point");
		Tools_SaveAsura::SetEntityModified();
		return(pxToolsObject);
	}
}

void Tools_Entity_StartPoint::UpdatePositionInAsuraData(bool bUpdateLinkedObjects)
{
	Asura_ServerEntity_StartPoint* pxAsuraEntity = (Asura_ServerEntity_StartPoint*)Entity;

	if(pxAsuraEntity->m_xPosition != Position || pxAsuraEntity->m_xOrientation != Orientation)
	{
		Changed = true;

		pxAsuraEntity->m_xOrientation = Orientation;
		pxAsuraEntity->m_xPosition = Position;
	}

	Tools_Entity_Object::UpdatePositionInAsuraData(bUpdateLinkedObjects);
}

/// End of file. ///
