/*========================================================================= * Brain.cpp : Brain's functions * * * * Brain MUST BE REPLACE BY THE C FILENAME * * * Version 1.0 * Creation date 01/10/96 * Revision date * * That file needs to be compatible for all platforms. * * (c) Ubi Studios 1996 *=======================================================================*/ /*******************************************************/ /**** For the structures and variables declarations ****/ /*******************************************************/ #define D_Brain_StructureDefine #define D_Brain_VariableDefine #include "InitEnum.h" #include "ToolsCPA.h" #include "Options/Options.h" #include "Macros.h" #include "Actions/AllActs.h" #include "Structur/MemGame.h" #include "Structur/EngMode.h" #include "Structur/ErrGame.h" #include "Structur/Objects.h" #include "Structur/GameScpt.h" #include "Structur/StdObjSt.h" #include "Basic.h" #include "ObjInit.h" #include "ZeMem.h" #include "ObjType.h" #include "ToolCam.h" #include "LoadBin.h" /* For BIN*/ #ifdef GAM_USE_SNA #include "sna\snaglob.h" #endif /* GAM_USE_SNA */ /* XB 05/05/99 */ extern void fn_vFirstInitAI(AI_tdxHandleToMind p_stMind); /* End XB 05/05/99 */ extern ACP_tdxBool fn_bIsInFix(struct tdstEngineObject_ *p_stObject); /*----------------------------------------------------------------------------- * Description : Brain's object action script callback *----------------------------------------------------------------------------- * Input : Object pointer * Output : None *----------------------------------------------------------------------------- * Creation date : 01/10/96 Author : Francois *----------------------------------------------------------------------------- * Modification date : Modification Author : * Modifications : *---------------------------------------------------------------------------*/ #if defined(GAM_USE_SCRIPT) SCR_tde_Anl_ReturnValue fn_eBrainScriptCallBack(SCR_tdst_File_Description *_p_stFile,char *_p_szName,char *_ap_szParams[],SCR_tde_Anl_Action _eAction) { SCR_tde_Anl_ReturnValue eReturnValue = SCR_ERV_Anl_NormalReturn; MS_tdxHandleToBrain h_Brain; AI_tdstMind *p_stMind; struct tdstEngineObject_ *p_stEngineObject; _p_stFile=_p_stFile; SCR_M_RdL0_GetSectionLong(C_ParentSection,0,struct tdstEngineObject_ *, p_stEngineObject); if (M_IsTitle) { char szIntellFileName[_MAX_PATH]; char *szModelName; char *szFamilyName; MMG_fn_vBeginMemoryInfo (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeBrain , p_stEngineObject); h_Brain = fn_h_BrainRealAlloc(); MMG_fn_vEndMemoryInfo (); p_stEngineObject->h_Brain=h_Brain; SCR_M_RdL0_SetSectionLong(C_ThisSection,0,h_Brain); p_stMind = M_pstGetMindOfBrain(h_Brain); szModelName = fn_szFindModelTypeNameOfModelType(M_ObjectGetModelType(p_stEngineObject)); szFamilyName = fn_szFindFamilyTypeNameOfFamilyType(M_ObjectGetFamilyType(p_stEngineObject)); sprintf(szIntellFileName,"%s\\%s\\%s.ai",szFamilyName,szModelName,szModelName); fn_vReadAI(p_stMind, szIntellFileName,p_stEngineObject ); } else if (M_IsEntry) { SCR_M_RdL0_GetSectionLong(C_ThisSection,0,MS_tdxHandleToBrain,h_Brain); } else if (M_IsEnd) { SCR_M_RdL0_GetSectionLong(C_ThisSection,0,MS_tdxHandleToBrain,h_Brain); } return(eReturnValue); } #endif /* GAM_USE_SCRIPT */ /*----------------------------------------------------------------------------- * Description : Brain's mini-structure sizeof *----------------------------------------------------------------------------- * Input : None * Output : Size of *----------------------------------------------------------------------------- * Creation date : 14/10/96 Author : Francois *----------------------------------------------------------------------------- * Modification date : Modification Author : * Modifications : *---------------------------------------------------------------------------*/ unsigned long fn_ulBrainSizeOf() { return(sizeof(struct tdstBrain_)); } /*----------------------------------------------------------------------------- * Description : Brain's object action allocation *----------------------------------------------------------------------------- * Input : Object pointer * Output : None *----------------------------------------------------------------------------- * Creation date : 01/10/96 Author : Francois *----------------------------------------------------------------------------- * Modification date : Modification Author : * Modifications : *---------------------------------------------------------------------------*/ void fn_vBrainAlloc(struct tdstEngineObject_ *p_stObject) { if (p_stObject==NULL) M_GameFatalError(E_uwGameMiniStructObjectNull); if (p_stObject->h_Brain!=NULL) M_GameFatalError(E_uwGameMiniStructAllocAlreadyAlloc); MMG_fn_vBeginMemoryInfo (MMG_C_lTypeMiniStructure , MMG_C_lSubTypeBrain , p_stObject); p_stObject->h_Brain = fn_h_BrainRealAlloc(); MMG_fn_vEndMemoryInfo (); } MS_tdxHandleToBrain fn_h_BrainRealAlloc() { MS_tdxHandleToBrain h_Brain; h_Brain = (MS_tdxHandleToBrain)M_p_GameMallocInHLM(fn_ulBrainSizeOf()); fn_vFirstInitBrain(h_Brain); return(h_Brain); } /*----------------------------------------------------------------------------- * Description : Brain's object action free *----------------------------------------------------------------------------- * Input : Object pointer * Output : None *----------------------------------------------------------------------------- * Creation date : 01/10/96 Author : Francois *----------------------------------------------------------------------------- * Modification date : Modification Author : * Modifications : *---------------------------------------------------------------------------*/ void fn_vBrainFree(struct tdstEngineObject_ *p_stObject) { if (p_stObject==NULL) M_GameFatalError(E_uwGameMiniStructObjectNull); if (p_stObject->h_Brain==NULL) M_GameFatalError(E_uwGameMiniStructNull); MMG_fn_vAddMemoryInfo( MMG_C_lTypeMiniStructure , MMG_C_lSubTypeBrain , p_stObject ); M_GameFreeInHLM(p_stObject->h_Brain); } /*----------------------------------------------------------------------------- * Description : Brain's object action first initialisation *----------------------------------------------------------------------------- * Input : Brain structure * Output : None *----------------------------------------------------------------------------- * Creation date : 14/11/96 Author : Francois *----------------------------------------------------------------------------- * Modification date : Modification Author : * Modifications : *---------------------------------------------------------------------------*/ void fn_vFirstInitBrain(MS_tdxHandleToBrain h_Brain) { AI_tdstMind *p_stMind = fn_pstAllocMind(); M_SetMindOfBrain(h_Brain, p_stMind); M_vSetLastCollidedGoThroughMaterialOfBrain(h_Brain, GMT_C_ulInvalidHandle); M_vSetWarnMechanicsFlagOfBrain(h_Brain, 0); } /*----------------------------------------------------------------------------- * Description : Brain's object action initialisation *----------------------------------------------------------------------------- * Input : When this function's called (see ObjInit.h) * Output : None *----------------------------------------------------------------------------- * Creation date : 01/10/96 Author : Francois *----------------------------------------------------------------------------- * Modification date : Modification Author : * Modifications : *---------------------------------------------------------------------------*/ void fn_vBrainInit(struct tdstEngineObject_ *p_stObject,enum tdeObjectTreeInit_ eObjectInit) { if (p_stObject==NULL) M_GameFatalError(E_uwGameMiniStructObjectNull); if (p_stObject->h_Brain==NULL) M_GameFatalError(E_uwGameMiniStructNull); M_vSetLastCollidedGoThroughMaterialOfBrain(p_stObject->h_Brain, GMT_C_ulInvalidHandle); M_vSetWarnMechanicsFlagOfBrain(p_stObject->h_Brain, 0); switch(eObjectInit) { case OTI_AlwaysCreated: /* ANNECY MT - 18/09/98 {*/ break; /* END ANNECY MT }*/ case OTI_PlayerDead: case OTI_ReinitTheMap: case OTI_LoadSavedGame: fn_vReinitAIWithFlags(M_pstGetMindOfBrain(p_stObject->h_Brain),eObjectInit); break; case OTI_MapLoaded: case OTI_WhenGameStart: /* For BIN*/ if ( !fn_bIsAllSecondPassDone(p_stObject->h_StandardGame) #if !defined(U64) &&SNA_fn_ucGetLoadType()!=SNA_LOAD_SNAPSHOT &&SNA_fn_ucGetLoadType()!=4 #endif /* U64 */ ) { #if !defined(U64) fn_vSecondPassOfMindLoading(M_pstGetMindOfBrain(p_stObject->h_Brain),(ACP_tdxBool) fn_bIsInFix(p_stObject),eObjectInit); #else fn_vFirstInitAI(M_pstGetMindOfBrain(p_stObject->h_Brain)); fn_vAllSecondPassAreDone(p_stObject->h_StandardGame); #endif /* U64 */ } else fn_vReinitAI(M_pstGetMindOfBrain(p_stObject->h_Brain)); AI_fn_vInsertDsgVarInSAI(M_pstGetMindOfBrain(p_stObject->h_Brain)); break; } } /*----------------------------------------------------------------------------- * Description : Brain's object action desinitialisation *----------------------------------------------------------------------------- * Input : When this function's called (see ObjInit.h) * Output : None *----------------------------------------------------------------------------- * Creation date : 01/10/96 Author : Francois *----------------------------------------------------------------------------- * Modification date : Modification Author : * Modifications : *---------------------------------------------------------------------------*/ void fn_vBrainDesinit(struct tdstEngineObject_ *p_stObject,enum tdeObjectTreeInit_ eObjectInit) { if (p_stObject==NULL) M_GameFatalError(E_uwGameMiniStructObjectNull); if (p_stObject->h_Brain==NULL) M_GameFatalError(E_uwGameMiniStructNull); switch(eObjectInit) { case OTI_ReinitTheMap: break; case OTI_MapLoaded: break; case OTI_AlwaysCreated: case OTI_PlayerDead: break; default: break; } } /*----------------------------------------------------------------------------- * Description : Brain's object copy clone action *----------------------------------------------------------------------------- * Input : Handle to destination, handle to source * Output : None *----------------------------------------------------------------------------- * Creation date : 30/06/97 Author : Olivier Jourdan *----------------------------------------------------------------------------- * Modification date : 07/07/97 Modification Author : Olivier Jourdan * Modifications : *---------------------------------------------------------------------------*/ void fn_vBrainCopyClone(struct tdstEngineObject_ * _p_stObjectDest,struct tdstEngineObject_ * _p_stObjectSrc) { AI_tdxHandleToMind hMindSrc,hMindDest; hMindSrc = M_pstGetMindOfBrain(_p_stObjectSrc->h_Brain); hMindDest = M_pstGetMindOfBrain(_p_stObjectDest->h_Brain); fn_vSimulateMindAllocationFromAnotherMind( hMindSrc,hMindDest); }