
///////////////////////////////////////////////////////////////////////////////
//
// File   : AVP_Predalien_AIAnimStateData.cpp
// Author : Will Plano
// Date   : 27/09/2007
//
// Copyright (C) 2007 Rebellion, All Rights Reserved.
//
///////////////////////////////////////////////////////////////////////////////

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

#include "Core/Asura.h"

// This file's header...
#include "Actor/Vertebrates/Predalien/AVP_Predalien_AIAnimStateData.h"

// Asura
#include "Blueprint/Asura_Blueprint_System.h"
#include "Core/Asura_Hash.h"
#include "Dynamics/Asura_Collision_Object.h"

// AVP
#include "Blueprint/AVP_Blueprint_HashIDs.h"
#include "Physics/AVP_Collision_Descriptor.h"

#ifdef ASURA_TOOLS
#include "Blueprint/ToolsAVP_Blueprint_AnimSpreadsheetExporter.h"
#endif

AVP_Actor_AnimStateData* AVP_Predalien_AIAnimStateData::s_apxAnimStateData[ AVP_Predalien_AIAnimStateMachine::PREDALIEN_STATE_END ];

bool AVP_Predalien_AIAnimStateData::s_bInitialised = false;

const AVP_Actor_AnimStateData* AVP_Predalien_AIAnimStateData::GetAnimStateData( const Asura_Hash_ID uAnimStateBlueprintType, u_int uState )
{
	if ( !s_bInitialised )
	{
		Initialise( uAnimStateBlueprintType );
	}
	Asura_Assert( uState < AVP_Predalien_AIAnimStateMachine::PREDALIEN_STATE_END, "Invalid state" );
	if ( uState < AVP_Predalien_AIAnimStateMachine::PREDALIEN_STATE_END )
	{
		return s_apxAnimStateData[ uState ];
	}
	return NULL;
}

void AVP_Predalien_AIAnimStateData::Initialise( const Asura_Hash_ID uAnimStateBlueprintType )
{
	if ( s_bInitialised )
	{
		return;
	}

	s_bInitialised = true;

	Asura_String xStateBPName("AI");
#ifdef ASURA_TOOLS
	if ( ToolsAVP_Blueprint_AnimSpreadsheetExporter::IsActive() )
	{
		ToolsAVP_Blueprint_AnimSpreadsheetExporter::CreateFile( ( Asura_String( "Predalien_" ) + xStateBPName + ".csv" ).GetString() );
	}
#endif
	u_int uStateItr = 0;
	for ( ; uStateItr < AVP_Predalien_AIAnimStateMachine::ACTOR_STATE_IDLE; ++uStateItr )
	{
		s_apxAnimStateData[ uStateItr ] = NULL;
	}
	for ( ; uStateItr < AVP_Predalien_AIAnimStateMachine::PREDALIEN_STATE_END; ++uStateItr )
	{
		s_apxAnimStateData[ uStateItr ] = NULL;
		const Asura_Blueprint* pxStateBlueprint = Asura_Blueprint_System::GetBlueprintByHashID( uAnimStateBlueprintType, xStateBPName.GetHash() );
		Asura_Assertf( pxStateBlueprint, ( "Unable to get state blueprint 0x%08x", xStateBPName.GetHash() ) );
		if ( pxStateBlueprint )
		{
			if ( AVP_Predalien_AIAnimStateMachine::IsDirectionalState( uStateItr ) )
			{
				s_apxAnimStateData[ uStateItr ] = new AVP_Actor_AnimStateData_Directional();
				s_apxAnimStateData[ uStateItr ]->InitialiseFromBlueprint( uAnimStateBlueprintType, *pxStateBlueprint, AVP_Predalien_AIAnimStateMachine::GetStateDescriptionStatic( uStateItr ), AVP_Vertebrate_AIAnimStateMachine::IsStateRequired( uStateItr ) );
			}
			else
			{
				s_apxAnimStateData[ uStateItr ] = new AVP_Actor_AnimStateData_NonDirectional();
				s_apxAnimStateData[ uStateItr ]->InitialiseFromBlueprint( uAnimStateBlueprintType, *pxStateBlueprint, AVP_Predalien_AIAnimStateMachine::GetStateDescriptionStatic( uStateItr ), AVP_Vertebrate_AIAnimStateMachine::IsStateRequired( uStateItr ) );
			}
#ifdef ASURA_TOOLS
			if ( ToolsAVP_Blueprint_AnimSpreadsheetExporter::IsActive() )
			{
				ToolsAVP_Blueprint_AnimSpreadsheetExporter::WriteState( AVP_Predalien_AIAnimStateMachine::GetStateDescriptionStatic( uStateItr ), s_apxAnimStateData[ uStateItr ], pxStateBlueprint, uAnimStateBlueprintType );
			}
#endif
		}
	} // end state loop
}

void AVP_Predalien_AIAnimStateData::ResetStorage()
{
	if ( s_bInitialised )
	{
		s_bInitialised = false;
		for ( u_int uStateItr = 0; uStateItr < AVP_Predalien_AIAnimStateMachine::PREDALIEN_STATE_END; ++uStateItr )
		{
			delete s_apxAnimStateData[ uStateItr ];
		}
	}
}
/// End of file. ///
