/* (c) Ubi Studios 1996*/
/* See Vincent Greco or Marc Villemain for any comment or question*/
 
 
#define HIE_FRIEND
#include "ACP_base.h"
 
 
#include "GMT.h"
#include "GEO.h"
#include "GLI.h"
#include "DPT.h"
#include "VIG.h"
#include "POS.h"
#include "MEC.h"
 
#include "PCS.h"
#include "PO.h"
#include "IPO.h"
#include "LST.h"
#include "SND.h"
#include "SCT.h"
#include "incGAM.h"
#include "SPO/HieMtStk.h"
#include "SPO/HieConst.h"
#include "SPO/HieExt.h"
#include "SPO/Specif/HieLoad.h"
#include "SPO/HieSpObj.h"
 
#include "GAM/Structur/3DOSLkTb.h" /* any other way ? perhaps...*/



// FBF N64-format pour coords, et logfile dans x:\exe\geodump.log{
#ifdef U64CONVERTETLOG
float				fScale = 32.0f;
BOOL				g_bLoadMap = FALSE;

#endif //U64CONVERTLOG
// } fin N64-format

 
 
/*ROMTEAM PLG Files Ionut Grozea 01-05-1998*/
#ifdef ACTIVE_EDITOR 
struct ISI_tdstObjectColorStruct_  m_ObjectColorStruct;
#endif
/*ENDROMTEAM PLG Files Ionut Grozea 01-05-1998*/
 
 
SCR_tdst_Link_Table gs_stSuperObjectLinkTable;
SCR_tdst_Link_Table gs_stLinkedObjectLinkTable;
 
 
SCR_tdst_Link_Table * HIE_fn_p_stGetSuperObjectLinkTable() {return &gs_stSuperObjectLinkTable;}
SCR_tdst_Link_Table * HIE_fn_p_stGetLinkedObjectLinkTable() {return &gs_stLinkedObjectLinkTable;}
 
 
/*-----------------------------------------------------------------------------
 *  Description :   function to prepare the binary save process
 *-----------------------------------------------------------------------------
 *-----------------------------------------------------------------------------
 *  Creation date : Aug 97            Author : Alain Robin
 *-----------------------------------------------------------------------------*/
/*
void HIE_fn_vPrepareSaveSuperObjectsBinaryBloc()
{
	BIN_fn_vCreateBinaryIds(HIE_fn_p_stGetSuperObjectLinkTable(),BIN_C_SPOID);
	IPO_fn_vPrepareSaveBinaryBloc();
 	PO_fn_vPrepareSaveBinaryBloc();
	SCT_fn_vPrepareSaveBinaryBloc();
	GEO_fn_vPrepareSaveGeometricObjects();
}
*/
/*-----------------------------------------------------------------------------
 *  Description :   function to write a binary PO
 *-----------------------------------------------------------------------------
 *-----------------------------------------------------------------------------
 *  Creation date : Aug 97            Author : Alain Robin
 *-----------------------------------------------------------------------------*/
/*
extern SCR_tdst_Link_Table INV_g_stInstanciatedItemLinkTable;
extern SCR_tdst_Link_Table INV_g_stInvBoxLinkTable;
extern HIE_tdxHandleToSuperObject HIE_fn_hGetSuperObjectPrevBrother(HIE_tdxHandleToSuperObject _hSprObj);
extern HIE_tdxHandleToSuperObject HIE_fn_hGetSuperObjectLastChild(HIE_tdxHandleToSuperObject _hSprObj);
extern void HIE_fn_vSetSuperObjectFirstChild(HIE_tdxHandleToSuperObject _hSprObj,HIE_tdxHandleToSuperObject _hChild);
extern void HIE_fn_vSetSuperObjectLastChild(HIE_tdxHandleToSuperObject _hSprObj,HIE_tdxHandleToSuperObject _hChild);
extern void HIE_fn_vSetSuperObjectNextBrother(HIE_tdxHandleToSuperObject _hSprObj,HIE_tdxHandleToSuperObject _hBrother);
extern void HIE_fn_vSetSuperObjectPrevBrother(HIE_tdxHandleToSuperObject _hSprObj,HIE_tdxHandleToSuperObject _hBrother);
extern void HIE_fn_vSetSuperObjectFather(HIE_tdxHandleToSuperObject _hSprObj,HIE_tdxHandleToSuperObject _hFather);
*/
 
 
/*
unsigned long SPO_fn_ulWriteBinaryBloc(unsigned long _ulStructAddress, char* _p_cDestBuffer)
{
	HIE_tdxHandleToSuperObject hSPO=(HIE_tdxHandleToSuperObject)_ulStructAddress;
	char* p_cBufferPointer=_p_cDestBuffer;
	HIE_tdeTypeOfObject lType;
 
	p_cBufferPointer=BIN_fn_p_cPutLong(p_cBufferPointer,
									(unsigned long)HIE_fn_ulGetSuperObjectType(hSPO));
 
  lType=HIE_fn_ulGetSuperObjectType(hSPO);
  lType&=0xffffff7f;
  switch(lType)
  {
 
  case C_ucSuperObject:
      p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
									(unsigned long)HIE_fn_hGetSuperObjectObject(hSPO),
									NULL);
  break;
  case C_ucPhysical:
  case C_ucGeometric:
      p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
									(unsigned long)HIE_fn_hGetSuperObjectObject(hSPO),
									GLI_p_stGetLinkTableOfGeometric());
 
  break;
  case C_ucSector:
      p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
									(unsigned long)HIE_fn_hGetSuperObjectObject(hSPO),
									SECT_fn_pGetLinkTable());
 
  break;
  case HIE_C_ulPO:
          p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
									(unsigned long)HIE_fn_hGetSuperObjectObject(hSPO),
									&PO_g_stLinkTable);
 
  break;
  case HIE_C_ulIPO_Mirror:
  case C_ucInstanciatedPhysicalObject:
        p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
						(unsigned long)HIE_fn_hGetSuperObjectObject(hSPO),
						&IPO_g_stLinkTable);
 
  break;
  default:
#ifndef U64
    _asm{int 3h}
#endif
  break;
  }
  p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
			(unsigned long)HIE_fn_hGetSuperObjectFirstChild(hSPO),
			HIE_fn_p_stGetSuperObjectLinkTable());
 
  p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
			(unsigned long)HIE_fn_hGetSuperObjectLastChild(hSPO),
			HIE_fn_p_stGetSuperObjectLinkTable());
 
 
  p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
			(unsigned long)HIE_fn_hGetSuperObjectNextBrother(hSPO),
			HIE_fn_p_stGetSuperObjectLinkTable());
  p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
			(unsigned long)HIE_fn_hGetSuperObjectPrevBrother(hSPO),
			HIE_fn_p_stGetSuperObjectLinkTable());
  p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
			(unsigned long)HIE_fn_hGetSuperObjectFather(hSPO),
			HIE_fn_p_stGetSuperObjectLinkTable());
 
 
 
  p_cBufferPointer=BIN_fn_p_cPutStruct(p_cBufferPointer,
									(char *)HIE_fn_hGetSuperObjectMatrix(hSPO),
									sizeof(POS_tdstCompletePosition));
 
  
	p_cBufferPointer=BIN_fn_p_cPutLong(p_cBufferPointer,
									(unsigned long)HIE_fn_lGetSuperObjectDrawMask(hSPO));
	//ANNECY VL SPOFLAG 22/01/98{
	p_cBufferPointer = BIN_fn_p_cPutLong(p_cBufferPointer, (unsigned long) HIE_fn_SO_ulGetFlags( hSPO ) );
	//ENDANNECY VL SPOFLAG}
  
	p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
						(unsigned long)NULL,
						GLI_p_stGetLinkTableOfGeometric()); // disabled for the moment
 
	return p_cBufferPointer-_p_cDestBuffer;
}
*/
/*
unsigned long SPO_fn_ulWriteBinaryBloc2(unsigned long _ulStructAddress, char* _p_cDestBuffer)
{
	HIE_tdxHandleToSuperObject hSPO=(HIE_tdxHandleToSuperObject)_ulStructAddress;
	char* p_cBufferPointer=_p_cDestBuffer;
	HIE_tdeTypeOfObject lType;
 
	p_cBufferPointer=BIN_fn_p_cPutLong(p_cBufferPointer,
									(unsigned long)HIE_fn_ulGetSuperObjectType(hSPO));
 
	lType=HIE_fn_ulGetSuperObjectType(hSPO);
	lType&=0xffffff7f;
	switch(lType)
	{
 
		case C_ucSuperObject:
			p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
													(unsigned long)HIE_fn_hGetSuperObjectObject(hSPO),
													NULL);
		break;
		case C_ucPhysical:
		case C_ucGeometric:
			p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
													(unsigned long)HIE_fn_hGetSuperObjectObject(hSPO),
													GLI_p_stGetLinkTableOfGeometric());
 
		break;
		case C_ucSector:
			p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
													(unsigned long)HIE_fn_hGetSuperObjectObject(hSPO),
													SECT_fn_pGetLinkTable());
 
		break;
		case HIE_C_ulPO:
			p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
													(unsigned long)HIE_fn_hGetSuperObjectObject(hSPO),
													&PO_g_stLinkTable);
 
		break;
		case HIE_C_ulIPO_Mirror:
		case C_ucInstanciatedPhysicalObject:
			p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
													(unsigned long)HIE_fn_hGetSuperObjectObject(hSPO),
													&IPO_g_stLinkTable);
 
		break;
		case C_ucCharacter:
			p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
													(unsigned long)HIE_fn_hGetSuperObjectObject(hSPO),
													&g_st3DOSLinkTable.stCharacter);
 
		break;
		default:
#ifndef U64
			_asm{int 3h} // use a good error later
			p_cBufferPointer=BIN_fn_p_cPutLong(p_cBufferPointer,0L); // if we want to continue...
#endif
		break;
	}
 
	// parent list
	p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
											(unsigned long)HIE_fn_hGetSuperObjectFirstChild(hSPO),
											HIE_fn_p_stGetSuperObjectLinkTable());
	p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
											(unsigned long)HIE_fn_hGetSuperObjectLastChild(hSPO),
											HIE_fn_p_stGetSuperObjectLinkTable());
	p_cBufferPointer=BIN_fn_p_cPutLong(p_cBufferPointer,hSPO->lNumberOfElementsDyn);
 
	// child list
	p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
											(unsigned long)HIE_fn_hGetSuperObjectNextBrother(hSPO),
											HIE_fn_p_stGetSuperObjectLinkTable());
	p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
											(unsigned long)HIE_fn_hGetSuperObjectPrevBrother(hSPO),
											HIE_fn_p_stGetSuperObjectLinkTable());
	p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
											(unsigned long)HIE_fn_hGetSuperObjectFather(hSPO),
											HIE_fn_p_stGetSuperObjectLinkTable());
 
	// position pointers
	p_cBufferPointer=BIN_fn_p_cPutLong(p_cBufferPointer,0);
	p_cBufferPointer=BIN_fn_p_cPutLong(p_cBufferPointer,0);
 
	// last computed frame  
	p_cBufferPointer=BIN_fn_p_cPutLong(p_cBufferPointer,hSPO->lLastComputeFrame);
 
	// draw mask
	p_cBufferPointer=BIN_fn_p_cPutLong(p_cBufferPointer,
									(unsigned long)HIE_fn_lGetSuperObjectDrawMask(hSPO));
 
	//ANNECY VL SPOFLAG 05/12/97{
	// SPO flags
	p_cBufferPointer = BIN_fn_p_cPutLong(p_cBufferPointer, (unsigned long) HIE_fn_SO_ulGetFlags( hSPO ) );
	//ENDANNECY VL SPOFLAG}
 
  
	// light
	p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
						(unsigned long)HIE_fn_hGetSuperObjectBoundingVolume(hSPO),
						LGT_fn_p_stGetLightLinkTable());
 
	// bounding volume
	p_cBufferPointer=BIN_fn_p_cPutPointer(p_cBufferPointer,
						(unsigned long)NULL,
						GLI_p_stGetLinkTableOfGeometric());
 
	// local position
	p_cBufferPointer=BIN_fn_p_cPutStruct(p_cBufferPointer,
									(char *)HIE_fn_hGetSuperObjectMatrix(hSPO),
									sizeof(POS_tdstCompletePosition));
 
	return p_cBufferPointer-_p_cDestBuffer;
}
*/
/*-----------------------------------------------------------------------------
 *  Description :   function to write all the binary SPO
 *-----------------------------------------------------------------------------
 *-----------------------------------------------------------------------------
 *  Creation date : Aug 97            Author : Alain Robin
 *-----------------------------------------------------------------------------*/
/*
void SPO_fn_vWriteAllSPOBinaryBlocs(char* _szBinaryFileName)
{
	HIE_fn_vPrepareSaveSuperObjectsBinaryBloc();
	BIN_fn_vPutBinaryDataIntoFileFromLinkTable(_szBinaryFileName,HIE_fn_p_stGetSuperObjectLinkTable(),
													sizeof(struct HIE_tdstSuperObject_)+sizeof(POS_tdstCompletePosition),SPO_fn_ulWriteBinaryBloc);
}
*/
/*-----------------------------------------------------------------------------
 *  Description :   function to write all the binary SPO
 *-----------------------------------------------------------------------------
 *-----------------------------------------------------------------------------
 *  Creation date : Sep 97            Author : Alain Robin
 *-----------------------------------------------------------------------------*/
/*
void SPO_fn_vWriteAllSPOBinaryBlocs2(char* _szBinaryFileName)
{
	HIE_fn_vPrepareSaveSuperObjectsBinaryBloc();
	BIN_fn_vPutBinaryDataIntoFileFromLinkTable(_szBinaryFileName,HIE_fn_p_stGetSuperObjectLinkTable(),
													sizeof(struct HIE_tdstSuperObject_)+sizeof(POS_tdstCompletePosition),SPO_fn_ulWriteBinaryBloc2);
}
*/
/*-----------------------------------------------------------------------------
 *  Description :   function to read a binary SPO
 *-----------------------------------------------------------------------------
 *-----------------------------------------------------------------------------
 *  Creation date : Aug 97            Author : Alain Robin
 *-----------------------------------------------------------------------------*/
/*
unsigned long SPO_fn_ulReadBinaryBloc(char* _p_cLoadedBuffer,unsigned long _ulLoadedBufferSize)
{
	HIE_tdxHandleToSuperObject hSPO;
	char* p_cBufferPointer=_p_cLoadedBuffer;
  long lType, lDrawMask; 
  unsigned long  lId;
  POS_tdxHandleToPosition hMatrix;
  HIE_tduLinkedObject hLink;
  ACP_tdxHandleOfObject hBdVol;
// ANNECY AV {
  MTH3D_tdstMatrix stIdentityMatrix;
// END ANNECY AV }
 
	hSPO = HIE_fn_hCreateSuperObject();
 
	p_cBufferPointer=BIN_fn_p_cGetLong(p_cBufferPointer,&lType);
	lType&=0xffffff7f;
  switch(lType)
  {
 
  case C_ucSuperObject:
      p_cBufferPointer=BIN_fn_p_cGetPointer(p_cBufferPointer, (unsigned long *)&hLink, NULL);
  break;
  case C_ucPhysical:
  case C_ucGeometric:
      p_cBufferPointer=BIN_fn_p_cGetPointer(p_cBufferPointer, (unsigned long *)&hLink,
									GLI_p_stGetLinkTableOfGeometric());
 
  break;
  case C_ucSector:
      p_cBufferPointer=BIN_fn_p_cGetPointer(p_cBufferPointer, (unsigned long *)&hLink,
									SECT_fn_pGetLinkTable());
 
  break;
  case HIE_C_ulPO:
          p_cBufferPointer=BIN_fn_p_cGetPointer(p_cBufferPointer, (unsigned long *)&hLink,
									&PO_g_stLinkTable);
 
  break;
  case C_ucIpoMirror:
  case C_ucInstanciatedPhysicalObject:
        p_cBufferPointer=BIN_fn_p_cGetPointer(p_cBufferPointer, (unsigned long *)&hLink,
						&IPO_g_stLinkTable);
 
  break;
  default:
    _asm{int 3h}
  break;
  }
  HIE_fn_vSetSuperObjectObjectAndType(hSPO, hLink.p_Void, lType);
 
  
  p_cBufferPointer=BIN_fn_p_cGetBinaryId(p_cBufferPointer,&lId);
  HIE_fn_vSetSuperObjectFirstChild(hSPO, (HIE_tdxHandleToSuperObject)lId);
  p_cBufferPointer=BIN_fn_p_cGetBinaryId(p_cBufferPointer, &lId);		
  HIE_fn_vSetSuperObjectLastChild(hSPO,(HIE_tdxHandleToSuperObject)lId);
  p_cBufferPointer=BIN_fn_p_cGetBinaryId(p_cBufferPointer, &lId);
	HIE_fn_vSetSuperObjectNextBrother(hSPO, (HIE_tdxHandleToSuperObject)lId);
  p_cBufferPointer=BIN_fn_p_cGetBinaryId(p_cBufferPointer, &lId);
	HIE_fn_vSetSuperObjectPrevBrother(hSPO, (HIE_tdxHandleToSuperObject)lId);
  p_cBufferPointer=BIN_fn_p_cGetBinaryId(p_cBufferPointer, &lId);
	HIE_fn_vSetSuperObjectFather(hSPO, (HIE_tdxHandleToSuperObject)lId);
 
 
	hMatrix=GEO_fn_hCreateMatrix();
 
  p_cBufferPointer=BIN_fn_p_cGetStruct(p_cBufferPointer,
									(char *)hMatrix,
									sizeof(POS_tdstCompletePosition));
 HIE_fn_vSetSuperObjectMatrix(hSPO, hMatrix);
  
	p_cBufferPointer=BIN_fn_p_cGetLong(p_cBufferPointer,
									&lDrawMask);
  HIE_fn_vSetSuperObjectDrawMask(hSPO, lDrawMask);
  //ANNECY VL SPOFLAG 05/12/97{
  //spo flags
  p_cBufferPointer = BIN_fn_p_cGetLong( p_cBufferPointer, &lDrawMask);
  HIE_fn_SO_vSetFlags( hSPO, lDrawMask );
  //ENDANNECY VL SPOFLAG}
// ANNECY AV {
  // If the matrix is the identity, we set the 'no transformation matrix' flag
  MTH3D_M_vSetIdentityMatrix (& stIdentityMatrix);
  if (MTH3D_M_bEqualMatrix (& hMatrix->stTransformMatrix, & stIdentityMatrix))
  {
      HIE_fn_SO_vSetFlags (hSPO, HIE_fn_SO_ulGetFlags (hSPO) | HIE_C_Flag_ulNoTransformationMatrix);
  }
// END ANNECY AV }
// ANNECY AV {
  // By default, a loaded super object has the "box instead of sphere bounding volume" flag
  HIE_fn_SO_vSetFlags (hSPO, HIE_fn_SO_ulGetFlags (hSPO) | HIE_C_Flag_ulTypeOfBoundingVolume);
// END ANNECY AV }
 
  p_cBufferPointer=BIN_fn_p_cGetPointer(p_cBufferPointer,
						(unsigned long*)&hBdVol,
						GLI_p_stGetLinkTableOfGeometric());
  HIE_fn_vSetSuperObjectBoundingVolume(hSPO, hBdVol);
 
  return (unsigned long)hSPO;
}
*/
/*-----------------------------------------------------------------------------
 *  Description :   function to read a binary SPO
 *-----------------------------------------------------------------------------
 *-----------------------------------------------------------------------------
 *  Creation date : Aug 97            Author : Alain Robin
 *-----------------------------------------------------------------------------*/
/*
void SPO_fn_vResolveBinaryBloc(unsigned long _ulAddress)
{
	HIE_tdxHandleToSuperObject hSPO;
	long lType; 
 
	hSPO=(HIE_tdxHandleToSuperObject)_ulAddress;
 
	lType=hSPO->lTypeOfLinkedObject&0xffffff7f;
	switch(lType)
	{
 
		case C_ucSuperObject:
			BIN_fn_p_cGetPointer((char*)&hSPO->hLinkedObject,(unsigned long *)&hSPO->hLinkedObject, NULL);
		break;
		case C_ucPhysical:
		case C_ucGeometric:
			BIN_fn_p_cGetPointer((char*)&hSPO->hLinkedObject,(unsigned long *)&hSPO->hLinkedObject,
									GLI_p_stGetLinkTableOfGeometric());
		break;
		case C_ucSector:
			BIN_fn_p_cGetPointer((char*)&hSPO->hLinkedObject,(unsigned long *)&hSPO->hLinkedObject,
									SECT_fn_pGetLinkTable());
		break;
		case C_ucPhysicalObject:
			BIN_fn_p_cGetPointer((char*)&hSPO->hLinkedObject,(unsigned long *)&hSPO->hLinkedObject,
									&PO_g_stLinkTable);
 
		break;
		case C_ucIpoMirror:
		case C_ucInstanciatedPhysicalObject:
			BIN_fn_p_cGetPointer((char*)&hSPO->hLinkedObject,(unsigned long *)&hSPO->hLinkedObject,
									&IPO_g_stLinkTable);
 
		break;
		case C_ucCharacter:
		break;
		default:
			_asm{int 3h}
		break;
	}
 
	// parent list 
	BIN_fn_p_cGetPointer((char*)&hSPO->hFirstElementDyn,(unsigned long *)&hSPO->hFirstElementDyn,
									HIE_fn_p_stGetSuperObjectLinkTable());
	BIN_fn_p_cGetPointer((char*)&hSPO->hLastElementDyn,(unsigned long *)&hSPO->hLastElementDyn,
									HIE_fn_p_stGetSuperObjectLinkTable());
	
	// child list 
	BIN_fn_p_cGetPointer((char*)&hSPO->hNextBrotherDyn,(unsigned long *)&hSPO->hNextBrotherDyn,
									HIE_fn_p_stGetSuperObjectLinkTable());
	BIN_fn_p_cGetPointer((char*)&hSPO->hPrevBrotherDyn,(unsigned long *)&hSPO->hPrevBrotherDyn,
									HIE_fn_p_stGetSuperObjectLinkTable());
	BIN_fn_p_cGetPointer((char*)&hSPO->hFatherDyn,(unsigned long *)&hSPO->hFatherDyn,
									HIE_fn_p_stGetSuperObjectLinkTable());
  
	// light 
	BIN_fn_p_cGetPointer((char*)&hSPO->hLight,(unsigned long *)&hSPO->hLight,
									LGT_fn_p_stGetLightLinkTable());
 
	//bounding volume 
	BIN_fn_p_cGetPointer((char*)&hSPO->hBoundingVolume,(unsigned long *)&hSPO->hBoundingVolume,
									GLI_p_stGetLinkTableOfGeometric());
 
	// position 
	hSPO->hLocalMatrix=(GEO_tdxHandleToMatrix)((char*)hSPO+sizeof(HIE_tdstSuperObject));
	hSPO->hGlobalMatrix=GEO_fn_hCreateMatrix();
}
*/
/*
// Second pass
void SPO_fn_vResolveBinaryBloc2(unsigned long _ulAddress)
{
	HIE_tdxHandleToSuperObject hSPO;
	long lType; 
 
	hSPO=(HIE_tdxHandleToSuperObject)_ulAddress;
 
	lType=hSPO->lTypeOfLinkedObject&0xffffff7f;
	switch(lType)
	{
		case C_ucCharacter:
			BIN_fn_p_cGetPointer((char*)&hSPO->hLinkedObject,(unsigned long*)&hSPO->hLinkedObject,
									&g_st3DOSLinkTable.stCharacter); 
		break;
		default:
#ifndef U64
			_asm{int 3h}
#endif
		break;
	}
}
*/
/*
void SPO_fn_vChangeIdsIntoAddresses(unsigned long ulAddress)
{
  HIE_tdxHandleToSuperObject hSPO, hRef;
  unsigned long lId;
 
  lId=(unsigned long)HIE_fn_hGetSuperObjectFirstChild(hSPO);
  hRef=(HIE_tdxHandleToSuperObject)BIN_fn_ulGetAddressFromId(HIE_fn_p_stGetSuperObjectLinkTable(),lId);
  HIE_fn_vSetSuperObjectFirstChild(hSPO, hRef);
  lId=(unsigned long)HIE_fn_hGetSuperObjectLastChild(hSPO);
  hRef=(HIE_tdxHandleToSuperObject)BIN_fn_ulGetAddressFromId(HIE_fn_p_stGetSuperObjectLinkTable(),lId);
  HIE_fn_vSetSuperObjectLastChild(hSPO,hRef);
	lId=(unsigned long)HIE_fn_hGetSuperObjectNextBrother(hSPO);
  hRef=(HIE_tdxHandleToSuperObject)BIN_fn_ulGetAddressFromId(HIE_fn_p_stGetSuperObjectLinkTable(),lId);
	HIE_fn_vSetSuperObjectNextBrother(hSPO, hRef);
	lId=(unsigned long)HIE_fn_hGetSuperObjectPrevBrother(hSPO);
  hRef=(HIE_tdxHandleToSuperObject)BIN_fn_ulGetAddressFromId(HIE_fn_p_stGetSuperObjectLinkTable(),lId);
	HIE_fn_vSetSuperObjectPrevBrother(hSPO, hRef);
	lId=(unsigned long)HIE_fn_hGetSuperObjectFather(hSPO);
  hRef=(HIE_tdxHandleToSuperObject)BIN_fn_ulGetAddressFromId(HIE_fn_p_stGetSuperObjectLinkTable(),lId);
	HIE_fn_vSetSuperObjectFather(hSPO, hRef);
 
}
 void SPO_fn_vChangeAllIdsIntoAddresses(char* _szBinaryFileName)
{
	BIN_fn_vResolvePointersFromLinkTable(HIE_fn_p_stGetSuperObjectLinkTable(),SPO_fn_vChangeIdsIntoAddresses);
}
*/
 
/*-----------------------------------------------------------------------------
 *  Description :   function to read all the binary blocs fort the visual sets
 *-----------------------------------------------------------------------------
 *-----------------------------------------------------------------------------
 *  Creation date : Aug 97            Author : Alain Robin
 *-----------------------------------------------------------------------------*/
/*
 void SPO_fn_vReadAllSPOBinaryBlocs(char* _szBinaryFileName)
{
	BIN_fn_vReadDataFromLinkTable(HIE_fn_p_stGetSuperObjectLinkTable(),SPO_fn_ulReadBinaryBloc,sizeof(HIE_tdstSuperObject)+sizeof(POS_tdstCompletePosition),_szBinaryFileName);
}
*/
 
 
/*===============================================================================*/
/*        FONCTIONS UTILISEES POUR LE CHARGEMENT DE SUPER-OBJET (SPO)            */
/*===============================================================================*/
BOOL HIE_fn_bInitSPOLoading()
{    
	SCR_fn_v_RdL0_RegisterCallback("SuperObject",HIE_fn_xLoadSuperObject, SCR_CRC_c_RdL0_ForSection);
	SCR_fn_v_RdL0_RegisterCallback("SuperInventory",HIE_fn_xLoadSuperObject, SCR_CRC_c_RdL0_ForSection);
	SCR_fn_v_RdL0_RegisterCallback("Matrix", HIE_fn_xLoadOneMatrix, SCR_CRC_c_RdL0_ForSection);
	/*ho...*/
  SCR_fn_v_RdL0_RegisterCallback("Mirror", GLI_xLoadGeometric, SCR_CRC_c_RdL0_ForSection);
 
	SCR_fn_v_Link_InitTable(HIE_fn_p_stGetSuperObjectLinkTable());
	return TRUE;
}
 
BOOL HIE_fn_bStopSPOLoading()
{    
	SCR_fn_v_Link_CloseTable(HIE_fn_p_stGetSuperObjectLinkTable());
	return TRUE;
}
 
 
 
/*===============================================================================*/
/*        FONCTIONS UTILISEES POUR LE CHARGEMENT DE SUPER-OBJET (SPO)            */
/*===============================================================================*/
BOOL HIE_fn_bInitSPOLoading2()
{    
	SCR_fn_v_RdL0_RegisterCallback("SuperObject",	HIE_fn_xLoadSuperObject2, SCR_CRC_c_RdL0_ForSection);
	SCR_fn_v_RdL0_RegisterCallback("SuperInventory",HIE_fn_xLoadSuperObject, SCR_CRC_c_RdL0_ForSection);
	SCR_fn_v_RdL0_RegisterCallback("Matrix",		HIE_fn_xLoadOneMatrix, SCR_CRC_c_RdL0_ForSection);
	/*ho...*/
	SCR_fn_v_RdL0_RegisterCallback("Mirror",		GLI_xLoadGeometric, SCR_CRC_c_RdL0_ForSection);
	SCR_fn_v_RdL0_RegisterCallback("CreateSubMaps", HIE_fn_xLoadSubMap, SCR_CRC_c_RdL0_ForSection);
  
	SCR_fn_v_Link_InitTable(HIE_fn_p_stGetSuperObjectLinkTable());
	SCR_fn_v_Link_InitTable(&gs_stLinkedObjectLinkTable);
	return TRUE;
}
 
BOOL HIE_fn_bStopSPOLoading2()
{    
	SCR_fn_v_Link_CloseTable(&gs_stLinkedObjectLinkTable);
	SCR_fn_v_Link_CloseTable(HIE_fn_p_stGetSuperObjectLinkTable());
	return TRUE;
}
 
 
/********************************************************************
NOM : GLI_vLoadMatrix
ROLE : Load matrices (with scripts)
*********************************************************************/
SCR_tde_Anl_ReturnValue HIE_fn_xLoadOneMatrix(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
	POS_tdstCompletePosition *p_stMatrix;
	long i;
	GLI_tdxValue a_xVertex[9];
	MTH3D_tdstVector stI,stJ,stK;
	
	switch (cType)
	{
	case SCR_EA_Anl_BeginSection:
		p_stMatrix=GEO_fn_hCreateMatrix();
		POS_fn_vSetIdentityMatrix(p_stMatrix);
		SCR_M_RdL0_SetSectionLong(0,0,p_stMatrix);
		SCR_M_RdL0_SetContextLong(0,0,p_stMatrix);
		break;
		
	case SCR_EA_Anl_Entry:
		/* Recuperation de la matrice a remplir*/
		SCR_M_RdL0_GetContextLong(0,0,POS_tdstCompletePosition*,p_stMatrix);
		
		/* Lecture de la matrice de translation*/
		if (strcmp(szAction,"MatrixTranslation")==0)
		{
			for (i=0;i<3;i++)
				a_xVertex[i]=(GLI_tdxValue)GLI_M_FloatToValue(atof(szParams[i]) * GLI_dGetUnitInMeterInFile(p_fFile->a_szOpenFileName));
			
			MTH3D_M_vSetVectorElements(&stI,a_xVertex[0],a_xVertex[1],a_xVertex[2]);
			POS_fn_vSetTranslationVector(p_stMatrix,&stI);
		}
		
		/* Lecture de la matrice de scale*/
		else if (strcmp(szAction,"MatrixScale")==0)
		{
			for (i=0;i<9;i++)
				a_xVertex[i]=(GLI_tdxValue)GLI_M_FloatToValue(atof(szParams[i]));
			
			if( !(  (a_xVertex[0] == 1.0)
				&& (a_xVertex[1] == 0.0)
				&& (a_xVertex[2] == 0.0)
				&& (a_xVertex[3] == 0.0)
				&& (a_xVertex[4] == 1.0)
				&& (a_xVertex[5] == 0.0)
				&& (a_xVertex[6] == 0.0)
				&& (a_xVertex[7] == 0.0)
				&& (a_xVertex[8] == 1.0))
				)
			{
				MTH3D_M_vSetVectorElements(&stI,a_xVertex[0],a_xVertex[1],a_xVertex[2]);
				MTH3D_M_vSetVectorElements(&stJ,a_xVertex[3],a_xVertex[4],a_xVertex[5]);
				MTH3D_M_vSetVectorElements(&stK,a_xVertex[6],a_xVertex[7],a_xVertex[8]);
				POS_fn_vSetScaleMatrix(p_stMatrix,&stI,&stJ,&stK);
			}
		}
		
		/* Lecture de la matrice de rotation*/
		else if (strcmp(szAction,"MatrixRotation")==0)
		{
			for (i=0;i<9;i++)
				a_xVertex[i]=(GLI_tdxValue)GLI_M_FloatToValue(atof(szParams[i]));
			
			MTH3D_M_vSetVectorElements(&stI,a_xVertex[0],a_xVertex[1],a_xVertex[2]);
			MTH3D_M_vSetVectorElements(&stJ,a_xVertex[3],a_xVertex[4],a_xVertex[5]);
			MTH3D_M_vSetVectorElements(&stK,a_xVertex[6],a_xVertex[7],a_xVertex[8]);
			POS_fn_vSetRotationMatrix(p_stMatrix,&stI,&stJ,&stK);
		}
		break;
		
	case C_SCRIPT_EndSection:
		/* Recuperation de la matrice a remplir*/
		SCR_M_RdL0_GetContextLong(0,0,POS_tdstCompletePosition*,p_stMatrix);
 
		/* Recalcul automatique du type*/
		POS_fn_vUpdateMatrixType(p_stMatrix);
 
		break;
	}
	return  R_SCRIPT_NormalReturn;
}
 
 
 
HIE_tdxHandleToSuperObject HIE_fn_hLoadOneSuperObject(char *p_cScriptFile)
{
  SCR_tdst_Cxt_Values *p_stValues;
  HIE_tdxHandleToSuperObject hSuperObjectLoaded=NULL;
  SCR_tdst_Link_Value* p_stLinkValue;
  unsigned int uiPos;
  /* BEGIN AR 970903 (Verify that the object hasn't been already loaded in binary mode)*/
/*  p_stLinkValue=BIN_fn_p_stSearchShortKey(HIE_fn_p_stGetSuperObjectLinkTable(),p_cScriptFile);*/
	uiPos = 0;
	SCR_M_DyAr_GetNextElement(SCR_tdst_Link_Value, uiPos, p_stLinkValue,SCR_M_st_Link_GetDynamicArray(HIE_fn_p_stGetSuperObjectLinkTable()));
	while(p_stLinkValue)
	{
        if(!strcmpi(SCR_M_p_sz_Link_GetKey(p_stLinkValue) + SCR_M_ul_Link_GetAdditionalLong(p_stLinkValue,1),p_cScriptFile))
			break;
        uiPos++;
        SCR_M_DyAr_GetNextElement(SCR_tdst_Link_Value, uiPos, p_stLinkValue,SCR_M_st_Link_GetDynamicArray(HIE_fn_p_stGetSuperObjectLinkTable()));
	}
 
  if(p_stLinkValue==NULL)
  {
	  p_stValues = SCR_fnp_st_RdL0_AnalyseSection(p_cScriptFile, SCR_CDF_uw_Anl_Normal);
  
	  if(p_stValues)
	  {
		hSuperObjectLoaded=(HIE_tdxHandleToSuperObject)SCR_M_ul_RdL0_ExtractLongValue(p_stValues,0);
		HIE_fn_vLoadLinkedObject(hSuperObjectLoaded);
	  }
  }
  else
	hSuperObjectLoaded=(HIE_tdxHandleToSuperObject)p_stLinkValue->ulValue;
  /* END AR 970903*/
  return hSuperObjectLoaded;
}
 
 
 
/********************************************************************
NOM : GLI_vLoadSuperObject
ROLE : Load a SuperObject (with scripts)
*********************************************************************/
SCR_tde_Anl_ReturnValue HIE_fn_xLoadSuperObject(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
	HIE_tdxHandleToSuperObject hSuperObject;
	HIE_tdxHandleToSuperObject hNewSuperObject;
	POS_tdstCompletePosition *p_stMatrix;
	ACP_tdxHandleOfObject hGeometric;
	HIE_tdxHandleToVoid hLinkedObj;
	char szSection[SCR_CV_ui_Cfg_MaxLenName], szName[SCR_CV_ui_Cfg_MaxLenName];
	long lType;
	char a255_cLongName[255];
/* ANNECY AV {*/
    MTH3D_tdstMatrix stIdentityMatrix;
    MTH3D_tdstMatrix * p_stTransformationMatrix;
/* END ANNECY AV }*/
	
	switch (cType)
	{
	case SCR_EA_Anl_BeginSection:
    VIG_fn_vAddToProgressBar(1);
		/* new SuperObject for that section*/
		hNewSuperObject=HIE_fn_hCreateSuperObject();
 
    /*old*/
    /*
		strcpy(a255_cLongName,fn_szGetLevelsDataPath());
		strcat(a255_cLongName,"\\");
		strcat(a255_cLongName,SCR_M_RdL0_GetCompleteSectionNameR(0));
		SCR_fnp_st_Link_SetValue(HIE_fn_p_stGetSuperObjectLinkTable(), a255_cLongName, (unsigned long)hNewSuperObject);
    */
    /*NEW NZO for CB*/
 
    SCR_M_RdL0_ComputeOpenSectionNameR(0,a255_cLongName);
    SCR_M_v_Link_SetAdditionalLong(SCR_fnp_st_Link_SetValue(HIE_fn_p_stGetSuperObjectLinkTable(), a255_cLongName, (unsigned long)hNewSuperObject), 1, strlen(a255_cLongName)-strlen(SCR_M_RdL0_GetCompleteSectionNameR(0)));
 
		/*I return my own handle*/
		SCR_M_RdL0_SetSectionLong(0,0,hNewSuperObject);
		SCR_M_RdL0_SetContextLong(0,0,hNewSuperObject);
		break;
		
	case SCR_EA_Anl_Entry:
		/* Here is my own handle*/
		SCR_M_RdL0_GetContextLong(0,0,HIE_tdxHandleToSuperObject,hSuperObject);
		
		/* Loading of a Child SuperObject*/
		if (strcmp(szAction,"AddChild")==0)
		{
			SCR_tdst_Cxt_Values *p_stVal;
			
			p_stVal = SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal);
			hNewSuperObject = (HIE_tdxHandleToSuperObject)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
			
			HIE_fn_vSuperObjectAddTail(hSuperObject,hNewSuperObject);
		}
		
		/* read a Matrix*/
		if (strcmp(szAction,"PutMatrix")==0)
		{
			SCR_tdst_Cxt_Values *p_stVal;
			
			p_stVal = SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal);
			p_stMatrix = (POS_tdstCompletePosition *)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
			
			HIE_fn_vSetSuperObjectMatrix(hSuperObject,p_stMatrix);
		}
		
		/* Loading of a Geometric Object*/
		if (strcmp(szAction,"Geometric")==0)
		{ 
			hGeometric =GLI_pLoadGeometricInFile(szParams[0]);
			
			HIE_fn_vSetSuperObjectObjectAndType(hSuperObject,hGeometric,HIE_C_ulEDT_Geometric);
		}
		
		if (strcmp(szAction,"LinkedObject")==0)
		{ 
			SCR_tdst_Cxt_Values *p_stVal;
			char sFile[255];
			
			p_stVal = SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal);
			hLinkedObj =(HIE_tdxHandleToVoid)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
			
			SCR_fn_v_RdL0_SplitSectionName(szParams[0], sFile, szSection, szName);
			if (strcmp(szSection,"Geometric")==0) lType=HIE_C_ulEDT_Geometric;
			else if(strcmp(szSection,"Sector")==0) lType=HIE_C_ulSector;
			else if (strcmp(szSection,"SpecialEffect")==0) lType=HIE_C_ulSpecialEffect;
			else if (strcmp(szSection,"PHY")==0) lType=HIE_C_ulPO;
			else if (strcmp(szSection,"IPO")==0) lType=HIE_C_ulIPO;
			else if (strcmpi(szSection,"Mirror")==0) lType=HIE_C_ulMirror;
			else if (strcmpi(szSection,"IpoMirror")==0) lType=HIE_C_ulIPO_Mirror;
			else if (strcmpi(szSection,"PhyMirror")==0) lType=HIE_C_ulPO_Mirror;
 
			/*				if (strcmp(Section,"Truc") lType=C_ucTruc;*/
			
			/* Link the SuperObject with its Object*/
			HIE_fn_vSetSuperObjectObjectAndType(hSuperObject,hLinkedObj,lType);
		}
		/*ANNECY VL SPOFLAG 05/12/97{*/
		/* loading flags*/
		else if (stricmp( szAction, "Flags" ) == 0 )
		{
			HIE_fn_SO_vSetFlags( hSuperObject, atoi( szParams[0] ) );
		}
		/*ENDANNECY VL SPOFLAG}*/
 
/*ANNECY Shaitan Transparency (26/03/98) {*/
		else if (strcmp( szAction, "Transparency" ) == 0 )
		{
			HIE_fn_vSetSuperObjectTransparenceLevel( hSuperObject, (float) atof( szParams[0] ) );
		}
/*ENDANNECY Shaitan Transparency }*/
 
		break;
		
	case C_SCRIPT_EndSection:
/* ANNECY AV {*/
  		  SCR_M_RdL0_GetContextLong(0,0,HIE_tdxHandleToSuperObject,hSuperObject);
          /* If the matrix is the identity, we set the 'no transformation matrix' flag*/
          MTH3D_M_vSetIdentityMatrix (& stIdentityMatrix);
          p_stTransformationMatrix = & HIE_fn_hGetSuperObjectMatrix (hSuperObject) -> stTransformMatrix;
          if (MTH3D_M_bEqualMatrix (p_stTransformationMatrix, & stIdentityMatrix))
          {
              HIE_fn_SO_vSetFlags (hSuperObject, HIE_fn_SO_ulGetFlags (hSuperObject) | HIE_C_Flag_ulNoTransformationMatrix);
          }
/* END ANNECY AV }*/
/* ANNECY AV {*/
  /* By default, a loaded super object has the "box instead of sphere bounding volume" flag*/
          HIE_fn_SO_vSetFlags (hSuperObject, HIE_fn_SO_ulGetFlags (hSuperObject) | HIE_C_Flag_ulTypeOfBoundingVolume);
/* END ANNECY AV }*/
		break;
	}
	return  R_SCRIPT_NormalReturn;
}
 
/********************************************************************
NOM : GLI_vLoadSPOFile
ROLE : Load an entire SPO file
*********************************************************************/
HIE_tdxHandleToSuperObject HIE_fn_hLoadSPOFile(char *szLoadPath, char *szFileName)
{
	char sName[256];
	HIE_tdxHandleToSuperObject hReturnedSuperObject;
	SCR_tdst_Cxt_Values *p_stVal;
	
	SCR_fn_v_RdL0_RegisterPath(szLoadPath);
	
	/*I assume that there is a SuperObject called Root, which is the ancestor of all the others*/
	SCR_fn_v_RdL0_ComputeSectionName(sName, szFileName, "SuperObject", "Root");

	p_stVal = SCR_fnp_st_RdL0_AnalyseSection(sName, SCR_CDF_uw_Anl_Normal);
	hReturnedSuperObject=(HIE_tdxHandleToSuperObject)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
	
	return hReturnedSuperObject;
}
 
 
/********************************************************************
NOM : HIE_fn_hLoadSUBFile
ROLE : Load an entire SUB file (submap file)
*********************************************************************/
/* ANNECY MT - 08/09/98 {*/
HIE_tdxHandleToSuperObject HIE_fn_hLoadSUBFile(char *szLoadPath, char *szFileName, long _lSubMap, long _lEntry)
{
	char sName[256];
	char sSubMapName[256];
 
	HIE_tdxHandleToSuperObject hReturnedSuperObject;
	SCR_tdst_Cxt_Values *p_stVal;
	
	SCR_fn_v_RdL0_RegisterPath(szLoadPath);
	
	/*I assume that there is a SuperObject called Root, which is the ancestor of all the others*/
	sprintf(sSubMapName, "submap%02d" , _lSubMap);
	SCR_fn_v_RdL0_ComputeSectionName(sName, szFileName, "CreateSubMaps", sSubMapName);
	/*SCR_fn_v_RdL0_ComputeSectionName(sSubMapName, sName, "SuperObject", "Root");*/
	
	SCR_M_RdL0_SetContextLong(1,0,_lEntry);
 
	p_stVal = SCR_fnp_st_RdL0_AnalyseSection(sName, SCR_CDF_uw_Anl_Normal);
	hReturnedSuperObject=(HIE_tdxHandleToSuperObject)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
	
	return hReturnedSuperObject;
}
/* END ANNECY MT }*/
 
/********************************************************************
NOM : GLI_vLoadSuperObject2
ROLE : Load a SuperObject (with scripts)
*********************************************************************/
SCR_tde_Anl_ReturnValue HIE_fn_xLoadSuperObject2(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
	HIE_tdxHandleToSuperObject hSuperObject;
	HIE_tdxHandleToSuperObject hNewSuperObject;
	POS_tdstCompletePosition *p_stMatrix;
	HIE_tdxHandleToVoid hLinkedObj;
	char a255_cLongName[255];
/* ANNECY AV {*/
    MTH3D_tdstMatrix stIdentityMatrix;
    MTH3D_tdstMatrix * p_stTransformationMatrix;
/* END ANNECY AV }*/
	
	switch (cType)
	{
	case SCR_EA_Anl_BeginSection:
    VIG_fn_vAddToProgressBar(1);
		/* new SuperObject for that section*/
		hNewSuperObject=HIE_fn_hCreateSuperObject();
    /*old*/
    /*
		strcpy(a255_cLongName,fn_szGetLevelsDataPath());
		strcat(a255_cLongName,"\\");
		strcat(a255_cLongName,SCR_M_RdL0_GetCompleteSectionNameR(0));
		SCR_fnp_st_Link_SetValue(HIE_fn_p_stGetSuperObjectLinkTable(), a255_cLongName, (unsigned long)hNewSuperObject);
    */
    /*NEW NZO for CB*/
    
    SCR_M_RdL0_ComputeOpenSectionNameR(0,a255_cLongName);
    SCR_M_v_Link_SetAdditionalLong(SCR_fnp_st_Link_SetValue(HIE_fn_p_stGetSuperObjectLinkTable(), a255_cLongName, (unsigned long)hNewSuperObject), 1, strlen(a255_cLongName)-strlen(SCR_M_RdL0_GetCompleteSectionNameR(0)));
    
 
		/*I return my own handle*/
		SCR_M_RdL0_SetSectionLong(0,0,hNewSuperObject);
		SCR_M_RdL0_SetContextLong(0,0,hNewSuperObject);
		break;
		
	case SCR_EA_Anl_Entry:
		/* Here is my own handle*/
		SCR_M_RdL0_GetContextLong(0,0,HIE_tdxHandleToSuperObject,hSuperObject);
		
		/* Loading of a Child SuperObject*/
		if (strcmp(szAction,"AddChild")==0)
		{
			SCR_tdst_Cxt_Values *p_stVal;
			
			p_stVal = SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal);
			hNewSuperObject = (HIE_tdxHandleToSuperObject)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
			
			HIE_fn_vSuperObjectAddTail(hSuperObject,hNewSuperObject);
		}
		
		/* read a Matrix*/
		if (strcmp(szAction,"PutMatrix")==0)
		{
			SCR_tdst_Cxt_Values *p_stVal;
			
			p_stVal = SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal);
			p_stMatrix = (POS_tdstCompletePosition *)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
			
			HIE_fn_vSetSuperObjectMatrix(hSuperObject,p_stMatrix);
		}
		
		/* Loading of a Geometric Object*/
/*
    if (strcmp(szAction,"Geometric")==0)
		{ 
			hGeometric =GLI_pLoadGeometricInFile(szParams[0]);
			
			HIE_fn_vSetSuperObjectObjectAndType(hSuperObject,hGeometric,C_ucPhysical);
		}
	*/	
		if (strcmp(szAction,"LinkedObject")==0)
		{ 
			hLinkedObj =(HIE_tdxHandleToVoid)SCR_fnp_st_Link_CreateOrGetLinkFromKey(HIE_fn_p_stGetLinkedObjectLinkTable(), szParams[0]);
      SCR_fnp_st_Link_SetValue(HIE_fn_p_stGetLinkedObjectLinkTable(), szParams[0], 0);/*for a problem with freeing link table*/
			
			
			/* store the line in the table of the linked object*/
			HIE_fn_vSetSuperObjectObjectAndType(hSuperObject,hLinkedObj,-3);
		}
		/*ANNECY VL SPOFLAG 05/12/97{*/
		/* loading flags*/
		else if (strcmp( szAction, "Flags" ) == 0 )
		{
			HIE_fn_SO_vSetFlags( hSuperObject, atoi( szParams[0] ) );
		}
		/*ENDANNECY VL SPOFLAG}*/
/*ANNECY Shaitan Transparency (26/03/98) {*/
		else if (strcmp( szAction, "Transparency" ) == 0 )
		{
			HIE_fn_vSetSuperObjectTransparenceLevel( hSuperObject, (float) atof( szParams[0] ) );
		}
/*ENDANNECY Shaitan Transparency }*/
		break;
		
	case C_SCRIPT_EndSection:
/* ANNECY AV {*/
  		  SCR_M_RdL0_GetContextLong(0,0,HIE_tdxHandleToSuperObject,hSuperObject);
          /* If the matrix is the identity, we set the 'no transformation matrix' flag*/
          MTH3D_M_vSetIdentityMatrix (& stIdentityMatrix);
          p_stTransformationMatrix = & HIE_fn_hGetSuperObjectMatrix (hSuperObject) -> stTransformMatrix;
          if (MTH3D_M_bEqualMatrix (p_stTransformationMatrix, & stIdentityMatrix))
          {
              HIE_fn_SO_vSetFlags (hSuperObject, HIE_fn_SO_ulGetFlags (hSuperObject) | HIE_C_Flag_ulNoTransformationMatrix);
          }
/* END ANNECY AV }*/
/* ANNECY AV {*/
  /* By default, a loaded super object has the "box instead of sphere bounding volume" flag*/
          HIE_fn_SO_vSetFlags (hSuperObject, HIE_fn_SO_ulGetFlags (hSuperObject) | HIE_C_Flag_ulTypeOfBoundingVolume);
/* END ANNECY AV }*/
		break;
	}
	return  R_SCRIPT_NormalReturn;
}
 
 
/*ROMTEAM PLG Files Ionut Grozea 01-05-1998*/
#ifdef ACTIVE_EDITOR 
SCR_tde_Anl_ReturnValue MLT_xLoadName(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
 
if (m_ObjectColorStruct.iNrObjects < 100)
	{
		switch (cType)
		{	
 
		case SCR_EA_Anl_BeginSection:
			{
				ISI_tdstObjectColor m_obj;
				strcpy( m_obj.csName  , szAction );
				m_obj.iNrVertex = (atoi)(szParams[0]);
				m_ObjectColorStruct.objColor[m_ObjectColorStruct.iNrObjects] = m_obj;
				m_ObjectColorStruct.iNrObjects++;
			}
 			break;
		
		case SCR_EA_Anl_Entry:
			{
				 if((atoi)(szParams[0])<1000)
				 {
					m_ObjectColorStruct.objColor[m_ObjectColorStruct.iNrObjects-1].xVertexColor[(atoi)(szParams[0])].xRed = (atoi)(szParams[1]);			
					m_ObjectColorStruct.objColor[m_ObjectColorStruct.iNrObjects-1].xVertexColor[(atoi)(szParams[0])].xGreen = (atoi)(szParams[2]);			
					m_ObjectColorStruct.objColor[m_ObjectColorStruct.iNrObjects-1].xVertexColor[(atoi)(szParams[0])].xBlue = (atoi)(szParams[3]);			
					m_ObjectColorStruct.objColor[m_ObjectColorStruct.iNrObjects-1].xVertexColor[(atoi)(szParams[0])].xAlpha = (atoi)(szParams[1]);/*init the alpha value with the r value			*/
				 }
			}
			break;
		
		case C_SCRIPT_EndSection:
			{
 
			}
			break;
		default :
			break;
		}
		return  R_SCRIPT_NormalReturn;
	}
}
#endif
/*ENDROMTEAM PLG Files Ionut Grozea 01-05-1998*/
 
/*ROMTEAM PLG Files Ionut Grozea 01-05-1998*/
#ifdef ACTIVE_EDITOR 
 
void PLG_InitPLGLoad()
{
  SCR_fn_v_RdL0_RegisterCallback("VertexColor", MLT_xLoadName,SCR_CRC_c_RdL0_ForSection);  
}
#endif
/*ENDROMTEAM PLG Files Ionut Grozea 01-05-1998*/
 
/*ROMTEAM PLG Files Ionut Grozea 01-05-1998*/
#ifdef ACTIVE_EDITOR 
void LGT_fn_xLoadPlgObject()
{
	char szCompleteLevelsFileName[SCR_CV_ui_Cfg_MaxLenName];
	char* pszLevelsFileName;
 
	fn_zsGetActualLevelFilename ( szCompleteLevelsFileName, "plg");
	pszLevelsFileName = szCompleteLevelsFileName + strlen(fn_szGetLevelsDataPath()) + 1;
 
	m_ObjectColorStruct.iNrObjects = 0;
/*	int iPosCurent;*/
	if (SCR_fn_c_RdL0_IsSectionExists (szCompleteLevelsFileName))
		SCR_fnp_st_RdL0_AnalyseSection (pszLevelsFileName,SCR_CDF_uw_Anl_ForceAnalyse);
 
}
#endif
/*ENDROMTEAM PLG Files Ionut Grozea 01-05-1998*/
 
void HIE_fn_vLoadLinkedObject(HIE_tdxHandleToSuperObject _hSuperObject)
{
  HIE_tdxHandleToSuperObject hChild;
	SCR_tdst_Cxt_Values *p_stVal;
	char sFile[255];
	char szSection[SCR_CV_ui_Cfg_MaxLenName], szName[SCR_CV_ui_Cfg_MaxLenName],*szParams;
  HIE_tdxHandleToVoid hLinkedObj;
	long lType;
	static int iCount;
  ACP_tdxIndex i;
 
  if(HIE_fn_ulGetSuperObjectType(_hSuperObject)==-3)
  {
      
      szParams=SCR_M_p_sz_Link_GetKey((SCR_tdst_Link_Value *)HIE_fn_hGetSuperObjectObject(_hSuperObject));
			SCR_fn_v_RdL0_SplitSectionName(szParams, sFile, szSection, szName);
      /*strcmpi because of the Script*/
      /*should use constants instead of strings...*/
	  if (strcmpi(szSection,"Geometric")==0)
	  {
		hLinkedObj =(HIE_tdxHandleToVoid)GLI_pLoadGeometricInFile(szParams);
 
		lType=HIE_C_ulEDT_Geometric;
	  }
	  else if (strcmpi(szSection,"Sector")==0)
	  {
        p_stVal = SCR_fnp_st_RdL0_AnalyseSection(szParams, SCR_CDF_uw_Anl_Normal);
		hLinkedObj =(HIE_tdxHandleToVoid)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
 
		lType=HIE_C_ulSector;
	  }
	  else if (strcmpi(szSection,"SpecialEffect")==0)
	  {
        p_stVal = SCR_fnp_st_RdL0_AnalyseSection(szParams, SCR_CDF_uw_Anl_Normal);
		hLinkedObj =(HIE_tdxHandleToVoid)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
 
		lType=HIE_C_ulSpecialEffect;
	  }
	  else if (strcmpi(szSection,"PHY")==0)
	  {
        p_stVal = SCR_fnp_st_RdL0_AnalyseSection(szParams, SCR_CDF_uw_Anl_Normal);
		hLinkedObj =(HIE_tdxHandleToVoid)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
 
		lType=HIE_C_ulPO;
	  }
	  else if (strcmpi(szSection,"IPO")==0)
	  {
        p_stVal = SCR_fnp_st_RdL0_AnalyseSection(szParams, SCR_CDF_uw_Anl_Normal);
		hLinkedObj =(HIE_tdxHandleToVoid)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
 
		lType=HIE_C_ulIPO;
	  }
	  else if (strcmpi(szSection,"Mirror")==0)
	  {
        p_stVal = SCR_fnp_st_RdL0_AnalyseSection(szParams, SCR_CDF_uw_Anl_Normal);
		hLinkedObj =(HIE_tdxHandleToVoid)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
 
		lType=HIE_C_ulMirror;
	  }
	  else if (strcmpi(szSection,"Ipo_Mirror")==0)
	  {
        p_stVal = SCR_fnp_st_RdL0_AnalyseSection(szParams, SCR_CDF_uw_Anl_Normal);
		hLinkedObj =(HIE_tdxHandleToVoid)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
 
		lType=HIE_C_ulIPO_Mirror;
	  }
	  else if (strcmpi(szSection,"PhyMirror")==0)
	  {
        p_stVal = SCR_fnp_st_RdL0_AnalyseSection(szParams, SCR_CDF_uw_Anl_Normal);
		hLinkedObj =(HIE_tdxHandleToVoid)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0);
 
	 	lType=HIE_C_ulPO_Mirror;
	  }
			/*				if (strcmp(Section,"Truc") lType=C_ucTruc;*/
			
			/* Link the SuperObject with its Object*/
			HIE_fn_vSetSuperObjectObjectAndType(_hSuperObject,hLinkedObj,lType);
 
  
  }
    HIE_M_ForEachChildOf(_hSuperObject, hChild, i)
    {
      /* recurence*/
      HIE_fn_vLoadLinkedObject(hChild);
    }
/*ROMTEAM PLG Files Ionut Grozea 01-05-1998*/
#ifdef ACTIVE_EDITOR 
	if (!iCount)
	{
		PLG_InitPLGLoad();
		LGT_fn_xLoadPlgObject();
		iCount = 1;
	}
#endif
/*ENDROMTEAM PLG Files Ionut Grozea 01-05-1998*/
}
 
			
/********************************************************************
NOM : HIE_fn_xLoadSubMap
ROLE : Load a "CreateSubMaps" section
*********************************************************************/
/* ANNECY MT - 08/09/98 {*/
SCR_tde_Anl_ReturnValue HIE_fn_xLoadSubMap(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType)
{
	HIE_tdxHandleToSuperObject hSuperObject;
	POS_tdstCompletePosition *p_stMatrix;
	long lWantedEntry,lCurrentEntry;
 
	switch (cType)
	{
	case SCR_EA_Anl_BeginSection:
		break;
		
	case SCR_EA_Anl_Entry:
		break;
		
    case SCR_EA_Anl_BeginSubSection:
		break;
 
    case SCR_EA_Anl_EndSubSection:
		if(strcmpi(szParams[0],"SuperObject")==0)
		{
			SCR_M_RdL0_GetContextLong(1,0,HIE_tdxHandleToSuperObject,hSuperObject);
			SCR_M_RdL0_SetSectionLong(0,0,hSuperObject);
			/**/
		}
		else if(strcmpi(szParams[0],"Matrix")==0)
		{
			SCR_M_RdL0_GetContextLong(1,0,POS_tdstCompletePosition *,p_stMatrix);
			SCR_M_RdL0_GetContextLong(0,0,long,lWantedEntry);
			lCurrentEntry = fn_lAToI(szParams[1] + strlen("Position"));
			if(lCurrentEntry == lWantedEntry)
			{
				POS_fn_vCopyMatrix(&g_stEngineStructure.stMainCharacterPosition,p_stMatrix);
				POS_fn_vCopyMatrix(&g_stEngineStructure.stMainCameraPosition,p_stMatrix);
				g_stEngineStructure.stMainCameraPosition.stTranslationVector.xZ = MTH_M_xAdd(g_stEngineStructure.stMainCameraPosition.stTranslationVector.xZ, MTH_C_2);
				g_stEngineStructure.stMainCameraPosition.stTranslationVector.xX = MTH_M_xAdd(g_stEngineStructure.stMainCameraPosition.stTranslationVector.xX, MTH_C_2);
				g_stEngineStructure.bResurection = TRUE;	
			}
		}
		break;
 
	case C_SCRIPT_EndSection:
		break;
	}
	return  R_SCRIPT_NormalReturn;
}
/* END ANNECY MT }*/
