//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#ifndef RTS_PARSEDATA_H
#define RTS_PARSEDATA_H
#ifdef _WIN32
#pragma once
#endif

#include "hl2wars/rts_shareddefs.h"
#include "../public/materialsystem/MaterialSystemUtil.h"

//class CHudTexture;
class KeyValues;
class BitmapImage;

#define MAX_UNIT_STRING	80
#define MAX_ABILITY_STRING	80
#define MAX_FACTION_STRING	80

typedef unsigned short UNIT_FILE_INFO_HANDLE;
typedef unsigned short ABILITY_FILE_INFO_HANDLE;
typedef unsigned short FACTION_FILE_INFO_HANDLE;

void PrecacheAllLoaded();
void RTSScriptsLevelInit();
void RTSScriptsLevelShutDown();
void RTSScriptsShutDown();

//-----------------------------------------------------------------------------
// Purpose: Contains data read from an unit script file.
//-----------------------------------------------------------------------------
class FileUnitInfo_t
{
public:

	FileUnitInfo_t();
	
	// Each game can override this to get whatever values it wants from the script.
	virtual void Parse( KeyValues *pKeyValuesData );

public:	
	// general data
	char		m_szImage[MAX_UNIT_STRING];
	BitmapImage *m_pImage;
	char		m_szName[MAX_UNIT_STRING];
	char		m_szDescription[MAX_UNIT_STRING];
	int			m_iAbilities[MAXABILITIESSLOTS];	// containing handles to the ability data
	float		m_fViewDistance;					// fog of war view distance

	// build data
	char		m_szUnit[MAX_UNIT_STRING];	// class name to spawn
	int			m_iCost;
	int			m_iRechargeTime;

	// sounds
	KeyValues	*m_pSoundData;

	KeyValues	*m_pUnitKeyValues;	// this keyvalues can be anything that is being setted in hammer for example
};

FileUnitInfo_t *GetFileUnitInfoFromHandle( UNIT_FILE_INFO_HANDLE handle );
bool ReadUnitInfoData( FileUnitInfo_t *insert, const char *name );
UNIT_FILE_INFO_HANDLE LookupUnitInfoSlot( const char *name );
//void PrecacheUnitData( FileUnitInfo_t *pFUI );

//-----------------------------------------------------------------------------
// Purpose: Contains data read from an ability script file.
//-----------------------------------------------------------------------------
class FileAbilityInfo_t
{
public:

	FileAbilityInfo_t();
	
	// Each game can override this to get whatever values it wants from the script.
	virtual void Parse( KeyValues *pKeyValuesData );

public:	
	// general data
	char		m_szImage[MAX_ABILITY_STRING];
	BitmapImage *m_pImage;
	char		m_szImageDis[MAX_ABILITY_STRING];
	BitmapImage *m_pImageDis;
	char		m_szName[MAX_ABILITY_STRING];
	char		m_szDescription[MAX_ABILITY_STRING];

	// ability data
	int			m_iAbilityType;		// important one, used to indentify what code the npc will select
	int			m_iCost;
	int			m_iRechargeTime;
	int			m_iMinRange;
	int			m_iMaxRange;
	int			m_iVisualHelper;
	char		m_szModel[MAX_ABILITY_STRING];
	char		m_szBuildEntity[MAX_ABILITY_STRING];

	// building info ( ability_building only )
	Vector		m_vOffSet;
	int			m_flHealth;
	float		m_fTolerance;

	// stages
	bool		m_bSpecPosition;
	bool		m_bRotate;

	// texture to project on the ground when placing the ability
	char		m_szProjectTexture[MAX_ABILITY_STRING];	// for restore
	CMaterialReference m_ProjectTexture;
	unsigned char m_cR;
	unsigned char m_cG;
	unsigned char m_cB;
	unsigned char m_cA;
	Vector		  m_vPTMin;		// the min and max define the position and size
	Vector		  m_vPTMax;		// the min and max define the position and size

	// sounds
	KeyValues	*m_pSoundData;

	// Keyvalues ( ability_building only )
	KeyValues	*m_pAbilityKeyValues;
	KeyValues	*m_pComponentKeyValues;
};



const char *GetFileAbilityName( ABILITY_FILE_INFO_HANDLE handle );
FileAbilityInfo_t *GetFileAbilityInfoFromHandle( ABILITY_FILE_INFO_HANDLE handle );
bool ReadAbilityInfoData( FileAbilityInfo_t *insert, const char *name );
ABILITY_FILE_INFO_HANDLE LookupAbilityInfoSlot( const char *name );
void PrecacheAbilityData( FileAbilityInfo_t *pFAI );
int GetAbilityType( const char *name );			// for mapping the ability type names into there numbers.


//-----------------------------------------------------------------------------
// Purpose: Contains data read from a faction script file.
//-----------------------------------------------------------------------------
typedef struct techtree_t
{
	char m_szName[MAX_FACTION_STRING];
	unsigned short m_iHandle;

	techtree_t *m_pParent;
	techtree_t *m_pChild;
	techtree_t *m_pSibling;
} techtree_t;

class FileFactionInfo_t
{
public:

	FileFactionInfo_t();
	
	// Each game can override this to get whatever values it wants from the script.
	virtual void Parse( KeyValues *pKeyValuesData );

	techtree_t *BuildTechTree( techtree_t *pParent, KeyValues *pTree );
	
	techtree_t *FindTechInfo( techtree_t *pCur, const char *find );

public:	
	// general data
	char		m_szName[MAX_FACTION_STRING];
	char		m_szStartBuilding[MAX_FACTION_STRING];

	// tech tree
	techtree_t *m_pRoot;
};

void LoadTechTree();
FileFactionInfo_t *GetTechTree( int element );
int GetCountTechTrees();

#endif // RTS_PARSEDATA_H
