#ifdef ACTIVE_EDITOR

//MFC
#include "stdafx.h"

//ACP
#include "ACP_Base.h"
#include "ITF.h"
#include "x:\cpa\main\inc\_editid.h"
#include "DPT.h"

#include "TAC.h"
#include "TFa.h"
#include "OAC.h"
#include "ACInterf.hpp"

#ifdef CPA_USES_LDT

#include "ldt.h"

#define lTagInitial               'tinI'
#define lTagAddState              'SddA'
#define lTagAddDefaultState       'DddA'
#define lTagAddTransitionalState  'TddA'


/*****************************************************************
Function name   : CPA_Action::fn_iCreateACEFile
Description     : 
Author          : Ovidiu Scripa (oscripa@ubisoft.ro) - ROMTEAM
Creation Date   : 15-Oct-98
Modified        : 
Return type     : int 
Argument        : LDT_tdst_Link *pLink
*****************************************************************/
int CPA_Action::fn_iCreateACEFile( LDT_tdst_Link *pLink )
{
  CPA_Family              *p_oFamily;

  p_oFamily = (CPA_Family * )LDT_GetTempLong( 0 );

  pLink->pObject = (void*)p_oFamily;
  return 0;
}



/*****************************************************************
Function name   : CPA_Action::fn_iCreateNewAction
Description     : 
Author          : Ovidiu Scripa (oscripa@ubisoft.ro) - ROMTEAM
Creation Date   : 15-Oct-98
Modified        : 
Return type     : int 
Argument        : LDT_tdst_Link *pLink
*****************************************************************/
int CPA_Action::fn_iCreateNewAction( LDT_tdst_Link *pLink )
{

  CPA_DLLBase             *p_oDLL;
  CPA_Family              *p_oFamily;
  CPA_Action              *p_oAction;
  CPA_Interface           *p_oInterface;
  BOOL                     bPreviousLoadingWorld;

  p_oFamily = (CPA_Family * )pLink->pParent->pObject;

  p_oDLL = p_oFamily -> GetMainWorld() -> GetToolDLLWithName( C_szDLLActionName );
  p_oInterface = p_oFamily -> GetMainWorld() -> GetInterface();
  bPreviousLoadingWorld = p_oInterface -> fn_bIsLoadingWorld();

  // create editor action
  p_oInterface -> SetLoadingWorld( TRUE );
  p_oAction = new CPA_Action ( p_oDLL, p_oFamily, LDT_szGetSectionName() );
  p_oInterface -> SetLoadingWorld( bPreviousLoadingWorld );
  p_oAction -> SetExistingSection( TRUE );
  p_oFamily -> mfn_vAddAction( p_oAction );

  pLink->pObject = (void*)p_oAction;

  return 0;
}


/*****************************************************************
Function name   : CPA_Action::fn_iLoadNewAction
Description     : 
Author          : Ovidiu Scripa (oscripa@ubisoft.ro) - ROMTEAM
Creation Date   : 15-Oct-98
Modified        : 
Return type     : int 
Argument        : LDT_tdst_Link *pLink
*****************************************************************/
int CPA_Action::fn_iLoadNewAction( LDT_tdst_Link *pLink )
{
  LDT_tdeParseResult result=ParseResult_BeginSection;
  CPA_DLLBase             *p_oDLL;
  CPA_Family              *p_oFamily;
  CPA_Action              *p_oAction;
  CPA_State				  *p_oState;
  CPA_Interface           *p_oInterface;
  BOOL                     bPreviousLoadingWorld;

  p_oFamily = (CPA_Family * )pLink->pParent->pObject;
  p_oAction = (CPA_Action * )pLink->pObject;

  p_oDLL = p_oFamily -> GetMainWorld() -> GetToolDLLWithName( C_szDLLActionName );
  p_oInterface = p_oFamily -> GetMainWorld() -> GetInterface();
  bPreviousLoadingWorld = p_oInterface -> fn_bIsLoadingWorld();

  p_oInterface -> SetLoadingWorld( TRUE );


  while( result!=ParseResult_EndSection ) 
  {
  	result=LDT_GetNextEntry();
  	switch( result )
  	{
  	  case ParseResult_Entry: /* an entry */
  	  {
  	    char *szEntry=LDT_szGetEntryName();
  	    switch (*(long*)szEntry)
  	    {

  	      case  lTagInitial : /*  */
  	      {
            // set as initial action of family
            p_oFamily -> mfn_vSetInitialAction( p_oAction );

  	      }
  	      break;
  	      case  lTagAddState : /*  */
  	      {
            // add editor state
      			p_oState = p_oAction -> mfn_p_oCreateNewState( LDT_szGetParam(1) );

  	      }
  	      break;
  	      case  lTagAddDefaultState : /*  */
  	      {
            // add default editor state
      			p_oState = p_oAction -> mfn_p_oCreateNewState( LDT_szGetParam(1) );
            p_oAction -> mfn_vSetDefaultState( p_oState, TRUE );

  	      }
  	      break;
  	      case  lTagAddTransitionalState : /*  */
  	      {
            // add editor transitional state
      			p_oState = p_oAction -> mfn_p_oCreateNewState( LDT_szGetParam(1) );
            p_oState -> mfn_vSetTransitional( TRUE, FALSE );

  	      }
  	      break;
  	    }
        p_oInterface -> SetLoadingWorld( bPreviousLoadingWorld );
  	  }
  	}
  }

  

  if( ! p_oAction -> mfn_p_oGetDefaultState () )
    p_oAction -> mfn_vSetDefaultState ( NULL, TRUE ) ;
//  CPA_Ed_1 Mihaela Tancu begin 
//	p_oAction->mfn_vSetListOfStates();  //sort the list with states at the loading
//  CPA_Ed_1 Mihaela Tancu end

  return 0;
}

#endif //CPA_USES_LDT

#endif //EDITOR_ACTIVE

