// EdIRLoad.cpp : implementation of the CEdIAFrame class // #include "stdafx.h" #include "Defines.hpp" //#ifdef D_ED_IR_ACTIVE #include "EdIRFrm.hpp" #include "EdIRStrg.hpp" #include "EdIRIRD.hpp" #include "EdIRBeEn.hpp" #include "EdIRGlob.hpp" #include "EdIRIAWd.hpp" #include "EDACModl.hpp" #include "ai_intf.hpp" #include "TFA.h" #include "incAI.h" #include "x:\cpa\main\inc\_EditID.h" #include "_Actors.hpp" #include "ITF.h" #include "GAM.h" #include "GMT.h" #include "DPT.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPA_EdIR_Frame load script /**********************************************************************************/ /* CHRISTOPHE QUICK SAVE MODIFICATIONS { */ #include "EdIRRes.h" class CQuickSave : public CDialog { public: CString msg; CQuickSave(int); virtual BOOL OnInitDialog() { CDialog::OnInitDialog(); CStatic *pstat = (CStatic *) GetDlgItem(IDC_STATIC); pstat->SetWindowText(msg); return TRUE; } afx_msg void OnYes() { EndDialog(IDYES); } afx_msg void OnNo() { EndDialog(IDNO); } afx_msg void OnNoAll() { EndDialog(IDNOALL); } afx_msg void OnDelete() { EndDialog(IDDELETE); } afx_msg void OnDeleteAll() { EndDialog(IDDELETEALL); } DECLARE_MESSAGE_MAP() }; BEGIN_MESSAGE_MAP(CQuickSave, CDialog) ON_COMMAND(IDYES,OnYes) ON_COMMAND(IDNO,OnNo) ON_COMMAND(IDNOALL,OnNoAll) ON_COMMAND(IDDELETE,OnDelete) ON_COMMAND(IDDELETEALL,OnDeleteAll) END_MESSAGE_MAP() BOOL QuickSaveDeleteAll = FALSE; BOOL QuickSaveNoAll = FALSE; CQuickSave::CQuickSave(int n) : CDialog(n) {} int QuickSaveDialog(CString text) { CQuickSave Dial(IDD_QUICKSAVE); Dial.msg = text; return Dial.DoModal(); } /**********************************************************************************/ void CPA_EdIR_Frame::m_fn_vLoadBrain(CPA_Actor *pclModel,CString csModelName) { //Loads Intelligence CString csFileName=csModelName+g_c_csIntelligenceFileExtension; CString csFileNameQS=csModelName+g_c_csIntelligenceFileExtensionQS; CString csSectionName=csFileName+'^'+g_c_csIntelligenceSectionName; CString csSectionNameQS=csFileNameQS+'^'+g_c_csIntelligenceSectionName; BOOL bQuickSaveFileExists=FALSE; BOOL bLoadQuickSaveFile=FALSE; BOOL bAsksQuestion=TRUE; BOOL bDeleteQuick = FALSE; SCR_tdst_Cxt_Values *p_stValues; char Path[255], File[255]; char *psz_Temp; CString csBaseMsg="Would you like to load QuickSave for "; char *psz_Famil = fn_szGetFamiliesDataPath(); SCR_M_RdL0_SetContextLong(1,0,(long)(((EdActors_EditorActorModel *)pclModel->m_fn_pclGetEditorActor())->m_pclBrain)); bQuickSaveFileExists=FALSE; bDeleteQuick=FALSE; if(QuickSaveNoAll == FALSE) bQuickSaveFileExists=SCR_fn_c_RdL0_IsSectionExists(M_MAKECHAR(csSectionNameQS)); if(bQuickSaveFileExists) { CString csMsg=csBaseMsg+csModelName+" model ?"; if((QuickSaveDeleteAll == FALSE)&&(bAsksQuestion)) { int iRes = QuickSaveDialog(csMsg); switch(iRes) { case IDYES: bLoadQuickSaveFile = TRUE; break; case IDNO: bLoadQuickSaveFile = FALSE; break; case IDNOALL: bLoadQuickSaveFile = FALSE; QuickSaveNoAll = TRUE; break; case IDDELETE: bLoadQuickSaveFile = FALSE; bDeleteQuick = TRUE; break; case IDDELETEALL: bLoadQuickSaveFile = FALSE; bDeleteQuick = TRUE; QuickSaveDeleteAll = TRUE; break; } } bAsksQuestion=FALSE; if(bDeleteQuick || QuickSaveDeleteAll) { strcpy(Path, psz_Famil); strcat(Path, "\\"); strcpy(File, (char *) (LPCSTR) csSectionNameQS); psz_Temp = strrchr(File, '^'); if(psz_Temp) { *psz_Temp = '\0'; strcat(Path, File); chmod(Path, _S_IWRITE); unlink(Path); } bLoadQuickSaveFile = FALSE; } else if (bLoadQuickSaveFile) { CPA_EdIR_Brain *pclBrain=((EdActors_EditorActorModel *)pclModel->m_fn_pclGetEditorActor())->m_pclBrain; pclBrain->m_fn_vSetModified(TRUE); pclBrain->m_fn_vNotify(); // for instances CPA_List clInstancesList; g_pclAIInterface->GetMainWorld()->fn_lFindObjects(&clInstancesList,"",C_szActorInstanceTypeName,pclModel); POSITION pos1=clInstancesList.GetHeadPosition(); while(pos1!=NULL) { CPA_Actor *pclInstance=(CPA_Actor *)(clInstancesList.GetNext(pos1)); tdstEngineObject *pstEngineObject=(tdstEngineObject *)pclInstance->GetStruct(); MS_tdxHandleToBrain hBrain=pstEngineObject->h_Brain; if(hBrain) AI_M_ucErrorFlag(M_pstGetMindOfBrain(hBrain))=1; } } } if(bLoadQuickSaveFile) p_stValues=SCR_fnp_st_RdL0_AnalyseSection(M_MAKECHAR(csSectionNameQS),SCR_CDF_uw_Anl_Normal); else p_stValues=SCR_fnp_st_RdL0_AnalyseSection(M_MAKECHAR(csSectionName),SCR_CDF_uw_Anl_Normal); //Loads Reflex csFileName=csModelName+g_c_csReflexFileExtension; csFileNameQS=csModelName+g_c_csReflexFileExtensionQS; csSectionName=csFileName+'^'+g_c_csReflexSectionName; csSectionNameQS=csFileNameQS+'^'+g_c_csReflexSectionName; SCR_M_RdL0_SetContextLong(1,0,(long)(((EdActors_EditorActorModel *)pclModel->m_fn_pclGetEditorActor())->m_pclBrain)); bQuickSaveFileExists=FALSE; if(QuickSaveNoAll == FALSE) bQuickSaveFileExists=SCR_fn_c_RdL0_IsSectionExists(M_MAKECHAR(csSectionNameQS)); if(bQuickSaveFileExists) { CString csMsg=csBaseMsg+csModelName+" model ?"; if((QuickSaveDeleteAll == FALSE)&&(bAsksQuestion)) { int iRes = QuickSaveDialog(csMsg); switch(iRes) { case IDYES: bLoadQuickSaveFile = TRUE; break; case IDNO: bLoadQuickSaveFile = FALSE; break; case IDNOALL: bLoadQuickSaveFile = FALSE; QuickSaveNoAll = TRUE; break; case IDDELETE: bLoadQuickSaveFile = FALSE; bDeleteQuick = TRUE; break; case IDDELETEALL: bLoadQuickSaveFile = FALSE; bDeleteQuick = TRUE; QuickSaveDeleteAll = TRUE; break; } } bAsksQuestion=FALSE; if(bDeleteQuick || QuickSaveDeleteAll) { strcpy(Path, psz_Famil); strcat(Path, "\\"); strcpy(File, (char *) (LPCSTR) csSectionNameQS); psz_Temp = strrchr(File, '^'); if(psz_Temp) { *psz_Temp = '\0'; strcat(Path, File); chmod(Path, _S_IWRITE); unlink(Path); } bLoadQuickSaveFile = FALSE; } } if(bLoadQuickSaveFile) p_stValues=SCR_fnp_st_RdL0_AnalyseSection(M_MAKECHAR(csSectionNameQS),SCR_CDF_uw_Anl_Normal); else p_stValues=SCR_fnp_st_RdL0_AnalyseSection(M_MAKECHAR(csSectionName),SCR_CDF_uw_Anl_Normal); //Loads Declaration csFileName=csModelName+g_c_csDeclarationFileExtension; csFileNameQS=csModelName+g_c_csDeclarationFileExtensionQS; csSectionName=csFileName+'^'+g_c_csDeclarationSectionName; csSectionNameQS=csFileNameQS+'^'+g_c_csDeclarationSectionName; SCR_M_RdL0_SetContextLong(1,0,(long)(((EdActors_EditorActorModel *)pclModel->m_fn_pclGetEditorActor())->m_pclBrain)); bQuickSaveFileExists=FALSE; if(QuickSaveNoAll == FALSE) bQuickSaveFileExists=SCR_fn_c_RdL0_IsSectionExists(M_MAKECHAR(csSectionNameQS)); if(bQuickSaveFileExists) { CString csMsg=csBaseMsg+csModelName+" model ?"; if((QuickSaveDeleteAll == FALSE)&&(bAsksQuestion)) { int iRes = QuickSaveDialog(csMsg); switch(iRes) { case IDYES: bLoadQuickSaveFile = TRUE; break; case IDNO: bLoadQuickSaveFile = FALSE; break; case IDNOALL: bLoadQuickSaveFile = FALSE; QuickSaveNoAll = TRUE; break; case IDDELETE: bLoadQuickSaveFile = FALSE; bDeleteQuick = TRUE; break; case IDDELETEALL: bLoadQuickSaveFile = FALSE; bDeleteQuick = TRUE; QuickSaveDeleteAll = TRUE; break; } } bAsksQuestion=FALSE; if(bDeleteQuick || QuickSaveDeleteAll) { strcpy(Path, psz_Famil); strcat(Path, "\\"); strcpy(File, (char *) (LPCSTR) csSectionNameQS); psz_Temp = strrchr(File, '^'); if(psz_Temp) { *psz_Temp = '\0'; strcat(Path, File); chmod(Path, _S_IWRITE); unlink(Path); } bLoadQuickSaveFile = FALSE; } } if(bLoadQuickSaveFile) p_stValues=SCR_fnp_st_RdL0_AnalyseSection(M_MAKECHAR(csSectionNameQS),SCR_CDF_uw_Anl_Normal); else p_stValues=SCR_fnp_st_RdL0_AnalyseSection(M_MAKECHAR(csSectionName),SCR_CDF_uw_Anl_Normal); //BEGIN ROMTEAM Cristi Petrescu 98-04- //Loads Macros csFileName=csModelName+g_c_csMacroFileExtension; csFileNameQS=csModelName+g_c_csMacroFileExtensionQS; csSectionName=csFileName+'^'+g_c_csMacroSectionName; csSectionNameQS=csFileNameQS+'^'+g_c_csMacroSectionName; SCR_M_RdL0_SetContextLong(1,0,(long)(((EdActors_EditorActorModel *)pclModel->m_fn_pclGetEditorActor())->m_pclBrain)); bQuickSaveFileExists=FALSE; if(QuickSaveNoAll == FALSE) bQuickSaveFileExists=SCR_fn_c_RdL0_IsSectionExists(M_MAKECHAR(csSectionNameQS)); if(bQuickSaveFileExists) { CString csMsg=csBaseMsg+csModelName+" model ?"; if((QuickSaveDeleteAll == FALSE)&&(bAsksQuestion)) { int iRes = QuickSaveDialog(csMsg); switch(iRes) { case IDYES: bLoadQuickSaveFile = TRUE; break; case IDNO: bLoadQuickSaveFile = FALSE; break; case IDNOALL: bLoadQuickSaveFile = FALSE; QuickSaveNoAll = TRUE; break; case IDDELETE: bLoadQuickSaveFile = FALSE; bDeleteQuick = TRUE; break; case IDDELETEALL: bLoadQuickSaveFile = FALSE; bDeleteQuick = TRUE; QuickSaveDeleteAll = TRUE; break; } } bAsksQuestion=FALSE; if(bDeleteQuick || QuickSaveDeleteAll) { strcpy(Path, psz_Famil); strcat(Path, "\\"); strcpy(File, (char *) (LPCSTR) csSectionNameQS); psz_Temp = strrchr(File, '^'); if(psz_Temp) { *psz_Temp = '\0'; strcat(Path, File); chmod(Path, _S_IWRITE); unlink(Path); } bLoadQuickSaveFile = FALSE; } } if(bLoadQuickSaveFile) { if (SCR_fn_c_RdL0_IsSectionExists(M_MAKECHAR(csSectionNameQS))) p_stValues=SCR_fnp_st_RdL0_AnalyseSection(M_MAKECHAR(csSectionNameQS),SCR_CDF_uw_Anl_Normal); } else { if (SCR_fn_c_RdL0_IsSectionExists(M_MAKECHAR(csSectionName))) p_stValues=SCR_fnp_st_RdL0_AnalyseSection(M_MAKECHAR(csSectionName),SCR_CDF_uw_Anl_Normal); } //Loads Subrs csFileName=csModelName+g_c_csSubrFileExtension; csFileNameQS=csModelName+g_c_csSubrFileExtensionQS; csSectionName=csFileName+'^'+g_c_csSubrSectionName; csSectionNameQS=csFileNameQS+'^'+g_c_csSubrSectionName; SCR_M_RdL0_SetContextLong(1,0,(long)(((EdActors_EditorActorModel *)pclModel->m_fn_pclGetEditorActor())->m_pclBrain)); bQuickSaveFileExists=FALSE; if(QuickSaveNoAll == FALSE) bQuickSaveFileExists=SCR_fn_c_RdL0_IsSectionExists(M_MAKECHAR(csSectionNameQS)); if(bQuickSaveFileExists) { CString csMsg=csBaseMsg+csModelName+" model ?"; if((QuickSaveDeleteAll == FALSE)&&(bAsksQuestion)) { int iRes = QuickSaveDialog(csMsg); switch(iRes) { case IDYES: bLoadQuickSaveFile = TRUE; break; case IDNO: bLoadQuickSaveFile = FALSE; break; case IDNOALL: bLoadQuickSaveFile = FALSE; QuickSaveNoAll = TRUE; break; case IDDELETE: bLoadQuickSaveFile = FALSE; bDeleteQuick = TRUE; break; case IDDELETEALL: bLoadQuickSaveFile = FALSE; bDeleteQuick = TRUE; QuickSaveDeleteAll = TRUE; break; } } bAsksQuestion=FALSE; if(bDeleteQuick || QuickSaveDeleteAll) { strcpy(Path, psz_Famil); strcat(Path, "\\"); strcpy(File, (char *) (LPCSTR) csSectionNameQS); psz_Temp = strrchr(File, '^'); if(psz_Temp) { *psz_Temp = '\0'; strcat(Path, File); chmod(Path, _S_IWRITE); unlink(Path); } bLoadQuickSaveFile = FALSE; } } if(bLoadQuickSaveFile) { if (SCR_fn_c_RdL0_IsSectionExists(M_MAKECHAR(csSectionNameQS))) p_stValues=SCR_fnp_st_RdL0_AnalyseSection(M_MAKECHAR(csSectionNameQS),SCR_CDF_uw_Anl_Normal); } else { if (SCR_fn_c_RdL0_IsSectionExists(M_MAKECHAR(csSectionName))) p_stValues=SCR_fnp_st_RdL0_AnalyseSection(M_MAKECHAR(csSectionName),SCR_CDF_uw_Anl_Normal); } //END ROMTEAM Cristi Petrescu 98-04- } /* } END CHRISTOPHE QUICK SAVE MODIFICATIONS */ /**********************************************************************************/ SCR_tde_Anl_ReturnValue CPA_EdIR_Frame::m_fn_tdeCallBackLoadIntelligence(SCR_tdst_File_Description *pfFile, char *szAction, char *szPars[], SCR_tde_Anl_Action eType) { if(eType==SCR_EA_Anl_BeginSection) { CPA_EdIR_Brain *p_clBrain; SCR_M_RdL0_GetContextLong(0,0,CPA_EdIR_Brain *,p_clBrain); SCR_M_RdL0_SetContextLong(1,0,long(&(p_clBrain->m_clListOfIntelligenceBehaviours))); SCR_M_RdL0_SetContextLong(1,1,long(p_clBrain->m_fn_pclGetModel())); } return SCR_ERV_Anl_NormalReturn; } /**********************************************************************************/ SCR_tde_Anl_ReturnValue CPA_EdIR_Frame::m_fn_tdeCallBackLoadReflex(SCR_tdst_File_Description *pfFile, char *szAction, char *szPars[], SCR_tde_Anl_Action eType) { if(eType==SCR_EA_Anl_BeginSection) { CPA_EdIR_Brain *p_clBrain; SCR_M_RdL0_GetContextLong(0,0,CPA_EdIR_Brain *,p_clBrain); SCR_M_RdL0_SetContextLong(1,0,long(&(p_clBrain->m_clListOfReflexBehaviours))); SCR_M_RdL0_SetContextLong(1,1,long(p_clBrain->m_fn_pclGetModel())); } return SCR_ERV_Anl_NormalReturn; } /**********************************************************************************/ SCR_tde_Anl_ReturnValue CPA_EdIR_Frame::m_fn_tdeCallBackLoadDeclaration(SCR_tdst_File_Description *pfFile, char *szAction, char *szPars[], SCR_tde_Anl_Action eType) { if(eType==SCR_EA_Anl_BeginSection) { CPA_EdIR_Brain *p_clBrain; SCR_M_RdL0_GetContextLong(0,0,CPA_EdIR_Brain *,p_clBrain); SCR_M_RdL0_SetContextLong(1,0,long(&(p_clBrain->m_clListOfDeclarations))); SCR_M_RdL0_SetContextLong(1,1,long(p_clBrain->m_fn_pclGetModel())); } return SCR_ERV_Anl_NormalReturn; } // BEGIN CPA2 Cristi Petrescu 98-03- /**********************************************************************************/ SCR_tde_Anl_ReturnValue CPA_EdIR_Frame::m_fn_tdeCallBackLoadMacro(SCR_tdst_File_Description *pfFile, char *szAction, char *szPars[], SCR_tde_Anl_Action eType) { if(eType==SCR_EA_Anl_BeginSection) { CPA_EdIR_Brain *p_clBrain; SCR_M_RdL0_GetContextLong(0,0,CPA_EdIR_Brain *,p_clBrain); SCR_M_RdL0_SetContextLong(1,0,long(&(p_clBrain->m_clListOfMacros))); SCR_M_RdL0_SetContextLong(1,1,long(p_clBrain->m_fn_pclGetModel())); } return SCR_ERV_Anl_NormalReturn; } // END CPA2 Cristi Petrescu 98-03- // BEGIN ROMTEAM CPA2 Cristi Petrescu 98-04- /**********************************************************************************/ SCR_tde_Anl_ReturnValue CPA_EdIR_Frame::m_fn_tdeCallBackLoadSubr(SCR_tdst_File_Description *pfFile, char *szAction, char *szPars[], SCR_tde_Anl_Action eType) { if(eType==SCR_EA_Anl_BeginSection) { CPA_EdIR_Brain *p_clBrain; SCR_M_RdL0_GetContextLong(0,0,CPA_EdIR_Brain *,p_clBrain); SCR_M_RdL0_SetContextLong(1,0,long(&(p_clBrain->m_clListOfSubrs))); SCR_M_RdL0_SetContextLong(1,1,long(p_clBrain->m_fn_pclGetModel())); } return SCR_ERV_Anl_NormalReturn; } // END ROMTEAM CPA2 Cristi Petrescu 98-04- /**********************************************************************************/ SCR_tde_Anl_ReturnValue CPA_EdIR_Frame::m_fn_tdeCreateMainBehaviour(SCR_tdst_File_Description *pfFile, char *szAction, char *szPars[], SCR_tde_Anl_Action eType) { static CPA_EdIR_MainBehaviour *s_pclMainBehaviour; static CString s_csLanguage; if(eType==SCR_EA_Anl_BeginSection) { CPA_Actor *pclModel; SCR_M_RdL0_GetContextLong(0,1,CPA_Actor *,pclModel); s_pclMainBehaviour=new CPA_EdIR_MainBehaviour(pclModel); s_csLanguage="French"; } else if(eType==SCR_EA_Anl_Entry) { if(strcmpi(szAction,g_c_csBehaviourLanguage)==0) { s_csLanguage=szPars[0]; } else if(strcmpi(szAction,g_c_csBehaviourName)==0) { if(s_pclMainBehaviour->fn_eRename(CString(szPars[0]))!=E_mc_None) s_pclMainBehaviour->SetDefaultUniqueName(); } else if(strcmpi(szAction,g_c_csBehaviourBoundingBox)==0) { s_pclMainBehaviour->m_crPosition.left=atol(szPars[0]); s_pclMainBehaviour->m_crPosition.top=atol(szPars[1]); s_pclMainBehaviour->m_crPosition.right=atol(szPars[2]); s_pclMainBehaviour->m_crPosition.bottom=atol(szPars[3]); } else if(strcmpi(szAction,g_c_csBehaviourText)==0) { //Old file format if(SCR_fn_uc_RdL0_GetNumberOfParameters(szPars)==3) { CFile cfFile; CString csFileName; csFileName=fn_szGetFamiliesDataPath()+CString("\\")+ CString(szPars[0]); if(cfFile.Open(csFileName,CFile::modeRead)) { long lOffset=atol(szPars[1]); long lLen=atol(szPars[2]); char *p_cBuf=new char[lLen+1]; cfFile.Seek(lOffset,CFile::begin); cfFile.Read(p_cBuf,lLen); p_cBuf[lLen]=0; s_pclMainBehaviour->m_csText=p_cBuf; delete[] p_cBuf; cfFile.Close(); } } //New file format else { CString csLine=CString(szPars[0]); csLine=fn_csReplaceChar(csLine,'\'','\"'); s_pclMainBehaviour->m_csText+=csLine+"\xD\xA"; } } } else if(eType==SCR_EA_Anl_EndSection) { CPA_EdIR_MainBehaviourList *p_clMainBehaviourList; SCR_M_RdL0_GetContextLong(0,0,CPA_EdIR_MainBehaviourList *,p_clMainBehaviourList); //Deletes the last "\xD\xA" sequence if(s_pclMainBehaviour->m_csText.Right(2).CompareNoCase("\xD\xA")==0) s_pclMainBehaviour->m_csText=s_pclMainBehaviour->m_csText.Left(s_pclMainBehaviour->m_csText.GetLength()-2); //Translates text if needed CString csCurrentLanguage=g_pclAIInterface->M_GetMainWorld()->GetInterface()->fn_csGetCurrentLanguage(); if(s_csLanguage!=csCurrentLanguage) { //s_pclMainBehaviour->m_csText=fn_csTranslateText(s_pclMainBehaviour->m_csText,csCurrentLanguage); s_pclMainBehaviour->m_csText=fn_csFastTranslateText(s_pclMainBehaviour->m_csText,s_csLanguage,csCurrentLanguage); } p_clMainBehaviourList->AddTail(s_pclMainBehaviour); } return SCR_ERV_Anl_NormalReturn; } //#endif //D_ED_IR_ACTIVE