#if defined(_AI_LIB_)
	#include "AIUseCPA.h"
	
	#include "specif/AIOption.h"
	#include "AIMacros.h"	
	#include "AI_Erm.h"
	
	#include "Convert.h"
	#include "EnumFild.h"
	#include "VarType.h"
 
	#include "ProtFild.h"
#else
	#include <string.h>
	#include "specif/AIOption.h"
	
	#include "ConvCst.h"
	#include "EnumFild.h"
	#include "VarType.h"
	#include "ConvFild.h"
#endif /* _AI_LIB_*/
 
#define C_MAX_SIZE_FIELD_SCRIPT_NAME 19
#define C_MAX_SIZE_FIELD_EDITOR_NAME 30
typedef struct tdstFieldEntry_
{
#if defined(ACTIVE_EDITOR)
    char szFieldEditorName[C_MAX_SIZE_FIELD_EDITOR_NAME+1];
    char szFieldEditorName_En[C_MAX_SIZE_FIELD_EDITOR_NAME+1];
#endif /* ACTIVE_EDITOR*/
#if defined (AI_USE_SCRIPT)
    char szFieldScriptName[C_MAX_SIZE_FIELD_SCRIPT_NAME+1];
#endif /* AI_USE_SCRIPT */
	enum tdeFieldTypeId_ eType;
#if defined(_AI_LIB_)
    tdp_fn_cGetFunctionPtr p_fn_cGetFieldFunction;
    tdp_fn_cSetFunctionPtr p_fn_cSetFieldFunction;
#endif /* _AI_LIB_*/
} tdstFieldEntry;
 
tdstFieldEntry a_stFieldTable[eNbField]
#if defined(OPTIMIZED_COMMAND)
=
{
/* Procedure initialisation */
#if defined (AI_USE_SCRIPT)
	#if defined(_AI_LIB_)
		#if defined(ACTIVE_EDITOR)
			#define M_DEFINE_FIELD(a,b,english,c,d,e,f) { b,english,c,d,e,f },
		#else
			#define M_DEFINE_FIELD(a,b,english,c,d,e,f) { c,d,e,f },
		#endif /* ACTIVE_EDITOR*/
	#else
		#if defined(ACTIVE_EDITOR)
			#define M_DEFINE_FIELD(a,b,english,c,d,e,f) { b,english,c,d },
		#else
			#define M_DEFINE_FIELD(a,b,english,c,d,e,f) { c,d },
		#endif /* ACTIVE_EDITOR*/
	#endif
#else /* AI_USE_SCRIPT */
	#if defined(_AI_LIB_)
		#if defined(ACTIVE_EDITOR)
			#define M_DEFINE_FIELD(a,b,english,c,d,e,f) { b,english,d,e,f },
		#else
			#define M_DEFINE_FIELD(a,b,english,c,d,e,f) { d,e,f },
		#endif /* ACTIVE_EDITOR*/
	#else
		#if defined(ACTIVE_EDITOR)
			#define M_DEFINE_FIELD(a,b,english,c,d,e,f) { b,english,d },
		#else
			#define M_DEFINE_FIELD(a,b,english,c,d,e,f) { d },
		#endif /* ACTIVE_EDITOR*/
	#endif
#endif /* AI_USE_SCRIPT */
	#include "DefFild.h" 
	#undef M_DEFINE_FIELD
}
#endif /* OPTIMIZED_COMMAND*/
;
 
typedef struct tdstFieldTypeEntry_
{
  enum tdeVariableType_ eType;
#if defined(_AI_LIB_)
  tdp_fn_vGetTypeFunctionPtr fn_p_fn_vGetTypeFunction;
  tdp_fn_vSetTypeFunctionPtr fn_p_fn_vSetTypeFunction;
#endif
} tdstFieldTypeEntry;
 
tdstFieldTypeEntry a_stFieldTypeTable[eNbFieldType]=
{
#if defined(_AI_LIB_)
	#define M_DEFINE_FIELD_TYPE(a,b,c,d) {b,c,d},
	/*#define M_DEFINE_FIELD_TYPE(a,b,c,d) {b,NULL,NULL},*/
#else
	#define M_DEFINE_FIELD_TYPE(a,b,c,d) {b,},
#endif
	#include "FildType.h"
	#undef M_DEFINE_FIELD_TYPE
};
 
#if defined(_AI_LIB_)
tdp_fn_vGetTypeFunctionPtr fn_p_fn_pGetFieldTypeGetFunctionPtr(enum tdeFieldTypeId_ eFieldTypeId)
{
	return(a_stFieldTypeTable[eFieldTypeId].fn_p_fn_vGetTypeFunction);
}
 
tdp_fn_vSetTypeFunctionPtr fn_p_fn_pGetFieldTypeSetFunctionPtr(enum tdeFieldTypeId_ eFieldTypeId)
{
	return(a_stFieldTypeTable[eFieldTypeId].fn_p_fn_vSetTypeFunction);
}
#endif
 
enum tdeFieldTypeId_ fn_eGetEngineFieldType(enum tdeFieldId_ eFieldId)
{
    return(a_stFieldTable[eFieldId].eType);
}
 
/*tempo //#if defined(ACTIVE_EDITOR)*/
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
enum tdeVariableType_ fn_eGetFieldType(enum tdeFieldId_ eFieldId)
{
    return(a_stFieldTypeTable[a_stFieldTable[eFieldId].eType].eType);
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
/*#endif*/
/**/
 
 
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
enum tdeFieldId_ fn_eGetNbField()
{
  return(eNbField);
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
 
#if defined (AI_USE_SCRIPT)
enum tdeFieldId_ fn_eFindFieldIdFromScriptName(char *szField)
{
    short wFieldEntry;
    for(wFieldEntry=0;wFieldEntry<fn_eGetNbField();wFieldEntry++)
    {
        if (!stricmp(a_stFieldTable[wFieldEntry].szFieldScriptName,szField))
        {
            return((enum tdeFieldId_) wFieldEntry);
        }
    }
    return(fn_eGetNbField());
}
#endif /* AI_USE_SCRIPT */
 
#if defined(ACTIVE_EDITOR)
enum tdeFieldId_ fn_eFindFieldIdFromEditorName(char *szField)
{
    short wFieldEntry;
    for(wFieldEntry=0;wFieldEntry<fn_eGetNbField();wFieldEntry++)
    {
        if (!stricmp(a_stFieldTable[wFieldEntry].szFieldEditorName,szField))
        {
            return((enum tdeFieldId_) wFieldEntry);
        }
    }
    return(fn_eGetNbField());
}
 
char *szFindFieldScriptNameFromId(enum tdeFieldId_ eFieldId)
{
    return(a_stFieldTable[eFieldId].szFieldScriptName);
}
 
char *szFindFieldEditorNameFromId(enum tdeFieldId_ eFieldId)
{
    return(a_stFieldTable[eFieldId].szFieldEditorName);
}
#endif /* ACTIVE_EDITOR*/
 
 
#if !defined(OPTIMIZED_COMMAND)
#if defined(ACTIVE_EDITOR)
void fn_vDefineFieldEntry(enum tdeFieldId_ eFieldId,char *szFieldEditorName,char *szFieldEditorName_En,char *szFieldScriptName,enum tdeFieldTypeId_ eType,tdp_fn_cGetFunctionPtr p_fn_cGetFieldFunction,tdp_fn_cSetFunctionPtr p_fn_cSetFieldFunction)
#else
void fn_vDefineFieldEntry(enum tdeFieldId_ eFieldId,char *szFieldScriptName,enum tdeFieldTypeId_ eType,tdp_fn_cGetFunctionPtr p_fn_cGetFieldFunction,tdp_fn_cSetFunctionPtr p_fn_cSetFieldFunction)
#endif /* ACTIVE_EDITOR*/
{
    if (
        (eFieldId<fn_eGetNbField())
#if defined(ACTIVE_EDITOR)
        &&(strlen(szFieldEditorName)<=C_MAX_SIZE_FIELD_EDITOR_NAME)
#endif /* ACTIVE_EDITOR*/
        &&(strlen(szFieldScriptName)<=C_MAX_SIZE_FIELD_SCRIPT_NAME)
        &&(p_fn_cGetFieldFunction!=NULL)
        &&(p_fn_cSetFieldFunction!=NULL)
        )
    {
#if defined(ACTIVE_EDITOR)
        strcpy(a_stFieldTable[eFieldId].szFieldEditorName,szFieldEditorName);
#endif /* ACTIVE_EDITOR*/
        strcpy(a_stFieldTable[eFieldId].szFieldScriptName,szFieldScriptName);
        a_stFieldTable[eFieldId].p_fn_cSetFieldFunction=p_fn_cSetFieldFunction;
        a_stFieldTable[eFieldId].p_fn_cGetFieldFunction=p_fn_cGetFieldFunction;
        a_stFieldTable[eFieldId].eType=eType;
    }
    else
    {
		char str[C_MAX_LENGTH_STRING];
  	    sprintf(str,"Error while defining %s field in %s\n",szFieldScriptName,__FILE__);
        M_AIFatalErrorMsg(E_uwAIFatalNotValidField,str);
    }
}
#endif /* OPTIMIZED_COMMAND*/
 
#if defined(_AI_LIB_)
tdp_fn_cGetFunctionPtr fn_p_fn_pGetFieldGetFunctionPtr(enum tdeFieldId_ eFieldId)
{
  return(a_stFieldTable[eFieldId].p_fn_cGetFieldFunction);
}
 
tdp_fn_cSetFunctionPtr fn_p_fn_pGetFieldSetFunctionPtr(enum tdeFieldId_ eFieldId)
{
  return(a_stFieldTable[eFieldId].p_fn_cSetFieldFunction);
}
#endif /* _AI_LIB_*/
 
#if !defined(OPTIMIZED_COMMAND)
#if defined(__DEBUG_AI__)
void fn_vInitFieldTable(tdp_fn_cGetFunctionPtr fn_cGetFieldDefaultFunctionPointer,tdp_fn_cSetFunctionPtr fn_cSetFieldDefaultFunctionPointer)
{
    short wFieldEntry;
    for(wFieldEntry=0;wFieldEntry<fn_eGetNbField();wFieldEntry++)
    {
        fn_vDefineFieldEntry(M_FIELD_ENTRY((enum tdeFieldId_) wFieldEntry,"","","",eFieldType_Integer,fn_cGetFieldDefaultFunctionPointer,fn_cSetFieldDefaultFunctionPointer));
    }
}
 
void fn_vCheckFieldTable(tdp_fn_cGetFunctionPtr fn_cGetFieldDefaultFunctionPointer,tdp_fn_cSetFunctionPtr fn_cSetFieldDefaultFunctionPointer)
{
  short wFieldEntry;
  char str[C_MAX_LENGTH_STRING];
  size_t lLen;
  size_t lMaxLengthScriptName=0;
#if defined(ACTIVE_EDITOR)
  size_t lMaxLengthEditorName=0;
#endif /* ACTIVE_EDITOR*/
  for(wFieldEntry=0;wFieldEntry<fn_eGetNbField();wFieldEntry++)
  {
	 if ((lLen=strlen(a_stFieldTable[wFieldEntry].szFieldScriptName))>lMaxLengthScriptName)
	 {
	   lMaxLengthScriptName=lLen;
	 }
#if defined(ACTIVE_EDITOR)
	 if ((lLen=strlen(a_stFieldTable[wFieldEntry].szFieldEditorName))>lMaxLengthEditorName)
	 {
	   lMaxLengthEditorName=lLen;
	 }
#endif /* ACTIVE_EDITOR*/
  }	
#if !defined(U64)
  {
	if (lMaxLengthScriptName<C_MAX_SIZE_FIELD_SCRIPT_NAME)
	{
		sprintf(str,"*** AI : You should reduce C_MAX_SIZE_FIELD_SCRIPT_NAME in %s to %d\n",__FILE__,lMaxLengthScriptName);
		OutputDebugString(str);
	}
#if defined(ACTIVE_EDITOR)
	if (lMaxLengthEditorName<C_MAX_SIZE_FIELD_EDITOR_NAME)
	{
		sprintf(str,"*** AI : You should reduce C_MAX_SIZE_FIELD_EDITOR_NAME in %s to %d\n",__FILE__,lMaxLengthEditorName);
		OutputDebugString(str);
	}
#endif /* ACTIVE_EDITOR*/
  }
#endif /* U64*/
}
 
#endif /* __DEBUG_AI__*/
#endif /* OPTIMIZED_COMMAND*/
