/*---------------------------------------------------------------------------*/ /* ReadFile.cpp : Manage the reading of rules file.*/ /* auteur : Olivier Didelot.*/ /* date : 29/08/1996*/ /* modify : 09/12/1996*/ /* modifications majeures : 22/12/96 Olivier Couvreur*/ /* 970115 : Vector management (Fabien Morales)*/ /* January 1997 : Adding Way and Waypoint management (Albert Pais)*/ /* 970131 : InitNode + Lint (Olivier Couvreur)*/ /* modify : Olivier Couvreur*/ /* date : 04/02/1997 Lint 0 warnings excepted those specified at the end of AIMacros.h*/ /* 970212 : Module & DsgVarId node types (Fabien Morales)*/ /* modify : Olivier Couvreur */ /* 970503 : C_...String for Editor + M_AIFatalError in InitConvertAndInitNode*/ /* modify : Olivier Couvreur */ /* 970503 : Model can be gathered between several perso + nearly all function rewritten to use new allocation functions*/ /* modify : Alb*/ /* Date : March 21,1997 : minus ways and waypoints modifications*/ /* modify : Olivier Couvreur 25/03/1997 NbNode is not an unsigned char anymore + REVERSE_RULES support*/ /* modify : Olivier Couvreur 03/04/1997 add button support*/ /* modify : Olivier Couvreur 09/04/1997 add error messages*/ /* modify : Olivier Couvreur 29/04/97 Init Comport and .IAI support + DsgVar Perso*/ /* modify : Olivier Couvreur 15/05/97 Support for special dsgVar init values for each perso (no more .IAI , all are transfered in .CAR in section brain )*/ /*---------------------------------------------------------------------------*/ #include "AIUseCPA.h" #include "specif/AIOption.h" #include "AIMacros.h" #include "AI_Erm.h" #include "AI_Struc.h" #include "StrIntel.h" #include "DsgMem.h" #include "specif/ActTable.h" #include "Action.h" #include "VIG.h" #include "CFast.h" /* For Bin*/ #include "SNA.h" /* MR0912*/ #include "SNA\SNAsyn.h" /* To activate 1st pass checking : so that editor is lanched if some specific errors occur*/ #if defined(ACTIVE_EDITOR) #define ACTIVE_1STPASS_CHECKING #if defined(ACTIVE_1STPASS_CHECKING) /*#pragma message("ACTIVE_1STPASS_CHECKING is defined ==> editor will run automaticaly if an error occured in AI while loading")*/ #endif #endif /* in order to compile AI in C++ and link with GAM in C and used for fn_vForceEditor*/ #if defined(__cplusplus) || defined(ACTIVE_1STPASS_CHECKING) #include "AI_Proto.h" #endif #if defined(__DEBUG_AI__) || defined(ACTIVE_1STPASS_CHECKING) #include "EnumAct.h" #include "EnumCond.h" #include "EnumFunc.h" #include "EnumOper.h" #include "EnumProc.h" #include "EnumFild.h" #include "EnumKey.h" #endif /* not useful according to lint but i let it*/ #define _WP_D_DEFINE_WAYPOINTS_ #include "WP_Handl.h" #include "WP_Func.h" #undef _WP_D_DEFINE_WAYPOINTS_ #include "Convert.h" #define __DeclareGlobalVariableReadRule_h__ #include "ReadRule.h" #undef __DeclareGlobalVariableReadRule_h__ /*-------------------------------------------------------------------------------*/ /* Global Variable definition.*/ /*-------------------------------------------------------------------------------*/ unsigned char ucInIntelligenceSection=FALSE; unsigned char ucInComportSection=FALSE; unsigned char ucInRuleSection=FALSE; AI_tdstAIModel *p_stLoadedAIModel=NULL; AI_tdstMind *p_stLoadedMind=NULL; tdstScriptAI *p_stLoadedScriptAI=NULL; tdstComport *p_stLoadedComport=NULL; tdstTreeInterpret *p_stLoadedRule=NULL; tdstNodeInterpret *p_stLoadedNode=NULL; tdstTreeInterpret *p_stLoadedSchedule=NULL; tdstEngineObject *p_stLoadedEngineObject; typedef struct { unsigned long ulNbComport; unsigned short uwNbNode; unsigned char ucNbRules; } tdstIntelligenceCounter; /* store values read by script*/ tdstIntelligenceCounter ScriptCounter; /* update values as we fill structures*/ tdstIntelligenceCounter StructCounter; /*-------------------------------------------------------------------------------*/ /* Functions definition.*/ /*-------------------------------------------------------------------------------*/ /*****************************************************************************************************************/ /* FOR EDITOR TO INTERCEPT ERRORS*/ #if defined(ACTIVE_1STPASS_CHECKING) || defined(__DEBUG_AI__) char szForErrorStringAt1stPass[400]; #endif #if defined(__DEBUG_AI__) #define M_StandardMessage(p_stMind,szTitle,szName,BaseMsg) \ sprintf(szForErrorStringAt1stPass,"%s (%s) in %s",szTitle,szName,AI_M_szGetPersoName((p_stMind))); \ M_AIFatalErrorMsg(E_uwAIFatal##BaseMsg,szForErrorStringAt1stPass); #else #define M_StandardMessage(p_stMind,szTitle,szName,BaseMsg) #endif #if defined(ACTIVE_1STPASS_CHECKING) #define M_TestNodeInterpret(p_stMind,M_Condition,szTitle,szName,BaseMsg) \ if(!(M_Condition)) \ { \ sprintf(szForErrorStringAt1stPass,"%s (%s) in %s",szTitle,szName,AI_M_szGetPersoName((p_stMind))); \ M_AIWarningErrorAndNeverStopForDebug(E_uwAIWarning##BaseMsg,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass); \ AI_M_ucErrorFlag((p_stMind))=1; \ fn_vForceEditor(); \ } #elif defined(__DEBUG_AI__) #define M_TestNodeInterpret(p_stMind,M_Condition,szTitle,szName,BaseMsg) \ if(!(M_Condition)) \ { \ M_StandardMessage((p_stMind),szTitle,szName,BaseMsg) \ } #else #define M_TestNodeInterpret(p_stMind,M_Condition,szTitle,szName,BaseMsg) #endif /*****************************************************************************************************************/ char szForScript[_MAX_PATH]; #if !defined(U64) /* To simplify access to link table*/ SCR_tdst_Link_Value *fn_vLinkWithLinkTable(SCR_tdst_Link_Table *p_stLinkTable, char *szPathToConcatenate, char *szStrToPutInLinkTable,tdstNodeInterpret *p_stNode,tdeTypeInterpret eTypeInterpret,unsigned char ucDepth) { SCR_tdst_Link_Value *p_stLinkValue; char szLocalForScript[_MAX_PATH]=""; if (szPathToConcatenate != NULL) { strcat(szLocalForScript, szPathToConcatenate); strcat(szLocalForScript, "\\"); } strcat(szLocalForScript,szStrToPutInLinkTable); p_stLinkValue = SCR_fnp_st_Link_CreateOrGetLinkFromKey( p_stLinkTable, szLocalForScript); M_lKeyLinkInterpret(p_stNode) = (long)p_stLinkValue; M_SetTypeInterpret(p_stNode, eTypeInterpret); M_DepthInterpret(p_stNode)= ucDepth; return p_stLinkValue; } #define MAX_NODE_STRING_LENGTH 19 typedef void (*tdp_fn_vInitNodeFunctionPointer)(struct tdstNodeInterpret_ *p_stNode,char *szParams[]); typedef struct tdstNodeEntry_ { char szNodeName[MAX_NODE_STRING_LENGTH+1]; tdeTypeInterpret eNodeType; tdp_fn_vInitNodeFunctionPointer p_fn_vInitNodeFunctionPointer; } tdstNodeEntry; #define M_DEFINE_NODE(a,b,cccc) static void cccc(struct tdstNodeInterpret_ *p_stNode,char *szParams[]); #include "DefNode.h" #undef M_DEFINE_NODE tdstNodeEntry a_stNodeTable[]= { #define M_DEFINE_NODE(a,b,c) {a,b,c}, #include "DefNode.h" #undef M_DEFINE_NODE }; void fn_vConvertAndInitNode(char *szAction,char *szParams[], tdstNodeInterpret *p_stNode,unsigned char ucDepth) { long i; /* clear node*/ M_ClearNodeInterpret(p_stNode); /* set depth*/ M_DepthInterpret(p_stNode)=ucDepth; /* default node type*/ M_SetTypeInterpret(p_stNode,E_ti_Unknown); for(i=0;i module list in the level SCR_M_RdL0_SetContextLong(C_GrandChildContext, 1, 0); // End Shaitan => module list in the level /*to make sure the table is loaded*/ (void) SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal); /* (void) for lint.*/ /*now we can set the node value with the handle*/ fn_vLinkWithLinkTable(&TBL_g_stLinkTable, fn_szGetFamiliesDataPath(), szParams[0],p_stNode,E_ti_ObjectTableRef,(unsigned char) atol(szParams[1])); } #ifdef D_USE_LIPSYNC static void fn_vInitNodeLipSynchroRef(tdstNodeInterpret *p_stNode,char *szParams[]) { SCR_tdst_Cxt_Values *p_stValues; /* MR0912*/ if (SNA_fn_ucGetLoadType()==SNA_LOAD_SCRIPT) { SCR_M_RdL0_SetContextLong(C_GrandChildContext,1,(long)fn_h3dDataGetFamily(p_stLoadedEngineObject->h_3dData)); p_stValues = SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal); M_hLipSynchroHandleIdInterpret(p_stNode) = (tdxHandleOfLipsSynchroTable)(p_stValues->a_ulValues[0]); } else if (SNA_fn_ucGetLoadType()==SNA_SAVE_SNAPSHOT) { /* Version Hybride*/ SCR_M_RdL0_SetContextLong(C_GrandChildContext,1,(long)fn_h3dDataGetFamily(p_stLoadedEngineObject->h_3dData)); p_stValues = SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal); /* A voir...*/ M_hLipSynchroHandleIdInterpret(p_stNode) = (tdxHandleOfLipsSynchroTable)(p_stValues->a_ulValues[0]); fn_vWriteLipsSynchroBloc((tdxHandleOfLipsSynchroTable)(p_stValues->a_ulValues[0]),szParams[0]); /* End VH*/ SNA_fn_vWriteLipsSynchEntryInLipsSynchTableFile(szParams[0],(unsigned long)p_stNode); } } #endif /* D_USE_LIPSYNC*/ static void fn_vInitNodeSoundEventRef(tdstNodeInterpret *p_stNode,char *szParams[]) { SCR_tdst_Cxt_Values *p_stValues; p_stValues = SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal); M_SoundEventInterpret(p_stNode) = (SND_tdxHandleToSoundEvent) (p_stValues->a_ulValues[0]); if (SNA_fn_ucGetLoadType()==SNA_SAVE_SNAPSHOT) /* we save the id of the sound event and the pointer on the structure that contains the id and the pointer of the sound event */ SNA_fn_vWriteSoundEntryInSoundTableFile(SND_fn_ulGetEventBinIdFromPointer((SND_tdxHandleToSoundEvent)p_stValues->a_ulValues[0]) ,(unsigned long)&(M_SoundEventInterpret(p_stNode))); } static void fn_vInitNodeBeginMacro(tdstNodeInterpret *p_stNode,char *szParams[]) { M_lValueInterpret(p_stNode) = 0; } static void fn_vInitNodeEndMacro(tdstNodeInterpret *p_stNode,char *szParams[]) { M_lValueInterpret(p_stNode) = 0; } static void fn_vInitNodeDsgVar(tdstNodeInterpret *p_stNode,char *szParams[]) { M_lValueInterpret(p_stNode)=atol(szParams[0]); } static void fn_vInitNodeDsgVarRef(tdstNodeInterpret *p_stNode,char *szParams[]) { fn_vLinkWithLinkTable(&g_stDsgVarLinkTable, fn_szGetFamiliesDataPath(), szParams[0],p_stNode,E_ti_DsgVarRef,(unsigned char) atol(szParams[1])); } static void fn_vInitNodeOperator(tdstNodeInterpret *p_stNode,char *szParams[]) { M_eOperatorIdInterpret(p_stNode)=fn_eFindOperatorIdFromScriptName(szParams[0]); M_TestNodeInterpret(p_stLoadedMind,M_IsOperatorIdValid(M_eOperatorIdInterpret(p_stNode)),"Operator name",szParams[0],UnknownOperator); } static void fn_vInitNodeFunction(tdstNodeInterpret *p_stNode,char *szParams[]) { M_eFuncIdInterpret(p_stNode)=fn_eFindFunctionIdFromScriptName(szParams[0]); M_TestNodeInterpret(p_stLoadedMind,M_IsFuncIdValid(M_eFuncIdInterpret(p_stNode)),"Function name",szParams[0],UnknownFunc); } static void fn_vInitNodeProcedure(tdstNodeInterpret *p_stNode,char *szParams[]) { M_eProcedureIdInterpret(p_stNode) = fn_eFindProcedureIdFromScriptName(szParams[0]); M_TestNodeInterpret(p_stLoadedMind,M_IsProcedureIdValid(M_eProcedureIdInterpret(p_stNode)),"Procedure name",szParams[0],UnknownFunc); } static void fn_vInitNodeKeyWord(tdstNodeInterpret *p_stNode,char *szParams[]) { M_eKeyWordIdInterpret(p_stNode)=fn_eFindKeyWordIdFromScriptName(szParams[0]); M_TestNodeInterpret(p_stLoadedMind,M_IsKeyWordIdValid(M_eKeyWordIdInterpret(p_stNode)),"Keyword name",szParams[0],UnknownKeyWord); } /* static void fn_vInitNodeMetaAction(tdstNodeInterpret *p_stNode,char *szParams[]) { M_eMetaActionIdInterpret(p_stNode) = fn_eFindMetaActionIdFromScriptName(szParams[0]); M_TestNodeInterpret(p_stLoadedMind,M_IsMetaActionIdValid(M_eMetaActionIdInterpret(p_stNode)),"Metaaction name",szParams[0],InvalidAction); } */ #include "enumproc.h" static void fn_vInitNodeMetaAction(tdstNodeInterpret *p_stNode,char *szParams[]) { M_eMetaActionIdInterpret(p_stNode) = fn_eFindMetaActionIdFromScriptName(szParams[0]); /* bidouille temporaire */ if (!M_IsMetaActionIdValid(M_eMetaActionIdInterpret(p_stNode))) { char str[256]="Proc"; char *ptr; if ((ptr=strchr(szParams[0],'_'))!=NULL) { tdeProcedureId eProcId; strcat(str,ptr); eProcId=fn_eFindProcedureIdFromScriptName(str); if (M_IsProcedureIdValid(eProcId)) { M_SetTypeInterpret(p_stNode,E_ti_Procedure); M_eProcedureIdInterpret(p_stNode)=eProcId; return; } } } M_TestNodeInterpret(p_stLoadedMind,M_IsMetaActionIdValid(M_eMetaActionIdInterpret(p_stNode)),"Metaaction name",szParams[0],InvalidAction); } static void fn_vInitNodeReal(tdstNodeInterpret *p_stNode,char *szParams[]) { M_xValueInterpret(p_stNode) = MTH_M_xFloatToReal((float) atof(szParams[0])); } static void fn_vInitNodeSuperObjectRef(tdstNodeInterpret *p_stNode,char *szParams[]) { fn_vLinkWithLinkTable(HIE_fn_p_stGetSuperObjectLinkTable(), fn_szGetLevelsDataPath(), szParams[0],p_stNode,E_ti_SuperObjectRef,(unsigned char) atol(szParams[1])); } static void fn_vInitNodeFamilyRef(tdstNodeInterpret *p_stNode,char *szParams[]) { M_hFamilyHandleIdInterpret(p_stNode) = fn_hFindOrAddFAmily(fn_otFindOrAddFamilyTypeOfFamilyTypeName(szParams[0])); } static void fn_vInitNodeTextRef(tdstNodeInterpret *p_stNode,char *szParams[]) { /*M_TextInterpret(p_stNode) = FON_fn_hGetTextHandle(szParams[0]);*/ FON_tdxHandleOfText hText = FON_fn_hGetTextHandle(szParams[0]); M_TestNodeInterpret(p_stLoadedMind,(long)hText,"Text Key",szParams[0],ScriptError); M_TextInterpret(p_stNode) = hText; } static void fn_vInitNodeParticleGenerator(tdstNodeInterpret *p_stNode,char *szParams[]) { SCR_tdst_Cxt_Values *p_stValues; p_stValues = SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal); M_ParticleGeneratorInterpret(p_stNode) = (tdxHandleToParticleGenerator)(p_stValues->a_ulValues[0]); } static void fn_vInitNodeGameMaterialRef(tdstNodeInterpret *p_stNode,char *szParams[]) { char szFile[SCR_CV_ui_Cfg_MaxLenName], szAction[SCR_CV_ui_Cfg_MaxLenName], szId[SCR_CV_ui_Cfg_MaxLenName]; SCR_tdst_File_Open *p_stFile; SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal); SCR_fn_v_RdL0_SplitSectionName(szParams[0], szFile, szAction, szId); p_stFile = SCR_fnp_st_RdL0_GetOpenFile(szFile); assert(p_stFile); SCR_fn_v_RdL0_ComputeSectionName(szFile, p_stFile->stFile.a_szOpenFileName, szAction, szId); fn_vLinkWithLinkTable(GMT_fn_p_stGetLinkTable(), NULL, szFile, p_stNode, E_ti_GameMaterialRef, (unsigned char) atol(szParams[1])); } static void fn_vInitNodeColor(tdstNodeInterpret *p_stNode,char *szParams[]) { M_ColorValueInterpret(p_stNode)=atol(szParams[0]); } static void fn_vInitNodePersoRef(tdstNodeInterpret *p_stNode,char *szParams[]) { unsigned char ucDepth=0; /* Reference compatibility : 0,1,2 <-> 0^1:2*/ if (szParams[2]!=NULL) { SCR_fn_v_RdL0_ComputeSectionName(szForScript, szParams[0], szParams[1], szParams[2]); ucDepth=(unsigned char) atol(szParams[3]); } else { strcpy(szForScript,szParams[0]); ucDepth=(unsigned char) atol(szParams[1]); } fn_vLinkWithLinkTable(&g_st3DOSLinkTable.stCharacter, fn_szGetCharactersDataPath(), szForScript,p_stNode,E_ti_PersoRef,ucDepth); } static void fn_vInitNodeComportRef(tdstNodeInterpret *p_stNode,char *szParams[]) { unsigned char ucDepth=0; SCR_tdst_Link_Value *p_stLinkValue; if (szParams[2]!=NULL) { SCR_fn_v_RdL0_ComputeSectionName(szForScript, szParams[0], szParams[1], szParams[2]); ucDepth=(unsigned char)atol(szParams[3]); } else { char szFileName[_MAX_PATH]; fn_v_File_ComputeFileSectionName(szParams[0],szFileName,szForScript); ucDepth =(unsigned char)atol(szParams[1]); } p_stLinkValue = fn_vLinkWithLinkTable(&g_stComportLinkTable, fn_szGetFamiliesDataPath(), szForScript,p_stNode,E_ti_ComportRef,ucDepth); SCR_M_v_Link_SetAdditionalLong(p_stLinkValue, 4, 0); } static void fn_vInitNodeModuleRef(tdstNodeInterpret *p_stNode,char *szParams[]) { /* struct tdstFamilyList_ *p_stFamily; SCR_tdst_Link_Value * _p_stLinkValue; p_stFamily=fn_h3dDataGetFamily(p_stLoadedEngineObject->h_3dData); strcpy(szForScript,fn_szFindFamilyTypeNameOfFamilyType(p_stFamily->otObjectFamilyType)); strcat(szForScript,"-"); strcat(szForScript,szParams[0]); _p_stLinkValue = SCR_fnp_st_Link_SearchKey(&CHL_g_stLinkTable,szForScript); if(_p_stLinkValue) { M_lModuleInterpret(p_stNode) = (unsigned short)SCR_M_ul_Link_GetValue(_p_stLinkValue); } else { M_lModuleInterpret(p_stNode) = (unsigned short)0; } */ fn_vLinkWithLinkTable(&CHL_g_stLinkTable, NULL, szParams[0], p_stNode, E_ti_ModuleRef, (unsigned char) atol(szParams[1])); } static void fn_vInitNodeActionRef(tdstNodeInterpret *p_stNode,char *szParams[]) { fn_vLinkWithLinkTable(&g_st3DOSLinkTable.stState, fn_szGetFamiliesDataPath(), szParams[0],p_stNode,E_ti_ActionRef,(unsigned char) atol(szParams[1])); } static void fn_vInitNodeVector(tdstNodeInterpret *p_stNode,char *szParams[]) { /* nothing to do : normal*/ } static void fn_vInitNodeConstantVector(tdstNodeInterpret *p_stNode,char *szParams[]) { MTH3D_tdstVector *p_stVector; MTH_tdxReal xX,xY,xZ; fn_vCreateNodeVector(p_stNode); p_stVector=M_p_stVectorInterpret(p_stNode); xX=MTH_M_xFloatToReal((float) atof(szParams[0])); xY=MTH_M_xFloatToReal((float) atof(szParams[1])); xZ=MTH_M_xFloatToReal((float) atof(szParams[2])); MTH3D_M_vSetVectorElements(p_stVector,xX,xY,xZ); M_DepthInterpret(p_stNode)= (unsigned char)atol(szParams[3]); } static void fn_vInitNodeWayPoint(tdstNodeInterpret *p_stNode,char *szParams[]) { /* ANNECY MT - 25/09/98 {*/ char szForScript[256]; strcpy(szForScript,fn_szGetLevelsDataPath()); strcat(szForScript,"\\"); strcat(szForScript,szParams[0]); M_lKeyLinkInterpret(p_stNode) = (long)SCR_fnp_st_Link_CreateOrGetLinkFromKey(WP_fnp_WayPoint_GetLinkTable(),szForScript); /* END ANNECY MT }*/ } static void fn_vInitNodeModule(tdstNodeInterpret *p_stNode,char *szParams[]) { M_lModuleInterpret(p_stNode)=atol(szParams[0]); } static void fn_vInitNodeDsgVarId(tdstNodeInterpret *p_stNode,char *szParams[]) { M_lDsgVarIdInterpret(p_stNode)=atol(szParams[0]); } static void fn_vInitNodeMask(tdstNodeInterpret *p_stNode,char *szParams[]) { M_xMaskInterpret(p_stNode)=(GMT_tdxMask) atol(szParams[0]); } static void fn_vInitNodeModelRef(tdstNodeInterpret *p_stNode,char *szParams[]) { fn_vLinkWithLinkTable(&g_stModelLinkTable, fn_szGetFamiliesDataPath(), szParams[0],p_stNode,E_ti_ModelRef,(unsigned char) atol(szParams[1])); } /*ANNECY CT 22/01/98 {*/ static void fn_vInitNodeLight(tdstNodeInterpret *p_stNode,char *szParams[]) { char a255_csCompleteSectionName [255]; strcpy(a255_csCompleteSectionName,fn_szGetLevelsDataPath()); strcat(a255_csCompleteSectionName,"\\"); strcat(a255_csCompleteSectionName,szParams[0]); M_lKeyLinkInterpret(p_stNode) = SCR_fnp_st_Link_CreateOrGetLinkFromKey(&gs_stLightLinkTable,a255_csCompleteSectionName)->ulValue; } /*ENDANNECY CT}*/ /*ANNECY Bart 02/02/98 {*/ static void fn_vInitNodeCaps(tdstNodeInterpret *p_stNode,char *szParams[]) { char* dummy; M_ulCapsInterpret(p_stNode) = (unsigned long) strtoul(szParams[0], &dummy, 2); } /* ANNECY MT - 25/09/98 {*/ static void fn_vInitNodeGraph(tdstNodeInterpret *p_stNode,char *szParams[]) { char szForScript[256]; sprintf(szForScript, "%s\\%s\\%s.%s^%s:%s", fn_szGetLevelsDataPath(), fn_p_szGetLevelName(), fn_p_szGetLevelName(), C_ScriptWayPointSuffixe, C_SectionWPGraphDescription, szParams[0]); M_lKeyLinkInterpret(p_stNode) = (long)SCR_fnp_st_Link_CreateOrGetLinkFromKey(WPG_fnp_Graph_GetLinkTable(),szForScript); } /* END ANNECY MT }*/ /*ENDANNECY Bart }*/ #define M_GET_AI_DEFINES_DATA_PATH fn_szGetFamiliesDataPath() static void fn_vInitNodeConstantRef(tdstNodeInterpret *p_stNode,char *szParams[]) { SCR_tdst_Link_Value *p_stLinkValue; sprintf(szForScript,"%s\\%s",M_GET_AI_DEFINES_DATA_PATH,szParams[0]); p_stLinkValue= SCR_fnp_st_Link_SearchKey(&g_stDefinesLinkTable,szForScript); M_TestNodeInterpret(p_stLoadedMind,p_stLinkValue,"Constant Ref",szParams[0],UnknownNode); if (p_stLinkValue!=NULL) M_lValueInterpret(p_stNode)=SCR_M_ul_Link_GetValue(p_stLinkValue); } static void fn_vInitNodeRealRef(tdstNodeInterpret *p_stNode,char *szParams[]) { SCR_tdst_Link_Value *p_stLinkValue; sprintf(szForScript,"%s\\%s",M_GET_AI_DEFINES_DATA_PATH,szParams[0]); p_stLinkValue = SCR_fnp_st_Link_SearchKey(&g_stDefinesLinkTable,szForScript); M_TestNodeInterpret(p_stLoadedMind,p_stLinkValue,"Real Ref",szParams[0],UnknownNode); if (p_stLinkValue!=NULL) M_lValueInterpret(p_stNode)=SCR_M_ul_Link_GetValue(p_stLinkValue); } #endif /*U64*/ #if !defined(U64) SCR_tde_Anl_ReturnValue fn_eCreateRule(SCR_tdst_File_Description *p_stFile, char *szAction, char *szParams[], SCR_tde_Anl_Action eType) { static char cIsCRR = 0; char *psz_Temp; char szErrorString[100]; p_stFile=p_stFile;/* for lint*/ /* Determin if it's a CRR */ psz_Temp = strrchr(p_stFile->a_szFileName, '.'); if(psz_Temp && !strcmpi(psz_Temp, ".crr")) cIsCRR = 1; else cIsCRR = 0; if (cIsCRR || (ucInComportSection==TRUE)) { if (eType == SCR_EA_Anl_BeginSection) { ucInRuleSection=TRUE; /* plus 1 for adding a dummy node at the end of the tree*/ ScriptCounter.uwNbNode=(unsigned short) (atoi(szParams[1])+1); StructCounter.uwNbNode=0; if (cIsCRR || (StructCounter.ucNbRules < ScriptCounter.ucNbRules)) { /* allocate nodes */ p_stLoadedNode=fn_p_stAllocNodeInterpret(ScriptCounter.uwNbNode); if(cIsCRR) { p_stLoadedMind->p_stAIModel->CFast_dst_RefTreeArray = p_stLoadedNode; p_stLoadedMind->p_stAIModel->uwNbNode = ScriptCounter.uwNbNode; } else { M_GetNodeInterpret(p_stLoadedRule)=p_stLoadedNode; M_SetNbNodeInterpret(p_stLoadedRule,ScriptCounter.uwNbNode); } } else { /* error : bad number of rule*/ sprintf(szErrorString,"Number of rules in this comport (comport n. %d) should be (%d)\n", StructCounter.ulNbComport, ScriptCounter.ucNbRules); M_AIFatalErrorMsg(E_uwAIFatalBadRuleNumber,szErrorString); } } else if (eType == SCR_EA_Anl_EndSection) { if(!cIsCRR) { /* add a dummy node at the end of the tree*/ fn_vInitNodeInterpret( M_GetNodeInterpretN(p_stLoadedRule,StructCounter.uwNbNode), 0, E_ti_EndTree, 0); StructCounter.uwNbNode++; if (ScriptCounter.uwNbNode!=StructCounter.uwNbNode) { sprintf(szErrorString,"Number of nodes in this rule (rule %d comport n. %d) should be (%d)\n",StructCounter.ucNbRules, StructCounter.ulNbComport,ScriptCounter.uwNbNode); M_AIFatalErrorMsg(E_uwAIFatalBadNodeNumber,szErrorString); } /* hyper important*/ StructCounter.ucNbRules++; p_stLoadedRule= M_GetComportRuleN(p_stLoadedComport,StructCounter.ucNbRules); } else { fn_vInitNodeInterpret( p_stLoadedMind->p_stAIModel->CFast_dst_RefTreeArray+StructCounter.uwNbNode, 0, E_ti_EndTree, 0); } ucInRuleSection=FALSE; } else { unsigned char ucDepth=0; if (szParams[1]!=NULL) { ucDepth=(unsigned char) atol(szParams[1]); } else { sprintf(szErrorString,"Depth undefined (node %d comport n. %d)\n",StructCounter.uwNbNode, StructCounter.ulNbComport); M_AIFatalErrorMsg(E_uwAIFatalUnknownNode,szErrorString); } if (StructCounter.uwNbNode < ScriptCounter.uwNbNode) { if(cIsCRR) fn_vConvertAndInitNode(szAction, szParams, p_stLoadedMind->p_stAIModel->CFast_dst_RefTreeArray + StructCounter.uwNbNode, ucDepth); else fn_vConvertAndInitNode(szAction, szParams, M_GetNodeInterpretN(p_stLoadedRule,StructCounter.uwNbNode), ucDepth); StructCounter.uwNbNode++; } else { M_AIFatalError(E_uwAIFatalBadNodeNumber); } } } else { /*error : CreateRule not in CreateComport*/ M_AIFatalError(E_uwAIFatalRuleNotInComport); } return SCR_ERV_Anl_NormalReturn; } SCR_tde_Anl_ReturnValue fn_eCreateSchedule(SCR_tdst_File_Description *p_stFile, char *szAction, char *szParams[], SCR_tde_Anl_Action eType) { char szErrorString[100]; p_stFile=p_stFile;/* for lint*/ if (ucInComportSection==TRUE) { if (eType == SCR_EA_Anl_BeginSection) { ucInRuleSection=TRUE; /* plus 1 for adding a dummy node at the end of the tree*/ ScriptCounter.uwNbNode=(unsigned short) (atoi(szParams[1])+1); StructCounter.uwNbNode=0; /* allocate schedule*/ p_stLoadedSchedule=fn_p_stAllocSchedule(ScriptCounter.uwNbNode); /* connect schedule to comport*/ M_GetComportSchedule(p_stLoadedComport)=p_stLoadedSchedule; } else if (eType == SCR_EA_Anl_EndSection) { /* add a dummy node at the end of the tree*/ fn_vInitNodeInterpret( M_GetNodeInterpretN(p_stLoadedSchedule,StructCounter.uwNbNode), 0, E_ti_EndTree, 0); StructCounter.uwNbNode++; if (ScriptCounter.uwNbNode!=StructCounter.uwNbNode) { sprintf(szErrorString,"Number of nodes in this schedule (comport n. %d) should be (%d)\n", StructCounter.ulNbComport,ScriptCounter.uwNbNode); M_AIFatalErrorMsg(E_uwAIFatalBadNodeNumber,szErrorString); } ucInRuleSection=FALSE; } else { unsigned char ucDepth=0; if (szParams[1]!=NULL) { ucDepth=(unsigned char) atol(szParams[1]); } else { sprintf(szErrorString,"Depth undefined (node %d schedule comport n. %d)\n",StructCounter.uwNbNode, StructCounter.ulNbComport); M_AIFatalErrorMsg(E_uwAIFatalUnknownNode,szErrorString); } if (StructCounter.uwNbNode < ScriptCounter.uwNbNode) { fn_vConvertAndInitNode(szAction, szParams, M_GetNodeInterpretN(p_stLoadedSchedule,StructCounter.uwNbNode), ucDepth); StructCounter.uwNbNode++; } else { sprintf(szErrorString,"Number of nodes in this schedule (schedule comport n. %d) should be (%d)\n", StructCounter.ulNbComport,ScriptCounter.uwNbNode); M_AIFatalErrorMsg(E_uwAIFatalBadNodeNumber,szErrorString); } } } else { /*error : CreateRule not in CreateComport*/ sprintf(szErrorString,"Problem (schedule comport n. %d)\n", StructCounter.ulNbComport); M_AIFatalErrorMsg(E_uwAIFatalRuleNotInComport,szErrorString); } return SCR_ERV_Anl_NormalReturn; } SCR_tde_Anl_ReturnValue fn_eCreateComport(SCR_tdst_File_Description *p_stFile, char *szAction, char *szParams[], SCR_tde_Anl_Action eType) { char szForScript[256]; char szErrorString[100]; p_stFile = p_stFile;/* for lint*/ szAction=szAction; if (ucInIntelligenceSection==TRUE) { if (eType == SCR_EA_Anl_BeginSection) { VIG_fn_vAddToProgressBar(1); ucInComportSection=TRUE; /* Nb Rules in this comport*/ if (szParams[1] != NULL) ScriptCounter.ucNbRules=(unsigned char) atoi(szParams[1]); else ScriptCounter.ucNbRules=(unsigned char) atoi(szParams[0]); StructCounter.ucNbRules=0; if (StructCounter.ulNbComport < ScriptCounter.ulNbComport) { p_stLoadedComport=M_GetScriptAIComportN(p_stLoadedScriptAI, StructCounter.ulNbComport); SCR_M_RdL0_ComputeOpenSectionNameR(0,szForScript); SCR_M_v_Link_SetAdditionalLong( SCR_fnp_st_Link_SetValue(&g_stComportLinkTable, szForScript, (unsigned long)p_stLoadedComport), 1, strlen(szForScript)-strlen(SCR_M_RdL0_GetCompleteSectionNameR(0)) ); if (M_GetComportRules(p_stLoadedComport) == NULL) { #ifndef ACTIVE_EDITOR if(p_stLoadedMind->p_stAIModel->CFast_bIsC == 2) { p_stLoadedRule = NULL; ScriptCounter.ucNbRules = 0; } else #endif p_stLoadedRule = fn_p_stAllocRule(ScriptCounter.ucNbRules); M_GetComportRules(p_stLoadedComport) = p_stLoadedRule; M_GetComportNbRules(p_stLoadedComport) = ScriptCounter.ucNbRules; #if defined(__DEBUG_AI__) strcpy(M_GetNameComport(p_stLoadedComport), SCR_M_RdL0_GetCompleteSectionNameR(0)); #endif } else { /*error : CreateComport(n) n is bad : already initialized*/ sprintf(szErrorString,"Problem (comport n. %d : %s)\n", StructCounter.ulNbComport, szAction); M_AIFatalErrorMsg(E_uwAIFatalBadComportNumber,szErrorString); } } else { /*error : CreateIntelligence(n) n is bad : too much comport*/ sprintf(szErrorString,"Problem (comport n. %d : %s)\n", StructCounter.ulNbComport, szAction); M_AIFatalErrorMsg(E_uwAIFatalBadComportNumber,szErrorString); } } else if (eType == SCR_EA_Anl_EndSection) { if (ScriptCounter.ucNbRules!=StructCounter.ucNbRules) { sprintf(szErrorString,"Number of rules in this comport (comport n. %d : %s) should be (%d)\n", StructCounter.ulNbComport, szAction, ScriptCounter.ucNbRules); M_AIFatalErrorMsg(E_uwAIFatalBadRuleNumber,szErrorString); } StructCounter.ulNbComport++; ucInComportSection=FALSE; } } else { /*error : CreateComport not in CreateIntelligence*/ M_AIFatalError(E_uwAIFatalComportNotInIntelligence); } #ifndef ACTIVE_EDITOR if(p_stLoadedMind->p_stAIModel->CFast_bIsC == 2) { StructCounter.ulNbComport++; ucInComportSection=FALSE; return SCR_ERV_Anl_TerminateCurrentSection; } #endif return SCR_ERV_Anl_NormalReturn; } SCR_tde_Anl_ReturnValue fn_eCreateScriptAI(SCR_tdst_File_Description *p_stFile, char *szAction, char *szParams[], SCR_tde_Anl_Action eType) { p_stFile = p_stFile;/* for lint*/ szAction=szAction; if (eType == SCR_EA_Anl_AlreadyAnalysed) { SCR_M_RdL0_GetSectionLong(0, 0, tdstScriptAI*, p_stLoadedScriptAI); return SCR_ERV_Anl_NormalReturn; } else if (eType == SCR_EA_Anl_BeginSection) { unsigned char ucActionTableNbEntry=DEFAULT_ACTION_TABLE_NB_ENTRIES; unsigned long ulNoComportInitDefault=0; ucInIntelligenceSection=TRUE; /* optional parameter in script*/ if (szParams[1]!=NULL) { ucActionTableNbEntry=(unsigned char) atoi(szParams[1]); if (ucActionTableNbEntry=M_GetNbDsgVar(p_stLoadedMind)) { sprintf(szErrorString,"Too many variables defined in %s .DEC (cf variable number %d,%s)\n",AI_M_szGetPersoName(p_stLoadedMind),ucVarId,szParams[1]); M_AIFatalErrorMsg(E_uwAIFatalScriptError,szErrorString); } #endif M_GetDsgVarSaveType(p_stLoadedMind,ucVarId) = fn_eFindSaveTypeFromScriptName(szParams[1], AI_M_szGetPersoName(p_stLoadedMind), ucVarId ); } else if (M_IsTypeInitVariable(szAction)) { #if defined(__DEBUG_AI__) if (ucVarId>=M_GetNbDsgVar(p_stLoadedMind)) { sprintf(szErrorString,"Too many variables defined in %s .DEC (cf variable number %d,%s)\n",AI_M_szGetPersoName(p_stLoadedMind),ucVarId,szParams[1]); M_AIFatalErrorMsg(E_uwAIFatalScriptError,szErrorString); } #endif M_GetDsgVarInitType(p_stLoadedMind,ucVarId)=fn_eFindInitTypeFromScriptName(szParams[1]); } else { tdeDsgVarTypeId eDsgVarTypeId=fn_eFindDsgVarTypeIdFromScriptName(szAction); if (!M_IsDsgVarTypeIdValid(eDsgVarTypeId)) { M_AIFatalError(E_uwAIFatalWrongTypeVar); } /* element of an array*/ if (szParams[1][0]=='@') { unsigned char ucIndex=(unsigned char) atoi(szParams[0]); char szDecFilenameSection[300]; tdstEngineObject *p_stEngineObject=p_stLoadedEngineObject; SCR_tdst_Link_Value *p_stLinkValue=NULL; char *szName=&szParams[1][1]; /* to delete @*/ tdeDsgVarTypeId eDsgVarTypeId=fn_eFindDsgVarTypeIdFromScriptName(szAction); if (!M_IsDsgVarTypeIdValid(eDsgVarTypeId)) { M_AIFatalError(E_uwAIFatalWrongTypeVar); } /* build .dec section*/ sprintf(szDecFilenameSection,"%s\\%s\\%s\\%s.dec^%s:%s", fn_szGetFamiliesDataPath(), fn_szFindFamilyTypeNameOfFamilyType(M_ObjectGetFamilyType(p_stLoadedEngineObject)), fn_szFindModelTypeNameOfModelType(M_ObjectGetModelType(p_stLoadedEngineObject)), fn_szFindModelTypeNameOfModelType(M_ObjectGetModelType(p_stLoadedEngineObject)), C_CreateVariables_String, szName ); /* is name known*/ p_stLinkValue = SCR_fnp_st_Link_SearchKey(&g_stDsgVarLinkTable,szDecFilenameSection); if (p_stLinkValue!=NULL) { /* VarId in bounds*/ ucVarId=(unsigned char) SCR_M_ul_Link_GetValue(p_stLinkValue); if (ucVarId=M_GetNbDsgVar(p_stLoadedMind)) { sprintf(szErrorString,"Too many variables defined in %s .DEC (cf variable number %d,%s)\n",AI_M_szGetPersoName(p_stLoadedMind),ucVarId,szParams[1]); M_AIFatalErrorMsg(E_uwAIFatalScriptError,szErrorString); } #endif /* Gamedata\World\Level\_Common\Families\NewEd\NewEd1\NewEd1.dec^CreateVariables*/ SCR_M_RdL0_ComputeOpenSectionNameR(0,szForScript); /* NewEd\NewEd1\NewEd1.dec^CreateVariables*/ lLen=strlen(szForScript)-strlen(SCR_M_RdL0_GetCompleteSectionNameR(0)); /* add :DsgVarName*/ strcat(szForScript,":"); strcat(szForScript,szParams[1]); SCR_M_v_Link_SetAdditionalLong( SCR_fnp_st_Link_SetValue(&g_stDsgVarLinkTable, szForScript, (unsigned long)ucVarId), 1, lLen ); M_SetDsgVarName(p_stLoadedMind,ucVarId,szParams[1]) switch (eDsgVarTypeId) { case eDsgVarType_WayPoint : case eDsgVarType_Perso : case eDsgVarType_Action : case eDsgVarType_Comport : case eDsgVarType_Float : case eDsgVarType_Text: case eDsgVarType_Vector : case eDsgVarType_List : case eDsgVarType_GameMaterial : case eDsgVarType_PersoArray: case eDsgVarType_VectorArray: case eDsgVarType_FloatArray: case eDsgVarType_IntegerArray: case eDsgVarType_WayPointArray: case eDsgVarType_Graph: case eDsgVarType_Caps: case eDsgVarType_TextArray: case eDsgVarType_Integer: case eDsgVarType_PositiveInteger: { M_GetDsgVarOffset(p_stLoadedMind,ucVarId)=ulBeginOffset; /* CAUTION : fn_vInitDsgVarDefault and not fn_vInitDsgVarInit nor fn_vInitDsgVar */ fn_vInitDsgVarDefault(p_stLoadedMind,ucVarId,eDsgVarTypeId,szParams); if (szParams[2] == NULL) ulBeginOffset+=fn_ulSizeOfDsgVar(eDsgVarTypeId, 0); else ulBeginOffset+=fn_ulSizeOfDsgVar(eDsgVarTypeId,(unsigned char) atoi(szParams[2])); /* check buffer overflow*/ #if defined(__DEBUG_AI__) if (ulBeginOffset>M_GetDsgVarSize(p_stLoadedMind)) { sprintf(szErrorString,"Allocated buffer for DsgMem is too small in %s .DEC (cf variable number %d,%s)\n",AI_M_szGetPersoName(p_stLoadedMind),ucVarId,szParams[1]); M_AIFatalErrorMsg(E_uwAIFatalScriptError,szErrorString); } #endif } break; case eDsgVarType_0To65535 : case eDsgVarType__32768To32767 : { M_GetDsgVarType(p_stLoadedMind,ucVarId)=eDsgVarTypeId; *p_wWordMem++ = ucVarId; switch (eDsgVarTypeId) { case eDsgVarType__32768To32767: *p_wWordMem++ = (C_TypeOf_32768To32767) atoi(szParams[2]); break; case eDsgVarType_0To65535: *p_wWordMem++ = (C_TypeOf0To65535) atoi(szParams[2]); break; default: break; } ucNbWord++; } break; default : { if (szParams[2] == NULL) ulEndOffset-=fn_ulSizeOfDsgVar(eDsgVarTypeId, 0); else ulEndOffset-=fn_ulSizeOfDsgVar(eDsgVarTypeId,(unsigned char) atoi(szParams[2])); /* check buffer overflow*/ #if defined(__DEBUG_AI__) if (ulEndOffset<0) { sprintf(szErrorString,"Allocated buffer for DsgMem is too small in %s .DEC (cf variable number %d,%s)\n",AI_M_szGetPersoName(p_stLoadedMind),ucVarId,szParams[1]); M_AIFatalErrorMsg(E_uwAIFatalScriptError,szErrorString); } #endif M_GetDsgVarOffset(p_stLoadedMind,ucVarId)=ulEndOffset; /* CAUTION : fn_vInitDsgVarDefault and not fn_vInitDsgVarInit nor fn_vInitDsgVar */ fn_vInitDsgVarDefault(p_stLoadedMind,ucVarId,eDsgVarTypeId,szParams); } break; } /* Switch*/ } } } else if (eType == SCR_EA_Anl_EndSection) { long ii=0; unsigned char ucVarIdWord; if (ucNbWord) { p_wWordMem = p_wWordMemInit; for (ii=0; iiulEndOffset) { sprintf(szErrorString,"Allocated buffer for DsgMem corrupted in %s .DEC\n",AI_M_szGetPersoName(p_stLoadedMind)); M_AIFatalErrorMsg(E_uwAIFatalScriptError,szErrorString); } #endif } return SCR_ERV_Anl_NormalReturn; } char cErrorInInitVariablesDetected = 0; SCR_tde_Anl_ReturnValue fn_eInitVariables(SCR_tdst_File_Description *p_stFile, char *szAction, char *szParams[], SCR_tde_Anl_Action eType) { p_stFile = p_stFile;/* for lint*/ if (eType == SCR_EA_Anl_BeginSection) { /* variables have not been allocated*/ if ( (p_stLoadedMind==NULL) || (AI_M_p_stGetDsgVar(p_stLoadedMind)==NULL) || (AI_M_p_stGetDsgMem(p_stLoadedMind)==NULL) || (M_GetDsgMemBufferInit(p_stLoadedMind)!=NULL) ) { #if defined(ACTIVE_1STPASS_CHECKING) || defined(__DEBUG_AI__) M_TestNodeInterpret(p_stLoadedMind,0,"This perso has no dsgvar anymore, so corresponding .CAR is an old one","",ScriptError); #if defined(ACTIVE_1STPASS_CHECKING) AI_M_ucErrorFlag(p_stLoadedMind)=2; #endif #else M_AIFatalErrorMsg(E_uwAIFatalScriptError,"This perso has no dsgvar anymore, so corresponding .CAR is an old one"); #endif } /* not the same sizes as in the .DEC !!!!! ????*/ else if ( (M_GetDsgVarSize(p_stLoadedMind)!=(unsigned long) atoi(szParams[0]) ) ||(M_GetNbDsgVar(p_stLoadedMind)!=(unsigned char) atoi(szParams[1]) ) ) { /* this is not the correct size*/ #if defined(__DEBUG_AI__) #if defined(ACTIVE_1STPASS_CHECKING) if(cErrorInInitVariablesDetected == 0) { cErrorInInitVariablesDetected = 1; sprintf(szForErrorStringAt1stPass,"Dsgvar number or size are different in .CAR and .DEC in %s",AI_M_szGetPersoName(p_stLoadedMind)); M_AIWarningErrorAndNeverStopForDebug(E_uwAIWarningScriptError,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass); } AI_M_ucErrorFlag(p_stLoadedMind)=1; fn_vForceEditor(); /* M_GetDsgMemBufferInit(p_stLoadedMind)=fn_p_cAllocDsgMemBuffer(M_GetDsgVarSize(p_stLoadedMind));*/ /* copy it from the model */ /* memcpy(M_GetDsgMemBufferInit(p_stLoadedMind),M_GetDsgMemDefaultInit(p_stLoadedMind),M_GetDsgVarSize(p_stLoadedMind));*/ #else sprintf(szForErrorStringAt1stPass,"Dsgvar number or size are different in .CAR and .DEC in %s",AI_M_szGetPersoName(p_stLoadedMind)); M_AIWarningErrorAndAllowStopForDebug(E_uwAIWarningScriptError,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass); #endif /* ACTIVE_1STPASS_CHECKING*/ #else /*M_AIFatalErrorMsg(E_uwAIFatalWrongTypeVar,"Dsgvar number or size are different in .CAR and .DEC");*/ #endif } /*else*/ { M_GetDsgMemBufferInit(p_stLoadedMind)=fn_p_cAllocDsgMemBuffer(M_GetDsgVarSize(p_stLoadedMind)); /* copy it from the model */ memcpy(M_GetDsgMemBufferInit(p_stLoadedMind),M_GetDsgMemDefaultInit(p_stLoadedMind),M_GetDsgVarSize(p_stLoadedMind)); } } else if (eType == SCR_EA_Anl_Entry) { /* si errorflag == 0 ok*/ /* si errorflag == 1 on peut faire certaines verifs*/ /* si errorflag == 2 on ne peut rien faire*/ #if defined(ACTIVE_1STPASS_CHECKING) if (AI_M_ucErrorFlag(p_stLoadedMind)!=2) #endif { tdeDsgVarTypeId eDsgVarTypeId=fn_eFindDsgVarTypeIdFromScriptName(szAction); unsigned char ucVarId= (unsigned char) atoi(szParams[0]); /* is type known ?*/ if (M_IsDsgVarTypeIdValid(eDsgVarTypeId)) { char szDecFilenameSection[300]; tdstEngineObject *p_stEngineObject=p_stLoadedEngineObject; SCR_tdst_Link_Value *p_stLinkValue=NULL; char cElement=(szParams[1][0]=='@'); char *szName=&szParams[1][cElement]; /* build .dec section*/ sprintf(szDecFilenameSection,"%s\\%s\\%s\\%s.dec^%s:%s", fn_szGetFamiliesDataPath(), fn_szFindFamilyTypeNameOfFamilyType(M_ObjectGetFamilyType(p_stLoadedEngineObject)), fn_szFindModelTypeNameOfModelType(M_ObjectGetModelType(p_stLoadedEngineObject)), fn_szFindModelTypeNameOfModelType(M_ObjectGetModelType(p_stLoadedEngineObject)), C_CreateVariables_String, szName ); /* is name known*/ p_stLinkValue = SCR_fnp_st_Link_SearchKey(&g_stDsgVarLinkTable,szDecFilenameSection); if (p_stLinkValue!=NULL) { ucVarId=(unsigned char) SCR_M_ul_Link_GetValue(p_stLinkValue); if (ucVarIdp_stAIModel->CFast_bIsC = 0; p_stLoadedMind->p_stAIModel->CFast_lFunction = 0; } else if (eType == SCR_EA_Anl_Entry) { if (M_IsIntellAIModel(szAction)) { AI_M_p_stGetIntelligenceScriptAIModel(p_stLoadedAIModel)=fn_p_stReadScriptAI(szParams[0]); } else if (M_IsReflexAIModel(szAction)) { AI_M_p_stGetReflexScriptAIModel(p_stLoadedAIModel)=fn_p_stReadScriptAI(szParams[0]); } else if (M_IsVariableDeclarationAIModel(szAction)) { /* read .dec*/ (void) SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal); /* (void) for lint.*/ } else if (M_IsMacroAIModel(szAction)) { SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal); } else if (!strcmpi(szAction, "CreateRefAIModel")) { #ifndef ACTIVE_EDITOR /* read .crr*/ if(SCR_fn_c_RdL0_IsSectionExists(szParams[0])) { SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal); } #endif } else if ( !strcmpi(szAction, "CreateRefTree")) { #ifndef ACTIVE_EDITOR /* read .nod*/ if(SCR_fn_c_RdL0_IsSectionExists(szParams[0])) { SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal); } #endif } /* Read for C run */ else if (!strcmpi(szAction, "CFast_IsC")) { p_stLoadedMind->p_stAIModel->CFast_bIsC = (ACP_tdxBool) fn_lAToI(szParams[0]); } else if (!strcmpi(szAction, "CFast_FunctionIndex")) { p_stLoadedMind->p_stAIModel->CFast_lFunction = fn_lAToI(szParams[0]); } else { M_AIFatalError(E_uwAIFatalBadEntryAIModel); } } else if (eType == SCR_EA_Anl_EndSection) { #if defined(ACTIVE_EDITOR) p_stLoadedMind->p_stAIModel->CFast_lFunction = 0; #endif } return SCR_ERV_Anl_NormalReturn; } char szDefineSection[256]; SCR_tde_Anl_ReturnValue fn_eCreateAIDefines(SCR_tdst_File_Description *p_stFile, char *szAction, char *szParams[], SCR_tde_Anl_Action eType) { static lLen=0; p_stFile=p_stFile;/* for lint*/ szAction=szAction; if (eType == SCR_EA_Anl_BeginSection) { strcpy(szDefineSection,SCR_M_RdL0_GetCompleteSectionNameR(0)); /* Gamedata\World\Level\_Common\Families\Defines.ai^CreateAiDefines*/ SCR_M_RdL0_ComputeOpenSectionNameR(0,szDefineSection); /* Defines.ai^CreateAiDefines*/ lLen=strlen(szDefineSection)-strlen(SCR_M_RdL0_GetCompleteSectionNameR(0)); } else if (eType == SCR_EA_Anl_Entry) /* work if data size if <= sizeof(long)*/ { unsigned long ulValue=0; /*ANNECY CHRISTOPHE MOFICATION CF XAVIER*/ unsigned long ulType = 0; /*ANNECY END CHRISTOPHE MODIFICATIONS CF XAVIER*/ szForScript[0]=0; if (M_IsConstantRef(szAction)) /* ConstantRef*/ { long lValue=(long) atoi(szParams[1]); ulValue=*((unsigned long*) &lValue); sprintf(szForScript,"%s:%s",szDefineSection,szParams[0]); /*ANNECY CHRISTOPHE MOFICATION CF XAVIER*/ ulType=E_vt_Integer; /*ANNECY END CHRISTOPHE MOFICATION CF XAVIER*/ } else if (M_IsRealRef(szAction)) /* RealRef*/ { MTH_tdxReal xReal=MTH_M_xFloatToReal((float) atof(szParams[1])); ulValue=*((long*) &xReal); sprintf(szForScript,"%s:%s",szDefineSection,szParams[0]); /*ANNECY CHRISTOPHE MOFICATION CF XAVIER*/ ulType=E_vt_Float; /*ANNECY END CHRISTOPHE MOFICATION CF XAVIER*/ } if (strlen(szForScript)!=0) { SCR_tdst_Link_Value *p_stLinkValue = SCR_fnp_st_Link_SearchKey(&g_stDefinesLinkTable,szForScript); if (p_stLinkValue==NULL) { p_stLinkValue=SCR_fnp_st_Link_SetValue(&g_stDefinesLinkTable, szForScript, ulValue); SCR_M_v_Link_SetAdditionalLong(p_stLinkValue,1,lLen); SCR_M_v_Link_SetAdditionalLong(p_stLinkValue,2,ulType); } else /* bizarre*/ { if (ulValue!=SCR_M_ul_Link_GetValue(p_stLinkValue)) { sprintf(szForScript,"%s redefinition in %s",szParams[0],szDefineSection); M_AIFatalErrorMsg(E_uwAIFatalScriptError,szForScript); } } } } return SCR_ERV_Anl_NormalReturn; } SCR_tde_Anl_ReturnValue fn_eCreatePseudoTree(SCR_tdst_File_Description *p_stFile, char *szAction, char *szParams[], SCR_tde_Anl_Action eType) { static lLen=0; static long lNumber = 0 ; struct tdstNodeInterpret_ *p_stNode ; if (eType == SCR_EA_Anl_BeginSection) { lNumber = 0 ; p_stLoadedNode = fn_p_stAllocNodeInterpret((unsigned short)atoi(szParams[0]) ); } else if (eType == SCR_EA_Anl_Entry) { if ( !strcmp(szAction, "MakeNode") ) { p_stNode = p_stLoadedNode + lNumber ; M_SetTypeInterpret(p_stNode, atoi(szParams[1]) ) ; M_lValueInterpret(p_stNode) = atoi(szParams[0]) ; lNumber++ ; } } else if (eType == SCR_EA_Anl_EndSection){ p_stLoadedMind->p_stAIModel->CFast_dst_ParamArray = p_stLoadedNode ; p_stLoadedMind->p_stAIModel->uwNbParamNode = lNumber ; } return SCR_ERV_Anl_NormalReturn; } #endif /* U64 */ void fn_vRegisterAllRulesScriptSections(void) { #if !defined(U64) /* .AI*/ SCR_fn_v_RdL0_RegisterCallback(C_CreateAIDefines_String ,fn_eCreateAIDefines , SCR_CRC_c_RdL0_ForSection); SCR_fn_v_RdL0_RegisterCallback(C_CreateAIModel_String ,fn_eCreateAIModel , SCR_CRC_c_RdL0_ForSection); /* .RUL & .RFX*/ SCR_fn_v_RdL0_RegisterCallback(C_CreateIntelligence_String ,fn_eCreateScriptAI , SCR_CRC_c_RdL0_ForSection); SCR_fn_v_RdL0_RegisterCallback(C_CreateComport_String ,fn_eCreateComport , SCR_CRC_c_RdL0_ForSection); SCR_fn_v_RdL0_RegisterCallback(C_CreateRule_String ,fn_eCreateRule , SCR_CRC_c_RdL0_ForSection); SCR_fn_v_RdL0_RegisterCallback(C_CreateSchedule_String ,fn_eCreateSchedule , SCR_CRC_c_RdL0_ForSection); /* .DEC*/ SCR_fn_v_RdL0_RegisterCallback(C_CreateVariables_String ,fn_eCreateVariables , SCR_CRC_c_RdL0_ForSection); /* .MAC*/ SCR_fn_v_RdL0_RegisterCallback(C_CreateMacro_String ,fn_eCreateMacros , SCR_CRC_c_RdL0_ForSection); SCR_fn_v_RdL0_RegisterCallback(C_CreateListOfMacro_String ,fn_eCreateListMacros , SCR_CRC_c_RdL0_ForSection); /* .CAR*/ SCR_fn_v_RdL0_RegisterCallback(C_InitVariables_String ,fn_eInitVariables , SCR_CRC_c_RdL0_ForSection); SCR_fn_v_RdL0_RegisterCallback(C_InitComportReflex_String ,fn_eInitComportReflex, SCR_CRC_c_RdL0_ForSection); SCR_fn_v_RdL0_RegisterCallback(C_InitComportIntelligence_String ,fn_eInitComportIntell, SCR_CRC_c_RdL0_ForSection); /* .NOD : CFAST*/ SCR_fn_v_RdL0_RegisterCallback(C_CreatePseudoTree_String ,fn_eCreatePseudoTree, SCR_CRC_c_RdL0_ForSection); #endif /* U64 */ } /* in fichier Defines.AI à mettre dans _Common\Families {CreateAIDefines: ConstantRef(Super,10) RealRef(XX,3.14156) RealRef(YY,5.0) RealRef(ZZ,10.0) } */ void fn_vReadAIDefines(char *szDefineFilename) { #if !defined(U64) char szSectionName[_MAX_PATH]; SCR_fn_v_RdL0_ComputeSectionName(szSectionName,szDefineFilename,C_CreateAIDefines_String,NULL); /* not activated for the moment*/ /*ANNECY CHRISTOPHE MODIFICATIONS CF XB*/ (void) SCR_fnp_st_RdL0_AnalyseSection(szSectionName, SCR_CDF_uw_Anl_Normal); /* (void) for lint.*/ /*ANNECY END CHRISTOPHE MODIFICATIONS CF XB*/ #endif } void fn_vReadAIModel(char *szModelFileName) { #if !defined(U64) char szSectionName[_MAX_PATH]; tdstScriptAI **p_p_stScriptAI=NULL; p_stLoadedAIModel=NULL; SCR_fn_v_RdL0_ComputeSectionName(szSectionName,szModelFileName,C_CreateAIModel_String,NULL); (void) SCR_fnp_st_RdL0_AnalyseSection(szSectionName, SCR_CDF_uw_Anl_Normal); /* (void) for lint.*/ /* alloc intelligence and link it with its script*/ p_p_stScriptAI=&AI_M_p_stGetIntelligenceScriptAIModel(p_stLoadedAIModel); if (*p_p_stScriptAI!=NULL) { AI_M_SetIntelligence(p_stLoadedMind, fn_p_stAllocIntelligence( p_p_stScriptAI, M_GetScriptAIActionTableNbEntry(*p_p_stScriptAI) ) ); } /* Alloc reflex (same structure as intelligence and link it with its script)*/ p_p_stScriptAI=&AI_M_p_stGetReflexScriptAIModel(p_stLoadedAIModel); if (*p_p_stScriptAI!=NULL) { AI_M_SetReflex(p_stLoadedMind, fn_p_stAllocIntelligence( p_p_stScriptAI, M_GetScriptAIActionTableNbEntry(*p_p_stScriptAI) ) ); } #endif /* U64 */ } void fn_vReadAI(AI_tdstMind *p_stMind,char *szIntellFileName,tdstEngineObject *p_stEngineObject) { /* global variable in this module*/ p_stLoadedMind = p_stMind; p_stLoadedEngineObject=p_stEngineObject; AI_M_SetPersoName(p_stMind, fn_szFindPersonalTypeNameOfPersonalType(M_ObjectGetPersonalType(p_stEngineObject))); fn_vReadAIModel(szIntellFileName); } void fn_vLoadCRR(AI_tdstMind *p_stMind, char *szFileName) { p_stLoadedMind = p_stMind; SCR_fnp_st_RdL0_AnalyseSection(szFileName, SCR_CDF_uw_Anl_ForceAnalyse); } SCR_tdst_Link_Value * fn_vGetLinkTableForCRR ( AI_tdstAIModel *p_stAIModel ) { return SCR_fnp_st_Link_SearchValue(&g_stModelLinkTable, (long)p_stAIModel) ; } void fn_vSetLinkTableForCRR ( SCR_tdst_Link_Value *p_stValue, unsigned long ulValue ) { SCR_tde_Link_State eState ; char szTemp[2048] ; eState = SCR_M_e_Link_GetState(p_stValue) ; strcpy ( szTemp, SCR_M_p_sz_Link_GetKey(p_stValue) ) ; SCR_fn_v_Link_DeleteEntry ( &g_stModelLinkTable, p_stValue ) ; SCR_fnp_st_Link_AddEntry( &g_stModelLinkTable, szTemp, ulValue, eState ) ; }