///////////////////////////////////////////////////////////////////////////////
//
// File   : AVP_CoreState_GameFrontend.cpp
// Author : Rav Tharanee
// Date   : 25/02/09
//
// Copyright (C) 2009 Rebellion, All Rights Reserved.
//
//	This is the main frontend state, which has a sub-state machine that incorporates
//	the loading-frontend, frontend and multiplayer lobby
//
//		PARENT(AVP_StateMachine_Core)
//			->	this(AVP_State_Core)
//					->	StateMachine
//							->	Loading-Frontend
//							->	Frontend
//							->	Multiplayer lobby
//
///////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Include files...
////////////////////////////////////////////////////////////////////////////////

#include "Core/Asura.h"

#if defined(AVP_USE_GAME_FRONTEND)

// This file's header...
#include "Core/States/Core/AVP_CoreState_GameFrontend.h"

// Asura independent header-files...
#include "Core/Resources/Asura_Resource_System.h"

// Game independent header-files...
#include "Core/AVP_Core.h"
#include "Core/AVP_Settings.h"
#include "Core/AVP_StateMachine_Core.h"
#include "GUIMenu/AVP_GUIMenu_System.h"


AVP_CoreState_GameFrontend::AVP_CoreState_GameFrontend( AVP_StateMachine_Core& xParentMachine )
: PARENT( xParentMachine )
{
}

void AVP_CoreState_GameFrontend::Enter(const u_int uPreviousState)
{
	const AVP_Settings::Species	eSpecies	= AVP_Settings::GetPlayerSpecies();

	// Load the loading screen...
	Asura_Resource_System::CreateResourceBank(uAVP_RESOURCE_BANK_HASH_LOADING, szAVP_RESOURCE_BANK_NAME_LOADING, uAVP_RESOURCE_BANK_TRG_LOADING);
	switch(eSpecies)
	{
		case AVP_Settings::AVP_SPECIES_PREDATOR:
		{
			AVP_Core::LoadFile("GUIMenu\\Predator_Loading." ASURA_GUIMENU_STANDARD_FILE_EXTENSION);
			break;
		}

		case AVP_Settings::AVP_SPECIES_ALIEN:
		{
			AVP_Core::LoadFile("GUIMenu\\Alien_Loading." ASURA_GUIMENU_STANDARD_FILE_EXTENSION);
			break;
		}

		case AVP_Settings::AVP_SPECIES_HUMAN:
		default:
		{
			AVP_Core::LoadFile("GUIMenu\\Marine_Loading." ASURA_GUIMENU_STANDARD_FILE_EXTENSION);
			break;
		}
	}		// End of switch.

	AVP_GUIMenu_System::Activate(AVP_GUIMenu_System::GUIMENU_ID_LOADING);

	// Time to begin loading the frontend data...
	Asura_Resource_System::CreateResourceBank(uAVP_RESOURCE_BANK_HASH_FRONTEND, szAVP_RESOURCE_BANK_NAME_FRONTEND, uAVP_RESOURCE_BANK_TRG_FRONTEND);

	m_xStateMachine.Initialise();
}

void AVP_CoreState_GameFrontend::Update()
{
	m_xStateMachine.Update();

	const	u_int	uCurrentState = m_xStateMachine.GetCurrentState();
	switch( uCurrentState )
	{
#if defined(AVP_USE_DEVELOPMENT_FRONT_END)
	case	AVP_StateMachine_GameFrontend::STATE_DEVELOPMENTFRONTEND:
		{
			GetParentMachine().ChangeState( AVP_StateMachine_Core::STATE_DEVELOPMENTFRONTEND );
		}
		break;
#endif
#if defined(ASURA_TOOLS)
	case	AVP_StateMachine_GameFrontend::STATE_LOADINGTOOLS:
		{
			GetParentMachine().ChangeState( AVP_StateMachine_Core::STATE_LOADINGTOOLS );
		};
		break;
#endif
	case	AVP_StateMachine_GameFrontend::STATE_SHUTTINGDOWN:
		{
			GetParentMachine().ChangeState( AVP_StateMachine_Core::STATE_SHUTTINGDOWN );
		}
		break;
	case	AVP_StateMachine_GameFrontend::STATE_GAME:
		{
			GetParentMachine().ChangeState( AVP_StateMachine_Core::STATE_GAME );
		}
		break;
	default:
		break;
	}
}

void AVP_CoreState_GameFrontend::Render() const
{
	m_xStateMachine.Render();
}

void AVP_CoreState_GameFrontend::Exit(const u_int uNextState)
{
	m_xStateMachine.Shutdown();

	Asura_Resource_System::DestroyResourceBank(uAVP_RESOURCE_BANK_HASH_FRONTEND);
	Asura_Resource_System::DestroyResourceBank(uAVP_RESOURCE_BANK_HASH_LOADING);
}

void AVP_CoreState_GameFrontend::RequestQuitApplication()
{
	m_xStateMachine.RequestQuitApplication();
}

#endif	//defined(AVP_USE_GAME_FRONTEND)
