/*---------------------------------------------------------------------------*/
/* Action parameters functions and macros for intelligence engine*/
/* author : Olivier Couvreur*/
/* date   : 7/11/1996*/
/* modify : Fabien MORALES*/
/* date   : 29/01/1997  Vertex param*/
/* modify : Olivier Couvreur*/
/* date   : 03/02/1997  Lint 0 warnings*/
/* modify : Olivier Couvreur*/
/* date   : 09/02/1997  error handling*/
/* modify : Olivier Couvreur 23/04/97 MMG + DIR*/
/*---------------------------------------------------------------------------*/
 
#include "AIUseCPA.h"
 
#include "specif/AIOption.h"
#include "AIMacros.h"
#include "AI_Erm.h"
 
#include "StrIntel.h"
#include "AI_Struc.h"
#include "specif/ActTable.h"
 
/* XB 20/05/1999 */
#ifndef D_THROW_COMPLEX_ACTION_TABLE

#define M_ActionParam(n) M_ActionTableParam((n),M_ActionTableCurrentEntry(n))
/* En Bref un truc du genre*/
/* M_ActionParam(p_stIntellOrReflex)*/
/* =*/
/* p_stIntelligence->stActionTable.a_stEntry[p_stIntelligence->stActionTable.ucCurrentEntry].stActionParam*/

#else /* D_THROW_COMPLEX_ACTION_TABLE */

#define M_ActionParam(n) M_ActionTableParam0((n))

#endif /* D_THROW_COMPLEX_ACTION_TABLE */
/* End XB 20/05/1999 */
 
#define M_InternalSetActionParam(p_SuperObjPerso, ucN, Value, AccesMacro) \
  tdstIntelligence *p_stIntellOrReflex = M_GetIntellOrReflex(AI_M_stGetMindOfSuperObj((p_SuperObjPerso))); \
##AccesMacro(&M_ActionParam(p_stIntellOrReflex).a_uParam[(ucN)]) = (Value);
 
#if defined(__DEBUG_AI__)
#define M_SetActionParam(p_SuperObjPerso, ucN, Value, AccesMacro) \
  if (ucN<C_MAX_NB_PARAM) \
    {\
    M_InternalSetActionParam(p_SuperObjPerso, ucN, Value, AccesMacro); \
    }\
    else\
    {\
    M_AIFatalError(E_uwAIFatalInvalidParameter);\
    }
#else
#define M_SetActionParam(p_SuperObjPerso, ucN, Value, AccesMacro) M_InternalSetActionParam(p_SuperObjPerso, ucN, Value, AccesMacro); 
#endif /* __DEBUG_AI__*/
 
#define M_InternalGetActionParam(p_SuperObjPerso, ucN, AccesMacro) \
  tdstIntelligence *p_stIntellOrReflex = M_GetIntellOrReflex(AI_M_stGetMindOfSuperObj((p_SuperObjPerso))); \
return(##AccesMacro(&M_ActionParam(p_stIntellOrReflex).a_uParam[(ucN)]));
 
#if defined(__DEBUG_AI__)
#define M_GetActionParam(p_SuperObjPerso, ucN, DefaultReturnValue, AccesMacro) \
  if (ucN<C_MAX_NB_PARAM) \
    {\
    M_InternalGetActionParam(p_SuperObjPerso, ucN, AccesMacro); \
    }\
    else\
    {\
    M_AIFatalError(E_uwAIFatalInvalidParameter);\
    return DefaultReturnValue; \
    }
#else
#define M_GetActionParam(p_SuperObjPerso, ucN, DefaultReturnValue, AccesMacro) M_InternalGetActionParam(p_SuperObjPerso, ucN, AccesMacro); 
#endif /* __DEBUG_AI__*/
 
/****************************************************************************************/
/* ACCESS TO ACTION PARAMETERS                                                          */
/****************************************************************************************/
 
/* REAL_PARAM*/
void fn_vSetActionParamxValue(unsigned char ucN, HIE_tdxHandleToSuperObject p_SuperObjPerso, MTH_tdxReal xValue)
{
  M_SetActionParam(p_SuperObjPerso, ucN, xValue, M_tduGetSetParam_xValue);
}
 
MTH_tdxReal fn_xGetActionParamxValue(unsigned char ucN, HIE_tdxHandleToSuperObject p_SuperObjPerso)
{
  M_GetActionParam(p_SuperObjPerso, ucN, MTH_M_xLongToReal(0), M_tduGetSetParam_xValue);
}
 
 
/* CGHT */
/* LIPSYNCHRO_PARAM*/
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
void fn_vSetActionParamhLipsSynchro(unsigned char ucN, HIE_tdxHandleToSuperObject p_SuperObjPerso,tdxHandleOfLipsSynchroTable hLipsSynchro)
{
  M_SetActionParam(p_SuperObjPerso, ucN, hLipsSynchro, M_tduGetSetParam_hLipsSynchro);
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
tdxHandleOfLipsSynchroTable fn_p_stGetActionParamhLipsSynchro(unsigned char ucN, HIE_tdxHandleToSuperObject p_SuperObjPerso)
{
  M_GetActionParam(p_SuperObjPerso, ucN, NULL, M_tduGetSetParam_hLipsSynchro);
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
/* CONSTANT_PARAM*/
void fn_vSetActionParamlValue(unsigned char ucN, HIE_tdxHandleToSuperObject p_SuperObjPerso, long lValue)
{
  M_SetActionParam(p_SuperObjPerso, ucN, lValue, M_tduGetSetParam_lValue);
}
 
long fn_lGetActionParamlValue(unsigned char ucN, HIE_tdxHandleToSuperObject p_SuperObjPerso)
{
  M_GetActionParam(p_SuperObjPerso, ucN, 0, M_tduGetSetParam_lValue);
}
 
/* ACTION_PARAM*/
void fn_vSetActionParamStateValue(unsigned char ucN, HIE_tdxHandleToSuperObject p_SuperObjPerso, tdxHandleToState hState)
{    
  M_SetActionParam(p_SuperObjPerso, ucN, hState, M_tduGetSetParam_HandleToState);
}
 
tdxHandleToState fn_xGetActionParamStateValue(unsigned char ucN, HIE_tdxHandleToSuperObject p_SuperObjPerso)
{
  M_GetActionParam(p_SuperObjPerso, ucN, NULL, M_tduGetSetParam_HandleToState);
}
 
 
/* VERTEX_PARAM*/
void fn_vSetActionParamp_stVertex(unsigned char ucN, HIE_tdxHandleToSuperObject p_SuperObjPerso, MTH3D_tdstVector *p_stVertex)
{	
#if defined(__DEBUG_AI__)
  if (ucN < C_MAX_NB_PARAM)
  {
#endif
    tdstIntelligence *p_stIntellOrReflex = M_GetIntellOrReflex(AI_M_stGetMindOfSuperObj(p_SuperObjPerso));
    MTH3D_M_vCopyVector( &M_tduGetSetParam_stVertexValue(&M_ActionParam(p_stIntellOrReflex).a_uParam[ucN]), p_stVertex );
#if defined(__DEBUG_AI__)
  }
  else
  {
    M_AIFatalError(E_uwAIFatalInvalidParameter);
  }
#endif
}
 
MTH3D_tdstVector *fn_p_stGetActionParamp_stVertex(unsigned char ucN, HIE_tdxHandleToSuperObject p_SuperObjPerso)
{
  tdstIntelligence *p_stIntellOrReflex = M_GetIntellOrReflex(AI_M_stGetMindOfSuperObj(p_SuperObjPerso));
#if defined(__DEBUG_AI__)
  if (ucN < C_MAX_NB_PARAM)
  {
#endif
    return(&M_tduGetSetParam_stVertexValue(&M_ActionParam(p_stIntellOrReflex).a_uParam[ucN]) );
#if defined(__DEBUG_AI__)
  }
  else
  {
    M_AIFatalError(E_uwAIFatalInvalidParameter);
    return(NULL);
  }
#endif
}
