#define D_MainChar_StructureDefine
/*----------------------------------------------------------------------
 * Includes
 *--------------------------------------------------------------------*/
 
#include "ToolsCPA.h"
 
#include "macros.h"
#include "GameEng.h"
 
#include "Actions/AllActs.h"
 
#include "Structur/GameScpt.h"
#include "Structur/ErrGame.h"
#include "Structur/MemGame.h"
#include "Structur/StdObjSt.h"
#include "Structur/EngMode.h"
#include "Structur/Objects.h"
 
#include "MainChar.h"
#include "Zemem.h"
/*----------------------------------------------------------------------
 * Functions
 *--------------------------------------------------------------------*/
MC_tdxHandleToMainCharacterNode MC_fn_hCreateMainCharacterNode()
{
   tdstNodeMainCharacter * p_stMainCharNode;
 
   MMG_fn_vAddMemoryInfo( MMG_C_lTypeGAM , MMG_C_lSubTypeMainChar , 0);
   p_stMainCharNode=(tdstNodeMainCharacter *)M_p_GameMallocInHLM(sizeof(tdstNodeMainCharacter));
   LST2_M_DynamicInitElement(p_stMainCharNode);
 
   /* O.D.*/
   MC_fn_vSetNewMainCharacter((MC_tdxHandleToMainCharacterNode)p_stMainCharNode, (HIE_tdxHandleToSuperObject)NULL);
 
   return( (MC_tdxHandleToMainCharacterNode)p_stMainCharNode );
}
/*--------------------------------------------------------------------*/
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
void MC_fn_vFreeMainCharacterNode(MC_tdxHandleToMainCharacterNode hMainCharNode)
{
   MMG_fn_vAddMemoryInfo( MMG_C_lTypeGAM , MMG_C_lSubTypeMainChar , 0);
   M_GameFreeInHLM((tdstNodeMainCharacter *)hMainCharNode);
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
/*--------------------------------------------------------------------*/
void MC_fn_vAddCharacterInMainCharacterList(HIE_tdxHandleToSuperObject hCharacter)
{
   MC_tdxHandleToMainCharacterNode hMainCharNode;
 
   hMainCharNode=MC_fn_hCreateMainCharacterNode();
   MC_fn_vSetCharacterInMainCharacterNode(hMainCharNode,hCharacter);
   LST2_M_DynamicAddTail(&g_stEngineStructure.hMainCharacterList,hMainCharNode);
   SAI_fn_bInsertPointerInTable(&hMainCharNode->hCharacter,SAI_eInitWhenPlayerDead|SAI_eInitWhenReinitTheMap|SAI_eInitWhenMapLoaded);
/**** DFM : Tant que le block ACP merde, il ne faut pas vers de référence dans SAI ****/
/*   SAI_fn_bInsertPointerInTable(&hMainCharNode->hCharacter,SAI_ePlayerSaveCurrentValue);*/
}
/*--------------------------------------------------------------------*/
 
#ifndef _FIRE_DEADCODE_U64_
 
void MC_fn_vRemoveCharacterinMainCharacterList(HIE_tdxHandleToSuperObject hCharacter)
{
   unsigned short uwI;
   MC_tdxHandleToMainCharacterNode hMainCharNode = NULL,hMainCharGoodNode = NULL;
 
   LST2_M_DynamicForEachElementOf(&g_stEngineStructure.hMainCharacterList,hMainCharNode,uwI)
   {
      if( MC_fn_hGetCharacterInMainCharacterNode(hMainCharNode)==hCharacter )
         hMainCharGoodNode=hMainCharNode;
   }
   SAI_fn_bRemoveValueFromTable(&hMainCharNode->hCharacter,SAI_eInitWhenPlayerDead|SAI_eInitWhenReinitTheMap|SAI_eInitWhenMapLoaded);
/*   SAI_fn_bRemoveValueFromTable(&hMainCharNode->hCharacter,SAI_ePlayerSaveCurrentValue);*/
 
   LST2_M_DynamicIsolate(hMainCharGoodNode);
   MC_fn_vFreeMainCharacterNode( hMainCharGoodNode );
}
 
 
/*--------------------------------------------------------------------*/
unsigned char MC_fn_ucIsCharacterInMainCharacterList(HIE_tdxHandleToSuperObject hCharacter)
{
 unsigned short uwI;
 MC_tdxHandleToMainCharacterNode hMainCharNode;
 
 LST2_M_DynamicForEachElementOf(&g_stEngineStructure.hMainCharacterList,hMainCharNode,uwI)
 {
  if( MC_fn_hGetCharacterInMainCharacterNode(hMainCharNode)==hCharacter )
   return(TRUE);
 }
 return(FALSE);
}
 
#endif /* _FIRE_DEADCODE_U64_ */
 
/*--------------------------------------------------------------------*/
void MC_fn_vSetCharacterInMainCharacterNode(MC_tdxHandleToMainCharacterNode hMainCharNode,HIE_tdxHandleToSuperObject hCharacter)
{
   ((tdstNodeMainCharacter *)hMainCharNode)->hCharacter=hCharacter;
}
/*--------------------------------------------------------------------*/
HIE_tdxHandleToSuperObject MC_fn_hGetCharacterInMainCharacterNode(MC_tdxHandleToMainCharacterNode hMainCharNode)
{
   return( ((tdstNodeMainCharacter *)hMainCharNode)->hCharacter );
}
/*--------------------------------------------------------------------*/
MC_tdxHandleToMainCharacterNode MC_fn_hGetFirstMainCharNode()
{
   return( LST2_M_DynamicGetFirstElement(&g_stEngineStructure.hMainCharacterList) );
}
/*--------------------------------------------------------------------*/
 
 
 
MC_tdxHandleToMainCharacterNode MC_fn_hGetNextMainCharNode(MC_tdxHandleToMainCharacterNode hMainCharNode)
{
   return( LST2_M_DynamicGetNextElement(hMainCharNode) );
}
/*--------------------------------------------------------------------*/
#ifndef _FIRE_DEADCODE_U64_
void MC_fn_vCopyStruct_MainCharNode(MC_tdxHandleToMainCharacterNode hDest,MC_tdxHandleToMainCharacterNode hSrc)
{
   MC_fn_vSetCharacterInMainCharacterNode(hDest,MC_fn_hGetCharacterInMainCharacterNode(hSrc));
}
 
#endif /* _FIRE_DEADCODE_U64_ */
 
/*--------------------------------------------------------------------*/
 
/* O.D. 15/8/97*/
/*--------------------------------------------------------------------------
 * Functions to modify the MainCharacter.
 * The Engine can modify the MainCharacter only on the beginning of a frame.
 *--------------------------------------------------------------------------*/
void MC_fn_vSetNewMainCharacter(MC_tdxHandleToMainCharacterNode hMainCharNode,HIE_tdxHandleToSuperObject hCharacter)
{
	((tdstNodeMainCharacter *)hMainCharNode)->hNewCharacterForTheNextFrame = hCharacter;
}
 
HIE_tdxHandleToSuperObject MC_fn_hGetNewMainCharacter(MC_tdxHandleToMainCharacterNode hMainCharNode)
{
	return (((tdstNodeMainCharacter *)hMainCharNode)->hNewCharacterForTheNextFrame);
}
 
#undef D_MainChar_StructureDefine
