/*=============================================================================
 *
 *  Filename:			CPAAnim.cpp
 *  Version:            1.0
 *  Date:				30/12/96
 *  Author:             Marc Trabucato & Vincent Lhullier
 *
 *  Description:		implementation of CPA_Animation class
 *
 *===========================================================================*/

#ifdef ACTIVE_EDITOR

#include "stdafx.h"

#include "ACP_Base.h"
#include "ITF.h"
#include "DPT.h"

#define D_State_Define
#define D_ObjsTbls_Define
#define D_ZdxStuff_StructureDefine
//#include "DNM.h"
#include "incGAM.h"
#undef D_ZdxStuff_StructureDefine
#undef D_ObjsTbls_Define
#undef D_State_Define

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

/*
 *=============================================================================
 * class CPA_Animation
 *=============================================================================
 */
#define M_Char(string)  ( (char*)(LPCTSTR)(string) )

/*
 *-----------------------------------------------------------------------------
 *  Description : constructor
 *-----------------------------------------------------------------------------
 */
CPA_Animation::CPA_Animation( CPA_EditorBase *p_oEditor, CPA_BaseObject *_p_oOwnerFamily, char *_szName )
              :CPA_BaseObject( p_oEditor, C_szAnimationTypeName, _p_oOwnerFamily, FALSE )
{
    // data
    m_p_stAnim3d = NULL;
    // name
    if ( fn_eRename( _szName ) != E_mc_None )
    {
        SetDefaultUniqueName();
    }
}

void CPA_Animation::SetData(struct tdstAnim3d_ *_p_stAnim)
{
    if( _p_stAnim != m_p_stAnim3d )
    {
        fn_vUpdateData( (void*) _p_stAnim );
        m_p_stAnim3d = _p_stAnim;
    }
}

//ANNECY CT 20/02/98{
// Modif 07/09/98 : Load Anim using game function - Carlos Torres
void CPA_Animation::mfn_vLoad()
{
    char szAnimName[MAX_PATH];

	sprintf(szAnimName,"%s\\%s",GetOwner()->fn_p_szGetName(),fn_p_szGetName());

	if( ! fn_bIsAvailable() )
    {
        struct tdstAnim3d_ * p_stAnim;

		p_stAnim = fn_p_stLoadAnimationFile(szAnimName,(struct tdstFamilyList_ *) GetOwner()->GetData());

		if (p_stAnim) {
            SetData(p_stAnim);
            SetAvailable(TRUE);
		}
	}

	/*else {
		// del section in script
		SCR_fn_v_RdL0_DeleteOpenSection(p_cShortName, SCR_CDR_c_RdL0_Contains);
		SCR_fn_v_RdL0_DeleteOpenFile(p_cShortName, SCR_CDR_c_RdL0_Contains);
		// free sub level in anim structure
		fn_vFreeSubStructAnim(m_p_stAnim3d);

        // load animations
        SCR_M_RdL0_SetContextLong(C_ChildContext, 1, (long)GetOwner() -> GetData() );
        SCR_fnp_st_RdL0_AnalyseSection(p_cShortName, SCR_CDF_uw_Anl_Normal);
        // search on linktable
        SCR_tdst_Link_Table *p_stLK = fnp_stGetAnimationLinkTable();
        SCR_tdst_Link_Value *p_xLVa = SCR_fnp_st_Link_SearchKey( p_stLK, szAnimName );

		// copy anim name
		strcpy(((struct tdstAnim3d_ *)SCR_M_ul_Link_GetValue(p_xLVa))->szAnimName,
			m_p_stAnim3d->szAnimName);
		// copy first level anim structure
        *m_p_stAnim3d = *(struct tdstAnim3d_ *)SCR_M_ul_Link_GetValue(p_xLVa);
		// free first level anim structure
        fn_vFreeJustStructAnim((struct tdstAnim3d_ *)SCR_M_ul_Link_GetValue(p_xLVa));

		// replace pointer in link table
		SCR_fnp_st_Link_SetValue(p_stLK,szAnimName,(unsigned long)m_p_stAnim3d);
	}*/
}
//ENDANNECY CT}

#endif //ACTIVE_EDITOR