//--------------------------------------------------------------------------------------
//	File		:	AVP_ServerEntity_SpawnPoint.cpp
//	Created		:	26 / 10 / 07
//	Author		:	Gareth Thomas
//	Copyright (C) 2006 Rebellion, All Rights Reserved.
//--------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------
//	INCLUDES
//--------------------------------------------------------------------------------------
// Always include Core first
#include "Core/Asura.h"
// This Files Header
#include "Entity/Spawners/AVP_ServerEntity_SpawnPoint.h"
// Asura include files
#include "Core/Asura_Timers.h"
#include "ChunkSystem/Asura_Chunk_Stream.h"
// Axon Include Files
// AVP Include files
#include "Entity/AVP_Entity_Classification.h"
// AVP Axon Include Files

#ifdef ASURA_TOOLS
#include "EntityTemplate/Tools_EntityTemplate_System.h"
#endif

//--------------------------------------------------------------------------------------
//	Statics
//--------------------------------------------------------------------------------------

Asura_Hashed_List<AVP_ServerEntity_SpawnPoint> AVP_ServerEntity_SpawnPoint::s_xList;

//--------------------------------------------------------------------------------------
//	Function	:	AVP_ServerEntity_SpawnPoint::AVP_ServerEntity_SpawnPoint
//	Created		:	26 / 10 / 07
//	Author		:	Gareth Thomas
//--------------------------------------------------------------------------------------
AVP_ServerEntity_SpawnPoint::AVP_ServerEntity_SpawnPoint(const Asura_Guid uGuid) : PARENT(uGuid)
, m_uGameSceneOutGuid(ASURA_GUID_UNREGISTERED)
, m_uGameSceneInGuid(ASURA_GUID_UNREGISTERED)
// , m_uSpawnBlueprintTypeHashID(ASURA_HASH_ID_UNSET)
// , m_uSpawnBlueprintHashID(ASURA_HASH_ID_UNSET)
{
	Classification = AVP_ENTITYCLASS_SPAWNPOINT;

	m_xOrientation.Identity();

	SetNeverUpdateClient();

	s_xList.AddToList( this );
}
/// End of function 'AVP_ServerEntity_SpawnPoint::AVP_ServerEntity_SpawnPoint'. ///


//--------------------------------------------------------------------------------------
//	Function	:	AVP_ServerEntity_SpawnPoint::~AVP_ServerEntity_SpawnPoint
//	Created		:	26 / 10 / 07
//	Author		:	Gareth Thomas
//--------------------------------------------------------------------------------------
AVP_ServerEntity_SpawnPoint::~AVP_ServerEntity_SpawnPoint()
{
	s_xList.RemoveFromList(this);
}
/// End of function 'AVP_ServerEntity_SpawnPoint::~AVP_ServerEntity_SpawnPoint'. ///


//--------------------------------------------------------------------------------------
//	Function	:	AVP_ServerEntity_SpawnPoint::Create
//	Created		:	26 / 10 / 07
//	Author		:	Gareth Thomas
//--------------------------------------------------------------------------------------
AVP_ServerEntity_SpawnPoint* AVP_ServerEntity_SpawnPoint::Create(const Asura_Guid uGuid)
{
	return(new AVP_ServerEntity_SpawnPoint(uGuid));
}
/// End of function 'AVP_ServerEntity_SpawnPoint::Create'. ///


//--------------------------------------------------------------------------------------
//	Function	:	AVP_ServerEntity_SpawnPoint::WriteToChunkStream
//	Created		:	26 / 10 / 07
//	Author		:	Gareth Thomas
//--------------------------------------------------------------------------------------
void AVP_ServerEntity_SpawnPoint::WriteToChunkStream(Asura_Chunk_Stream& xStream) const
{
	//Version
	xStream << CURRENT_CHUNK_VERSION;

	//Parent
	PARENT::WriteToChunkStream( xStream );

	//our data
	xStream << m_xPosition;
	xStream << m_uGameSceneOutGuid;
	xStream << m_uGameSceneInGuid;
	xStream << m_xOrientation;
// 	xStream << m_uSpawnBlueprintTypeHashID;
// 	xStream << m_uSpawnBlueprintHashID;
}
/// End of function 'AVP_ServerEntity_SpawnPoint::WriteToChunkStream'. ///


//--------------------------------------------------------------------------------------
//	Function	:	AVP_ServerEntity_SpawnPoint::ReadFromChunkStream
//	Created		:	26 / 10 / 07
//	Author		:	Gareth Thomas
//--------------------------------------------------------------------------------------
void AVP_ServerEntity_SpawnPoint::ReadFromChunkStream(Asura_Chunk_Stream& xStream)
{
	//Version
	u_int	uVersion	= CURRENT_CHUNK_VERSION + 1;

	// Read the data...
	xStream	>> uVersion;

	//Parent
	PARENT::ReadFromChunkStream( xStream );

	//our data
	xStream >> m_xPosition;

	// No longer stored
	if( uVersion == 1 )
	{
		float fDummy;
		xStream >> fDummy;
	}

	xStream >> m_uGameSceneOutGuid;

	if( uVersion > 2 )
	{
		xStream >> m_uGameSceneInGuid;
	}

	xStream >> m_xOrientation;
// 	xStream << m_uSpawnBlueprintTypeHashID;
// 	xStream << m_uSpawnBlueprintHashID;
}
/// End of function 'AVP_ServerEntity_SpawnPoint::ReadFromChunkStream'. ///

#ifdef ASURA_TOOLS
bool AVP_ServerEntity_SpawnPoint::CanBeIncludedInTemplate() const
{
	return ( Classification == AVP_ENTITYCLASS_SPAWNPOINT );
}

void AVP_ServerEntity_SpawnPoint::ApplyChangesForTemplateInstance( Tools_EntityTemplateInstance* pxInstance )
{
	PARENT::ApplyChangesForTemplateInstance( pxInstance );

    m_xPosition         = pxInstance->TransformPosition( m_xPosition );
    m_xOrientation      = pxInstance->TransformMatrix( m_xOrientation );
	m_uGameSceneOutGuid = pxInstance->ConvertGuid( m_uGameSceneOutGuid );
    m_uGameSceneInGuid  = pxInstance->ConvertGuid( m_uGameSceneInGuid );
}
#endif
