// EdIRFrm.cpp : implementation of the CEdIAFrame class
//

#include "stdafx.h"

#include "Defines.hpp"

#ifdef D_ED_IR_ACTIVE

#include "EdIRFrm.hpp"

#include "EdIRRVw.hpp"
#include "EdIRBVw.hpp"
#include "EdIRBtVw.hpp"
#include "EdIRBeha.hpp"
#include "EdIRBeEn.hpp"
#include "EdIRIRD.hpp"
#include "EdIRStrg.hpp"
#include "EdIR2Eng.hpp"
#include "EdIRIAGl.hpp"
#include "EdIRGlob.hpp"
#include "EdIRCstB.hpp"

#include "EdIRIAWd.hpp"
#include "EdIRDvVw.hpp"

#include "EdIRBis.hpp"

//BEGIN ROMTEAM Cristi Petrescu 98-04-
#include "EdIRMacL.hpp"
//END ROMTEAM Cristi Petrescu 98-04-

#include "ai_intf.hpp"

#include "EDACModl.hpp"

#include "incAI.h"
#include "TFA.h"

#include "x:\cpa\main\inc\_EditID.h"

#include "_Actors.hpp"

#include "IncTUT.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern long g_lNbTotalDeNoeud;

/////////////////////////////////////////////////////////////////////////////
// class CPA_EdIR_Frame
/////////////////////////////////////////////////////////////////////////////

//IMPLEMENT_DYNCREATE(CPA_EdIR_Frame, CFrameWnd)
IMPLEMENT_DYNCREATE(CPA_EdIR_Frame, FRMBase)

//BEGIN_MESSAGE_MAP(CPA_EdIR_Frame, CFrameWnd)
BEGIN_MESSAGE_MAP(CPA_EdIR_Frame, FRMBase)
	//{{AFX_MSG_MAP(CPA_EdIR_Frame)
	ON_WM_DESTROY()
	ON_WM_SYSCOMMAND()
	ON_WM_ACTIVATE()
	ON_WM_SETFOCUS()
	//}}AFX_MSG_MAP
//	ON_WM_NCHITTEST()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPA_EdIR_Frame construction/destruction

/**********************************************************************************/
CPA_EdIR_Frame::CPA_EdIR_Frame()
{
	m_pclBrain=NULL;
	m_bKnownWordsFileIsCreated=FALSE;

	//BEGIN ROMTEAM Cristi Petrescu 98-05-
	m_bMarkExecutedLines = TRUE;
	m_bShowTests = TRUE;
	//END ROMTEAM Cristi Petrescu 98-05-

	// BEGIN ROMTEAM Cristi Petrescu 98-06-
	m_pclDebugBrain = NULL;
	// END ROMTEAM Cristi Petrescu 98-06-
}

/**********************************************************************************/
CPA_EdIR_Frame::~CPA_EdIR_Frame()
{
}

/**********************************************************************************/
/*BOOL CPA_EdIR_Frame::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
		| WS_THICKFRAME | WS_MAXIMIZEBOX | WS_SYSMENU;

	HDC	hDC=::GetWindowDC(NULL);

	cs.x=250;
	cs.y=::GetDeviceCaps(hDC,VERTRES)-250;
	cs.cx=::GetDeviceCaps(hDC,HORZRES)-250;
	cs.cy=250;

	::ReleaseDC(NULL,hDC);

	return FRMBase::PreCreateWindow(cs);
} */

/**********************************************************************************/
/*BOOL CPA_EdIR_Frame::Create(LPCTSTR lpszClassName,LPCTSTR lpszWindowName,
							DWORD dwStyle,const RECT& rect,
							CWnd* pParentWnd,LPCTSTR lpszMenuName,
							DWORD dwExStyle,CCreateContext* pContext)
{
	return FRMBase::Create(lpszClassName,lpszWindowName,dwStyle,rect,
							 pParentWnd,lpszMenuName,dwExStyle,pContext);
} */
														
/////////////////////////////////////////////////////////////////////////////
// CPA_EdIR_Frame diagnostics

#ifdef _DEBUG
/**********************************************************************************/
void CPA_EdIR_Frame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

/**********************************************************************************/
void CPA_EdIR_Frame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPA_EdIR_Frame message handlers

/**********************************************************************************/
void CPA_EdIR_Frame::OnSysCommand(UINT nID,LPARAM lParam)
{
	static int	iSplitter1Width;
	static int	iSplitter1MinWidth;
	static int	iSplitter2Height;
	static int	iSplitter2MinHeight;

	if(nID==SC_CLOSE)
	{
		M_GetMainWnd()->SendMessage(WM_CLOSE);
		return;
	}

	if(nID!=SC_MINIMIZE)
	   CFrameWnd::OnSysCommand(nID,lParam);

	switch(nID)
	{
		case SC_MAXIMIZE:
			m_clSplitter2.GetRowInfo(0,iSplitter2Height,iSplitter2MinHeight);
			m_clSplitter1.GetColumnInfo(0,iSplitter1Width,iSplitter1MinWidth);
			m_clSplitter2.SetRowInfo(0,0,1000);
			m_clSplitter1.SetColumnInfo(1,0,1000);

			m_clSplitter1.RecalcLayout();
			m_clSplitter2.RecalcLayout();
			break;

		case SC_RESTORE:
			m_clSplitter1.SetColumnInfo(0,iSplitter1Width,iSplitter1MinWidth);
			m_clSplitter1.SetColumnInfo(1,2000,0);
			m_clSplitter2.SetRowInfo(0,iSplitter2Height,iSplitter2MinHeight);

			m_clSplitter1.RecalcLayout();
			m_clSplitter2.RecalcLayout();
			break;
	}
}

/**********************************************************************************/
/*UINT CPA_EdIR_Frame::OnNcHitTest(CPoint point)
{
	UINT	uiHitTest=CFrameWnd::OnNcHitTest(point);

	return uiHitTest;
} */

/**********************************************************************************/
BOOL CPA_EdIR_Frame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
	if(!m_clSplitter1.CreateStatic(this,1,2,WS_CHILD|WS_VISIBLE))
		return FALSE;

	if(!m_clSplitter2.CreateStatic(&m_clSplitter1,2,1,WS_CHILD|WS_VISIBLE))
		return FALSE;

	HINSTANCE hOldInstance = AfxGetResourceHandle();
	AfxSetResourceHandle(g_stAIIdentity.hModule);

	if(!m_clSplitter1.CreateView(0,1,RUNTIME_CLASS(CPA_EdIR_View),CSize(0,0),pContext))
		return FALSE;

	if(!m_clSplitter2.CreateView(0,0,RUNTIME_CLASS(CPA_EdIR_ButtonView),CSize(0,0),pContext))
		return FALSE;

	if(!m_clSplitter2.CreateView(1,0,RUNTIME_CLASS(CPA_EdIR_DiagView),CSize(0,0),pContext))
		return FALSE;

	m_clSplitter1.SetColumnInfo(0,250,0);

	m_clSplitter2.SetRowInfo(0,44,0);	// CPA2 ASilvescu 98-04-29

	AfxSetResourceHandle( hOldInstance );

	return TRUE;
}

/**********************************************************************************/
void CPA_EdIR_Frame::OnDestroy()
{
	//////////////
	//////////////
	//UnRegisters for TUT Module
	TUT_M_vGetTutDll();
	
	TUT_M_vUnregisterControl(m_hWnd);
	//End of UnRegister for TUT Module
	//////////////

	FRMBase::OnDestroy();
}

/**********************************************************************************/
CPA_EdIR_DiagView *CPA_EdIR_Frame::m_fn_pclGetDiagrammeView()
{
	return (CPA_EdIR_DiagView *)m_clSplitter2.GetPane(1,0);
}

/**********************************************************************************/
CPA_EdIR_View *CPA_EdIR_Frame::m_fn_pclGetEdRulesView()
{
	return (CPA_EdIR_View *)m_clSplitter1.GetPane(0,1);
}

/**********************************************************************************/
CPA_EdIR_ButtonView *CPA_EdIR_Frame::m_fn_pclGetButtonView()
{
	return (CPA_EdIR_ButtonView *)m_clSplitter2.GetPane(0,0);
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vCreateEditor()
{
	CreateBase("Editeur d'Intelligence et de Réflexes",
						 2,3,
						 g_pclAIInterface->GetMainWorld() );

	m_iInitHeight=200;
	m_bKeepPos=TRUE;
	mfn_vEnableCaption(FALSE);
	
	m_stWinTop.cLinkSame = FRM_C_MoveBottom;
	m_stWinLeft.cLinkSame = FRM_C_MoveRight;

	//////////////
	//////////////
	//Registers for TUT Module
	TUT_M_vGetTutDll();
	
	TUT_M_vRegisterControl(m_hWnd,"EdIR_MainFrame",TUT_e_Window);
	//End of Register for TUT Module
	//////////////
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vLevelChanges()
{
	if(!m_bKnownWordsFileIsCreated)
	{
		fn_vInitTranslation();

		//Creates KnownWords File
		fn_vCreateKnownWordsFile();

		m_fn_vFillConstantList();

		m_bKnownWordsFileIsCreated=TRUE;
	}
}

/*
struct tdstBrain_
{
	struct AI_tdstMind_				*p_stMind;
	GMT_tdxHandleToGameMaterial		hLastCollidedGoThroughMaterial;
	ACP_tdxBool						bWarnMechanicsFlag;
  long                  CFast_lCmpMetaAction ; 
  long                  CFast_lRfxMetaAction ; 
  long                  CFast_lCmpMetaActionForMacro ; 
  long                  CFast_lRfxMetaActionForMacro ; 
};
*/

/**********************************************************************************/
BOOL CPA_EdIR_Frame::m_fn_bAcceptToRunEngine()
{
	BOOL	bIaIsAlreadyProcessed;
	CPA_List<CPA_BaseObject> clModelsList;
	g_pclAIInterface->GetMainWorld()->fn_lFindObjects(&clModelsList,"",C_szActorModelTypeName,NO_CRITERIA);


	//IA must be processed ?
	POSITION	pos=clModelsList.GetHeadPosition();
	while(pos!=NULL)
	{
		CPA_Actor		*pclModel=(CPA_Actor *)(clModelsList.GetNext(pos));
		CPA_EdIR_Brain	*pclBrain=((EdActors_EditorActorModel *)pclModel->m_fn_pclGetEditorActor())->m_pclBrain;
		BOOL			bRes;

// YLG
		bIaIsAlreadyProcessed = FALSE;
		//Converts model
		CPA_List<CPA_BaseObject> clInstancesList;
		g_pclAIInterface->GetMainWorld()->fn_lFindObjects(&clInstancesList,"",C_szActorInstanceTypeName,pclModel);

		if(pclBrain->m_fn_bHasBeenModified() || pclBrain->m_bMustBuildDebugInfo)
		{
			pclBrain->m_fn_vSetModified(TRUE);	// Force compile all
			bRes=pclBrain->m_fn_bProcessIA(FALSE);
			if(bRes == FALSE)
				return FALSE;
			bIaIsAlreadyProcessed = TRUE;
		}
		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))
			{
				pclBrain->m_fn_vNotify();	
	 			AI_M_ucErrorFlag(M_pstGetMindOfBrain(hBrain))=0;

				if (bIaIsAlreadyProcessed == FALSE)
				{
					pclBrain->m_fn_vSetModified(TRUE);	// Force compile all
					bRes=pclBrain->m_fn_bProcessIA(FALSE);
					if(bRes == FALSE)
						return FALSE;
					bIaIsAlreadyProcessed = TRUE;
				}
			} 
		}
	}

	BOOL bIAAreGood = TRUE;		// Nicu 31-07-98

	CString	csMsg="Check error raised by engine in IA";
	fn_vDisplayInfoInStatusBar(csMsg,C_STATUS_NORMAL);

	g_pclAIInterface->GetMainWorld()->fn_lFindObjects(&clModelsList,"",C_szActorModelTypeName,NO_CRITERIA);

	pos=clModelsList.GetHeadPosition();
	while(pos!=NULL && bIAAreGood)
	{
		CPA_Actor	*pclModel=(CPA_Actor *)(clModelsList.GetNext(pos));
		CString		csFamilyName=(pclModel->m_pub_fn_pclGetFamily()==NULL) ? "" : pclModel->m_pub_fn_pclGetFamily()->GetName();
		CString		csModelName=pclModel->GetName();

		CString	csMsg="Checking error raised by engine in IA of "+csFamilyName+"@"+csModelName;
		fn_vDisplayInfoInStatusBar(csMsg,C_STATUS_NORMAL);

		//Instances
		CPA_List<CPA_BaseObject> clInstancesList;
		g_pclAIInterface->GetMainWorld()->fn_lFindObjects(&clInstancesList,"",C_szActorInstanceTypeName,pclModel);
		POSITION	pos=clInstancesList.GetHeadPosition();
		while(pos!=NULL && bIAAreGood)
		{
			CPA_Actor						*pclInstance=(CPA_Actor *)(clInstancesList.GetNext(pos));
			tdstEngineObject		*pstEngineObject=(tdstEngineObject *)pclInstance->GetStruct();
			MS_tdxHandleToBrain	hBrain=pstEngineObject->h_Brain;

			if(hBrain!=NULL)
			{
				AI_tdstMind	*pstMind=M_pstGetMindOfBrain(hBrain);

				if(pstMind!=NULL)
				{
					if(AI_M_ucErrorFlag(pstMind))
					{
						CString	csMsg="Error raised by engine in IA of "+csFamilyName+"@"+csModelName+"@"+pclInstance->GetName();
						fn_vDisplayInfoInStatusBar(csMsg,C_STATUS_ERROR);

						bIAAreGood=FALSE;
					}
				}
			}
		}
	}

	return bIAAreGood;
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vAddOneModifiedBrain(CPA_EdIR_Brain *pclBrain)
{
	if(m_clListOfModifiedBrains.Find(pclBrain)==NULL)
		m_clListOfModifiedBrains.AddTail(pclBrain);
}

/**********************************************************************************/
BOOL CPA_EdIR_Frame::m_fn_bAcceptToSave()
{
	CList<CPA_EdIR_Brain *,CPA_EdIR_Brain *>	clListOfCheckedBrains;

	//Checks IA
	POSITION	pos=m_clListOfModifiedBrains.GetHeadPosition();
	BOOL			bAcceptToSave=TRUE;

	while(pos!=NULL && bAcceptToSave)
	{
		CPA_EdIR_Brain	*pclBrain=m_clListOfModifiedBrains.GetNext(pos);
		CPA_Actor				*pclModel=pclBrain->m_fn_pclGetModel();
		CString					csFamilyName=(pclModel->m_pub_fn_pclGetFamily()==NULL) ? "" : pclModel->m_pub_fn_pclGetFamily()->GetName();
		CString					csModelName=pclModel->GetName();

		g_pclCurrentModel=pclModel;
		// BEGIN ROMTEAM Cristi Petrescu 99-01- debug
		BOOL bModified = pclBrain->m_fn_bHasBeenModified();
		//bAcceptToSave=pclBrain->m_fn_bCheckIA();
		
		// process them if needed...
		if (bAcceptToSave)
		{
			if (bModified)
			{
				CString csMessage = "You modified the AI of model  " + 
									 csFamilyName+"@"+ csModelName + ", \n" +
									 "but you did not parse it.\n" +
									 "There may be incoherences between model and instance. \n" +
									 "Do you want to parse the AI before saving ?";

				int iAction = AfxMessageBox (csMessage, MB_YESNOCANCEL);
				switch (iAction)
				{
				case IDYES:
					pclBrain->m_fn_vSetModified(TRUE);	// Force compile all
					bAcceptToSave = pclBrain -> m_fn_bProcessIA (FALSE);
					break;
				case IDNO:
					bAcceptToSave = pclBrain -> m_fn_bCheckIA ();
					break;
				case IDCANCEL:
					bAcceptToSave = FALSE;
					break;
				}
			}
			else
				bAcceptToSave = pclBrain -> m_fn_bCheckIA ();
		}
// END ROMTEAM Cristi Petrescu 99-01- debug


		if(bAcceptToSave==FALSE)
		{
			CString	csMsg="Can't save IA : check IA of "+csFamilyName+"@"+csModelName;
//			fn_vDisplayInfoInStatusBar(csMsg,C_STATUS_ERROR);
		}
		else
		{
			clListOfCheckedBrains.AddTail(pclBrain);
		}
	}

	//Removes good IA from m_clListOfModifiedBrains
	pos=clListOfCheckedBrains.GetHeadPosition();
	while(pos!=NULL)
	{
		CPA_EdIR_Brain	*pclBrain=clListOfCheckedBrains.GetNext(pos);

		POSITION	p=m_clListOfModifiedBrains.Find(pclBrain);

		if(p!=NULL)
			m_clListOfModifiedBrains.RemoveAt(p);
	}

	return bAcceptToSave;
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vBeforeSaveAll()
{
	if(m_pclBrain)
		m_fn_pclGetButtonView()->m_fn_vEnableButtons(FALSE);
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vAfterSaveAll()
{
	m_clListOfModifiedBrains.RemoveAll();

	if(m_pclBrain)
		m_fn_pclGetButtonView()->m_fn_vEnableButtons(TRUE);
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vBeforeEngine()
{
	/* CHRISTOPHE QUICK SAVE MODIFICATIONS { */
	//Quick Save : save all modified IA
	POSITION	pos=m_clListOfModifiedBrains.GetHeadPosition();
	while(pos!=NULL)
	{
		CPA_EdIR_Brain	*pclBrain=m_clListOfModifiedBrains.GetNext(pos);

		pclBrain->m_fn_vQuickSave();
	}

	CPA_List<CPA_BaseObject> clModelsList;
	g_pclAIInterface->GetMainWorld()->fn_lFindObjects(&clModelsList,"",C_szActorModelTypeName,NO_CRITERIA);

	pos=clModelsList.GetHeadPosition();
	/* } END CHRISTOPHE QUICK SAVE MODIFICATIONS */
	while(pos!=NULL)
	{
		CPA_Actor	*pclModel=(CPA_Actor *)(clModelsList.GetNext(pos));
		CString		csFamilyName=(pclModel->m_pub_fn_pclGetFamily()==NULL) ? "" : pclModel->m_pub_fn_pclGetFamily()->GetName();
		CString		csModelName=pclModel->GetName();

		CString	csMsg="Modifying IA of "+csFamilyName+"@"+csModelName;
		fn_vDisplayInfoInStatusBar(csMsg,C_STATUS_NORMAL);

		//BEGIN ROMTEAM Cristi Petrescu 98-05-
		// before all, build debug info (and rebuild all engine structures...
		CPA_EdIR_Brain	*pclBrain=((EdActors_EditorActorModel *)pclModel->m_fn_pclGetEditorActor())->m_pclBrain;
		pclBrain -> m_fn_vUpdateDebugInfo ();
		//END ROMTEAM Cristi Petrescu 98-05-

		//Converts model
		CPA_List<CPA_BaseObject> clInstancesList;
		g_pclAIInterface->GetMainWorld()->fn_lFindObjects(&clInstancesList,"",C_szActorInstanceTypeName,pclModel);
		if(!clInstancesList.IsEmpty())
		{
			CPA_Actor						*pclInstance=(CPA_Actor *)(clInstancesList.GetHead());
			tdstEngineObject		*pstEngineObject=(tdstEngineObject *)pclInstance->GetStruct();
			MS_tdxHandleToBrain	hBrain=pstEngineObject->h_Brain;

			if(hBrain!=NULL)
			{
				AI_tdstMind	*pstMind=M_pstGetMindOfBrain(hBrain);

				if(pstMind!=NULL)
				{
					AI_tdstAIModel	*pstAIModel=AI_M_p_stGetAIModel(pstMind);

					if(pstAIModel!=NULL)
					{
						fn_vConvertIndexToPointerForModel(pstAIModel);
						fn_vConvertEditorPointerIntoEnginePointer(pstAIModel);
					}
				}
			}
		}

		/*
		 * Convert instances.
		 * Test if one instance of the model must be reinit (comport). If yes, all the instances
		 * will be reinit juste after.
		 */
		POSITION	pos=clInstancesList.GetHeadPosition();
		BOOL		bMustReinit = FALSE;
		while(pos!=NULL)
		{
			CPA_Actor				*pclInstance=(CPA_Actor *)(clInstancesList.GetNext(pos));
			tdstEngineObject		*pstEngineObject=(tdstEngineObject *)pclInstance->GetStruct();
			MS_tdxHandleToBrain		hBrain=pstEngineObject->h_Brain;

			if(hBrain!=NULL)
			{
				AI_tdstMind	*pstMind=M_pstGetMindOfBrain(hBrain);

				if(pstMind!=NULL)
				{
					/* Convert */
					fn_vConvertIndexToPointerForInstance(pstMind);

					/* Test if instance must be reinit */
					CPA_EdIR_Brain	*pclBrain=((EdActors_EditorActorModel *)pclModel->m_fn_pclGetEditorActor())->m_pclBrain;
					if(pclBrain->m_fn_bReInitBehaviourIsNeeded())
					{
						bMustReinit = TRUE;
					}
				}
			}
		}

		if(bMustReinit)
		{
			POSITION	pos=clInstancesList.GetHeadPosition();
			while(pos!=NULL)
			{
				CPA_Actor			*pclInstance=(CPA_Actor *)(clInstancesList.GetNext(pos));
				tdstEngineObject	*pstEngineObject=(tdstEngineObject *)pclInstance->GetStruct();
				MS_tdxHandleToBrain	hBrain=pstEngineObject->h_Brain;

				if(hBrain!=NULL)
				{
					AI_tdstMind	*pstMind=M_pstGetMindOfBrain(hBrain);
					if(pstMind!=NULL)
					{
						CPA_EdIR_Brain	*pclBrain=((EdActors_EditorActorModel *)pclModel->m_fn_pclGetEditorActor())->m_pclBrain;
						fn_vReinitAIComport(pstMind);
						pclBrain->m_fn_vSetReInitBehaviourFlag(FALSE);
					}
				}
			}
		}
	}

	//For Ai Engine
	//fn_vRESET_STOP_AI_ENGINE_FLAG();

	//Sets BreakPoints
	pos=clModelsList.GetHeadPosition();
	while(pos!=NULL)
	{
		CPA_Actor	*pclModel=(CPA_Actor *)(clModelsList.GetNext(pos));
		CString		csFamilyName=(pclModel->m_pub_fn_pclGetFamily()==NULL) ? "" : pclModel->m_pub_fn_pclGetFamily()->GetName();
		CString		csModelName=pclModel->GetName();

		CString	csMsg="Updating Break points in IA of "+csFamilyName+"@"+csModelName+" ... ";
		fn_vDisplayInfoInStatusBar(csMsg,C_STATUS_NORMAL);

		CPA_EdIR_Brain	*pclBrain=((EdActors_EditorActorModel *)pclModel->m_fn_pclGetEditorActor())->m_pclBrain;

		pclBrain->m_fn_vSetEngineBreakPoints(TRUE);

		csMsg += "OK";
		fn_vDisplayInfoInStatusBar(csMsg,C_STATUS_NORMAL);
	}

	//
	fn_vReSetStopAIEngineFlag();
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vBeforeEditor()
{
	CPA_List<CPA_BaseObject> clModelsList;
	g_pclAIInterface->GetMainWorld()->fn_lFindObjects(&clModelsList,"",C_szActorModelTypeName,NO_CRITERIA);

	POSITION	pos=clModelsList.GetHeadPosition();
	while(pos!=NULL)
	{
		CPA_Actor	*pclModel=(CPA_Actor *)(clModelsList.GetNext(pos));

		//Converts model
		CPA_List<CPA_BaseObject> clInstancesList;
		g_pclAIInterface->GetMainWorld()->fn_lFindObjects(&clInstancesList,"",C_szActorInstanceTypeName,pclModel);
		if(!clInstancesList.IsEmpty())
		{
			CPA_Actor						*pclInstance=(CPA_Actor *)(clInstancesList.GetHead());
			tdstEngineObject		*pstEngineObject=(tdstEngineObject *)pclInstance->GetStruct();
			MS_tdxHandleToBrain	hBrain=pstEngineObject->h_Brain;

			if(hBrain!=NULL)
			{
				AI_tdstMind	*pstMind=M_pstGetMindOfBrain(hBrain);

				if(pstMind!=NULL)
				{
					AI_tdstAIModel	*pstAIModel=AI_M_p_stGetAIModel(pstMind);

					if(pstAIModel!=NULL)
					{
						fn_vConvertPointerToIndexForModel(pstAIModel);
						fn_vConvertEnginePointerIntoEditorPointer(pstAIModel);
					}
				}
			}
		}

		//Converts instances
		POSITION	pos=clInstancesList.GetHeadPosition();
		while(pos!=NULL)
		{
			CPA_Actor						*pclInstance=(CPA_Actor *)(clInstancesList.GetNext(pos));
			tdstEngineObject		*pstEngineObject=(tdstEngineObject *)pclInstance->GetStruct();
			MS_tdxHandleToBrain	hBrain=pstEngineObject->h_Brain;

			if(hBrain!=NULL)
			{
				AI_tdstMind	*pstMind=M_pstGetMindOfBrain(hBrain);

				if(pstMind!=NULL)
					fn_vConvertPointerToIndexForInstance(pstMind);
			}
		}
	}

	//Removes BreakPoints
	pos=clModelsList.GetHeadPosition();
	while(pos!=NULL)
	{
		CPA_Actor	*pclModel=(CPA_Actor *)(clModelsList.GetNext(pos));

		CPA_EdIR_Brain	*pclBrain=((EdActors_EditorActorModel *)pclModel->m_fn_pclGetEditorActor())->m_pclBrain;

		pclBrain->m_fn_vSetEngineBreakPoints(FALSE);
	}

	CPA_DLLBase	*pclActorDLL=(CPA_DLLBase*)(g_pclAIInterface->GetMainWorld()->GetObjectDLLWithName(C_szDLLActorName));
	CPA_EdIR_DesignerVariablesView	*pclDsgVarView=(CPA_EdIR_DesignerVariablesView *)pclActorDLL->OnQueryAction(g_pclAIInterface,C_uiActor_GetDesignerVariablesView,0);
	CPA_Actor	*pclSelectedActor=(CPA_Actor *)pclActorDLL->OnQueryAction(g_pclAIInterface,C_uiActor_GetSelectedActor,0);
	CTL_Editor_DataList	*pclListOfDesignerVariableType;
	if(pclSelectedActor)
	{
/*
		pclListOfDesignerVariableType=pclSelectedActor->m_fn_pclGetEditorActor()->m_pclListOfDesignerVariableType;
		pclDsgVarView->m_fn_vUpdateDisplayWithValues(pclListOfDesignerVariableType);
*/
    //EdActors_EditorActorModel *pclModel = (EdActors_EditorActorModel *) pclSelectedActor->m_fn_pclGetModel()->m_fn_pclGetEditorActor();
		EdActors_EditorActorModel *pclModel;
		if(pclSelectedActor->m_fn_bIsAnInstance())
			pclModel= (EdActors_EditorActorModel* ) pclSelectedActor->m_fn_pclGetModel()->m_fn_pclGetEditorActor();
		else
			pclModel = (EdActors_EditorActorModel* ) pclSelectedActor->m_fn_pclGetEditorActor();

		pclListOfDesignerVariableType = pclSelectedActor->m_fn_pclGetEditorActor()->m_pclListOfDesignerVariableType;
	
		pclDsgVarView->m_fn_vUpdateControls(&(pclModel->m_clListOfDesignerVariableControl));
		pclDsgVarView->m_fn_vUpdateDisplayWithValues(pclListOfDesignerVariableType);
	}
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vAModelHasBeenRemoved()
{
	m_pclBrain=NULL;

	m_fn_pclGetDiagrammeView()->m_fn_vAModelHasBeenRemoved();

	m_fn_pclGetButtonView()->m_fn_vEnableButtons(FALSE);
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vShowBrain(CPA_EdIR_Brain *pclBrain)
{
	if(pclBrain)
	{
		AfxGetApp()->DoWaitCursor(1);
//ANNECY CB
		SetCapture();
		if(m_fn_pclGetDiagrammeView())
			m_fn_pclGetDiagrammeView()->ShowWindow(FALSE);
		gbFirstShowBrain = pclBrain->m_bFirstShow;
//END ANNECY

		CString	csFamilyName=(pclBrain->m_fn_pclGetModel()->m_pub_fn_pclGetFamily()==NULL) ? "" : pclBrain->m_fn_pclGetModel()->m_pub_fn_pclGetFamily()->GetName();
		CString	csModelName=pclBrain->m_fn_pclGetModel()->GetName();

		CString	csMsg;
		CString	csMsgBase="Updating IA controls for "+csFamilyName+"@"+csModelName+" ... ";
		fn_vDisplayInfoInStatusBar(csMsgBase,C_STATUS_NORMAL);

		m_fn_pclGetButtonView()->m_fn_vEnableButtons(TRUE);

//ANNECY CB
	CPA_EdIR_Brain	*pclOldBrain=m_pclBrain;
	m_pclBrain=pclBrain;
	// BEGIN CPA2 Cristi Petrescu 98-03-
	g_pclListOfSubrs = & m_pclBrain -> m_clListOfSubrs;
	// END CPA2 Cristi Petrescu 98-03-
	m_fn_vUpdateBehaviours();

	csMsg=csMsgBase+"OK";
	fn_vDisplayInfoInStatusBar(csMsg,C_STATUS_NORMAL);

	if(m_pclBrain)
	{
		if(m_pclBrain!=pclOldBrain)
			m_pclBrain->m_fn_vCreateOrUpdateDsgVarControlsWithEngineValues();
	}

//		m_fn_pclUpdateBrain(pclBrain);
//		csMsg=csMsgBase+"OK";
//		fn_vDisplayInfoInStatusBar(csMsg,C_STATUS_NORMAL);
//END ANNECY

		//Update BreakPoint
		m_fn_pclGetEdRulesView()->m_fn_vSetBreakPointList(m_pclBrain->m_fn_pclGetBreakPointList());
		m_fn_pclGetEdRulesView()->InvalidateRect(NULL);

		//Update DebugInfo
		//BEGIN ROMTEAM Cristi Petrescu 98-05-
		m_fn_pclGetEdRulesView()->m_fn_vSetDebugInfoList(NULL);
		//END ROMTEAM Cristi Petrescu 98-05-

//ANNECY CB
		AfxGetApp()->DoWaitCursor(-1);
		ReleaseCapture();
		if(m_fn_pclGetDiagrammeView())
			m_fn_pclGetDiagrammeView()->ShowWindow(TRUE);
		gbFirstShowBrain = pclBrain->m_bFirstShow = FALSE;
//END ANNECY
		//BEGIN ROMTEAM Cristi Petrescu 98-06-
		CPA_DLLBase *pclActorDLL = (CPA_DLLBase *) (g_pclAIInterface -> GetMainWorld () -> GetObjectDLLWithName (C_szDLLActorName));
		CPA_EdIR_DesignerVariablesView *pclDsgVarView = (CPA_EdIR_DesignerVariablesView *) pclActorDLL->OnQueryAction (g_pclAIInterface, C_uiActor_GetDesignerVariablesView, 0);
		pclDsgVarView -> m_fn_vSynchronizeWithBrain (pclBrain);
		//END ROMTEAM Cristi Petrescu 98-06-
	}
}

/**********************************************************************************/
//ANNECY CB
CPA_EdIR_Brain *CPA_EdIR_Frame::m_fn_pclUpdateBrain(CPA_EdIR_Brain *pclBrain,BOOL bCreateDsgVar/*=TRUE*/,BOOL Disp)
//CPA_EdIR_Brain *CPA_EdIR_Frame::m_fn_pclUpdateBrain(CPA_EdIR_Brain *pclBrain,BOOL bCreateDsgVar/*=TRUE*/)
//END
{
	CPA_EdIR_Brain	*pclOldBrain=m_pclBrain;

	m_pclBrain=pclBrain;
	// BEGIN CPA2 Cristi Petrescu 98-03-
	g_pclListOfSubrs = & m_pclBrain -> m_clListOfSubrs;
	// END CPA2 Cristi Petrescu 98-03-

//ANNECY CB
	m_fn_vUpdateBehaviours(Disp);
//	m_fn_vUpdateBehaviours();
//END
	if(m_pclBrain)
	{
		if(bCreateDsgVar && m_pclBrain!=pclOldBrain)
			m_pclBrain->m_fn_vCreateOrUpdateDsgVarControlsWithEngineValues();

		//BEGIN ROMTEAM Cristi Petrescu 98-06-
		CPA_DLLBase *pclActorDLL = (CPA_DLLBase *) (g_pclAIInterface -> GetMainWorld () -> GetObjectDLLWithName (C_szDLLActorName));
		CPA_EdIR_DesignerVariablesView *pclDsgVarView = (CPA_EdIR_DesignerVariablesView *) pclActorDLL->OnQueryAction (g_pclAIInterface, C_uiActor_GetDesignerVariablesView, 0);
		pclDsgVarView -> m_fn_vSynchronizeWithBrain (pclBrain);
		//END ROMTEAM Cristi Petrescu 98-06-
	}

	return pclOldBrain;
}

/**********************************************************************************/
//ANNECY CB
void CPA_EdIR_Frame::m_fn_vUpdateBehaviours(BOOL Disp)
//void CPA_EdIR_Frame::m_fn_vUpdateBehaviours()
//END
{
	if(m_pclBrain)
	{
		tdeEditState					tdeSate=m_fn_pclGetButtonView()->m_fn_tdeGetEditState();
		tdeBehaviourModeView	tdeMode=m_fn_pclGetButtonView()->m_fn_tdeGetViewMode();
		switch(tdeSate)
		{
			case EditIntell:
				m_pclBrain->m_fn_vUpdateBehavioursList(m_fn_pclGetDiagrammeView(),tdeSate);
//ANNECY CB
				if(!Disp) break;
//END
				m_fn_pclGetDiagrammeView()->m_fn_vUpdateListOfBehaviour(&(m_pclBrain->m_clListOfIntelligenceBehaviours));
				m_fn_pclGetDiagrammeView()->m_fn_vChangeViewModeOfBehaviours(tdeMode);
				break;

			case EditReflex:
				m_pclBrain->m_fn_vUpdateBehavioursList(m_fn_pclGetDiagrammeView(),tdeSate);
//ANNECY CB
				if(!Disp) break;
//END
				m_fn_pclGetDiagrammeView()->m_fn_vUpdateListOfBehaviour(&(m_pclBrain->m_clListOfReflexBehaviours));
				m_fn_pclGetDiagrammeView()->m_fn_vChangeViewModeOfBehaviours(tdeMode);
				break;

			case EditDecl:
				m_pclBrain->m_fn_vUpdateBehavioursList(m_fn_pclGetDiagrammeView(),tdeSate);
//ANNECY CB
				if(!Disp) break;
//END
				m_fn_pclGetDiagrammeView()->m_fn_vUpdateListOfBehaviour(&(m_pclBrain->m_clListOfDeclarations));
				m_fn_pclGetDiagrammeView()->m_fn_vChangeViewModeOfBehaviours(tdeMode);
				break;

			// BEGIN CPA2 Cristi Petrescu 98-03-
			case EditMacro:

				// BEGIN ROMTEAM CPA2 Cristi Petrescu 98-04-
				if (!Disp)
					break;
				// END ROMTEAM CPA2 Cristi Petrescu 98-04-

				m_pclBrain->m_fn_vUpdateBehavioursList(m_fn_pclGetDiagrammeView(),tdeSate);
				m_fn_pclGetDiagrammeView()->m_fn_vUpdateListOfBehaviour(&(m_pclBrain->m_clListOfMacros));
				m_fn_pclGetDiagrammeView()->m_fn_vChangeViewModeOfBehaviours(tdeMode);
				break;
			// END CPA2 Cristi Petrescu 98-03-

			// BEGIN ROMTEAM CPA2 Cristi Petrescu 98-04-
			case EditSubr:

				if (!Disp)
					break;
			
				m_pclBrain->m_fn_vUpdateBehavioursList(m_fn_pclGetDiagrammeView(),tdeSate);
				m_fn_pclGetDiagrammeView()->m_fn_vUpdateListOfBehaviour(&(m_pclBrain->m_clListOfSubrs));
				m_fn_pclGetDiagrammeView()->m_fn_vChangeViewModeOfBehaviours(tdeMode);
				break;
			// END ROMTEAM CPA2 Cristi Petrescu 98-04-
			
			default:
				break;
		}
	}
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vChangeViewModeOfBehaviours()
{
	if(m_pclBrain)
	{
		tdeBehaviourModeView	tdeMode=m_fn_pclGetButtonView()->m_fn_tdeGetViewMode();
		m_fn_pclGetDiagrammeView()->m_fn_vChangeViewModeOfBehaviours(tdeMode);
	}
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vCreateNewBehaviour()
{
	if(m_pclBrain)
	{
		tdeBehaviourModeView	tdeMode=m_fn_pclGetButtonView()->m_fn_tdeGetViewMode();
		m_fn_pclGetDiagrammeView()->m_fn_vCreateNewBehaviour(tdeMode);
	}
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vSetRulesEditorReadOnly(BOOL bReadOnly)
{
	m_fn_pclGetEdRulesView()->m_fn_vSetReadOnly(bReadOnly);
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vChangeRulesView(tdeRulesViewMode tdeMode)
{
	if(m_pclBrain)
	{
		switch(tdeMode)
		{
			case IntelligenceView:
				m_fn_pclGetButtonView()->m_fn_vSetEditState(EditIntell);
				break;

			case ReflexView:
				m_fn_pclGetButtonView()->m_fn_vSetEditState(EditReflex);
				break;

			default:
				break;
		}
	}
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vCheckBehaviour()
{
	if(m_pclBrain!=NULL)
	{
		tdeEditState	tdeSate=m_fn_pclGetButtonView()->m_fn_tdeGetEditState();
		g_pclCurrentModel=m_pclBrain->m_fn_pclGetModel();
		switch(tdeSate)
		{
			case EditIntell:
				m_fn_pclGetDiagrammeView()->m_fn_vCheckBehaviour(IntelligenceText);
				break;

			case EditReflex:
				m_fn_pclGetDiagrammeView()->m_fn_vCheckBehaviour(ReflexText);
				break;

			case EditDecl:
				m_fn_pclGetDiagrammeView()->m_fn_vCheckBehaviour(DsgVarText);
				break;

			// BEGIN CPA2 Cristi Petrescu 98-03-
			case EditMacro:
				m_fn_pclGetDiagrammeView()->m_fn_vCheckBehaviour(Macro_2_Text);
				break;
			// END CPA2 Cristi Petrescu 98-03-

			//BEGIN ROMTEAM Cristi Petrescu 98-04-
			case EditSubr:
				m_fn_pclGetDiagrammeView()->m_fn_vCheckBehaviour(SubrText);
				break;
				//END ROMTEAM Cristi Petrescu 98-04-

			default:
				break;
		}
	}
}
/**********************************************************************************/
/* CHRISTOPHE QUICK SAVE MODIFICATIONS { */
void CPA_EdIR_Frame::m_fn_vQuickSave()
{
	AfxGetApp()->DoWaitCursor(1);
	SetCapture();
	//If SHIFT is down we save all modifies IAs
	if((GetAsyncKeyState(VK_SHIFT) & 0x8000) == 0x8000)
	{
		POSITION	pos=m_clListOfModifiedBrains.GetHeadPosition();
		while(pos!=NULL)
		{
			CPA_EdIR_Brain	*pclBrain=m_clListOfModifiedBrains.GetNext(pos);

			pclBrain->m_fn_vQuickSave();
		}
	}
	else
	//else we save the current IA
	if(m_pclBrain)
	{
		m_pclBrain->m_fn_vQuickSave();
	}
	ReleaseCapture();
	AfxGetApp()->DoWaitCursor(-1);
}
/* } END CHRISTOPHE QUICK SAVE MODIFICATIONS */
/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vSaveAll()
{
	int	iRes=MessageBox("Are you sure you want to save all IA(s) ?\nThis will be erase all old IA(s) !!\nChoosing \"SaveAll\" in the Project Menu will take few minutes !!",
											"Save All ?",
											MB_YESNO|MB_ICONQUESTION);

	if(iRes==IDYES)
	{
		CPA_List<CPA_BaseObject> clModelsList;
		g_pclAIInterface->GetMainWorld()->fn_lFindObjects(&clModelsList,"",C_szActorModelTypeName,NO_CRITERIA);

		POSITION	pos=clModelsList.GetHeadPosition();
		while(pos!=NULL)
		{
			CPA_Actor	*pclModel=(CPA_Actor *)(clModelsList.GetNext(pos));

			if(pclModel->fn_bIsAvailable())
			{
				CPA_EdIR_Brain	*pclBrain=((EdActors_EditorActorModel *)pclModel->m_fn_pclGetEditorActor())->m_pclBrain;
//ROMTEAM Check save 12.06.98 Ionut Grozea
				CString m_szModelName = pclBrain->m_fn_csGetModelName();
				if (m_szModelName == "StdCam" || m_szModelName == "YLT_RaymanModel")
				{
					if (pclBrain->m_fn_bHasBeenModified())
						pclBrain->m_fn_vNotify();
				}
				else
//ENDROMTEAM Check save 12.06.98 Ionut Grozea
				pclBrain->m_fn_vNotify();
			}
		}
	}
}

/**********************************************************************************/
BOOL CPA_EdIR_Frame::m_fn_bProcessIA(BOOL bProcessAll)
{
	if(m_pclBrain)
	{
		CPA_DLLBase											*pclActorDLL=(CPA_DLLBase*)(g_pclAIInterface->GetMainWorld()->GetObjectDLLWithName(C_szDLLActorName));
		CPA_EdIR_DesignerVariablesView	*pclDsgVarView=(CPA_EdIR_DesignerVariablesView *)pclActorDLL->OnQueryAction(g_pclAIInterface,C_uiActor_GetDesignerVariablesView,0);
		CPA_Actor												*pclSelectedActor;

		pclSelectedActor=(CPA_Actor *)pclActorDLL->OnQueryAction(g_pclAIInterface,C_uiActor_GetSelectedActor,0);

		if(pclSelectedActor->m_fn_bIsAModel() &&
			 pclSelectedActor!=m_fn_pclGetModel())
		{
			AfxMessageBox("[DEV] CPA_EdIR_Frame::m_fn_bProcessIA : models are not the same !!");

			return FALSE;
		}
		else
		if(pclSelectedActor->m_fn_bIsAnInstance() &&
			 pclSelectedActor->m_fn_pclGetModel()!=m_fn_pclGetModel())
		{
			AfxMessageBox("[DEV] CPA_EdIR_Frame::m_fn_bProcessIA : instance is not an instance of model !!");

			return FALSE;
		}
		else
		{
			return m_pclBrain->m_fn_bProcessIA(bProcessAll,pclSelectedActor);
		}
	}
	else
		return FALSE;
}

// Shaitan FastC (16/06/98) {
/**********************************************************************************/
extern int  gi_ActualRefStr;
extern int  gi_ActualRefNode;
FILE		*gh_CRRFile = NULL;
extern		char CFast_IsAReference(tdstNodeInterpret *_pst_Node, int *pi_Indice);

struct AI_tdstMind_ *gp_stCurrentMind = NULL;
EdActors_MyDocument *fn_pclGetEdActorsDocument();

#include	"CFast_3.hpp"
#include	"CFast_2.hpp"

/**********************************************************************************/
BOOL CFast_GenerateCRR(CPA_EdIR_Brain *pBrain, char *pszName)
{
	char name[255], *psz_Temp;
  struct tdstTreeInterpret_	stTree;

	gi_ActualRefStr = gi_ActualRefNode = 0;

	strcpy(name, pszName);
	psz_Temp = strrchr(name, '.');
	strcpy(psz_Temp, ".crr");

	gh_CRRFile = fopen(name, "wt");
	if(gh_CRRFile == NULL)
		return FALSE;

	fprintf(gh_CRRFile, "{CreateRule:(1, XXXX)\n", gi_ActualRefStr);

	pBrain->m_clListOfReflexBehaviours.m_fn_bProcessIA(TRUE, FALSE, NULL,NULL,CRRGeneration, pBrain->m_fn_pclGetDebugInfoList());
	pBrain->m_clListOfIntelligenceBehaviours.m_fn_bProcessIA(TRUE, FALSE, NULL,NULL,CRRGeneration, pBrain->m_fn_pclGetDebugInfoList());
	pBrain->m_clListOfSubrs.m_fn_bProcessIA(TRUE, FALSE, NULL,NULL,CRRGeneration, pBrain->m_fn_pclGetDebugInfoList());

	fprintf(gh_CRRFile, "}\n", gi_ActualRefStr);
	fseek(gh_CRRFile, 0, SEEK_SET);
	fprintf(gh_CRRFile, "{CreateRule:(1, %4d)\n", gi_ActualRefStr);
	fclose(gh_CRRFile);

  /*
   * reload the crr
   */
	fn_vLoadCRR ( gp_stCurrentMind, name ) ;
  if ( AI_M_p_stGetAIModel(gp_stCurrentMind)->CFast_dst_RefTreeArray != NULL ) {
    M_GetNodeInterpret(&stTree) = AI_M_p_stGetAIModel(gp_stCurrentMind)->CFast_dst_RefTreeArray ;
    M_SetNbNodeInterpret(&stTree, AI_M_p_stGetAIModel(gp_stCurrentMind)->uwNbNode);
    fn_vSecondPassOfTree(gp_stCurrentMind, &stTree);
  }

	return TRUE;
}

BOOL CPA_EdIR_Frame::m_fn_bGenerateFastC(BOOL bProcessAll)
{
	CString                   msg;
	tdstEngineObject          *pstEngineObject;
	CPA_EdIR_Brain            *pOrgBrain = m_pclBrain;
	EdActors_MyDocument       *pclDocument=fn_pclGetEdActorsDocument();
	Position                  pos;
	CPA_Actor                 *pclSelectedActor;
	EdActors_EditorActorModel	*pclEditorModel;
	CPA_EdIR_Brain				    *pclOrgBrain = m_pclBrain;
	long					            lSizeTree = 0;
//	FILE					            *hLog = fopen("x:/cpa/exe/main/sizetree.log", "wt");
	FILE					            *hLog = fopen("sizetree.log", "wt");
  AI_tdstAIModel						*p_stAIModel=NULL;
  SCR_tdst_Link_Value       *p_stValue ;
  unsigned long             ulCFastFunction, ulOldCFastFunction, ulOldCFastIsC ;
  unsigned long             ulCFastIsC ;


	if(MessageBox("Convert all loaded models ?", "IA to C", MB_YESNO) == IDYES)
		bProcessAll = TRUE;
	else
		bProcessAll = FALSE;

	pos = pclDocument->m_clModelsList.GetHeadPosition();
	while(pos)
	{
		if(bProcessAll)
		{
			pclSelectedActor = (CPA_Actor*) pclDocument->m_clModelsList.GetAt(pos);
			if(!pclSelectedActor->fn_bIsAvailable())
			{
				goto nextpos;
			}
			pclEditorModel=pclSelectedActor->m_fn_pclGetEditorModel();
			m_pclBrain = pclEditorModel->m_pclBrain;
		}
		else
		{
			CPA_DLLBase	*pclActorDLL=(CPA_DLLBase*)(g_pclAIInterface->GetMainWorld()->GetObjectDLLWithName(C_szDLLActorName));
			pclSelectedActor=(CPA_Actor *)pclActorDLL->OnQueryAction(g_pclAIInterface,C_uiActor_GetSelectedActor,0);
		}
		
		if(m_pclBrain)
		{
			/*****************************/			
			CPA_EdIR_MainBehaviourList	*p_oReflex, *p_oComport, *p_oSubroutines ;
			CPA_EdIR_MainBehaviour		*p_oBehaviour;
			POSITION					pos ;
			unsigned long				ulCount ; 
			struct AI_tdstMind_			*p_stMind = NULL;
			tdstComport					*p_stMyComport = NULL;
			CFast_tdstComportTree		*p_stMyFastTree = NULL;

      CPA_DLLBase						*pclActorDLL=(CPA_DLLBase*)(g_pclAIInterface->GetMainWorld()->GetObjectDLLWithName(C_szDLLActorName));
			CPA_EdIR_DesignerVariablesView	*pclDsgVarView=(CPA_EdIR_DesignerVariablesView *)pclActorDLL->OnQueryAction(g_pclAIInterface,C_uiActor_GetDesignerVariablesView,0);

      /*
       * get mind of an instance of the model
       */
			if (pclSelectedActor->m_fn_bIsAnInstance())
			{
				pstEngineObject = M_GetEngineObject(pclSelectedActor->m_pub_fn_hGetMotorSuperObject());
				gp_stCurrentMind = p_stMind = AI_M_stGetMindOfSuperObj(pclSelectedActor->m_pub_fn_hGetMotorSuperObject());
			}
			if (pclSelectedActor->m_fn_bIsAModel())
			{
				CPA_List<CPA_BaseObject> clInstancesList;
				g_pclAIInterface->GetMainWorld()->fn_lFindObjects(&clInstancesList, "", C_szActorInstanceTypeName, pclSelectedActor);
				if(!clInstancesList.IsEmpty())
				{
					CPA_Actor						*pclInstance=(CPA_Actor *)(clInstancesList.GetHead());
					pstEngineObject=(tdstEngineObject *)pclInstance->GetStruct();
					MS_tdxHandleToBrain	hBrain=pstEngineObject->h_Brain;
					
					if(hBrain!=NULL)
						gp_stCurrentMind = p_stMind = M_pstGetMindOfBrain(hBrain);
				}
			}
			
			if (p_stMind == NULL) 
			{
				goto nextpos;
			}
      /*
       * save old reftree
       */
      p_stAIModel=AI_M_p_stGetAIModel(p_stMind);
      ulCFastFunction = p_stAIModel->CFast_lFunction ;
      ulCFastIsC      = p_stAIModel->CFast_bIsC ;
      p_stValue = fn_vGetLinkTableForCRR ( p_stAIModel ) ;


		  /* Process IA */
		  if(m_pclBrain->m_fn_bProcessIA(TRUE,pclSelectedActor) == FALSE)
		  {
			  fn_vDisplayInfoInStatusBar("ERROR!",C_STATUS_NORMAL);
			  m_pclBrain = pclOrgBrain;
			  if(hLog) fclose(hLog);
			  return FALSE;
		  }
      /*
       * get mind of an instance of the model
       */
			if (pclSelectedActor->m_fn_bIsAnInstance())
			{
				pstEngineObject = M_GetEngineObject(pclSelectedActor->m_pub_fn_hGetMotorSuperObject());
				gp_stCurrentMind = p_stMind = AI_M_stGetMindOfSuperObj(pclSelectedActor->m_pub_fn_hGetMotorSuperObject());
			}
			if (pclSelectedActor->m_fn_bIsAModel())
			{
				CPA_List<CPA_BaseObject> clInstancesList;
				g_pclAIInterface->GetMainWorld()->fn_lFindObjects(&clInstancesList, "", C_szActorInstanceTypeName, pclSelectedActor);
				if(!clInstancesList.IsEmpty())
				{
					CPA_Actor						*pclInstance=(CPA_Actor *)(clInstancesList.GetHead());
					pstEngineObject=(tdstEngineObject *)pclInstance->GetStruct();
					MS_tdxHandleToBrain	hBrain=pstEngineObject->h_Brain;
					
					if(hBrain!=NULL)
						gp_stCurrentMind = p_stMind = M_pstGetMindOfBrain(hBrain);
				}
			}
			
			if (p_stMind == NULL) 
			{
				goto nextpos;
			}

      /*
       * restore old reftree
       */
      if ( p_stValue ) {
        p_stAIModel=AI_M_p_stGetAIModel(p_stMind);
        fn_vSetLinkTableForCRR ( p_stValue, (unsigned long)p_stAIModel ) ;
        p_stAIModel->CFast_lFunction = ulCFastFunction ;
        p_stAIModel->CFast_bIsC      = (unsigned char) ulCFastIsC ;
      }
      else {
        ::MessageBox (NULL,  "oups !! bad key", "edirfrm.cpp", MB_ICONSTOP) ;
      }

			/*** Name of file ***/
			CString					csFamilyName=m_fn_pclGetModel()->m_pub_fn_pclGetFamily()->GetName();
			CString					csModelName=m_fn_pclGetModel()->GetName();
			CString					csPathName=CString(fn_szGetFamiliesDataPath())+"\\"+csFamilyName+"\\"+csModelName+"\\";
			CString					csEngineSectionName;
			csEngineSectionName = csPathName + csModelName + g_c_csAIRulFileExtension;
			
			msg = "Convert IA to C for "+csModelName;
			fn_vDisplayInfoInStatusBar(msg,C_STATUS_NORMAL);



			p_oReflex = &(m_pclBrain->m_clListOfReflexBehaviours) ;
			p_oComport = &(m_pclBrain->m_clListOfIntelligenceBehaviours) ;			
			p_oSubroutines = &(m_pclBrain->m_clListOfSubrs) ;			
			/*** 1 *** Generate CRR file */
			
			if(CFast_GenerateCRR(m_pclBrain, (char *) (LPCSTR) csEngineSectionName) == FALSE)
			{
				fn_vDisplayInfoInStatusBar("ERROR!",C_STATUS_NORMAL);
				m_pclBrain = pclOrgBrain;
				if(hLog) fclose(hLog);
				return FALSE;
			}


			CFast_ThirdPassInitMacro ( p_stMind ) ;
			CFast_ThirdPassInitSubr ( p_stMind ) ;
			if ( CFast_ThirdPassInit ( m_pclBrain, (char *) (LPCSTR) csEngineSectionName, (char *) (LPCSTR)csModelName, 
        (char *) (LPCSTR)csFamilyName ) == FALSE ) {
				fn_vDisplayInfoInStatusBar("Error in cfast initialisation !",C_STATUS_NORMAL);
				m_pclBrain = pclOrgBrain;
				if(hLog) fclose(hLog);
				return FALSE;
      }
			
			
	#if defined (CFAST_DEBUG_FIRST_PASS)
			CFast_FirstPassOpening() ;
	#endif //defined (CFAST_DEBUG_FIRST_PASS)
			
			/* 
			* subroutine
			*/
			pos = p_oSubroutines->GetHeadPosition () ;
			ulCount = 0 ;
			while (pos)
			{
				p_oBehaviour = p_oSubroutines->GetNext (pos) ;
				tdstMacro *p_stMyMacro = M_GetMacroN(AI_M_p_stGetListOfMacroAIModel(p_stMind->p_stAIModel), ulCount );
				p_stMyFastTree = CFast_FirstPassInitSubr(p_stMyMacro);
				CFast_FirstPassFillTreeSubr ( p_stMyFastTree, p_stMyMacro );
				/*** 2 *** */
				CFast_fn_vPassTwo(p_stMyFastTree, pstEngineObject, p_stMyFastTree->uwNbNode);
				
				/*** 3 *** */
				CFast_ThirdPassAddSubroutine ( m_pclBrain, p_stMyFastTree, p_stMyMacro, ulCount) ;
				/*** 4 *** */     
				CFast_FirstPassDesinit();
				ulCount ++ ;
			}
			/* 
			* reflex 
			*/
			pos = p_oReflex->GetHeadPosition () ;
			ulCount = 0 ;
			while (pos)
			{
				p_oBehaviour = p_oReflex->GetNext (pos) ;
				
				p_stMyComport = M_GetComportN(AI_M_p_stGetReflex(p_stMind), ulCount );
				p_stMyFastTree = CFast_FirstPassInitComport(p_stMyComport);
				CFast_FirstPassFillTreeComport ( p_stMyFastTree, p_stMyComport );
				/*** 2 *** */
				CFast_fn_vPassTwo(p_stMyFastTree, pstEngineObject, p_stMyFastTree->uwNbNode);
				
				/*** 3 *** */
				CFast_ThirdPassAddRfx ( m_pclBrain, p_stMyFastTree, ulCount) ;
				/*** 4 *** */     
				CFast_FirstPassDesinit();
				ulCount ++ ;
			}
			/*
			* comportement
			*/
			pos = p_oComport->GetHeadPosition () ;
			ulCount = 0 ;
			while (pos)
			{
				p_oBehaviour = p_oComport->GetNext (pos) ;
				
				p_stMyComport = M_GetComportN(AI_M_p_stGetIntelligence(p_stMind), ulCount );
				p_stMyFastTree = CFast_FirstPassInitComport(p_stMyComport);
				CFast_FirstPassFillTreeComport ( p_stMyFastTree, p_stMyComport );
				
				/*** 2 *** */
				CFast_fn_vPassTwo(p_stMyFastTree,pstEngineObject , p_stMyFastTree->uwNbNode);
				
				/*** 3 *** */
				CFast_ThirdPassAddCmp ( m_pclBrain, p_stMyFastTree, ulCount) ;
				/*** 4 *** */
				CFast_FirstPassDesinit();
				ulCount ++ ;
			}
			CFast_ThirdPassFinish (m_pclBrain) ;
			
#if defined (CFAST_DEBUG_FIRST_PASS)
			// #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# MON AMI CB : C'EST Là QUE TU RéCUPèRES LE "g_lNbTotalDeNoeud" ! OK ? #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
			lCFast_FirstPassClosing(); 
			lSizeTree += (g_lNbTotalDeNoeud * 8);
#endif //defined (CFAST_DEBUG_FIRST_PASS)

			//
			// Sauvegarde de cfastf.cxx
			//
			{        
				if(!(access("x:/cpa/tempgrp/ai/aibase/cfastf.cxx", 0)))
					chmod("x:/cpa/tempgrp/ai/aibase/cfastf.cxx", _S_IREAD|_S_IWRITE);
				FILE *hFile = fopen("x:/cpa/tempgrp/ai/aibase/cfastf.cxx", "rb");
				
				if(!(access("x:/cpa/tempgrp/ai/aibase/cfastf.$$$", 0)))
					chmod("x:/cpa/tempgrp/ai/aibase/cfastf.$$$", _S_IREAD|_S_IWRITE);
				FILE *hNewFile = fopen("x:/cpa/tempgrp/ai/aibase/cfastf.$$$", "wb");
				
				if(hFile && hNewFile)
				{
					char  szFileName[15] ;
					char	szTemp[512];
					char	szModel[512];
					
					fgets(szTemp,512,hFile);			// Comment
					fputs(szTemp, hNewFile);
					fgets(szTemp,512,hFile);			// #ifdef
					fputs(szTemp, hNewFile);
					
					fgets(szTemp,512,hFile);
					while((szTemp[0] == '/') && (szTemp[1] == '*') && (szTemp[2] != '$'))
					{
						fputs(szTemp, hNewFile); /* comment : model name*/
						
						/* Get name of model */
						strcpy(szModel, szTemp + 2);
						szModel[strlen(szModel) - 3] = 0;
						if(!strcmpi(csModelName, szModel)) {
							/* the current model is already there */
							ulCFastFunction = p_stAIModel->CFast_lFunction  ;
							while(!feof(hFile)) {
								if ( fgets(szTemp,512,hFile) != NULL )
									fputs(szTemp, hNewFile);
							}
							goto endcfastf ;
						}
						
						fgets(szTemp,512,hFile); 
						fputs(szTemp, hNewFile); /* include */
						
						fgets(szTemp,512,hFile);
					}
					fprintf(hNewFile, "/*%s*/\n", csModelName);
					CFast_vMakeFileNameFromModel ( szFileName, (char *)(LPCTSTR)csModelName ) ;
					fprintf(hNewFile, "#include \"%s%s.cxx\"\n", CFast_szCFastPath, szFileName);

					fputs(szTemp, hNewFile);	/*$*/
					
					fgets(szTemp,512,hFile); /* CFast_tdst_ArrayFunctions CFast_gast_ArrayFunctions[] = */
					fputs(szTemp, hNewFile);
					fgets(szTemp,512,hFile); /* { */
					fputs(szTemp, hNewFile);
					fgets(szTemp,512,hFile); /* CFast_M_MakeRef(NULL, NULL, 0, NULL), */
					fputs(szTemp, hNewFile);
					fgets(szTemp,512,hFile); /* #ifdef */
					fputs(szTemp, hNewFile);
					
					/* just copy until #endif was found */
//CB				ulCFastFunction = 1 ;
					ulCFastFunction = 0 ;
					fgets ( szTemp, 512, hFile ) ;
					while ( strncmp (szTemp, "#endif", 6 ) ) {
						ulCFastFunction++ ;
						fputs (szTemp, hNewFile) ;
						fgets ( szTemp, 512, hFile ) ;
					}
					/*
					while ( (c=fgetc(hFile)) != '}' ) {
					if ( c == '\n' )
					ulCFastFunction++ ;
					fputc ( c, hNewFile ) ;
					}
					*/
					fprintf(hNewFile, "  CFast_M_MakeRef(\"CFast_%s_Main\", CFast_%s_Main, (long)CFast_Dummy_%s, NULL),\n", csModelName, csModelName, csModelName, csModelName);
					fprintf(hNewFile, "#endif /* U64_IA_EN_C */\n" ) ;
					fprintf(hNewFile, "CFast_M_MakeRef(NULL, NULL, 0, NULL)\n" ) ;
					fprintf(hNewFile, "};\n" ) ;
					
endcfastf:
					fclose(hFile);
					fclose(hNewFile);
					unlink("x:/cpa/tempgrp/ai/aibase/cfastf.cxx");
					rename("x:/cpa/tempgrp/ai/aibase/cfastf.$$$","x:/cpa/tempgrp/ai/aibase/cfastf.cxx");
				}
				else
				{
					fn_vDisplayInfoInStatusBar("cfastf.cxx not generated",C_STATUS_NORMAL);
					m_pclBrain = pclOrgBrain;
					if(hFile) fclose(hFile);
					if(hNewFile) fclose(hNewFile);
					if(hLog) fclose(hLog);
					return FALSE;
				}
			}
			// Sauvegarde du .AI
			if(ulCFastFunction){
/*
				char	szTemp[512];
				sprintf(szTemp, "x:/cpa/exe/main/gamedata/world/levels/_common/families/%s/%s/%s.ai", csFamilyName, csModelName, csModelName);
				if(!(access(szTemp, 0)))
					chmod(szTemp, _S_IREAD|_S_IWRITE);
				FILE *hFile = fopen(szTemp, "wt");
        //ulCFastFunction = 0 ;
				if(hFile)
				{
					fprintf(hFile, "{CreateAIModel:\n");
					fprintf(hFile, "    CFast_IsC(1)\n");
					fprintf(hFile, "    CFast_FunctionIndex(%d)\n", ulCFastFunction);	
					fprintf(hFile, "    CreateVariableDeclarationAIModel(\"%s\\%s\\%s.dec\")\n",csFamilyName,csModelName,csModelName);
					fprintf(hFile, "    CreateIntellAIModel(\"%s\\%s\\%s.rul\")\n",csFamilyName,csModelName,csModelName);
					fprintf(hFile, "    CreateReflexAIModel(\"%s\\%s\\%s.rfx\")\n",csFamilyName,csModelName,csModelName);
					fprintf(hFile, "    CreateRefAIModel(\"%s\\%s\\%s.crr\")\n",csFamilyName,csModelName,csModelName);
          fprintf(hFile, "    CreateRefTree(\"%s\\%s\\%s.nod\")\n",csFamilyName,csModelName,csModelName);
					fprintf(hFile, "}\n");
					fclose(hFile);
				}
*/
        ulOldCFastFunction = p_stMind->p_stAIModel->CFast_lFunction ;
        ulOldCFastIsC = p_stMind->p_stAIModel->CFast_bIsC ;
        /*
         * bIsC = 1 : AI in C but interperted tree still loaded (for bugging)
         * bIsC = 2 : AI in C and interpreted tree not loaded
         */
        p_stMind->p_stAIModel->CFast_bIsC = 1 ; 
        //p_stMind->p_stAIModel->CFast_bIsC = 2 ; 
        p_stMind->p_stAIModel->CFast_lFunction = ulCFastFunction ;

        m_pclBrain->m_fn_vNotify() ;
        pclSelectedActor->fn_vNotifySave() ;
        pclSelectedActor->mfn_vUpdateAllInstancesForFastC() ;


/*
        p_stMind->p_stAIModel->CFast_bIsC =  ulOldCFastIsC; 
        p_stMind->p_stAIModel->CFast_lFunction = ulOldCFastFunction ;
*/
      }
		}
		else
		{
			fn_vDisplayInfoInStatusBar("ERROR!",C_STATUS_NORMAL);
			m_pclBrain = pclOrgBrain;
			if(hLog) fclose(hLog);
			return FALSE;
		}


		if(bProcessAll == FALSE)
			break;

nextpos:
		pclDocument->m_clModelsList.GetNext(pos);
	}
  
  //Shows current actor
  CPA_DLLBase	*pclActorDLL=(CPA_DLLBase*)(g_pclAIInterface->GetMainWorld()->GetObjectDLLWithName(C_szDLLActorName));
  pclSelectedActor=(CPA_Actor *)pclActorDLL->OnQueryAction(g_pclAIInterface,C_uiActor_GetSelectedActor,0);
  pclActorDLL->OnQueryAction(g_pclAIInterface,C_uiActor_DisplayActor,(long)NULL);
  pclActorDLL->OnQueryAction(g_pclAIInterface,C_uiActor_DisplayActor,(long)pclSelectedActor);
  

	if(hLog)
	{
		fprintf(hLog, "%d", lSizeTree);
		fclose(hLog);
	}

	//msg="OK (Good Work !!)";
	msg="OK (ça vaaaaa 3lik !!)";	
	fn_vDisplayInfoInStatusBar(msg,C_STATUS_NORMAL);
	m_pclBrain = pclOrgBrain;
	return TRUE;
}

//End Shaitan FastC }

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vSetOrRemoveOneBreakPoint(long lIndex,long lLineIndex)
{
	if(m_pclBrain!=NULL)
	{
		CPA_EdIR_Behaviour	*pclBehaviour=m_fn_pclGetDiagrammeView()->m_fn_pclGetActiveBehaviour();

		if((pclBehaviour!=NULL) && (pclBehaviour->m_bDeclaration==FALSE))
		{
			CPA_EdIR_MainBehaviour	*pclMainBehaviour=pclBehaviour->m_fn_pclGetMainBehaviour();

			m_pclBrain->m_fn_vSetOrRemoveOneBreakPoint(lIndex,pclMainBehaviour->GetName());

			m_fn_pclGetEdRulesView()->m_fn_vSetBreakPointList(m_pclBrain->m_fn_pclGetBreakPointList());
//Stefan Dumitrean 11-06-98 ( new scroll )
			CRect clRect;
			m_fn_pclGetEdRulesView()->GetClientRect( &clRect );
			CRect clRectI( 0, 0, 12, clRect.Height() );
			m_fn_pclGetEdRulesView()->InvalidateRect( &clRectI );
//End Stefan Dumitrean 11-06-98 ( new scroll )
		}
	}
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vPrint()
{
	m_fn_pclGetDiagrammeView()->m_fn_vPrint();
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vShowConstant()
{
	CPA_EdIR_ConstantDialog	clConstantDlg(&m_clConstantList);

	clConstantDlg.DoModal();
}

/**********************************************************************************/
CPA_Actor *CPA_EdIR_Frame::m_fn_pclGetModel()
{
	if(m_pclBrain)
		return m_pclBrain->m_fn_pclGetModel();
	else
		return NULL;
}

/**********************************************************************************/
CPA_EdIR_MainBehaviourList *CPA_EdIR_Frame::m_fn_pclGetIntelligenceBehaviours()
{
	if(m_pclBrain)
		return &(m_pclBrain->m_clListOfIntelligenceBehaviours);
	else
		return NULL;
}

/**********************************************************************************/
CPA_EdIR_MainBehaviourList *CPA_EdIR_Frame::m_fn_pclGetReflexBehaviours()
{
	if(m_pclBrain)
		return &(m_pclBrain->m_clListOfReflexBehaviours);
	else
		return NULL;
}

/**********************************************************************************/
CPA_EdIR_MainBehaviourList *CPA_EdIR_Frame::m_fn_pclGetDeclarations()
{
	if(m_pclBrain)
		return &(m_pclBrain->m_clListOfDeclarations);
	else
		return NULL;
}

// BEGIN CPA2 Cristi Petrescu 98-03-
/**********************************************************************************/
CPA_EdIR_MainBehaviourList *CPA_EdIR_Frame::m_fn_pclGetMacros()
{
	if(m_pclBrain)
		return &(m_pclBrain->m_clListOfMacros);
	else
		return NULL;
}
// END CPA2 Cristi Petrescu 98-03-

// BEGIN ROMTEAM CPA2 Cristi Petrescu 98-04-
/**********************************************************************************/
CPA_EdIR_MainBehaviourList *CPA_EdIR_Frame::m_fn_pclGetSubrs()
{
	if(m_pclBrain)
		return &(m_pclBrain->m_clListOfSubrs);
	else
		return NULL;
}
// END ROMTEAM CPA2 Cristi Petrescu 98-04-

/**********************************************************************************/
void *CPA_EdIR_Frame::m_fn_pvGetStateHandle(CString csActionName)
{
	if(m_pclBrain)
		return m_pclBrain->m_fn_pvGetStateHandle(csActionName);
	else
		return NULL;
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vGetActionList(CStringList *cslActionList)
{
	if(m_pclBrain)
		m_pclBrain->m_fn_vGetActionList(cslActionList);
}

/**********************************************************************************/
void CPA_EdIR_Frame::OnActivate(UINT nState,CWnd* pWndOther,BOOL bMinimized) 
{
	SetActiveView(m_fn_pclGetEdRulesView());

	FRMBase::OnActivate(nState,pWndOther,bMinimized);
}

/**********************************************************************************/
void CPA_EdIR_Frame::OnSetFocus(CWnd* pOldWnd) 
{
	SetActiveView(m_fn_pclGetEdRulesView());

	FRMBase::OnSetFocus(pOldWnd);
}

/**********************************************************************************/
void CPA_EdIR_Frame::m_fn_vFillConstantList()
{
	SCR_tdst_DyAr_Description	*pstArray;
	SCR_tdst_Link_Value				*pstLinkValue;
	unsigned long							lPos=0;

	pstArray=&(SCR_M_st_Link_GetDynamicArray(AI_fn_p_stGetDsgVarLinkTable()));

	SCR_M_DyAr_GetNextElement(SCR_tdst_Link_Value,lPos,pstLinkValue,(*pstArray));
	while(pstLinkValue!=NULL)
	{
		unsigned long	ulValue=SCR_M_ul_Link_GetValue(pstLinkValue);
		unsigned long	ulType=SCR_M_ul_Link_GetAdditionalLong(pstLinkValue,2);
		CString				csType;
		CString				csName;
		CString				csValue;

		if(ulType==E_vt_Integer)
		{
			csType=g_c_csInteger;
			csValue.Format("%ld",ulValue);
		}
		else
		if(ulType==E_vt_Float)
		{
			csType=g_c_csDecimal;
			csValue.Format("%f",MTH_M_xRealToFloat(*(MTH_tdxReal *)(&ulValue)));
		}
		else
		{
			AfxMessageBox("CPA_EdIR_Frame::m_fn_vFillConstantList : Unknown constant type !!");

			ASSERT(FALSE);
		}

		csName=SCR_M_p_sz_Link_GetKey(pstLinkValue);
		long	lIndex=csName.ReverseFind(':');
		if(lIndex!=-1)
		{
			csName=csName.Right(csName.GetLength()-lIndex-1);
		}
		else
		{
			AfxMessageBox("CPA_EdIR_Frame::m_fn_vFillConstantList : Can't get the constant name ("+csName+")!!");

			ASSERT(FALSE);
		}

		m_clConstantList.m_fn_vAdd(csType,csName,csValue);

		lPos++;
		SCR_M_DyAr_GetNextElement(SCR_tdst_Link_Value,lPos,pstLinkValue,(*pstArray));
	}
}
#endif //D_ED_IR_ACTIVE
