/*=========================================================================
* Dynam.cpp : Dynam's functions
*
*
*
*         Dynam MUST BE REPLACE BY THE C FILENAME
*
*
* Version              1.0
* Creation date        01/10/96
* Revision date
*
* That file needs to be compatible for all platforms.
*
* (c) Ubi Studios 1996
*=======================================================================*/
 
/*******************************************************/
/**** For the structures and variables declarations ****/
/*******************************************************/
#define D_Dynam_StructureDefine
#define D_Dynam_VariableDefine
 
#include "ToolsCPA.h"
 
#include "Options/Options.h"
#include "Macros.h"
 
#include "Actions/AllActs.h"
 
#include "Structur/MemGame.h"
#include "Structur/ErrGame.h"
#include "Structur/Objects.h"
#include "Structur/GameScpt.h"
#include "Structur/StdObjSt.h"
#include "Structur/EngMode.h"
#include "Always.h"
 
#include "ObjInit.h"
#include "ObjType.h"
#include "ZeMem.h"
#include "ia_dnm.h"
 
 
/*-----------------------------------------------------------------------------
 *  Description : Dynam's object action script callback
 *-----------------------------------------------------------------------------
 *  Input :         Object pointer
 *  Output :        None
 *-----------------------------------------------------------------------------
 *  Creation date : 01/10/96            Author : Francois
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author :
 *  Modifications :
 *---------------------------------------------------------------------------*/
/* #if !defined(U64)*/
#if defined(GAM_USE_SCRIPT)
SCR_tde_Anl_ReturnValue fn_eDynamScriptCallBack(SCR_tdst_File_Description *_p_stFile,char *_p_szName,char *_ap_szParams[],SCR_tde_Anl_Action	_eAction)
{
	SCR_tde_Anl_ReturnValue eReturnValue = SCR_ERV_Anl_NormalReturn;
	MS_tdxHandleToDynam h_Dynam;
	struct tdstEngineObject_ *p_stEngineObject;
	ACP_tdxBool bCanHangOn;
	ACP_tdxBool bBase, bAdvanced, bComplex;
	eDynamicSize eSize;
	ACP_tdxBool bCollision;
	long lObjectType;
	unsigned char ucTypeOfObject;
	ACP_tdxBool bIsMobile;
	DNM_tdstDynamics* p_stDynamics;
	
	_p_stFile=_p_stFile;
	
	SCR_M_RdL0_GetSectionLong(C_ParentSection,0,struct tdstEngineObject_ *, p_stEngineObject);
	
	lObjectType = DNM_C_lObjectType_SolidMobile;
	ucTypeOfObject = DNM_C_lObjectType_Solid;
	bIsMobile = TRUE;
	bCanHangOn = TRUE;
	
	if (M_IsTitle)
	{
		bBase = bAdvanced = bComplex = FALSE;
		bCollision = FALSE; /* default value */
		eSize = eDynamicSizeBase; /* default size */
 
		MMG_fn_vBeginMemoryInfo (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeDynamics , p_stEngineObject);
 
		h_Dynam = fn_h_DynamRealAlloc();
		
		if (SCR_fn_uc_RdL0_GetNumberOfParameters(_ap_szParams)>=1)
		{
			if (!strcmp (_ap_szParams[0],C_szDynamicSizeBase)) eSize=eDynamicSizeBase;
			else if (!strcmp (_ap_szParams[0],C_szDynamicSizeAdvanced)) eSize=eDynamicSizeAdvanced;
			else if (!strcmp (_ap_szParams[0],C_szDynamicSizeComplex)) eSize=eDynamicSizeComplex;
 
			if (SCR_fn_uc_RdL0_GetNumberOfParameters(_ap_szParams)==2) bCollision = (ACP_tdxBool)atoi (_ap_szParams[1]);
		}
		
		fn_v_DynamicAlloc ( h_Dynam, eSize, bCollision, FALSE );
		
		MMG_fn_vEndMemoryInfo ();
		p_stEngineObject->h_Dynam=h_Dynam;
		
		fn_vInitDynamicalFunctionPointer(h_Dynam);
		p_stDynamics = fn_p_stDynamGetDynamics(h_Dynam);
		
		if (DNM_M_bDynamicsIsAdvancedSize(p_stDynamics))
		{
			DNM_M_vDynamicsSetSlideFactorX ( p_stDynamics, MTH_C_ONE );
			DNM_M_vDynamicsSetSlideFactorY ( p_stDynamics, MTH_C_ONE );
			DNM_M_vDynamicsSetSlideFactorZ ( p_stDynamics, MTH_C_ONE );
		}
	}
	else if (M_IsEntry)
	{
		DNM_tdstDynamics* p_stDynamics;
		p_stDynamics = fn_p_stDynamGetDynamics(p_stEngineObject->h_Dynam);
		
		/* this test is only usefull to read old .car */
		if (DNM_M_bDynamicsIsAdvancedSize(p_stDynamics))
		{
 
			if(M_ActionIs(C_szSlideFactorX))
			{
				double fSlideX;
				fSlideX = atof (_ap_szParams[0]);
				DNM_M_vDynamicsSetSlideFactorX (p_stDynamics,MTH_M_xDoubleToReal(fSlideX));
			}
			else if(M_ActionIs(C_szSlideFactorY))
			{
				double fSlideY;
				fSlideY = atof (_ap_szParams[0]);
				DNM_M_vDynamicsSetSlideFactorY (p_stDynamics,MTH_M_xDoubleToReal(fSlideY));
			}
			else if(M_ActionIs(C_szSlideFactorZ))
			{
				double fSlideZ;
				fSlideZ = atof (_ap_szParams[0]);
				DNM_M_vDynamicsSetSlideFactorZ (p_stDynamics,MTH_M_xDoubleToReal(fSlideZ));
			}
		}
	}
	
	return(eReturnValue);
}
#endif /* GAM_USE_SCRIPT */
 
/*-----------------------------------------------------------------------------
 *  Description : Dynam's mini-structure sizeof
 *-----------------------------------------------------------------------------
 *  Input :         None
 *  Output :        Size of
 *-----------------------------------------------------------------------------
 *  Creation date : 14/10/96            Author : Francois
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author :
 *  Modifications :
 *---------------------------------------------------------------------------*/
unsigned long fn_ulDynamSizeOf()
{
 return(sizeof(struct tdstDynam_));
}
 
/*-----------------------------------------------------------------------------
 *  Description : Dynam's object action allocation
 *-----------------------------------------------------------------------------
 *  Input :         Object pointer
 *  Output :        None
 *-----------------------------------------------------------------------------
 *  Creation date : 01/10/96            Author : Francois
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author :
 *  Modifications :
 *---------------------------------------------------------------------------*/
void fn_vDynamAlloc(struct tdstEngineObject_ *p_stObject)
{
	if (p_stObject==NULL)
		M_GameFatalError(E_uwGameMiniStructObjectNull);
	
	if (p_stObject->h_Dynam!=NULL)
		M_GameFatalError(E_uwGameMiniStructAllocAlreadyAlloc);
	
	MMG_fn_vBeginMemoryInfo (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeDynamics , p_stObject);
	p_stObject->h_Dynam = fn_h_DynamRealAlloc();
 
	fn_v_DynamicAlloc ( p_stObject->h_Dynam, eDynamicSizeBase, FALSE, (ACP_tdxBool)fn_ucIsAnAlwaysObject(p_stObject)  );
	
	MMG_fn_vEndMemoryInfo ();
}
 
MS_tdxHandleToDynam fn_h_DynamRealAlloc()
{
	MS_tdxHandleToDynam h_Dynam;
	
	h_Dynam = (MS_tdxHandleToDynam)M_p_GameMallocInHLM(fn_ulDynamSizeOf());
	fn_vDynamSetParsingDatas(h_Dynam,(struct DNM_stParsingDatas *)M_p_GameMallocInHLM(sizeof(DNM_tdstParsingDatas)));
	return(h_Dynam);
}
 
 
void fn_v_DynamicAlloc ( MS_tdxHandleToDynam h_Dynam, eDynamicSize eSize, ACP_tdxBool bCollision, ACP_tdxBool bAlways )
{
	DNM_tdstDynamics* p_stDynamic=NULL;	
	
#ifdef ACTIVE_EDITOR
	/* In editor mode, we make a full allocation */
 
	/* allocation */
	p_stDynamic = (DNM_tdstDynamics*)M_p_GameMallocInHLM(sizeof(DNM_tdstComplexDynamics));
	fn_vDynamSetDynamics ( h_Dynam, p_stDynamic );
	DNM_M_DynamicsSetReport ( p_stDynamic, (DNM_tdstReport*)M_p_GameMallocInHLM(sizeof(DNM_tdstReport)) );
 
	/* update flags */
	switch (eSize)
	{
	case eDynamicSizeBase : DNM_M_vDynamicsSetBaseSize (p_stDynamic); break;
	case eDynamicSizeAdvanced : DNM_M_vDynamicsSetAdvancedSize (p_stDynamic); break;
	case eDynamicSizeComplex : DNM_M_vDynamicsSetComplexSize (p_stDynamic); break;
	}
	/* since we always allocate the collision report, say so! */
	DNM_M_vDynamicsSetCollisionReport ( p_stDynamic, TRUE );
 
#else /* ACTIVE_EDITOR*/
 
	/* allocation */
	if (bAlways)
	{
		switch (eSize)
		{
		case eDynamicSizeBase :
			p_stDynamic = (DNM_tdstDynamics*)TMP_M_p_Malloc(sizeof(DNM_tdstBaseDynamics));
			DNM_M_vDynamicsSetBaseSize (p_stDynamic);
			break;
		case eDynamicSizeAdvanced :
			p_stDynamic = (DNM_tdstDynamics*)TMP_M_p_Malloc(sizeof(DNM_tdstAdvancedDynamics));
			DNM_M_vDynamicsSetAdvancedSize (p_stDynamic);
			break;
		case eDynamicSizeComplex :
			p_stDynamic = (DNM_tdstDynamics*)TMP_M_p_Malloc(sizeof(DNM_tdstComplexDynamics));
			DNM_M_vDynamicsSetComplexSize (p_stDynamic);
			break;
		}
	}
	else
	{
		switch (eSize)
		{
		case eDynamicSizeBase :
			p_stDynamic = (DNM_tdstDynamics*)M_p_GameMallocInHLM(sizeof(DNM_tdstBaseDynamics));
			DNM_M_vDynamicsSetBaseSize (p_stDynamic);
			break;
		case eDynamicSizeAdvanced :
			p_stDynamic = (DNM_tdstDynamics*)M_p_GameMallocInHLM(sizeof(DNM_tdstAdvancedDynamics));
			DNM_M_vDynamicsSetAdvancedSize (p_stDynamic);
			break;
		case eDynamicSizeComplex :
			p_stDynamic = (DNM_tdstDynamics*)M_p_GameMallocInHLM(sizeof(DNM_tdstComplexDynamics));
			DNM_M_vDynamicsSetComplexSize (p_stDynamic);
			break;
		}
	}
 
	fn_vDynamSetDynamics ( h_Dynam, p_stDynamic );
	DNM_M_vDynamicsSetAlways ( p_stDynamic, bAlways );
 
	if (bCollision)
	{
		if( bAlways )
			DNM_M_DynamicsSetReport ( p_stDynamic, (DNM_tdstReport*)TMP_M_p_Malloc(sizeof(DNM_tdstReport)) );
		else
			DNM_M_DynamicsSetReport ( p_stDynamic, (DNM_tdstReport*)M_p_GameMallocInHLM(sizeof(DNM_tdstReport)) );
	}
	else
		DNM_M_DynamicsSetReport ( p_stDynamic, NULL );
 
	DNM_M_vDynamicsSetCollisionReport ( p_stDynamic, bCollision );
 
#endif /* ACTIVE_EDITOR*/
}
 
 
void fn_v_DynamicFree  ( MS_tdxHandleToDynam h_Dynam )
{
	DNM_tdstDynamics* p_stDynamic;
 
	if( (p_stDynamic = fn_p_stDynamGetDynamics(h_Dynam)) == NULL )
		return;
 
#ifdef ACTIVE_EDITOR
	if (DNM_M_bDynamicsIsCollisionReport(p_stDynamic))
		M_GameFreeInHLM (DNM_M_p_stDynamicsGetReportWithoutCheckAccess(p_stDynamic));
	M_GameFreeInHLM (p_stDynamic);
#else
	if (DNM_M_bDynamicsIsAlways(p_stDynamic))
	{
		if (DNM_M_bDynamicsIsCollisionReport(p_stDynamic))
			TMP_M_Free (DNM_M_p_stDynamicsGetReportWithoutCheckAccess(p_stDynamic));
		TMP_M_Free (p_stDynamic);
	}
	else
	{
		if (DNM_M_bDynamicsIsCollisionReport(p_stDynamic))
			M_GameFreeInHLM (DNM_M_p_stDynamicsGetReportWithoutCheckAccess(p_stDynamic));
		M_GameFreeInHLM (p_stDynamic);
	}
#endif
 
	fn_vDynamSetDynamics( h_Dynam, NULL );
	p_stDynamic = NULL;
}
 
 
 
/*-----------------------------------------------------------------------------
 *  Description : Dynam's object action free
 *-----------------------------------------------------------------------------
 *  Input :         Object pointer
 *  Output :        None
 *-----------------------------------------------------------------------------
 *  Creation date : 01/10/96            Author : Francois
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author :
 *  Modifications :
 *---------------------------------------------------------------------------*/
void fn_vDynamFree(struct tdstEngineObject_ *p_stObject)
{
	if (p_stObject==NULL)
		M_GameFatalError(E_uwGameMiniStructObjectNull);
	
	if (p_stObject->h_Dynam==NULL)
		M_GameFatalError(E_uwGameMiniStructNull);
	
	MMG_fn_vAddMemoryInfo( MMG_C_lTypeMiniStructure , MMG_C_lSubTypeLight , p_stObject );
 
	fn_v_DynamicFree (p_stObject->h_Dynam);
	M_GameFreeInHLM(p_stObject->h_Dynam);
}
 
 
/*-----------------------------------------------------------------------------
 *  Description : Dynam's object action initialisation
 *-----------------------------------------------------------------------------
 *  Input :         When this function's called (see ObjInit.h)
 *  Output :        None
 *-----------------------------------------------------------------------------
 *  Creation date : 01/10/96            Author : Francois
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author :
 *  Modifications :
 *---------------------------------------------------------------------------*/
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
void fn_vUpdateDynamicsMS(struct tdstEngineObject_ *p_stObject)
{
	if (p_stObject==NULL)
		M_GameFatalError(E_uwGameMiniStructObjectNull);
 
	if (p_stObject->h_Dynam==NULL)
		M_GameFatalError(E_uwGameMiniStructNull);
 
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
 
 
void fn_vDynamInit(struct tdstEngineObject_ *p_stObject,enum tdeObjectTreeInit_ eObjectInit)
{
	switch(eObjectInit)
	{
	case OTI_PlayerDead:
	case OTI_ReinitTheMap:
		
	case OTI_LoadSavedGame:
	case OTI_MapLoaded:
	case OTI_WhenGameStart:
		DNM_fn_vInitBaseMechanic (p_stObject->h_Dynam->p_stDynamics);
		memset(p_stObject->h_Dynam->p_stParsingDatas,0,sizeof(struct DNM_stParsingDatas));
		break;
/* ANNECY MT - 18/09/98 {*/
	case OTI_AlwaysCreated:
		break;
/* END ANNECY MT }*/
	}
}
 
/*-----------------------------------------------------------------------------
 *  Description : Dynam's object action desinitialisation
 *-----------------------------------------------------------------------------
 *  Input :         When this function's called (see ObjInit.h)
 *  Output :        None
 *-----------------------------------------------------------------------------
 *  Creation date : 01/10/96            Author : Francois
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author :
 *  Modifications :
 *---------------------------------------------------------------------------*/
void fn_vDynamDesinit(struct tdstEngineObject_ *p_stObject,enum tdeObjectTreeInit_ eObjectInit)
{
	if (p_stObject==NULL)
		M_GameFatalError(E_uwGameMiniStructObjectNull);
	
	if (p_stObject->h_Dynam==NULL)
		M_GameFatalError(E_uwGameMiniStructNull);
	
	switch(eObjectInit)
	{
	case OTI_ReinitTheMap:
		break;
	case OTI_MapLoaded:
		/* Free only dynamics for always (because it's in TMP)*/
		if (DNM_M_bDynamicsIsAlways(p_stObject->h_Dynam->p_stDynamics))
			fn_v_DynamicFree( p_stObject->h_Dynam );
		break;
	case OTI_AlwaysCreated:
	case OTI_PlayerDead:
		break;
	default:
		break;
	}
}
 
/*-----------------------------------------------------------------------------
 *  Description : Dynam's object copy clone action
 *-----------------------------------------------------------------------------
 *  Input :         Handle to destination, handle to source
 *  Output :        None
 *-----------------------------------------------------------------------------
 *  Creation date : 30/06/97            Author : Olivier Jourdan
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author :
 *  Modifications :
 *---------------------------------------------------------------------------*/
void fn_vDynamCopyClone(struct tdstEngineObject_ * _p_stObjectDest,struct tdstEngineObject_ * _p_stObjectSrc)
{
	MS_tdxHandleToDynam hDest,hSrc;
	DNM_tdstDynamics *p_stSrcDynamic, *p_stDestDynamic;	
	eDynamicSize eSize;
	ACP_tdxBool bAlloc=TRUE;
	ACP_tdxBool bAlways;
 
	hDest = _p_stObjectDest->h_Dynam;
	hSrc  = _p_stObjectSrc->h_Dynam;
	p_stSrcDynamic = _p_stObjectSrc->h_Dynam->p_stDynamics;
	p_stDestDynamic = _p_stObjectDest->h_Dynam->p_stDynamics;
	if (!p_stSrcDynamic) return;
	
 
	bAlways = (ACP_tdxBool) fn_ucIsAnAlwaysObject (_p_stObjectDest);
 
	/* alloc */
/* Oliv' - Portage v15 - ???*/
/*#ifndef U64*/
	if (DNM_M_bDynamicsIsComplexSize(p_stSrcDynamic)) eSize = eDynamicSizeComplex;
	else if (DNM_M_bDynamicsIsAdvancedSize(p_stSrcDynamic)) eSize = eDynamicSizeAdvanced;
	else eSize = eDynamicSizeBase;
/*#else*/
/*	eSize = eDynamicSizeComplex;*/
/*#endif*/
/* EndOfOliv'*/
	
	if (p_stDestDynamic)
	{
		/* size */
		switch (eSize)
		{
		case eDynamicSizeComplex :
			bAlloc = (ACP_tdxBool)!DNM_M_bDynamicsIsComplexSize(p_stDestDynamic);
			break;
		case eDynamicSizeAdvanced :
			bAlloc = (ACP_tdxBool)!DNM_M_bDynamicsIsAdvancedSize(p_stDestDynamic);
			break;
		case eDynamicSizeBase :
			bAlloc = (ACP_tdxBool)!DNM_M_bDynamicsIsBaseSize(p_stDestDynamic);
			break;
		}
 
		/* collision */
		/* LOL*/
/*#ifndef U64*/
		if (DNM_M_bDynamicsIsCollisionReport(p_stSrcDynamic)!=DNM_M_bDynamicsIsCollisionReport(p_stDestDynamic))
			bAlloc = TRUE;
 
		if (bAlloc) fn_v_DynamicFree (hDest);
/*#endif*/
	}
	
	if (bAlloc) fn_v_DynamicAlloc ( hDest, eSize, (ACP_tdxBool)(DNM_M_bDynamicsIsCollisionReport(p_stSrcDynamic)), bAlways );
 
	/* copy */
	DNM_fn_vDynamicsCopyClone(hDest->p_stDynamics,hSrc->p_stDynamics);
	memcpy(hDest->p_stParsingDatas,hSrc->p_stParsingDatas,sizeof(DNM_tdstParsingDatas));
	hDest->eUsedMechanics = hSrc->eUsedMechanics;
 
	/* Set the always flag again, because it may have been changed by DNM_fn_vDynamicsCopyClone.*/
	DNM_M_vDynamicsSetAlways( hDest->p_stDynamics, bAlways );
}
 
void fn_vInitDynamicalFunctionPointer(MS_tdxHandleToDynam h_Dynam)
{
	DNM_fn_vDynamicsInitDefault(fn_p_stDynamGetDynamics(h_Dynam));
}
 
/*-----------------------------------------------------------------------------
 *  Description : Dynam access functions
 *-----------------------------------------------------------------------------
 *  Input :         MS_tdxHandleToDynam + (value)
 *  Output :        (value or pointer)
 *-----------------------------------------------------------------------------
 *  Creation date : 31/01/97            Author : Francois
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author :
 *  Modifications :
 *---------------------------------------------------------------------------*/
struct DNM_stDynamics *fn_p_stDynamGetDynamics(MS_tdxHandleToDynam h_Dynam)
{
 return(h_Dynam->p_stDynamics);
}
void fn_vDynamSetDynamics(MS_tdxHandleToDynam h_Dynam,struct DNM_stDynamics *p_stDynam)
{
 h_Dynam->p_stDynamics=p_stDynam;
}
DNM_tdstParsingDatas *fn_p_stDynamGetParsingDatas(MS_tdxHandleToDynam h_Dynam)
{
 return((h_Dynam->p_stParsingDatas));
}
void fn_vDynamSetParsingDatas(MS_tdxHandleToDynam h_Dynam,DNM_tdstParsingDatas *p_stParsingDatas)
{
 h_Dynam->p_stParsingDatas = p_stParsingDatas;
}
 
 
 
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
DNM_tdeMechanicsID fn_eDynamGetUsedMechanics(MS_tdxHandleToDynam h_Dynam)
{
	return (h_Dynam->eUsedMechanics);
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
 
void fn_vDynamSetUsedMechanics(MS_tdxHandleToDynam h_Dynam,DNM_tdeMechanicsID eUsedMechanics)
{
	h_Dynam->eUsedMechanics = eUsedMechanics;
}
 
 
/* ANNECY MT - 25/08/98 {
MTH3D_tdstVector *fn_p_DynamGetCheckedSpeed(MS_tdxHandleToDynam h_Dynam,unsigned long _ul)
{
	if ( _ul < C_ucNbOfCheckedSpeeds )
		return (&(h_Dynam ->AveragePosition.a_CheckedSpeed[_ul]));
	return NULL;
}
 
void fn_vDynamSetCheckedSpeed(MS_tdxHandleToDynam h_Dynam,unsigned long _ul,MTH3D_tdstVector *p_Speed)
{
	if ( _ul < C_ucNbOfCheckedSpeeds )
	{
		MTH3D_M_vCopyVector((&(h_Dynam->AveragePosition.a_CheckedSpeed[_ul])),p_Speed);
	}
	else
		MTH3D_M_vNullVector(&(h_Dynam ->AveragePosition.a_CheckedSpeed[_ul]));
}
 
 
MTH_tdxReal fn_xDynamGetCheckedTime(MS_tdxHandleToDynam h_Dynam,unsigned long _ul)
{
	if ( _ul < C_ucNbOfCheckedSpeeds )
		return (h_Dynam ->AveragePosition.a_CheckedTime[_ul]);
	return 0;
}
 
void fn_vDynamSetCheckedTime(MS_tdxHandleToDynam h_Dynam,unsigned long _ul,MTH_tdxReal _dt)
{
	if ( _ul < C_ucNbOfCheckedSpeeds )
	{
		h_Dynam ->AveragePosition.a_CheckedTime[_ul] = _dt;
	}
	else
		h_Dynam ->AveragePosition.a_CheckedTime[_ul] = 0;
}
 
 
 
MTH3D_tdstVector *fn_p_DynamGetCheckedPos(MS_tdxHandleToDynam h_Dynam,unsigned long _ul)
{
	if ( _ul < C_ucNbOfCheckedSpeeds )
		return (&(h_Dynam ->AveragePosition.a_CheckedPos[_ul]));
	return NULL;
}
 
void fn_vDynamSetCheckedPos(MS_tdxHandleToDynam h_Dynam,unsigned long _ul,MTH3D_tdstVector *p_Pos)
{
	if ( _ul < C_ucNbOfCheckedSpeeds )
	{
		MTH3D_M_vCopyVector((&(h_Dynam->AveragePosition.a_CheckedPos[_ul])),p_Pos);
	}
	else
		MTH3D_M_vNullVector(&(h_Dynam ->AveragePosition.a_CheckedPos[_ul]));
}
 
 
tdstSightAxisSystem *fn_p_DynamGetSightAxisSystem(MS_tdxHandleToDynam h_Dynam)
{
	return &(h_Dynam->stSightAxisSystem);
}
 
 
MTH3D_tdstVector *fn_p_DynamGetSightAxis(MS_tdxHandleToDynam h_Dynam)
{
	return (&(h_Dynam->stSightAxisSystem.SightAxis));
}
 
MTH3D_tdstVector *fn_p_DynamGetFirstComplementaryAxis(MS_tdxHandleToDynam h_Dynam)
{
	return (&(h_Dynam->stSightAxisSystem.FirstComplementaryAxis));
}
 
MTH3D_tdstVector *fn_p_DynamGetSecondComplementaryAxis(MS_tdxHandleToDynam h_Dynam)
{
	return (&(h_Dynam->stSightAxisSystem.SecondComplementaryAxis));
}
 
 
void fn_vDynamSetSightAxisSystem(MS_tdxHandleToDynam h_Dynam,tdstSightAxisSystem *p_stAxisSystem)
{
	MTH3D_M_vCopyVector(&(h_Dynam->stSightAxisSystem.SightAxis),
		&(p_stAxisSystem->SightAxis));
	MTH3D_M_vCopyVector(&(h_Dynam->stSightAxisSystem.FirstComplementaryAxis),
		&(p_stAxisSystem->FirstComplementaryAxis));
	MTH3D_M_vCopyVector(&(h_Dynam->stSightAxisSystem.SecondComplementaryAxis),
		&(p_stAxisSystem->SecondComplementaryAxis));
}
 
 
void fn_vDynamSetSightAxis(MS_tdxHandleToDynam h_Dynam,MTH3D_tdstVector *p_stVector)
{
	MTH3D_M_vCopyVector(&(h_Dynam->stSightAxisSystem.SightAxis), p_stVector);
}
 
void fn_vDynamSetFirstComplementaryAxis(MS_tdxHandleToDynam h_Dynam,MTH3D_tdstVector *p_stVector)
{
	MTH3D_M_vCopyVector(&(h_Dynam->stSightAxisSystem.FirstComplementaryAxis), p_stVector);
 
}
 
void fn_vDynamSetSecondComplementaryAxis(MS_tdxHandleToDynam h_Dynam,MTH3D_tdstVector *p_stVector)
{
	MTH3D_M_vCopyVector(&(h_Dynam->stSightAxisSystem.SecondComplementaryAxis), p_stVector);
 
}
 
void fn_vGetPersoSightAxisSystem
(
	HIE_tdxHandleToSuperObject 	_hPerso,
	MTH3D_tdstVector			*_p_stSightAxis,
	MTH3D_tdstVector			*_p_stFirstComplementaryAxis,
	MTH3D_tdstVector			*_p_stSecondComplementaryAxis
)
{
	MS_tdxHandleToDynam h_Dynam;
 
	if((h_Dynam = M_GetMSHandle(_hPerso,Dynam)) == NULL )
  {
		MTH3D_M_vSetBaseJVector(_p_stSightAxis);
		MTH3D_M_vSetBaseJVector(_p_stFirstComplementaryAxis);
		MTH3D_M_vSetBaseJVector(_p_stSecondComplementaryAxis);
    return;
  }
 
	MTH3D_M_vCopyVector(_p_stSightAxis , fn_p_DynamGetSightAxis(h_Dynam));
	MTH3D_M_vCopyVector(_p_stFirstComplementaryAxis , fn_p_DynamGetFirstComplementaryAxis(h_Dynam));
	MTH3D_M_vCopyVector(_p_stSecondComplementaryAxis , fn_p_DynamGetSecondComplementaryAxis(h_Dynam));
}
END ANNECY MT } */
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
void fn_v_DynamUpdateDNMObjectTypeFromMS(struct tdstDynam_ *p_stDynam)
{
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
 
/*ANNECY jt {*/
struct DNM_stDynamics* fn_p_stDynamGetDynamicsSO (HIE_tdxHandleToSuperObject hSupObj)
{
	MS_tdxHandleToDynam h_Dynam;
	HIE_tdxHandleToVoid h_Object;
	struct DNM_stDynamics* p_stDynamics = NULL;
 
	h_Object = HIE_fn_hGetSuperObjectObject(hSupObj);
 
	if (h_Object)
	{
		h_Dynam = M_GetMSHandle (hSupObj,Dynam);
		if (h_Dynam) p_stDynamics = fn_p_stDynamGetDynamics (h_Dynam);
	}
 
	return p_stDynamics;
}
 
/*vient de AI\AiTools.c*/
/********************************************************************************************
*  Set the position of p_SuperObjPerso to p_stVertex. Do not make the mecanic collision test.
*********************************************************************************************/
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
ACP_tdxBool fn_bSetPositionWithoutCollideTest(HIE_tdxHandleToSuperObject p_SuperObjPerso, MTH3D_tdstVector *p_stVertex)
{
	/* Set the new position*/
	POS_fn_vSetTranslationVector(HIE_fn_hGetSuperObjectGlobalMatrix(p_SuperObjPerso),p_stVertex);
	POS_fn_vSetTranslationVector(HIE_fn_hGetSuperObjectMatrix(p_SuperObjPerso),p_stVertex);
 
	return TRUE;
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
/*ENDANNECY jt }*/
