/*******************************************************/
/**** 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 "ObjInit.h"
#include "ObjType.h"
#include "ZeMem.h"
#include "ia_dnm.h"
 
#include "ldt.h"
 
#define lTagSlideFactorX 'Xrot'
#define lTagSlideFactorY 'Yrot'
#define lTagSlideFactorZ 'Zrot'
 
/*****************************************************************
Name: 
Description: Create callback for LDT
Author: Mircea Petrescu
Date: 8/24/98
Modified: Ovidiu Scripa 01/09/98; 13/10/98
*****************************************************************/
int fn_iCreateDynam( LDT_tdst_Link *pLink )
{
    MS_tdxHandleToDynam h_Dynam;
    struct tdstEngineObject_ *p_stEngineObject=(struct tdstEngineObject_ *)pLink->pParent->pObject;
    DNM_tdstDynamics* p_stDynamics;
    ACP_tdxBool bCanHangOn;
    long lObjectType;
    unsigned char ucTypeOfObject;
    ACP_tdxBool bIsMobile;
    char *szP0;
    int nNoParams;
	ACP_tdxBool bBase, bAdvanced, bComplex;
	ACP_tdxBool bCollision;
	eDynamicSize eSize;
 
    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();
    nNoParams = LDT_iGetNbParams();
    if (nNoParams>=2)
    {
        szP0 = LDT_szGetParam(1);
 
		if (!strcmp (szP0,C_szDynamicSizeBase)) 
            eSize=eDynamicSizeBase;
		else if (!strcmp (szP0,C_szDynamicSizeAdvanced)) 
            eSize=eDynamicSizeAdvanced;
		else if (!strcmp (szP0,C_szDynamicSizeComplex)) 
            eSize=eDynamicSizeComplex;
 
        if (nNoParams==3)
            bCollision = (ACP_tdxBool)atoi (LDT_szGetParam(2));
    }
	fn_v_DynamicAlloc ( h_Dynam, eSize, bCollision );
	
    MMG_fn_vEndMemoryInfo ();
 
    p_stEngineObject->h_Dynam=h_Dynam;
 
    lObjectType = DNM_C_lObjectType_SolidMobile;
    ucTypeOfObject = DNM_C_lObjectType_Solid;
    bIsMobile = TRUE;
    bCanHangOn = TRUE;
 
    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 );
    }
    pLink->pObject=(void *)h_Dynam;
    return 0;
}
 
 
/*****************************************************************
Name: 
Description: Load callback for LDT
Author: Mircea Petrescu
Date: 8/24/98
Modified: Ovidiu Scripa 09/01/98; 13/10/98
*****************************************************************/
int fn_iLoadDynam( LDT_tdst_Link *pLink )
{
 LDT_tdeParseResult result=ParseResult_BeginSection;
 MS_tdxHandleToDynam h_Dynam=(MS_tdxHandleToDynam)pLink->pObject;
 struct tdstEngineObject_ *p_stEngineObject=(struct tdstEngineObject_ *)pLink->pParent->pObject;
 ACP_tdxBool bCanHangOn;
 long lObjectType;
 unsigned char ucTypeOfObject;
 ACP_tdxBool bIsMobile;
 DNM_tdstDynamics* p_stDynamics = fn_p_stDynamGetDynamics(p_stEngineObject->h_Dynam);
 
 
 lObjectType = DNM_C_lObjectType_SolidMobile;
 ucTypeOfObject = DNM_C_lObjectType_Solid;
 bIsMobile = TRUE;
 bCanHangOn = TRUE;
 
  while( result!=ParseResult_EndSection ) 
  {
  	result=LDT_GetNextEntry();
	/* this test is only usefull to read old .car */
	if (DNM_M_bDynamicsIsAdvancedSize(p_stDynamics))
	{
 
  	    switch( result )
  	    {
  	      case ParseResult_Entry: /* an entry */
  	      {
  	        char *szEntry=LDT_szGetEntryName();
  	        switch (*(long*)(szEntry+8))
  	        {
  	          case  lTagSlideFactorX: /*  */
  	          {
						    DNM_M_vDynamicsSetSlideFactorX (p_stDynamics, MTH_M_xDoubleToReal(atof(LDT_szGetParam(1))));
  	          }
  	          break;
  	          case  lTagSlideFactorY: /*  */
  	          {
						    DNM_M_vDynamicsSetSlideFactorY (p_stDynamics, MTH_M_xDoubleToReal(atof(LDT_szGetParam(1))));
  	          }
  	          break;
  	          case  lTagSlideFactorZ: /*  */
  	          {
						    DNM_M_vDynamicsSetSlideFactorZ (p_stDynamics, MTH_M_xDoubleToReal(atof(LDT_szGetParam(1))));
  	          }
  	          break;
  	        }
  	      }
  	    }
    }
  }
 
 
  return 0;
}
 
