/**
*
* \file AVP_ServerEntity_WaypointBlockerVolume.cpp
*
* Created by Anthony Gregson - 11/12/07
*
* Copyright (C) 2007 Rebellion, All Rights Reserved.
*
**/

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

// header
#include "Entity/Triggers/AVP_ServerEntity_WaypointBlockerVolume.h"

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

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

// axon
#include "Core/AVP_Waypoint_Manager.h"

// avp

Asura_Hashed_List<AVP_ServerEntity_WaypointBlockerVolume> AVP_ServerEntity_WaypointBlockerVolume::s_xList(3);

AVP_ServerEntity_WaypointBlockerVolume::AVP_ServerEntity_WaypointBlockerVolume( Asura_Guid uGuid )
: PARENT(uGuid)
, m_bBlockHuman(false)
, m_bBlockAlien(false)
, m_bBlockPredator(false)
{
	Classification = AVP_ENTITYCLASS_WAYPOINTBLOCKERVOLUME;
	s_xList.AddToList(this);
}

AVP_ServerEntity_WaypointBlockerVolume::~AVP_ServerEntity_WaypointBlockerVolume()
{
	s_xList.RemoveFromList(this);
}

void AVP_ServerEntity_WaypointBlockerVolume::ReadFromChunkStream( Asura_Chunk_Stream& xStream )
{
	int iVersion;
	xStream >> iVersion;

	PARENT::ReadFromChunkStream(xStream);

	if (iVersion == 1)
	{
		xStream >> m_bBlockHuman;
		xStream >> m_bBlockAlien;
		xStream >> m_bBlockPredator;
	}
	else
	{
		Asura_Assertf(false, ("Unexpected version %d for AVP waypoint blocker volume", iVersion) );
	}
}

void AVP_ServerEntity_WaypointBlockerVolume::WriteToChunkStream( Asura_Chunk_Stream& xStream ) const
{
	xStream << CURRENT_CHUCK_VERSION;
	
	PARENT::WriteToChunkStream(xStream);

	xStream << m_bBlockHuman;
	xStream << m_bBlockAlien;
	xStream << m_bBlockPredator;
}

void AVP_ServerEntity_WaypointBlockerVolume::PostLoadInitialise()
{
	PARENT::PostLoadInitialise();
	Asura_Assertf(m_bBlockHuman | m_bBlockAlien | m_bBlockPredator, ("Waypoint blocker %u is set to not block any specie ", GetGuid()));
}

void AVP_ServerEntity_WaypointBlockerVolume::BlockLinks(bool bBlockLinks)
{
	AVP_Waypoint_Manager::SetBlockParams(m_bBlockHuman, m_bBlockAlien, m_bBlockPredator);

	PARENT::BlockLinks(bBlockLinks);

	AVP_Waypoint_Manager::RestoreBlockParamsDefault();
}