//////////////////////////////////////////////////////////////////////////////
//
// ToolsAVP_Entity_MarineTeam.cpp
//
// Copyright (C) 2007 Rebellion. All Rights Reserved.
//
//////////////////////////////////////////////////////////////////////////////

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

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

// header
#include "Entity/Controller/ToolsAVP_Entity_MarineTeam.h"

// asura
#include "Camera/Asura_Camera.h"
#include "Interface/Asura_Dialog.h"
#include "Interface/Asura_Overlay.h"
#include "Blueprint/Asura_Blueprint.h"
#include "Blueprint/Asura_Blueprint_System.h"

// avp
#include "Entity/AVP_Messages.h"
#include "Entity/AVP_Entity_EventIDs.h"
#include "Entity/Controller/AVP_Controller_Messages.h"
#include "Entity/Controller/AVP_ServerEntity_Team_Marine.h"
#include "Entity/Controller/ToolsAVP_Entity_MarineSquad.h"
#include "Entity/GamePlayVolume/ToolsAVP_Entity_GamePlayVolume.h"
#include "Entity/PhysicalObject/Actor/Vertebrates/Human/Android/AVP_ServerActor_Android.h"
#include "Entity/PhysicalObject/Actor/Vertebrates/Human/Civilian/AVP_ServerActor_Civilian.h"
#include "Entity/PhysicalObject/Actor/Vertebrates/Human/Marine/AVP_ServerActor_Marine.h"
#include "Entity/Spawners/Human/ToolsAVP_Entity_HumanSpawnPoint.h"

// tools
#include "Load&Save/Tools_SaveAsura.h"
#include "Misc/Tools_Modal_Overlay.h"
#include "Misc/Tools_Timed_Messages.h"
#include "Movement/Tools_Movement.h"
#include "Objects/ToolsAVP_Object_Type.h"


//////////////////////////////////////////////////////////////////////////////
//
// ToolsAVP_Entity_MarineTeam
//
//////////////////////////////////////////////////////////////////////////////

int									ToolsAVP_Entity_MarineTeam::s_iNumSquads				= 0;
const char**						ToolsAVP_Entity_MarineTeam::s_ppszSquadNames			= NULL;
int									ToolsAVP_Entity_MarineTeam::s_iSelectedSquad			= 0;

const char**						ToolsAVP_Entity_MarineTeam::s_ppszCategoryNames			= NULL;
int									ToolsAVP_Entity_MarineTeam::s_iSelectedCategory			= 0;
int									ToolsAVP_Entity_MarineTeam::s_iNumCategories			= 0;
bool								ToolsAVP_Entity_MarineTeam::s_bSelectedCategoryChanged	= false;

const char**						ToolsAVP_Entity_MarineTeam::s_ppszHumanSpawnerNames		= NULL;
int									ToolsAVP_Entity_MarineTeam::s_iSelectedSpawner			= 0;
int									ToolsAVP_Entity_MarineTeam::s_iNumSpawners				= 0;

float								ToolsAVP_Entity_MarineTeam::s_fRespawnDelay				= 1.0f;

ToolsAVP_Entity_MarineSquad*		ToolsAVP_Entity_MarineTeam::s_pxSelectedSquad			= NULL;
ToolsAVP_Entity_MarineTeam*			ToolsAVP_Entity_MarineTeam::s_pxToolsMarineTeam			= NULL;
ToolsAVP_Entity_HumanSpawnPoint*	ToolsAVP_Entity_MarineTeam::s_pxSelectedSpawnPoint		= NULL;

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: Constructor
//--------------------------------------------------------------------------------------------------------------------
ToolsAVP_Entity_MarineTeam::ToolsAVP_Entity_MarineTeam( Asura_Entity* pxEntity )
: PARENT( pxEntity )
, m_pxMarineTeam( static_cast< AVP_ServerEntity_Team_Marine* >( pxEntity ) )
{
    Type = TOT_Entity_MarineTeam;

    SetMesh( "ToolsShape_MarineTeam" );

    s_pxToolsMarineTeam = this;

	s_fRespawnDelay = m_pxMarineTeam->GetSpawnDelay();
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: Destructor
//--------------------------------------------------------------------------------------------------------------------
ToolsAVP_Entity_MarineTeam::~ToolsAVP_Entity_MarineTeam()
{
    s_pxToolsMarineTeam = NULL;

	delete [] s_ppszHumanSpawnerNames;
	s_ppszHumanSpawnerNames = 0;
	delete [] s_ppszCategoryNames;
	s_ppszCategoryNames = 0;
	delete [] s_ppszSquadNames;
	s_ppszSquadNames = 0;
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: UpdatePositionInAsuraData
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::UpdatePositionInAsuraData(bool /*updateLinkedObjects*/)
{
    // Moving the tools object around doesn't change any asura data, but we still want to save
    // the new tools object position out, so we set the entity data as modified.
    PARENT::UpdatePositionInAsuraData( true );
    Tools_SaveAsura::SetEntityModified();
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: HandlesThisMessage
//--------------------------------------------------------------------------------------------------------------------
bool ToolsAVP_Entity_MarineTeam::HandlesThisMessage( int iMessageID )
{
	switch (iMessageID)
	{
		case AVP_MSGID_CHANGE_HUMANOID_KNOWLEDGE_SETTINGS:
		case AVP_MSGID_SET_AI_TARGET_PRIORITIES:
		{
			return true;
		}
	}

    return PARENT::HandlesThisMessage( iMessageID );
}

//----------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: HandlesThisEvent
//----------------------------------------------------------------------
bool ToolsAVP_Entity_MarineTeam::HandlesThisEvent(int iEventID) const
{
	switch ( iEventID )
	{
		case AVP_ENTITY_EVENT_CIVILIAN_KILLED:
		{
			return true;
		}break;

		default:
		{
			return PARENT::HandlesThisEvent(iEventID);
		}break;
	}
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: Create
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::Create()
{
    // We only allow one of these per level.
    if ( AVP_ServerEntity_Team_Marine::GetInstance() )
    {
        Tools_Timed_Message_System::AddMessage( Tools_Timed_Message_System::COLOUR_ERROR, "Only one of these allowed per-level." );
        return;
    }

    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( "Humanoid Team", "Humanoid Team", uGuid );
    if ( !pxToolsData ) { return; }

    AVP_ServerEntity_Team_Marine* pxGameMarineTeam = new AVP_ServerEntity_Team_Marine( uGuid );
    if ( !pxGameMarineTeam ) { return; }
    pxGameMarineTeam->ToolsData = pxToolsData;

    ToolsAVP_Entity_MarineTeam* pxToolsMarineTeam = new ToolsAVP_Entity_MarineTeam( pxGameMarineTeam );
    if ( !pxToolsMarineTeam ) { return; }

    Tools_Object_System::SelectObject( pxToolsMarineTeam );

    Asura_Vector_3 xCameraForward;
    Asura_Camera::GetForwardVector( xCameraForward );
    pxToolsMarineTeam->Position = *Asura_Camera::GetPosition() + xCameraForward * 2.0f;
    pxToolsMarineTeam->Orientation.Identity();

    Tools_Timed_Message_System::AddMessage( Tools_Timed_Message_System::COLOUR_DEFAULT, "Created new Humanoid Team" );
    Tools_SaveAsura::SetEntityModified();
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: Create
//--------------------------------------------------------------------------------------------------------------------
Tools_Object* ToolsAVP_Entity_MarineTeam::Create(Asura_Entity* pxEntity)
{
    return new ToolsAVP_Entity_MarineTeam(pxEntity);
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: Update
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::Update(void)
{
	PARENT::Update();

	UpdateOverlay();
	UpdateSelectedSquad();
	UpdateSelectedSpawnPoint();
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: UpdateOverlay
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::UpdateSelectedSquad(void)
{
	if (m_xMarineSquadList.size() > 0)
	{
		if (s_iSelectedSquad > -1)
		{
			s_iSelectedSquad = Asura_Maths::Max(0, Asura_Maths::Min(s_iSelectedSquad, m_xMarineSquadList.size() - 1));
			s_pxSelectedSquad = m_xMarineSquadList.get_entry(s_iSelectedSquad);
		}
	}
	else
	{
		s_iSelectedSquad = -1;
	}
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: UpdateOverlay
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::UpdateSelectedSpawnPoint(void)
{
	if (m_xHumanSpawnList.size() > 0)
	{
		if (s_iSelectedSpawner > -1)
		{
			s_iSelectedSpawner = Asura_Maths::Max(0, Asura_Maths::Min(s_iSelectedSpawner, m_xHumanSpawnList.size() - 1));
			s_pxSelectedSpawnPoint = m_xHumanSpawnList.get_entry(s_iSelectedSpawner);
		}
	}
	else
	{
		s_iSelectedSquad = -1;
	}
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: UpdateOverlay
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::UpdateOverlay(void)
{
	if (s_bSelectedCategoryChanged)
	{
		DeleteOverlay();
		CreateOverlay();
		s_bSelectedCategoryChanged = false;
	}
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: UpdateWhileSelected
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::UpdateWhileSelected(void)
{
	if (m_pxMarineTeam)
	{
		m_pxMarineTeam->SetSpawnDelay(s_fRespawnDelay);
	}
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: UpdateWhileSelected
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::ChooseMarineBlueprint(void)
{
	Asura_Hash_ID uBlueprintTypeHashID = 0x7ad7bd1b; //"AI Settings"
	Asura_Hash_ID uBlueprintHashID     = s_pxToolsMarineTeam->m_pxMarineTeam->GetMarineKnowledgeBlueprintHash();

	if ( uBlueprintHashID == ASURA_HASH_ID_UNSET )
	{
		uBlueprintHashID = s_pxToolsMarineTeam->GetDefaultMarineBlueprintHashID();
	}

	BlueprintSelect_Overlay xBPOverlay( "Choose A Blueprint", &uBlueprintHashID, &uBlueprintTypeHashID );

	if ( !xBPOverlay.DoModal() ) 
	{
		return;
	}

	s_pxToolsMarineTeam->m_pxMarineTeam->SetMarineKnowledgeBlueprintHash( uBlueprintHashID );

	s_pxToolsMarineTeam->SetEntityModified();
	s_pxToolsMarineTeam->DeleteOverlay();
	s_pxToolsMarineTeam->CreateOverlay();
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: UpdateWhileSelected
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::ChooseAndroidBlueprint(void)
{
	Asura_Hash_ID uBlueprintTypeHashID = 0x7ad7bd1b; //"AI Settings"
	Asura_Hash_ID uBlueprintHashID     = s_pxToolsMarineTeam->m_pxMarineTeam->GetAndroidKnowledgeBlueprintHash();

	if ( uBlueprintHashID == ASURA_HASH_ID_UNSET )
	{
		uBlueprintHashID = s_pxToolsMarineTeam->GetDefaultAndroidBlueprintHashID();
	}

	BlueprintSelect_Overlay xBPOverlay( "Choose A Blueprint", &uBlueprintHashID, &uBlueprintTypeHashID );

	if ( !xBPOverlay.DoModal() ) 
	{
		return;
	}

	s_pxToolsMarineTeam->m_pxMarineTeam->SetAndroidKnowledgeBlueprintHash( uBlueprintHashID );

	s_pxToolsMarineTeam->SetEntityModified();
	s_pxToolsMarineTeam->DeleteOverlay();
	s_pxToolsMarineTeam->CreateOverlay();

}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: UpdateWhileSelected
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::ChooseCivilianBlueprint(void)
{
	Asura_Hash_ID uBlueprintTypeHashID = 0x7ad7bd1b; //"AI Settings"
	Asura_Hash_ID uBlueprintHashID     = s_pxToolsMarineTeam->m_pxMarineTeam->GetCivilianKnowledgeBlueprintHash();

	if ( uBlueprintHashID == ASURA_HASH_ID_UNSET )
	{
		uBlueprintHashID = s_pxToolsMarineTeam->GetDefaultCivilianBlueprintHashID();
	}

	BlueprintSelect_Overlay xBPOverlay( "Choose A Blueprint", &uBlueprintHashID, &uBlueprintTypeHashID );

	if ( !xBPOverlay.DoModal() ) 
	{
		return;
	}

	s_pxToolsMarineTeam->m_pxMarineTeam->SetCivilianKnowledgeBlueprintHash( uBlueprintHashID );

	s_pxToolsMarineTeam->SetEntityModified();
	s_pxToolsMarineTeam->DeleteOverlay();
	s_pxToolsMarineTeam->CreateOverlay();

}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: AddOverlayControls
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::AddOverlayControls(class Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset)
{
	PARENT::AddOverlayControls(pxOverlay, xOffset);

	Asura_Dialog* pxDialog;

	// Bump it down a little so its not right next to the Starts active tick box.
	xOffset.y += Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Function_Dialog( "Marine Knowledge Blueprint: ", xOffset, ChooseMarineBlueprint, &m_bChanged );
	pxOverlay->AddDialog( pxDialog );
	xOffset.y += Asura_Dialog::DefaultSpacing();
	pxDialog = new Asura_StringDisplay_Dialog( "", xOffset );
	pxOverlay->AddDialog( pxDialog );
	Asura_Blueprint* pxBlueprint = Asura_Blueprint_System::GetBlueprintByHashID( 0x7ad7bd1b /*"AI Settings"*/, m_pxMarineTeam->GetMarineKnowledgeBlueprintHash() );
	if ( pxBlueprint ) { pxDialog->UpdateLabel( pxBlueprint->GetName().GetString() ); }
	else { pxDialog->UpdateLabel( "ERROR" ); }
	xOffset.y += Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Function_Dialog( "Android Knowledge Blueprint: ", xOffset, ChooseAndroidBlueprint, &m_bChanged );
	pxOverlay->AddDialog( pxDialog );
	xOffset.y += Asura_Dialog::DefaultSpacing();
	pxDialog = new Asura_StringDisplay_Dialog( "", xOffset );
	pxOverlay->AddDialog( pxDialog );
	pxBlueprint = NULL;
	pxBlueprint = Asura_Blueprint_System::GetBlueprintByHashID( 0x7ad7bd1b /*"AI Settings"*/, m_pxMarineTeam->GetAndroidKnowledgeBlueprintHash() );
	if ( pxBlueprint ) { pxDialog->UpdateLabel( pxBlueprint->GetName().GetString() ); }
	else { pxDialog->UpdateLabel( "ERROR" ); }
	xOffset.y += Asura_Dialog::DefaultSpacing();
	
	pxDialog = new Asura_Function_Dialog( "Civilian Knowledge Blueprint: ", xOffset, ChooseCivilianBlueprint, &m_bChanged );
	pxOverlay->AddDialog( pxDialog );
	xOffset.y += Asura_Dialog::DefaultSpacing();
	pxDialog = new Asura_StringDisplay_Dialog( "", xOffset );
	pxOverlay->AddDialog( pxDialog );
	pxBlueprint = NULL;
	pxBlueprint = Asura_Blueprint_System::GetBlueprintByHashID( 0x7ad7bd1b /*"AI Settings"*/, m_pxMarineTeam->GetCivilianKnowledgeBlueprintHash() );
	if ( pxBlueprint ) { pxDialog->UpdateLabel( pxBlueprint->GetName().GetString() ); }
	else { pxDialog->UpdateLabel( "ERROR" ); }
	xOffset.y += Asura_Dialog::DefaultSpacing();

	//---------------------------------------------------------
	// Squad List
	//---------------------------------------------------------
	xOffset.y += Asura_Dialog::DefaultSpacing();
	UpdateSquadList();

	pxDialog = new Asura_StringDisplay_Dialog("Humanoid Squad List", xOffset);
	pxOverlay->AddDialog(pxDialog);
	xOffset.y += 1.5f;

	// Squad List
	Asura_List_Dialog* pxSquadListDialog = new Asura_List_Dialog(xOffset, s_ppszSquadNames, &s_iSelectedSquad, s_iNumSquads, s_iNumSquads, NULL);
	pxSquadListDialog->SetHelpText("Choose Squad");
	pxSquadListDialog->SetDoubleClickFunction(EditSelectedSquad, 0);
	pxOverlay->AddDialog(pxSquadListDialog);
	xOffset.y = pxSquadListDialog->m_xMaxCoord.y + Asura_Dialog::DefaultSpacing();

	pxDialog = new Asura_Function_Dialog("Edit And Focus On Selected Squad", xOffset, EditSelectedSquad);
	pxOverlay->AddDialog(pxDialog);
	xOffset.y += Asura_Dialog::LargeSpacing();
}

/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
int ToolsAVP_Entity_MarineTeam::GetNumRowsToDisplay()
{
	if (s_iNumSpawners <= 0)
	{
		return 1;
	}
	else if (s_iNumSpawners >= 11)
	{
		return 10;
	}
	else
	{
		return s_iNumSpawners;
	}
}

/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
int ToolsAVP_Entity_MarineTeam::GetNumEntriesToDisplay()
{
	if (s_iNumSpawners <= 0)
	{
		return 1;
	}
	else
	{
		return s_iNumSpawners;
	}
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: UpdateSpawnPointsList
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::UpdateSpawnPointsList()
{
	m_xHumanSpawnList.empty();
	s_iNumSpawners = 0;

	// build a list of
	for (Asura_Hashed_List_It<ToolsAVP_Entity_HumanSpawnPoint> it(ToolsAVP_Entity_HumanSpawnPoint::GetList()); !it.Done(); it.Next())
	{
		ToolsAVP_Entity_HumanSpawnPoint* pxSpawnPoint = it.GetCurrent();

		if (pxSpawnPoint)
		{

			if (s_iSelectedCategory > 0)
			{
				const Asura_Char* szCatName = s_ppszCategoryNames[s_iSelectedCategory]; 
				Asura_String szSpawnName = pxSpawnPoint->GetName();

				if (szSpawnName.Contains(szCatName))
				{
					m_xHumanSpawnList.add_entry(pxSpawnPoint);
				}
			}
			else
			{
				m_xHumanSpawnList.add_entry(pxSpawnPoint);
			}
		}
	}

	// reset our static array information
	s_iNumSpawners = m_xHumanSpawnList.size();

	if (s_iNumSpawners <= 0)
	{
		if (s_ppszHumanSpawnerNames)
		{
			delete [] s_ppszHumanSpawnerNames;
		}

		s_ppszHumanSpawnerNames = new const char*[1];
		s_ppszHumanSpawnerNames[0] = "No Human Spawn Points Available";
		s_pxSelectedSpawnPoint = NULL;
	}
	else
	{
		delete [] s_ppszHumanSpawnerNames;

		s_ppszHumanSpawnerNames = new const char*[s_iNumSpawners];

		// Fill our static arrays with the spawn point information
		for (int i = 0; i < s_iNumSpawners; i += 1)
		{
			s_ppszHumanSpawnerNames[i] = m_xHumanSpawnList.get_entry(i)->GetName();
		}
	}
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: UpdatCategoryList
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::UpdateCategoryList()
{
	List <ToolsAVP_Entity_GamePlayVolume*> xCategoryList;

	xCategoryList.empty();
	s_iNumCategories = 0;

	// build a list of
	for (Asura_Hashed_List_It<ToolsAVP_Entity_GamePlayVolume> it(ToolsAVP_Entity_GamePlayVolume::GetList()); !it.Done(); it.Next())
	{
		ToolsAVP_Entity_GamePlayVolume* pxGPVolume = it.GetCurrent();

		if (pxGPVolume)
		{
			xCategoryList.add_entry(pxGPVolume);
		}
	}

	// reset our static array information
	s_iNumCategories = xCategoryList.size() + 1;

	if (s_iNumCategories > 0)
	{
		delete [] s_ppszCategoryNames;

		s_ppszCategoryNames = new const char*[s_iNumCategories];

		s_ppszCategoryNames[0] = "All";

		// Fill our static arrays with the spawn point information
		for (int i = 1; i < s_iNumCategories; i += 1)
		{
			s_ppszCategoryNames[i] = xCategoryList.get_entry(i - 1)->GetName();
		}
	}
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: AddOverlayControls
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::UpdateSquadList(void)
{
	m_xMarineSquadList.empty();

	s_iNumSquads = 0;

	// build a list of
	for (Asura_Hashed_List_It<ToolsAVP_Entity_MarineSquad> it(ToolsAVP_Entity_MarineSquad::GetList()); !it.Done(); it.Next())
	{
		ToolsAVP_Entity_MarineSquad* pxSquad = it.GetCurrent();

		if (pxSquad)
		{
			m_xMarineSquadList.add_entry(pxSquad);
		}
	}

	// reset our static array information
	s_iNumSquads = m_xMarineSquadList.size();

	if (s_iNumSquads > 0)
	{
		delete [] s_ppszSquadNames;

		s_ppszSquadNames = new const char*[s_iNumSquads];

		// Fill our static arrays with the spawn point information
		for (int i = 0; i < s_iNumSquads; i += 1)
		{
			s_ppszSquadNames[i] = m_xMarineSquadList.get_entry(i)->GetName();
		}
	}
	else
	{
		delete [] s_ppszSquadNames;

		s_iNumSquads = 1;
		s_ppszSquadNames = new const char*[1];
		s_ppszSquadNames[0] = "No Squads Available";
	}
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: EditSelectedSquad
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::EditSelectedSquad(void)
{
	ToolsAVP_Entity_MarineTeam* pxMarineTeam = s_pxToolsMarineTeam;

	if (pxMarineTeam)
	{
		if (pxMarineTeam->s_pxSelectedSquad)
		{
			Asura_Vector_3		xNewCameraPos	= pxMarineTeam->s_pxSelectedSquad->Position;
			Asura_Matrix_3x3	xNewCameraOri	= *Asura_Camera::GetOrientation();
			Asura_Vector_3		xFwdVec;

			Asura_Camera::GetForwardVector(xFwdVec);
			xNewCameraPos -= xFwdVec * 8.0f;

			Tools_Movement::TeleportCameraToPosition(&xNewCameraPos, &xNewCameraOri);

			Tools_Object_System::SelectObject(pxMarineTeam->s_pxSelectedSquad);
		}
		else
		{
			Tools_Timed_Message_System::AddMessage(0xff0000,"No Squads Available");
		}
	}
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: EditSelectedSpawnPoint
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::EditSelectedSpawnPoint(void)
{
	ToolsAVP_Entity_MarineTeam* pxMarineTeam = s_pxToolsMarineTeam;

	if (pxMarineTeam)
	{
		if (pxMarineTeam->s_pxSelectedSpawnPoint)
		{
			Asura_Vector_3		xNewCameraPos	= pxMarineTeam->s_pxSelectedSpawnPoint->Position;
			Asura_Matrix_3x3	xNewCameraOri	= *Asura_Camera::GetOrientation();
			Asura_Vector_3		xFwdVec;

			Asura_Camera::GetForwardVector(xFwdVec);
			xNewCameraPos -= xFwdVec * 8.0f;

			Tools_Movement::TeleportCameraToPosition(&xNewCameraPos, &xNewCameraOri);

			Tools_Object_System::SelectObject(pxMarineTeam->s_pxSelectedSpawnPoint);
		}
		else
		{
			Tools_Timed_Message_System::AddMessage(0xff0000,"No Spawn Points Available");
		}
	}
}

//--------------------------------------------------------------------------------------------------------------------
// ToolsAVP_Entity_MarineTeam :: AddFilesToExportListFromMessage
//--------------------------------------------------------------------------------------------------------------------
void ToolsAVP_Entity_MarineTeam::AddFilesToExportListFromMessage(u_short usMessageID, void* pData, List<Asura_String>& nameList) const
{
	// If message is adding a spawn token, add the necessary files to the export list
	if (usMessageID == AVP_MSGID_SPAWN_HUMANOIDS)
	{
		const AVP_Message_SpawnHumanoids* pxMsgData = static_cast<AVP_Message_SpawnHumanoids*>(pData);

		if (!pxMsgData)
		{
			Asura_Assert(false, "ToolsAVP_Entity_AlienTeam::AddFilesToExportListFromMessage - Can't Find Spawn HUmanoids Message Data");
			return;
		}

		// Export Files depending on humanoid type to spawn
		if ((pxMsgData->GetBlueprintHashID() != ASURA_HASH_ID_UNSET) || (pxMsgData->GetBlueprintTypeHashID() != ASURA_HASH_ID_UNSET))
		{
			switch (pxMsgData->GetHumanoidTypeToSpawn())
			{
				// have to create a dummy android to get the dialogue! horrible
				case AVP_Message_SpawnHumanoids::SPAWN_HUMANOID_ANDROID:
				{
					AVP_Human_Description::AddAndroidFilesToExport(false, pxMsgData->m_uBlueprintHashID, nameList);
				}break;

				case AVP_Message_SpawnHumanoids::SPAWN_HUMANOID_CIVILIAN:
				{
					AVP_Human_Description::AddCivilianFilesToExport(false, pxMsgData->m_uBlueprintHashID, nameList);
				}break;

				case AVP_Message_SpawnHumanoids::SPAWN_HUMANOID_MARINE:
				{
					AVP_Human_Description::AddMarineFilesToExport(false, pxMsgData->m_uBlueprintHashID, nameList);
				}break;

				default:
				{
					Asura_Assert(false, "ToolsAVP_Entity_MarineTeam::AddFilesToExportListFromMessage - Invalid Humanoid type, please check you Humanoid Spawn message and set the correct humanoid type!");
				}break;
			}
		}
	}
	else
	{
		PARENT::AddFilesToExportListFromMessage(usMessageID, pData, nameList);
	}
}

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