reman3/Rayman_X/cpa/tempgrp/AI/AIBase/specif/readruleCB.c

2210 lines
73 KiB
C
Raw Blame History

#include "ldt.h"
extern "C" HREF g_hRefBrain;
enum{
iEndCreateVariables,
iEndIntellModel,
iEndReflexModel,
iEndAIModel,
iEndInitVariables,
iEndComportIntell,
iEndComportReflex
};
/********************************************************
Init Node Functions
********************************************************/
#ifdef CPA_USES_LDT
static void fn_vInitNodeMacroRef(tdstNodeInterpret *p_stNode, char *szParams[])
{
unsigned char ucDepth=0;
SCR_tdst_Link_Value *p_stLinkValue;
char szFileName[_MAX_PATH];
/* fill the string szForScript.*/
fn_v_File_ComputeFileSectionName(LDT_szGetParam(1),szFileName,szForScript);
ucDepth =(unsigned char)atol(LDT_szGetParam(2));
p_stLinkValue = fn_vLinkWithLinkTable(&g_stMacroLinkTable, fn_szGetFamiliesDataPath(), szForScript,p_stNode,E_ti_MacroRef,ucDepth);
}
static void fn_vInitNodeCondition(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_eCondIdInterpret(p_stNode)=fn_eFindConditionIdFromScriptName(LDT_szGetParam(1));
M_TestNodeInterpret(p_stLoadedMind,M_IsConditionIdValid(M_eCondIdInterpret(p_stNode)),"Condition name",LDT_szGetParam(1),UnknownCond);
}
static void fn_vInitNodeField(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_eFieldIdInterpret(p_stNode)=fn_eFindFieldIdFromScriptName(LDT_szGetParam(1));
M_TestNodeInterpret(p_stLoadedMind,M_IsFieldIdValid(M_eFieldIdInterpret(p_stNode)),"Field name",LDT_szGetParam(1),UnknownFieldName);
}
static void fn_vInitNodeConstant(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_lValueInterpret(p_stNode)=atol(LDT_szGetParam(1));
}
static void fn_vInitNodeString(tdstNodeInterpret *p_stNode, char *szParams[])
{
fn_vCreateNodeString(p_stNode, LDT_szGetParam(1));
}
static void fn_vInitNodeButton(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_hInputHandleIdInterpret(p_stNode)=IPT_fn_hGetEntryActionHandle(LDT_szGetParam(1));
#if defined(__DEBUG_AI__)
if(!IPT_fn_bIsAValidEntryActionHandle(M_hInputHandleIdInterpret(p_stNode)))
{
M_StandardMessage(p_stLoadedMind,"Button name",LDT_szGetParam(1),UnknownButton);
}
#endif
}
static void fn_vInitNodeObjectTableRef(tdstNodeInterpret *p_stNode, char *szParams[])
{
/*to make sure the table is loaded*/
LDT_LoadSection(LDT_szGetParam(1));
/*now we can set the node value with the handle*/
fn_vLinkWithLinkTable(&TBL_g_stLinkTable, fn_szGetFamiliesDataPath(),LDT_szGetParam(1),p_stNode,E_ti_ObjectTableRef,(unsigned char) atol(LDT_szGetParam(2)));
}
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(LDT_szGetParam(1), SCR_CDF_uw_Anl_Normal);
/* p_stValues = (*SCR_tdst_Cxt_Values)LDT_LoadSection(LDT_szGetParam(1));*/
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(LDT_szGetParam(1), SCR_CDF_uw_Anl_Normal);
/* p_stValues = (*SCR_tdst_Cxt_Values)LDT_LoadSection(LDT_szGetParam(1));*/
/* A voir...*/
M_hLipSynchroHandleIdInterpret(p_stNode) = (tdxHandleOfLipsSynchroTable)(p_stValues->a_ulValues[0]);
fn_vWriteLipsSynchroBloc((tdxHandleOfLipsSynchroTable)(p_stValues->a_ulValues[0]),LDT_szGetParam(1));
/* End VH*/
SNA_fn_vWriteLipsSynchEntryInLipsSynchTableFile(LDT_szGetParam(1),(unsigned long)p_stNode);
}
}
static void fn_vInitNodeSoundEventRef(tdstNodeInterpret *p_stNode, char *szParams[])
{
/* SCR_tdst_Cxt_Values *p_stValues;*/
/* p_stValues = SCR_fnp_st_RdL0_AnalyseSection(LDT_szGetParam(1), SCR_CDF_uw_Anl_Normal);*/
/* M_SoundEventInterpret(p_stNode) = (SND_tdxHandleToSoundEvent) (p_stValues->a_ulValues[0]);*/
SND_tdxHandleToSoundEvent handle =
M_SoundEventInterpret(p_stNode) = (SND_tdxHandleToSoundEvent) LDT_LoadSection(LDT_szGetParam(1));
if (SNA_fn_ucGetLoadType()==SNA_SAVE_SNAPSHOT)
SNA_fn_vWriteSoundEntryInSoundTableFile(SND_fn_ulGetEventBinIdFromPointer(handle) ,(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(LDT_szGetParam(1));
}
static void fn_vInitNodeDsgVarRef(tdstNodeInterpret *p_stNode, char *szParams[])
{
char sz[MAX_PATH];
strcpy( sz, LDT_szGetParam(1) );
fn_vLinkWithLinkTable(&g_stDsgVarLinkTable, fn_szGetFamiliesDataPath(), sz,p_stNode,E_ti_DsgVarRef,(unsigned char) atol(LDT_szGetParam(2)));
sz[0]=sz[0];
}
static void fn_vInitNodeOperator(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_eOperatorIdInterpret(p_stNode)=fn_eFindOperatorIdFromScriptName(LDT_szGetParam(1));
M_TestNodeInterpret(p_stLoadedMind,M_IsOperatorIdValid(M_eOperatorIdInterpret(p_stNode)),"Operator name",LDT_szGetParam(1),UnknownOperator);
}
static void fn_vInitNodeFunction(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_eFuncIdInterpret(p_stNode)=fn_eFindFunctionIdFromScriptName(LDT_szGetParam(1));
M_TestNodeInterpret(p_stLoadedMind,M_IsFuncIdValid(M_eFuncIdInterpret(p_stNode)),"Function name",LDT_szGetParam(1),UnknownFunc);
}
static void fn_vInitNodeProcedure(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_eProcedureIdInterpret(p_stNode) = fn_eFindProcedureIdFromScriptName(LDT_szGetParam(1));
M_TestNodeInterpret(p_stLoadedMind,M_IsProcedureIdValid(M_eProcedureIdInterpret(p_stNode)),"Procedure name",LDT_szGetParam(1),UnknownFunc);
}
static void fn_vInitNodeKeyWord(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_eKeyWordIdInterpret(p_stNode)=fn_eFindKeyWordIdFromScriptName(LDT_szGetParam(1));
M_TestNodeInterpret(p_stLoadedMind,M_IsKeyWordIdValid(M_eKeyWordIdInterpret(p_stNode)),"Keyword name",LDT_szGetParam(1),UnknownKeyWord);
}
static void fn_vInitNodeMetaAction(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_eMetaActionIdInterpret(p_stNode) = fn_eFindMetaActionIdFromScriptName(LDT_szGetParam(1));
/* bidouille temporaire */
if (!M_IsMetaActionIdValid(M_eMetaActionIdInterpret(p_stNode)))
{
char str[256]="Proc";
char *ptr;
if ((ptr=strchr(LDT_szGetParam(1),'_'))!=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",LDT_szGetParam(1),InvalidAction);
}
static void fn_vInitNodeReal(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_xValueInterpret(p_stNode) = MTH_M_xFloatToReal((float) atof(LDT_szGetParam(1)));
}
static void fn_vInitNodeSuperObjectRef(tdstNodeInterpret *p_stNode, char *szParams[])
{
fn_vLinkWithLinkTable(HIE_fn_p_stGetSuperObjectLinkTable(), fn_szGetLevelsDataPath(), LDT_szGetParam(1),p_stNode,E_ti_SuperObjectRef,(unsigned char) atol(LDT_szGetParam(2)));
}
static void fn_vInitNodeFamilyRef(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_hFamilyHandleIdInterpret(p_stNode) = fn_hFindOrAddFAmily(fn_otFindOrAddFamilyTypeOfFamilyTypeName(LDT_szGetParam(1)));
}
static void fn_vInitNodeTextRef(tdstNodeInterpret *p_stNode,char *szParams[])
{
/*M_TextInterpret(p_stNode) = FON_fn_hGetTextHandle(szParams[0]);*/
FON_tdxHandleOfText hText = FON_fn_hGetTextHandle(LDT_szGetParam(1));
M_TestNodeInterpret(p_stLoadedMind,(long)hText,"Text Key",LDT_szGetParam(1),ScriptError);
M_TextInterpret(p_stNode) = hText;
}
static void fn_vInitNodeParticleGenerator(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_ParticleGeneratorInterpret(p_stNode) = (tdxHandleToParticleGenerator)LDT_LoadSection(LDT_szGetParam(1));/*(p_stValues->a_ulValues[0]);*/
}
static void fn_vInitNodeGameMaterialRef(tdstNodeInterpret *p_stNode, char *szParams[])
{
char szFile[SCR_CV_ui_Cfg_MaxLenName], szParent[SCR_CV_ui_Cfg_MaxLenName], szAction[SCR_CV_ui_Cfg_MaxLenName], szId[SCR_CV_ui_Cfg_MaxLenName];
char Buffer[SCR_CV_ui_Cfg_MaxLenName];
LDT_SplitSectionName( LDT_szGetParam(1), szFile, szParent, szAction, szId );
if( !LDT_SearchFile( szFile, Buffer ) )
{
strcpy( szFile, Buffer );
strcat( szFile, "^" );
if( szParent[0] )
{
strcat( szFile, szParent );
strcat( szFile, "^" );
}
strcat( szFile, szAction );
if( szId[0] )
{
strcat( szFile, ":" );
strcat( szFile, szId );
}
}
else
strcat( szFile, " (not loaded!!)" );
fn_vLinkWithLinkTable(GMT_fn_p_stGetLinkTable(), NULL, szFile, p_stNode, E_ti_GameMaterialRef, (unsigned char) atol(LDT_szGetParam(2)));
}
static void fn_vInitNodeColor(tdstNodeInterpret *p_stNode,char *szParams[])
{
M_ColorValueInterpret(p_stNode)=atol(LDT_szGetParam(1));
}
static void fn_vInitNodePersoRef(tdstNodeInterpret *p_stNode, char *szParams[])
{
unsigned char ucDepth=0;
/* Reference compatibility : 0,1,2 <-> 0^1:2*/
if (LDT_iGetNbParams()-1>2)
{
strcpy(szForScript,LDT_szGetParam(1));
strcat(szForScript,SCR_CC_sz_Cfg_NameSeparator);
strcat(szForScript,LDT_szGetParam(2));
strcat(szForScript,SCR_CC_sz_Cfg_SectionIdMark);
strcat(szForScript,LDT_szGetParam(3));
/* szForScript contains now the complete section name*/
ucDepth=(unsigned char) atol(LDT_szGetParam(4));
}
else
{
strcpy(szForScript,LDT_szGetParam(1));
ucDepth=(unsigned char) atol(LDT_szGetParam(2));
}
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 (LDT_iGetNbParams()-1>2)
{
SCR_fn_v_RdL0_ComputeSectionName(szForScript, LDT_szGetParam(1), LDT_szGetParam(2), LDT_szGetParam(3));
ucDepth=(unsigned char)atol(LDT_szGetParam(4));
}
else
{
char szFileName[_MAX_PATH];
fn_v_File_ComputeFileSectionName(LDT_szGetParam(1),szFileName,szForScript);
ucDepth =(unsigned char)atol(LDT_szGetParam(2));
}
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[])
{
fn_vLinkWithLinkTable(&CHL_g_stLinkTable, NULL, LDT_szGetParam(1), p_stNode, E_ti_ModuleRef, (unsigned char) atol(LDT_szGetParam(2)));
}
static void fn_vInitNodeActionRef(tdstNodeInterpret *p_stNode, char *szParams[])
{
fn_vLinkWithLinkTable(&g_st3DOSLinkTable.stState, fn_szGetFamiliesDataPath(), LDT_szGetParam(1),p_stNode,E_ti_ActionRef,(unsigned char) atol(LDT_szGetParam(2)));
}
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(LDT_szGetParam(1)));
xY=MTH_M_xFloatToReal((float) atof(LDT_szGetParam(2)));
xZ=MTH_M_xFloatToReal((float) atof(LDT_szGetParam(3)));
MTH3D_M_vSetVectorElements(p_stVector,xX,xY,xZ);
M_DepthInterpret(p_stNode)= (unsigned char)atol(LDT_szGetParam(4));
}
static void fn_vInitNodeWayPoint(tdstNodeInterpret *p_stNode, char *szParams[])
{
char szForScript[256];
strcpy(szForScript,fn_szGetLevelsDataPath());
strcat(szForScript,"\\");
strcat(szForScript,LDT_szGetParam(1));
M_lKeyLinkInterpret(p_stNode) = (long)SCR_fnp_st_Link_CreateOrGetLinkFromKey(WP_fnp_WayPoint_GetLinkTable(),szForScript);
}
static void fn_vInitNodeModule(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_lModuleInterpret(p_stNode)=atol(LDT_szGetParam(1));
}
static void fn_vInitNodeDsgVarId(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_lDsgVarIdInterpret(p_stNode)=atol(LDT_szGetParam(1));
}
static void fn_vInitNodeMask(tdstNodeInterpret *p_stNode, char *szParams[])
{
M_xMaskInterpret(p_stNode)=(GMT_tdxMask) atol(LDT_szGetParam(1));
}
static void fn_vInitNodeModelRef(tdstNodeInterpret *p_stNode, char *szParams[])
{
fn_vLinkWithLinkTable(&g_stModelLinkTable, fn_szGetFamiliesDataPath(), LDT_szGetParam(1),p_stNode,E_ti_ModelRef,(unsigned char) atol(LDT_szGetParam(2)));
}
static void fn_vInitNodeLight(tdstNodeInterpret *p_stNode, char *szParams[])
{
char a255_csCompleteSectionName [255];
strcpy(a255_csCompleteSectionName,fn_szGetLevelsDataPath());
strcat(a255_csCompleteSectionName,"\\");
strcat(a255_csCompleteSectionName,LDT_szGetParam(1));
M_lKeyLinkInterpret(p_stNode) =
SCR_fnp_st_Link_CreateOrGetLinkFromKey(&gs_stLightLinkTable,a255_csCompleteSectionName)->ulValue;
}
static void fn_vInitNodeCaps(tdstNodeInterpret *p_stNode, char *szParams[])
{
char* dummy;
M_ulCapsInterpret(p_stNode) = (unsigned long) strtoul(LDT_szGetParam(1), &dummy, 2);
}
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, LDT_szGetParam(1));
M_lKeyLinkInterpret(p_stNode) = (long)SCR_fnp_st_Link_CreateOrGetLinkFromKey(WPG_fnp_Graph_GetLinkTable(),szForScript);
}
#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,LDT_szGetParam(1));
p_stLinkValue= SCR_fnp_st_Link_SearchKey(&g_stDefinesLinkTable,szForScript);
M_TestNodeInterpret(p_stLoadedMind,p_stLinkValue,"Constant Ref",LDT_szGetParam(1),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,LDT_szGetParam(1));
p_stLinkValue = SCR_fnp_st_Link_SearchKey(&g_stDefinesLinkTable,szForScript);
M_TestNodeInterpret(p_stLoadedMind,p_stLinkValue,"Real Ref",LDT_szGetParam(1),UnknownNode);
if (p_stLinkValue!=NULL)
M_lValueInterpret(p_stNode)=SCR_M_ul_Link_GetValue(p_stLinkValue);
}
#endif /* CPA_USES_LDT*/
/*################################################################
End of init node functions
################################################################*/
/*****************************************************************
Name:
Description: Create callback for LDT
Author: Mircea Petrescu
Date: 10/2/98
Modified: Mircea Petrescu 98/10/02 - fixed values transfer
*****************************************************************/
int fn_iCreateRule( LDT_tdst_Link *pLink )
{
LDT_SetVolatileSubsection(pLink);
return 0;
}
/*----------------------------------------------------------------------
* Description: callback for CreateRule section from .RUL sript file
*----------------------------------------------------------------------
* Input:
* Output:
*----------------------------------------------------------------------
* Author: FS
* Creation date:6/18/98
* Modif date:
*----------------------------------------------------------------------*/
int fn_iLoadRule( LDT_tdst_Link *pLink )
{
LDT_tdeParseResult result=ParseResult_BeginSection;
static char cIsCRR = 0;
char *psz_Temp;
char szErrorString[100];
/* Determin if it's a CRR */
psz_Temp = strrchr(pLink->szFile, '.');
if(psz_Temp && !strcmpi(psz_Temp, ".crr"))
cIsCRR = 1;
else
cIsCRR = 0;
if (cIsCRR || (ucInComportSection==TRUE))
{
/* Begin section*/
ucInRuleSection=TRUE;
/* plus 1 for adding a dummy node at the end of the tree*/
ScriptCounter.uwNbNode=(unsigned short) (atoi(LDT_szGetParam(2))+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);
}
/* work for entries*/
result=LDT_GetNextEntry();
while( result!=ParseResult_EndSection )
{
unsigned char ucDepth=0;
if (LDT_iGetNbParams()-1>=2)
{
ucDepth=(unsigned char) atol(LDT_szGetParam(2));
}
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( LDT_szGetEntryName(), NULL, p_stLoadedMind->p_stAIModel->CFast_dst_RefTreeArray + StructCounter.uwNbNode,
ucDepth);
else
fn_vConvertAndInitNode( LDT_szGetEntryName(), NULL, M_GetNodeInterpretN(p_stLoadedRule,StructCounter.uwNbNode),
ucDepth);
StructCounter.uwNbNode++;
}
else
{
M_AIFatalError(E_uwAIFatalBadNodeNumber);
}
result=LDT_GetNextEntry();
} /*end while for entries*/
/* work for 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
{
/*error : CreateRule not in CreateComport*/
M_AIFatalError(E_uwAIFatalRuleNotInComport);
}
return 0;
}
/*****************************************************************
Name:
Description: Create callback for LDT
Author: Mircea Petrescu
Date: 10/2/98
Modified: Mircea Petrescu 98/10/02 - fixed values transfer
*****************************************************************/
int fn_iCreateSchedule( LDT_tdst_Link *pLink )
{
LDT_SetVolatileSubsection( pLink );
return 0;
}
/*----------------------------------------------------------------------
* Description: callback for CreateSchedule section from .RUL and ,RFX
* script files
*----------------------------------------------------------------------
* Input:
* Output:
*----------------------------------------------------------------------
* Author: FS
* Creation date:6/28/98
* Modif date:
*----------------------------------------------------------------------*/
int fn_iLoadSchedule( LDT_tdst_Link *pLink )
{
LDT_tdeParseResult result=ParseResult_BeginSection;
char szErrorString[100];
if (ucInComportSection==TRUE)
{
/* BeginSection*/
ucInRuleSection=TRUE;
/* plus 1 for adding a dummy node at the end of the tree*/
ScriptCounter.uwNbNode=(unsigned short) (atoi(LDT_szGetParam(2))+1);
StructCounter.uwNbNode=0;
/* allocate schedule*/
p_stLoadedSchedule=fn_p_stAllocSchedule(ScriptCounter.uwNbNode);
/* connect schedule to comport*/
M_GetComportSchedule(p_stLoadedComport)=p_stLoadedSchedule;
/* Working for Entries*/
result=LDT_GetNextEntry();
while( result!=ParseResult_EndSection )
{
unsigned char ucDepth=0;
if (LDT_iGetNbParams()-1>=2)
{
ucDepth=(unsigned char) atol(LDT_szGetParam(2));
}
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( LDT_szGetEntryName(), NULL, 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);
}
result=LDT_GetNextEntry();
} /*end while for entries*/
/* Work for 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
{
/*error : CreateSchedule not in CreateComport*/
sprintf(szErrorString,"Problem (schedule comport n. %d)\n", StructCounter.ulNbComport);
M_AIFatalErrorMsg(E_uwAIFatalRuleNotInComport,szErrorString);
}
return 0;
}
/*----------------------------------------------------------------------
* Description: callback for CreateComport section from .RUL & .RFX sript files
*----------------------------------------------------------------------
* Input:
* Output:
*----------------------------------------------------------------------
* Author: FS
* Creation date:6/28/98
* Modif date:
*----------------------------------------------------------------------*/
int fn_iLoadComport( LDT_tdst_Link *pLink )
{
LDT_tdeParseResult result;
char szForScript[MAX_PATH], szSectionName[100];
char szErrorString[100];
int iLengthFile=0;
if (ucInIntelligenceSection==TRUE)
{
/* this parameter (section name) is many times used*/
strcpy(szSectionName,LDT_szGetSectionName());
/* BeginSection*/
VIG_fn_vAddToProgressBar(1);
ucInComportSection=TRUE;
/* Nb Rules in this comport*/
if (LDT_iGetNbParams()-1==2)
ScriptCounter.ucNbRules=(unsigned char) atoi(LDT_szGetParam(2));
else
ScriptCounter.ucNbRules=(unsigned char) atoi(LDT_szGetParam(1));
StructCounter.ucNbRules=0;
if (StructCounter.ulNbComport < ScriptCounter.ulNbComport)
{
p_stLoadedComport=M_GetScriptAIComportN(p_stLoadedScriptAI, StructCounter.ulNbComport);
/* iLengthFile wills contain the length of string file name*/
/* szForScript wills contain the complete section name*/
iLengthFile=LDT_ComputeSectionName(pLink, szForScript);
/* determin iLengthFile manual*/
/* iLengthFile=strlen(fn_szGetFamiliesDataPath())+1;*/
/* pana aici scot*/
SCR_M_v_Link_SetAdditionalLong(SCR_fnp_st_Link_SetValue(&g_stComportLinkTable,
szForScript,
(unsigned long)p_stLoadedComport),
1,iLengthFile);
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__)
/* szFamiliesDataPath=fn_szGetFamiliesDataPath();*/
strcpy(M_GetNameComport(p_stLoadedComport), szForScript+iLengthFile);
#endif
}
else
{
/*error : CreateComport(n) n is bad : already initialized*/
sprintf(szErrorString,"Problem (comport n. %d : %s)\n", StructCounter.ulNbComport, szSectionName);
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, szSectionName);
M_AIFatalErrorMsg(E_uwAIFatalBadComportNumber,szErrorString);
}
result=LDT_GetNextEntry();
while( result!=ParseResult_EndSection )
{
/* Load SubSection (CreateRule or CreateSchedule)*/
LDT_LoadSection(NULL);
result=LDT_GetNextEntry();
}
/* Working for EndSection*/
if (ScriptCounter.ucNbRules!=StructCounter.ucNbRules)
{
sprintf(szErrorString,"Number of rules in this comport (comport n. %d : %s) should be (%d)\n", StructCounter.ulNbComport, szSectionName, 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 0;
}
/*****************************************************************
Name:
Description: Create callback for LDT
Author: Mircea Petrescu
Date: 10/2/98
Modified: Mircea Petrescu 98/10/02 - fixed values transfer
*****************************************************************/
int fn_iCreateIntelligence( LDT_tdst_Link *pLink )
{
return 0;
}
/*----------------------------------------------------------------------
* Description: callback for CreateIntelligence section from .RUL or
* .RFX sript files
*----------------------------------------------------------------------
* Input:
* Output:
*----------------------------------------------------------------------
* Author: FS
* Creation date:6/28/98
* Modif date:
*----------------------------------------------------------------------*/
int fn_iLoadIntelligence( LDT_tdst_Link *pLink )
{
char szForScript[MAX_PATH];
LDT_tdeParseResult result=ParseResult_BeginSection;
unsigned char ucActionTableNbEntry=DEFAULT_ACTION_TABLE_NB_ENTRIES;
unsigned long ulNoComportInitDefault=0;
int i=LDT_iGetNbParams();
p_stLoadedAIModel=(AI_tdstAIModel *)pLink->pParent->pObject;
p_stLoadedEngineObject=(tdstEngineObject *)LDT_GetLinkValue( pLink->pParent );
p_stLoadedMind=M_pstGetMindOfBrain((MS_tdxHandleToBrain)p_stLoadedEngineObject->h_Brain);
ucInIntelligenceSection=TRUE;
if (LDT_iGetNbParams()-1>1)
{
ucActionTableNbEntry=(unsigned char) atoi(LDT_szGetParam(2));
if (ucActionTableNbEntry<MIN_ACTION_TABLE_NB_ENTRIES)
{
ucActionTableNbEntry=MIN_ACTION_TABLE_NB_ENTRIES;
}
}
/* optional parameter in script : comportement initial*/
/* une grosse bidouille : on stocke ce qui est retourn<72> par SCR_fnp_st_Link_CreateOrGetLinkFromKey gr<67>ce <20> M_GetScriptAINoComportInitDefault*/
/* attention <20> la deuxi<78>me passe dans AI_PROTO.C*/
if ( LDT_iGetNbParams()-1==3 )
{
SCR_tdst_Link_Value *p_stLinkValue;
LDT_ComputeSectionName(pLink,szForScript);
strcat(szForScript,SCR_CC_sz_Cfg_NameSeparator); /* add the type section prefix*/
strcat(szForScript,strlwr(C_CreateComport_String)); /* add the "CreateComport" section name*/
strcat(szForScript,SCR_CC_sz_Cfg_SectionIdMark); /* add the name section prefix*/
strcat(szForScript,LDT_szGetParam(3)); /* add the section name*/
p_stLinkValue = SCR_fnp_st_Link_CreateOrGetLinkFromKey(&g_stComportLinkTable, szForScript);
SCR_M_v_Link_SetAdditionalLong(p_stLinkValue, 4, 0);
ulNoComportInitDefault = (unsigned long) p_stLinkValue;
}
ScriptCounter.ulNbComport=(unsigned long) atoi(LDT_szGetParam(1));
StructCounter.ulNbComport=0;
if (ScriptCounter.ulNbComport!=0)
{
/* alloc script AI*/
p_stLoadedScriptAI=fn_p_stAllocScriptAI(ucActionTableNbEntry);
p_stLoadedComport=fn_p_stAllocComport(ScriptCounter.ulNbComport);
M_GetScriptAIComport(p_stLoadedScriptAI)=p_stLoadedComport;
M_GetScriptAINbComport(p_stLoadedScriptAI)=ScriptCounter.ulNbComport;
M_GetScriptAINoComportInitDefault(p_stLoadedScriptAI)=ulNoComportInitDefault;
}
/* read the next line in script file*/
result=LDT_GetNextEntry();
while( result!=ParseResult_EndSection )
{
/* Load SubSection (CreateComport)*/
LDT_LoadSection(NULL);
result=LDT_GetNextEntry();
}
/* EndSection*/
if (ScriptCounter.ulNbComport!=StructCounter.ulNbComport)
{
M_AIFatalError(E_uwAIFatalBadComportNumber);
}
ucInIntelligenceSection=FALSE;
if (ScriptCounter.ulNbComport!=0)
pLink->pObject=(void *)p_stLoadedScriptAI;
else
pLink->pObject=NULL;
return 0;
}
int fn_iCreateAIModel( LDT_tdst_Link *pLink )
{
p_stLoadedAIModel=fn_p_stAllocAIModel();
pLink->pObject=(void *)p_stLoadedAIModel;
LDT_SetLinkValue( pLink, (long)p_stLoadedEngineObject );
return 0;
}
/*----------------------------------------------------------------------
* Description: callback for CreateAIModel section from .AI script file
*----------------------------------------------------------------------
* Input:
* Output:
*----------------------------------------------------------------------
* Author: FS
* Creation date:9/10/98
* Modif date:
*----------------------------------------------------------------------*/
#define lCreateIntellAIModel 0x65746E49 /*"CreateIntellAIModel" - the 4 letters after "Create"*/
#define lCreateReflexAIModel 0x6C666552 /*"CreateReflexAIModel" - the 4 letters after "Create"*/
#define lCreateVariableDeclarationAIModel 0x69726156 /*"CreateVariableDeclarationAIModel" - the 4 letters after "Create"*/
#define lCreateMacroAIModel 0x7263614D /*"CreateMacroAIModel" - the 4 letters after "Create"*/
#define lCreateRefAIModel 0x41666552 /*"CreateRefAIModel" - the 4 letters after "Create"*/
#define lCFast_IsC 0x00437349 /*"CFast_IsC" - the 4 letters after "CFast_"*/
#define lCFast_FunctionIndex 0x636E7546 /*"CFast_FunctionIndex" the 4 letters after "CFast_"*/
int fn_iLoadAIModel( LDT_tdst_Link *pLink )
{
LDT_tdeParseResult result=ParseResult_BeginSection;
char *szEntryName;
char szForScript[_MAX_PATH]="";
static int CFast=0;
int iLen;
p_stLoadedAIModel=(AI_tdstAIModel *)pLink->pObject;
p_stLoadedEngineObject=(tdstEngineObject *)LDT_GetLinkValue( pLink );
p_stLoadedMind=M_pstGetMindOfBrain((MS_tdxHandleToBrain)p_stLoadedEngineObject->h_Brain);
/*Working for BeginSection*/
/* hyper important*/
AI_M_SetAIModel(p_stLoadedMind,p_stLoadedAIModel);
iLen=LDT_ComputeSectionName( pLink, szForScript );
SCR_M_v_Link_SetAdditionalLong(
SCR_fnp_st_Link_SetValue(&g_stModelLinkTable, szForScript, (unsigned long)p_stLoadedAIModel),1,
/* the next is the length of path*/
iLen);
/* Some inits */
p_stLoadedMind->p_stAIModel->CFast_bIsC = 0;
p_stLoadedMind->p_stAIModel->CFast_lFunction = 0;
/* read the next line in script file*/
result=LDT_GetNextEntry();
/*Working for entries*/
while( result!=ParseResult_EndSection )
{
szEntryName=LDT_szGetEntryName();
switch (*(long*)(szEntryName+strlen("Create")))
{
case lCreateIntellAIModel:
/* read .rul*/
fn_p_stReadScriptAI(LDT_szGetParam(1));
LDT_AddToRefsTable( g_hRefBrain, pLink, iEndIntellModel, 0 );
break;
case 'TfeR' : /* CreateRefTree */
{
/* read .nod*/
LDT_LoadSection(LDT_szGetParam(1));
}
break;
case lCreateReflexAIModel:
/* read .rfx*/
fn_p_stReadScriptAI(LDT_szGetParam(1));
LDT_AddToRefsTable( g_hRefBrain, pLink, iEndReflexModel, 0 );
break;
case lCreateVariableDeclarationAIModel:
/*(void) SCR_fnp_st_RdL0_AnalyseSection(LDT_szGetParam(1), SCR_CDF_uw_Anl_Normal); // (void) for lint.*/
LDT_LoadSection(LDT_szGetParam(1));
break;
case lCreateMacroAIModel:
LDT_LoadSection(LDT_szGetParam(1));
break;
case lCreateRefAIModel:
/* read .crr*/
/*(void) SCR_fnp_st_RdL0_AnalyseSection(LDT_szGetParam(1), SCR_CDF_uw_Anl_Normal); // (void) for lint.*/
LDT_LoadSection( LDT_szGetParam(1) );
break;
case lCFast_IsC:
p_stLoadedMind->p_stAIModel->CFast_bIsC = (ACP_tdxBool) fn_lAToI(LDT_szGetParam(1));
break;
case lCFast_FunctionIndex:
p_stLoadedMind->p_stAIModel->CFast_lFunction = fn_lAToI(LDT_szGetParam(1));
break;
}/* end switch*/
result=LDT_GetNextEntry();
}/*end while*/
/*Working for EndSection*/
/*
* Search CFast function in array.
*/
/*
int i;
char a_szTemp[255];
char *szModelName;
strcpy(a_szTemp, "CFast_");
szModelName = fn_szFindModelTypeNameOfModelType(M_ObjectGetModelType(p_stLoadedEngineObject));
strcat(a_szTemp, szModelName);
strcat(a_szTemp, "_Main");
i = 1;
while(CFast_gast_ArrayFunctions[i].mpsz_Name != NULL)
{
if(!strcmpi(CFast_gast_ArrayFunctions[i].mpsz_Name, a_szTemp))
{
p_stLoadedMind->p_stAIModel->CFast_lFunction = i;
break;
}
i++;
}
*/
if ( !CFast )
p_stLoadedMind->p_stAIModel->CFast_lFunction = 0;
return 0;
}
/*****************************************************************
Name:
Description: Create callback for LDT
Author: Mircea Petrescu
Date: 10/2/98
Modified: Mircea Petrescu 98/10/02 - fixed values transfer
*****************************************************************/
int fn_iCreateAIDefines( LDT_tdst_Link *pLink )
{
/* pLink->pObject=(void *)p_stElement;*/
return 0;
}
/*----------------------------------------------------------------------
* Description: callback for CreateAIDefines section from .AI sript file
*----------------------------------------------------------------------
* Input:
* Output:
*----------------------------------------------------------------------
* Author: FS
* Creation date:9/10/98
* Modif date:
*----------------------------------------------------------------------*/
int fn_iLoadAIDefines( LDT_tdst_Link *pLink )
{
#define lConstantRef 0x736E6F43 /*"ConstantRef" - the first 4 letters*/
#define lRealRef 0x6C616552 /*"RealRef" - the first 4 letters*/
char szDefineSection[MAX_PATH];
LDT_tdeParseResult result=ParseResult_BeginSection;
char *szEntryName;
static lLen=0;
unsigned long ulValue=0, ulType = 0;
long lValue;
/*Working for BeginSection*/
lLen=LDT_ComputeSectionName(pLink,szDefineSection);
/* read the next line in script file*/
result=LDT_GetNextEntry();
/*Working for entries*/
while( result!=ParseResult_EndSection )
{
ulValue=0;
/*ANNECY CHRISTOPHE MOFICATION CF XAVIER*/
ulType = 0;
/*ANNECY END CHRISTOPHE MODIFICATIONS CF XAVIER*/
szForScript[0]=0;
szEntryName=LDT_szGetEntryName();
switch (*(long*)(szEntryName))
{
case lConstantRef:
lValue=(long) atoi(LDT_szGetParam(2));
ulValue=*((unsigned long*) &lValue);
sprintf(szForScript,"%s:%s",szDefineSection,LDT_szGetParam(1));
/*ANNECY CHRISTOPHE MOFICATION CF XAVIER*/
ulType=E_vt_Integer;
/*ANNECY END CHRISTOPHE MOFICATION CF XAVIER*/
break;
case lRealRef:
MTH_tdxReal xReal=MTH_M_xFloatToReal((float) atof(LDT_szGetParam(2)));
ulValue=*((long*) &xReal);
sprintf(szForScript,"%s:%s",szDefineSection,LDT_szGetParam(1));
/*ANNECY CHRISTOPHE MOFICATION CF XAVIER*/
ulType=E_vt_Float;
/*ANNECY END CHRISTOPHE MOFICATION CF XAVIER*/
break;
}/* end switch*/
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",LDT_szGetParam(1),szDefineSection);
M_AIFatalErrorMsg(E_uwAIFatalScriptError,szForScript);
}
}
}
result=LDT_GetNextEntry();
}/*end while*/
return 0;
}
/*****************************************************************
Name:
Description: Create callback for LDT
Author: Mircea Petrescu
Date: 9/17/98
Modified: Mircea Petrescu 98/10/02 - fixed values transfer
*****************************************************************/
int CreateDEC( LDT_tdst_Link *pLink )
{
LDT_SetLinkValue( pLink, (long)p_stLoadedEngineObject );
pLink->pObject=(void *)p_stLoadedMind;
return 0;
}
/*****************************************************************
Name: fn_iCreateMacros
Description: Create callback for LDT
Author: Florin Scantee
Date: 8/7/98
Modified: Mircea Petrescu 98/10/02 - fixed values transfer
*****************************************************************/
int fn_iCreateMacros( LDT_tdst_Link *pLink )
{
LDT_SetLinkValue(pLink,(long)p_stLoadedMind);
return 0;
}
/*****************************************************************
Name:
Description: Load callback for LDT
Author: Florin Scantee
Date: 8/12/98
Modified: Mircea Petrescu 98/10/02 - fixed values transfer
*****************************************************************/
int fn_iLoadMacros( LDT_tdst_Link *pLink )
{
char szForScript[256];
char szErrorString[100];
tdstMacro *p_stMacro;
int iLen;
LDT_tdeParseResult result=ParseResult_BeginSection;
AI_tdstMind *p_stLoadedMind=(AI_tdstMind *)LDT_GetLinkValue(pLink);
ucInRuleSection=TRUE;
/* plus 1 for adding a dummy node at the end of the tree*/
ScriptCounter.uwNbNode=(unsigned short) (atoi(LDT_szGetParam(2))+1);
StructCounter.uwNbNode=0;
/* allocate Macro*/
p_stMacro = M_GetMacroN(AI_M_p_stGetListOfMacroAIModel(AI_M_p_stGetAIModel(p_stLoadedMind)), atoi(LDT_szGetParam(1)));
fn_vAllocNodeMacro(p_stMacro, ScriptCounter.uwNbNode);
p_stLoadedNode = M_GetNodeInterpret(M_GetMacroInitTree(p_stMacro));
iLen=LDT_ComputeSectionName(pLink,szForScript);
SCR_M_v_Link_SetAdditionalLong(SCR_fnp_st_Link_SetValue(&g_stMacroLinkTable, szForScript, (unsigned long)p_stMacro), 1, iLen );
while( result!=ParseResult_EndSection )
{
result=LDT_GetNextEntry();
switch( result )
{
case ParseResult_Entry: /* an entry */
{
char szAction[MAX_PATH];
unsigned char ucDepth=0;
strcpy( szAction, LDT_szGetEntryName() );
if(LDT_iGetNbParams()>=2)
ucDepth=(unsigned char) atol(LDT_szGetParam(2));
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,
NULL,
p_stLoadedNode+StructCounter.uwNbNode,
ucDepth);
StructCounter.uwNbNode++;
}
else
{
sprintf(szErrorString,"Number of nodes in this macro should be (%d)\n", ScriptCounter.uwNbNode);
M_AIFatalErrorMsg(E_uwAIFatalBadNodeNumber,szErrorString);
}
}
break;
case ParseResult_EndSection:
#ifdef __DEBUG_AI__
strcpy ( M_GetNameMacro(p_stMacro), szForScript + iLen ) ;
#endif
/* add a dummy node at the end of the tree*/
fn_vInitNodeInterpret(p_stLoadedNode+StructCounter.uwNbNode, 0, E_ti_EndTree, 0);
StructCounter.uwNbNode++;
if (ScriptCounter.uwNbNode!=StructCounter.uwNbNode)
{
sprintf(szErrorString,"Number of nodes in this macro should be (%d)\n", ScriptCounter.uwNbNode);
M_AIFatalErrorMsg(E_uwAIFatalBadNodeNumber,szErrorString);
}
ucInRuleSection=FALSE;
}
}
return 0;
}
/*****************************************************************
Name:
Description: Load callback for LDT
Author: Florin Scantee
Date: 8/12/98
Modified: Mircea Petrescu 98/10/02 - fixed values transfer
*****************************************************************/
int fn_iLoadListMacros( LDT_tdst_Link *pLink )
{
VIG_fn_vAddToProgressBar(1);
fn_vAllocListOfMacro(p_stLoadedMind, (unsigned char)atoi( LDT_szGetParam( 1 ) ));
return 0;
}
/*****************************************************************
Name:
Description: Create callback for LDT
Author: Mircea Petrescu
Date: 9/14/98
Modified: Mircea Petrescu 98/10/02 - fixed values transfer
*****************************************************************/
int fn_iCreateInitVariables( LDT_tdst_Link *pLink )
{
LDT_SetLinkValue( pLink, (unsigned long)(LDT_GetLinkValue( pLink->pParent)) );
return 0;
}
/*****************************************************************
Name:
Description: Load callback for LDT
Author: Mircea Petrescu
Date: 9/14/98
Modified: Mircea Petrescu 98/10/02 - fixed values transfer
*****************************************************************/
int fn_iLoadDelayed( LDT_tdst_Link *pLink )
{
char temp[18888], *values;
LDT_tdeParseResult result=ParseResult_BeginSection;
int iLen=0, iCnt=0, i;
short sNbP, sNbE=0;
char *pNbE, *szTemp;
*(void **)temp=(void *)LDT_GetLinkValue( pLink );
iLen+=sizeof(void *);
pNbE=temp+iLen; /* put here the number of entries (including begin section)*/
iLen+=sizeof(short);
sNbP=LDT_iGetNbParams(); /* place number of parameters*/
*(short *)(temp+iLen)=sNbP;
iLen+=sizeof(short);
for( i=1; i<sNbP; i++ )
{
szTemp=LDT_szGetParam( i );
strcpy( temp+iLen, szTemp );
iLen+=strlen( szTemp )+1;
}
while( result!=ParseResult_EndSection )
{
result=LDT_GetNextEntry();
switch( result )
{
case ParseResult_Entry: /* an entry */
{
sNbP=LDT_iGetNbParams(); /* place number of parameters*/
*(short *)(temp+iLen)=sNbP;
iLen+=sizeof(short);
for( i=0; i<sNbP; i++ )
{
szTemp=LDT_szGetParam( i );
strcpy( temp+iLen, szTemp );
iLen+=strlen( szTemp )+1;
}
sNbE++;
}
break;
case ParseResult_BeginSection: /* a subsection */
LDT_LoadSection( NULL );
}
}
*(short *)pNbE=sNbE;
values=(char *)LDT_M_malloc( iLen );
memcpy( values, temp, iLen );
LDT_SetLinkValue( pLink, (unsigned long)values );
return 0;
}
/*****************************************************************
Name:
Description: Create callback for LDT
Author: Mircea Petrescu
Date: 10/5/98
Modified:
*****************************************************************/
int fn_iCreateVariables( LDT_tdst_Link *pLink )
{
LDT_SetLinkValue( pLink, (long)pLink->pParent->pObject );
return 0;
}
/*****************************************************************
Name: AI_iLoadVariables
Description: Load callback for LDT
Author: Florin Scantee
Date: 8/7/98
Modified: Mircea Petrescu 98/10/02 - fixed values transfer
*****************************************************************/
int fn_iLoadVariables( LDT_tdst_Link *pLink )
{
int retVal=fn_iLoadDelayed( pLink );
char *szForScript=(char *)LDT_M_malloc( 256 );
int lLen=LDT_ComputeSectionName( pLink, szForScript );
LDT_AddToRefsTable( g_hRefBrain, pLink, iEndCreateVariables, 2, (long)lLen, (long)szForScript );
return retVal;
}
int fn_iLoadInitVariables( LDT_tdst_Link *pLink )
{
int retVal=fn_iLoadDelayed( pLink );
LDT_AddToRefsTable( g_hRefBrain, pLink, iEndInitVariables, 0 );
return retVal;
}
void PostProcessCreateVariables( LDT_tdst_Link *pLink, long *pVal )
{
#if defined(__DEBUG_AI__)
char szErrorString[200];
#endif
char *szParams[100], *values, *pCrt, *szAction, *szForScriptAll=(char *)pVal[1];
short sNbE, sNbP, i;
int lLen=(int)pVal[0];
pCrt=values=(char *)LDT_GetLinkValue( pLink );\
AI_tdstMind *p_stLoadedMind=*(AI_tdstMind **)pCrt;
tdstEngineObject *p_stLoadedEngineObject=(tdstEngineObject *)LDT_GetLinkValue(pLink->pParent);
pCrt+=sizeof( void * );
sNbE=*(short *)pCrt;
pCrt+=sizeof( short );
sNbP=*(short *)pCrt;
pCrt+=sizeof( short );
for( i=1; i<sNbP; i++ )
{
szParams[i-1]=pCrt;
pCrt+=strlen( pCrt )+1;
}
szParams[i-1]=NULL;
fn_vAllocVariableDesigner(p_stLoadedMind,(unsigned long) atoi(szParams[0]),(unsigned char) atoi(szParams[1]));
ulBeginOffset=0;
ulEndOffset=(unsigned long) atoi(szParams[0]);
for( ;sNbE; sNbE-- )
{
unsigned char ucVarId;
sNbP=*(short *)pCrt;
pCrt+=sizeof( short );
szAction=pCrt;
pCrt+=strlen( pCrt )+1;
for( i=1; i<sNbP; i++ )
{
szParams[i-1]=pCrt;
pCrt+=strlen( pCrt )+1;
}
szParams[i-1]=NULL;
ucVarId= (unsigned char) atoi(szParams[0]);
if (M_IsTypeSaveVariable(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_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))
{
/* it's an array*/
if (fn_GetDsgVarType(M_GetDsgVarType(p_stLoadedMind,ucVarId))==E_vt_Array)
{
/* of the good type*/
tdstArray *p_stArray=(tdstArray*) M_GetDsgVarAddrDefault(p_stLoadedMind,ucVarId);
if (eDsgVarTypeId==M_ARRAY_TYPE(p_stArray))
{
/* good index*/
if (ucIndex<M_ARRAY_SIZE(p_stArray))
{
char *p_MyVarAddr=(char*) M_ARRAY_ELEMENT(p_stArray,ucIndex);
fn_vInitDsgVarValue(p_MyVarAddr,eDsgVarTypeId,szParams);
}
#if defined(__DEBUG_AI__)
else /* element out of bounds*/
{
sprintf(szErrorString,"Can't define element %d in %s .DEC (cf variable number %d,%s)\n",ucIndex,AI_M_szGetPersoName(p_stLoadedMind),ucVarId,szName);
M_AIFatalErrorMsg(E_uwAIFatalScriptError,szErrorString);
}
#endif
}
#if defined(__DEBUG_AI__)
else /* bad type of element for array*/
{
sprintf(szErrorString,"Bad type between an array and element %d in %s .DEC (cf variable number %d,%s)\n",ucIndex,AI_M_szGetPersoName(p_stLoadedMind),ucVarId,szName);
M_AIFatalErrorMsg(E_uwAIFatalScriptError,szErrorString);
}
#endif
}
#if defined(__DEBUG_AI__)
else /* not an array*/
{
sprintf(szErrorString,"Not an array in %s .DEC (cf variable number %d,%s)\n",AI_M_szGetPersoName(p_stLoadedMind),ucVarId,szName);
M_AIFatalErrorMsg(E_uwAIFatalScriptError,szErrorString);
}
#endif
}
#if defined(__DEBUG_AI__)
else /* out of bounds ucVarId*/
{
sprintf(szErrorString,"Too many variables defined in %s .DEC (cf variable number %d,%s)\n",AI_M_szGetPersoName(p_stLoadedMind),ucVarId,szName);
M_AIFatalErrorMsg(E_uwAIFatalScriptError,szErrorString);
}
#endif
}
#if defined(__DEBUG_AI__)
else /* unknown variable*/
{
sprintf(szErrorString,"Unknown variable used in %s .DEC (cf variable number %d,%s)\n",AI_M_szGetPersoName(p_stLoadedMind),ucVarId,szName);
M_AIFatalErrorMsg(E_uwAIFatalScriptError,szErrorString);
}
#endif
}
else /* insert DsgVar Name in link table and initialize it*/
{
tdeDsgVarTypeId eDsgVarTypeId=fn_eFindDsgVarTypeIdFromScriptName(szAction);
if (!M_IsDsgVarTypeIdValid(eDsgVarTypeId))
{
M_AIFatalError(E_uwAIFatalWrongTypeVar);
}
#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
/* 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));*/
strcpy( szForScript, szForScriptAll );
/* add :DsgVarName*/
strcat(szForScript,SCR_CC_sz_Cfg_SectionIdMark);
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_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_Text:
case eDsgVarType_TextArray:
{
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;
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*/
}
}
}
#if defined(__DEBUG_AI__)
if /*(ulEndOffset != ulBeginOffset)*/ (ulBeginOffset>ulEndOffset)
{
sprintf(szErrorString,"Allocated buffer for DsgMem corrupted in %s .DEC\n",AI_M_szGetPersoName(p_stLoadedMind));
M_AIFatalErrorMsg(E_uwAIFatalScriptError,szErrorString);
}
#endif
LDT_M_free( values );
}
void PostProcessInitVariables( LDT_tdst_Link* pLink )
{
char *szParams[100], *values, *pCrt, *szAction;
short sNbE, sNbP, i;
pCrt=values=(char *)LDT_GetLinkValue( pLink );
/*p_stLoadedMind=*(AI_tdstMind **)pCrt;*/
pCrt+=sizeof( void * );
sNbE=*(short *)pCrt;
pCrt+=sizeof( short );
sNbP=*(short *)pCrt;
pCrt+=sizeof( short );
for( i=1; i<sNbP; i++ )
{
szParams[i-1]=pCrt;
pCrt+=strlen( pCrt )+1;
}
szParams[i-1]=NULL;
/* 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));
}
for( ; sNbE; sNbE-- )
{
sNbP=*(short *)pCrt;
pCrt+=sizeof( short );
szAction=pCrt;
pCrt+=strlen( pCrt )+1;
for( i=1; i<sNbP; i++ )
{
szParams[i-1]=pCrt;
pCrt+=strlen( pCrt )+1;
}
szParams[i-1]=NULL;
/* 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 (ucVarId<M_GetNbDsgVar(p_stLoadedMind))
{
/* for array*/
if (cElement)
{
unsigned char ucIndex=(unsigned char) atoi(szParams[0]);
if (fn_GetDsgVarType(M_GetDsgVarType(p_stLoadedMind,ucVarId))==E_vt_Array)
{
/* of the good type*/
tdstArray *p_stArray=(tdstArray*) M_GetDsgVarAddrInit(p_stLoadedMind,ucVarId);
if (eDsgVarTypeId==M_ARRAY_TYPE(p_stArray))
{
/* good index*/
if (ucIndex<M_ARRAY_SIZE(p_stArray))
{
char *p_MyVarAddr=(char*) M_ARRAY_ELEMENT(p_stArray,ucIndex);
fn_vInitDsgVarValue(p_MyVarAddr,eDsgVarTypeId,szParams);
}
#if defined(__DEBUG_AI__)
else /* element out of bounds*/
{
sprintf(szForErrorStringAt1stPass,"Can't define element %d in %s .DEC (cf variable number %d,%s)\n",ucIndex,AI_M_szGetPersoName(p_stLoadedMind),ucVarId,szName);
#if defined(ACTIVE_1STPASS_CHECKING) || defined(__DEBUG_AI__)
M_TestNodeInterpret(p_stLoadedMind,0,szForErrorStringAt1stPass,szName,WrongTypeVar);
#else
M_AIFatalErrorMsg(E_uwAIFatalScriptError,szForErrorStringAt1stPass);
#endif
}
#endif
}
#if defined(__DEBUG_AI__)
else /* bad type of element for array*/
{
sprintf(szForErrorStringAt1stPass,"Bad type between an array and element %d in %s .DEC (cf variable number %d,%s)\n",ucIndex,AI_M_szGetPersoName(p_stLoadedMind),ucVarId,szName);
#if defined(ACTIVE_1STPASS_CHECKING) || defined(__DEBUG_AI__)
M_TestNodeInterpret(p_stLoadedMind,0,szForErrorStringAt1stPass,szName,WrongTypeVar);
#else
M_AIFatalErrorMsg(E_uwAIFatalScriptError,szForErrorStringAt1stPass);
#endif
}
#endif
}
#if defined(__DEBUG_AI__)
else /* not an array*/
{
sprintf(szForErrorStringAt1stPass,"Not an array in %s .CAR (cf variable number %d,%s)\n",AI_M_szGetPersoName(p_stLoadedMind),ucVarId,szName);
#if defined(ACTIVE_1STPASS_CHECKING) || defined(__DEBUG_AI__)
M_TestNodeInterpret(p_stLoadedMind,0,szForErrorStringAt1stPass,szName,WrongTypeVar);
#else
M_AIFatalErrorMsg(E_uwAIFatalScriptError,szForErrorStringAt1stPass);
#endif
}
#endif
}
else
{
if (eDsgVarTypeId==M_GetDsgVarType(p_stLoadedMind,ucVarId))
{
/* CAUTION : fn_vInitDsgVarInit and not fn_vInitDsgVarDefault nor fn_vInitDsgVar*/
fn_vInitDsgVarInit(p_stLoadedMind,ucVarId,eDsgVarTypeId,szParams);
#if defined(__DEBUG_AI__)
/* warning if variable remapped*/
if (ucVarId!=atoi(szParams[0]))
{
#if defined(ACTIVE_1STPASS_CHECKING)
if(cErrorInInitVariablesDetected == 0)
{
sprintf(szForErrorStringAt1stPass,"Difference in Dsgvar between .CAR and .DEC [DsgVar (%s) No %s remapped to No %d] in %s",szParams[1],szParams[0],ucVarId,AI_M_szGetPersoName(p_stLoadedMind));
M_AIWarningErrorAndAllowStopForDebug(E_uwAIWarningScriptError,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass);
cErrorInInitVariablesDetected = 1;
}
AI_M_ucErrorFlag(p_stLoadedMind)=1;
fn_vForceEditor();
#else
sprintf(szForErrorStringAt1stPass,"Difference in Dsgvar between .CAR and .DEC [DsgVar (%s) No %s remapped to No %d] in %s",szParams[1],szParams[0],ucVarId,AI_M_szGetPersoName(p_stLoadedMind));
M_AIWarningErrorAndAllowStopForDebug(E_uwAIWarningScriptError,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass);
#endif /* ACTIVE_1STPASS_CHECKING*/
}
#endif /* __DEBUG_AI__*/
}
else
{
/* error : invalid type between .dec and .car*/
#if defined(ACTIVE_1STPASS_CHECKING) || defined(__DEBUG_AI__)
M_TestNodeInterpret(p_stLoadedMind,0,"Difference in Dsgvar between .CAR and .DEC [name is ok, type is bad] ",szParams[1],WrongTypeVar);
#else
M_AIFatalErrorMsg(E_uwAIFatalWrongTypeVar,"Difference in Dsgvar between .CAR and .DEC [name is ok, type is bad]");
#endif /* ACTIVE_1STPASS_CHECKING || __DEBUG_AI__*/
}
}
}
else
{
/* warning unknown variable id*/
#if defined(__DEBUG_AI__)
#if defined(ACTIVE_1STPASS_CHECKING)
if(cErrorInInitVariablesDetected == 0)
{
sprintf(szForErrorStringAt1stPass,"Difference in Dsgvar between .CAR and .DEC [Unknown DsgVar Id (%s) so dsgvar %s ignored] in %s",szParams[0],szParams[1],AI_M_szGetPersoName(p_stLoadedMind));
M_AIWarningErrorAndNeverStopForDebug(E_uwAIWarningScriptError,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass);
cErrorInInitVariablesDetected = 1;
}
AI_M_ucErrorFlag(p_stLoadedMind)=1;
fn_vForceEditor();
#else
sprintf(szForErrorStringAt1stPass,"Difference in Dsgvar between .CAR and .DEC [Unknown DsgVar Id (%s) so dsgvar %s ignored] in %s",szParams[0],szParams[1],AI_M_szGetPersoName(p_stLoadedMind));
M_AIWarningErrorAndAllowStopForDebug(E_uwAIWarningScriptError,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass);
#endif /* ACTIVE_1STPASS_CHECKING*/
#endif /* __DEBUG_AI__*/
}
}
else
{
/* warning unknown variable name*/
#if defined(__DEBUG_AI__)
#if defined(ACTIVE_1STPASS_CHECKING)
if(cErrorInInitVariablesDetected == 0)
{
sprintf(szForErrorStringAt1stPass,"Difference in Dsgvar between .CAR and .DEC [Unknown DsgVar name (%s) No %s ignored] in %s",szParams[1],szParams[0],AI_M_szGetPersoName(p_stLoadedMind));
M_AIWarningErrorAndNeverStopForDebug(E_uwAIWarningScriptError,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass);
cErrorInInitVariablesDetected = 1;
}
AI_M_ucErrorFlag(p_stLoadedMind)=1;
fn_vForceEditor();
#else
sprintf(szForErrorStringAt1stPass,"Difference in Dsgvar between .CAR and .DEC [Unknown DsgVar name (%s) No %s ignored] in %s",szParams[1],szParams[0],AI_M_szGetPersoName(p_stLoadedMind));
M_AIWarningErrorAndAllowStopForDebug(E_uwAIWarningScriptError,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass);
#endif /* ACTIVE_1STPASS_CHECKING*/
#else
char szForErrorStringAt1stPass[200];
sprintf(szForErrorStringAt1stPass,"Difference in Dsgvar between .CAR and .DEC [Unknown DsgVar name (%s) No %s ignored] in %s",szParams[1],szParams[0],AI_M_szGetPersoName(p_stLoadedMind));
M_AIWarningErrorAndNeverStopForDebug(E_uwAIWarningScriptError,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass);
#endif /* __DEBUG_AI__*/
}
}
else
{
/* error unknown variable type*/
#if defined(ACTIVE_1STPASS_CHECKING) || defined(__DEBUG_AI__)
if(cErrorInInitVariablesDetected == 0)
{
cErrorInInitVariablesDetected = 1;
M_TestNodeInterpret(p_stLoadedMind,0,"Unknown variable type",szParams[0],WrongTypeVar);
}
#if defined(ACTIVE_1STPASS_CHECKING)
AI_M_ucErrorFlag(p_stLoadedMind)=1;
#endif
#else
M_AIFatalErrorMsg(E_uwAIFatalWrongTypeVar,"Unknown variable type");
#endif /* ACTIVE_1STPASS_CHECKING || __DEBUG_AI__*/
}
}
}
#if defined(ACTIVE_1STPASS_CHECKING)
if (AI_M_ucErrorFlag(p_stLoadedMind) == 2)
#endif
{
/* should not happen now because .CAR contains only necessary init data*/
#if defined(ACTIVE_EDITOR)
/* because : if M_GetDsgMemBufferInit content == M_GetDsgMemDefaultInit content then free M_GetDsgMemBufferInit*/
if (!memcmp(M_GetDsgMemBufferInit(p_stLoadedMind),M_GetDsgMemDefaultInit(p_stLoadedMind),M_GetDsgVarSize(p_stLoadedMind)))
{
fn_vFreeDsgMemBuffer(&(M_GetDsgMemBufferInit(p_stLoadedMind)));
}
#endif
}
LDT_M_free( values );
}
extern "C" void AI_PostProcessLDT( HREF hRef );
void AI_PostProcessLDT( HREF hRef )
{
tdstScriptAI **p_p_stScriptAI=NULL;
LDT_tdst_Link *pLink;
LDT_tdst_Link *pGetFrom;
int iType;
short xCount;
long *pVal;
while( LDT_GetRefFromTable( hRef, &pLink, &pGetFrom, &iType, &xCount, &pVal )==0 )
{
switch( iType )
{
case iEndIntellModel:
{
p_stLoadedAIModel=(AI_tdstAIModel *)pLink->pObject;
p_stLoadedEngineObject=(tdstEngineObject *)LDT_GetLinkValue( pLink );
p_stLoadedMind=M_pstGetMindOfBrain((MS_tdxHandleToBrain)p_stLoadedEngineObject->h_Brain);
p_stLoadedScriptAI=(tdstScriptAI *)pGetFrom->pObject;
AI_M_p_stGetIntelligenceScriptAIModel(p_stLoadedAIModel)=p_stLoadedScriptAI;
#if defined(__DEBUG_AI__) || defined(ACTIVE_1STPASS_CHECKING)
fn_vCheckScriptAI(p_stLoadedMind,p_stLoadedScriptAI);
#endif
}
break;
case iEndReflexModel:
{
p_stLoadedAIModel=(AI_tdstAIModel *)pLink->pObject;
p_stLoadedEngineObject=(tdstEngineObject *)LDT_GetLinkValue( pLink );
p_stLoadedMind=M_pstGetMindOfBrain((MS_tdxHandleToBrain)p_stLoadedEngineObject->h_Brain);
p_stLoadedScriptAI=(tdstScriptAI *)pGetFrom->pObject;
AI_M_p_stGetReflexScriptAIModel(p_stLoadedAIModel)=p_stLoadedScriptAI;
#if defined(__DEBUG_AI__) || defined(ACTIVE_1STPASS_CHECKING)
fn_vCheckScriptAI(p_stLoadedMind,p_stLoadedScriptAI);
#endif
}
break;
case iEndCreateVariables:
PostProcessCreateVariables( pLink, pVal );
LDT_FreeRefValues( pVal );
break;
case iEndAIModel:
{
AI_tdstAIModel *p_stLoadedAIModel=(AI_tdstAIModel *)pGetFrom->pObject;
tdstEngineObject *p_stLoadedEngineObject=(tdstEngineObject *)pLink->pParent->pObject;
AI_tdstMind *p_stLoadedMind=M_pstGetMindOfBrain((MS_tdxHandleToBrain)p_stLoadedEngineObject->h_Brain);
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)
)
);
}
AI_M_SetAIModel(p_stLoadedMind,p_stLoadedAIModel);
/* il faut allouer DsgMem si il y a des variables designer*/
if ( AI_M_p_stGetDsgVar(p_stLoadedMind)!=NULL)
{
if (M_GetDsgVarSize(p_stLoadedMind)!=0)
{
AI_M_p_stGetDsgMem(p_stLoadedMind)=fn_p_stAllocDsgMem(&AI_M_p_stGetDsgVar(p_stLoadedMind),M_GetDsgVarSize(p_stLoadedMind) );
}
}
}
break;
case iEndInitVariables:
{
p_stLoadedEngineObject = (struct tdstEngineObject_ *)pLink->pParent->pParent->pObject;
p_stLoadedMind=M_pstGetMindOfBrain((MS_tdxHandleToBrain)p_stLoadedEngineObject->h_Brain);
PostProcessInitVariables( pLink );
}
break;
case iEndComportIntell:
{
p_stLoadedMind=M_pstGetMindOfBrain((MS_tdxHandleToBrain)pLink->pParent->pObject);
tdstIntelligence *p_stIntelligence;
unsigned long ulNoComportInit = (unsigned long )(*pVal);
p_stIntelligence=AI_M_p_stGetIntelligence(p_stLoadedMind);
if(p_stIntelligence)
M_GetNoComportInit(p_stIntelligence) = ulNoComportInit;
#if defined(__DEBUG_AI__)
else
{
#if defined(ACTIVE_1STPASS_CHECKING)
if(cErrorInInitComportReflex == 0)
{
cErrorInInitComportReflex = 1;
sprintf(szForErrorStringAt1stPass,"There is an initial Reflex in .CAR but no reflex in model in %s",AI_M_szGetPersoName(p_stLoadedMind));
M_AIWarningErrorAndNeverStopForDebug(E_uwAIWarningScriptError,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass);
}
AI_M_ucErrorFlag(p_stLoadedMind)=1;
fn_vForceEditor();
#else
sprintf(szForErrorStringAt1stPass,"There is an initial Reflex in .CAR but no reflex in model in %s",AI_M_szGetPersoName(p_stLoadedMind));
M_AIWarningErrorAndAllowStopForDebug(E_uwAIWarningScriptError,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass);
#endif /* ACTIVE_1STPASS_CHECKING*/
}
#endif
LDT_FreeRefValues(pVal);
}
break;
case iEndComportReflex:
{
p_stLoadedMind=M_pstGetMindOfBrain((MS_tdxHandleToBrain)pLink->pParent->pObject);
tdstIntelligence *p_stIntelligence;
unsigned long ulNoComportInit = (unsigned long )(*pVal);
p_stIntelligence=AI_M_p_stGetReflex(p_stLoadedMind);
if(p_stIntelligence)
M_GetNoComportInit(p_stIntelligence) = ulNoComportInit;
#if defined(__DEBUG_AI__)
else
{
#if defined(ACTIVE_1STPASS_CHECKING)
if(cErrorInInitComportReflex == 0)
{
cErrorInInitComportReflex = 1;
sprintf(szForErrorStringAt1stPass,"There is an initial Reflex in .CAR but no reflex in model in %s",AI_M_szGetPersoName(p_stLoadedMind));
M_AIWarningErrorAndNeverStopForDebug(E_uwAIWarningScriptError,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass);
}
AI_M_ucErrorFlag(p_stLoadedMind)=1;
fn_vForceEditor();
#else
sprintf(szForErrorStringAt1stPass,"There is an initial Reflex in .CAR but no reflex in model in %s",AI_M_szGetPersoName(p_stLoadedMind));
M_AIWarningErrorAndAllowStopForDebug(E_uwAIWarningScriptError,C_ucErmOpenInfoWindow,szForErrorStringAt1stPass);
#endif /* ACTIVE_1STPASS_CHECKING*/
}
#endif
LDT_FreeRefValues(pVal);
}
break;
}
}
}
/*****************************************************************
Name:
Description: Load callback for LDT
Author: Mircea Petrescu
Date: 9/14/98
Modified: Ovidiu Scripa
*****************************************************************/
int fn_iLoadComportReflex( LDT_tdst_Link *pLink )
{
LDT_tdeParseResult result=ParseResult_BeginSection;
char szForScript[_MAX_PATH], sz1[_MAX_PATH], sz2[_MAX_PATH], sz3[_MAX_PATH];
unsigned long ulNoComportInit;
/*p_stLoadedMind=M_pstGetMindOfBrain((MS_tdxHandleToBrain)pLink->pParent->pObject);*/
strcpy(szForScript,fn_szGetFamiliesDataPath());
strcat(szForScript,"\\");
if( LDT_iGetNbParams()==4 )
{
SCR_tdst_Link_Value *p_stLinkValue;
strcpy( sz1, LDT_szGetParam(1) );
strcpy( sz2, LDT_szGetParam(2) );
strcpy( sz3, LDT_szGetParam(3) );
SCR_fn_v_RdL0_ComputeSectionName( szForScript+strlen(szForScript), sz1, sz2, sz3);
p_stLinkValue = SCR_fnp_st_Link_CreateOrGetLinkFromKey(&g_stComportLinkTable, szForScript);
SCR_M_v_Link_SetAdditionalLong(p_stLinkValue, 4, 0);
ulNoComportInit = (unsigned long)p_stLinkValue;
}
else
{
char szFileName[_MAX_PATH];
SCR_tdst_Link_Value *p_stLinkValue;
fn_v_File_ComputeFileSectionName(LDT_szGetParam(1),szFileName,szForScript+strlen(szForScript));
p_stLinkValue = SCR_fnp_st_Link_CreateOrGetLinkFromKey(&g_stComportLinkTable, szForScript);
SCR_M_v_Link_SetAdditionalLong(p_stLinkValue, 4, 0);
ulNoComportInit = (unsigned long) p_stLinkValue;
}
LDT_AddToRefsTable( g_hRefBrain, pLink, iEndComportReflex, 1, ulNoComportInit );
while( result!=ParseResult_EndSection )
{
result=LDT_GetNextEntry();
}
return 0;
}
/*****************************************************************
Name:
Description: Load callback for LDT
Author: Mircea Petrescu
Date: 9/14/98
Modified: Ovidiu Scripa
*****************************************************************/
int fn_iLoadComportIntell( LDT_tdst_Link *pLink )
{
LDT_tdeParseResult result=ParseResult_BeginSection;
char szForScript[_MAX_PATH], sz1[_MAX_PATH], sz2[_MAX_PATH], sz3[_MAX_PATH];
unsigned long ulNoComportInit;
/*p_stLoadedMind=M_pstGetMindOfBrain((MS_tdxHandleToBrain)pLink->pParent->pObject);*/
strcpy(szForScript,fn_szGetFamiliesDataPath());
strcat(szForScript,"\\");
if( LDT_iGetNbParams()==4 )
{
SCR_tdst_Link_Value *p_stLinkValue;
strcpy( sz1, LDT_szGetParam(1) );
strcpy( sz2, LDT_szGetParam(2) );
strcpy( sz3, LDT_szGetParam(3) );
SCR_fn_v_RdL0_ComputeSectionName( szForScript+strlen(szForScript), sz1, sz2, sz3);
p_stLinkValue = SCR_fnp_st_Link_CreateOrGetLinkFromKey(&g_stComportLinkTable, szForScript);
SCR_M_v_Link_SetAdditionalLong(p_stLinkValue, 4, 0);
ulNoComportInit = (unsigned long)p_stLinkValue;
}
else
{
char szFileName[_MAX_PATH];
SCR_tdst_Link_Value *p_stLinkValue;
fn_v_File_ComputeFileSectionName(LDT_szGetParam(1),szFileName,szForScript+strlen(szForScript));
p_stLinkValue = SCR_fnp_st_Link_CreateOrGetLinkFromKey(&g_stComportLinkTable, szForScript);
SCR_M_v_Link_SetAdditionalLong(p_stLinkValue, 4, 0);
ulNoComportInit = (unsigned long) p_stLinkValue;
}
LDT_AddToRefsTable( g_hRefBrain, pLink, iEndComportIntell, 1, ulNoComportInit );
while( result!=ParseResult_EndSection )
{
result=LDT_GetNextEntry();
}
return 0;
}