#include "myCRoot.h"			// Include Root.h
#include "State_Startup.h"		// Include States.h
#include "State_Choose.h"
#include "State_levelinit.h"
#include "State_Exit.h"

// GLOBALE OBJEKTE INSTANZIEREN

CGamevars		CRoot_SF42::m_gamevars;		// Konfigvariablen
CMusikPlayer	CRoot_SF42::m_musikplayer;	// Streamed MP3,ADPCM,PCM, + MIDI
CWavePlayer		CRoot_SF42::m_waveplayer;	// non streamed soundfx
CBackground		CRoot_SF42::m_background;	// globaler Hintergrund
CFps			CRoot_SF42::m_fps;		// fps actor
CMousePointer	CRoot_SF42::m_mouse;		// MouseObject
CEventMgr		CRoot_SF42::m_eventmgr;		// EventMgr
CVarMgr		CRoot_SF42::m_varmgr;		// VarMgr

CRoot_SF42::CRoot_SF42()
{
	m_gamevars.LoadVars("myGames.cfg");		// Im Konstruktor config File laden
}

int CRoot_SF42::InitPlayfield()
{
	/*
	 * Display öffnen
	 */
	if(llgfx_SetMode(320,240,16,0,0)) 
	{
		return FAIL;	// Fehler beim Bildschirm öffnen
	}
	
	m_global_object_queue.Put( &m_background );
	m_global_object_queue.Put( &m_fps);
	m_global_object_queue.Put( &m_mouse);
	m_global_object_queue.Put( &m_eventmgr);
	m_global_object_queue.Put( &m_varmgr);
	m_global_object_queue.Put( &m_waveplayer );

	SetNewState( "startup" );

	return OK;
}

CRoot_SF42::~CRoot_SF42()
{
	llfile_SetCurDir( "/" );		// Games Root dir
	m_gamevars.SaveVars("sf42.cfg");	// Save config
}

CRoot * CRoot_SF42::CreateStateByName( const char * name)
{
	if( strcmp(name,"startup") == 0 ) 
		return new CState_Startup();
	if( strcmp(name,"choose") == 0 )
		return new CState_Choose();
	if( strcmp(name,"levelinit") == 0 )
		return new CState_levelinit();
	if( strcmp(name,"exit") == 0 )
		return new CState_Exit();
	//default

	MsgBox("CRoot_SF42::CreateStateByName()\nError: unknown state %s", name );
	return 0;
}

void CRoot_SF42::InitState(const char * name)
{
	llfile_SetCurDir( "/data/" );
	llfile_SetCurDir( name );
	
	Execute("state.cfg",0);
}

CActor * CRoot_SF42::FindActor(const char * name)
{
	return m_Layerfactory.FindLayer(name);
}