/*=========================================================================
* Model.c : This module contain all models functions
* This is a part of the Game project.
*
* Version              1.0
* Creation date        16/10/96
* Revision date
*
* That file needs to be compatible for all platforms.
*
* (c) Ubi Studios 1996
*=======================================================================*/
/*
*=======================================================================
Modifications: New LST2_M_??? Macros / Michaël / 070297
*=======================================================================*/
 
/*ANNECY BBB 10/03/98 {*/
#define  D_ObjsTbls_Define
/*ENDANNECY BBB 10/03/98 }*/
 
#include "ToolsCPA.h"
 
#include "Options/Options.h"
#include "Macros.h"
 
#include "Actions/AllActs.h"
 
#include "Structur/EngMode.h"
#include "Structur/ErrGame.h"
#include "Structur/MemGame.h"
#include "Structur/Objects.h"
#include "Structur/StdObjSt.h"
 
#include "Family.h"
#include "LoadFml.h"
#include "ZeMem.h"
 
#include "Structur/ObjsTbls.h"
 
/*-----------------------------------------------------------------------------
 *  Description :   Desinitialize the family's structure (when the map is finish)
 *-----------------------------------------------------------------------------
 *  Input :         void
 *  Output :        void
 *-----------------------------------------------------------------------------
 *  Creation date : 16/10/96            Author : Francois
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author :
 *  Modifications :
 *---------------------------------------------------------------------------*/

#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC 04/06/99 */
void fn_vLastDesinitFamilyStructure()
{
	struct tdstFamilyList_ *p_stThisFamily,*p_stNextFamily;
	long i;
 
  LST2_M_DynamicForEachMovingElementOf(&g_stEngineStructure.hFamilyList,p_stThisFamily,p_stNextFamily,i)
  {
    LST2_M_DynamicIsolate(p_stThisFamily);
  }
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC 04/06/99 */

 
 
void fn_vDesinitFamilyStructureForPriority(unsigned char ucPriority)
{
	struct tdstFamilyList_ *p_stThisFamily,*p_stNextFamily;
	long i;
 
  LST2_M_DynamicForEachMovingElementOf(&g_stEngineStructure.hFamilyList,p_stThisFamily,p_stNextFamily,i)
  {
   if(p_stThisFamily->ucPriority==GAM_g_ucHLMMemoryBlock)
    LST2_M_DynamicIsolate(p_stThisFamily);
  }
}
 
 
/*-----------------------------------------------------------------------------
 *  Description :   find or add a model
 *-----------------------------------------------------------------------------
 *  Input :         Family type
 *  Output :        Family's pointer
 *-----------------------------------------------------------------------------
 *  Creation date : 16/10/96            Author : Francois
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author :
 *  Modifications :
 *---------------------------------------------------------------------------*/
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
tdxHandleToFamilyList fn_hFindOrAddFAmily(tdObjectType otFamilyType)
{
 struct tdstFamilyList_ *p_stFamily = NULL;
 
 p_stFamily = fn_hFindFamily(otFamilyType);
 
/*#ifndef BIN_LoadBin // In binary mode all the families are loaded with another method*/
 if (p_stFamily==NULL)
 {
  MMG_fn_vAddMemoryInfo( MMG_C_lTypeFamily , MMG_C_lSubTypeFamily , 0 );
  p_stFamily = (struct tdstFamilyList_*)M_p_GameMallocInHLM(sizeof(struct tdstFamilyList_));
  p_stFamily->otObjectFamilyType = otFamilyType;
 
  fn_vInitObjectsTablesList(p_stFamily); /* tmp SD Gizmo 14/04/97*/
 
	/*fn_vAllocateOneMoreObjectsTablesInList(p_stFamily,100);// tmp SD Gizmo 14/04/97*/
 
  fn_vLoadFamily(p_stFamily);
  LST2_M_DynamicAddTail(&g_stEngineStructure.hFamilyList,p_stFamily);
  p_stFamily->ucPriority = GAM_g_ucHLMMemoryBlock;
 }
/*#endif /*BIN_LoadBin  */
 
 return(p_stFamily);
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
 
/*-----------------------------------------------------------------------------
 *  Description :   find a family
 *-----------------------------------------------------------------------------
 *  Input :         Family type
 *  Output :        Family's pointer (NULL if not found)
 *-----------------------------------------------------------------------------
 *  Creation date : 16/10/96            Author : Francois
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author :
 *  Modifications :
 *---------------------------------------------------------------------------*/
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
tdxHandleToFamilyList fn_hFindFamily(tdObjectType otFamilyType)
{
 struct tdstFamilyList_ *p_stThisFamily;
	long i;
 
 LST2_M_DynamicForEachElementOf(&g_stEngineStructure.hFamilyList,p_stThisFamily,i)
 {
  if (p_stThisFamily->otObjectFamilyType==otFamilyType)
   return(p_stThisFamily);
 }
 return(NULL);
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
 
 
GEO_tdxHandleToBoundingSphere fn_vGetBoundingVolumeOfFamily(tdxHandleToFamilyList h_Family)
{
	return(h_Family->hBoundingSphere);
}
 
void fn_vSetBoundingVolumeOfFamily(tdxHandleToFamilyList h_Family,GEO_tdxHandleToBoundingSphere hBV)
{
	h_Family->hBoundingSphere = hBV;
}
 
#if defined (ACTIVE_EDITOR)
ACP_tdxHandleOfObject fn_vGetGeometricSphereOfFamily(tdxHandleToFamilyList h_Family)
{
	return(h_Family->hGeometricSphere);
}
 
void fn_vSetGeometricSphereOfFamily(tdxHandleToFamilyList h_Family, ACP_tdxHandleOfObject hGS)
{
	h_Family->hGeometricSphere = hGS;
}
#endif /*ACTIVE_EDITOR*/
 
/* debut GIZMO NEW 07/06/97*/
tdxHandleToObjectsTablesList  fn_vGetDefaultObjectsTableOfFamily(tdxHandleToFamilyList h_Family)
{
	return(h_Family->h_DefaultObjectsTable);
}
 
void fn_vSetDefaultObjectsTableOfFamily(tdxHandleToFamilyList h_Family,tdxHandleToObjectsTablesList h_DefaultObjectsTable)
{
	h_Family->h_DefaultObjectsTable = h_DefaultObjectsTable;
}
/* fin GIZMO NEW 07/06/97*/
 
/*ANNECY BBB {*/
 
tdxHandleToObjectsTablesList fn_hGetObjectsTableOfFamilyByIndex(tdxHandleToFamilyList _hFamily, ACP_tdxIndex _xIndex)
{
	ACP_tdxIndex xForMacro = 0;
	tdxHandleToObjectsTablesList hTable;
 
  LST2_M_StaticGetElementNumber(&(_hFamily->hForObjectsTablesList), hTable, _xIndex, xForMacro);
 
	return hTable;
}
/*ANNECY BBB }*/
 
 
#ifdef _TMP_FAMILY_HANDLE_
/*-----------------------------------------------------------------------------
 *  Description :   Add a New State To StateArray Of a Family
 *-----------------------------------------------------------------------------
 *  Input :         Handle to Family, Handle to State
 *  Output :        Nothing
 *-----------------------------------------------------------------------------
 *  Creation date : 27/02/97            Author : Sebastien DAVID (Gizmo)
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author :
 *  Modifications :
 *---------------------------------------------------------------------------*/
void fn_vAddNewStateToStateArrayOfFamily(tdxHandleToFamily h_Family, tdxHandleToState h_State)
{
  LST2_M_StaticAddTail(&h_Family->hForStateArray, h_State);
}
 
 
/*-----------------------------------------------------------------------------
 *  Description :   Remove a State From StateArray Of a Family
 *-----------------------------------------------------------------------------
 *  Input :         Handle to Family, Handle to State
 *  Output :        Nothing
 *-----------------------------------------------------------------------------
 *  Creation date : 27/02/97            Author : Sebastien DAVID (Gizmo)
 *-----------------------------------------------------------------------------
 *  Modification date :                 Modification Author :
 *  Modifications :
 *---------------------------------------------------------------------------*/
void fn_vRemoveStateFromStateArrayOfFamily(tdxHandleToState h_State)
{
  LST2_M_StaticAddTail(&h_Family->hForStateArray, h_State);
}
#endif
 
 
