/*---------------------------------------------------------------------------*/ /* Strintel.cpp : Definition des fonctions utiles pour manipuler les structures*/ /* de donnée du module d'intelligence.*/ /* auhor : Olivier Didelot 08/08/96*/ /* modify : Olivier Didelot 21/10/96*/ /* .....???????????*/ /* modify : Olivier Couvreur 04/02/97 Lint 0 warnings excepted those specified at the end of AIMacros.h*/ /* modify : Olivier Couvreur 14/02/97 Creation of Deallocation functions*/ /* modify : Olivier Couvreur 18/02/97 CPA_EXPORT + new functions for editor*/ /* modify : Olivier Couvreur 05/03/97 Model can be gathered between several perso + Alloc and Free functions rewritten + Lint*/ /* modify : Olivier Couvreur 11/03/97 .dec can be gathered between several perso + Alloc and Free functions rewritten + Lint*/ /* modify : Olivier Couvreur 25/03/97 NbNode is not an unsigned char anymore + NoComportInit support + minor changes for editor*/ /* modify : Olivier Couvreur 29/04/97 Init Comport and .IAI support + DsgVar Perso*/ /*---------------------------------------------------------------------------*/ #include "AIUseCPA.h" #include "specif/AIOption.h" #include "AIMacros.h" #include "AI_Mmg.h" #include "AI_Erm.h" #include "AI_Struc.h" #include "AI_Proto.h" #include "DsgMem.h" #include "specif/ActTable.h" #include "StrIntel.h" #include "Intell.h" #include "Convert.h" #if defined(ACTIVE_AIDEBUG) /*** DR ***/ #include "AID_Erm.h" #include "specif/AID_Trac.h" #endif /*ACTIVE_AIDEBUG*/ void fn_vOnAIErm_M_UpdateLastError(unsigned short FatalErrorNum,char *szMsg) { Erm_M_UpdateLastError(AI, C_ucErmDefaultChannel, FatalErrorNum, C_lErmNoDebugData, C_ucErmOpenInfoWindow, C_ucAllowStopForDebug, szMsg); } void fn_vErrorOnAIAlloc() { M_AIIfErrorUpdateFatalError(Mmg, E_uwAIFatalFailedAllocationMem); } #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ void fn_vErrorOnAIFree() { M_AIIfErrorUpdateWarningError (Mmg, E_uwAIWarningCanNotFree, C_ucErmOpenInfoWindow); } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */ void fn_vReinitComport(tdstIntelligence *p_stIntelligence) { (void) fn_ucChangeComportIntell(p_stIntelligence, (tdstComport *)M_GetNoComportInit(p_stIntelligence)); M_GetPrevComport(p_stIntelligence) = M_GetCurrentComport(p_stIntelligence); } unsigned char fn_ucChangeComportIntell(tdstIntelligence *p_stIntelligence, tdstComport *p_stComport) { #if defined(__DEBUG_AI__) long lComport=(p_stComport-M_GetComport(p_stIntelligence)); if ( (lComport<0) || (lComport>=(long) M_GetNbComport(p_stIntelligence)) ) { M_AIWarningErrorAndNeverStopForDebug(E_uwAIWarningComportOfAnotherPerso, C_ucErmOpenInfoWindow,M_GetNameComport(p_stComport)); #if defined(ACTIVE_EDITOR) && defined(ACTIVE_EXEC_CHECKING) fn_vSetStopAIEngineFlag(); #endif return(FALSE); } else #endif { M_GetPrevComport(p_stIntelligence) = M_GetCurrentComport(p_stIntelligence); M_GetCurrentComport(p_stIntelligence) = p_stComport; fn_vInitActionTable(p_stIntelligence); /* Update new schedule.*/ if (M_GetComportSchedule(p_stComport) == NULL) M_GetCurrentSchedule(p_stIntelligence) = NULL; else M_GetCurrentSchedule(p_stIntelligence) = M_GetTreeComportSchedule(p_stComport); #if defined(ACTIVE_AIDEBUG) /*** DR ***/ AIDebug_M_SetCurrentComport( fn_p_stGetCurrentMind(), p_stComport ); #endif /*ACTIVE_AIDEBUG*/ } return(TRUE); } unsigned char fn_ucGetTreeNbParam(tdstNodeInterpret *p_stTree) { unsigned char ucNbParam=0; unsigned char ucDepth = M_DepthInterpret(p_stTree-1); while ( (M_DepthInterpret(p_stTree) > ucDepth) && (!M_IsTheEndOfTree(p_stTree))) { if (M_DepthInterpret(p_stTree)==ucDepth+1) { ucNbParam++; } p_stTree++; } return(ucNbParam); } #if defined(OPTIMIZE_NB_NODES) unsigned short fn_uwGetNbNodeInterpret(struct tdstTreeInterpret_ *p_stTreeInterpret) { tdstNodeInterpret *p_stTree,*p_stTreeInit; p_stTree=p_stTreeInit=M_GetNodeInterpret(p_stTreeInterpret); if (p_stTree==NULL) return(0); while(!M_IsTheEndOfTree(p_stTree)) p_stTree++; p_stTree++; return ((unsigned short) (p_stTree-p_stTreeInit) ); } #endif /* OPTIMIZE_NB_NODES*/ /**************************************************************/ /* AI init functions used by allocations */ /**************************************************************/ //#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC 04/06/99 */ void fn_vInitMacro(tdstMacro *p_stMacro) { M_GetMacroInitTree(p_stMacro) = NULL; M_GetMacroCurrentTree(p_stMacro) = M_GetMacroInitTree(p_stMacro); } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC 04/06/99 */ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ void fn_vInitListOfMacro(tdstListOfMacro *p_stListOfMacro, unsigned char ucNbMacro) { M_GetMacro(p_stListOfMacro) = NULL; M_GetNbMacro(p_stListOfMacro) = ucNbMacro; } #endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */ void fn_vInitComport(tdstComport *p_stComport) { M_GetComportNbRules(p_stComport)=0; M_GetComportRules(p_stComport) = NULL; M_GetComportSchedule(p_stComport) = NULL; } void fn_vInitRule(tdstTreeInterpret *p_stRule) { M_SetNbNodeInterpret(p_stRule,0); M_GetNodeInterpret(p_stRule)=NULL; } void fn_vInitNodeInterpret(tdstNodeInterpret *p_stNode, long lVal, tdeTypeInterpret eTypeInterpret, unsigned char ucDepth) { M_ClearNodeInterpret(p_stNode); M_DepthInterpret(p_stNode)=ucDepth; M_lValueInterpret(p_stNode)=lVal; M_SetTypeInterpret(p_stNode,eTypeInterpret); #if defined(OPTIMIZE_SWAP_PARAMETER) M_NodeToSkip(p_stNode)=0; #endif #if defined( ACTIVE_AIDEBUG ) M_SetBreakPoint(p_stNode,FALSE); #endif /*ACTIVE_AIDEBUG*/ } #ifdef ACTIVE_EDITOR /**************************************************************/ /* AI desallocation functions : */ /**************************************************************/ char CFast_g_bNoNeedForFreeNodeContent = 0; /*********************************************************************************************/ void fn_vFreeNodeContent(tdstNodeInterpret *p_stNode) { /* is there node ?*/ if (p_stNode!=NULL) { if (M_GetTypeInterpret(p_stNode) == E_ti_String) { if (M_szStringInterpret(p_stNode) != NULL) { M_AIFree(M_szStringInterpret(p_stNode)); } } else if (M_GetTypeInterpret(p_stNode) == E_ti_ConstantVector) { if (M_p_stVectorInterpret(p_stNode) != NULL) { M_AIFree(M_p_stVectorInterpret(p_stNode)); } } fn_vInitNodeInterpret(p_stNode,0,(tdeTypeInterpret) 0,0); } } /* free an array of nodes */ void fn_vFreeNodeInterpretAll(tdstNodeInterpret **p_p_stNode,unsigned short uwNbNodes) { /* is there node ?*/ if (*p_p_stNode!=NULL) { unsigned short i; /* free nodes content*/ if ( !CFast_g_bNoNeedForFreeNodeContent ) { for (i=0;iCFast_dst_RefTreeArray != NULL) { fn_vFreeNodeInterpretAll(&(*p_p_stAIModel)->CFast_dst_RefTreeArray, (*p_p_stAIModel)->uwNbNode) ; } /* CFast, is there a ParamTree*/ if ((*p_p_stAIModel)->CFast_dst_ParamArray != NULL) { CFast_g_bNoNeedForFreeNodeContent = 1 ; fn_vFreeNodeInterpretAll(&(*p_p_stAIModel)->CFast_dst_ParamArray, (*p_p_stAIModel)->uwNbParamNode) ; CFast_g_bNoNeedForFreeNodeContent = 0 ; } /* free ScriptAI itself*/ M_AIFree(*p_p_stAIModel); *p_p_stAIModel=NULL; } } /*********************************************************************************************/ /* free action table entry content*/ void fn_vFreeActionTableEntryContent(tdstActionTableEntry *p_stActionTableEntry) { /* are there actiontable entries ?*/ if (p_stActionTableEntry!=NULL) { /* nothing to do */ } } void fn_vFreeActionTableEntryAll(tdstActionTableEntry **p_p_stActionTableEntry,unsigned ucActionTableNbEntry) { /* is there comport ?*/ if (*p_p_stActionTableEntry!=NULL) { unsigned char i; /* free comport content*/ for (i=0;ip_p_stScriptAI=NULL; } } /* free intelligence*/ void fn_vFreeIntelligenceAll(tdstIntelligence **p_p_stIntelligence) { /* is there intelligence ?*/ if (*p_p_stIntelligence!=NULL) { fn_vFreeIntelligenceContent(*p_p_stIntelligence); /* free intelligence itself*/ M_AIFree(*p_p_stIntelligence); *p_p_stIntelligence=NULL; } } /* free reflex*/ void fn_vFreeReflexAll(tdstIntelligence **p_p_stReflex) { fn_vFreeIntelligenceAll(p_p_stReflex); } /********************************************************************************************/ /* free mind content*/ void fn_vFreeMindContent(AI_tdstMind *p_stMind) { if (p_stMind!=NULL) { /* before model*/ /* free designer variable from mind*/ fn_vFreeDesignerVariable(p_stMind); /* free AI model*/ /* fn_vFreeAIModelAll(&AI_M_p_stGetAIModel(p_stMind));*/ /* free intelligence from mind*/ fn_vFreeIntelligenceAll(&AI_M_p_stGetIntelligence(p_stMind)); /* free reflex from mind*/ fn_vFreeReflexAll(&AI_M_p_stGetReflex(p_stMind)); } } /* free mind all*/ void fn_vFreeMindAll(AI_tdstMind **p_p_stMind) { if (*p_p_stMind!=NULL) { /* free mind content*/ fn_vFreeMindContent(*p_p_stMind); /* free mind itself*/ M_AIFree(*p_p_stMind); *p_p_stMind=NULL; } } #endif /* ACTIVE_EDITOR*/ /**************************************************************/ /* AI allocation functions : */ /**************************************************************/ /**************************************************************/ /* AI allocation functions for macros : */ /**************************************************************/ #ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */ tdstListOfMacro *fn_p_stAllocListOfMacro(unsigned char ucNbMacro) { tdstListOfMacro *p_stListOfMacro=NULL; /*XB980430*/ /* tdstMacro *p_stMacro=NULL;*/ /*End XB*/ MMG_fn_vAddMemoryInfo (MMG_C_lTypeAI , MMG_C_lSubTypeMacro , NULL); M_AIAlloc(p_stListOfMacro, tdstListOfMacro *, sizeof(tdstListOfMacro)); fn_vInitListOfMacro(p_stListOfMacro, ucNbMacro); if (ucNbMacro!=0) { unsigned long i; MMG_fn_vAddMemoryInfo (MMG_C_lTypeAI , MMG_C_lSubTypeMacro , NULL); M_AIAlloc(M_GetMacro(p_stListOfMacro), tdstMacro *, ucNbMacro*sizeof(tdstMacro)); for (i=0;iucNbEntriesUsed=0; p_stActionTable->ucCurrentEntry=0; /**/ for (ucNEntry=0,p_stEntry=M_TableEntry(p_stActionTable);ucNEntry bUseDefaultActionReturn = g_ucUseDefaultActionReturn; p_stEntry -> ucNewActionReturn = g_ucNewActionReturn; } /* END ANNECY MT }*/ /*//*/ #else /* D_THROW_COMPLEX_ACTION_TABLE */ p_stEntry = &(p_stActionTable->stEntry); p_stEntry->bUseDefaultActionReturn=g_ucUseDefaultActionReturn; p_stEntry->ucNewActionReturn=g_ucNewActionReturn; #endif /* D_THROW_COMPLEX_ACTION_TABLE */ /* End XB 20/05/1999 */ return(p_stActionTable); } AI_tdstAIModel *fn_p_stAllocAIModel() { AI_tdstAIModel *p_stAIModel=NULL; MMG_fn_vAddMemoryInfo (MMG_C_lTypeAI , MMG_C_lSubTypeModel , NULL); M_AIAlloc(p_stAIModel, AI_tdstAIModel *, sizeof(AI_tdstAIModel)); AI_M_SetIntelligenceScriptAIModel(p_stAIModel, NULL); AI_M_SetReflexScriptAIModel(p_stAIModel, NULL); AI_M_SetDsgVarAIModel(p_stAIModel,NULL); #ifndef U64 AI_M_SetListOfMacroAIModel(p_stAIModel,NULL); #endif /* U64 */ AI_M_SetSecondPassDone(p_stAIModel,0); //XB 05/08/99 #ifndef D_THROW_CFAST_AI //End XB p_stAIModel->CFast_dst_RefTreeArray = NULL; /* BART ?*/ p_stAIModel->uwNbNode = 0; /* BART ?*/ p_stAIModel->CFast_dst_ParamArray = NULL ; p_stAIModel->uwNbParamNode = 0 ; p_stAIModel->CFast_lFunction = 0; //XB 05/08/99 #endif /* D_THROW_CFAST_AI */ //End XB return(p_stAIModel); } tdstScriptAI *fn_p_stAllocScriptAI(unsigned char ucActionTableNbEntry) { tdstScriptAI *p_stScriptAI=NULL; MMG_fn_vAddMemoryInfo (MMG_C_lTypeAI , MMG_C_lSubTypeScriptAI , NULL); M_AIAlloc(p_stScriptAI, tdstScriptAI *, sizeof(tdstScriptAI)); M_GetScriptAINbComport(p_stScriptAI)=0; M_GetScriptAIComport(p_stScriptAI)=NULL; M_GetScriptAIActionTableNbEntry(p_stScriptAI)=ucActionTableNbEntry; M_GetScriptAINoComportInitDefault(p_stScriptAI)=0; return(p_stScriptAI); } tdstIntelligence *fn_p_stAllocIntelligence(tdstScriptAI **p_p_stScriptAI,unsigned char ucActionTableNbEntry) { tdstIntelligence *p_stIntelligence=NULL; if (M_GetScriptAINbComport(*p_p_stScriptAI)!=0) { MMG_fn_vAddMemoryInfo (MMG_C_lTypeAI , MMG_C_lSubTypeIntelligence , NULL); M_AIAlloc(p_stIntelligence, tdstIntelligence *, sizeof(tdstIntelligence)); /* link intelligence to its model*/ p_stIntelligence->p_p_stScriptAI=p_p_stScriptAI; /* faire macro*/ /* initialise with default comport*/ M_GetNoComportInit(p_stIntelligence)=M_GetScriptAINoComportInitDefault(*p_p_stScriptAI); M_ActionTable(p_stIntelligence)=fn_p_stAllocActionTable(ucActionTableNbEntry); /* ANNECY MT - 18/09/98 { fn_p_stAllocActionTable() initializes the table now*/ /*fn_vInitActionTable(p_stIntelligence);*/ /* END ANNECY MT }*/ } return(p_stIntelligence); } #ifdef ACTIVE_EDITOR /*********************/ /* DESIGNER VARAIBLE */ /*********************/ void fn_vFreeDsgVarInfoContent(tdstDsgVarInfo *p_stDsgVarInfo) { if (p_stDsgVarInfo!=NULL) { p_stDsgVarInfo->ulOffsetInDsgMem=0; p_stDsgVarInfo->eDsgVarTypeId=eNbDsgVarType; } } void fn_vFreeDsgVarInfoAll(tdstDsgVarInfo **p_p_stDsgVarInfo,unsigned char ucNbDsgVar) { if (*p_p_stDsgVarInfo!=NULL) { unsigned char i; /* free DsgVarContent*/ for(i=0;ip_cDsgMemDefaultInit)); fn_vFreeDsgVarInfoAll(&(p_stDsgVar->p_stDsgVarInfo),p_stDsgVar->ucNbDsgVar); p_stDsgVar->ulSize=0; p_stDsgVar->ucNbDsgVar=0; } } void fn_vFreeDsgVarAll(tdstDsgVar **p_p_stDsgVar) { if (*p_p_stDsgVar!=NULL) { fn_vFreeDsgVarContent(*p_p_stDsgVar); M_AIFree(*p_p_stDsgVar); *p_p_stDsgVar=NULL; } } void fn_vFreeDsgMemBuffer(char **p_p_cDsgMemBuffer) { if (*p_p_cDsgMemBuffer!=NULL) { M_AIFree(*p_p_cDsgMemBuffer); *p_p_cDsgMemBuffer=NULL; } } void fn_vFreeDsgMemContent(tdstDsgMem *p_stDsgMem) { if (p_stDsgMem!=NULL) { fn_vFreeDsgMemBuffer(&(p_stDsgMem->p_cDsgMemBufferInit)); fn_vFreeDsgMemBuffer(&(p_stDsgMem->p_cDsgMemBuffer)); } } void fn_vFreeDsgMemAll(tdstDsgMem **p_p_stDsgMem) { if (*p_p_stDsgMem!=NULL) { fn_vFreeDsgMemContent(*p_p_stDsgMem); M_AIFree(*p_p_stDsgMem); *p_p_stDsgMem=NULL; } } void fn_vFreeDesignerVariable(AI_tdstMind *p_stMind) { if (M_GetDsgMem(p_stMind)!=NULL) { if(M_GetDsgVar(p_stMind)!=NULL) { fn_vFreeDsgVarAll(&M_GetDsgVar(p_stMind)); } fn_vFreeDsgMemAll(&M_GetDsgMem(p_stMind)); } } #endif /* ACTIVE_EDITOR*/ tdstDsgVarInfo *fn_p_stAllocDsgVarInfo(unsigned char ucNbDsgVar) { unsigned char i; tdstDsgVarInfo *p_stDsgVarInfo=NULL; MMG_fn_vAddMemoryInfo (MMG_C_lTypeAI , MMG_C_lSubTypeDsgVarInfo , NULL); M_AIAlloc(p_stDsgVarInfo,tdstDsgVarInfo *,ucNbDsgVar*sizeof(tdstDsgVarInfo)); for (i=0;ip_cDsgMemDefaultInit=fn_p_cAllocDsgMemBuffer(ulSize); p_stDsgVar->p_stDsgVarInfo=fn_p_stAllocDsgVarInfo(ucNbDsgVar); p_stDsgVar->ulSize=ulSize; p_stDsgVar->ucNbDsgVar=ucNbDsgVar; return(p_stDsgVar); } char *fn_p_cAllocDsgMemBuffer(unsigned long ulSize) { char *p_cDsgMemBuffer=NULL; MMG_fn_vAddMemoryInfo (MMG_C_lTypeAI , MMG_C_lSubTypeDsgMemBuffer , NULL); M_AIAlloc(p_cDsgMemBuffer,char *,ulSize*sizeof(char)); /* memset(p_cDsgMemBuffer,0,ulSize); AR9904 Already done in the alloc function */ return(p_cDsgMemBuffer); } tdstDsgMem *fn_p_stAllocDsgMem(tdstDsgVar **p_p_stDsgVar,unsigned long ulSize) { tdstDsgMem *p_stDsgMem=NULL; MMG_fn_vAddMemoryInfo (MMG_C_lTypeAI , MMG_C_lSubTypeDsgMem , NULL); M_AIAlloc(p_stDsgMem,tdstDsgMem*,sizeof(tdstDsgMem)); /* link DsgMem to its model : dont forget it*/ p_stDsgMem->p_p_stDsgVar=p_p_stDsgVar; /* no specific values by default */ p_stDsgMem->p_cDsgMemBufferInit=NULL; /* zone which stores current DsgVarValues : Set during 2nd pass*/ p_stDsgMem->p_cDsgMemBuffer=fn_p_cAllocDsgMemBuffer(ulSize); return(p_stDsgMem); } void fn_vAllocVariableDesigner(AI_tdstMind *p_stMind,unsigned long ulSizeDsgMem,unsigned char ucNbDsgVar) { if ( (ulSizeDsgMem!=0) && (ucNbDsgVar!=0) ) { /* note : instruction order is important*/ /* obliged to use these macros instead of those defined in dsgmem.h*/ /* because at this moment p_p_stDsgVar in tdstDsgMem (in tdstMind) is not allocated yet*/ AI_M_p_stGetDsgVar(p_stMind)=fn_p_stAllocDsgVar(ulSizeDsgMem,ucNbDsgVar); AI_M_p_stGetDsgMem(p_stMind)=fn_p_stAllocDsgMem(&AI_M_p_stGetDsgVar(p_stMind),ulSizeDsgMem); } else { AI_M_p_stGetDsgVar(p_stMind)=NULL; AI_M_p_stGetDsgMem(p_stMind)=NULL; } } void fn_vCreateNodeString(tdstNodeInterpret *p_stNode, char *szString) { MMG_fn_vAddMemoryInfo (MMG_C_lTypeAI , MMG_C_lSubTypeNodeString , NULL); /* don't forget +1 because of the terminal zero*/ M_AIAlloc(M_szStringInterpret(p_stNode), char *, (strlen(szString)+1)*sizeof(char)); strcpy(M_szStringInterpret(p_stNode), szString); M_SetTypeInterpret(p_stNode,E_ti_String); } void fn_vCreateNodeVector(struct tdstNodeInterpret_ *p_stNode) { MMG_fn_vAddMemoryInfo (MMG_C_lTypeAI , MMG_C_lSubTypeNodeVector , NULL); M_AIAlloc(M_p_stVectorInterpret(p_stNode), MTH3D_tdstVector *, sizeof(MTH3D_tdstVector)); MTH3D_M_vNullVector(M_p_stVectorInterpret(p_stNode)); M_SetTypeInterpret(p_stNode,E_ti_ConstantVector); }