/*=========================================================================
* CollSet.h : CollSet's functions
*
*
*         CollSet MUST BE REPLACE BY THE HEADER FILENAME
*
*
* Version              1.0
* Creation date        01/10/96
* Revision date
*
* That file needs to be compatible for all platforms.
*
* (c) Ubi Studios 1996
*=======================================================================*/
 
#if !defined(__CollSet_H__)
#define __CollSet_H__
 
/******************************************/
#if _MSC_VER >= 1000
#pragma once
#endif /* _MSC_VER >= 1000 */
/******************************************/
 
#include "GAM/Header.h"
 
#undef EXTERN
#undef extern
#if !defined(D_CollSet_VariableDefine)
#define EXTERN extern
#else
#define EXTERN
#endif /* D_CollSet_VariableDefine */
 
#if defined(__cplusplus)
extern "C"
{
#endif /* __cplusplus */
 
/* various parameters set by the collisionning actor, used in the AI of the collided actor*/
#define C_wCollsetNbCollisionVectors 2
#define C_wCollsetNbCollisionReals	2
 
#if defined(D_CollSet_StructureDefine)
 
typedef struct tdstCollSet_
{
   ZDX_tdxHandleToZdxList  hZddList;
   ZDX_tdxHandleToZdxList  hZdeList;
   ZDX_tdxHandleToZdxList  hZdmList;
   ZDX_tdxHandleToZdxList  hZdrList;
   ZDX_tdxHandleToCsaList  hZddActivationList;
   ZDX_tdxHandleToCsaList  hZdeActivationList;
   ZDX_tdxHandleToCsaList  hZdmActivationList;
   ZDX_tdxHandleToCsaList  hZdrActivationList;
 
   /* Only to optimize call to GetCurrentZoneSet function*/
   ZDX_tdxHandleToZoneSetList    hZddCurrentActivation;
   ZDX_tdxHandleToZoneSetList    hZdeCurrentActivation;
   ZDX_tdxHandleToZoneSetList    hZdrCurrentActivation;
   ZDX_tdxHandleToZoneSetList    hZdmCurrentActivation;
 
#ifdef MAY_BE_SUPPRESSED
   ZDX_tdxHandleToZdxList  hInitialZddList;
   ZDX_tdxHandleToZdxList  hInitialZdeList;
   ZDX_tdxHandleToZdxList  hInitialZdmList;
   ZDX_tdxHandleToZdxList  hInitialZdrList;
   ZDX_tdxHandleToCsaList  hZddInitialActivationList;
   ZDX_tdxHandleToCsaList  hZdeInitialActivationList;
   ZDX_tdxHandleToCsaList  hZdmInitialActivationList;
   ZDX_tdxHandleToCsaList  hZdrInitialActivationList;
#endif /* MAY_BE_SUPPRESSED */
	unsigned long ulFBZddPriviligedZones;
	unsigned long ulFBZdePriviligedZones;
	unsigned long ulFBZdmPriviligedZones;
	unsigned long ulFBZdrPriviligedZones;
    unsigned char ucCollComputeFrequency;
 
    unsigned char ucCharacterPriority;
    unsigned char ucCollisionFlag;  /* 0 : collide only with map*/
 
	/*ANNECY BBB {*/
	/*internal variables for collision parameter management and communication*/
	struct stColliderInfo_
	{
		MTH3D_tdstVector	a_stColliderVectors[C_wCollsetNbCollisionVectors];
		MTH_tdxReal			a_xColliderReals[C_wCollsetNbCollisionReals];
		unsigned char		ucColliderType;
		/* if a collision is already registered, only higher a higher priority collision may replace it*/
		unsigned char		ucColliderPriority; /* 0 means that no collision is recorded*/
		unsigned char		a2_ucUnused[2];	/* alignment*/
	} stColliderInfo;
	/*ANNECY BBB }*/
} tdstCollSet;
#endif /* D_CollSet_StructureDefine */
 
M_BeginDeclareEnumerate(tdeCollSetPrivilegedActivation)
 edmPriviligedDefault		= 0x00,
 edmPriviligedActivated		= 0x01,
 edmPriviligedDisactivated	= 0x02,
 edmNumberOfPrivilegedActivation
M_EndDeclareEnumerate(tdeCollSetPrivilegedActivation,unsigned char)
 
/***********************/
/**** Handle define ****/
/***********************/
typedef struct tdstCollSet_ * MS_tdxHandleToCollSet;
 
/**** Put here all globals variables : ****/
/****    EXTERN typeofvar  variable;   ****/
 
/* CollSet Section*/
#define C_SectionCollSetDescription                      "CollSet"
/* CollSet Entries*/
#define C_EntryZdmTable                                  "ZdmTable"
#define C_EntryZddTable                                  "ZddTable"
#define C_EntryZdeTable                                  "ZdeTable"
#define C_EntryZdrTable                                  "ZdrTable"
#define C_EntryZddActivationTable                        "ZddActivationTable"
#define C_EntryZdeActivationTable                        "ZdeActivationTable"
#define C_EntryZdmActivationTable                        "ZdmActivationTable"
#define C_Entry_CharacterPriority                        "CharacterPriority"
#define C_EntryZdrActivationTable                        "ZdrActivationTable"
#define C_EntryCollisionFlag                             "CollisionFlag"
#define C_EntryCollComputeFrequency                      "CollComputeFrequency"
 
/* Macros*/
/* Macros*/
#define CS_M_GetZdxList(ZoneType,p_stCollSet)								((p_stCollSet)->h##ZoneType##List)
#define CS_M_SetZdxList(ZoneType,p_stCollSet,p_stZdxList)					((p_stCollSet)->h##ZoneType##List=p_stZdxList)
 
#ifdef MAY_BE_SUPPRESSED
   #define CS_M_GetZdxInitialList(ZoneType,p_stCollSet)						((p_stCollSet)->hInitial##ZoneType##List)
   #define CS_M_SetZdxInitialList(ZoneType,p_stCollSet,p_stZdxList)			((p_stCollSet)->hInitial##ZoneType##List=p_stZdxList)
#endif /* MAY_BE_SUPPRESSED */
 
#define CS_M_GetActivationList(ZoneType,p_stCollSet)						((p_stCollSet)->h##ZoneType##ActivationList)
#define CS_M_SetActivationList(ZoneType,p_stCollSet,hCsaList)				((p_stCollSet)->h##ZoneType##ActivationList=hCsaList)
 
#ifdef MAY_BE_SUPPRESSED
   #define CS_M_GetActivationInitialList(ZoneType,p_stCollSet)				((p_stCollSet)->h##ZoneType##InitialActivationList)
   #define CS_M_SetActivationInitialList(ZoneType,p_stCollSet,hCsaList)     ((p_stCollSet)->h##ZoneType##InitialActivationList=hCsaList)
#endif /* MAY_BE_SUPPRESSED */
 
#define CS_M_GetPrivilegedZone(ZoneType,p_stCollSet)						((p_stCollSet)->ulFB##ZoneType##PriviligedZones)
#define CS_M_SetPrivilegedZone(ZoneType,p_stCollSet,ulValue)				((p_stCollSet)->ulFB##ZoneType##PriviligedZones=ulValue)
 
#define CS_M_IsAllDefaultPrivilegedZones(ZoneType,p_stCollSet)				(CS_M_GetPrivilegedZone(ZoneType,p_stCollSet) == 0)
 
/*******************************/
/**** Base functions define ****/
/*******************************/
#if !defined(U64)
extern CPA_EXPORT SCR_tde_Anl_ReturnValue fn_eCollSetScriptCallBack(SCR_tdst_File_Description *_p_stFile,char *_p_szName,char *_ap_szParams[],SCR_tde_Anl_Action	_eAction);
#endif /* U64 */
/*extern CPA_EXPORT void fn_vCollSetSaveMiniStructure(SCRIPT_tdstSaveFile *p_stFile,struct tdstEngineObject_ *p_stObject);*/
extern CPA_EXPORT unsigned long fn_ulCollSetSizeOf();
extern CPA_EXPORT void fn_vCollSetAlloc(struct tdstEngineObject_ *p_stObject);
extern CPA_EXPORT MS_tdxHandleToCollSet fn_h_CollSetRealAlloc();
extern CPA_EXPORT void fn_vCollSetFree(struct tdstEngineObject_ *p_stObject);
extern CPA_EXPORT void fn_vCollSetInit(struct tdstEngineObject_ *p_stObject,enum tdeObjectTreeInit_ eObjectInit);
extern CPA_EXPORT void fn_vCollSetDesinit(struct tdstEngineObject_ *p_stObject,enum tdeObjectTreeInit_ eObjectInit);
extern CPA_EXPORT void fn_vCollSetCopyClone(struct tdstEngineObject_ * _p_stObjectDest,struct tdstEngineObject_ * _p_stObjectSrc);
 
/*********************************/
/**** Access functions define ****/
/*********************************/
/*ANNECY BBB {*/
extern CPA_EXPORT unsigned char fn_ucCollSetGetColliderPriority(MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT unsigned char fn_ucCollSetGetColliderPrioritySO (HIE_tdxHandleToSuperObject _hSuperObject);
extern CPA_EXPORT unsigned char fn_ucCollSetGetColliderType(MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT MTH3D_tdstVector fn_stCollSetGetColliderVector(MS_tdxHandleToCollSet _hCollSet, short _wIndex);
extern CPA_EXPORT MTH_tdxReal fn_xCollSetGetColliderReal(MS_tdxHandleToCollSet _hCollSet, short _wIndex);
extern CPA_EXPORT void fn_vCollSetSetColliderPriority(MS_tdxHandleToCollSet _hCollSet, unsigned char _ucPri);
extern CPA_EXPORT void fn_vCollSetSetColliderType(MS_tdxHandleToCollSet _hCollSet, unsigned char _ucType);
extern CPA_EXPORT void fn_vCollSetSetColliderVector(MS_tdxHandleToCollSet _hCollSet, short _wIndex, MTH3D_tdstVector *_p_stVector);
extern CPA_EXPORT void fn_vCollSetSetColliderReal(MS_tdxHandleToCollSet _hCollSet, short _wIndex, MTH_tdxReal _xReal);
/*ANNECY BBB }*/
 
/* Functions with Handles*/
extern CPA_EXPORT ZDX_tdxHandleToZdxList CS_fn_hGetZdxList(unsigned char ucZoneType,HIE_tdxHandleToSuperObject hSuperObj);
extern CPA_EXPORT void CS_fn_vSetZdxList(unsigned char ucZoneType,HIE_tdxHandleToSuperObject hSuperObj,ZDX_tdxHandleToZdxList);
 
extern CPA_EXPORT ZDX_tdxHandleToCsaList CS_fn_hGetActivationList(unsigned char ucZoneType,HIE_tdxHandleToSuperObject hSuperObj);
extern CPA_EXPORT void CS_fn_vSetActivationList(unsigned char ucZoneType,HIE_tdxHandleToSuperObject hSuperObj,ZDX_tdxHandleToCsaList);
 
extern CPA_EXPORT ZDX_tdxHandleToCsaList CS_fn_hGetActivationListInCollSet(unsigned char ucZoneType,MS_tdxHandleToCollSet hCollSet);
extern CPA_EXPORT void CS_fn_vSetActivationListInCollSet(unsigned char ucZoneType,MS_tdxHandleToCollSet hCollSet,ZDX_tdxHandleToCsaList);
 
extern CPA_EXPORT unsigned char CS_fn_ucGetCharacterPriority(MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT void CS_fn_vSetCharacterPriority(MS_tdxHandleToCollSet hCollSet,unsigned char _ucPriority);
extern CPA_EXPORT void fn_vCorrectAllActivationLists(struct tdstEngineObject_ * _p_stObject);
 
/* ANNECY AV {*/
extern CPA_EXPORT unsigned char fn_ucCollSetGetCharacterCollisionFlag(MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT void fn_vCollSetSetCharacterCollisionFlag(MS_tdxHandleToCollSet _hCollSet,unsigned char _ucCollisionFlag);
extern CPA_EXPORT ACP_tdxBool fn_bCollSetGetCharacterNoCollisionWithMap                (MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT ACP_tdxBool fn_bCollSetGetCharacterNoCollisionWithProjectile         (MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT ACP_tdxBool fn_bCollSetGetCharacterNoCollisionWithSecondaryCharacter (MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT ACP_tdxBool fn_bCollSetGetCharacterNoCollisionWithMainCharacter      (MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT ACP_tdxBool fn_bCollSetGetCharacterForceCollisionWhenNotMoving       (MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT ACP_tdxBool fn_bCollSetGetCharacterNoCollisionWithOtherSectors       (MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT ACP_tdxBool fn_bCollSetGetCharacterNoCollisionZdeWithProjectile      (MS_tdxHandleToCollSet _hCollset);
extern CPA_EXPORT void        fn_vCollSetSetCharacterNoCollisionWithMap                (MS_tdxHandleToCollSet _hCollSet, ACP_tdxBool _bValue);
extern CPA_EXPORT void        fn_vCollSetSetCharacterNoCollisionWithProjectile         (MS_tdxHandleToCollSet _hCollSet, ACP_tdxBool _bValue);
extern CPA_EXPORT void        fn_vCollSetSetCharacterNoCollisionWithSecondaryCharacter (MS_tdxHandleToCollSet _hCollSet, ACP_tdxBool _bValue);
extern CPA_EXPORT void        fn_vCollSetSetCharacterNoCollisionWithMainCharacter      (MS_tdxHandleToCollSet _hCollSet, ACP_tdxBool _bValue);
extern CPA_EXPORT void        fn_vCollSetSetCharacterForceCollisionWhenNotMoving       (MS_tdxHandleToCollSet _hCollSet, ACP_tdxBool _bValue);
extern CPA_EXPORT void        fn_vCollSetSetCharacterNoCollisionWithOtherSectors       (MS_tdxHandleToCollSet _hCollSet, ACP_tdxBool _bValue);
extern CPA_EXPORT void        fn_vCollSetSetCharacterNoCollisionZdeWithProjectile      (MS_tdxHandleToCollSet _hCollSet, ACP_tdxBool _bValue);
 
/* Same access functions with a super object for the DNM module*/
extern CPA_EXPORT ACP_tdxBool fn_bGetCharacterNoCollisionWithMap                       (HIE_tdxHandleToSuperObject _hSuperObject);
extern CPA_EXPORT ACP_tdxBool fn_bGetCharacterForceCollisionWhenNotMoving              (HIE_tdxHandleToSuperObject _hSuperObject);
extern CPA_EXPORT void        fn_vSetCharacterNoCollisionWithMap                       (HIE_tdxHandleToSuperObject _hSuperObject, ACP_tdxBool _bValue);
/* END ANNECY AV }*/
 
extern CPA_EXPORT void fn_vCollSetSetCollComputeFrequency(MS_tdxHandleToCollSet _hCollSet,unsigned char _ucFrequency);
extern CPA_EXPORT unsigned char fn_ucCollSetGetCollComputeFrequency(MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT unsigned char fn_ucCollSetGetCollComputeFrequencySO(HIE_tdxHandleToSuperObject hSuperObj);
 
extern CPA_EXPORT void GAM_fn_vChangeFather(HIE_tdxHandleToSuperObject _hSprObj, HIE_tdxHandleToSuperObject _hNewFather);
 
/* JO 20/10/97 for optimisation*/
void fn_vSetCurrentZoneSetOfType(unsigned char _ucZoneType,MS_tdxHandleToCollSet _hCollSet,ZDX_tdxHandleToZoneSetList _hCurrentZoneSet);
ZDX_tdxHandleToZoneSetList fn_hGetCurrentZoneSetOfType(unsigned char _ucZoneType,MS_tdxHandleToCollSet _hCollSet);
 
#ifdef MAY_BE_SUPPRESSED
 
   extern CPA_EXPORT ZDX_tdxHandleToZdxList CS_fn_hGetZdxInitialList(unsigned char ucZoneType,HIE_tdxHandleToSuperObject hSuperObj);
   extern CPA_EXPORT void CS_fn_vSetZdxInitialList(unsigned char ucZoneType,HIE_tdxHandleToSuperObject hSuperObj,ZDX_tdxHandleToZdxList);
 
   extern CPA_EXPORT ZDX_tdxHandleToCsaList CS_fn_hGetActivationInitialList(unsigned char ucZoneType,HIE_tdxHandleToSuperObject hSuperObj);
   extern CPA_EXPORT void CS_fn_vSetActivationInitialList(unsigned char ucZoneType,HIE_tdxHandleToSuperObject hSuperObj,ZDX_tdxHandleToCsaList);
 
   extern CPA_EXPORT ZDX_tdxHandleToZdxList CS_fn_hGetZdxInitialListInCollSet(unsigned char ucZoneType,MS_tdxHandleToCollSet hCollSet);
   extern CPA_EXPORT void CS_fn_vSetZdxInitialListInCollSet(unsigned char ucZoneType,MS_tdxHandleToCollSet hCollSet,ZDX_tdxHandleToZdxList);
 
   extern CPA_EXPORT ZDX_tdxHandleToCsaList CS_fn_hGetActivationInitialListInCollSet(unsigned char ucZoneType,MS_tdxHandleToCollSet hCollSet);
   extern CPA_EXPORT void CS_fn_vSetActivationInitialListInCollSet(unsigned char ucZoneType,MS_tdxHandleToCollSet hCollSet,ZDX_tdxHandleToCsaList);
 
   extern CPA_EXPORT ZDX_tdxHandleToZdxList CS_fn_hGetZdxListInCollSet(unsigned char ucZoneType,MS_tdxHandleToCollSet hCollSet);
   extern CPA_EXPORT void CS_fn_vSetZdxListInCollSet(unsigned char ucZoneType,MS_tdxHandleToCollSet hCollSet,ZDX_tdxHandleToZdxList);
 
#endif /* MAY_BE_SUPPRESSED */
 
extern CPA_EXPORT unsigned long CS_fn_ulGetPrivilegedActivationZoneInCollSet(unsigned char _ucZoneType,MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT void			CS_fn_vSetPrivilegedActivationZoneInCollSet(unsigned char _ucZoneType,MS_tdxHandleToCollSet _hCollSet, unsigned long _ulFB);
 
extern CPA_EXPORT void			CS_fn_vSetPrivilegedActivationZone(unsigned char _ucZoneType,MS_tdxHandleToCollSet _hCollSet,short _wIndex, tdeCollSetPrivilegedActivation _ePrivilege);
extern CPA_EXPORT tdeCollSetPrivilegedActivation CS_fn_eGetPrivilegedActivationZone(unsigned char _ucZoneType,MS_tdxHandleToCollSet _hCollSet,short _wIndex);
 
/**********************/
/**** SAI function ****/
/**********************/
extern CPA_EXPORT void fn_vCollSetInitValueSAI(MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT void fn_vCollSetSavedValueSAI(MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT void fn_vCollSetFreeInitValueSAI(MS_tdxHandleToCollSet _hCollSet);
 
extern CPA_EXPORT void fn_vCollSetReInitCharacterCollisionFlag(MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT void fn_vCollSetReInitCollComputeFrequency(MS_tdxHandleToCollSet _hCollSet);
/**********************************/
/**** Special functions define ****/
/**********************************/
 
#ifdef ACTIVE_EDITOR
 
extern CPA_EXPORT unsigned char *fn_p_ucCollSetGetCharacterCollisionFlagInit(MS_tdxHandleToCollSet _hCollSet);
extern CPA_EXPORT unsigned char *fn_p_ucCollSetGetCollComputeFrequencyInit(MS_tdxHandleToCollSet _hCollSet);
 
#endif /* ACTIVE_EDITOR */
 
#if defined(__cplusplus)
}
#endif /* __cplusplus */
 
#endif /* __CollSet_H__ */
 
