/*---------------------------------------------------------------------------*/
/* list.h : perso list for AI.*/
/* author : Olivier Couvreur  28/11/1997*/
/*---------------------------------------------------------------------------*/
 
#if !defined(__LIST_H__)
#define __LIST_H__
 
/* Function Prototypes for List of perso*/
/*///////////////////////////////////////*/
#define C_ucSizeOfMinimalList 2
#define C_ucSizeOfMaximalList 30 /* the biggest list can have only C_ucSizeOfMaximalList */
#define C_ucEndOfList 255
 
#define C_TypeOfPersoInList		HIE_tdxHandleToSuperObject 
#define C_SizeOfPersoInList		(sizeof (C_TypeOfPersoInList))
 
#define C_TypeOfList1			struct tdstList1_
#define C_SizeOfList1			(sizeof (C_TypeOfList1))
 
/* Macros*/
/*************/
#define M_Min(a,b) (((a)>(b)) ? (b) : (a))
 
/* Macros for List of perso*/
/*//////////////////////////*/
#define M_bListEmptyTest(p_List) (((p_List)->ucNbElt) == 0)
 
#define M_ucNbEltInList(p_List) ((p_List)->ucNbElt)
#define M_ucGetMaxSizeOfList(p_List) ((p_List)->ucMaxSize)
 
#define M_ClearList(p_List) (p_List)->ucNbElt = 0;
 
#define M_InitList(p_List, ucNbEltMax) \
{\
	M_ClearList(p_List);\
	(p_List)->ucMaxSize = ucNbEltMax;\
}
 
/*Only for debug !!y!!*/
#define M_Init3List(p_List) (p_List)->ucNbElt = 3;
 
/*Scan every perso in a list in order to read or modif the list.*/
#define M_InitScanList(p_List, p_p_Perso) p_p_Perso=p_List->d_TabElt
#define M_EndingCondScanList(p_List, p_p_Perso) (p_p_Perso < (p_List->d_TabElt + p_List->ucNbElt))
#define M_GoNextScanList(p_List, p_p_Perso) p_p_Perso++
 
/* Types & structures for List of perso*/
/*//////////////////////////////////////*/
/*tdePosInList is used for the fn_ListChoice function.*/
typedef enum tdePosInList_{
	E_pil_First,/*we want to get the first elements in shorted list.*/
	E_pil_Last,/*we want to get the last elements in shorted list.*/
	E_pil_StartedPos,/*we want to get the elements beginning at a specific position. Here we want to start with the second elemenent.*/
	E_pil_StartedPos3,/*we want to get the elements beginning at the third position.*/
	E_pil_StartedPosMAx = (255+2/*minimal position*/-E_pil_StartedPos)/*we want to get the elements beginning at the third position.*/
}tdePosInList;
 
typedef char Bool;
 
typedef struct tdstList1_ {
	unsigned char ucNbElt;
	unsigned char ucMaxSize;
	HIE_tdxHandleToSuperObject d_TabElt[1];
} tdstList1;/* used to know the size of the a list with one element*/
 
typedef struct tdstList_ {
	unsigned char ucNbElt;	
	unsigned char ucMaxSize;
	HIE_tdxHandleToSuperObject d_TabElt[C_ucSizeOfMaximalList];
} tdstList;/* use for every list pointer, easy to watch all element in debug mode*/
 
 
void fn_vPutInList (tdstList *p_List, HIE_tdxHandleToSuperObject p_Perso);
void fn_vInsertPersoAtPositionInList (tdstList *p_List, HIE_tdxHandleToSuperObject p_Perso, unsigned char ucPosition);
Bool fn_bFindPersoInList(tdstList *p_List, HIE_tdxHandleToSuperObject p_Perso);
Bool fn_bFindModelInList(tdstList *p_List, AI_tdstAIModel *_p_stModel);
Bool fn_bFindFamilyInList(tdstList *p_List, tdxHandleToFamilyList hFamily);
Bool fn_bFindPersoAndDeleteInList (tdstList *p_List, HIE_tdxHandleToSuperObject p_Perso);
HIE_tdxHandleToSuperObject fn_p_stGetPersoInList(tdstList *p_List, unsigned char ucPosition);
void fn_vDeletePersoAtPositionInList (tdstList *p_List, unsigned char ucPosition);
void fn_vSortListByFamily(tdstList *p_List, tdxHandleToFamilyList hFamily);
void fn_vSortListByModel(tdstList *p_List, AI_tdstAIModel *_p_stModel);
void fn_vUnionList (tdstList *p_ListA, tdstList *p_ListB, tdstList *p_ListC);
void fn_vInterList (tdstList *p_ListA, tdstList *p_ListB, tdstList *p_ListC);
void fn_vDiffList (tdstList *p_ListA, tdstList *p_ListB, tdstList *p_ListC);
void fn_vAddList (tdstList *p_ListA, tdstList *p_ListB);
void fn_v_InitList(tdstList *p_List);
void fn_v_Init3List(tdstList *p_List);/*!!y!!*/
 
void fn_vAffectZddInList(tdstList *, HIE_tdxHandleToSuperObject, unsigned char, ACP_tdxIndex);
void fn_vAffectZdeInList(tdstList *, HIE_tdxHandleToSuperObject, unsigned char, ACP_tdxIndex, GMT_tdxMask uwMask);
void fn_vAffectTypeZdeWithTypeZdeInList(tdstList *, HIE_tdxHandleToSuperObject, GMT_tdxMask xPersoMask, GMT_tdxMask xOthersMask);
 
unsigned char fn_ucAtLeastOnePersoInZdd(HIE_tdxHandleToSuperObject p_stPerso, unsigned char ucModulOrCharact, ACP_tdxIndex xZoneId);
unsigned char fn_ucAtLeastOnePersoInZde(HIE_tdxHandleToSuperObject p_stPerso, unsigned char ucModulOrCharact, ACP_tdxIndex xZoneId, GMT_tdxMask xMask);
 
struct tdstNodeInterpret_ * fn_p_stListSelect(tdstList * p_List, char b_cInverse, struct tdstNodeInterpret_ *p_stTree/*, struct tdstGetSetParam_ * p_stParam*/);
struct tdstNodeInterpret_ * fn_p_stListSort (tdstList * p_List, unsigned char ucWantedNbElt, char b_cIncrease, struct tdstNodeInterpret_ *p_stTree/*, struct tdstGetSetParam_ * p_stParam*/);
 
#endif
