/*=========================================================================
* CHLLoad.c : Loading CHL Files
* 
* Version              1.0
* Creation date        29/05/97
* Revision date
*
* That file needs to be compatible for all platforms.
*
* (c) Ubi Studios 1997
*=======================================================================*/
#if defined (WIN32)
#include <stdio.h>
#endif /* WIN32 */
 
/* to be Friend*/
#define D_State_Define
 
#include "ToolsCPA.h"
 
/*#include "Options/Options.h"*/
#include "Macros.h"
 
#include "Actions/AllActs.h"
 
#include "Structur/3DOSLkTb.h"
#include "Structur/Objects.h"
#include "Structur/ErrGame.h"
#include "Structur/GameScpt.h"
#include "Structur/MemGame.h"
#include "Structur/StdObjSt.h"
#include "Structur/EngMode.h"
 
 
#include "Basic.h"
#include "Family.h"
#include "ObjType.h"
#include "ZeMem.h"
#include "CHLLoad.h"
 
 
/* global for CHL Link Table*/
SCR_tdst_Link_Table CHL_g_stLinkTable;
 
 /*-----------------------------------------------------------------------------
 *  Description : initialize and close link table for CHL
 *-----------------------------------------------------------------------------
 *-----------------------------------------------------------------------------
 *  Creation date : 29/05/97            Author : Sebastien DAVID (Gïzmo)
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author : 
 *  Modifications : 
 *---------------------------------------------------------------------------*/
SCR_tdst_Link_Table *CHL_fn_p_stGetLinkTable(void)
{
 return(&CHL_g_stLinkTable);
}
 
void CHL_fn_vInitLinkTable(void)
{
	SCR_fn_v_Link_InitTable(&CHL_g_stLinkTable);
}
 
void CHL_fn_vCloseLinkTable(void)
{
	SCR_fn_v_Link_CloseTable(&CHL_g_stLinkTable);
}
 
/*-----------------------------------------------------------------------------
 *  Description : Used to register all script callback functions
 *-----------------------------------------------------------------------------
 *  Creation date : 29/05/97            Author : Sebastien DAVID (Gïzmo)
 *-----------------------------------------------------------------------------*/
void CHL_fn_vRegisterAllScriptSections(void)
{
	SCR_fn_v_RdL0_RegisterCallback(C_Section_CHLGeneral, CHL_fn_eScriptCallBackGeneral,SCR_CRC_c_RdL0_ForSection);
}
 
/*-----------------------------------------------------------------------------
 *  Description :   call-back for general section of CHL script file
 *-----------------------------------------------------------------------------
 *-----------------------------------------------------------------------------
 *  Creation date : 29/05/97            Author : Sebastien DAVID (Gïzmo)
 *-----------------------------------------------------------------------------*/
SCR_tde_Anl_ReturnValue CHL_fn_eScriptCallBackGeneral(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;
	char sz_ForLinkTable[MAX_PATH];
	long		lChannelNumber;
	struct	tdstFamilyList_ *p_stFamily;
	
	if ( M_IsTitle )	
	{
		SCR_M_RdL0_GetContextLong(C_ThisContext,0,struct tdstFamilyList_ *,p_stFamily);
		p_stFamily->ulNumberOfChannels = fn_lAToI(_ap_szParams[0]);
 
		SCR_M_RdL0_SetSectionLong(C_ThisSection,0,fn_lAToI(_p_szName));
		SCR_M_RdL0_SetContextLong(C_ThisContext,1,0); /*counter*/
	}
	else if ( M_IsEntry )
	{
		SCR_M_RdL0_GetContextLong(C_ThisContext,0,struct tdstFamilyList_ *,p_stFamily);
		
		
  strcpy(sz_ForLinkTable,fn_szFindFamilyTypeNameOfFamilyType(p_stFamily->otObjectFamilyType));
		strcat(sz_ForLinkTable,"-");
		strcat(sz_ForLinkTable,_ap_szParams[0]);
		
		SCR_M_RdL0_GetContextLong(C_ThisContext,1,long,lChannelNumber);
		SCR_fnp_st_Link_SetValue(&CHL_g_stLinkTable,sz_ForLinkTable,lChannelNumber);
		lChannelNumber++;
		SCR_M_RdL0_SetContextLong(C_ThisContext,1,lChannelNumber); /*counter*/
	}
	
	return ( eReturnValue );
}
 
 
