/*---------------------------------------------------------------------------*/
/* Intell.h : Test pour le module d'intelligence.*/
/* auteur : Olivier Didelot.*/
/* date   : 07/08/1996*/
/* 970120 :	fnc fn_vInterpretComportNPerso					(Fabien Morales) */
/*---------------------------------------------------------------------------*/
#if !defined(__INTELL_H__)
#define __INTELL_H__
 
struct tdstGetSetParam_;
struct tdstIntelligence_;
#if defined(ACTIVE_EDITOR)
  /* to active error intercepting while running : not finished yet*/
  #define ACTIVE_EXEC_CHECKING
  #if defined(ACTIVE_EXEC_CHECKING)
    /*#pragma message("ACTIVE_EXEC_CHECKING is defined ==> editor will run automaticaly if an error occured in AI while running");*/
  #endif
#endif
 
/*///////////////////////////////////////////////////////////////////////////*/
/* PLEASE Never use p_stEvalTree directly, but use theses macros instead ! //*/
/*///////////////////////////////////////////////////////////////////////////*/
 
/* Oliv' - 27/11/1998*/
#ifdef U64_AIDEBUG
struct AI_tdstMind_ *fn_p_stGetCurrentMind();
void fn_v_SetCurrentMind(struct AI_tdstMind_ *p_stMind);
#endif /* U64_AIDEBUG */
/* EndOfOliv'*/
 
/*** DR ***/
#if ( (defined(ACTIVE_EXEC_CHECKING) && defined(ACTIVE_EDITOR)) || defined(ACTIVE_AIDEBUG) ) && !defined(U64_AIDEBUG)
 
void fn_vSetStopAIEngineFlag();
/*void fn_vReSetStopAIEngineFlag(); *** DR ****/
unsigned char fn_ucGetStopAIEngineFlag();
struct AI_tdstMind_ *fn_p_stGetCurrentMind();
void fn_v_SetCurrentMind(struct AI_tdstMind_ *p_stMind);
unsigned char fn_ucGetErrorFlag(HIE_tdxHandleToSuperObject p_SuperObjPerso);
 
#include "ActConst.h"
 
#include "AI_Struc.h"
 
#define M_EvalOneParameter(p_SuperObjPerso,p_stTreeOut,p_stTreeIn,p_stParam) \
	    if ( (!fn_ucGetErrorFlag(p_SuperObjPerso)) && (!fn_ucGetStopAIEngineFlag()) ) \
          (p_stTreeOut) = fn_p_stEvalTree( (p_SuperObjPerso), (p_stTreeIn), (p_stParam) ); \
		if ( (fn_ucGetErrorFlag(p_SuperObjPerso)) || fn_ucGetStopAIEngineFlag() ) \
		{ \
			M_Full_GetSetParam_ActionReturn((p_stParam), (C_ACTION_FINISHED | C_ACTION_ENGINE_STOP)); \
			return((p_stTreeOut)); \
		}
#else
 
#define M_EvalOneParameter(p_SuperObjPerso,p_stTreeOut,p_stTreeIn,p_stParam) \
        (p_stTreeOut) = fn_p_stEvalTree( (p_SuperObjPerso), (p_stTreeIn), (p_stParam) ); 
 
#endif
 
#define M_EvalTwoParameters(p_SuperObjPerso,p_stTreeOut,p_stTreeIn,p_stParam1,p_stParam2) \
	    M_EvalOneParameter((p_SuperObjPerso),(p_stTreeOut),(p_stTreeIn),(p_stParam1)); \
	    M_EvalOneParameter((p_SuperObjPerso),(p_stTreeOut),(p_stTreeIn),(p_stParam2)); \
 
#define M_EvalNextParameter(p_stValue) \
		M_EvalOneParameter(p_SuperObjPerso,p_stTree,p_stTree,(p_stValue)) \
 
#define M_EvalNextTwoParameter() \
	    M_EvalNextParameter(&stParam1); \
		M_EvalNextParameter(&stParam2); 
 
#define M_vEvalNextVarId(p_stResultMind, ucResultVarId) \
{ \
  HIE_tdxHandleToSuperObject p_stResultOwnerPerso; \
  if ( M_GetTypeInterpret(p_stTree) == E_ti_Operator ) /* if the dsgvar is passed through an ultra operator, parse it */ \
  { \
    /* make sure it is an ultra operator */ \
    SAF_M_AssertWithMsg((M_eOperatorIdInterpret(p_stTree) == eOperator_Dot),"the argument is not a dsgvar reference"); \
    /* skip the operator node to go to the arguments */ \
    p_stTree ++; \
    /* get the perso argument of the ultra operator */ \
    p_stTree = fn_p_stOperatorGetPerso(p_SuperObjPerso,p_stTree,&p_stResultOwnerPerso); \
  } \
  else \
    /* the dsgvar reference is owned by the calling instance */ \
    p_stResultOwnerPerso = p_SuperObjPerso; \
\
  /* get the mind of the owning perso (where the dsgvar is stored */ \
  p_stResultMind = AI_M_stGetMindOfSuperObj(p_stResultOwnerPerso); \
  /* get the dsgvar index (the second argument of the ultra operator if relevant */ \
  ucResultVarId = M_ucVarIdInterpret(p_stTree); \
  p_stTree ++; \
}
 
struct tdstNodeInterpret_ *fn_p_stSwapNextParameter(struct tdstNodeInterpret_ *p_stTree);
struct tdstNodeInterpret_ *fn_p_stSwapNextParameter2(struct tdstNodeInterpret_ *p_stTree);
struct tdstNodeInterpret_ *fn_p_stSkipThisArgument(struct tdstNodeInterpret_ *p_stTree);
struct tdstNodeInterpret_ *fn_p_stEvalTree(HIE_tdxHandleToSuperObject p_SuperObjPerso, struct tdstNodeInterpret_ *p_stTree, struct tdstGetSetParam_ *p_stValue);
struct tdstNodeInterpret_ *fn_p_stIntelligenceEvalTreeEngine(HIE_tdxHandleToSuperObject p_SuperObjPerso, struct tdstNodeInterpret_ *p_stTree, struct tdstGetSetParam_ *p_stValue);
ACP_tdxBool fn_bIntelligenceEngine(HIE_tdxHandleToSuperObject p_SuperObjPerso, struct tdstIntelligence_ *p_stIntelligence);
 
#if defined(__DEBUG_AI__)
void fn_vTestGetDsgVarOrField(unsigned char choice,unsigned char ucVarId,unsigned char ucIndex,enum tdeFieldId_ eFieldId,HIE_tdxHandleToSuperObject p_SuperObjPerso ,struct tdstGetSetParam_ *p_stValue);
#endif
 
#include "TypePtr.h"
void fn_vSetProcedureActionReturn(tducActionReturn ucActionReturn);
tducActionReturn fn_ucGetProcedureActionReturn(void); /*AR980313*/
 
/*////////////////////*/
/* Global Variables //*/
/*////////////////////*/
#undef EXTERN
#undef extern
#if !defined(__DeclareGlobalVariableIntell_h__)
#define EXTERN extern
#else
#define EXTERN
#endif /*__DeclareGlobalVariableIntell_h__*/
 
EXTERN struct tdstIntelligence_ *g_p_stIntelligence;
EXTERN unsigned char g_ucNRule;
EXTERN ACP_tdxBool bSomethingDone;
 
#endif /* __INTELL_H__*/
