//////////////////////////////////////////////////////////////////////////////
//
// AVP_ServerEntity_Team_Marine.h
//
// Copyright (C) 2007 Rebellion. All Rights Reserved.
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef __AVP_SERVERENTITY_TEAM_MARINE_H__
#define __AVP_SERVERENTITY_TEAM_MARINE_H__ 1

// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

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

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

// AVP
#include "Entity/Controller/AVP_ServerEntity_Team.h"

// F O R W A R D   D E C L A R A T I O N S ///////////////////////////////////

class AVP_Brain_Team_Marine;
class AVP_Message_SpawnHumanoids;
class AVP_ServerEntity_HumanSpawnPoint;

//----------------------------------------------------------------------
// Structure :: SpawnRecord
// Used to store information about Humanoids that will be spawned
//----------------------------------------------------------------------
struct SpawnRecord
{
	u_int			m_uHumanoidType;			// AVP_ENTITYCLASSIFICATION.
	u_int			m_uNumToSpawn;				// Number of humanoids to spawn.
	u_int			m_uSpawnMethod;				// Method of spawning.
	Asura_Guid		m_uGamePlayVolumeGuid;		// Guid of Game Play Volume to spawn inside (depends on spawn method if use or not).
	Asura_Guid		m_uSpawnPointGuid;			// Guid of Humanoid Spawn Point to spawn at (depends on spawn method if use or not).
	Asura_Guid		m_uSquadGuid;				// Guid of Squad to join after spawning (depends on Humanoid type if used ort not).
	Asura_Hash_ID	m_uBlueprintHashID;			// Blueprint Hash Id of the Humanoid we are going to spawn.
	Asura_Hash_ID	m_uBlueprintTypeHashID;		// Blueprint Type Hash Id of the Humanoid we are going to spawn.
};

//////////////////////////////////////////////////////////////////////////////
//
// AVP_ServerEntity_Team_Marine
//
//////////////////////////////////////////////////////////////////////////////

class AVP_ServerEntity_Team_Marine : public AVP_ServerEntity_Team
{
    typedef AVP_ServerEntity_Team PARENT;

public:
    AVP_ServerEntity_Team_Marine( Asura_Guid uGuid );
    virtual ~AVP_ServerEntity_Team_Marine();

    virtual void ReadFromChunkStream( Asura_Chunk_Stream& xStream );
    virtual void WriteToChunkStream( Asura_Chunk_Stream& xStream ) const;
	virtual bool HandleMessage(const Asura_Message* pxMessage);
	virtual void Update(void);

	void	SetSpawnDelay(float fVal)	{m_fSpawningDelay = fVal;}
	float	GetSpawnDelay(void)			{return m_fSpawningDelay;}

    static AVP_ServerEntity_Team_Marine* Create( const Asura_Guid uGuid );
    static AVP_ServerEntity_Team_Marine* FindEntity( const Asura_Guid uGuid );
    static AVP_ServerEntity_Team_Marine* GetInstance() { return s_pxMarineTeam; }

	Asura_Hash_ID GetMarineKnowledgeBlueprintHash( void )	{ return m_uMarineKnowledgeBpHash; }
	Asura_Hash_ID GetAndroidKnowledgeBlueprintHash( void )	{ return m_uAndroidKnowledgeBpHash; }
	Asura_Hash_ID GetCivilianKnowledgeBlueprintHash( void )	{ return m_uCivilianKnowledgeBpHash; }

	void SetMarineKnowledgeBlueprintHash( Asura_Hash_ID uBPHashID )		{ m_uMarineKnowledgeBpHash = uBPHashID; }
	void SetAndroidKnowledgeBlueprintHash( Asura_Hash_ID uBPHashID )	{ m_uAndroidKnowledgeBpHash = uBPHashID; }
	void SetCivilianKnowledgeBlueprintHash( Asura_Hash_ID uBPHashID )	{ m_uCivilianKnowledgeBpHash = uBPHashID; }

protected:

	enum SpawnMethods
	{
		SPAWN_METHOD_TEAM_CONTROLLED = 0,
		SPAWN_METHOD_SPECIFIC_SPAWN_POINT,
		SPAWN_METHOD_SPECIFIC_GAME_PLAY_VOLUME,
		MAX_SPAWN_METHODS,
	};

    AVP_Brain_Team_Marine*	GetMarineTeamBrain() const;

	// Spawn Functions


	SpawnRecord*	GetCurrentSpawnRecord				(void)							{return m_pxCurrentSpawnRecord;}
	void			SetCurrentSpawnRecord				(SpawnRecord* pxSpawnRecord)	{m_pxCurrentSpawnRecord = pxSpawnRecord;}
	void			SpawnSuccess						(void)							{--(m_pxCurrentSpawnRecord->m_uNumToSpawn);}
	u_int			GetNumToSpawn						(void)							{return (m_pxCurrentSpawnRecord->m_uNumToSpawn);}
	u_int			GetSpawnMethod						(void)							{return (m_pxCurrentSpawnRecord->m_uSpawnMethod);}
	u_int			GetSpawningHumanoidType				(void)							{return (m_pxCurrentSpawnRecord->m_uHumanoidType);}
	Asura_Guid		GetSpawningGamePlayVolumeGuid		(void)							{return (m_pxCurrentSpawnRecord->m_uGamePlayVolumeGuid);}
	Asura_Guid		GetSpawningSquadGuid				(void)							{return (m_pxCurrentSpawnRecord->m_uSquadGuid);}
	Asura_Guid		GetSpawnPointGuid					(void)							{return (m_pxCurrentSpawnRecord->m_uSpawnPointGuid);}
	Asura_Hash_ID	GetSpawningBlueprintHashID			(void)							{return (m_pxCurrentSpawnRecord->m_uBlueprintHashID);}
	Asura_Hash_ID	GetSpawningBlueprintTypeHashID		(void)							{return (m_pxCurrentSpawnRecord->m_uBlueprintTypeHashID);}
	float			GetTimeSinceLastSpawn				(void)							{return m_fTimeSinceLastSpawn;}
	void			IncreaseTimeSinceLastSpawn			(const float fTime)				{m_fTimeSinceLastSpawn += fTime;}
	void			ResetTimeSinceLastSpawn				(void)							{m_fTimeSinceLastSpawn = 0.0f;}


	void			HandleSpawning						(void);
	void			AddSpawnRecord						(const AVP_Message_SpawnHumanoids* pxData);
	u_int			GetHumanoidToSpawnClassification	(int iHumanoidType);
	bool			HandleSpawningFromSpawnPoint		(void);
	bool			HandleSpawningInsideGamePlayVolume	(void);
	bool			HandleTeamSpawning					(void);
	bool			SquadIsFull							(Asura_Guid uSquadGuid);
	bool			IsSpawnRecordValid					(void);
	void			HandleChangeKnowledgeSettingsMessage( const Asura_Message* pxMessage );

	Asura_List<SpawnRecord>*		m_pxSpawnRecordList;
	SpawnRecord*					m_pxCurrentSpawnRecord;
	float							m_fTimeSinceLastSpawn;
	float							m_fSpawningDelay;
	Asura_Hash_ID					m_uMarineKnowledgeBpHash;
	Asura_Hash_ID					m_uAndroidKnowledgeBpHash;
	Asura_Hash_ID					m_uCivilianKnowledgeBpHash;


private:
    // Only one of these per level currently.
    static AVP_ServerEntity_Team_Marine* s_pxMarineTeam;

    enum { CURRENT_CHUNK_VERSION = 2 };
};

//////////////////////////////////////////////////////////////////////////////
//
// 
//
//////////////////////////////////////////////////////////////////////////////

#endif //__AVP_SERVERENTITY_TEAM_MARINE_H__
