#ifndef _GAME_H_
#define _GAME_H_

#include "..\WCode\Engine.h"
#include "Defines.h"
//#include "FontBlb.h"

// function
void DrawVoda();
void Draw3dFade(uint texture_id, TVector3 vec[4], TRGBf color = RGBf_WHITE);
void onResize(int w, int h);
void Render();
bool onInit();
void onKeyboard(bool keys[255]);
void onMouse(int button,int x,int y);
void onMouseMove(int button, int x, int y);
void onTimer();
void konec();

// fce Ckouzla.cpp
void DrawOlejProt();

//////////////////////////////////////////////////////////////////////////
const int BOJ_HRADBY = 1;
const int BOJ_HRAD = 2;
const int BOJ_JED = 3;
const int BOJ_UTEK = 4;
const int BOJ_STRELEC = 5;
const int BOJ_KAT = 6;
const int BOJ_MAG = 7;

struct TVyzkumProt
{
	bool olej;
	void Init()
	{
		olej=0;
	}
};

class CVyzkum
{
private :
	CParticleEmitor _p;

public :
	bool olej;
	bool sipy;
	bool koule;

	bool obrana;
	bool brneni;
	bool kostel;

	bool zlato;
	bool kameni;
	bool mana;

	bool domoobrana;
	bool trziste;
	bool chram;

	void Init();
	void DrawOlej();
};

struct TGrafData
{
	std::vector<int> _data;
	int _aktBody;
	void ZapisBody()
	{
		if(_aktBody < 0) _aktBody=0;
		_data.push_back( _aktBody );
	}
	void Init() 
	{	
		_data.clear();
		_aktBody=0; 
	}
};

struct THrac
{
	int kdo;//0-hrac, 1-prot
	int Hrad;
	int max_hrad;
	int domoobrana;
	int doly, kamenictvy, chram, vedCentrum;
	int kovarny, zbrojnice, strelnice, dilny1, dilny2;
	int penize, kameny, mana, vedBody;
	float vyska_zed;
	// jednotkz
	int pocLeh, pocTez, pocStr, pocKat, pocMag, pocSpecJed;
	int silaPlus;
	int speedPlus;
};

extern THrac g_hrac;
extern THrac g_prot;

const int JED_TYP_JED=1;
const int JED_TYP_STR=2;
const int JED_TYP_KAT=3;
const int JED_TYP_MAG=4;

struct TJednotka
{
	int kdo; // 0-hrac, 1-prot
	int jaka_jed;
	int typ; // 1-jednotka, 2-strelec, 3-catapult
	bool show;
	uint id_texture;
	CVector3 pos;
	float w,h;
	float px;
	uint akce; // 0-nic, 1-boj hradba, 2-boj jednotka
	int speed;
	int plus_speed;
	int sila;
	int live;
	int max_live;
	TJednotka *jednotka;
	int smrt;
	float fBlend;
	float fTime; // katapult
	int oldTim, aktTim; // katapult

	// animace
	int poc_x, poc_y;
	float akt_speed;
	float anim_speed;
	int akt_frame;
	int plus_y;

	// animace
	int pocX1, pocY1;	// chuze
	int pocX2, pocY2;	// smrt
	int pocX3, pocY3;	// utok
	uint texId1, texId2, texId3;
	void Set1() {
		poc_x = pocX1;
		poc_y = pocY1;
		id_texture = texId1;
	}
	void Set2() {
		poc_x = pocX2;
		poc_y = pocY2;
		id_texture = texId2;
		akt_frame = 0;
	}
	void Set3() {
		poc_x = pocX3;
		poc_y = pocY3;
		id_texture = texId3;
	}
	bool kata_zac;
	bool odecitat;
};

//const TJednotka HRAC_LEHKA = {1, (CVector3(0,0,0)), 0.5, 0.5, 0.1};

class C_SCENAJED_0
{
private :
	
	int _kdo; // 0 - hrac, 1 - prot
public :
	std::vector<TJednotka> _hracJed;
	C_SCENAJED_0(int i);	// 0 - hrac, 1 - prot
public :
	std::vector<TJednotka> GetJedn() {return _hracJed;}
	void GetJedn(std::vector<TJednotka> *j) {j = &_hracJed;}
	void Add(TJednotka j);
	void Add(int i);
	void Render();
	void RenderOblak();
	void Coli(float zed_prot, THrac &p, C_SCENAJED_0 &jed_prot);
	void Move(THrac &prot, float time);
	void Refresh(THrac &prot, int i);
	bool ColiZed( float zed, int kdo_zed, bool ret=0 );
	void DeleteAll();
};

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

struct TKapka
{
	CVector3 pos;
	uint texture_id;
	float delka;
	float pz;
};

class C_DEST_0
{
private :
	int _iKolik;
	float _od;
	float _do;
	std::vector<TKapka> _vKapky;

	void _NewKapka(TKapka &k);
	
public :
	C_DEST_0(int iKolik, float fOd,float fDo);

public :
	void Init();
	void Render( int max_ren );
	void Move(float time);
	
};

struct TStar
{
	CVector2	pos;
	float		blend;
	float		bx;
};

class C_STARS_0
{
private :
	std::vector<TStar>	_vStar;
	TRect				_rect;
	uint				_texId;
	void				_NewStar(TStar &s);

public :
	void		Init(TRect r, uint tex_id, int kolik = 0);
	void		Render();
	void		Move(float time);
};

struct TFirebool
{
	int			show;		// 0 a 1
	uint		texId;
	CVector3	pos;
	CVector3	kam;
	CVector3	pPos;
	float				wh;
	CParticleEmitor		em1;
	int					col;
	int kdo;
};

class C_FIREBOOL_0
{
private :
	std::vector<TFirebool> _vFireBool;
		
public :
	void NewFirebool(uint tex_id, uint tex_id2, CVector3 pos_od, CVector3 pos_do, CVector3 pPos, float wh, int kdo);
	void Render();
	void Move(float time);
	void Coli(float zed, float hrad, THrac &prot, int kdo);
	void Delete()
	{
		_vFireBool.clear();
	}
};

struct TInfoData
{
	bool			bShow;
	int				iDelay;
	int				iAktDelay;
	std::string		text;
	int				iStav; // 0 - vyjeti,1 - zobrazeni, 2 - zajeti
	float				iPosun;
	bool zvuk;
};

class C_INFO_0
{
private :
	std::vector<TInfoData>	_vData;
	TRect					_vel;
public :
	C_INFO_0();
public :
	inline void Add(int delay, std::string text)
	{
		TInfoData temp;
		temp.iDelay = delay;
		temp.text = text;
		temp.bShow = true;
		temp.iAktDelay = delay;
		temp.iStav = 0;
		temp.iPosun = 0.0f;
		temp.zvuk = 0;
		
		_vData.push_back(temp);
	}
	void Init();
	void Render(float time);
	void AktKonec();

};

struct TUdalost
{
	uint texture_id;
	bool show;
	int delay;
	std::string text;
	uint jaka;
};

class C_UDALOST_0
{
private :
	int			_old_cas;
	TUdalost	_udalost;
	bool		_full;
	bool		_stav;

	void _NastavFull();
public :
	C_UDALOST_0();
	
public :
	bool Add(uint texID, int delay, std::string text, uint jaka );
	void Render();
	void Refresh();
	void Enable(){_stav = 1;}
};

struct TStatistika
{
	uint hraciDoba;
	uint poc_budov;
	uint poc_jednotek;
	uint poc_kouzel;
	uint poc_zabJednotek;
	uint celkemBodu;
	int stesti;
	int celkemStesti;
	void Init()
	{
		hraciDoba=0;
		poc_budov=0;
		poc_jednotek=0;
		poc_kouzel=0;
		poc_zabJednotek=0;
		celkemBodu=0;
		stesti=0;
	}
};

//////////////////////////////////////////////////////////////////////////
// AI - inteligence rotihrace
//////////////////////////////////////////////////////////////////////////

class C_AI_0
{
private :
	THrac *_hrac;

	bool _KoupitJednotkuLehkou();
	bool _KoupitJednotkuTezkou();
	bool _KoupitJednotkuStrelce();
	bool _KoupitJednotkuKat();

	bool _KupBudovuDul();
	bool _KupKamenolom();
	bool _KupChram();
	bool _KupVedCentrum();
	bool _KupZed();

	bool _KupBudovuKovarna();
	bool _KupBudovuZbrojnice();
	bool _KupBudovuStrelnice();
	bool _KupDilna1();

	bool _ProvedKouzlo1(); // suroviny
	bool _ProvedKouzlo2(); // Firebooll
	bool _ProvedKouzlo3(); // Vzsati
	bool _ProvedKouzlo4(); // Demonicka prisera
public :
public :
	void SetHrac(THrac &hrac) {_hrac = &hrac;}
	void Ai();
	void Refresh( bool nulovani = 0 );

	
};

//////////////////////////////////////////////////////////////////////////
// Kouzla - 
//////////////////////////////////////////////////////////////////////////

class CKouzloKC
{
private :
	THrac			*_scena;
	bool			_stav;
	uint			_citac;

public :
	CKouzloKC(THrac &j);
	~CKouzloKC();
	
public :
	void Draw(uint texture_id);
	void Enable();
	void Disable();
	
};

class cKouzloSpomal
{
private :
	THrac			*_scena;
	bool			_stav;
	uint			_citac;

public :
	cKouzloSpomal(THrac &j);
	~cKouzloSpomal();
	
public :
	void Draw();
	void Enable();
	
};

void Vysati_soupere(THrac &ja, THrac &souper, int kdo, uint texture_id ); // Ckouzla.h

struct TVlna
{
	CParticleEmitor em;
};

class CScenaVlna
{
private :
	std::list<TVlna> _lData;
public :
	void AddVlna( uint texture_id, float start, float mx );
	void Render();
	void Move();
	void DeleteAll();
};
extern CScenaVlna g_scenaVlna;


// BONUSY

class CBonus
{
private :
	CWfoModel	*_model;
	int			_bonus;
	float		_speed;
	CVector3	_pos;
	bool		_full;
	int			_stav; // 0-nic, 1-pada dolu, 2-je dole, 3-bonus mizi
	int			_typ;
public :
	CBonus();
public :
	void Draw();
	void Refresh(float time);
	void Add(CWfoModel &model, int bonus, float speed, int typ);
	void Colise(THrac &hrac, C_SCENAJED_0 &jed, int kdo );
	int GetStav() {return _stav;}
	void Delete();
};

struct TSip
{
	bool show;
	CVector3 pos;
	float w, h;
	int kdo;	// 0 hrac, 1 - prot
	uint textureId;
	int sila;
};

class CScenaSip
{
private:
	std::vector<TSip> _vSip;

public:
	void Add( uint textureId, CVector3 pos, int kdo, int sila );
	void Render( );
	void Delete( );
	void Move( float time );
	void Coli();
	void Coli( C_SCENAJED_0 &h, int mKdo, float &prot_zed );
};

struct TKoule
{
	bool show;
	CVector3 pos;
	float w, h;
	int kdo;	// 0 hrac, 1 - prot
	uint textureId;
	int sila;
	float uhel;
	CVector3 plus_pos;
};

class CScenaKoule
{
private:
	std::vector<TKoule> _vKoule;
	bool _init;

public:
	CScenaKoule();
	void Add( uint textureId, CVector3 pos, int kdo );
	void Render( );
	void Delete( );
	void Move( float time );
	void Coli( );
	void Coli( CWfoModel &m, THrac &prot, int kdo );
	void Coli( C_SCENAJED_0 &h, int mKdo, float &prot_zed );
};

struct TInfoText
{
	CVector2 pos;
	std::string text;
	TRGBf color;
	float live;
};

class CInfoText
{
private :
	std::list<TInfoText>	_lData;
	CVector2				_startPos;
public :
	void SetStartPos( const CVector2 pos ){ _startPos = pos; }
	void Add( const std::string text, const TRGBf color );
	void Render( C_FREETYPE_0 &font );
	void DeleteAll();
};
extern CInfoText InfoText;

// Pocasi //
/*
 *	Typy :
 *   Svetlo
 *   Tma
 *   Mlha
 *   Slab. dest
 *   Velky dest 
 *   Bourka
 *   Svetlo-LensFlare
 */
const int POC_SVETLO	=	0;
const int POC_TMA		=	1;
const int POC_MLHA		=	2;
const int POC_SLADEST	=	3;
const int POC_VELDEST	=	4;
const int POC_BOURKA	=	5;
const int POC_SVELENS	=	6;

class CPocasi
{
private :
	int _typ;
	int _prubech;	// 0-nacitani, 1-pocasi, 2-odelani, 3 - odelano
	int _dalsiTyp;
	
public :
	CPocasi();
	~CPocasi();

public :
	void Render();
	bool SetPocasi( int pocasi );
	void GenerujPocasi();
	void Reset()
	{
		_typ = 0;
	}

};


// DUCH //
struct TDuch
{
	CVector3 pos;
	TVel vel;
	float live;
	float speed;
};

class CDuch
{
private :
	std::list<TDuch>	_vData;
	uint				_texID;
public :
	void Draw();
	void Move( );
	void Add( CVector3 pos, TVel vel );
	inline void SetTexture( uint texID ) { _texID = texID; }
	void Delete()
	{
		_vData.clear();
	}
};

void DelSur(); // kouzla.cpp
void NactiTexty( std::string name, std::string text[12] );
void NactiDataVyz(std::string name, bool p[], int *body);
void NastavVyzkum(bool pole[12]);
void NastavHrac1(THrac &hrac, int kdo);// Nastav.cpp
void NastavHrac2(THrac &hrac, int kdo);// Nastav.cpp
void NastavHrac3(THrac &hrac, int kdo);// Nastav.cpp
void NastavTlacitkaProNoveKolo(C_GUI_0 &menu, int kolo ); // Nastav.cpp
TPoint VratPosTlac( C_GUI_0 &menu, std::string name );// Nastav.cpp
void PridejSuroviny(THrac &hrac, int kdo, uint texture);	// kouzlo.cpp
void DrawEfektSuroviny();	// kouzla.cpp
void NactiData1(std::string name, bool p[]); // Nastav.cpp
void NastavTlacVyberMenu(C_GUI_0 &menu, bool pole[12]); // Nastav.cpp
void UlozData1(std::string name, bool p[]); // Nastav.cpp
void UlozData1V(std::string name, bool p[]); // Nastav.cpp
void SpustKouzlo( UCHAR znak ); // Nastav.cpp
void RenderVybuchHrad( float time ); // kouzlo.cpp

void DrawVyberMenu();

void LoadPostavSpec();
void LoadPostav1(); // Loading.cpp
void LoadPostav2();
void LoadPostav3();
void LoadPostav4();
void LoadPostav5();

void DrawBlesk( CVector3 pos, TVel vel, float blend=0.4f );

// Externi promnene
//////////////////////////////////////////////////////////////////////////
extern int g_nasGfx;
extern C_BASE_GL_0 *gl2;
extern bool		b_full_screen;
extern int SCRHeight;
extern int SCRWidth;
extern HWND g_hWnd;
extern bool g_light; // CKouzla.h
extern int g_aktKolo; // Nastav.cpp
extern C_FREETYPE_0 g_font;
extern uint texture_odpad;
extern uint texture_trosky;
extern bool	g_light;
extern C_FPS_0 g_fps;
const extern float dalkaZed_x;
const extern float sirkaZed;
extern C_TEXTURE_MANAGER_0 TM;
extern uint	g_JedTextures[30];
extern uint g_specTextures[30];
extern uint g_textures[50];
extern uint g_texBlesk[4];
extern CVector3 g_rotate;
extern bool g_pausa;
extern C_GUI_0 menu_vyber;
extern CPartKruh g_partKruh;
extern C_ASEMODEL_0	hradD, hradZ;
extern CBonus Bonus;
extern C_SCENAJED_0	g_hracScena, g_protScena;
extern C_FIREBOOL_0	g_fire;
extern CVyzkum g_vyzkum;
extern TVyzkumProt g_vyzkumProt;
extern C_SOUND_0 g_zvuk;
extern SOUND_TYP g_idZvuk[20];
extern bool g_silaPlus;
extern bool g_kouzloBoziOchrana;
extern bool g_butVyzMove;
extern bool	g_showUpozVyz;
extern TStatistika g_hracStat;
extern bool	g_zapomnetlivostProt;
extern CKouzloKC kouKC;
extern cKouzloSpomal kouSP;
extern int g_1sFps;

extern int plus_penize;
extern int plus_kameny;
extern int plus_mana;
//////////////////////////////////////////////////////////////////////////

// Function
int GetCena(int cena, int pocet);
int CelkemJednotek(THrac h);
int GetCenaJed(int cena, int pocet);

#endif //_GAME_H_