//--------------------------------------------------------------------------------------
//	File	:	AVP_ServerEntity_ShootAt.cpp
//	Author	:	Gareth Thomas
//	Created	:	18 / 12 / 2007
//	Copyright (C) 2006 Rebellion, All Rights Reserved.
//--------------------------------------------------------------------------------------

// Core
#include "Core/Asura.h"

// Header
#include "Entity/Locations/ShootAt/AVP_ServerEntity_ShootAt.h"

// Asura
#include "ChunkSystem/Asura_Chunk_Stream.h"

// AVP
#include "Entity/AVP_Entity_Classification.h"

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

//------------------------------------------------------------------------------
// Constants, Defines, Statics and Globals
//------------------------------------------------------------------------------
Asura_Hashed_List<AVP_ServerEntity_ShootAt> AVP_ServerEntity_ShootAt::s_xList;

//--------------------------------------------------------------------------------------
// AVP_ServerEntity_ShootAt :: Constructor
//--------------------------------------------------------------------------------------
AVP_ServerEntity_ShootAt::AVP_ServerEntity_ShootAt(const Asura_Guid uGuid) 
: PARENT(uGuid)
, m_bShootAtPlayer( false )
, m_bShootAtLinkedEntity( false )
, m_uLinkedShootAtEntity( ASURA_GUID_UNREGISTERED )
{
	Classification = AVP_ENTITYCLASS_SHOOTAT;
		
	SetNeverUpdateClient();
	SetNeverUpdates(true);
	s_xList.AddToList(this);
}

//--------------------------------------------------------------------------------------
// AVP_ServerEntity_ShootAt :: Deconstructor
//--------------------------------------------------------------------------------------
AVP_ServerEntity_ShootAt::~AVP_ServerEntity_ShootAt(void)
{
	s_xList.RemoveFromList(this);
}

//--------------------------------------------------------------------------------------
// AVP_ServerEntity_ShootAt :: PostLoadInitialise
//--------------------------------------------------------------------------------------
void AVP_ServerEntity_ShootAt::PostLoadInitialise(void)
{
	PARENT::PostLoadInitialise();
}

//--------------------------------------------------------------------------------------
// AVP_ServerEntity_ShootAt :: WriteToChunkStream
//--------------------------------------------------------------------------------------
void AVP_ServerEntity_ShootAt::WriteToChunkStream(Asura_Chunk_Stream& xStream) const
{
	//Version
	xStream << CURRENT_CHUNK_VERSION;

	//Parent
	PARENT::WriteToChunkStream(xStream);

	if (m_bShootAtPlayer)
		xStream << 1;
	else
		xStream << 0;

	if (m_bShootAtLinkedEntity)
		xStream << 1;
	else
		xStream << 0;

	xStream << m_uLinkedShootAtEntity;
}

//--------------------------------------------------------------------------------------
// AVP_ServerEntity_ShootAt :: ReadFromChunkStream
//--------------------------------------------------------------------------------------
void AVP_ServerEntity_ShootAt::ReadFromChunkStream(Asura_Chunk_Stream& xStream)
{
	//Version
	u_int uVersion;
	xStream	>> uVersion;

	//Parent
	PARENT::ReadFromChunkStream(xStream);

	u_int uBoolValue;

	xStream >> uBoolValue;

	if (uBoolValue == 0)
		m_bShootAtPlayer = false;
	else
		m_bShootAtPlayer = true;

	xStream >> uBoolValue;

	if (uBoolValue == 0)
		m_bShootAtLinkedEntity = false;
	else
		m_bShootAtLinkedEntity = true;


	xStream >> m_uLinkedShootAtEntity;
}

//--------------------------------------------------------------------------------------
// AVP_ServerEntity_ShootAt :: Create
//--------------------------------------------------------------------------------------
AVP_ServerEntity_ShootAt* AVP_ServerEntity_ShootAt::Create(const Asura_Guid uGuid)
{
	return(new AVP_ServerEntity_ShootAt(uGuid));
}

#ifdef ASURA_TOOLS
//--------------------------------------------------------------------------------------
// AVP_ServerEntity_ShootAt :: ApplyChangesForTemplateInstance
//--------------------------------------------------------------------------------------
void AVP_ServerEntity_ShootAt::ApplyChangesForTemplateInstance( Tools_EntityTemplateInstance* pxInstance )
{
	PARENT::ApplyChangesForTemplateInstance( pxInstance );
}
#endif
