/*
 * Loading of differents Zdx Tables in a global structure
 * (Csa means CollSetChoice Array)
 */
#ifndef __ZDXSTUFF_H
#define __ZDXSTUFF_H
 
/******************************************/
#if _MSC_VER >= 1000
#pragma once
#endif /* _MSC_VER >= 1000 */
/******************************************/
 
#include "GAM/Header.h"
 
#if defined(__cplusplus)
extern "C"
{
#endif /* __cplusplus */
 
/* ANNECY AV NONEVER {*/
/* EXTERN ACP_tdxHandleOfObject g_hNeverMovingZDM; */
/* END ANNECY AV NONEVER }*/
 
#define C_MaxLengthOfName     20
 
#define C_lAllZdxAreOn           0xFFFFFFFF
#define C_lModuleZdxAreOn        1
#define C_lCharacterZdxAreOn     2
#define C_lZdeAreOn              4
#define C_lZddAreOn              8
#define C_lZdrAreOn              16
#define C_lZdmAreOn              32
 
/*----------------------------------------------------------------------
 * Handles
 *--------------------------------------------------------------------*/
typedef struct tdstGeometricZdxList_ *       ZDX_tdxHandleToGeoZdxList;
typedef struct tdstZdxIndexList_ *           ZDX_tdxHandleToZdxIndexList;
typedef struct tdstZoneSetEncapsulation_ *   ZDX_tdxHandleToZoneSetEncapsulation;
 
LST2_M_StaticUseListOf(ZDX_tdxHandleToGeoZdxList);
LST2_M_StaticUseListOf(ZDX_tdxHandleToZoneSetList);
LST2_M_StaticUseListOf(ZDX_tdxHandleToZdxIndexList);
LST2_M_StaticUseListOf(ZDX_tdxHandleToZoneSetEncapsulation);
 
 
#ifdef D_ZdxStuff_StructureDefine
/*----------------------------------------------------------------------
 * Structures
 *--------------------------------------------------------------------*/
typedef struct tdstCsaList_
{
   LST2_M_StaticAnchorDeclaration(ZDX_tdxHandleToZoneSetEncapsulation) hZoneSetEncapsulationList;
 
} tdstCsaList;
/*--------------------------------------------------------------------*/
typedef struct tdstZdxList_ 
{
   LST2_M_StaticAnchorDeclaration(ZDX_tdxHandleToGeoZdxList) hGeoZdxList;
   unsigned short uwNumberOfZdx;
   
} tdstZdxList;
/*--------------------------------------------------------------------*/
typedef struct tdstGeometricZdxList_
{
   LST2_M_StaticElementDeclaration(ZDX_tdxHandleToGeoZdxList)
   ACP_tdxHandleOfObject hGeoObj;
 
} tdstGeometricZdxList;
/*--------------------------------------------------------------------*/
typedef struct tdstZoneSetList_
{
   LST2_M_StaticAnchorDeclaration(ZDX_tdxHandleToZdxIndexList) hZdxIndexList;
 
} tdstZoneSetList;
/*--------------------------------------------------------------------*/
typedef struct tdstZdxIndexList_
{
   LST2_M_StaticElementDeclaration(ZDX_tdxHandleToZdxIndexList)
   unsigned short uwZdxIndex;
 
} tdstZdxIndexList;
/*--------------------------------------------------------------------*/
/*
 * This structure is added for binarisation
 */
typedef struct tdstZoneSetEncapsulation_
{
   LST2_M_StaticElementDeclaration(ZDX_tdxHandleToZoneSetEncapsulation)
   tdstZoneSetList * p_stZoneSetList;
/* Oliv' - 21/06/1999 */
#ifndef D_THROW_ZSE_INDEX
   unsigned short uwIndex;
#endif
/* EndOfOliv' */
} tdstZoneSetEncapsulation;
/*--------------------------------------------------------------------*/
#endif /* D_ZdxStuff_StructureDefine */
/*----------------------------------------------------------------------
 * Sections
 *--------------------------------------------------------------------*/
#define C_SectionCreateNewArrayOfZdx         "CreateNewArrayOfZdx"
#define C_SectionCreateNewZoneSetArray       "CreateNewArrayOfZoneSet"
/* MR0404*/
#define C_SectionNewActivationZone			 "NewActivationZone"
/* JO 22/04/97 */
#define C_SectionPhysicalCollideSetDescription     "Physical_CollSet"
/* JO 15/07/97*/
#define C_SectionAddActivation              "AddActivation"
/*----------------------------------------------------------------------
 * Entries
 *--------------------------------------------------------------------*/
#define C_EntryGeometricObject               "GeometricObject"
#define C_EntryNewCollSet                    "NewCollSet"
#define C_EntryEndCollSet                    "EndCollSet"
#define C_EntryNewZdd                        "Zdd"
#define C_EntryNewZdm                        "Zdm"
#define C_EntryNewZde                        "Zde"
#define C_EntryNewZdr                        "Zdr"
#define C_EntryNewIndex                      "ZdxIndex"
#define C_EntryActivationZone				 "ActivationZone"
/*----------------------------------------------------------------------
 * Miscellaneous
 *--------------------------------------------------------------------*/
#define C_szTypeZdd                          "Zdd"
#define C_szTypeZdm                          "Zdm"
#define C_szTypeZde                          "Zde"
#define C_szTypeZdr                          "Zdr"
 
#define C_ucTypeZdd                          (unsigned char)0
#define C_ucTypeZdm                          (unsigned char)1
#define C_ucTypeZde                          (unsigned char)2
#define C_ucTypeZdr                          (unsigned char)3
/*----------------------------------------------------------------------
 * CallBacks
 *--------------------------------------------------------------------*/
#if !defined(U64)
SCR_tde_Anl_ReturnValue fn_eScriptCallBackZdxArrayDescription(SCR_tdst_File_Description *_p_stFile,char *_p_szName,char *_ap_szParams[],SCR_tde_Anl_Action	_eAction);
SCR_tde_Anl_ReturnValue fn_eScriptCallBackCreateNewZoneSetArray(SCR_tdst_File_Description *_p_stFile,char *_p_szName,char *_ap_szParams[],SCR_tde_Anl_Action	_eAction);
/* MR0404*/
SCR_tde_Anl_ReturnValue fn_eScriptCallBackCreateNewActivationZone(SCR_tdst_File_Description *_p_stFile,char *_p_szName,char *_ap_szParams[],SCR_tde_Anl_Action	_eAction);
/* JO 15/07/97*/
SCR_tde_Anl_ReturnValue fn_eScriptCallBackCreateActivation(SCR_tdst_File_Description *_p_stFile,char *_p_szName,char *_ap_szParams[],SCR_tde_Anl_Action	_eAction);
#endif /* U64 */
 
/*----------------------------------------------------------------------
 * Memory management functions
 *--------------------------------------------------------------------*/
extern CPA_EXPORT ZDX_tdxHandleToZdxList      fn_p_stCreateZdxListElement();
extern CPA_EXPORT ZDX_tdxHandleToZdxIndexList fn_p_stCreateZdxIndexListElement();
extern CPA_EXPORT ZDX_tdxHandleToGeoZdxList   fn_p_stCreateGeometricZdxListElement();
extern CPA_EXPORT ZDX_tdxHandleToZoneSetList  fn_p_stCreateZoneSetListElement();
extern CPA_EXPORT ZDX_tdxHandleToCsaList      fn_p_stCreateCsaListElement();
extern CPA_EXPORT void fn_vFreeZdxListElement(ZDX_tdxHandleToZdxList p_stZdxList);
extern CPA_EXPORT void fn_vFreeZdxIndexListElement(ZDX_tdxHandleToZdxIndexList p_stZdxIndexList);
extern CPA_EXPORT void fn_vFreeGeometricZdxListElement(ZDX_tdxHandleToGeoZdxList p_stGeoZdxList);
extern CPA_EXPORT void fn_vFreeZoneSetListElement(ZDX_tdxHandleToZoneSetList p_stZoneSetList);
extern CPA_EXPORT void fn_vFreeCsaListElement(ZDX_tdxHandleToCsaList p_stCsaList);
/* JO 24/09/97*/
extern CPA_EXPORT ZDX_tdxHandleToZoneSetEncapsulation fn_p_stCreateZoneSetEncapsulation();
extern CPA_EXPORT void fn_vFreeZoneSetEncapsulation(ZDX_tdxHandleToZoneSetEncapsulation);
/*----------------------------------------------------------------------
 * Access functions
 *--------------------------------------------------------------------*/
extern CPA_EXPORT unsigned short                 fn_uwGetNumberOfGeoObjInList(ZDX_tdxHandleToZdxList hZdxList);
/*--------------------------------------------------------------------*/
long fn_lGetZdxListNumberOfElements(unsigned char ucZoneType,HIE_tdxHandleToSuperObject hSuperObj);
/*--------------------------------------------------------------------*/
/*** tdstGeometricZdxList ***/
extern CPA_EXPORT ACP_tdxHandleOfObject fn_hGetGeoObjFromGeoZdx(ZDX_tdxHandleToGeoZdxList hGeoZdxList);
extern CPA_EXPORT void                  fn_vSetGeoObjInGeoZdx(ZDX_tdxHandleToGeoZdxList hGeoZdxList,ACP_tdxHandleOfObject hGeoObj);
/*--------------------------------------------------------------------*/
/*** tdstZdxIndexList ***/
extern CPA_EXPORT unsigned short fn_uwGetIndexFromZdxIndexList(struct tdstZdxIndexList_ * p_stZdxIndexList);
extern CPA_EXPORT ZDX_tdxHandleToZdxIndexList ZDX_fn_hGetNextBrotherInZdxIndexList(ZDX_tdxHandleToZdxIndexList hZdxIndexList);
/*--------------------------------------------------------------------*/
/*** Mixed access functions ***/
/* JO 20/10/97 for optimisation*/
extern CPA_EXPORT ZDX_tdxHandleToZoneSetList fn_p_stGetCurrentZoneSetOfType2(unsigned char ucZoneType,HIE_tdxHandleToSuperObject hSuperObj);
extern CPA_EXPORT void fn_vUpdateCurrentActivationForCharacter(HIE_tdxHandleToSuperObject _hCharacter);
 
extern CPA_EXPORT ZDX_tdxHandleToZoneSetList fn_p_stGetCurrentZoneSetOfType(unsigned char ucZoneType,HIE_tdxHandleToSuperObject hSuperObj);
extern CPA_EXPORT unsigned short             fn_uwGetIndexOfZdx(unsigned char ucZoneNumber,struct tdstZoneSetList_ * p_stZoneSetList);
extern CPA_EXPORT void                       fn_vSetGeometricZdxOfTypeAtIndex(unsigned char ucZoneType,unsigned short uwIndex,HIE_tdxHandleToSuperObject hSuperObj,ACP_tdxHandleOfObject hGeoObj);
extern CPA_EXPORT ACP_tdxHandleOfObject      fn_hGetGeometricZdxOfTypeAtIndex(unsigned char ucZoneType,unsigned short uwIndex,HIE_tdxHandleToSuperObject hSuperObj);
extern CPA_EXPORT void                       ZDX_fn_vDisplayAllZdx(GLD_tdstViewportAttributes * p_stViewPort,HIE_tdxHandleToSuperObject p_stSupObject);
/*ANNECY TQ 11/03/98{*/
extern CPA_EXPORT void                       ZDX_fn_vDisplayAllBoundingVolumes(GLD_tdstViewportAttributes * p_stViewPort,HIE_tdxHandleToSuperObject p_stSupObject);
/*ENDANNECY TQ}*/
/*--------------------------------------------------------------------*/
/*** Access functions for editors ***/
extern CPA_EXPORT ACP_tdxHandleOfObject      ZDX_fn_hGetGeometricZdxInListAtIndex(unsigned short uwIndex,ZDX_tdxHandleToZdxList hZdxList);
extern CPA_EXPORT void                       ZDX_fn_vSetGeometricZdxInListAtIndex(unsigned short uwIndex,ZDX_tdxHandleToZdxList hZdxList,ACP_tdxHandleOfObject hGeoObj);
extern CPA_EXPORT ZDX_tdxHandleToZdxList     ZDX_fn_hCreateEmptyListOftype(unsigned char ucZonetype,unsigned short uwNumberOfElements);
extern CPA_EXPORT ZDX_tdxHandleToZdxIndexList ZDX_fn_hGetFirstZdxIndexListOfTypeInZoneSet(unsigned char ucZoneType,ZDX_tdxHandleToZoneSetList hZoneSet);
extern CPA_EXPORT ZDX_tdxHandleToZdxList     ZDX_fn_hCreateEmptyListOftype(unsigned char ucZonetype,unsigned short uwNumberOfElements);
#ifdef ACTIVE_EDITOR
extern CPA_EXPORT void ZDX_fn_vDestructZdxList(ZDX_tdxHandleToZdxList hZdxList);
#endif /* ACTIVE_EDITOR */
/*--------------------------------------------------------------------*/
/*** New for convenience... ***/
ACP_tdxHandleOfObject ZDX_fn_hGetGeoObjOfTypeAndMatrixFromZdxInfos(
            HIE_tdxHandleToSuperObject _hCharacter,
            unsigned char _ucZoneType,
            unsigned char _ucModuleOrCharacter,
            unsigned char _ucChannelNumber,
            POS_tdstCompletePosition ** _p_hMatrix);
 
/*--------------------------------------------------------------------
 * Return Game Material if this type exist, NULL if can't find it
 *--------------------------------------------------------------------*/
GMT_tdxHandleToGameMaterial fn_hIsTypeExistsInGeoObj(ACP_tdxHandleOfObject _hGeoObj,GMT_tdxMask _wMaterialMask);
 
/*--------------------------------------------------------------------*/
/*** Functions to use Zde ***/
ACP_tdxBool fn_bIsThisModuleZdeInContactWithZdeOfTypes(HIE_tdxHandleToSuperObject _hSuperObj,unsigned short  _uwChannelNumber,GMT_tdxMask wMaterialMask);
ACP_tdxBool fn_bIsThisZdeInClashWithCharacterZdeOfTypes(ACP_tdxHandleOfObject _hGeoObj,POS_tdstCompletePosition * _hMatrix,HIE_tdxHandleToSuperObject _hCharacter,GMT_tdxMask wMaterialMask);
/*** New request from design ***/
void fn_vGetAllCharactersInContactWithThisZde(HIE_tdxHandleToSuperObject _hSuperObj,unsigned char _ucModuleOrCharacter,unsigned char _ucChannelNumber,HIE_tdxHandleToSuperObject * _hSuperObjTable,unsigned short * _p_wNumber,GMT_tdxMask _wMaterialMask);
 
void fn_vGetAllCharactersInContactWithThisModuleZde(
            HIE_tdxHandleToSuperObject _hSuperObj,
            unsigned char _ucChannelNumber,
            HIE_tdxHandleToSuperObject * _hSuperObjTable,
            GMT_tdxMask _wMaterialMask,
            long _lMaxNumberOfObjects,
            long * _p_lCurrentNumberOfObjects);
 
void fn_vGetAllCharacterInContactWithThisGeoObj(
            HIE_tdxHandleToSuperObject _hSuperObj,
            ACP_tdxHandleOfObject _hGeoObj,
            POS_tdstCompletePosition * _hMatrix,
            HIE_tdxHandleToSuperObject * _hSuperObjTable,
            GMT_tdxMask _wMaterialMask,
            long _lMaxNumberOfObjects,
            long * _p_lCurrentNumberofObjects);
 
ACP_tdxBool fn_bCharacterOwnsZdeOfType(HIE_tdxHandleToSuperObject _hCharacter,GMT_tdxMask _wMaterialMask);
ACP_tdxBool fn_bIsTypeExistsInGeoObj(ACP_tdxHandleOfObject _hGeoObj,GMT_tdxMask _wMaterialMask);
/*** New request from AI ***/
ACP_tdxBool fn_bThisZdeFromOneVsAllZdeFromTwo(
            HIE_tdxHandleToSuperObject _hCharacterONE,
            unsigned char _ucModuleOrCharacter,
            unsigned char _ucChannelNumber,
            HIE_tdxHandleToSuperObject _hCharacterTWO,
            GMT_tdxMask _wMaterialMask);
/*** Re-New request from AI (oh yes) ***/
ACP_tdxBool fn_bThisZdeFromOneVsThisZdeFromTwo(
            HIE_tdxHandleToSuperObject _hCharacterONE,
            unsigned char _ucModuleOrCharacterForONE,
            unsigned char _ucChannelNumberForONE,
            HIE_tdxHandleToSuperObject _hCharacterTWO,
            unsigned char _ucModuleOrCharacterForTWO,
            unsigned char _ucChannelNumberForTWO);
 
ACP_tdxBool fn_bThisTypeFromOneVsThisTypeFromTwo(
            HIE_tdxHandleToSuperObject _hCharacterONE,
            GMT_tdxMask _wMaterialMaskOfONE,
            HIE_tdxHandleToSuperObject _hCharacterTWO,
            GMT_tdxMask _wMaterialMaskOfTWO);
 
void fn_vThisTypeVsThisType(
            HIE_tdxHandleToSuperObject _hCharacter,
            GMT_tdxMask _wCharacterMask,
            GMT_tdxMask _wOthersMask,
            HIE_tdxHandleToSuperObject * _p_hObjectTable,
            unsigned short * _p_uwNumber);
 
/*--------------------------------------------------------------------*/
/*** Coz Physical Collide Set is now a CPA module ***/
void fn_vDetectAllObjectsInThisModule(
            HIE_tdxHandleToSuperObject _hCharacter,
            ACP_tdxHandleOfObject _hModule,
            POS_tdstCompletePosition * _p_stMatrix,
            HIE_tdxHandleToSuperObject * _p_hSuperObjTable,
            long _lMaxNumberOfObjects,
            long * _p_lCurrentNumberOfObjects);
 
PCS_tdxHandleToPhysicalCollSet fn_pGetPhysicalCollSet(HIE_tdxHandleToSuperObject hSuperObj,unsigned char ucChannelNumber,unsigned char ucSubChannelNumber,POS_tdstCompletePosition * p_stMatrix);
ACP_tdxHandleOfObject fn_hGetGeoObjOfZdm(HIE_tdxHandleToSuperObject hSuperObj,unsigned char ucChannelNumber,unsigned char ucSubChannelNumber);
HIE_tdxHandleToSuperObject * fn_pGetObjectsInZone (HIE_tdxHandleToSuperObject hObj,long lIndex,unsigned short * uwnb);
 
#if !defined(U64)
SCR_tde_Anl_ReturnValue fn_eScriptCallBackPhysicalCollideSetDescription(SCR_tdst_File_Description *_p_stFile,char *_p_szName,char *_ap_szParams[],SCR_tde_Anl_Action	_eAction);
#endif /* U64 */
 
/*** New request from AI ***/
ACP_tdxBool fn_bIsCharacterTWODetectedByThisZddOfCharacterOne(
            HIE_tdxHandleToSuperObject _hCharacterONE,
            unsigned char _ucModuleOrCharacter,
            unsigned char _ucChannelNumber,
            HIE_tdxHandleToSuperObject _hCharacterTWO);
ACP_tdxBool fn_bIsCharacterTWODetectedByCharacterOne(
            HIE_tdxHandleToSuperObject _hCharacterONE,
            HIE_tdxHandleToSuperObject _hCharacterTWO);
 
void fn_vFirstTimeInitCollisionGeometricObject();
 
void fn_vClearCollisionGeometricObject(void);
void fn_vClearStaticCollisionGeometricObject(void);
 
ACP_tdxHandleOfObject fn_hStaticMakeOneObjectFromManyZdx(
            unsigned char _ucZoneType,
            HIE_tdxHandleToSuperObject _hCharacter);
 
ACP_tdxHandleOfObject fn_hMakeOneObjectFromManyZdx(
            unsigned char _ucZoneType,
            HIE_tdxHandleToSuperObject _hCharacter);
 
ACP_tdxHandleOfObject fn_hMakeOneObjectFromManyOthers(
            unsigned char _ucZoneType,
            HIE_tdxHandleToSuperObject _hCharacter,
			ACP_tdxHandleOfObject _hTargetObject);
 
EXTERN ACP_tdxHandleOfObject g_hCollisionGeoObj;
EXTERN ACP_tdxHandleOfObject g_hStaticCollisionGeoObj;
/* ANNECY AV {*/
/*EXTERN ACP_tdxHandleOfObject g_hZdrCollisionGeoObj;*/
/* END ANNECY AV }*/
 
/*--------------------------------------------------------------------*/
/*** Zdx drawing management for one character ***/
extern CPA_EXPORT void fn_vSetActivationOfModuleZdxDrawing(
   HIE_tdxHandleToSuperObject _hCharacter,
   ACP_tdxBool _bState);
extern CPA_EXPORT void fn_vSetActivationOfCharacterZdxDrawing(
   HIE_tdxHandleToSuperObject _hCharacter,
   ACP_tdxBool _bState);
extern CPA_EXPORT void fn_vSetActivationOfZoneTypeDrawing(
   HIE_tdxHandleToSuperObject _hCharacter,
   ACP_tdxBool _bState,
   unsigned char _ucZoneType);
extern CPA_EXPORT void fn_vUnactivateAllZdxDisplay(
   HIE_tdxHandleToSuperObject _hCharacter);
extern CPA_EXPORT void fn_vActivateAllZdxDisplay(
   HIE_tdxHandleToSuperObject _hCharacter);
/*--------------------------------------------------------------------*/
/*** Zdx drawing management for all characters ***/
extern CPA_EXPORT void fn_vSetActivationOfModuleZdxDrawingForAllCharacters(
   ACP_tdxBool _bState);
extern CPA_EXPORT void fn_vSetActivationOfCharacterZdxDrawingForAllCharacters(
   ACP_tdxBool _bState);
extern CPA_EXPORT void fn_vUnactivateAllZdxDisplayForAllCharacters(void);
extern CPA_EXPORT void fn_vActivateAllZdxDisplayForAllCharacters(void);
extern CPA_EXPORT void fn_vSetActivationOfZoneTypeDrawingForAllCharacters(
   ACP_tdxBool _bState,unsigned char _ucZoneType);
/*--------------------------------------------------------------------*/
/*** Special functions to test integrity of Activation Lists ***/
extern CPA_EXPORT void fn_vCorrectActivationList(
   ZDX_tdxHandleToCsaList _p_stCsaList,long _lNumberOfState);
/*--------------------------------------------------------------------*/
/*** Functions used for tests in the console ***/
/* ANNECY AV {*/
/* Not used anymore
ACP_tdxBool GAM_fn_bTestZoneDisplacement  (HIE_tdxHandleToSuperObject _hCharacter,
                                           unsigned char _ucZoneType,
                                           long _lZoneNumber,
                                           MTH3D_tdstVector * _p_stDisplacement);
*/
/* END ANNECY AV }*/
 
/*--------------------------------------------------------------------*/
/*** Function to order ZoneSetList by index ***/
extern CPA_EXPORT void GAM_fn_vOrderZoneSetList(ZDX_tdxHandleToZoneSetList _hZoneSetList);
 
tdeCollSetPrivilegedActivation fn_eGetPrivilegedActivationZoneOfCharacter(
	unsigned char _ucZoneType,
    HIE_tdxHandleToSuperObject _hCharacter,
    ACP_tdxIndex _xIndex);
 
ACP_tdxBool fn_bIsAllDefaultPrivilegedActivationZoneOfCharacter(
	unsigned char _ucZoneType,
    HIE_tdxHandleToSuperObject _hCharacter);
 
/*--------------------------------------------------------------------*/        
/*#define ZDX_M_ForEachZdxIndexListOfTypeInZoneSet(_ZoneType,_hZoneSet,_hZdxIndexList,_i) \
for														\
(														\
	_i=0,(_hZdxIndexList)=ZDX_fn_hGetFirstZdxIndexListOfTypeInZoneSet(_ZoneType,_hZoneSet);		\
	_hZdxIndexList;									\
	_i++,(_hZdxIndexList)=ZDX_fn_hGetNextBrotherInZdxIndexList(_hZdxIndexList)			\
)*/
/* AR9808 This macro wasn't valid for optimized static lists*/
#define ZDX_M_ForEachZdxIndexListOfTypeInZoneSet(_ZoneType,_hZoneSet,_hZdxIndexList,_i) \
	LST2_M_StaticForEachElementOf(&_hZoneSet->hZdxIndexList, _hZdxIndexList, _i)
 
 
/*--------------------------------------------------------------------
 * Return geometric zone if active, NULL if inactive
 *--------------------------------------------------------------------*/
ACP_tdxHandleOfObject fn_hIsThisZoneActive(
   HIE_tdxHandleToSuperObject _hCharacter,
   unsigned char _ucZoneType,
   unsigned char _ucZoneNumber);
 
#if defined(__cplusplus)
}
#endif /* __cplusplus */
 
#endif /* __ZDXSTUFF_H */
