
#include "stdafx.h"
#include "Game.h"
#include <fstream>

C_TEXTURE_MANAGER_0 TM;
uint textures[10];
float g_fFps;
int g_iNumFrame=0;  
float g_fUhel=45.0f;
C_FREETYPE_0 g_font, g_font32;

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


// Game funkce
void NacistCredits(std::string &text);
void DrawGame();
void DrawVyzkum();
void DrawCredits();
void DrawVictori(int i);
void DrawIntro();
void DrawParticleHrad1();
void DrawParticleHrad2();
void RenderEfektUdalosti();

void NastaveniRefresh();

// Game struktury
enum TGame {game_hra, game_menu, game_intro, game_nap, game_outro, game_credits, game_nastaveni, game_vyberKola, game_vyzkum, game_victori, game_video};
struct TZed
{
	float blend;
	bool on;
};

float fogMlha[4] = {0.5, 0.5, 0.5, 1.0};
float fogTma[4] = {0.0, 0.0, 0.0, 1.0};
float fogBou[4] =  {0.0, 0.0, 0.1, 1.0};

// 
int plus_penize	= 7;
int plus_kameny	= 4;
int plus_mana	= 2;

// Game promnene 
int g_mlha_co=0;
float			g_indexFade = 0.05f;
std::string		g_textVyzkum;
float			g_fogColor[4];
TGame			g_game = game_intro;
C_GUI_0			menu;
C_GUI_0			menu_hra, menu_vyber, menu_uvod, menu_nas, menu_vyz, menu_nap, menu_upo;
uint			g_textures[50];
uint			g_texBlesk[4];
uint			g_JedTextures[30];
uint			g_specTextures[30];
int				g_aktKolo = 0; // 0-11 [12kol]
THrac			g_hrac, g_prot;
C_ASEMODEL_0	model, hradD, hradZ;
std::string		g_textHelp;
uint			g_strom;
uint			g_strom2;
C_SCENAJED_0	g_hracScena(0), g_protScena(1);
C_DEST_0		g_dest(250, 8, -0.2);
std::string		g_credits_text;
CVector3		g_plane(0,-3,-10);
TZed			g_BlendZedHrac = {1, 0};
TZed			g_BlendZedProt = {1, 0};
bool			g_blend_hrac=0, g_blend_prot=0;
C_STARS_0		g_star;
C_FIREBOOL_0	g_fire;
int				g_mlha_cislo=0;
C_FPS_0			g_fps;
bool			g_showFPS=0;
bool			g_light=1;
bool			g_infiltrace=1;
C_INFO_0		g_info;
int				g_1sFps;
int				g_citFps=0;
CVector3		g_rotate(0, 0, 0);
C_UDALOST_0		g_udalost;
bool			g_pausa=0;
bool			g_showUvod=0;
TStatistika		g_hracStat;
C_AI_0			g_ai;
C_GLLIGHT_0		g_light0;
C_GAMECURZOR_0	g_curzor;

CKouzloKC		kouKC(g_hrac);
cKouzloSpomal	kouSP(g_prot);
CBonus			Bonus;
CWfoModel		bonModel[5];
CWfoModel		g_scena;
bool			g_polePripusLevel[12];
CAviFile		g_aviIntro;
CAviFile		g_aviOutro;
CScenaSip		g_scenSip;
CScenaKoule		g_scenKou;
CTimer			timer1;
uint			texture_trosky;
char			g_kdoVyhral=0; // 0-nikdo, 1 - hrac, 2 - pocitac
char			g_bFade=0;	// 0-nic, 1-ztmaveni, 2-odtmaveni
char			g_coDelatPoFade = 0;	// 0-nic, 1- nahod menu victori, 2 - menu vyber levelu
TGrafData		g_grafDataHrac, g_grafDataProt;
int				g_stavUdalost=-1;
bool			g_newUdalost=0;
CInfoText		InfoText;
CScenaVlna		g_scenaVlna;
CDuch			g_duch;
int				g_camera = 0;		// 0,1,2
bool			g_zakazNakupu=0;
CPocasi			g_pocasi;
int				g_destKolik = 0;
bool			g_blesknuti=0;
C_SOUND_0		g_sound;
C_SOUND_0		g_zvuk;
SOUND_TYP		g_idZvuk[20];
SOUND_TYP		sound_menu, sound_loop1, sound_loop2;
SOUND_TYP		sound_intro, sound_outro;
CPartKruh		g_partKruh;
//CMotionBlur 	g_MB( 256, 256 );
bool			g_zapomnetlivostProt = 0;
CVyzkum			g_vyzkum;
TVyzkumProt		g_vyzkumProt;
bool			g_kouzloBoziOchrana=0;
bool			g_vykumSave[12];
C_3D_TEXT		g_3dFont;
int				g_cas5kolo=300;
int				g_prvniLoad=0;
std::string		g_poleTextu[12];
char			g_obtiznost = 1;
int				g_AktNapoveda = 0;
int				g_hracVedBody=0;
bool			g_silaPlus=0;
bool			g_enableTimer=1;
bool			g_butVyzMove=0;
bool			g_showUpozVyz=1;

const float LIGHT_S[3] = {0.6,0.6,0.6};
const float LIGHT_T[3] = {0.2,0.2,0.2};
const float LIGHT_B[3] = {1.0,1.0,1.0};

void NastaveniRefresh()
{
	C_BASEGUI_0 *p = menu_nas.GetPointerObject("ID_SLIDER2");
	C_SLIDER_0 *s = (C_SLIDER_0*)p;
	g_sound.SetVolumeAll( (unsigned char) ((float)s->GetAktSpin()*2.55f) );

	C_BASEGUI_0 *pp = menu_nas.GetPointerObject("ID_SLIDER1");
	C_SLIDER_0 *ss = (C_SLIDER_0*)pp;
	g_zvuk.SetVolumeAll( (unsigned char) ((float)ss->GetAktSpin()*2.55f) );
}

void SetPlayHudba( int id )
{
	static TGame akt_game;
	static int last_id=-1;
	bool neselhal=0;

	if( g_game != akt_game )
	{
		g_sound.PlayLoop( id );
		if( last_id != -1 ) g_sound.SetStopId( last_id );
		last_id = id;
		akt_game = g_game;
	}
}

void SetMatAmbEx(const float p[3])
{
	GLfloat materialAmbient[]={p[0], p[1], p[2], 1.0f}; 
	glMaterialfv(GL_FRONT, GL_AMBIENT, materialAmbient); 
}

void SetMatAmb( float a, float b, float c )
{
	GLfloat materialAmbient[]={a, b, c, 1.0f}; 
	glMaterialfv(GL_FRONT, GL_AMBIENT, materialAmbient); 
}

//////////////////////////////////////////////////////////////////////////
// funkce
//////////////////////////////////////////////////////////////////////////
void SetCamera()
{
	if(g_camera==0)
	{
		g_rotate = CV3_NULL;
		g_plane = CVector3(0, -3, -10);
	}
	if(g_camera==1)
	{
		g_rotate = CV3_NULL;
		g_plane = CVector3(0, -2, -7);
	}
	if(g_camera==2) 
	{
		g_rotate = CV3_NULL;
		g_plane = CVector3(0, -4, -10);
	}
}

void NullJednotek( THrac &h )
{
	h.pocLeh=0;
	h.pocTez=0;
	h.pocKat=0;
	h.pocStr=0;
	h.pocMag=0;
	h.pocSpecJed=0;
}

void MlhaOff()
{
	glDisable(GL_FOG);
}

void NoveKolo()
{
	g_rotate = CV3_NULL;
	g_plane = CVector3(0, -3, -10);
	g_camera=0;
	MlhaOff();
	kouKC.Disable();
	if( g_aktKolo == 4 ) g_cas5kolo = 300;
	g_plane.z = -10;
	g_coDelatPoFade=0;
	g_kdoVyhral=0;
	
	if( g_obtiznost == 0 )
	{
		NastavHrac1(g_hrac, 0);
		NastavHrac1(g_prot, 1);
	}else
	if( g_obtiznost == 1 )
	{
		NastavHrac2(g_hrac, 0);
		NastavHrac2(g_prot, 1);
	}else
	if( g_obtiznost == 2 )
	{
		NastavHrac3(g_hrac, 0);
		NastavHrac3(g_prot, 1);
	}
	
	g_grafDataHrac.Init();
	g_grafDataProt.Init();
	g_hracStat.Init();
	InfoText.DeleteAll();
	g_hracScena.DeleteAll();
	g_protScena.DeleteAll();
	g_scenaVlna.DeleteAll();
	NastavTlacitkaProNoveKolo( menu_hra, g_aktKolo );
	
	gl2->SetAktWglMakeCurrent();
	
	if( g_aktKolo+1 % 3 == 0 ) g_scena.DeleteTexture( TM );
	g_scena.Delete();
	g_scena.LoadModel( W_GetString("Data/Models/level%d.wfo", g_aktKolo+1) );
	g_scena.ReloadTexture(TM);

	hradD.Delete();
	hradD.LoadModel( W_GetString("Data/Models/DHrad%d.wfo",(g_aktKolo)/3 + 1 ) );
	hradD.Translate(3, 3, 3);
	hradD.ReloadTexture(TM);

	hradZ.Delete();
	hradZ.LoadModel( W_GetString("Data/Models/ZHrad%d.wfo",(g_aktKolo)/3 + 1 ) );
	hradZ.Translate(3, 3, 3);
	hradZ.ReloadTexture(TM);

	gl2->SetNullWglMakeCurrent();
	g_pausa = 1;
	g_showUvod = 1;
	g_pocasi.SetPocasi(0);
	g_destKolik=0;
	g_hrac.pocMag = 0;
	g_prot.pocMag = 0;
	g_scenKou.Delete();
	g_scenSip.Delete();
	Bonus.Delete();
	g_fire.Delete();
	g_duch.Delete();
	DelSur();
	NullJednotek( g_hrac );
	NullJednotek( g_prot );
	g_hracVedBody = 0;
	g_ai.Refresh( 1 );
}

bool FadeOn( ) // ztmavit
{
	static float jas=1.0f;
	C_2DOBJECT_0 obj( 0, 0, 0, SCRWidth, SCRHeight );
	glColor4f( 0, 0, 0, jas );
	obj.SetAplha( 0 );
	glEnable( GL_BLEND );
	glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
	obj.SetBlend( 0 );
	obj.Render();
	glDisable( GL_BLEND );
	jas -= (g_indexFade*60)/g_fps.GetFPS();
	if( jas <= 0 ) 
	{
		jas = 1.0f;
		return TRUE;
	}
	return FALSE;
}

bool FadeOff() // odtmavit
{
	static float jas=0.0f;
	C_2DOBJECT_0 obj( 0, 0, 0, SCRWidth, SCRHeight );
	glColor4f( 0, 0, 0, jas );
	obj.SetAplha( 0 );
	glEnable( GL_BLEND );
	glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
	obj.SetBlend( 0 );
	obj.Render();
	glDisable( GL_BLEND );
	jas += (0.005*60)/g_fps.GetFPS();
	if( jas <= 0 ) 
	{
		jas = 1.0f;
		return TRUE;
	}
	return FALSE;
}

void BunusUpdate()
{
	if( g_aktKolo < 1 )	return;
	int nah = ( rand()%1500 );
	if(nah == 1) {Bonus.Add(bonModel[1], 1, 0.01, 1);}
	if(nah == 2) {Bonus.Add(bonModel[0], 2, 0.01, 2);}
	if(nah == 3 && g_aktKolo > 1 ) {Bonus.Add(bonModel[2], 3, 0.01, 3);} // mana - az treti kolo
	if(nah == 4 && (rand()%8)==2 ) { Bonus.Add(bonModel[3], 4, 0.01, 4); }
}

int CelkemJednotek(THrac h)
{
	int celkem=0;
	celkem += h.pocLeh;
	celkem += h.pocTez;
	celkem += h.pocKat;
	celkem += h.pocStr;
	celkem += h.pocMag;
	celkem += h.pocSpecJed;
	return celkem;
}

void OmezeniMaxima(THrac &h)
{
}

int GetCena(int cena, int pocet)
{
	return cena+((cena*pocet)/2);
}

int GetCenaJed(int cena, int pocet)
{
	return cena+((cena*pocet)/2);
}

void DrawLine(int x1, int y1, int x2, int y2)
{
	W_Ortho();
	glDisable(GL_TEXTURE_2D);
	if(g_light) glDisable(GL_LIGHTING);
	glBegin(GL_LINES);
		glVertex2i(x1, y1);
		glVertex2i(x2, y2);
	glEnd();
	if(g_light) glEnable(GL_LIGHTING);
	W_Proj();
}

void Draw3dFade(uint texture_id, TVector3 vec[4], TRGBf color)
{
	if(texture_id > 0)
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texture_id);
	}else glDisable(GL_TEXTURE_2D);
	glColor3f(color.r, color.g, color.b);

	CVector3 v0(vec[0].x, vec[0].y, vec[0].z);
	CVector3 v1(vec[1].x, vec[1].y, vec[1].z);
	CVector3 v2(vec[2].x, vec[2].y, vec[2].z);
	CVector3 n1 = (v0-v2)<<(v2-v1);
	n1.Normalize();

	glBegin(GL_QUADS);
		glNormal3f(n1.x, n1.y, n1.z);
		glTexCoord2f(0, 0);		glVertex3f(vec[3].x, vec[3].y, vec[3].z);
		glTexCoord2f(1, 0);		glVertex3f(vec[2].x, vec[2].y, vec[2].z);
		glTexCoord2f(1, 1);		glVertex3f(vec[1].x, vec[1].y, vec[1].z);
		glTexCoord2f(0, 1);		glVertex3f(vec[0].x, vec[0].y, vec[0].z);
	glEnd();
}

void Draw2dAlpha(uint texture_id, TRect rect, float alpha)
{
	C_2DOBJECT_0 o1(texture_id, rect);
	o1.SetAplha(0);
	glColor4f(1.0f, 1.0f, 1.0f, alpha);
	glEnable(GL_BLEND);
	//glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	o1.Render();
	glColor4f(1.0f, 1.0f, 1.0f, alpha);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);  
	o1.Render();
	glDisable(GL_BLEND);
}

// Odcitaci pruhlednost
void Draw2dAlphaMin(uint texture_id, TRect rect, float alpha)
{
	C_2DOBJECT_0 o1(texture_id, rect);
	o1.SetAplha(0);
	glColor4f(1.0f, 1.0f, 1.0f, alpha);
	glEnable(GL_BLEND);
	glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
	//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	o1.Render();
	glColor4f(1.0f, 1.0f, 1.0f, alpha);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);  
	o1.Render();
	glDisable(GL_BLEND);
}

void MlhaOn()
{
	glEnable(GL_FOG);
	glFogi(GL_FOG_MODE, GL_EXP2);
	glFogfv(GL_FOG_COLOR, g_fogColor);
	glFogf(GL_FOG_DENSITY, 0.040);
	glHint(GL_FOG_HINT, GL_DONT_CARE);
	//glFogf(GL_FOG_START, 1.0);
	//glFogf(GL_FOG_END, 5.0);
}

bool SpoustejMlhu(bool sp, float timer)	// 0 - vypinej mlhu, 1 - spoustej mlhu
{
	static bool mlha_on=0;
	static float mlha_hustota = 0.0f;
	if(sp == 1)
	{
		if(!mlha_on) MlhaOn();
		if(mlha_hustota <= 0.060f) mlha_hustota += 0.0002;
		glFogf(GL_FOG_DENSITY, mlha_hustota);
		mlha_on = 1;
		if(mlha_hustota > 1.0f) {mlha_hustota=1.0f;return 1;}
	}else
	if(sp == 0)
	{
		if(mlha_hustota >= 0.0f) mlha_hustota -= 0.0002;
		glFogf(GL_FOG_DENSITY, mlha_hustota);
		if(mlha_hustota <= 0.0f ) {MlhaOff();mlha_on = 0;return 1;}
	}
	return 0;
}

void OnBlendZed(TZed &t, float time)
{
	t.on = 1;
	if(t.blend > 0.3) t.blend -=((0.02*60)/g_fps.GetFPS() ); 
}

void OffBlendZed(TZed &t, float time)
{
	if(t.blend < 1.0) t.blend +=((0.02*60)/g_fps.GetFPS()); 
	if(t.blend >= 1.0) t.on = 0;
}

int SpecRand(int i,bool b=false)
{
	//if(b) return ((rand()%i)+i/2);
	if(i >= 0) return (rand()%i);
	return ((rand()%i)+i);
}

void RenderJednotka(TJednotka j, bool oblak, float fBlendValue=1.0f, bool blend=0)
{
	CVector3 v = j.pos;
	float w = j.w;
	float h = j.h;
	TVector3 vec[4] = {v.x,v.y+h,v.z, v.x+w,v.y+h,v.z, v.x+w,v.y,v.z, v.x,v.y,v.z};
	glDisable(GL_BLEND);
	glEnable(GL_ALPHA_TEST);
	glEnable(GL_TEXTURE_2D);
	
	glColor3f(1, 1, 1);
	glBindTexture(GL_TEXTURE_2D, j.id_texture);
	if(j.poc_x == 0) j.poc_x = 1;
	if(j.poc_y == 0) j.poc_y = 1;
	float jeden_frame_x = 1.0f/j.poc_x;
	float jeden_frame_y = 1.0f/j.poc_y;
	int akt_y = (j.akt_frame + j.plus_y*2*j.poc_x)/j.poc_x;
	int akt_x = (j.akt_frame + j.plus_y*2*j.poc_x) - akt_y*j.poc_x;
	float vyp_x = jeden_frame_x*akt_x ;
	float vyp_y = jeden_frame_y*akt_y ;
	
	if( blend )
	{
		glBlendFunc( GL_SRC_ALPHA, GL_ONE );
		glEnable( GL_BLEND );
		glColor3f( fBlendValue, fBlendValue, fBlendValue );
	}
	if(g_light) glDisable(GL_LIGHTING);
	glBegin(GL_QUADS);
		glNormal3f(0, 0, 1);
		glTexCoord2f(vyp_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y);			
		glVertex3f(vec[0].x, vec[0].y, vec[0].z);
		glTexCoord2f(vyp_x+ jeden_frame_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y);		
		glVertex3f(vec[1].x, vec[1].y, vec[1].z);
		glTexCoord2f(vyp_x+ jeden_frame_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y - jeden_frame_y);			
		glVertex3f(vec[2].x, vec[2].y, vec[2].z);
		glTexCoord2f(vyp_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y - jeden_frame_y);				
		glVertex3f(vec[3].x, vec[3].y, vec[3].z);
	glEnd();
	glDisable(GL_BLEND);
	/*// ramecek
	glColor3f(1,0,0);
	glDisable(GL_TEXTURE_2D);
	glBegin(GL_LINE_LOOP);
		//glTexCoord2f(vyp_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y);			
		glVertex3f(vec[0].x, vec[0].y, vec[0].z);
		//glTexCoord2f(vyp_x+ jeden_frame_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y);		
		glVertex3f(vec[1].x, vec[1].y, vec[1].z);
		//glTexCoord2f(vyp_x+ jeden_frame_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y - jeden_frame_y);			
		glVertex3f(vec[2].x, vec[2].y, vec[2].z);
		//glTexCoord2f(vyp_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y - jeden_frame_y);				
		glVertex3f(vec[3].x, vec[3].y, vec[3].z);
	glEnd();*/
	bool bDrawLive = 1;
	if(j.smrt >= 1) bDrawLive=0;
	if(bDrawLive)
	{
		// zivoty
		glColor3f(0,1,0);
		glDisable(GL_TEXTURE_2D);
		float new_x = ((vec[1].x-vec[0].x)/float(j.max_live)) * (float)j.live;
		glBegin(GL_QUADS);
			//glTexCoord2f(vyp_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y);			
			glVertex3f(vec[0].x, vec[0].y, vec[0].z);
			//glTexCoord2f(vyp_x+ jeden_frame_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y);		
			glVertex3f(vec[0].x+new_x, vec[1].y, vec[1].z);
			//glTexCoord2f(vyp_x+ jeden_frame_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y - jeden_frame_y);			
			glVertex3f(vec[0].x+new_x, vec[1].y+0.12, vec[2].z);
			//glTexCoord2f(vyp_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y - jeden_frame_y);				
			glVertex3f(vec[3].x, vec[0].y+0.12, vec[3].z);
		glEnd();
		// ohraniceni zivotu
		glColor3f(1,0,0);
		glBegin(GL_LINE_LOOP);
			//glTexCoord2f(vyp_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y);			
			glVertex3f(vec[0].x, vec[0].y, vec[0].z);
			//glTexCoord2f(vyp_x+ jeden_frame_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y);		
			glVertex3f(vec[1].x, vec[1].y, vec[1].z);
			//glTexCoord2f(vyp_x+ jeden_frame_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y - jeden_frame_y);			
			glVertex3f(vec[2].x, vec[1].y+0.12, vec[2].z);
			//glTexCoord2f(vyp_x, (j.poc_y*jeden_frame_y)-vyp_y*jeden_frame_y - jeden_frame_y);				
			glVertex3f(vec[3].x, vec[0].y+0.12, vec[3].z);
		glEnd();
	}
	/*// Vykreslit oblacek na jednotkou pokud je spomalena 
	if(oblak)
	{
		bool bFog = (bool)glIsEnabled(GL_FOG);
		if(bFog) glDisable(GL_FOG);
		glDisable(GL_ALPHA_TEST);
		static float fBlick=0.8f;
		static float fMinus=0.01f;
		fBlick -= fMinus;
		if(fBlick < 0.6f) fMinus = -fMinus;
		if(fBlick > 0.9f) fMinus = -fMinus;
		glColor4f(0, 0, 1, fBlick);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, TM.GetIdTexture(g_textures[25]));
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
		glEnable(GL_BLEND);
		glBegin(GL_QUADS);
			glTexCoord2f(0, 1);			
			glVertex3f(vec[0].x, vec[0].y, vec[0].z);
			
			glTexCoord2f(1, 1);		
			glVertex3f(vec[1].x, vec[1].y, vec[1].z);
			
			glTexCoord2f(1, 0);			
			glVertex3f(vec[2].x, vec[2].y, vec[2].z);
			
			glTexCoord2f(0, 0);				
			glVertex3f(vec[3].x, vec[3].y, vec[3].z);
		glEnd();
		glDisable(GL_BLEND);
		if(bFog) glEnable(GL_FOG);
	}*/
	
	if(g_light) glEnable(GL_LIGHTING);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_ALPHA_TEST);
}

void RenderJednotkaOblak(TJednotka j, bool oblak, float fBlendValue=1.0f, bool blend=0)
{
	glPushAttrib( GL_ENABLE_BIT );
	CVector3 v = j.pos;
	float w = j.w;
	float h = j.h;
	float plus_vz = 0.1f;
	TVector3 vec[4] = {v.x,v.y+h,v.z+plus_vz, v.x+w,v.y+h,v.z+plus_vz, v.x+w,v.y,v.z+plus_vz, v.x,v.y,v.z+plus_vz};
	glDisable(GL_BLEND);
	glEnable(GL_ALPHA_TEST);
	glEnable(GL_TEXTURE_2D);
	
	if(j.poc_x == 0) j.poc_x = 1;
	if(j.poc_y == 0) j.poc_y = 1;
	float jeden_frame_x = 1.0f/j.poc_x;
	float jeden_frame_y = 1.0f/j.poc_y;
	int akt_y = (j.akt_frame + j.plus_y*2*j.poc_x)/j.poc_x;
	int akt_x = (j.akt_frame + j.plus_y*2*j.poc_x) - akt_y*j.poc_x;
	float vyp_x = jeden_frame_x*akt_x ;
	float vyp_y = jeden_frame_y*akt_y ;
	
	// Vykreslit oblacek na jednotkou pokud je spomalena 
	if(oblak)
	{
		bool bFog = (bool)glIsEnabled(GL_FOG);
		if(bFog) glDisable(GL_FOG);
		glDisable(GL_ALPHA_TEST);
		static float fBlick=0.8f;
		static float fMinus=0.01f;
		fBlick -= fMinus;
		if(fBlick < 0.6f) fMinus = -fMinus;
		if(fBlick > 0.9f) fMinus = -fMinus;
		glColor4f(0, 0, 1, fBlick);
		glDisable( GL_LIGHTING );
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, TM.GetIdTexture(g_textures[25]));
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
		glEnable(GL_BLEND);
		glBegin(GL_QUADS);
			glTexCoord2f(0, 1);			
			glVertex3f(vec[0].x, vec[0].y, vec[0].z);
			
			glTexCoord2f(1, 1);		
			glVertex3f(vec[1].x, vec[1].y, vec[1].z);
			
			glTexCoord2f(1, 0);			
			glVertex3f(vec[2].x, vec[2].y, vec[2].z);
			
			glTexCoord2f(0, 0);				
			glVertex3f(vec[3].x, vec[3].y, vec[3].z);
		glEnd();
		glDisable(GL_BLEND);
		if(bFog) glEnable(GL_FOG);
	}
	
	if(g_light) glEnable(GL_LIGHTING);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_ALPHA_TEST);
	glPopAttrib();
}

void Testing()
{
	// T4estujem konec hry, nebo dalsi kolo
	if( g_kdoVyhral==0 )
	{
		if(g_hrac.Hrad < 0) 
		{
			g_kdoVyhral=2;
			g_grafDataHrac._aktBody -= 20000; 
			g_grafDataProt._aktBody += 20000; 
			g_indexFade = 0.005f;
		}
		else if(g_prot.Hrad < 0) 
		{
			g_kdoVyhral=1; 
			g_grafDataHrac._aktBody += 20000; 
			g_grafDataProt._aktBody -= 20000; 
			g_indexFade = 0.005f;
		}
	}
}

void NastavTlacitka()
{
	// Tlacitko 1 - dul //
	C_BASEGUI_0 *p = menu_hra.GetPointerObject("ID_BUT1");
	p->SetState(false);
	if(g_hrac.penize >= GetCena(cena_dul, g_hrac.doly) && g_hrac.kameny >= GetCena(kamen_dul, g_hrac.doly)) p->SetState(true);
	C_BUTTON_0 *but = (C_BUTTON_0*)p; 
	char string[255];
	sprintf(string, "Cena :\n  %dzl.\n  %dkam.", GetCena(cena_dul, g_hrac.doly), GetCena(kamen_dul, g_hrac.doly));
	but->SetTextMouseMove( string );
	// Tlacitko 2 - kamenictvy //
	p = menu_hra.GetPointerObject("ID_BUT2");
	p->SetState(false);
	if(g_hrac.penize >= GetCena(cena_kamen, g_hrac.kamenictvy) && g_hrac.kameny >= GetCena(kamen_kamen, g_hrac.kamenictvy)) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "Cena :\n  %dzl.\n  %dkam.", GetCena(cena_kamen, g_hrac.kamenictvy), GetCena(kamen_kamen, g_hrac.kamenictvy));
	but->SetTextMouseMove( string );
	// Tlacitko 3 - dul //
	p = menu_hra.GetPointerObject("ID_BUT3");
	p->SetState(false);
	if(g_hrac.penize >= GetCena(cena_chram, g_hrac.chram) && g_hrac.kameny >= GetCena(kamen_chram, g_hrac.chram)) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "Cena :\n  %dzl.\n  %dkam.", GetCena(cena_chram, g_hrac.chram), GetCena(kamen_chram, g_hrac.chram));
	but->SetTextMouseMove( string );
	// Tlacitko 4 - dul //
	p = menu_hra.GetPointerObject("ID_BUT4");
	p->SetState(false);
	if(g_hrac.penize >= GetCena(cena_vedCen, g_hrac.vedCentrum) && g_hrac.kameny >= GetCena(kamen_vedCen, g_hrac.vedCentrum)) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "Cena :\n  %dzl.\n  %dkam.", GetCena(cena_vedCen, g_hrac.vedCentrum), GetCena(kamen_vedCen, g_hrac.vedCentrum));
	but->SetTextMouseMove( string );
	// Tlacitko 5- hradba //
	p = menu_hra.GetPointerObject("ID_BUT5");
	p->SetState(false);
	if(g_hrac.penize >= cena_hradba && g_hrac.kameny >= kamen_hradba && g_hrac.vyska_zed < max_vyska_zed) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "Cena :\n  %dzl.\n  %dkam.", cena_hradba, kamen_hradba );
	but->SetTextMouseMove( string );
	// Jednotky //
	// Tlacitko jednotka 1 //
	p = menu_hra.GetPointerObject("ID_JED1");
	p->SetState(false);
	if(g_hrac.penize >= GetCenaJed(cena_jed1, CelkemJednotek(g_hrac)) && (g_hrac.kovarny > 0)&& !g_zakazNakupu) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "Cena :\n  %dzl.", GetCenaJed(cena_jed1, CelkemJednotek(g_hrac) ) );
	but->SetTextMouseMove( string );
	// Tlacitko jednotka 2 //
	p = menu_hra.GetPointerObject("ID_JED2");
	p->SetState(false);
	if(g_hrac.penize >= GetCenaJed(cena_jed2, CelkemJednotek(g_hrac)) && (g_hrac.zbrojnice > 0)&& !g_zakazNakupu) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "Cena :\n  %dzl.", GetCenaJed(cena_jed2, CelkemJednotek(g_hrac) ) );
	but->SetTextMouseMove( string );
	// Tlacitko jednotka 3 //
	p = menu_hra.GetPointerObject("ID_JED3");
	p->SetState(false);
	if(g_hrac.penize >= GetCenaJed(cena_jed3, CelkemJednotek(g_hrac)) && (g_hrac.strelnice > 0)&& !g_zakazNakupu) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "Cena :\n  %dzl.", GetCenaJed(cena_jed3,CelkemJednotek(g_hrac) ) );
	but->SetTextMouseMove( string );
	// Tlacitko jednotka 4 //
	p = menu_hra.GetPointerObject("ID_JED4");
	p->SetState(false);
	if(g_hrac.penize >= GetCenaJed(cena_jed4, CelkemJednotek(g_hrac)) && (g_hrac.dilny1 > 0)&& !g_zakazNakupu) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "Cena :\n  %dzl.", GetCenaJed(cena_jed4, CelkemJednotek(g_hrac) ) );
	but->SetTextMouseMove( string );
	// Tlacitko jednotka 5 //
	p = menu_hra.GetPointerObject("ID_JED5");
	p->SetState(false);
	if(g_hrac.penize >= GetCenaJed(cena_jed5, CelkemJednotek(g_hrac)) && (g_hrac.zbrojnice > 0)&& !g_zakazNakupu) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "Cena :\n  %dzl.", GetCenaJed(cena_jed5, CelkemJednotek(g_hrac) ) );
	but->SetTextMouseMove( string );
	// Kouzla //
	// Tlacitko 1 - magie - suroviny //
	p = menu_hra.GetPointerObject("ID_KOU1");
	p->SetState(false);
	if(g_hrac.mana >= mana_sur) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, " Suroviny \n Mana : %d  ", mana_sur );
	but->SetTextMouseMove( string );

	// Tlacitko 2 - magie - fireboll //
	p = menu_hra.GetPointerObject("ID_KOU2");
	p->SetState(false);
	if(g_hrac.mana >= mana_att) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, " Ohnivá koule \n Mana : %d ", mana_att );
	but->SetTextMouseMove( string );

	// Tlacitko 3 - magie - vysati zasob //
	p = menu_hra.GetPointerObject("ID_KOU3");
	p->SetState(false);
	if(g_hrac.mana >= mana_3) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, " Vysatí zásob \n Mana : %d ", mana_3 );
	but->SetTextMouseMove( string );

	// Tlacitko 4 - magie - spomaleni //
	p = menu_hra.GetPointerObject("ID_KOU4");
	p->SetState(false);
	if(g_hrac.mana >= mana_4) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, " Zpomalení \n Mana : %d ", mana_4 );
	but->SetTextMouseMove( string );
	
	// Tlacitko 5 - magie - spomaleni //
	p = menu_hra.GetPointerObject("ID_KOU5");
	p->SetState(false);
	if(g_hrac.mana >= mana_5) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, " Dračí úder \n Mana : %d ", mana_5 );
	but->SetTextMouseMove( string );

	// Tlacitko 6 - magie - spomaleni //
	p = menu_hra.GetPointerObject("ID_KOU6");
	p->SetState(false);
	if(g_hrac.mana >= mana_6) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, " Zapomnětlivost \n Mana : %d ", mana_6 );
	but->SetTextMouseMove( string );

	// Tlacitko 7 - magie - spomaleni //
	p = menu_hra.GetPointerObject("ID_KOU7");
	p->SetState(false);
	if(g_hrac.mana >= mana_7) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, " Boží ochrana \n Mana : %d ", mana_7 );
	but->SetTextMouseMove( string );

	// Tlacitko 8 - magie - spomaleni //
	p = menu_hra.GetPointerObject("ID_KOU8");
	p->SetState(false);
	if(g_hrac.mana >= mana_8) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, " Vyvolání příšery \n Mana : %d ", mana_8 );
	but->SetTextMouseMove( string );


	// Tlacitko pro nakup budov pro jednotky
	// Tlacitko 1 - Kovarna //
	p = menu_hra.GetPointerObject("ID_BUTA");
	p->SetState(false);
	if(g_hrac.penize >= GetCena(cena_kovarna, g_hrac.kovarny) && 
		g_hrac.kameny >= GetCena(kamen_kovarna, g_hrac.kovarny)) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "Cena :\n  %dzl.\n  %dkam.", GetCena(cena_kovarna, g_hrac.kovarny), GetCena(kamen_kovarna, g_hrac.kovarny) );
	but->SetTextMouseMove( string );

	// Tlacitko 2 - Zbrojnice //
	p = menu_hra.GetPointerObject("ID_BUTB");
	p->SetState(false);
	if(g_hrac.penize >= GetCena(cena_zbrojnice, g_hrac.zbrojnice) && 
		g_hrac.kameny >= GetCena(kamen_zbrojnice, g_hrac.zbrojnice) && (g_hrac.kovarny > 0)) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "Cena :\n  %dzl.\n  %dkam.", GetCena(cena_zbrojnice, g_hrac.zbrojnice), GetCena(kamen_zbrojnice, g_hrac.zbrojnice) );
	but->SetTextMouseMove( string );

	// Tlacitko 2 - strelnice //
	p = menu_hra.GetPointerObject("ID_BUTC");
	p->SetState(false);
	if(g_hrac.penize >= GetCena(cena_strelnice, g_hrac.strelnice) && 
		g_hrac.kameny >= GetCena(kamen_strelnice, g_hrac.strelnice) && (g_hrac.zbrojnice > 0)) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "Cena :\n  %dzl.\n  %dkam.", GetCena(cena_strelnice, g_hrac.strelnice), GetCena(kamen_strelnice, g_hrac.strelnice) );
	but->SetTextMouseMove( string );

	// Tlacitko 4 - dilny - katapult //
	p = menu_hra.GetPointerObject("ID_BUTD");
	p->SetState(false);
	if(g_hrac.penize >= GetCena(cena_dilny1, g_hrac.dilny1) && 
		g_hrac.kameny >= GetCena(kamen_dilny1, g_hrac.dilny1) && (g_hrac.strelnice > 0) ) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "Cena :\n  %dzl.\n  %dkam.", GetCena(cena_dilny1, g_hrac.dilny1), GetCena(kamen_dilny1, g_hrac.dilny1) );
	but->SetTextMouseMove( string );

	// Trziste 1  //
	p = menu_hra.GetPointerObject("ID_TRH1");
	p->SetState(false);
	if(g_hrac.kameny >= 500 ) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "500 kamení >> 200 zlata ");
	but->SetTextMouseMove( string );

	// Trziste 2  //
	p = menu_hra.GetPointerObject("ID_TRH2");
	p->SetState(false);
	if(g_hrac.mana >= 50 ) p->SetState(true);
	but = (C_BUTTON_0*)p; 
	sprintf(string, "50 many >> 200 zlata ");
	but->SetTextMouseMove( string );

}

//////////////////////////////////////////////////////////////////////////
// Render - vykreslovaci funkce GL okna
//////////////////////////////////////////////////////////////////////////
void Render()
{
	g_enableTimer = 1;
	g_fps.Vypocet();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	if( g_prvniLoad==1 || g_prvniLoad == 2)
	{
		C_2DOBJECT_0 obj( TM.GetIdTexture( g_textures[45]),0,0,SCRWidth, SCRHeight );
		obj.Render();
		return;
	}

	if(g_game == game_nastaveni || g_game == game_menu)
	{
		NastaveniRefresh();
	}
	
	if(g_game == game_hra)
	{
		//glViewport(0,SCRHeight/3,SCRWidth,SCRHeight-SCRHeight/6);
		SetPlayHudba( sound_loop1 );
		glDisable(GL_LIGHT0);
		glEnable(GL_LIGHT1);
		glLoadIdentity();
		//glScalef(1, 0.4f, 1);
		glTranslatef(g_plane.x, g_plane.y, g_plane.z);
		if( g_kdoVyhral > 0 ) g_plane.z += (0.15f*60)/g_fps.GetFPS();
		
		glRotatef(g_rotate.x,1,0,0);
		glRotatef(g_rotate.y,0,1,0);
		glRotatef(g_rotate.z,0,0,1);

		GLfloat LightPosition[]= { 0.0, 10.0f, 0.0f, 5.0f };// Pozice světla
		glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);// Nastavení pozice světla
		glDisable( GL_ALPHA_TEST );
		glPointSize(20);
		glDisable(GL_TEXTURE_2D);
		glColor3ub(255,0,0);
		glDisable(GL_LIGHTING);
		glBegin(GL_POINTS);
			glVertex3fv(LightPosition);
		glEnd();
		if(g_light) glEnable( GL_LIGHTING );
		glColor3f(1,1,1);
		DrawGame();
		//textREC.Add("vol : ", g_zvuk.);
		//g_font.Print(120,50,"hrac %d, prot %d ", g_grafDataHrac._aktBody, g_grafDataProt._aktBody);

		InfoText.Render( g_font );
		if(!g_pausa)
		{
			int iMouse = menu_hra.MouseMove(g_hWnd);
			if(iMouse == menu_hra.GetIterObject("ID_BUT1")) g_textHelp = text_ko_dul; 
			if(iMouse == menu_hra.GetIterObject("ID_BUT2")) g_textHelp = text_ko_kam; 	
			if(iMouse == menu_hra.GetIterObject("ID_BUT3")) g_textHelp = text_ko_chr; 	
			if(iMouse == menu_hra.GetIterObject("ID_BUT4")) g_textHelp = text_ko_ved; 	
			if(iMouse == menu_hra.GetIterObject("ID_BUT5")) g_textHelp = text_ko_hra; 
			if(iMouse == menu_hra.GetIterObject("ID_BUTA")) g_textHelp = text_ko_A; 
			if(iMouse == menu_hra.GetIterObject("ID_BUTB")) g_textHelp = text_ko_B; 
			if(iMouse == menu_hra.GetIterObject("ID_BUTC")) g_textHelp = text_ko_C; 
			if(iMouse == menu_hra.GetIterObject("ID_BUTD")) g_textHelp = text_ko_D;
			if(iMouse == menu_hra.GetIterObject("ID_KOU1")) g_textHelp = text_mag_sur; 
			if(iMouse == menu_hra.GetIterObject("ID_KOU2")) g_textHelp = text_mag_att; 
			if(iMouse == menu_hra.GetIterObject("ID_KOU3")) g_textHelp = text_mag_kou; 
			if(iMouse == menu_hra.GetIterObject("ID_KOU4")) g_textHelp = text_mag_4; 
			if(iMouse == menu_hra.GetIterObject("ID_KOU5")) g_textHelp = text_mag_5; 
			if(iMouse == menu_hra.GetIterObject("ID_KOU6")) g_textHelp = text_mag_6; 
			if(iMouse == menu_hra.GetIterObject("ID_KOU7")) g_textHelp = text_mag_7; 
			if(iMouse == menu_hra.GetIterObject("ID_KOU8")) g_textHelp = text_mag_8; 
			if(iMouse == menu_hra.GetIterObject("ID_JED1")) g_textHelp = text_jed1; 
			if(iMouse == menu_hra.GetIterObject("ID_JED2")) g_textHelp = text_jed2; 
			if(iMouse == menu_hra.GetIterObject("ID_JED3")) g_textHelp = text_jed3; 
			if(iMouse == menu_hra.GetIterObject("ID_JED4")) g_textHelp = text_jed4; 
			if(iMouse == menu_hra.GetIterObject("ID_JED5")) g_textHelp = text_jed5; 

			if(iMouse == -1) g_textHelp = ""; 
		}
		menu_hra.Render();
		// others //
		// Vykreslit pocty penez, bodu atd.. //
		int iTextPosY = menu_hra.PrevedIntYNaScreen(3);
		glColor3f(1,1,1);
		g_font.Print(menu_hra.PrevedIntXNaScreen(365), iTextPosY, "%d", g_hrac.penize );
		g_font.Print(menu_hra.PrevedIntXNaScreen(440), iTextPosY, "%d", g_hrac.kameny );
		g_font.Print(menu_hra.PrevedIntXNaScreen(515), iTextPosY, "%d", g_hrac.mana );
		g_font.Print(menu_hra.PrevedIntXNaScreen(595), iTextPosY, "%d", g_hracVedBody );

		// Vykresli napovedu //
		glColor3ub(255,255,255);
		g_font.Print(menu_hra.PrevedIntXNaScreen(100), iTextPosY, g_textHelp.c_str() );

		// kouzla
		kouKC.Draw( TM.GetIdTexture( g_textures[26] ) );
	//	DrawEfektSuroviny();
		
		if(g_showUvod)
		{
			TRect rect_uvod = {120, 50, 400, 300};
			rect_uvod = W_PrevedRectNaScreen( rect_uvod, SCRWidth, SCRHeight );
			Draw2dAlpha( TM.GetIdTexture( g_textures[13] ), rect_uvod, 0.7f );
			menu_uvod.Render();
			menu_uvod.MouseMove(g_hWnd);
			g_font.Print(menu_uvod.PrevedIntXNaScreen(170),menu_uvod.PrevedIntYNaScreen(100),g_poleTextu[g_aktKolo].c_str());
		}

	}else
	if(g_game == game_menu)
	{
		//g_MB.StartMotionBlur( SCRWidth, SCRHeight );
		SetPlayHudba( sound_menu );
		menu.Render();
		menu.MouseMove(g_hWnd);
		
		glDisable(GL_LIGHT1);
		glEnable(GL_LIGHT0);
		glDisable(GL_BLEND);
		glTranslatef(0, 0, -20);
		//g_light0.Draw();
		g_light0.SetPosition(0,0,20,1);

		static float angle_x=0;
		//angle_x += g_fps.GetFPS()/60 * 0.05f;
		
		angle_x += (0.4f*60.0f)/g_fps.GetFPS();
		glRotatef(angle_x, 0, 1, 0);
		char bFog = glIsEnabled( GL_FOG ); //new
		if(bFog) glDisable( GL_FOG );
		glEnable(GL_LIGHTING);
		glEnable(GL_TEXTURE_2D);
		GLUquadricObj *quadratic;
		quadratic=gluNewQuadric();// Vrátí ukazatel na nový kvadrik
		gluQuadricNormals(quadratic, GLU_SMOOTH);// Vygeneruje normálové vektory (hladké)
		gluQuadricTexture(quadratic, GL_TRUE);// Vygeneruje texturové koordináty
		glRotatef(90, 1, 0, 0);
		glBindTexture(GL_TEXTURE_2D, TM.GetIdTexture(g_textures[23]));
		gluSphere(quadratic, 5.0f, 32, 32);
		
		gluDeleteQuadric(quadratic);	
		static float barva = 0.4f;
		static float plus_green = 0.02f;
		barva += (plus_green*60)/g_fps.GetFPS();
		if( barva > 0.8f || barva < 0.4f ) plus_green = -plus_green;
		glColor3f( 0, barva, 0);
		g_font.Print(20, 20, " - http://hrady.freegame.cz - ");
		glColor3f(1, 1, 1);
		//g_MB.EndMotionBlur( SCRWidth, SCRHeight );
		if(bFog) glEnable(GL_FOG);
	}else
	if(g_game == game_vyzkum)
	{
		DrawVyzkum();
	}else
	if(g_game == game_victori)
	{
		DrawVictori( g_kdoVyhral-1 );
	}else
	if(g_game == game_vyberKola)
	{
		// Vyber jednoho z 12 kol
		menu_vyber.Render();
		DrawVyberMenu();
		menu_vyber.MouseMove(g_hWnd);
	}else
	if(g_game == game_nastaveni)
	{
		menu_nas.Render();
		menu_nas.MouseMove(g_hWnd);
	}else
	if(g_game == game_intro)
	{
		DrawIntro();
		//SetPlayHudba( sound_menu );
	}else
	if(g_game == game_credits)
	{
		DrawCredits();
	}else
	if( g_game == game_video )
	{
		glTranslatef(0,0,-4	);
		g_aviIntro.Render();
		g_aviIntro.Update();
		if( g_aviIntro.Konec() ) g_game = game_menu;
		static bool hraje=0;
		if( !hraje ) g_sound.Play( sound_intro );
		hraje = 1;
	}else
	if( g_game == game_outro )
	{
		g_aviOutro.Render();
		g_aviOutro.Update();
		if( g_aviOutro.Konec() ) g_game = game_menu;
	}else
	if( g_game == game_nap )
	{
		C_2DOBJECT_0 obj( TM.GetIdTexture(g_textures[45]+g_AktNapoveda), 0,0,SCRWidth, SCRHeight );
		obj.Render();
		menu_nap.Render();
		menu_nap.MouseMove( g_hWnd );
	}
	if(g_showFPS)
	{
		g_font.Print(SCRWidth/2-50, 10, "Fps : %f", g_fps.GetFPS());
		g_font.Print(SCRWidth/2-50, 30, "Fps : %d", g_1sFps);
/*		g_font.Print(SCRWidth/2-50, 50, "Move : %f", (60*10)/g_fps.GetFPS() );
		g_font.Print(SCRWidth/2-50, 70, "Kolo : %d / %f", (60*10), g_fps.GetFPS());
		g_font.Print(SCRWidth/2-50, 90, "Kolo : %d", g_aktKolo);*/
	}
	g_citFps++;

	// Ztmaveni, odtmaveni
	if(g_light) glDisable(GL_LIGHTING);
	if( g_bFade==1 )
	{
		if( FadeOn( ) )
		{
			if( g_coDelatPoFade == 1) { g_game = game_victori; g_bFade=0; }
			else
			if( g_coDelatPoFade == 2) { g_game = game_vyberKola; g_bFade=0; }
		}
	}else 
	if( g_bFade==2 )
	{
		FadeOff();
	}
	if(g_light) glEnable(GL_LIGHTING);

	glColor3f(1,1,1);
	g_curzor.Render(g_hWnd);
	menu_hra.RenderText();
}

//////////////////////////////////////////////////////////////////////////
// onInit - inicializace dat
//////////////////////////////////////////////////////////////////////////
bool onInit()
{
	// Pri fullscreenu se spusti onInit ze zacatku 2x takze to poprvy si vypnem
	static bool indikace = 0;
	if(!indikace && b_full_screen) { indikace=1; return TRUE; }

	glLineWidth(2.0f);
	glDisable(GL_TEXTURE_2D);							// Zapne mapování textur
	glShadeModel(GL_SMOOTH);							// Povolí Smooth Shading
	glClearColor(0.0f,0.0f,0.0f,1.0f);				
	glClearDepth(1.0f);									// nastavení Depth Buffer
	glEnable(GL_DEPTH_TEST);							// povolý testování hloubky
	glDepthFunc(GL_LEQUAL);								// způsob testování hloubky
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// pěkná perspektiva
	glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);				// Jemnost bodů
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);					// Typ blendingu
	glAlphaFunc(GL_EQUAL, 1.0f);
	
	// Svetlo
	GLfloat LightAmbient[]= { 1.0f, 1.0f, 1.0f, 1.0f };// Okolní světlo
	GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };// Přímé světlo
	
	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);// Nastavení okolního světla
	glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);// Nastavení přímého světla

	
	GLfloat materialDiffuse[]={1.0f, 1.0f, 1.0f, 1.0f};
	glMaterialfv(GL_FRONT, GL_DIFFUSE, materialDiffuse);
	glEnable(GL_LIGHT1);
	glEnable(GL_LIGHTING);

	GLfloat materialAmbient[]={0.7f, 0.7f, 0.7f, 1.0f}; 
	glMaterialfv(GL_FRONT, GL_AMBIENT, materialAmbient); 
														/*GLfloat materialDiffuse[]={0.8f, 0.4f, 0.4f, 1.0f}; // difuzni slozka barvy materialu
	GLfloat materialSpecular[]={1.0f, 1.0f, 1.0f, 1.0f}; // barva odlesku
	GLfloat materialShininess[]={50.0f};            // faktor odlesku*/
   // nastaveni ambientni slozky barvy materialu
   /* glMaterialfv(GL_FRONT, GL_DIFFUSE, materialDiffuse);    // nastaveni difuzni slozky barvy materialu
    glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular);  // nastaveni barvy odlesku
    glMaterialfv(GL_FRONT, GL_SHININESS, materialShininess);// nastaveni faktoru odlesku*/

	// PRVNI LOAD
	if( g_prvniLoad==0 )
	{
		g_textures[45] = TM.AddTexture("Data/Gfx/load.bmp", TM_LINEAR);
		TM.ReloadTextures();
		g_prvniLoad = 1;
		return 0;
	}
	
	// Nastavit context
	gl2->SetAktWglMakeCurrent();

	//SCRHeight = SCRHeight-SCRHeight/6;
	srand( GetTickCount() );
	g_sound.Init();
	sound_menu = g_sound.Load( "Data/sound/hudba/menu.mp3" );
	sound_loop1 = g_sound.Load( "Data/sound/hudba/tema1.mp3" );
	sound_intro = g_sound.Load( "Data/sound/hudba/introXX.mp3" );
	sound_outro = g_sound.Load( "Data/sound/hudba/outroXX.mp3" );
	g_sound.SetVolumeAll( (unsigned char) (122) );
	

	//g_zvuk.Init();
	g_idZvuk[0] = g_zvuk.Load( "Data/sound/zvuky/jednotkaUtok1.WAV" );
	g_idZvuk[1] = g_zvuk.Load( "Data/sound/zvuky/jednotkaUtok2.WAV" );
	g_idZvuk[2] = g_zvuk.Load( "Data/sound/zvuky/jednotkaSmrt1.WAV" );
	g_idZvuk[3] = g_zvuk.Load( "Data/sound/zvuky/jednotkaSmrt2.WAV" );
	g_idZvuk[4] = g_zvuk.Load( "Data/sound/zvuky/jednotkaSmrt3.WAV" );
	g_idZvuk[5] = g_zvuk.Load( "Data/sound/zvuky/KataluptUtok.WAV" );
	g_idZvuk[6] = g_zvuk.Load( "Data/sound/zvuky/KatapultSmrt.wav" );
	g_idZvuk[7] = g_zvuk.Load( "Data/sound/zvuky/lukostrelecUtok.WAV" );
	g_idZvuk[8] = g_zvuk.Load( "Data/sound/zvuky/stisknutiTlacitka.WAV" );

	g_idZvuk[9] = g_zvuk.Load( "Data/sound/zvuky/lukostrelecUtok2.WAV" );
	g_idZvuk[10] = g_zvuk.Load( "Data/sound/zvuky/Dest01.wav" );
	g_idZvuk[11] = g_zvuk.Load( "Data/sound/zvuky/Dest02.wav" );
	g_idZvuk[12] = g_zvuk.Load( "Data/sound/zvuky/Fireball.wav" );
	g_idZvuk[13] = g_zvuk.Load( "Data/sound/zvuky/kouzloVZ.wav" );
	g_idZvuk[14] = g_zvuk.Load( "Data/sound/zvuky/FireballNar.wav" );
	g_idZvuk[15] = g_zvuk.Load( "Data/sound/zvuky/going.wav" );
	// LOADING GRAPHIC //
	/////////////////////
	TM.SetColorAlpha(0, 255, 0);
	
	int setTextureGfx = TM_LINEAR;
	if( g_nasGfx == 1 ) setTextureGfx = TM_NEAREST;
	
	// Loading menu
	menu.SetScreen(SCRWidth, SCRHeight);//
	menu.LoadGUIScript("Data/Menu/menu.men", &TM, setTextureGfx);//
	
	menu_hra.SetScreen(SCRWidth, SCRHeight);//
	menu_hra.LoadGUIScript("Data/Menu/menu_hra.men", &TM, setTextureGfx);//

	menu_vyber.SetScreen(SCRWidth, SCRHeight);
	menu_vyber.LoadGUIScript("Data/Menu/menu_vyber.men", &TM, setTextureGfx);
	
	menu_uvod.SetScreen(SCRWidth, SCRHeight);//
	menu_uvod.LoadGUIScript("Data/Menu/menu_uvod.men", &TM, setTextureGfx);//

	menu_nas.SetScreen(SCRWidth, SCRHeight);//
	menu_nas.LoadGUIScript("Data/Menu/menu_nast.men", &TM, setTextureGfx);//
	
	menu_vyz.SetScreen(SCRWidth, SCRHeight);//
	menu_vyz.LoadGUIScript("Data/Menu/menu_vyz.men", &TM, setTextureGfx);//

	menu_nap.SetScreen(SCRWidth, SCRHeight);//
	menu_nap.LoadGUIScript("Data/Menu/menu_nap.men", &TM, setTextureGfx);//

	//menu_upo.SetScreen(SCRWidth, SCRHeight);//
	//menu_upo.LoadGUIScript("Data/Menu/menu_upo.men", &TM, setTextureGfx);//
	
	// Loading textures scnes - na konci nebudou
	TM.SetColorAlpha(0, 255, 0);
	TM.SetAlphaRozmezi(0);
	g_textures[1] = TM.AddTexture("Data/Gfx/Stones09.bmp", 0x101100);
	g_textures[2] = TM.AddTexture("Data/Gfx/NahUdalosti/zeme.bmp",		setTextureGfx);
	g_textures[3] = TM.AddTexture("Data/Gfx/NahUdalosti/vichr.bmp",		setTextureGfx);
	g_textures[4] = TM.AddTexture("Data/Gfx/NahUdalosti/mor.bmp",		setTextureGfx);
	g_textures[5] = TM.AddTexture("Data/Gfx/NahUdalosti/bore.bmp",		setTextureGfx);
	g_textures[6] = TM.AddTexture("Data/Gfx/NahUdalosti/pozar.bmp",		setTextureGfx);
	g_textures[7] = TM.AddTexture("Data/Gfx/NahUdalosti/banditi.bmp",	setTextureGfx);
	g_textures[9] = TM.AddTexture("Data/Gfx/kapka.bmp", setTextureGfx);
	g_textures[11] = TM.AddTexture("Data/Gfx/Log/Logo_SGSoft05.bmp", setTextureGfx);
	g_textures[12] = TM.AddTexture("Data/Gfx/Log/Nap_Hrady01.bmp", setTextureGfx);
	g_textures[13] = TM.AddTexture("Data/Gfx/Uvod/TabulkaUvodHrady02.bmp", setTextureGfx);
	g_textures[14] = TM.AddTexture("Data/Gfx/Katapult_Strela.bmp", 0x101100 );
	g_textures[36] = TM.AddTexture("Data/Gfx/Katapult_StrelaO.bmp", 0x101100 );//14
	g_textures[15] = TM.AddTexture("Data/Gfx/Particle/firesmall.bmp", setTextureGfx);
	g_textures[16] = TM.AddTexture("Data/Gfx/Particle/smoke.bmp", setTextureGfx);
	g_textures[17] = TM.AddTexture("Data/Gfx/Napis/NapisVitezstvi.bmp", setTextureGfx);
	g_textures[18] = TM.AddTexture("Data/Gfx/Napis/NapisProhra.bmp", setTextureGfx);
	g_textures[19] = TM.AddTexture("Data/Gfx/sip.bmp", TM_NEAREST );
	g_textures[35] = TM.AddTexture("Data/Gfx/sipo.bmp", TM_NEAREST ); 
	g_textures[20] = TM.AddTexture("Data/Gfx/bg_info.bmp", setTextureGfx);
	g_textures[21] = TM.AddTexture("Data/Gfx/Background/TPBvytezstvy.bmp", setTextureGfx);
	g_textures[22] = TM.AddTexture("Data/Gfx/Background/TPBprohra.bmp", setTextureGfx);
	g_textures[23] = TM.AddTexture("Data/Gfx/Earth02.bmp", 0x101100);
	g_textures[24] = TM.AddTexture("Data/Gfx/curzor.bmp", TM_NEAREST);
	g_textures[25] = TM.AddTexture("Data/Gfx/Particle/Flare23.bmp", setTextureGfx);
	g_textures[26] = TM.AddTexture("Data/Gfx/blood.bmp", setTextureGfx);
	g_textures[27] = TM.AddTexture("Data/Gfx/Particle/Flare08.bmp", setTextureGfx);	// textura particle
	g_textures[28] = TM.AddTexture("Data/Gfx/Particle/Flare27.bmp", setTextureGfx);	
	g_textures[29] = TM.AddTexture("Data/Gfx/credits.bmp", setTextureGfx );
	g_textures[30] = TM.AddTexture("Data/Gfx/Particle/pul.bmp", setTextureGfx);	
	g_textures[31] = TM.AddTexture("Data/Gfx/Particle/flare23.bmp", setTextureGfx);	
	g_textures[32] = TM.AddTexture("Data/Gfx/Particle/lensflare.bmp", setTextureGfx);
	TM.SetColorAlpha(0,0,0);
	g_textures[33] = TM.AddTexture("Data/Gfx/Hrady_Mece01.bmp", setTextureGfx);	
	g_textures[34] = TM.AddTexture("Data/Gfx/Particle/flare24.bmp", setTextureGfx);		
	texture_trosky = TM.AddTexture( "Data/Gfx/Particle/firesmall.bmp", setTextureGfx );

	g_textures[37] = TM.AddTexture("Data/Gfx/duha01.bmp", setTextureGfx ); // 19
	g_textures[38] = TM.AddTexture("Data/Gfx/duha02.bmp", 0x101100 );//14
	g_textures[39] = TM.AddTexture("Data/Gfx/NahUdalosti/zlato.bmp", setTextureGfx);
	g_textures[40] = TM.AddTexture("Data/Gfx/NahUdalosti/kameni.bmp", setTextureGfx);
	g_textures[41] = TM.AddTexture("Data/Gfx/NahUdalosti/mana.bmp", setTextureGfx);
	g_textures[42] = TM.AddTexture("Data/Gfx/voda.bmp", setTextureGfx);
	g_textures[43] = TM.AddTexture("Data/Gfx/lava.bmp", setTextureGfx);
	g_textures[44] = TM.AddTexture("Data/Gfx/kriz.bmp", setTextureGfx);

	g_textures[45] = TM.AddTexture("Data/Gfx/Nap/strana1.bmp", setTextureGfx);
	g_textures[46] = TM.AddTexture("Data/Gfx/Nap/strana2.bmp", setTextureGfx);
	g_textures[47] = TM.AddTexture("Data/Gfx/Nap/strana3.bmp", setTextureGfx);

	g_texBlesk[0] = TM.AddTexture("Data/Gfx/Particle/bolt1.bmp", setTextureGfx);	
	g_texBlesk[1] = TM.AddTexture("Data/Gfx/Particle/bolt2.bmp", setTextureGfx);	
	g_texBlesk[2] = TM.AddTexture("Data/Gfx/Particle/bolt3.bmp", setTextureGfx);	
	
	g_textures[48] = TM.AddTexture("Data/Gfx/www.freegame.cz.bmp", setTextureGfx);
	TM.ReloadTextures();
	texture_trosky = TM.GetIdTexture( texture_trosky );
	
	LoadPostav1();
	LoadPostav2();
	LoadPostav3();
	LoadPostav4();
	LoadPostav5();
	LoadPostavSpec();

	TM.ReloadTextures();
	texture_odpad = TM.GetIdTexture( g_textures[29] );
	// Load font //
// ERROR USEK BEGIN
	int iFontSize;
	iFontSize =  (SCRWidth)/(70);
	g_font.LoadFont("Data/Fonts/font1.ttf", iFontSize);
// ERROR USEK END	
	// 3D font
	g_3dFont.Build3dText( g_hWnd );
	g_3dFont.GrabTexture( TM.GetIdTexture( g_textures[43] ) );

	g_vyzkum.Init();
	g_vyzkumProt.Init();
	// Nacist video intro
	g_aviIntro.LoadFile("Data/Avi/intro.avi", 512, 512, 1);
	// Outro
	g_aviOutro.LoadFile("Data/Avi/outro.avi", 512, 512, 1);

	g_dest.Init();
	TRect star_rect = {0,0,50,50};
	g_star.Init(star_rect, TM.GetIdTexture(g_textures[10]), 20);
	//g_info.Add(10000, "Hlášeni :\n---------\n Výtej ve hře hrady. Tvým úkolem \n je bojovat proti nepřítely. ");
	g_info.Init();
	g_ai.SetHrac(g_prot);

	// nacist texty //
	NactiTexty("Data/text.txt", g_poleTextu );

	// nastaveni svetel //
	g_light0.Init(GL_LIGHT0);
	g_light0.SetColor(1,1,1);
	glPushMatrix();
	glLoadIdentity();
	g_light0.SetPosition(0,0,5,0);
	glPopMatrix();
	// nastaveni curzoru //
	g_curzor.SetImage(TM.GetIdTexture(g_textures[24]));
	g_curzor.SetSize(32, 32);
	g_curzor.ShowCursor( 0 );
	g_udalost.Enable();

	// Bonus
	for(register i=0; i<4; i++)
	{
		bonModel[i].LoadModel( W_GetString( "Data/Models/bonus%d.wfo", i+2) ); // zacina od bonus2
		bonModel[i].ReloadTexture( TM );
		bonModel[i].Translate(4, 4, 4);
	}

	NactiData1("Data/data1.txt", g_polePripusLevel);
	NastavTlacVyberMenu(menu_vyber, g_polePripusLevel);
	NastavTlacitka();

	NactiDataVyz("Data/data2.txt", g_vykumSave, &g_hrac.vedBody );
	NastavTlacVyberMenu(menu_vyz, g_vykumSave );
	NastavVyzkum( g_vykumSave );
	

	g_grafDataHrac.Init();
	g_grafDataProt.Init();

	// MENU
	C_BASEGUI_0 *p = menu_nas.GetPointerObject("ID_RADIOBUTTON4");
	C_RADIOBUTTON_0 *r = (C_RADIOBUTTON_0*)p;
	r->SetCheckStavEx( true );

	InfoText.SetStartPos( CVector2(20, 400) );
	g_duch.SetTexture( TM.GetIdTexture( g_textures[31] ) );
	//g_MB.Create();
	g_hrac.kdo = 0;
	g_prot.kdo = 1;
	g_prvniLoad = 3;
	//gl2->SetNullWglMakeCurrent();
	
	return TRUE;
}

//////////////////////////////////////////////////////////////////////////
// onKeyboard - zpracování zpráv z klávesnice
//////////////////////////////////////////////////////////////////////////
void onKeyboard(bool keys[255])
{
	if( keys['C'] ) { ;;keys['C']=0;}
	if( keys['V'] ) {keys['V']=0;}
	
	//if( keys['H'] ) {Bonus.Add(bonModel[1], 1, 0.01, 1); keys['H']=0;}

	if(keys[VK_F5]) {g_showFPS = !g_showFPS;keys[VK_F5]=false;}
	if(keys[VK_F6]) 
	{
		if(g_light)  glDisable(GL_LIGHTING);
		if(!g_light) glEnable(GL_LIGHTING);
		g_light = !g_light;
		keys[VK_F6]=false;
	}
	
	if( keys[VK_ESCAPE] )
	{
		//{game_hra, game_menu, game_intro, game_credits, game_nastaveni, game_vyberKola, game_vyzkum, game_victori, game_video};
		if( g_game == game_menu )			konec();
		if( g_game == game_vyberKola )		g_game = game_menu;
		if( g_game == game_hra && g_pausa == 1 && g_showUvod == 1 ) 
		{
			g_pausa = 0;
			g_showUvod = 0;
		}else
		if( g_game == game_hra && g_kdoVyhral==0 ) 
		{
			g_pausa = 1;
			g_showUvod = 1;
		}
		if( g_game == game_intro )			g_game = game_menu;
		if( g_game == game_credits)			g_game = game_menu;
		if( g_game == game_nastaveni )		g_game = game_menu;
		if( g_game == game_vyzkum )			g_game = game_vyberKola;
		if( g_game == game_victori )		g_game = game_vyberKola;
		if( g_game == game_video )			{g_game = game_menu;g_sound.SetStopId( sound_intro );}
		if( g_game == game_outro )			{g_game = game_menu;g_sound.SetStopId( sound_outro );}
		keys[VK_ESCAPE] = 0;
	}

	// 3D pohledy
	if(keys[VK_F2]) 
	{
		g_rotate = CV3_NULL;
		g_plane = CVector3(0, -3, -10);
		g_camera=0;
	}
	if(keys[VK_F3]) 
	{
		g_rotate = CV3_NULL;
		g_plane = CVector3(0, -2, -8);
		g_camera=1;
	}
	if(keys[VK_F4]) 
	{
		g_rotate = CV3_NULL;
		g_plane = CVector3(0, -4, -10);
		g_camera=2;
	}
	if(keys[VK_ESCAPE])
	{
		g_pausa = 1;
		g_showUvod = 1;
	}
	
	if(keys[VK_F8]) 
	{
		g_hrac.penize += 25000;
		g_hrac.mana += 25000;
		g_hrac.kameny += 25000;
		keys[VK_F8] = 0;
		
	}/*
	if(keys[VK_F7]) 
	{
		g_prot.Hrad = 0;
	}*/
	
	//if( g_game == game_hra ) if(keys['L']) {g_pausa = !g_pausa;keys['L']=0;}

	// screen
	static int citac=0;
	if(keys['P']) 
	{
		TM.SaveImage( W_GetString("image%d.jpg", citac) , SCRWidth, SCRHeight, TM_JPEG_QNORMAL);
		citac++;
		keys['P']=0;
	}

	if(g_game == game_hra && !g_pausa)
	{
		for(int i=0; i<8; i++) if( keys['A'+i] ) SpustKouzlo('A'+i);
		//if(keys['A']) g_plane.z += 0.1f;
		//if(keys['S']) g_plane.z -= 0.1f;

		//if(keys['Q']) {g_hracScena.Add(5);keys['Q']=0;}
		//if(keys['W']) {g_hracScena.Add(10);keys['W']=0;}

		menu_hra.Keyboard(keys);
	}else
	if(g_game == game_menu)
	{
		menu.Keyboard(keys);
	}else
	if( g_game == game_victori )
	{
		if( keys[ VK_RETURN ] )
		{
			g_bFade = 1;
			g_indexFade = 0.05f;
			g_coDelatPoFade = 2;
			
			if( g_kdoVyhral==1 )
			{
				if( g_aktKolo != 11 && g_polePripusLevel[g_aktKolo+1] == 0 ) g_hrac.vedBody +=g_bodyVyzkum[g_aktKolo];
				if( g_aktKolo == 11 ) 
				{
					g_game = game_outro;
					g_coDelatPoFade=0;
					g_bFade=0;
					g_sound.SetStopAll();
					g_sound.Play( sound_outro );
				}
				g_polePripusLevel[g_aktKolo+1] = 1;
				UlozData1("Data/data1.txt", g_polePripusLevel);
				NactiData1("Data/data1.txt", g_polePripusLevel);
				NastavTlacVyberMenu(menu_vyber, g_polePripusLevel);
				NastavTlacitka();
				g_hrac.vedBody += g_hracVedBody;
				UlozData1V("Data/data2.txt", g_vykumSave );
			}else
			{
				NactiData1("Data/data1.txt", g_polePripusLevel);
				NastavTlacVyberMenu(menu_vyber, g_polePripusLevel);
				NastavTlacitka();
			}
			keys[ VK_RETURN ] = 0;
		}
	}
}

//////////////////////////////////////////////////////////////////////////
// onMöuse - Pohyb myšíi
//////////////////////////////////////////////////////////////////////////
void onMouse(int button, int x, int y) // onMouseClick
{
	if(g_game == game_hra && !g_pausa)
	{
		int iClick = menu_hra.MouseClick(button, x, y);
		if( button == W_MOUSE_LEFT && iClick != -1 ) g_zvuk.Play( g_idZvuk[8] );
		if(iClick == menu_hra.GetIterObject("ID_BUT_LISTA") && button == W_MOUSE_LEFT) 
		{
			g_pausa = 1;
			g_showUvod = 1;
		}else
		if(iClick == menu_hra.GetIterObject("ID_BUT1") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= GetCena(cena_dul, g_hrac.doly) && g_hrac.kameny >= GetCena(kamen_dul, g_hrac.doly)) 
			{
				g_hrac.penize -= GetCena(cena_dul, g_hrac.doly); 
				g_hrac.kameny -= GetCena(kamen_dul, g_hrac.doly);
				g_hrac.doly++;
				g_hracStat.poc_budov++;
			}
			//NastavTlacitka();
		}else
		if(iClick == menu_hra.GetIterObject("ID_BUT2") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= GetCena(cena_kamen, g_hrac.kamenictvy) && g_hrac.kameny >= GetCena(kamen_kamen, g_hrac.kamenictvy))
			{
				g_hrac.penize -= GetCena(cena_kamen, g_hrac.kamenictvy);
				g_hrac.kameny -= GetCena(kamen_kamen, g_hrac.kamenictvy);
				g_hrac.kamenictvy++;
				g_hracStat.poc_budov++;
			}
		}else
		if(iClick == menu_hra.GetIterObject("ID_BUT3") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= GetCena(cena_chram, g_hrac.chram) && g_hrac.kameny >= GetCena(kamen_chram, g_hrac.chram)) 
			{
				g_hrac.penize -= GetCena(cena_chram, g_hrac.chram);
				g_hrac.kameny -= GetCena(kamen_chram, g_hrac.chram);
				g_hrac.chram++;
				g_hracStat.poc_budov++;
			}
		}else
		if(iClick == menu_hra.GetIterObject("ID_BUT4") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= GetCena(cena_vedCen, g_hrac.vedCentrum) && g_hrac.kameny >= GetCena(kamen_vedCen, g_hrac.vedCentrum)) 
			{
				g_hrac.penize -= GetCena(cena_vedCen, g_hrac.vedCentrum);
				g_hrac.kameny -= GetCena(kamen_vedCen, g_hrac.vedCentrum);
				g_hrac.vedCentrum++;
				g_hracStat.poc_budov++;
			}
		}else
		// Zed
		if(iClick == menu_hra.GetIterObject("ID_BUT5") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= cena_hradba && g_hrac.kameny >= kamen_hradba && g_hrac.vyska_zed < max_vyska_zed) 
			{
				g_hrac.penize -= cena_hradba;
				g_hrac.kameny -= kamen_hradba;
				g_hrac.vyska_zed += 1.0f;
				if(g_hrac.vyska_zed > max_vyska_zed) g_hrac.vyska_zed = max_vyska_zed;
			}
		}else
		// KOVARNA
		if(iClick == menu_hra.GetIterObject("ID_BUTA") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= GetCena(cena_kovarna, g_hrac.kovarny) && g_hrac.kameny >= GetCena(kamen_kovarna, g_hrac.kovarny)) 
			{
				g_hrac.penize -= GetCena(cena_kovarna, g_hrac.kovarny);
				g_hrac.kameny -= GetCena(kamen_kovarna, g_hrac.kovarny);
				g_hrac.kovarny++;
				g_hracStat.poc_budov++;
			}
		}else
		// ZBROJNICE
		if(iClick == menu_hra.GetIterObject("ID_BUTB") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= GetCena(cena_zbrojnice, g_hrac.zbrojnice) && g_hrac.kameny >= GetCena(kamen_zbrojnice, g_hrac.zbrojnice)) 
			{
				g_hrac.penize -= GetCena(cena_zbrojnice, g_hrac.zbrojnice);
				g_hrac.kameny -= GetCena(kamen_zbrojnice, g_hrac.zbrojnice);
				g_hrac.zbrojnice++;
				g_hracStat.poc_budov++;
			}
		}else
		// STRELNICE
		if(iClick == menu_hra.GetIterObject("ID_BUTC") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= GetCena(cena_strelnice, g_hrac.strelnice) && g_hrac.kameny >= GetCena(kamen_strelnice, g_hrac.strelnice)) 
			{
				g_hrac.penize -= GetCena(cena_strelnice, g_hrac.strelnice);
				g_hrac.kameny -= GetCena(kamen_strelnice, g_hrac.strelnice);
				g_hrac.strelnice++;
				g_hracStat.poc_budov++;
			}
		}else	
		// DILNA 1
		if(iClick == menu_hra.GetIterObject("ID_BUTD") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= GetCena(cena_dilny1, g_hrac.dilny1) && g_hrac.kameny >= GetCena(kamen_dilny1, g_hrac.dilny1)) 
			{
				g_hrac.penize -= GetCena(cena_dilny1, g_hrac.dilny1);
				g_hrac.kameny -= GetCena(kamen_dilny1, g_hrac.dilny1);
				g_hrac.dilny1++;
				g_hracStat.poc_budov++;
			}
		}else
		// Jednotka cislo 1 - lehka jednotka
		if(iClick == menu_hra.GetIterObject("ID_JED1") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= GetCenaJed(cena_jed1, CelkemJednotek(g_hrac) )) 
			{
				g_hrac.penize -=  GetCenaJed(cena_jed1, CelkemJednotek(g_hrac) );
				g_hracScena.Add(1);
			}
		}else
		// Jednotka cislo 2 - tezka jednotka
		if(iClick == menu_hra.GetIterObject("ID_JED2") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= GetCenaJed(cena_jed2, CelkemJednotek(g_hrac) )) 
			{
				g_hrac.penize -=  GetCenaJed(cena_jed2, CelkemJednotek(g_hrac) );
				g_hracScena.Add(3);
			}
		}else
		// Jednotka cislo 3 - strelec
		if(iClick == menu_hra.GetIterObject("ID_JED3") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= GetCenaJed(cena_jed3, CelkemJednotek(g_hrac) )) 
			{
				g_hrac.penize -=  GetCenaJed(cena_jed3, CelkemJednotek(g_hrac) );
				g_hracScena.Add(5);
			}
		}else
		// Jednotka cislo 4 - katapult
		if(iClick == menu_hra.GetIterObject("ID_JED4") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= GetCenaJed(cena_jed4, CelkemJednotek(g_hrac) )) 
			{
				g_hrac.penize -=  GetCenaJed(cena_jed4, CelkemJednotek(g_hrac) );
				g_hracScena.Add(10);
			}
		}else
		// Jednotka cislo 5 - mag
		if(iClick == menu_hra.GetIterObject("ID_JED5") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.penize >= GetCenaJed(cena_jed5, CelkemJednotek(g_hrac) )) 
			{
				g_hrac.penize -=  GetCenaJed(cena_jed5, CelkemJednotek(g_hrac) );
				g_hracScena.Add(7);
			}
		}else
		if(iClick == menu_hra.GetIterObject("ID_KOU1") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.mana >= mana_sur) 
			{
				g_hrac.mana -= mana_sur;
				PridejSuroviny(g_hrac, 0, TM.GetIdTexture( g_textures[28] ));
				g_hracStat.poc_kouzel++;
			}
		}else
		if(iClick == menu_hra.GetIterObject("ID_KOU2") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.mana >= mana_att) 
			{
				g_hrac.mana -= mana_att;			
				for(register j=0; j<1; j++)
				{
					float od_x = (rand()%100)/1000.0f;
					float od_y = (rand()%20)/10.0f ;
					g_fire.NewFirebool(TM.GetIdTexture(g_textures[15]), TM.GetIdTexture(g_textures[27]), CVector3(-4.0f+od_x,1+od_y,-1.0), CVector3(5,0,0), CVector3(0.05,0,0), 0.5f, 0);
					g_hracStat.poc_kouzel++;
				}
			}
		}else
			// VYSATI ZASOB SOUPERE
		if(iClick == menu_hra.GetIterObject("ID_KOU3") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.mana >= mana_3)
			{
				g_hrac.mana -= mana_3;
				// vlastni kouzlo
				Vysati_soupere(g_hrac, g_prot, 0, TM.GetIdTexture( g_textures[30] ) );
				g_hracStat.poc_kouzel++;
			}
		}else
			// ZPOMALENI
		if(iClick == menu_hra.GetIterObject("ID_KOU4") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.mana >= mana_4)
			{
				g_hrac.mana -= mana_4;
				// vlastni kouzlo
				kouSP.Enable();
				g_hracStat.poc_kouzel++;
			}
		}else
		// KAMEN CHAOSU
		if(iClick == menu_hra.GetIterObject("ID_KOU5") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.mana >= mana_5)
			{
				g_hrac.mana -= mana_5;
				// vlastni kouzlo
				kouKC.Enable();
				g_hracStat.poc_kouzel++;
			}
		}else
		// kouzlo 6 - ZAPOMNETLIVOST
		if(iClick == menu_hra.GetIterObject("ID_KOU6") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.mana >= mana_6)
			{
				g_hrac.mana -= mana_6;
				// vlastni kouzlo
				g_zapomnetlivostProt = 1;
				g_hracStat.poc_kouzel++;
			}
		}else
		// kouzlo 7
		if(iClick == menu_hra.GetIterObject("ID_KOU7") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.mana >= mana_7)
			{
				g_hrac.mana -= mana_7;
				// vlastni kouzlo
				g_kouzloBoziOchrana = 1;
				g_hracStat.poc_kouzel++;
			}
		}else
		// kouzlo 8 - vyvolani dem. prisery
		if(iClick == menu_hra.GetIterObject("ID_KOU8") && button == W_MOUSE_LEFT) 
		{
			if(g_hrac.mana >= mana_8)
			{
				g_hrac.mana -= mana_8;
				// vlastni kouzlo
				g_hracScena.Add( 20 );
			}
		}else
		// TRH 1 
		if(iClick == menu_hra.GetIterObject("ID_TRH1") && button == W_MOUSE_LEFT) 
		{
			// Prevod Kameni na zlato
			if( g_hrac.kameny >= 500 )
			{
				g_hrac.kameny -= 500;
				g_hrac.penize += 200;
				InfoText.Add(" Vyměnil jsi 500 kameni za 200 zlata ", RGBf_WHITE );
			}
		}else
		// TRH 2 
		if(iClick == menu_hra.GetIterObject("ID_TRH2") && button == W_MOUSE_LEFT) 
		{
			// Prevod Kameni na zlato
			if( g_hrac.mana >= 50 )
			{
				g_hrac.mana -= 50;
				g_hrac.penize += 200;
				InfoText.Add(" Vyměnil jsi 50 many za 200 zlata ", RGBf_WHITE );
			}
		}
	}else
	if(g_game == game_vyberKola)
	{
		int iClick = menu_vyber.MouseClick(button, x, y);
		if( button == W_MOUSE_LEFT && iClick != -1 ) g_zvuk.Play( g_idZvuk[8] );
		if(iClick == menu_vyber.GetIterObject("ID_BUT_BACK") && button == W_MOUSE_LEFT) g_game = game_menu;
		if(iClick == menu_vyber.GetIterObject("ID_BUT_VYZ") && button == W_MOUSE_LEFT) {g_game = game_vyzkum;g_showUpozVyz=0;}
		for(int i=0; i<12; i++)
		{
			std::string text = "ID_BUTTON";
			char cislo[10];
			_itoa(i+1, cislo, sizeof(cislo));
			text += cislo;
			if(iClick == menu_vyber.GetIterObject( text.c_str() ) && button == W_MOUSE_LEFT)
			{
				g_aktKolo = i;
				NoveKolo();
				g_game = game_hra;
			}
		}
	}else
	if(g_game == game_vyzkum)
	{
		int iClick = menu_vyz.MouseClick(button, x, y);
		if(iClick == menu_vyz.GetIterObject("ID_BUT_BACK") && button == W_MOUSE_LEFT) g_game = game_vyberKola;
		// Vyzkum
		if(iClick == menu_vyz.GetIterObject("ID_BUTTON1") && button == W_MOUSE_LEFT && g_hrac.vedBody >= cena_vyz[0])
		{
			g_vyzkum.olej = 1;
			C_BASEGUI_0 *p = menu_vyz.GetPointerObject("ID_BUTTON1");	
			p->SetState(0);
			g_hrac.vedBody -= cena_vyz[0];
			g_vykumSave[0] = 0;
			UlozData1V("Data/data2.txt", g_vykumSave );
		}else
		if(iClick == menu_vyz.GetIterObject("ID_BUTTON2") && button == W_MOUSE_LEFT && g_hrac.vedBody >= cena_vyz[1])
		{
			g_textures[19] = g_textures[35];
			C_BASEGUI_0 *p = menu_vyz.GetPointerObject("ID_BUTTON2");	
			p->SetState(0);
			g_hrac.vedBody -= cena_vyz[1];
			g_vykumSave[1] = 0;
			UlozData1V("Data/data2.txt", g_vykumSave );
		}else
		if(iClick == menu_vyz.GetIterObject("ID_BUTTON3") && button == W_MOUSE_LEFT && g_hrac.vedBody >= cena_vyz[2])
		{
			g_textures[14] = g_textures[36];
			C_BASEGUI_0 *p = menu_vyz.GetPointerObject("ID_BUTTON3");	
			p->SetState(0);
			g_hrac.vedBody -= cena_vyz[2];
			g_vykumSave[2] = 0;
			UlozData1V("Data/data2.txt", g_vykumSave );
		}
		if(iClick == menu_vyz.GetIterObject("ID_BUTTON4") && button == W_MOUSE_LEFT && g_hrac.vedBody >= cena_vyz[3])
		{
			g_vyzkum.obrana = 1;
			C_BASEGUI_0 *p = menu_vyz.GetPointerObject("ID_BUTTON4");	
			p->SetState(0);
			g_hrac.vedBody -= cena_vyz[3];
			g_vykumSave[3] = 0;
			UlozData1V("Data/data2.txt", g_vykumSave );
		}else
		if(iClick == menu_vyz.GetIterObject("ID_BUTTON5") && button == W_MOUSE_LEFT && g_hrac.vedBody >= cena_vyz[4])
		{
			g_vyzkum.brneni = 1;
			C_BASEGUI_0 *p = menu_vyz.GetPointerObject("ID_BUTTON5");	
			p->SetState(0);
			g_hrac.vedBody -= cena_vyz[4];
			g_vykumSave[4] = 0;
			UlozData1V("Data/data2.txt", g_vykumSave );
		}else
		if(iClick == menu_vyz.GetIterObject("ID_BUTTON6") && button == W_MOUSE_LEFT && g_hrac.vedBody >= cena_vyz[5])
		{
			g_vyzkum.kostel = 1;
			C_BASEGUI_0 *p = menu_vyz.GetPointerObject("ID_BUTTON6");	
			p->SetState(0);
			g_hrac.vedBody -= cena_vyz[5];
			g_vykumSave[5] = 0;
			UlozData1V("Data/data2.txt", g_vykumSave );
		}
		if(iClick == menu_vyz.GetIterObject("ID_BUTTON7") && button == W_MOUSE_LEFT && g_hrac.vedBody >= cena_vyz[6])
		{
			plus_penize++;
			C_BASEGUI_0 *p = menu_vyz.GetPointerObject("ID_BUTTON7");	
			p->SetState(0);
			g_hrac.vedBody -= cena_vyz[6];
			g_vykumSave[6] = 0;
			UlozData1V("Data/data2.txt", g_vykumSave );
		}else
		if(iClick == menu_vyz.GetIterObject("ID_BUTTON8") && button == W_MOUSE_LEFT && g_hrac.vedBody >= cena_vyz[7])
		{
			plus_kameny += 2;
			C_BASEGUI_0 *p = menu_vyz.GetPointerObject("ID_BUTTON8");	
			p->SetState(0);
			g_hrac.vedBody -= cena_vyz[7];
			g_vykumSave[7] = 0;
			UlozData1V("Data/data2.txt", g_vykumSave );
		}else
		if(iClick == menu_vyz.GetIterObject("ID_BUTTON9") && button == W_MOUSE_LEFT && g_hrac.vedBody >= cena_vyz[8])
		{
			plus_mana += 1;
			C_BASEGUI_0 *p = menu_vyz.GetPointerObject("ID_BUTTON9");	
			p->SetState(0);
			g_hrac.vedBody -= cena_vyz[8];
			g_vykumSave[8] = 0;
			UlozData1V("Data/data2.txt", g_vykumSave );
		}
		if(iClick == menu_vyz.GetIterObject("ID_BUTTON10") && button == W_MOUSE_LEFT && g_hrac.vedBody >= cena_vyz[9])
		{
			g_vyzkum.domoobrana = 1;
			C_BASEGUI_0 *p = menu_vyz.GetPointerObject("ID_BUTTON10");	
			p->SetState(0);
			g_hrac.vedBody -= cena_vyz[9];
			g_vykumSave[9] = 0;
			UlozData1V("Data/data2.txt", g_vykumSave );
		}else
		if(iClick == menu_vyz.GetIterObject("ID_BUTTON11") && button == W_MOUSE_LEFT && g_hrac.vedBody >= cena_vyz[10])
		{
			g_vyzkum.trziste = 1;
			C_BASEGUI_0 *p = menu_vyz.GetPointerObject("ID_BUTTON11");	
			p->SetState(0);
			g_hrac.vedBody -= cena_vyz[10];
			g_vykumSave[10] = 0;
			UlozData1V("Data/data2.txt", g_vykumSave );
		}else
		if(iClick == menu_vyz.GetIterObject("ID_BUTTON12") && button == W_MOUSE_LEFT && g_hrac.vedBody >= cena_vyz[11])
		{
			g_vyzkum.chram = 1;
			C_BASEGUI_0 *p = menu_vyz.GetPointerObject("ID_BUTTON12");	
			p->SetState(0);
			g_hrac.vedBody -= cena_vyz[11];
			g_vykumSave[11] = 0;
			UlozData1V("Data/data2.txt", g_vykumSave );
		}
		
	}else
	if(g_game == game_menu)
	{
		//menu.MouseClick(button, x, y);
		int iClick = menu.MouseClick(button, x, y);
		if(iClick == menu.GetIterObject("ID_BUTTON1") && button == W_MOUSE_LEFT) g_game = game_vyberKola;
		if(iClick == menu.GetIterObject("ID_BUTTON2") && button == W_MOUSE_LEFT) g_game = game_nastaveni;
		if(iClick == menu.GetIterObject("ID_BUTTON3") && button == W_MOUSE_LEFT) g_game = game_credits;
		if(iClick == menu.GetIterObject("ID_BUTTON4") && button == W_MOUSE_LEFT) konec();
	}
	if( g_game == game_nastaveni )
	{
		int iClick = menu_nas.MouseClick(button, x, y);
		if( button == W_MOUSE_LEFT && iClick != -1 ) g_zvuk.Play( g_idZvuk[8] );
		textREC.Add("Click ", iClick);
		if(iClick == menu_nas.GetIterObject("ID_BUT_BACK") && button == W_MOUSE_LEFT) g_game = game_menu;

		if( menu_nas.GetIterObject("ID_CHECKBOX2") == iClick )
		{
			C_BASEGUI_0 *p = menu_nas.GetPointerObject("ID_CHECKBOX2");
			C_CHECKBOX_0 *c = (C_CHECKBOX_0*)p;
			bool stav_check = c->GetCheckStav();
			g_sound.PauseAll( stav_check );
		}
		if( menu_nas.GetIterObject("ID_CHECKBOX1") == iClick )
		{
			C_BASEGUI_0 *p = menu_nas.GetPointerObject("ID_CHECKBOX1");
			C_CHECKBOX_0 *c = (C_CHECKBOX_0*)p;
			bool stav_check = c->GetCheckStav();
			g_zvuk.PauseAll( stav_check );
		}
		static bool going_enable=0;
		if( button != W_MOUSE_UNLEFT ) going_enable=0; 
		if( menu_nas.GetIterObject("ID_SLIDER1") == iClick ) going_enable=1;
		if( going_enable && button == W_MOUSE_UNLEFT ) g_zvuk.Play( g_idZvuk[15] );

		if( menu_nas.GetIterObject("ID_RADIOBUTTON3") == iClick ) g_obtiznost = 0;
		if( menu_nas.GetIterObject("ID_RADIOBUTTON4") == iClick ) g_obtiznost = 1;
		if( menu_nas.GetIterObject("ID_RADIOBUTTON5") == iClick ) g_obtiznost = 2;
	}
	if( g_game == game_nap )
	{
		int iClick = menu_nap.MouseClick(button, x, y);
		if( button == W_MOUSE_LEFT && iClick != -1 ) g_zvuk.Play( g_idZvuk[8] );
		if(iClick == menu_nap.GetIterObject("ID_BUT_BACK") && button == W_MOUSE_LEFT) g_game = game_hra;
		if(iClick == menu_nap.GetIterObject("ID_BUT_DALSI") && button == W_MOUSE_LEFT) g_AktNapoveda++;
		if( g_AktNapoveda > 2 ) g_AktNapoveda = 0;
	}

	//////////////////////////////////////////////////////////////////////////
	// Uvodni menu ve hre
	if(g_game == game_hra && g_pausa)
	{
		int iClick = menu_uvod.MouseClick(button, x, y);
		if( button == W_MOUSE_LEFT && iClick != -1 ) g_zvuk.Play( g_idZvuk[8] );
		if(iClick == menu_uvod.GetIterObject("ID_BUTTON1") && button == W_MOUSE_LEFT)
		{
			g_pausa = 0;
			g_showUvod = 0;
		}else
		if(iClick == menu_uvod.GetIterObject("ID_BUTTON2") && button == W_MOUSE_LEFT)
		{
			g_game = game_nap;
		}else
		if(iClick == menu_uvod.GetIterObject("ID_BUTTON3") && button == W_MOUSE_LEFT) // konec
		{
			g_game = game_menu;
			NactiData1("Data/data1.txt", g_polePripusLevel);
			NastavTlacVyberMenu(menu_vyber, g_polePripusLevel);
			NastavTlacitka();
		}
	}
}

void onMouseMove(int button, int x, int y)
{
	if(g_game == game_hra /*&& !g_pausa*/)
	{
	/*	// otaceni s hrou
		static bool bOtoceni = 0;
		static TPoint pBod;
		if(button == W_MOUSE_RIGHT)		bOtoceni=1;
		if(button == W_MOUSE_UNRIGHT)	bOtoceni=0;
		if(bOtoceni)
		{
			if(pBod.x != x) g_rotate.y -= pBod.x-x; 
			if(pBod.y != y) g_rotate.x -= pBod.y-y; 
		}
		{
			pBod.x = x;
			pBod.y = y;
		}*/
	}else
	if( g_game == game_vyzkum )
	{
		int iMouse = menu_vyz.MouseMove(x,y);
		if( iMouse == menu_vyz.GetIterObject("ID_BUTTON1") ) g_textVyzkum = textVyzkum1;
		else if( iMouse == menu_vyz.GetIterObject("ID_BUTTON2") ) g_textVyzkum = textVyzkum2;
		else if( iMouse == menu_vyz.GetIterObject("ID_BUTTON3") ) g_textVyzkum = textVyzkum3;
		else if( iMouse == menu_vyz.GetIterObject("ID_BUTTON4") ) g_textVyzkum = textVyzkum4;
		else if( iMouse == menu_vyz.GetIterObject("ID_BUTTON5") ) g_textVyzkum = textVyzkum5;
		else if( iMouse == menu_vyz.GetIterObject("ID_BUTTON6") ) g_textVyzkum = textVyzkum6;
		else if( iMouse == menu_vyz.GetIterObject("ID_BUTTON7") ) g_textVyzkum = textVyzkum7;
		else if( iMouse == menu_vyz.GetIterObject("ID_BUTTON8") ) g_textVyzkum = textVyzkum8;
		else if( iMouse == menu_vyz.GetIterObject("ID_BUTTON9") ) g_textVyzkum = textVyzkum9;
		else if( iMouse == menu_vyz.GetIterObject("ID_BUTTON10") ) g_textVyzkum = textVyzkum10;
		else if( iMouse == menu_vyz.GetIterObject("ID_BUTTON11") ) g_textVyzkum = textVyzkum11;
		else if( iMouse == menu_vyz.GetIterObject("ID_BUTTON12") ) g_textVyzkum = textVyzkum12;
		else if( iMouse == 0 ) g_textVyzkum="";

	}else
	if( g_game == game_vyberKola )
	{
		g_butVyzMove = 0;
		int iMouse = menu_vyber.MouseMove(x,y);
		if( iMouse == menu_vyber.GetIterObject("ID_BUT_VYZ") ) g_butVyzMove = 1;
	}
}

//////////////////////////////////////////////////////////////////////////
// onResize
//////////////////////////////////////////////////////////////////////////
void onResize(int w, int h)
{
	glViewport(0, 0, w, h);						
	glMatrixMode(GL_PROJECTION);						
	glLoadIdentity();
	
	//gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f);
	gluPerspective(45.0f, (GLfloat)SCRWidth/(GLfloat)SCRHeight, 0.1f, 100.0f);
	glMatrixMode(GL_MODELVIEW);							
	glLoadIdentity();
}

//////////////////////////////////////////////////////////////////////////
// onTimer - funkce casovace 
//////////////////////////////////////////////////////////////////////////
void onTimer()
{
	if( !g_enableTimer ) return;
	if( g_prvniLoad==1 )
	{
		static int citac;
		citac++;
		if( citac > 2 )
		{
			g_prvniLoad=2;
			onInit();
		}
	}

	if(g_game == game_hra && !g_pausa)
	{
		g_hracStat.hraciDoba++;
		// pocitani pro 5 kolo
		if( g_aktKolo == 4 )
		{
			static int citac;
		
			if( citac == 5 )
			{
				g_cas5kolo--;
				if( g_cas5kolo == 250 )
				{
					g_info.Add(4000, "Král Godefroy ti posílá jako pomoc \n 3000 zlata.");
					g_hrac.penize += 3000;
				}
				if( g_cas5kolo == 280 )
				{
					g_info.Add(4000, "Král Godefroy ze sousedního království \n ti jako pomoc posílá 1 odíl \n lučišníků.");
					g_hracScena.Add( 5 );
				}
				if( g_cas5kolo == 190 ) g_prot.penize += 2000;
				if( g_cas5kolo == 170 ) g_prot.penize += 4000;
				if( g_cas5kolo == 150 ) g_prot.penize += 3000;
				if( g_cas5kolo == 100 ) g_prot.penize += 3000;
				if( g_cas5kolo == 80 ) g_prot.penize += 2000;
				if( g_cas5kolo == 70 ) g_prot.penize += 4000;
				if( g_cas5kolo == 60 ) g_prot.penize += 1500;
				if( g_cas5kolo == 30 ) g_prot.penize += 3500;
				if( g_cas5kolo == 15 ) g_prot.penize += 8000;
				if( g_cas5kolo < 0 )
				{
					g_cas5kolo = 0;
				}
				citac = 0;
			}
			citac++;
		}
		// scripting pro 1 kolo
		if( g_aktKolo == 0 && g_hracStat.hraciDoba == 50)
		{
			g_info.Add(5000, "Info : \n -------------- \n Použitím kláves F2, F3, F4 můžeš \n přepínat pohledy.");
		}
		if( g_aktKolo == 0 && g_hracStat.hraciDoba == 130)
		{
			g_info.Add(5000, "Info : \n -------------- \n Použitím klávesy F5 můžeš zjistit \n aktuální FPS.");
		}
		// scripting pro 3 kolo
		if( g_aktKolo == 2 && g_hracStat.hraciDoba == 20)
		{
			g_info.Add(5000, "Info : \n -------------- \n Od tohoto kola múžeš používat kouzla.\n Kouzla se zobrazují dole.");
		}
		if( g_aktKolo == 2 && g_hracStat.hraciDoba == 60)
		{
			g_info.Add(5000, "Info : \n -------------- \n Pro rychlé použití kouzla Přidání \n surovin, použij klávesu A.");
		}
		// scripting pro 4 kolo

		g_hrac.penize  += plus_penize*g_hrac.doly;
		g_hrac.kameny  += plus_kameny*g_hrac.kamenictvy;
		static int citac=0;
		if( citac == 5 ) 
		{
			g_hrac.mana    += plus_mana*g_hrac.chram;
			citac = 0;
		}
		citac++;
		static int cit = 0;
		if(cit == 10)
		{
			g_hracVedBody += plus_vedBody*g_hrac.vedCentrum;
			cit=0;
		}
		cit++;
		if( g_hracVedBody > 100 ) g_hracVedBody = 100;
		// Tlacitka
		NastavTlacitka();
		g_hracScena.Refresh(g_prot, 0.15f);
		g_protScena.Refresh(g_hrac, 0);

		if( g_kouzloBoziOchrana )
		{
			static int cas=0;
			cas++;
			if( cas == 30 )
			{
				g_kouzloBoziOchrana=0;
				cas=0;
			}
		}
		
		// domoobrana //
		if( g_vyzkum.domoobrana ) g_hrac.Hrad += g_hrac.domoobrana;
		if(g_hrac.Hrad > g_hrac.max_hrad) g_hrac.Hrad = g_hrac.max_hrad;
		
		// AI - protihrac //
		g_ai.Refresh();

		// domoobrana prot //
		g_prot.Hrad += g_prot.domoobrana;
		if(g_prot.Hrad > g_prot.max_hrad) g_prot.Hrad = g_prot.max_hrad;
		OmezeniMaxima(g_hrac);
		OmezeniMaxima(g_prot);
		g_udalost.Refresh();
		BunusUpdate();
		g_pocasi.GenerujPocasi();
		if( g_zapomnetlivostProt )
		{
			static int citac=0;
			citac++;
			if( citac >= 30*4 )
			{
				// pul minuty
				g_zapomnetlivostProt = 0;
				citac=0;
			}
		}
	}

	g_1sFps = g_citFps*4;
	g_citFps=0;

	//////////////////////////////////////////////////////////////////////////
	// Prepocutavani hradu
	static int citacGraf=0;
	static int hrac_hrad_old=0, hrac_rozdil=0;
	static int prot_hrad_old=0, prot_rozdil=0;
	if( hrac_hrad_old != 0 ) hrac_rozdil += hrac_hrad_old-g_hrac.Hrad;
	if( prot_hrad_old != 0 ) prot_rozdil += prot_hrad_old-g_prot.Hrad;
	
	if( citacGraf % 2 == 0 )
	{
		g_grafDataHrac._aktBody += prot_rozdil;
		g_grafDataProt._aktBody += hrac_rozdil;

		prot_rozdil=0;
		hrac_rozdil=0;
	}

	hrac_hrad_old = g_hrac.Hrad;
	prot_hrad_old = g_prot.Hrad;

	// Pocitani grafu
	if( citacGraf >= 5*4 && g_game==game_hra) // 5sec
	{
		g_grafDataHrac.ZapisBody();
		g_grafDataProt.ZapisBody();
		citacGraf = 0;
	}
	citacGraf++;
	g_enableTimer = 0;
}
//////////////////////////////////////////////////////////////////////////
// DrawGame - vlastni vykresleni hry
//////////////////////////////////////////////////////////////////////////
void DrawGame()
{
	float x1 = -40, y1 = -60;
	float dalkaZed_y = 3.0f;
	float vyskaZed = 0.0f;

	glPushMatrix();
	glTranslatef(0,0,-10);
	//glRotatef(-90, 1, 0, 0);
	//glRotatef(90, 0, 0, 1);
	g_scena.Render();
	glPopMatrix();

	int iZedTextY = menu_hra.PrevedIntYNaScreen(390);
	// Vykresleni fontu velikost zdi //
	g_font.Print(menu_hra.PrevedIntXNaScreen(130), iZedTextY, "Zed : %d", int(g_hrac.vyska_zed*100));
	g_font.Print(menu_hra.PrevedIntXNaScreen(470), iZedTextY, "Zed : %d", int(g_prot.vyska_zed*100));
	
	// Vykresleni fontu velikost hradu //
	g_font.Print(menu_hra.PrevedIntXNaScreen(40), iZedTextY, "Hrad : %d", int(g_hrac.Hrad));
	//g_font.Print(menu_hra.PrevedIntXNaScreen(540), iZedTextY, "Hrad : %d", int(g_prot.Hrad));

	glColor3ub(1,1,1);

	glEnable(GL_LIGHTING);
	SetMatAmbEx( LIGHT_T );
	if( g_blesknuti )	SetMatAmbEx( LIGHT_B );
	
	// modely hradu 1 //
	glPushMatrix();
	glTranslatef(-4.9, 0.0, -2);
	glRotatef(90,0,1,0);
	if( g_aktKolo >= 6 ) glTranslatef(0,0,-0.4f);
	hradD.Render();
	g_scenKou.Coli( hradD, g_hrac, 1 );
	glRotatef(-90,0,1,0);
	DrawParticleHrad2();//hrac
	glPopMatrix();

	// modely hradu 2 //
	glPushMatrix();
	glTranslatef(5.0,0.0, -2);
	glRotatef(-90,0,1,0);
	hradZ.Render();
	g_scenKou.Coli( hradZ, g_prot, 0 );
	glRotatef(90,0,1,0);
	DrawParticleHrad1();//prot
	glPopMatrix();
	if( !g_light ) glDisable(GL_LIGHTING);
	SetMatAmbEx( LIGHT_S );
	if( g_blesknuti )	SetMatAmbEx( LIGHT_B );

	// Vykresli pocty budov //
	glColor3ub(0,0,255);
	TRect rect = {23,55,0,0};
	rect = menu_hra.PrevedRectNaScreen(rect);
	int od_okna = menu_hra.PrevedIntXNaScreen(40);
	g_font.Print(rect.x,rect.y,"%d", g_hrac.doly);
	g_font.Print(rect.x+od_okna*1,rect.y,"%d", g_hrac.kamenictvy);
	if( g_aktKolo >= 2 ) g_font.Print(rect.x+od_okna*2,rect.y,"%d", g_hrac.chram);
	if( g_aktKolo >= 3 ) g_font.Print(rect.x+od_okna*3,rect.y,"%d", g_hrac.vedCentrum);

	int pos_y = menu_hra.PrevedIntYNaScreen(105);	
	g_font.Print(rect.x, pos_y, "%d", g_hrac.kovarny);
	if( g_aktKolo >= 1 ) g_font.Print(rect.x+od_okna, pos_y, "%d", g_hrac.zbrojnice);
	if( g_aktKolo >= 2 ) g_font.Print(rect.x+od_okna*2, pos_y, "%d", g_hrac.strelnice);
	if( g_aktKolo >= 4 ) g_font.Print(rect.x+od_okna*3, pos_y, "%d", g_hrac.dilny1);

	// Vykreslit pocty surovin u protivniku //
	//if( g_infiltrace )
	{
		glColor3f(1,1,1);
		int iFontSize;
		iFontSize = (SCRWidth)/(70);
		int x = menu_hra.PrevedIntXNaScreen(555);
		int y = menu_hra.PrevedIntYNaScreen(370);
		g_font.Print(x, y,    "Peníze : %d", g_prot.penize );
		g_font.Print(x, y+iFontSize, "Kamení : %d", g_prot.kameny );
		g_font.Print(x, y+iFontSize*2, "Mana : %d", g_prot.mana );
		g_font.Print(x, y+iFontSize*3, "Doly : %d", g_prot.doly );
		g_font.Print(x, y+iFontSize*4, "Hrad : %d", g_prot.Hrad );
		g_font.Print(x, y+iFontSize*5, "Kovárny : %d", g_prot.kovarny );
		g_font.Print(x, y+iFontSize*6, "Zbrojnice : %d", g_prot.zbrojnice );
		g_font.Print(x, y+iFontSize*7, "Střelnice : %d", g_prot.strelnice );
		g_font.Print(x, y+iFontSize*8, "Dílny : %d", g_prot.dilny1 );
	}
	
	// Ovladani a vykresleni jednotek //
	g_hracScena.Coli(-dalkaZed_x, g_prot, g_protScena);
	if(!g_pausa) g_hracScena.Move( g_hrac, g_fps.GetFPS() );
	
	g_protScena.Coli(dalkaZed_x, g_hrac, g_hracScena);
	if(!g_pausa) g_protScena.Move( g_prot, g_fps.GetFPS() );
	
	// sip
	g_scenSip.Render();
	if(!g_pausa) g_scenSip.Move( 0.12f );
	g_scenSip.Coli();
	g_scenSip.Coli(g_protScena, 1, g_hrac.vyska_zed );
	g_scenSip.Coli(g_hracScena, 0, g_prot.vyska_zed );
	// Koule
	if(!g_pausa) g_scenKou.Move( 0.12f );
	g_scenKou.Coli();
	g_scenKou.Coli( g_hracScena, 0, g_prot.vyska_zed );
	g_scenKou.Coli( g_protScena, 1, g_hrac.vyska_zed );


	// Vykresli zdi //
	g_blend_hrac = g_hracScena.ColiZed( dalkaZed_x, 0 );
	g_blend_prot = g_protScena.ColiZed( -dalkaZed_x, 1 );

	g_blend_prot = g_hracScena.ColiZed( -dalkaZed_x, 1, g_blend_prot );
	g_blend_hrac = g_protScena.ColiZed( dalkaZed_x, 0, g_blend_hrac );

	if(g_blend_prot) OnBlendZed(g_BlendZedProt, 0);
	if(!g_blend_prot) OffBlendZed(g_BlendZedProt, 0);
	
	if(g_blend_hrac) OnBlendZed(g_BlendZedHrac, 0);
	if(!g_blend_hrac) OffBlendZed(g_BlendZedHrac, 0);

	float zed_prot_ods = -0.03f;
	//if( g_aktKolo == 6 ) zed_prot_ods = -0.18f;
	C_3DOBJECT_0 hrac_zed(TM.GetIdTexture(g_textures[1]), dalkaZed_x, -0.03, 0.3, 0.3f, g_hrac.vyska_zed,-4);
	hrac_zed.SetNatazeni( 2 );
	hrac_zed.Set3d(1);
	float barva1 = g_BlendZedHrac.blend;
	hrac_zed.SetColorf(barva1, barva1, barva1);
	if(g_BlendZedHrac.on) hrac_zed.SetBlend(1);

	C_3DOBJECT_0 prot_zed(TM.GetIdTexture(g_textures[1]), -dalkaZed_x, zed_prot_ods, 0.3, 0.3f, g_prot.vyska_zed,-4);
	prot_zed.SetNatazeni( 2 );
	prot_zed.Set3d(1);
	float barva2 = g_BlendZedProt.blend;
	prot_zed.SetColorf(barva2, barva2, barva2);
	if(g_BlendZedProt.on) prot_zed.SetBlend(1);

	// Hvezdy & Kouzla//
	//g_star.Render();
	//g_star.Move(0.1f);
	
	// delka zed == -3.5
	g_fire.Coli( -dalkaZed_x, 4.5, g_prot, 0);
	g_fire.Coli( dalkaZed_x, -4.5, g_hrac, 1);
	Testing();
	if(!g_pausa) g_mlha_co = SpoustejMlhu(g_mlha_cislo, 0.0f);	//timer
	g_info.Render( g_fps.GetFPS() );

	// bomusy
	g_partKruh.Draw();
	Bonus.Draw();

	g_udalost.Render();

	kouSP.Draw(); // kouzlo spomaleni // refresh, bez kresleni :/ grrrr

	if( !g_pausa ) Bonus.Refresh( g_fps.GetFPS() );
	Bonus.Colise( g_hrac, g_hracScena, 0 );
	Bonus.Colise( g_prot, g_protScena, 1 );

	if( g_cas5kolo <= 0 && g_aktKolo == 4 ) {g_kdoVyhral=1;g_indexFade = 0.005f;}
	// Napsat napis vyhra nebo prohra
	if( g_kdoVyhral==1 ) // hrac vyhral
	{
		TRect rect = {170, 140, 300, 100};
		rect = W_PrevedRectNaScreen( rect, SCRWidth, SCRHeight );
		C_2DOBJECT_0 obj( TM.GetIdTexture(g_textures[17]), rect );
		obj.SetAplha(0);
		obj.SetBlend(1);
		glColor4f( 1, 1, 1, 0.9 );
		obj.Render();
		g_bFade = 1;
		g_coDelatPoFade = 1;
	}else
	if( g_kdoVyhral ==2 ) // protivnik vyhral
	{
		TRect rect = {170, 140, 300, 100};
		rect = W_PrevedRectNaScreen( rect, SCRWidth, SCRHeight );
		C_2DOBJECT_0 obj( TM.GetIdTexture(g_textures[18]), rect );
		obj.SetAplha(0);
		obj.SetBlend(1);
		glColor4f( 1, 1, 1, 0.9 );
		obj.Render();
		g_bFade = 1;
		g_coDelatPoFade = 1;
	}
	RenderEfektUdalosti();


	// Blending polygons //

	// Pocasi //
	if( g_aktKolo < 9 )
	{
		g_pocasi.Render();
		// Dest //
		g_dest.Render( g_destKolik );
	}
	if(!g_pausa) g_dest.Move( g_fps.GetFPS() );
	
	
	DrawVoda();

		g_partKruh.Draw();
	Bonus.Draw();

	g_hracScena.Render();
	g_protScena.Render();

	prot_zed.Render();
	hrac_zed.Render();

	if(!g_pausa) g_partKruh.Move( g_fps.GetFPS() );	

	// olej //
	g_vyzkum.DrawOlej();
	if( g_vyzkumProt.olej ) DrawOlejProt();

	RenderVybuchHrad( g_fps.GetFPS() );

	if(!g_pausa) g_duch.Move();
	g_duch.Draw();

	g_hracScena.RenderOblak();
	g_protScena.RenderOblak();

	// Vybuchy 
	// vybuch koule o hrad
	g_scenKou.Render( );

	g_fire.Render();
	DrawEfektSuroviny();
	if(!g_pausa) g_fire.Move( g_fps.GetFPS() );

	g_scenaVlna.Render();
	
	// Time pro 5 kolo
	if( g_aktKolo == 4 )
	{
		glPushMatrix();
		glTranslatef(-0.9,0,1);
		glEnable( GL_BLEND );
		glBlendFunc( GL_ONE, GL_ONE );
		if( (g_cas5kolo%60) < 10 ) g_3dFont.print3dText( (char*)W_GetString("%d:0%d", g_cas5kolo/60, g_cas5kolo%60 ).c_str() );
		else g_3dFont.print3dText( (char*)W_GetString("%d:%d", g_cas5kolo/60, g_cas5kolo%60 ).c_str() );
		glDisable( GL_BLEND );
		glPopMatrix();
	}
}

void DrawVyzkum()
{
	menu_vyz.Render();
	glColor3f(1,1,1);
	g_font.Print( (float)W_PrevedIntXNaScreen(177, SCRWidth), (float)W_PrevedIntYNaScreen(311, SCRHeight), g_textVyzkum.c_str() );
	g_font.Print( W_PrevedIntXNaScreen(20, SCRWidth), W_PrevedIntYNaScreen(300, SCRHeight), "Výzkumných bodů : %d", g_hrac.vedBody );
	menu_vyz.MouseMove(g_hWnd);
}

void DrawCredits()
{
	C_2DOBJECT_0 obj( TM.GetIdTexture( g_textures[29] ), SCRWidth/3, 0, SCRWidth/3, SCRHeight );
	obj.Render();

	// efekty - muhehe :D
	static bool create=0;
	static CParticleEmitor em1, em2;
	if( !create )
	{
		// emitor 1
		em1.SetTexture( TM.GetIdTexture( g_textures[28]) );
		TRGBf color[2] = {1,1,0, 1,1,0};
		em1.SetColor( color[0], color[1] );
		em1.SetStartVel(0.4f);
		em1.SetAtribut( CVector3(-1.8,-1.4,-5), 0, 30, 0.02f, 1.2f);
		em1.Create(120);
		// emitor 2
		em2.SetTexture( TM.GetIdTexture( g_textures[28]) );
		em2.SetColor( color[0], color[1] );
		em2.SetStartVel(0.4f);
		em2.SetAtribut( CVector3(1.6,-1.4,-5), 0, 30, 0.02f, 1.2f);
		em2.Create(120);
		create = 1;
	}
	em1.Render( g_rotate.x, g_rotate.y );
	em1.Update( g_fps.GetFPS() );
	em2.Render( g_rotate.x, g_rotate.y );
	em2.Update( g_fps.GetFPS() );
}

void DrawIntro()
{
	static bool dod_FGLogo=0;
	TRect rect = {120, 180, 400, 120};
	rect = W_PrevedRectNaScreen(rect, SCRWidth, SCRHeight);
	static C_2DOBJECT_0 obj( TM.GetIdTexture( g_textures[11] ), rect );
	static float alpha=0.0f;
	static float ink=0.012f;
	alpha += (ink*60.0f)/g_fps.GetFPS();
	if(alpha > 1.0f) ink = -ink;
	if(alpha < 0.0f)
	{
		static bool uz_probehlo=0;
		if( uz_probehlo ) g_game = game_video;
		ink = -ink;
		obj.SetTextureId( TM.GetIdTexture( g_textures[48]) );
		if( dod_FGLogo == 1 ) obj.SetTextureId( TM.GetIdTexture( g_textures[12] ) );
		if(dod_FGLogo==1) uz_probehlo = 1;
		dod_FGLogo=1;
	}
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glColor4f(1, 1, 1, alpha);
	obj.SetAplha(0);
	obj.Render();
	glDisable(GL_BLEND);
}

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// Scena - ovladani jednotek
//
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

C_SCENAJED_0::C_SCENAJED_0(int i)
{
	_kdo = i;
}

void C_SCENAJED_0::Add(TJednotka j)
{
	_hracJed.push_back(j);
}

bool C_SCENAJED_0::ColiZed( float zed, int kdo_zed, bool ret)
{
	std::vector<TJednotka>::iterator iter = _hracJed.begin();
	for(; iter != _hracJed.end(); iter++)
	{
		if(!iter->show) continue;
		float lenght = 1.5f;
		// kdo znaci kohoje to zed
		if( kdo_zed==0 && iter->pos.x+iter->w > zed-lenght && iter->pos.x < zed+lenght) return TRUE;
		if( kdo_zed==1 && iter->pos.x < zed+lenght && iter->pos.x+iter->w > zed-lenght) return TRUE;
	}
	return ret;
}

void C_SCENAJED_0::Add(int i)
{
	bool bCreate=1;
	TJednotka j;
	j.smrt = 0;
	j.anim_speed = 0.3f; // cim min tim rychlejc
	j.pocY1 = j.pocY2 = j.pocY3 = 2;
	if(_kdo == 0) j.pos = CVector3(zacPosJednotka0, 0, -1.5);
	if(_kdo == 1) j.pos = CVector3(zacPosJednotka1, 0, -1.5);
	if(_kdo == 0) j.px = 0.05f;
	if(_kdo == 1) j.px = -0.05f;
	j.akce = 0;
	j.show = 1;
	j.fBlend = 0.8f;
	j.akt_speed = 0;
	j.akt_frame = 0;
	j.speed = 10;
	j.plus_speed = 0;
	j.fTime = 0.0f;
	j.oldTim = 0;
	j.aktTim = 0;
	j.kata_zac = 0;
	j.odecitat = 1;
	j.kdo = 0;
	if(_kdo==0) g_hracStat.poc_jednotek++;
	j.jaka_jed = i;
	int plus_brneni=0;
	if( g_vyzkum.brneni ) plus_brneni=200;
	if(i == 1)
	{
		// CLOVEK 1 - vojak
		j.typ = 1;
		j.texId1 = TM.GetIdTexture(g_JedTextures[0]);
		j.texId2 = TM.GetIdTexture(g_JedTextures[1]);
		j.texId3 = TM.GetIdTexture(g_JedTextures[2]);
		j.pocX1 = 9;
		j.pocX2 = 9;
		j.pocX3 = 13;
		j.Set1();
		j.h = 0.9;
		j.w = 0.9;

		j.sila = 17 + (g_hrac.kovarny*5);
		j.live = 700 + plus_brneni + (g_hrac.kovarny*100);
		j.max_live = 700+ plus_brneni + (g_hrac.kovarny*100);
		j.plus_y = 0;
		j.speed = 20;
		g_hrac.pocLeh++;
	}else if(i == 2)
	{
		// ZLO 1 - KOSTLIVEC
		j.typ = 1;
		j.texId1 = TM.GetIdTexture(g_JedTextures[6]);
		j.texId2 = TM.GetIdTexture(g_JedTextures[7]);
		j.texId3 = TM.GetIdTexture(g_JedTextures[8]);
		j.pocX1 = 9;
		j.pocX2 = 9;
		j.pocX3 = 10;
		j.pocY1 = j.pocY2 = j.pocY3 = 2;
		j.Set1();
		j.h = 0.9;
		j.w = 0.9;

		j.sila = 12 + (g_prot.kovarny*4);
		j.live = 900 + (g_prot.kovarny*140);
		j.max_live = 900 + (g_prot.kovarny*140);
		j.plus_y = 1;
		j.speed = 15;
		g_prot.pocLeh++;
		j.kdo = 1;
	}else if(i == 3)
	{
		// CLOVEK - Tezka jednotka
		j.typ = 1;
		j.texId1 = TM.GetIdTexture(g_JedTextures[3]);
		j.texId2 = TM.GetIdTexture(g_JedTextures[4]);
		j.texId3 = TM.GetIdTexture(g_JedTextures[5]);
		j.pocX1 = 8;
		j.pocX2 = 9;
		j.pocX3 = 13;
		j.Set1();
		j.h = 1.2;
		j.w = 1.2;

		j.sila = 20 + (g_hrac.zbrojnice*5);
		j.live = 900+ plus_brneni+(g_hrac.zbrojnice*140);
		j.max_live = 900+plus_brneni+ (g_hrac.zbrojnice*140);
		j.plus_y = 0;
		g_hrac.pocTez++;
	}else if(i == 4)
	{
		// ZLO 4 - TEZKA JEDNOTKA
		j.typ = 1;
		j.texId1 = TM.GetIdTexture(g_JedTextures[9]);
		j.texId2 = TM.GetIdTexture(g_JedTextures[10]);
		j.texId3 = TM.GetIdTexture(g_JedTextures[11]);
		j.pocX1 = 8;
		j.pocX2 = 9;
		j.pocX3 = 13;
		j.pocY1 = j.pocY2 = j.pocY3 = 2;
		j.Set1();
		j.h = 1.2;
		j.w = 1.2;

		j.sila = 12 + (g_prot.zbrojnice*4);
		j.live = 1600+  (g_prot.zbrojnice*230);
		j.max_live = 1600+  (g_prot.zbrojnice*230);
		j.plus_y = 1;
		j.speed = 15;
		g_prot.pocTez++;
		j.kdo = 1;
	}else if(i == 5)
	{
		// CLOVEK 5 - STRELEC
		j.typ = JED_TYP_STR;
		j.texId1 = TM.GetIdTexture( g_JedTextures[15] );
		j.texId2 = TM.GetIdTexture( g_JedTextures[16] );
		j.texId3 = TM.GetIdTexture( g_JedTextures[17] );
		j.pocX1 = 8;
		j.pocX2 = 13;
		j.pocX3 = 13;
		j.Set1();
		j.h = 1.0;
		j.w = 1.0;

		j.sila = 35 + (g_hrac.strelnice*25);
		j.live = 200+plus_brneni+(g_hrac.strelnice*50);
		j.max_live = 200+plus_brneni+(g_hrac.strelnice*50);
		j.speed = 15;

		j.plus_y = 0;
		g_hrac.pocStr++;
	}else if(i == 6)
	{
		// ZLO 6 - STRELEC
		j.typ = JED_TYP_STR;
		j.texId1 = TM.GetIdTexture( g_JedTextures[15] );
		j.texId2 = TM.GetIdTexture( g_JedTextures[16] );
		j.texId3 = TM.GetIdTexture( g_JedTextures[17] );
		j.pocX1 = 8;
		j.pocX2 = 13;
		j.pocX3 = 13;
		j.pocY1 = j.pocY2 = j.pocY3 = 2;
		j.Set1();
		j.h = 1.0;
		j.w = 1.0;

		j.sila = 45 + (g_prot.strelnice*30);
		j.live = 200 + (g_prot.strelnice*50);
		j.max_live = 200+ (g_prot.strelnice*50);
		j.plus_y = 1;
		j.speed = 15;
		g_prot.pocStr++;
		j.kdo = 1;
	}else if(i == 7) //
	{
		// DOBRO 7 - MAG
		j.typ = JED_TYP_MAG;
		j.texId1 = TM.GetIdTexture( g_JedTextures[21] );
		j.texId2 = TM.GetIdTexture( g_JedTextures[22] );
		j.texId3 = TM.GetIdTexture( g_JedTextures[23] );
		j.pocX1 = 8;
		j.pocX2 = 13;
		j.pocX3 = 13;
		j.pocY1 = j.pocY2 = j.pocY3 = 2;
		j.Set1();
		j.h = 1.0;
		j.w = 1.0;

		j.sila = 20;
		j.live = 150+plus_brneni+(g_hrac.chram*50);
		j.max_live = 150+plus_brneni+(g_hrac.chram*50);
		j.plus_y = 0;
		j.speed = 15;
		g_hrac.pocMag++;
		j.kdo = 0;
	}else if(i == 8)
	{
		// ZLO 8 - MAG
		j.typ = JED_TYP_MAG;
		j.texId1 = TM.GetIdTexture( g_JedTextures[24] );
		j.texId2 = TM.GetIdTexture( g_JedTextures[25] );
		j.texId3 = TM.GetIdTexture( g_JedTextures[26] );
		j.pocX1 = 8;
		j.pocX2 = 13;
		j.pocX3 = 13;
		j.pocY1 = j.pocY2 = j.pocY3 = 2;
		j.Set1();
		j.h = 1.0;
		j.w = 1.0;

		j.sila = 20;
		j.live = 150+ plus_brneni+(g_prot.chram*50);
		j.max_live = 150+ plus_brneni+(g_prot.chram*50);;
		j.plus_y = 1;
		j.speed = 15;
		g_prot.pocMag++;
		j.kdo = 1;
	}else if(i == 10)
	{
		// DOBRY - KATAPULT
		j.typ = JED_TYP_KAT;
		j.texId1 = TM.GetIdTexture( g_JedTextures[12] );
		j.texId2 = TM.GetIdTexture( g_JedTextures[13] );
		j.texId3 = TM.GetIdTexture( g_JedTextures[14] );
		j.pocX1 = 8;
		j.pocX2 = 8;
		j.pocX3 = 8;
		
		j.Set1();
		j.h = 1.0;
		j.w = 1.0;

		j.pocY1 = j.pocY2 = j.pocY3 = 1;
		j.sila = 20 + g_hrac.dilny1*5;
		j.live = 200+(g_hrac.dilny1*100);
		j.max_live = 200+(g_hrac.dilny1*100);
		j.plus_y = 0;
		g_hrac.pocKat++;
	}else if(i == 11)
	{
		// ZLY - KATAPULT
		j.typ = JED_TYP_KAT;
		j.texId1 = TM.GetIdTexture( g_JedTextures[18] );
		j.texId2 = TM.GetIdTexture( g_JedTextures[19] );
		j.texId3 = TM.GetIdTexture( g_JedTextures[20] );
		j.pocX1 = 8;
		j.pocX2 = 8;
		j.pocX3 = 8;
		
		j.Set1();
		j.h = 1.0;
		j.w = 1.0;

		j.pocY1 = j.pocY2 = j.pocY3 = 1;
		j.sila = 20+g_hrac.dilny1*5;
		j.live = 100+g_prot.dilny1*100;
		j.max_live = 100+g_prot.dilny1*100;
		j.plus_y = 1;
		g_prot.pocKat++;
		j.kdo = 1;
	}else if(i == 20)
	{
		// DOBRO TROL - specialni jednotka
		j.typ = 1;
		j.texId1 = TM.GetIdTexture( g_specTextures[3] );
		j.texId2 = TM.GetIdTexture( g_specTextures[4] );
		j.texId3 = TM.GetIdTexture( g_specTextures[5] );
		j.pocX1 = 8;
		j.pocX2 = 8;
		j.pocX3 = 8;
		
		j.Set1();
		j.h = 1.4;
		j.w = 1.4;

		j.pocY1 = j.pocY2 = j.pocY3 = 1;
		j.sila = 350;
		j.live = 7000;
		j.max_live = 7000;
		j.plus_y = 0;
		j.kdo = 0;
		g_hrac.pocSpecJed++;
	}else if(i == 21)
	{
		// ZLY - DABEL - specialni jednotka
		j.typ = 1;
		j.texId1 = TM.GetIdTexture( g_specTextures[0] );
		j.texId2 = TM.GetIdTexture( g_specTextures[1] );
		j.texId3 = TM.GetIdTexture( g_specTextures[2] );
		j.pocX1 = 8;
		j.pocX2 = 8;
		j.pocX3 = 8;
		
		j.Set1();
		j.h = 1.4;
		j.w = 1.4;

		j.pocY1 = j.pocY2 = j.pocY3 = 1;
		j.sila = 260;
		j.live = 6000;
		j.max_live = 6000;
		j.plus_y = 0;
		j.kdo = 1;
		g_prot.pocSpecJed++;
	}else bCreate=0;
	
	if(bCreate) _hracJed.push_back(j);
}

void C_SCENAJED_0::Render()
{
	std::vector<TJednotka>::iterator iter = _hracJed.begin();
	for(; iter != _hracJed.end(); iter++)
	{
		if(!iter->show) continue;
		CVector3 v = iter->pos;
		if(v.x > 10) continue;
		float w = iter->w;
		float h = iter->h;
		TVector3 vec[4] = {v.x,v.y+h,v.z, v.x+w,v.y+h,v.z, v.x+w,v.y,v.z, v.x,v.y,v.z};
		//Draw3dFade(iter->id_texture, vec);
		bool oblak=0;
		if(_kdo == 0 && g_hrac.speedPlus == -1) oblak = 1;
		if(_kdo == 1 && g_prot.speedPlus == -1) oblak = 1;
		if(iter->smrt == 2) RenderJednotka(*iter, 0, iter->fBlend, 1);
		else RenderJednotka(*iter, 0, 1.0f, 0);

		if( g_kouzloBoziOchrana && _kdo==0 )
		{
			C_3DOBJECT_0 obj(TM.GetIdTexture( g_textures[44] ), iter->pos.x, iter->pos.y+iter->h, iter->pos.z, iter->w,
				iter->h, 0);
			obj.SetColorf( 0,0, 0.6f ); // alfa :|
			obj.SetBlend( 1.0f );
			obj.Render();
		}	
	}
}

void C_SCENAJED_0::RenderOblak()
{
	std::vector<TJednotka>::iterator iter = _hracJed.begin();
	for(; iter != _hracJed.end(); iter++)
	{
		if(!iter->show) continue;
		CVector3 v = iter->pos;
		if(v.x > 10) continue;
		float w = iter->w;
		float h = iter->h;
		TVector3 vec[4] = {v.x,v.y+h,v.z, v.x+w,v.y+h,v.z, v.x+w,v.y,v.z, v.x,v.y,v.z};
		//Draw3dFade(iter->id_texture, vec);
		bool oblak=0;
		if(_kdo == 0 && g_hrac.speedPlus == -1) oblak = 1;
		if(_kdo == 1 && g_prot.speedPlus == -1) oblak = 1;
		if(iter->smrt != 2 && oblak == 1) RenderJednotkaOblak(*iter, oblak);

	}
}

//////////////////////////////////////////////////////////////////////////
// Move -
//////////////////////////////////////////////////////////////////////////
void C_SCENAJED_0::Move(THrac &prot, float time)
{
	std::vector<TJednotka>::iterator iter = _hracJed.begin();
	for(; iter != _hracJed.end(); iter++)
	{
		if(!iter->show) continue;
		CVector3 *v = &iter->pos;
		if(iter->akce != BOJ_JED && iter->akce != BOJ_HRAD && iter->smrt == 0) 
		{
			// Vlastni pohyb jednotek
		
			float bonus = 0;
			float nasobicka = 1;
			float itrSpeed = iter->speed;
			if( iter->speed < 0 ) {nasobicka = -1;itrSpeed=-itrSpeed;}
			if( iter->kdo == 0 ) bonus = g_hrac.pocMag * 3;
			if( iter->kdo == 1 ) bonus = g_prot.pocMag * 3;
			if( prot.speedPlus == 0 )   v->x += (iter->px *nasobicka* (itrSpeed+iter->plus_speed+bonus))/time;
			if( prot.speedPlus == -1 )  v->x += (iter->px *nasobicka* ((itrSpeed+iter->plus_speed+bonus) - (itrSpeed+iter->plus_speed+bonus)/2))/time;
		}

		if(iter->akt_speed >= iter->anim_speed)
		{
			iter->akt_frame++;
			if(iter->akt_frame > iter->poc_x-1 && iter->smrt == 1) {iter->smrt = 2;iter->akt_frame = iter->poc_x-1;}
			if(iter->akt_frame > iter->poc_x-1) iter->akt_frame = 0;
			iter->akt_speed = 0;
		}
		if(iter->smrt != 2)	iter->akt_speed+= (0.1f*60)/g_fps.GetFPS();
		if(iter->smrt == 2) 
		{
			iter->fBlend -= (0.01f*60)/g_fps.GetFPS(); // *time
			// Smrt // dodelat
			if(_kdo == 0 && iter->odecitat)
			{
				if( iter->jaka_jed == 1 ) g_hrac.pocLeh--;
				if( iter->jaka_jed == 3 ) g_hrac.pocTez --;
				if( iter->jaka_jed == 5 ) g_hrac.pocStr--;
				if( iter->jaka_jed == 7 ) g_hrac.pocMag--;
				if( iter->jaka_jed == 10 ) g_hrac.pocKat--; 
				iter->odecitat=0;
				// create duch
				TVel iterVel = { iter->w, iter->h };
				g_duch.Add( iter->pos, iterVel );
			}
			if(_kdo == 1 && iter->odecitat)
			{
				if( iter->jaka_jed == 2 ) g_prot.pocLeh--;
				if( iter->jaka_jed == 4 ) g_prot.pocTez --;
				if( iter->jaka_jed == 6 ) g_prot.pocStr--;
				if( iter->jaka_jed == 8 ) g_prot.pocMag--;
				if( iter->jaka_jed == 11 ) g_prot.pocKat--;


				g_hracStat.poc_zabJednotek++;
				iter->odecitat=0;
				// create duch
				TVel iterVel = { iter->w, iter->h };
				g_duch.Add( iter->pos, iterVel );
			}
		}
		if( (iter->smrt == 2) && (iter->fBlend <= 0.0f) ) iter->show = 0;

		if( iter->typ > JED_TYP_JED ) // strelec, mag, katapult
		{
			if( (iter->typ == JED_TYP_STR || iter->typ == JED_TYP_KAT) && g_zapomnetlivostProt && iter->kdo == 1 )
			{
				iter->akce = BOJ_UTEK;
			}
			//if( iter->typ > JED_TYP_JED && iter->smrt == 1 ) iter->Set2(); 
			if( _kdo==0 && iter->pos.x < -6.0f && iter->speed < 0 )
			{
				iter->pos.x = -6.0f;
				iter->speed = -iter->speed;
				iter->plus_speed = 0;
			}else
			if( _kdo == 1 && iter->pos.x > 6.0f && iter->speed < 0)
			{
				iter->pos.x = 6.0f;
				iter->speed = -iter->speed;
				iter->plus_speed = 0;
			}

			// zastaveni o zed
			if( _kdo == 0 && iter->pos.x+iter->w > dalkaZed_x && g_hrac.vyska_zed > 0 )
			{
				iter->pos.x = dalkaZed_x-iter->w;
				iter->speed = -iter->speed;
			}
			if( _kdo == 1 && iter->pos.x < -dalkaZed_x+sirkaZed && g_prot.vyska_zed > 0 )
			{
				iter->pos.x = -dalkaZed_x+sirkaZed;
				iter->speed = -iter->speed;
			}

			if( _kdo==0 && iter->pos.x+iter->w/2 > 0 && iter->speed > 0) iter->speed = -iter->speed;
			else
			if( _kdo==1 && iter->pos.x < 0 && iter->speed > 0) iter->speed = -iter->speed;
			CVector3 sipPos = iter->pos;
			if(_kdo==0)
			{
				sipPos.y += iter->h/2;
				sipPos.x += iter->w;
			}else
			if(_kdo == 1)
			{
				sipPos.y += iter->h/2;
				sipPos.x -= 0.8f;
			}
			if( iter->typ == JED_TYP_STR && iter->akce==BOJ_STRELEC && iter->akt_frame == 8 )
			{ 
				if(iter->kdo == 0) g_scenSip.Add( TM.GetIdTexture( g_textures[19] ), CVector3( sipPos ), _kdo, iter->sila+g_hrac.strelnice*plusSilaD3 ); 
				if(iter->kdo == 1 && !g_zapomnetlivostProt) g_scenSip.Add( TM.GetIdTexture( g_textures[19] ), CVector3( sipPos ), _kdo, iter->sila+g_prot.strelnice*plusSilaZ3 ); 
				char nah = (rand()%2);
				if( nah==0 ) g_zvuk.Play( g_idZvuk[7] );
				if( nah==1 ) g_zvuk.Play( g_idZvuk[9] );
				iter->akt_frame++;
			}
			
			iter->oldTim = timeGetTime();
			float roz = 0.0f;
			if(iter->aktTim != 0) roz = float(float(iter->oldTim-iter->aktTim)/1000.0f);
			CVector3 kouPos = iter->pos;
			if( _kdo == 0 )
			{
				kouPos.y += iter->h-0.3;
				kouPos.x += 0.3f;
			}else
			if( _kdo == 1 )
			{
				kouPos.y += iter->h-0.3;
				kouPos.x += 0.3f;
			}
			if( iter->typ == JED_TYP_KAT && iter->fTime > 3.5f )
			{
				// Utokiter->fTime = 0;
				iter->akce = BOJ_KAT;				
				//iter->Set3();
				//iter->fTime = 0.0f;
				if(iter->kata_zac==0) {iter->akt_frame=0;iter->kata_zac=1;}
				iter->Set3();
				if( iter->akt_frame == 4 && iter->akce == BOJ_KAT ) 
				{
					if( iter->kdo == 0 ) g_scenKou.Add( TM.GetIdTexture( g_textures[14] ) , kouPos, _kdo);
					if( iter->kdo == 1 && !g_zapomnetlivostProt ) g_scenKou.Add( TM.GetIdTexture( g_textures[14] ) , kouPos, _kdo);
					iter->akt_frame++;
					g_zvuk.Play( g_idZvuk[5] );
				}

				if( iter->akt_frame == iter->poc_x-1 && iter->akce == BOJ_KAT)
				{
					iter->akce = BOJ_UTEK;
					iter->fTime = 0;
					iter->Set1();
					iter->kata_zac=0;
				}
			}
			if(iter->typ == JED_TYP_KAT) 
			{
				iter->fTime += roz;
			}
			iter->aktTim = timeGetTime();
		}
		if(iter->live <= 0)
		{
			// smrt
			//iter->jednotka->Set2();
			if(iter->smrt == 0) { iter->smrt = 1;iter->Set2(); }
			if(iter->smrt == 1 && iter->typ > JED_TYP_JED )
			{
				
				iter->poc_x = iter->pocX2;
				iter->poc_y = iter->pocY2;
				iter->id_texture = iter->texId2;
			}
		}
	}
}

//////////////////////////////////////////////////////////////////////////
// Coli - 
//////////////////////////////////////////////////////////////////////////
void C_SCENAJED_0::Coli(float zed_prot, THrac &p, C_SCENAJED_0 &jed_prot)
{
	bool zed = 1;
	if(p.vyska_zed <= 0) 
	{
		p.vyska_zed = 0;
		zed = 0;
	}
	std::vector<TJednotka>::iterator iter = _hracJed.begin();
	for(; iter != _hracJed.end(); iter++)
	{
		if(!iter->show) continue;
		if(iter->smrt > 0) continue;
		if( iter->typ == JED_TYP_STR && p.vyska_zed > 0.5f && iter->smrt == 0) iter->akce = BOJ_STRELEC;
		
		if(_kdo == 0) // hrac
		{
			CVector3 *v = &iter->pos;
			if(zed)
			{	// colise zed prot
				if(v->x+iter->w > zed_prot && v->x < zed_prot+0.3f) 
				{
					v->x = zed_prot-iter->w;
					//p.vyska_zed -= 0.01;
					iter->akce = BOJ_HRADBY; 
				}
			}
		
			// Colise Hrad prot // 
			if(v->x+iter->w > pos_hrad_x) 
			{
				//v->x = pos_hrad_x-iter->w;
				iter->akce = BOJ_HRAD;
			}			
		}else
		if(_kdo == 1) // protivnik
		{
			CVector3 *v = &iter->pos;
			if(zed)
			{
				// Colise zed
				if(v->x < zed_prot+0.3 && v->x+iter->w/2 > zed_prot+0.3) 
				{
					v->x = zed_prot+0.3f;
					iter->akce = BOJ_HRADBY; 
				}
			}
			// Colise Hrad prot // 
			if(v->x < -pos_hrad_x) 
			{
				//v->x = -pos_hrad_x;
				iter->akce = BOJ_HRAD;
			}
		}

		// Colise hrac , protivnik
		std::vector<TJednotka> *j = &jed_prot._hracJed;
		std::vector<TJednotka>::iterator iter_prot = j->begin();
		for(;iter_prot != j->end(); iter_prot++)
		{
			if(!iter_prot->show) continue;
			if(iter_prot->smrt > 0) continue;
			CVector3 a = iter->pos;
			float a_w = iter->w;
			CVector3 b = iter_prot->pos;
			float b_w = iter_prot->w;
			// zmenseni velikosti, kvuly efektu
			a_w = a_w/2;
			b_w = b_w/2;

			/*if( iter->kdo == 0 ) { 
				textREC.Add("1a ", a.x+a_w);
				textREC.Add("1b ", b.x);
			}
			if( iter->kdo == 1 ) { 
				textREC.Add("2a ", a.x);
				textREC.Add("2b ", b.x+b_w);
			}*/

			if((a.x+a_w >= b.x && a.x+a_w <= b.x+b_w) || (b.x+b_w >= a.x && b.x+b_w <= a.x+a_w)) 
			{ 
				if( iter->typ != JED_TYP_KAT ) {iter->akce = BOJ_JED;}
				if( iter->typ > JED_TYP_JED )
				{
					iter->plus_speed = abs( iter->speed );
					//*** oprava
					iter->live -= iter_prot->sila/2;
					iter->akce = BOJ_UTEK;
				}
				// otoceni chozeni
				if( iter->typ > JED_TYP_JED && iter->speed > 0) iter->speed = -iter->speed; 
				if( iter->typ == JED_TYP_KAT && iter->speed > 0) iter->speed = -1; 
				iter->jednotka = iter_prot;
				break;
			}
			if( iter->typ == JED_TYP_STR && CelkemJednotek( p ) > 0 && iter->smrt == 0) iter->akce = BOJ_STRELEC;
		}
	}
	
}

//////////////////////////////////////////////////////////////////////////
// Refresh - 
//////////////////////////////////////////////////////////////////////////
void C_SCENAJED_0::Refresh(THrac &prot, int i)
{
	bool blend_hradby = 0;
	std::vector<TJednotka>::iterator iter = _hracJed.begin();
	for(; iter != _hracJed.end(); iter++)
	{
		if(!iter->show) continue;
		if(iter->smrt == 0) iter->Set1();

		// uzdraveni kostelem
		if( g_vyzkum.kostel &&  prot.kdo == 1 && iter->pos.x < 0.0f && iter->live < iter->max_live) iter->live += 1;
		
		// Uzdraveni jednotek
		if( iter->smrt == 0 && iter->live < iter->max_live)
		{
			if( iter->kdo == 0 ) iter->live += g_hrac.pocMag * 9;
			if( iter->kdo == 1 ) iter->live += g_prot.pocMag * 9;
		}

		if(iter->akce == BOJ_HRADBY)
		{
			if(iter->smrt == 0) iter->Set3();
			if(iter->smrt >= 1) continue;
			prot.vyska_zed -= 0.01f;
			blend_hradby = 1;

			// ZVUK - UTOK
			if( iter->akt_frame == iter->pocX3-4 || iter->akt_frame == iter->pocX3-3 || iter->akt_frame == iter->pocX3-2 )
			{
				if( iter->typ == 6 || iter->typ == 5 || iter->typ == 10 || iter->typ == 11 )
				{

				}else
				{
					int nah = (rand()%2);
					if( nah==0 ) g_zvuk.Play( g_idZvuk[0] );
					if( nah==1 ) g_zvuk.Play( g_idZvuk[1] );
				}
			}
		}else
		if(iter->akce == BOJ_HRAD)
		{
			iter->Set3();
			if( g_vyzkum.obrana && prot.kdo==1 ) prot.Hrad -= iter->sila/2;
			else prot.Hrad -= iter->sila;

			// ZVUK - UTOK
			if( iter->akt_frame == iter->pocX3-4 || iter->akt_frame == iter->pocX3-3 || iter->akt_frame == iter->pocX3-2 )
			{
				if( iter->typ == 6 || iter->typ == 5 || iter->typ == 10 || iter->typ == 11 )
				{

				}else
				{
					int nah = (rand()%2);
					if( nah==0 ) g_zvuk.Play( g_idZvuk[0] );
					if( nah==1 ) g_zvuk.Play( g_idZvuk[1] );
				}
			}
		}else
		if(iter->akce == BOJ_JED)
		{
			if( g_kouzloBoziOchrana == 1 && iter->jednotka->kdo == 0 ) continue;
			if(iter->smrt == 0) iter->Set3();
			if(iter->smrt >= 1) continue;
			// uber protivnikovz
			if(g_silaPlus == 1 && iter->kdo == 0) iter->jednotka->live -=(iter->sila*3);
			else iter->jednotka->live -=iter->sila;
			
			// ZVUK - UTOK
			if( iter->akt_frame == iter->pocX3-4 || iter->akt_frame == iter->pocX3-3 || iter->akt_frame == iter->pocX3-2 )
			{
				if( iter->typ == 6 || iter->typ == 5 || iter->typ == 10 || iter->typ == 11 )
				{

				}else
				{
					int nah = (rand()%2);
					if( nah==0 ) g_zvuk.Play( g_idZvuk[0] );
					if( nah==1 ) g_zvuk.Play( g_idZvuk[1] );
				}
			}
			
			if(iter->jednotka->live <= 0)
			{
				// smrt
				//iter->jednotka->Set2();
				if(iter->jednotka->smrt == 0) {iter->jednotka->smrt = 1;iter->jednotka->Set2();}
				// jednotka smrt zvuk
				if( iter->typ == 10 || iter->typ == 11 )
				{
					g_zvuk.Play( g_idZvuk[6] );
				}else
				{
					int nah = (rand()%3);
					if( nah == 0 ) g_zvuk.Play( g_idZvuk[2] );
					if( nah == 1 ) g_zvuk.Play( g_idZvuk[3] );
					if( nah == 2 ) g_zvuk.Play( g_idZvuk[4] );
				}
			}
		}else
		if( iter->akce == BOJ_UTEK )
		{
			iter->Set1();
		}else
		if( iter->akce == BOJ_STRELEC )
		{
			iter->Set3();
		}else
		if( iter->akce == BOJ_KAT )
		{
			iter->Set3();
		}
		iter->akce = 0;
		// olej //
		if( g_vyzkum.olej && iter->pos.x < -pos_hrad_x+0.8f && iter->kdo == 1 ) iter->live -= 10;  
		if( g_vyzkumProt.olej && iter->pos.x > pos_hrad_x-1.4f && iter->kdo == 0 && !g_kouzloBoziOchrana ) iter->live -= 10;
		
	}	
}

void C_SCENAJED_0::DeleteAll()
{
	_hracJed.clear();
}


//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
//
//
//
//
//                          EFEKTY
//
//
//
//
//
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

C_DEST_0::C_DEST_0(int iKolik, float fOd, float fDo)
{
	_iKolik = iKolik;
	_od = fOd;
	_do = fDo;
}

void C_DEST_0::Init()
{
	for(register i=0; i<_iKolik; i++)
	{
		TKapka temp;
		_NewKapka(temp);
		_vKapky.push_back(temp);
	}
}

void C_DEST_0::Render( int max_ren )
{
	bool bFog = (bool)glIsEnabled(GL_FOG);
	if(bFog) glDisable(GL_FOG);
	std::vector<TKapka>::iterator i = _vKapky.begin();
	int citac=1;
	glPushMatrix();
	glTranslatef( 0, 0, -2 );
	glRotatef(12, 0, 0, 1);
	for(; i != _vKapky.end(); i++)
	{
		if( citac > max_ren ) break;
		citac++;
		C_3DOBJECT_0 obj(i->texture_id,i->pos.x,i->pos.y,i->pos.z,0.16,i->delka+0.3,0.02);
		
		obj.SetColorf(0, 0, 0.3f+((float(rand()%20))/100.0f) );
		obj.SetBlend(1);
		obj.Render();

	}
	glPopMatrix();
	if(bFog) glEnable(GL_FOG);
}

void C_DEST_0::Move( float time )
{
	std::vector<TKapka>::iterator i = _vKapky.begin();
	for(; i != _vKapky.end(); i++)
	{
		i->pos.y -= (i->pz*60)/time;
		if(i->pos.y+i->delka < _do) _NewKapka(*i);
	}
}

void C_DEST_0::_NewKapka(TKapka &k)
{
	//k.pos.x = (rand()%1000)/100 - 500/200;
	k.pos.x = SpecRand(-19000)/1000.0f + 12000.0f/1000.0f;
	k.pos.y = _od+2.0f;
	k.pos.z = SpecRand(-18000)/1000.0f - 2.0f;
	float plusDelka = float(rand()%6)/10.0f;
	k.delka = 0.25+plusDelka;
	k.texture_id = 0;
	k.pz = SpecRand(10)/100.0f + 0.15;
	k.texture_id = TM.GetIdTexture(g_textures[9]);
}

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
void C_STARS_0::Init(TRect r, uint tex_id, int kolik /* = 0 */)
{
	_rect = r;
	_texId = tex_id;
	
	for(register i=0; i<kolik; i++)
	{
		TStar temp;
		_NewStar(temp);
		_vStar.push_back(temp);
	}
}

void C_STARS_0::Render()
{
	std::vector<TStar>::iterator i=_vStar.begin();
	for(; i<_vStar.end(); i++)
	{
		C_2DOBJECT_0 obj;
		obj.SetTextureId(_texId);
		obj.SetPos(i->pos.x, i->pos.y, 20, 20);
		
		obj.SetColorf(i->blend, i->blend, i->blend);
		glColor3f(i->blend, i->blend, i->blend);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
		obj.Render();
		glDisable(GL_BLEND);
	}
}

void C_STARS_0::_NewStar(TStar &s)
{
	s.blend = 0.0f;
	s.pos.x = (rand() % (int)_rect.width) + _rect.x;
	s.pos.y = (rand() % (int)_rect.height) + _rect.y;
	s.bx	= (rand() % 100) / 10000.0f;
}

void C_STARS_0::Move(float time)
{
	std::vector<TStar>::iterator i=_vStar.begin();
	for(; i != _vStar.end(); i++)
	{
		i->blend += i->bx;
		if(i->blend > 1.0f) _NewStar(*i);
	}
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

C_INFO_0::C_INFO_0()
{
}

void C_INFO_0::Init()
{
	_vel.width = menu_hra.PrevedIntXNaScreen(240);
	_vel.height = menu_hra.PrevedIntXNaScreen(100);
	_vel.x = SCRWidth/2 - _vel.width/2;
	_vel.y = menu_hra.PrevedIntYNaScreen(20);
}

void C_INFO_0::Render(float time)
{
	std::vector<TInfoData>::iterator i = _vData.begin();
	for(; i != _vData.end(); i++)
	{
		if(i->bShow)
		{
			float posun = (4.0f*60.0f)/time;
			if(i->iStav == 0)
			{
				// zobraz info
				if( !i->zvuk )
				{
					g_zvuk.Play( g_idZvuk[15] );
					i->zvuk = 1;
				}
				TRect m_vel = _vel;
				m_vel.height = i->iPosun;
				if(i->iPosun < _vel.height && !g_pausa) i->iPosun += posun;
				if(i->iPosun >= _vel.height) {i->iStav = 1;i->iPosun = _vel.height;}
				
				C_2DOBJECT_0 o(m_vel);
				o.SetTextureId( TM.GetIdTexture(g_textures[20]) );
				glDisable(GL_BLEND);
				glColor3f(1,1,1);
				o.Render();
				//g_font.Print(m_vel.x+40, m_vel.y+20, i->text.c_str());
			}else
			if(i->iStav == 1)
			{
				// zobraz info
				C_2DOBJECT_0 o(_vel);
				o.SetTextureId( TM.GetIdTexture(g_textures[20]) );
				glDisable(GL_BLEND);
				glColor3f(1,1,1);
				o.Render();
				g_font.Print(_vel.x+15, _vel.y+10, i->text.c_str());
				
				if(!g_pausa)
				{
					static uint old_cas=0, new_cas=0;
					new_cas = timeGetTime();
					int kolik = new_cas - old_cas;

					if(old_cas != 0) i->iAktDelay -= kolik;
					old_cas = new_cas;
					if(i->iAktDelay <= 0) {i->iStav=2;old_cas=0;new_cas=0;}
				}
			}else
			if(i->iStav == 2)
			{
				// zobraz info
				TRect m_vel = _vel;
				m_vel.height = i->iPosun;
				if(i->iPosun > 0 && !g_pausa) i->iPosun -= posun;
				if(i->iPosun <= 0 ) i->bShow = 0;
				C_2DOBJECT_0 o( m_vel );
				o.SetTextureId( TM.GetIdTexture(g_textures[20]) );
				glDisable(GL_BLEND);
				glColor3f(1,1,1);
				o.Render();
				//g_font.Print(m_vel.x+40, m_vel.y+20, i->text.c_str());
			}else
			break;
		}
	}
}

//void C_INFO_0::AktKonec();

C_UDALOST_0::C_UDALOST_0()
{
	_full = 0;
	_stav = 0;
}

bool C_UDALOST_0::Add(uint texID, int delay, std::string text, uint jaka )
{
	if(!_full)
	{
		_udalost.texture_id = texID;
		_udalost.delay = delay;
		_udalost.show = 1;
		_udalost.text = text;
		_udalost.jaka = jaka;
		g_newUdalost = 1;
		_NastavFull();
	}else return 0;
	return 1;
}

void C_UDALOST_0::Render()
{
	g_stavUdalost = -1;
	if(!_udalost.show) return;

	TRect rect = {555, 40, 60, 60};
	rect = menu_hra.PrevedRectNaScreen(rect);
	glColor3f(1, 1, 1);
	g_font.Print(rect.x, rect.y-15, _udalost.text.c_str());
	Draw2dAlphaMin(_udalost.texture_id, rect, 0.8f);
	g_stavUdalost = _udalost.jaka;
	// odecet casu
	if(!g_pausa)
	{
		static int new_cas;
		new_cas = timeGetTime();
		if(_old_cas != 0) _udalost.delay -= (new_cas-_old_cas);
		_old_cas = new_cas;
	}else _old_cas=0;
	if(_udalost.delay <= 0) 
	{
		_udalost.show = 0;
		_NastavFull();
	}
}

void C_UDALOST_0::_NastavFull()
{
	_full = _udalost.show;
	_old_cas=0;
}

void C_UDALOST_0::Refresh()
{
	if( g_aktKolo < 3 ) return;
	if(!_stav) return;
	int nah = (rand()%1500);
	
	
	if(nah == 1) 
	{
		g_udalost.Add( TM.GetIdTexture( g_textures[2] ), 5000, "Zemětřesení", 0);
	}else
	if(nah == 2)
	{ 
		g_udalost.Add( TM.GetIdTexture( g_textures[3] ), 5000, "Vichřice", 1);
	}else
	if(nah == 3)
	{
		g_udalost.Add( TM.GetIdTexture( g_textures[4] ), 5000, "Mor", 2);
	}else
	if(nah == 4)
	{
		g_udalost.Add( TM.GetIdTexture( g_textures[5] ), 5000, "Magická bouře", 3);
	}else
	if(nah == 5)
	{
		g_udalost.Add( TM.GetIdTexture( g_textures[6] ), 5000, "Požár", 4);
	}else
	if(nah == 6)
	{
		g_udalost.Add( TM.GetIdTexture( g_textures[7] ), 5000, "Banditi", 5);
	}else
	if(nah == 7)
	{
		g_udalost.Add( TM.GetIdTexture( g_textures[39] ), 5000, "Zlato", 6);
	}else
	if(nah == 8)
	{
		g_udalost.Add( TM.GetIdTexture( g_textures[40] ), 5000, "Kamení", 7);
	}else
	if(nah == 9)
	{
		g_udalost.Add( TM.GetIdTexture( g_textures[41] ), 5000, "Mana", 8);
	}
}

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
std::string PrevedSec(uint sec)
{
	std::string ret;
	int hod = sec/3600;
	sec -= hod*3600;
	int minut = sec/60;
	sec -= minut*60;
	char text[255];
	sprintf(text, "%dHod, %dMin, %dSek", hod, minut, sec);
	ret = text;
	return ret;
}

void DrawVictori(int i)
{
	const int POC_POLE = 8;
	int pole_y[POC_POLE] = {55, 70, 85, 100, 115, 130, 155, 180};
	for(register j=0; j<POC_POLE; j++) pole_y[j] = W_PrevedIntYNaScreen( pole_y[j], SCRHeight );
	
	TRect rect = {0, 0, 640, 480};
	rect = W_PrevedRectNaScreen( rect, SCRWidth, SCRHeight );
	C_2DOBJECT_0 o(TM.GetIdTexture(g_textures[21+i]), rect);
	o.SetAplha(0);
	glColor3f(1, 1, 1);
	o.Render();

	int m_x = W_PrevedIntXNaScreen(20, SCRWidth);
	int m_y = W_PrevedIntYNaScreen(20, SCRHeight);
	if( g_hracStat.celkemStesti == 0 ) g_hracStat.celkemStesti = 1;	// divide by zero
	// Zobrazit vysledky boje
	glColor3f(1,1,1);
	g_font.Print(m_x, pole_y[0],"Hrací doba : %s", PrevedSec(g_hracStat.hraciDoba/5).c_str());
	g_font.Print(m_x, pole_y[1],"Počet postavených budov : %d", g_hracStat.poc_budov);
	g_font.Print(m_x, pole_y[2],"Počet vyrobených jednotek : %d", g_hracStat.poc_jednotek);
	g_font.Print(m_x, pole_y[3],"Počet použitých kouzel : %d", g_hracStat.poc_kouzel);
	g_font.Print(m_x, pole_y[4],"Počet zabitých jednotek : %d", g_hracStat.poc_zabJednotek);	
	g_font.Print(m_x, pole_y[5],"Štěstí : %d ( %f%% )",g_hracStat.stesti,float(float(g_hracStat.stesti)/float(g_hracStat.celkemStesti)) * 100.0f);	
	g_font.Print(m_x, pole_y[6],"Bodů celkem : %d", g_hracStat.stesti+g_hracStat.poc_zabJednotek*20+g_hracStat.poc_kouzel*30+
		g_hracStat.poc_jednotek*5+g_hracStat.poc_budov*60-g_hracStat.hraciDoba/5);	
	if( i == 0 ) g_font.Print(m_x, pole_y[7],"Bonus, %d bodů pro výzkum.", g_bodyVyzkum[g_aktKolo]);

	glLineWidth(2.0f);
	DrawLine(0, pole_y[6]-5, rect.width, pole_y[6]-5);

	// pis
	static int cas;
	cas += timer1.GetCas();
	if( cas > 500 ) g_font.Print(W_PrevedIntXNaScreen( 200, SCRWidth ), W_PrevedIntYNaScreen( 440, SCRHeight )," -- ZMÁČKNI ENTER PRO POKRAČOVANÍ -- ");
	if( cas > 1000 ) cas = 0;

	// Graf -
	glLoadIdentity();
	CGraf graf, graf_prot;
	TRect grafRect = { 30.0f, 200.0f, 580.0f, 240.0f };
	grafRect = W_PrevedRectNaScreen( grafRect, SCRWidth, SCRHeight );
	graf.SetBackground( 10, grafRect );
	graf_prot.SetBackground( 0, grafRect );
	graf_prot.SetBackBool( 0 );
	graf.SetBackBool( 0 );
	int *pocX = new int [g_grafDataHrac._data.size()];
	int *pocY = new int [g_grafDataHrac._data.size()];
	int *pocYProt = new int [g_grafDataProt._data.size()];
	for( register graf_j=0; graf_j < g_grafDataHrac._data.size(); graf_j++)
	{
		pocY[graf_j] = g_grafDataHrac._data[ graf_j ];
		pocYProt[graf_j] = g_grafDataProt._data[ graf_j ];
	}

	for( register graf_i=0; graf_i < g_grafDataHrac._data.size(); graf_i++)
		pocX[graf_i] = graf_i;
	graf.SetAtribut( g_grafDataHrac._data.size(), pocX, pocY );
	graf_prot.SetAtribut(g_grafDataProt._data.size(), pocX, pocYProt );
	graf.SetColor(0, 0, 1);
	graf_prot.SetColor(1, 0, 0);
	graf.Render();
	graf_prot.Render();
	delete [] pocX;
	delete [] pocY;
	delete [] pocYProt;
}

// protivnik
void DrawParticleHrad1( )
{
	static CParticleEmitor hradSmoke;
	static CParticleEmitor hradPlamen;
	static bool nastaveno=0;
	THrac hrac = g_prot;
	CVector3 pos_smoke = hradZ.GetPosPoint( "POINT_OHEN" );

	// pos_smoke.x = 0;
	glDisable(GL_ALPHA_TEST);
	if( hrac.Hrad < hrac.max_hrad/3 && !nastaveno )
	{
		// Create smoke
		hradSmoke.SetStartVel( 0.6f );
		hradSmoke.DeleteParticle();
		hradSmoke.SetAtribut( CVector3(pos_smoke.x-0.3, pos_smoke.y, pos_smoke.z), 0, 40, 0.01f, 0.8f );
		hradSmoke.SetTexture( TM.GetIdTexture( g_textures[16] ) );
		hradSmoke.SetBlend(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
		TRGBf color[2] = {1,1,1, 0,0,0}; 
		hradSmoke.SetColor( color[0], color[1] );
		hradSmoke.Create( 30 );
		// Create plamen
		hradPlamen.SetStartVel( 0.6f );
		hradPlamen.DeleteParticle();
		hradPlamen.SetAtribut(CVector3(pos_smoke.x-0.3, pos_smoke.y, pos_smoke.z), 0, 30, 0.01f, 0.5f );
		hradPlamen.SetTexture( TM.GetIdTexture( g_textures[15] ) );
		hradPlamen.SetColor( color[0], color[1] );
		hradPlamen.Create( 30 );
		nastaveno = 1;
	}else if(hrac.Hrad >=hrac.max_hrad/3 ) nastaveno=0;
	if( hrac.Hrad < hrac.max_hrad/4 )
	{
		hradSmoke.SetAtribut( CVector3(pos_smoke.x-0.3f, pos_smoke.y, pos_smoke.z), 0, 40, 0.01f, 1.0f );
		hradPlamen.SetAtribut( CVector3(pos_smoke.x-0.3f, pos_smoke.y, pos_smoke.z), 0, 30, 0.01f, 0.7f );
	}
	if( nastaveno )
	{
		hradSmoke.Render( g_rotate.x, g_rotate.y );
		hradSmoke.Update( 60.0f );
		hradPlamen.Render( g_rotate.x, g_rotate.y );
		hradPlamen.Update( 60.0f );
	}
}
void DrawParticleHrad2( )
{
	static CParticleEmitor hradSmoke;
	static CParticleEmitor hradPlamen;
	static bool nastaveno=0;
	THrac hrac = g_hrac;
	CVector3 pos_smoke = hradD.GetPosPoint( "POINT_OHEN" );
	glDisable(GL_ALPHA_TEST);
	if( hrac.Hrad < hrac.max_hrad/3 && !nastaveno )
	{
		// Create
		hradSmoke.DeleteParticle();
		hradSmoke.SetStartVel( 0.6f );
		hradSmoke.SetAtribut( CVector3(pos_smoke.x-0.3f, pos_smoke.y, pos_smoke.z), 0, 40, 0.01f, 0.8f );
		hradSmoke.SetTexture( TM.GetIdTexture( g_textures[16] ) );
		hradSmoke.SetBlend(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
		TRGBf color[2] = {1,1,1, 0,0,0};
		hradSmoke.SetColor( color[0], color[1] );
		hradSmoke.Create( 30 );
		// Create plamen
		hradPlamen.DeleteParticle();
		hradPlamen.SetStartVel( 0.6f );
		hradPlamen.SetAtribut( CVector3(pos_smoke.x-0.3f, pos_smoke.y, pos_smoke.z), 0, 30, 0.01f, 0.5f );
		hradPlamen.SetTexture( TM.GetIdTexture( g_textures[15] ) );
		hradPlamen.SetColor( color[0], color[1] );
		hradPlamen.Create( 30 );
		nastaveno = 1;
	}else if(hrac.Hrad >=hrac.max_hrad/3 ) nastaveno=0;

	if( hrac.Hrad < hrac.max_hrad/4 )
	{
		hradSmoke.SetAtribut( CVector3(pos_smoke.x-0.3f, pos_smoke.y, pos_smoke.z), 0, 40, 0.01f, 1.0f );
		hradPlamen.SetAtribut( CVector3(pos_smoke.x-0.3f, pos_smoke.y, pos_smoke.z), 0, 30, 0.01f, 0.7f );
	}

	if( nastaveno )
	{
		hradSmoke.Render( g_rotate.x, g_rotate.y );
		hradSmoke.Update( 60.0f );
		hradPlamen.Render( g_rotate.x, g_rotate.y );
		hradPlamen.Update( 60.0f );
	}
}

// / / // / / / 

void RenderEfektUdalosti()
{
	TRGBf barva = RGBf_RED;
	TRGBf barva2 = RGBf_GREEN;
	static int posledni=-1;
	if( g_stavUdalost == 0 )
	{
		// Vyvolej zemetreseni
		if( g_newUdalost ) 
		{
			InfoText.Add( "Právě začalo zemětřesení ", barva );
			int nah = (rand()%20);
			if( nah >= 18 )
			{
				// spadla budova
				if( nah == 18 && g_hrac.zbrojnice > 0 )
				{
					InfoText.Add( "Spadla ti budova ZBROJNICE :( ", barva );
					g_hrac.zbrojnice--;
					g_hracStat.stesti++;
					g_hracStat.celkemStesti++;
				}
				if( nah == 19 && g_hrac.strelnice > 0 )
				{
					InfoText.Add( "Spadla ti budova STŘELNICE :( ", barva );
					g_hrac.strelnice--;
					g_hracStat.stesti--;
					g_hracStat.celkemStesti++;
				}
			}else InfoText.Add( "Naštěstí ti nespadla žádná budova :D ", barva2 );
		}
		// rendering zemetreseni
		float rand = W_Spec2Rand(0,50);
		float rand2 = W_Spec2Rand(0,50);
		static int citac=0;
		rand = (rand/100.0f)*(2.5f/90)*cos( citac )*6;
		rand2 = (rand/100.0f)*(2.5f/90)*cos( citac )*6;
		g_plane.x += rand;
		g_plane.y += rand2/2;
		citac++;
		posledni=g_stavUdalost;
	}else
	if( g_stavUdalost == 1 )
	{
		// Vychrice
		if( g_newUdalost ) InfoText.Add( "Vichřice - jednotky jsou zpomalené ", barva );
		posledni=g_stavUdalost;
		g_hrac.speedPlus = -1;
		g_prot.speedPlus = -1;
	}else
	if( g_stavUdalost == 2 )
	{
		// Mor
		if( g_newUdalost ) InfoText.Add( "Mor - nemúžeš nakupovat jednotky ", barva );
		posledni=g_stavUdalost;
		g_zakazNakupu=1;
	}else
	if( g_stavUdalost == 3 )
	{
		// Magicka boure
		if( g_newUdalost ) InfoText.Add( "Magická bouře - postupně ubíra manu ", barva );
		posledni=g_stavUdalost;
		static uint old_cas=0, new_cas=0;
		new_cas = timeGetTime();
		int kolik = new_cas - old_cas;

		if(old_cas != 0)
		{
			static uint cas;
			cas += kolik;
			if(cas > 20 && g_hrac.mana > 0) {g_hrac.mana--; cas=0;}
			else {g_hracStat.stesti++;g_hracStat.celkemStesti++;}
		}
		old_cas = new_cas;

	}else
	if( g_stavUdalost == 4 )
	{
		// Pozar
		if( g_newUdalost ) 
		{
			if( g_hrac.kamenictvy > 2 )
			{
				InfoText.Add( "Požár - vypukl požár a shořel jeden důl na kamení", barva );
				g_hrac.kamenictvy--;
				g_hracStat.stesti--;
				g_hracStat.celkemStesti++;
			}else
			{
				InfoText.Add( "Požár - vypukl požár ale nic ti nezhořelo", barva2 );
				g_hracStat.stesti++;
				g_hracStat.celkemStesti++;
			}
		}
		posledni=g_stavUdalost;

		
	}else
	if( g_stavUdalost == 5 )
	{
		// Banditi
		if( g_newUdalost ) 
		{
			InfoText.Add( "Tvé doly okupují banditi  ", barva );	
			if( g_hrac.doly > 2 ) {g_hrac.doly--;InfoText.Add( "- 1 dul :(", barva );}
			else {g_hracStat.stesti++;g_hracStat.celkemStesti++;}
		}

		posledni=g_stavUdalost;
	}else
	if( g_stavUdalost == 6 )
	{
		// Zlato
		if( g_newUdalost ) 
		{
			int plus_zl = 200*g_aktKolo + 500;
			InfoText.Add( W_GetString("Zlato +%d ", plus_zl), barva2 );
			g_hracStat.stesti++;
			g_hracStat.celkemStesti++;
			g_hrac.penize += plus_zl;
		}
		posledni=g_stavUdalost;
	}else
	if( g_stavUdalost == 7 )
	{
		// Kameni
		if( g_newUdalost ) 
		{
			int plus_zl = 300*g_aktKolo + 500;
			InfoText.Add( W_GetString("Kamení +%d ", plus_zl), barva2 );
			g_hracStat.stesti++;
			g_hracStat.celkemStesti++;
			g_hrac.kameny += plus_zl;
		}
		posledni=g_stavUdalost;
	}else
	if( g_stavUdalost == 8 )
	{
		// Mana
		if( g_newUdalost ) 
		{
			int plus_zl = 40*g_aktKolo + 10;
			InfoText.Add( W_GetString("Mana +%d ", plus_zl), barva2 );
			g_hracStat.stesti++;
			g_hracStat.celkemStesti++;
			g_hrac.mana += plus_zl;
		}
		posledni=g_stavUdalost;
	}else
	{
		if(posledni == 0)
		{
			SetCamera();
		}else
		if(posledni == 1)
		{
			g_hrac.speedPlus = 0;
			g_prot.speedPlus = 0;
		}else
		if(posledni == 2)
		{
			g_zakazNakupu=0;
		}else
		if(posledni == 3)
		{
		}else
		if(posledni == 4)
		{
		}else
		if(posledni == 5)
		{
		}
		posledni=-1;
	}
	if( g_stavUdalost != -1 ) g_newUdalost=0;
}

// POCASI //
////////////
/*
 *	Typy :
 *   Svetlo
 *   Tma
 *   Mlha
 *   Slab. dest
 *   Velky dest 
 *   Bourka
 *   Svetlo-LensFlare
 */

CPocasi::CPocasi()
: _typ(POC_SVETLO), _prubech(3)
{
	
}

CPocasi::~CPocasi()
{
	
}

void CPocasi::Render()
{
	if( _typ == 0 )
	{
		// nic klasika
	}else
	if( _typ == 1 )
	{
		// tma
		W_NaplnPole( g_fogColor, fogTma, 4 );
		if( _prubech == 0 )
		{
			g_mlha_cislo = 1;
			if( g_mlha_co==1 ) _prubech=1;
		}else
		if( _prubech == 2 )
		{
			g_mlha_cislo = 0;
			if( g_mlha_co==1 ) _prubech=3;
		}
	}else
	if( _typ == 2 )
	{
		// mlha
		W_NaplnPole( g_fogColor, fogMlha, 4 );
		if( _prubech == 0 )
		{
			g_mlha_cislo = 1;
			if( g_mlha_co==1 ) _prubech=1;
		}else
		if( _prubech == 2 )
		{
			g_mlha_cislo = 0;
			if( g_mlha_co==1 ) _prubech=3;
		}
	}else
	if( _typ == 3 )
	{
		// dest
		if( _prubech == 0 )
		{
			static float cit;
			cit += 1.0*(g_fps.GetFPS()/60);
			if( cit > 1.0f ) {g_destKolik++; cit=0; }
			if( g_destKolik >= 90 ) _prubech=1;
		}else
		if( _prubech == 2 )
		{
			g_destKolik--;
			if( g_destKolik <= 0 ) _prubech=3;
		}
	}else	
	if( _typ == 4 )
	{
		// velky dest
		if( _prubech == 0 )
		{
			g_destKolik++;
			if( g_destKolik > 199 ) _prubech=1;
		}else
		if( _prubech == 2 )
		{
			g_destKolik--;
			if( g_destKolik < 0 ) _prubech=3;
		}
	}
	if( _typ == 5 )
	{
		// bourka
		W_NaplnPole( g_fogColor, fogBou, 4 );
		if( g_destKolik < 250 && g_mlha_cislo==1 ) g_destKolik++;
		if( g_destKolik > 0 && g_mlha_cislo==0 ) g_destKolik--;
		if( _prubech == 0 )
		{
			g_mlha_cislo = 1;
			if( g_mlha_co==1 ) { _prubech=1; }
		}else
		if( _prubech == 2 )
		{
			g_mlha_cislo = 0;
			if( g_mlha_co==1 ) _prubech=3;
		}
		static bool draw_blesk=0;
		static CVector3 pos;
		int nah = (rand()%100);
		if( nah==1 && draw_blesk==0 )  
		{
			draw_blesk = 1;
			pos.x = float(rand()%100)/10.0f - 10.0f;
			pos.y = 0;
			pos.z = -(float(rand()%100)/10.0f + 16.0f);
		}
		TVel vel = { 7.0f, 11.0f };
		g_blesknuti=0;
		if( draw_blesk ) 
		{
			DrawBlesk( pos, vel, 0.3f ); 
			g_blesknuti=1;
			static float citac=0;
			citac += g_fps.GetFPS()/60 * 1;
			if( citac >= 0.25f ) 
			{
				citac=0.0f;
				draw_blesk=0;
			}
		}

	}else
	if( _typ == 6 )
	{
		// svetlo-lensflare
		static float blend = 0.0f;
		if( _prubech == 0 )
		{
			static float cit;
			cit += 1.0*(g_fps.GetFPS()/60);
			if( cit > 1.0f ) {blend += 0.02; cit=0; }
			if( blend >= 1.0f ) _prubech=1;
		}else
		if( _prubech == 2 )
		{
			static float cit;
			cit += 1.0*(g_fps.GetFPS()/60);
			if( cit > 1.0f ) {blend -= 0.02; cit=0; }
			if( blend <= 0.0f ) _prubech=3;
		}
		static C_2DOBJECT_0 obj(TM.GetIdTexture( g_textures[32]), 0, 0, SCRWidth, SCRHeight );
		glColor4f(1,1,1, blend );
		obj.SetBlend(1);
		obj.SetAplha(0);
		obj.Render();
	}else
	if( _typ == 7 )
	{
		// hehe duha :) blendovana
		static float blend = 0.0f;
		if( _prubech == 0 )
		{
			static float cit;
			cit += 1.0*(g_fps.GetFPS()/60);
			if( cit > 1.0f ) {blend += 0.02; cit=0; }
			if( blend >= 1.0f ) _prubech=1;
		}else
		if( _prubech == 2 )
		{
			static float cit;
			cit += 1.0*(g_fps.GetFPS()/60);
			if( cit > 1.0f ) {blend -= 0.02; cit=0; }
			if( blend <= 0.0f ) _prubech=3;
		}
		static C_2DOBJECT_0 obj(TM.GetIdTexture( g_textures[37]), 0, 0, SCRWidth, SCRHeight );
		glColor4f(1,1,1, blend );
		obj.SetBlend(1);
		obj.SetAplha(0);
		obj.Render();
	}

	if( _prubech == 1 && _dalsiTyp != _typ ) _prubech=2;
	if( _prubech == 3 && _dalsiTyp != _typ ) {_typ = _dalsiTyp;_prubech=0;}
}

bool CPocasi::SetPocasi( int pocasi )
{
	_dalsiTyp = pocasi;
	return 0;
}

void CPocasi::GenerujPocasi()
{
	// Generuj pocasi
	int nah = (rand()%100);

	if(nah==10)
	{
		int poc = (rand()%7)+1;
		this->SetPocasi( poc );
	}
	
}