// The Special functions called on Instanciation,
// when a particular MS is allocated
///////////////////////////////////////////////////////
#include "StdAfx.h"

/////////////////////////////////////////////////////
//////// !!!!!!!!!!!! DANGER !!!!!!!!!!! ////////////
/////////////////////////////////////////////////////
#define _ED_CAR_MUST_DEFINE_STRUCT_
#include "EdAllAct.hpp"
/////////////////////////////////////////////////////
//////// !!!!!!!!!!!! End DANGER !!!!!!!!!!! ////////
/////////////////////////////////////////////////////

#include "EDACSpec.hpp"

#include "EDACMStA.hpp"
#include "EDACActr.hpp"
#include "_AInterf.hpp"
#include "EDACStrg.hpp"

//External Modules
#include "ErO.h"
#include "CTL.h"
//End of External Modules

#undef CPA_WANTS_IMPORT
#undef CPA_EXPORT
#define CPA_WANTS_EXPORT
    #include "_Actors.hpp"
#undef CPA_WANTS_EXPORT
#define CPA_WANTS_IMPORT

//***********************************************************************
void EDACT_fn_vCineinfoAfterAllocation(EdActors_ActorMiniStructure *pclAMS)
{
	struct tdstCineinfo_ *hCineInfo = (struct tdstCineinfo_ *)pclAMS->m_fn_pvGetBaseAddress();
	
	ERROR_ASSERT( hCineInfo != NULL );

	CPA_Actor *pclActor = pclAMS->m_pclParentActor->m_pclActor;

	if ( pclActor->m_fn_bIsAnInstance() )
	{
		//Always points on Ed at allocation
//ANNECY YLG 23/01/98{
//		CPA_Actor *pclActorEd = (CPA_Actor *)g_pclInterface->GetMainWorld()->fn_p_oFindObject("Ed", C_szActorInstanceTypeName);

//		HIE_tdxHandleToSuperObject hMotorSO = pclActorEd->m_pub_fn_hGetMotorSuperObject();
			HIE_tdxHandleToSuperObject hMotorSO = MC_fn_hGetCharacterInMainCharacterNode( MC_fn_hGetFirstMainCharNode());
//ENDANNECY YLG }

//ANNECY CB
		CAM_fn_vCineInfoSetSuperObjectTargeted(hCineInfo->hInit, hMotorSO);
//ENDANNECY CB
	}
}

//***********************************************************************
void EDACT_fn_vLightAfterAllocation(EdActors_ActorMiniStructure *pclAMS)
{
	struct tdstMSLight_ *ptdstLight = (struct tdstMSLight_ *)pclAMS->m_fn_pvGetBaseAddress();
	
	//PROVISOIRE...
	if ( ptdstLight->p_stLight == NULL )
		GLI_xCreateLight(&(ptdstLight->p_stLight), 1);
}

//***********************************************************************
void EDACT_fn_vStdGameAfterAllocation(EdActors_ActorMiniStructure *pclAMS)
{
	MS_tdxHandleToStandardGame hStdGame = (MS_tdxHandleToStandardGame)pclAMS->m_fn_pvGetBaseAddress();
	
	ERROR_ASSERT( hStdGame != NULL );

	CPA_Actor *pclActor = pclAMS->m_pclParentActor->m_pclActor;
	if ( pclActor != NULL )
		if ( pclActor->m_fn_bIsAnInstance() )
		{
			HIE_tdxHandleToSuperObject h_SuperObject = pclActor->m_pub_fn_hGetMotorSuperObject();
			h_SuperObject->hLinkedObject.p_Void = (void *)pclActor->m_fn_pclGetEditorActor()->m_fn_ptdstGetMotorActor();
			
			fn_vStandardGameSetSuperObject(hStdGame, h_SuperObject);
		}
}

//***********************************************************************
void EDACT_fn_v3dDataAfterAllocation(EdActors_ActorMiniStructure *pclAMS)
{
	MS_tdxHandleTo3dData h3dData = (MS_tdxHandleTo3dData)pclAMS->m_fn_pvGetBaseAddress();
	
	ERROR_ASSERT( h3dData != NULL );

}

// Shaitan FastC {
//***********************************************************************
void EDACT_fn_vBrainAfterAllocation(EdActors_ActorMiniStructure *pclAMS)
{
	MS_tdxHandleToBrain hBrain = (MS_tdxHandleToBrain)pclAMS->m_fn_pvGetBaseAddress();
	
	ERROR_ASSERT( hBrain != NULL );

}
//End Shaitan FastC }

//***********************************************************************
void EDACT_fn_vDynamicsAfterAllocation(EdActors_ActorMiniStructure *pclAMS)
{
	MS_tdxHandleToDynam hDynam = (MS_tdxHandleToDynam)pclAMS->m_fn_pvGetBaseAddress();
	
	ERROR_ASSERT( hDynam != NULL );

	CPA_Actor *pclActor = pclAMS->m_pclParentActor->m_pclActor;

	ERROR_ASSERT( pclActor != NULL );

	if ( pclActor->m_fn_bIsAnInstance() )
	{
		if	(		(pclActor->m_pub_fn_pclGetSuperObject() != NULL)
				&&	(pclActor->m_pub_fn_pclGetSuperObject()->GetData() != NULL)
				&&	(!pclActor->m_fn_bIsAnAlways())
				)
		{
			struct tdstEngineObject_ *p_stObject = pclAMS->m_pclParentActor->m_fn_ptdstGetMotorActor();
			fn_vDynamInit(p_stObject, OTI_MapLoaded);
		}
		//else this is done elsewhere !
	}
}

