2
0
Эх сурвалжийг харах

some warning & code cleanup - nothing significant

Łukasz Wychrystenko 17 жил өмнө
parent
commit
633b0007ba

+ 7 - 8
AI_Base.h

@@ -1,15 +1,14 @@
+#ifndef AIBASE_H
+#define AIBASE_H
+
+#ifdef _MSC_VER
 #pragma once
+#endif
+
 #include <vector>
 #include <iostream>
 #include "CGameInterface.h"
 
 #define AI_INTERFACE_VER 1
 
-
-
-
-
-
-
-
-
+#endif //AIBASE_H

+ 19 - 13
AdventureMapButton.cpp

@@ -118,29 +118,31 @@ void AdventureMapButton::init(const CFunctionList<void()> &Callback, const std::
 	state=0;
 	hoverTexts = Name;
 	helpBox=HelpBox;
-	int est = LOCPLINT->playerID;
+	//int est = LOCPLINT->playerID; //TODO use me
 	CDefHandler * temp = CDefHandler::giveDef(defName); 
 	temp->notFreeImgs = true;
-	for (int i=0;i<temp->ourImages.size();i++)
+	for (size_t i=0;i<temp->ourImages.size();i++)
 	{
 		imgs.resize(1);
 		imgs[0].push_back(temp->ourImages[i].bitmap);
-		if(playerColoredButton)
+		if(playerColoredButton) {
 			graphics->blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
+                }
 	}
 	delete temp;
 	if (add && add->size())
 	{
 		imgs.resize(imgs.size()+add->size());
-		for (int i=0; i<add->size();i++)
+		for (size_t i=0; i<add->size();i++)
 		{
 			temp = CDefHandler::giveDef((*add)[i]);
 			temp->notFreeImgs = true;
-			for (int j=0;j<temp->ourImages.size();j++)
+			for (size_t j=0;j<temp->ourImages.size();j++)
 			{
 				imgs[i+1].push_back(temp->ourImages[j].bitmap);
-				if(playerColoredButton)
+				if(playerColoredButton) {
 					graphics->blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
+                                }
 			}
 			delete temp;
 		}
@@ -220,25 +222,28 @@ CHighlightableButtonsGroup::CHighlightableButtonsGroup(const CFunctionList2<void
 }
 CHighlightableButtonsGroup::~CHighlightableButtonsGroup()
 {
-	for(int i=0;i<buttons.size();i++)
-		delete buttons[i];
+	for(size_t i=0;i<buttons.size();i++) {
+		delete buttons[i]; //TODO smartpointers
+        }
 }
 void CHighlightableButtonsGroup::activate()
 {
-	for(int i=0;i<buttons.size();i++)
+	for(size_t i=0;i<buttons.size();i++) {
 		buttons[i]->activate();
+        }
 }
 void CHighlightableButtonsGroup::deactivate()
 {
-	for(int i=0;i<buttons.size();i++)
+	for(size_t i=0;i<buttons.size();i++) {
 		buttons[i]->deactivate();
+        }
 }
 void CHighlightableButtonsGroup::select(int id, bool mode)
 {
 	CHighlightableButton *bt = NULL;
 	if(mode)
 	{
-		for(int i=0;i<buttons.size() && !bt;i++)
+		for(size_t i=0;i<buttons.size() && !bt; ++i)
 			if (buttons[i]->ID == id)
 				bt = buttons[i];
 	}
@@ -252,15 +257,16 @@ void CHighlightableButtonsGroup::select(int id, bool mode)
 
 void CHighlightableButtonsGroup::selectionChanged(int to)
 {
-	for(int i=0;i<buttons.size();i++)
+	for(size_t i=0;i<buttons.size(); ++i)
 		if(buttons[i]->ID!=to && buttons[i]->selected)
 			buttons[i]->select(false);
 	onChange(to);
 }
 void CHighlightableButtonsGroup::show(SDL_Surface * to )
 {
-	for(int i=0;i<buttons.size();i++)
+	for(size_t i=0;i<buttons.size(); ++i) {
 		buttons[i]->show();
+        }
 }
 
 void CSlider::sliderClicked()

+ 8 - 0
AdventureMapButton.h

@@ -1,4 +1,11 @@
+#ifndef ADVENTUREMAPBUTTON_H
+#define ADVENTUREMAPBUTTON_H
+
+#ifdef _MSC_VER
 #pragma once
+#endif
+
+
 #include "CPlayerInterface.h"
 #include "client/FunctionList.h"
 #include <boost/bind.hpp>
@@ -91,3 +98,4 @@ public:
 		int Value=0, bool Horizontal=true);
 	~CSlider();
 };	
+#endif //ADVENTUREMAPBUTTON_H

+ 21 - 16
CAdvmapInterface.cpp

@@ -27,8 +27,13 @@
 #include <boost/assign/std/vector.hpp>
 #include <boost/thread.hpp>
 #include <sstream>
-#pragma warning (disable : 4355) 
+
+#ifdef _MSC_VER
+#pragma warning (disable : 4355)
+#endif
+
 extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
+
 #define ADVOPT (conf.go()->ac)
 using namespace boost::logic;
 using namespace boost::assign;
@@ -113,7 +118,7 @@ void CMinimap::draw()
 	int mw = map[0]->w, mh = map[0]->h,
 		wo = mw/mapSizes.x, ho = mh/mapSizes.y;
 
-	for (int i=0; i<hh.size();i++)
+	for (size_t i=0; i < hh.size(); ++i)
 	{
 		int3 hpos = hh[i]->getPosition(false);
 		if(hpos.z!=LOCPLINT->adventureInt->position.z)
@@ -136,7 +141,7 @@ void CMinimap::draw()
 		for(int y=0; y<mapSizes.y; ++y)
 		{
 			std::vector < const CGObjectInstance * > oo = LOCPLINT->cb->getFlaggableObjects(int3(x, y, LOCPLINT->adventureInt->position.z));
-			for(int v=0; v<oo.size(); ++v)
+			for(size_t v=0; v<oo.size(); ++v)
 			{
 				if(!dynamic_cast< const CGHeroInstance * >(oo[v])) //heroes have been printed
 				{
@@ -170,7 +175,7 @@ void CMinimap::draw()
 void CMinimap::redraw(int level)// (level==-1) => redraw all levels
 {
 	int3 mapSizes = LOCPLINT->cb->getMapSize();
-	for (int i=0; i<CGI->mh->sizes.z; i++)
+	for (size_t i=0; i<CGI->mh->sizes.z; i++)
 	{
 		SDL_Surface * pom ;
 		if ((level>=0) && (i!=level))
@@ -194,8 +199,8 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels
 	}
 
 	//FoW
-	int mw = map[0]->w, mh = map[0]->h,
-		wo = mw/mapSizes.x, ho = mh/mapSizes.y;
+	int mw = map[0]->w, mh = map[0]->h;//,
+		//wo = mw/mapSizes.x, ho = mh/mapSizes.y; //TODO use me
 	for(int d=0; d<CGI->mh->map->twoLevel+1; ++d)
 	{
 		if(level>=0 && d!=level)
@@ -302,7 +307,7 @@ CTerrainRect::CTerrainRect():currentPath(NULL)
 	pos.h=tilesh*32 - ADVOPT.advmapTrimY;
 	moveX = moveY = 0;
 	arrows = CDefHandler::giveDef("ADAG.DEF");
-	for(int y=0; y<arrows->ourImages.size(); ++y)
+	for(size_t y=0; y < arrows->ourImages.size(); ++y)
 	{
 		arrows->ourImages[y].bitmap = CSDL_Ext::alphaTransform(arrows->ourImages[y].bitmap);
 	}
@@ -338,7 +343,7 @@ void CTerrainRect::clickLeft(tribool down)
 			currentPath = NULL;
 		}
 		objs = LOCPLINT->cb->getBlockingObjs(mp);
-		for(int i=0; i<objs.size();i++)
+		for(size_t i=0; i < objs.size(); ++i)
 		{
 			if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town
 			{
@@ -363,13 +368,13 @@ void CTerrainRect::clickLeft(tribool down)
 	else
 	{
 		objs = LOCPLINT->cb->getVisitableObjs(mp);
-		for(int i=0; i<objs.size();i++)
+		for(size_t i=0; i < objs.size(); ++i)
 		{
 			if(objs[i]->ID == 98)
 				goto endchkpt;
 		}
 		objs = LOCPLINT->cb->getBlockingObjs(mp);
-		for(int i=0; i<objs.size();i++)
+		for(size_t i=0; i < objs.size(); ++i)
 		{
 			if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town
 			{
@@ -451,7 +456,7 @@ void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
 		}
 	}
 	objs = LOCPLINT->cb->getBlockingObjs(pom);
-	for(int i=0; i<objs.size();i++)
+	for(size_t i=0; i < objs.size(); ++i)
 	{
 		if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town
 		{
@@ -475,7 +480,7 @@ void CTerrainRect::hover(bool on)
 }
 void CTerrainRect::showPath()
 {
-	for (int i=0;i<currentPath->nodes.size()-1;i++)
+	for (size_t i=0; i < currentPath->nodes.size()-1; ++i)
 	{
 		int pn=-1;//number of picture
 		if (i==0) //last tile
@@ -728,7 +733,7 @@ void CTerrainRect::showPath()
 }
 void CTerrainRect::show()
 {
-	SDL_Surface * teren = CGI->mh->terrainRect
+	SDL_Surface * teren = CGI->mh->terrainRect //TODO use me
 		(LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
 		tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim,
 		&LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
@@ -1028,8 +1033,8 @@ nextHero(CGI->generaltexth->zelp[301].first,CGI->generaltexth->zelp[301].second,
 endTurn(CGI->generaltexth->zelp[302].first,CGI->generaltexth->zelp[302].second,
 		  boost::bind(&CAdvMapInt::fendTurn,this), &ADVOPT.endTurn, SDLK_e),
 
-townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlistAD),//(5,&genRect(192,48,747,196),747,196,747,372),
-heroList(ADVOPT.hlistSize)
+heroList(ADVOPT.hlistSize),
+townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlistAD)//(5,&genRect(192,48,747,196),747,196,747,372),
 {
 	selection = NULL;
 	townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
@@ -1339,7 +1344,7 @@ void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * c
 	}
 	else
 	{
-		for (int i=0;i<LOCPLINT->objsToBlit.size();i++)
+		for (size_t i=0; i < LOCPLINT->objsToBlit.size(); ++i)
 		{
 			//TODO: pewnie da sie to zrobic lepiej, ale nie chce mi sie. Wolajacy obiekt powinien informowac kogo spodziewa sie odwolac (null jesli down)
 			CSimpleWindow * pom = dynamic_cast<CSimpleWindow*>(LOCPLINT->objsToBlit[i]);

+ 2542 - 2511
CBattleInterface.cpp

@@ -1,2511 +1,2542 @@
-#include "CBattleInterface.h"
-#include "CGameInfo.h"
-#include "hch/CLodHandler.h"
-#include "SDL_Extensions.h"
-#include "CAdvmapInterface.h"
-#include "AdventureMapButton.h"
-#include "hch/CObjectHandler.h"
-#include "hch/CHeroHandler.h"
-#include "hch/CDefHandler.h"
-#include "hch/CSpellHandler.h"
-#include "CCursorHandler.h"
-#include "CCallback.h"
-#include "CGameState.h"
-#include "hch/CGeneralTextHandler.h"
-#include "client/CCreatureAnimation.h"
-#include "client/Graphics.h"
-#include "client/CSpellWindow.h"
-#include <queue>
-#include <sstream>
-#include "lib/CondSh.h"
-#include "lib/NetPacks.h"
-#include <boost/assign/list_of.hpp>
-#ifndef __GNUC__
-const double M_PI = 3.14159265358979323846;
-#else
-#define _USE_MATH_DEFINES
-#include <cmath>
-#endif
-
-extern SDL_Surface * screen;
-extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
-extern SDL_Color zwykly;
-
-class CMP_stack2
-{
-public:
-	inline bool operator ()(const CStack& a, const CStack& b)
-	{
-		return (a.speed())>(b.speed());
-	}
-} cmpst2 ;
-
-CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2)
-: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL),
-	attackingInfo(NULL), myTurn(false), resWindow(NULL), showStackQueue(false), animSpeed(2), printStackRange(true),
-	printMouseShadow(true), spellDestSelectMode(false), spellToCast(NULL), previouslyHoveredHex(-1)
-{
-	strongInterest = true;
-	givenCommand = new CondSh<BattleAction *>(NULL);
-	//initializing armies
-	this->army1 = army1;
-	this->army2 = army2;
-	std::map<int, CStack> stacks = LOCPLINT->cb->battleGetStacks();
-	for(std::map<int, CStack>::iterator b=stacks.begin(); b!=stacks.end(); ++b)
-	{
-		std::pair <int, int> coords = CBattleHex::getXYUnitAnim(b->second.position, b->second.owner == attackingHeroInstance->tempOwner, b->second.creature);
-		creAnims[b->second.ID] = (new CCreatureAnimation(b->second.creature->animDefName));
-		creAnims[b->second.ID]->setType(2);
-		creAnims[b->second.ID]->pos = genRect(creAnims[b->second.ID]->fullHeight, creAnims[b->second.ID]->fullWidth, coords.first, coords.second);
-		creDir[b->second.ID] = b->second.owner==attackingHeroInstance->tempOwner;
-	}
-	//preparing menu background and terrain
-	std::vector< std::string > & backref = graphics->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ];
-	background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] );
-	menu = BitmapHandler::loadBitmap("CBAR.BMP");
-	graphics->blueToPlayersAdv(menu, hero1->tempOwner);
-
-	//preparing graphics for displaying amounts of creatures
-	amountNormal = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
-	CSDL_Ext::alphaTransform(amountNormal);
-	for(int g=0; g<amountNormal->format->palette->ncolors; ++g)
-	{
-		if((amountNormal->format->palette->colors+g)->b != 132 &&
-			(amountNormal->format->palette->colors+g)->g != 231 &&
-			(amountNormal->format->palette->colors+g)->r != 255) //it's not yellow border
-		{
-			(amountNormal->format->palette->colors+g)->r = (float)((amountNormal->format->palette->colors+g)->r) * 0.54f;
-			(amountNormal->format->palette->colors+g)->g = (float)((amountNormal->format->palette->colors+g)->g) * 0.19f;
-			(amountNormal->format->palette->colors+g)->b = (float)((amountNormal->format->palette->colors+g)->b) * 0.93f;
-		}
-	}
-	amountPositive = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
-	CSDL_Ext::alphaTransform(amountPositive);
-	for(int g=0; g<amountPositive->format->palette->ncolors; ++g)
-	{
-		if((amountPositive->format->palette->colors+g)->b != 132 &&
-			(amountPositive->format->palette->colors+g)->g != 231 &&
-			(amountPositive->format->palette->colors+g)->r != 255) //it's not yellow border
-		{
-			(amountPositive->format->palette->colors+g)->r = (float)((amountPositive->format->palette->colors+g)->r) * 0.18f;
-			(amountPositive->format->palette->colors+g)->g = (float)((amountPositive->format->palette->colors+g)->g) * 1.00f;
-			(amountPositive->format->palette->colors+g)->b = (float)((amountPositive->format->palette->colors+g)->b) * 0.18f;
-		}
-	}
-	amountNegative = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
-	CSDL_Ext::alphaTransform(amountNegative);
-	for(int g=0; g<amountNegative->format->palette->ncolors; ++g)
-	{
-		if((amountNegative->format->palette->colors+g)->b != 132 &&
-			(amountNegative->format->palette->colors+g)->g != 231 &&
-			(amountNegative->format->palette->colors+g)->r != 255) //it's not yellow border
-		{
-			(amountNegative->format->palette->colors+g)->r = (float)((amountNegative->format->palette->colors+g)->r) * 1.00f;
-			(amountNegative->format->palette->colors+g)->g = (float)((amountNegative->format->palette->colors+g)->g) * 0.18f;
-			(amountNegative->format->palette->colors+g)->b = (float)((amountNegative->format->palette->colors+g)->b) * 0.18f;
-		}
-	}
-	amountEffNeutral = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
-	CSDL_Ext::alphaTransform(amountNegative);
-	for(int g=0; g<amountNegative->format->palette->ncolors; ++g)
-	{
-		if((amountNegative->format->palette->colors+g)->b != 132 &&
-			(amountNegative->format->palette->colors+g)->g != 231 &&
-			(amountNegative->format->palette->colors+g)->r != 255) //it's not yellow border
-		{
-			(amountNegative->format->palette->colors+g)->r = (float)((amountNegative->format->palette->colors+g)->r) * 1.00f;
-			(amountNegative->format->palette->colors+g)->g = (float)((amountNegative->format->palette->colors+g)->g) * 1.00f;
-			(amountNegative->format->palette->colors+g)->b = (float)((amountNegative->format->palette->colors+g)->b) * 0.18f;
-		}
-	}
-
-	////blitting menu background and terrain
-	blitAt(background, 0, 0);
-	blitAt(menu, 0, 556);
-	CSDL_Ext::update();
-
-	//preparing buttons and console
-	bOptions = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bOptionsf,this), 3, 561, "icm003.def", SDLK_o);
-	bSurrender = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSurrenderf,this), 54, 561, "icm001.def", SDLK_s);
-	bFlee = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bFleef,this), 105, 561, "icm002.def", SDLK_r);
-	bAutofight  = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bAutofightf,this), 157, 561, "icm004.def", SDLK_a);
-	bSpell = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSpellf,this), 645, 561, "icm005.def", SDLK_c);
-	bWait = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bWaitf,this), 696, 561, "icm006.def", SDLK_w);
-	bDefence = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bDefencef,this), 747, 561, "icm007.def", SDLK_d);
-	bDefence->assignedKeys.insert(SDLK_SPACE);
-	bConsoleUp = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624, 561, "ComSlide.def", SDLK_UP);
-	bConsoleDown = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624, 580, "ComSlide.def", SDLK_DOWN);
-	bConsoleDown->bitmapOffset = 2;
-	console = new CBattleConsole();
-	console->pos.x = 211;
-	console->pos.y = 560;
-	console->pos.w = 406;
-	console->pos.h = 38;
-
-	//loading hero animations
-	if(hero1) // attacking hero
-	{
-		attackingHero = new CBattleHero(graphics->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner, hero1->tempOwner == LOCPLINT->playerID ? hero1 : NULL, this);
-		attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40, 0);
-	}
-	else
-	{
-		attackingHero = NULL;
-	}
-	if(hero2) // defending hero
-	{
-		defendingHero = new CBattleHero(graphics->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner, hero2->tempOwner == LOCPLINT->playerID ? hero2 : NULL, this);
-		defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690, 0);
-	}
-	else
-	{
-		defendingHero = NULL;
-	}
-
-	//preparing cells and hexes
-	cellBorder = BitmapHandler::loadBitmap("CCELLGRD.BMP");
-	CSDL_Ext::alphaTransform(cellBorder);
-	cellShade = BitmapHandler::loadBitmap("CCELLSHD.BMP");
-	CSDL_Ext::alphaTransform(cellShade);
-	for(int h=0; h<BFIELD_SIZE; ++h)
-	{
-		bfield[h].myNumber = h;
-
-		int x = 14 + ((h/BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(h%BFIELD_WIDTH);
-		int y = 86 + 42 * (h/BFIELD_WIDTH);
-		bfield[h].pos = genRect(cellShade->h, cellShade->w, x, y);
-		bfield[h].accesible = true;
-		bfield[h].myInterface = this;
-	}
-	//locking occupied positions on batlefield
-	for(std::map<int, CStack>::iterator it = stacks.begin(); it!=stacks.end(); ++it) //stacks gained at top of this function
-	{
-		bfield[it->second.position].accesible = false;
-	}
-
-	//loading projectiles for units
-	for(std::map<int, CStack>::iterator g = stacks.begin(); g != stacks.end(); ++g)
-	{
-		if(g->second.creature->isShooting() && CGI->creh->idToProjectile[g->second.creature->idNumber] != std::string())
-		{
-			idToProjectile[g->second.creature->idNumber] = CDefHandler::giveDef(CGI->creh->idToProjectile[g->second.creature->idNumber]);
-
-			if(idToProjectile[g->second.creature->idNumber]->ourImages.size() > 2) //add symmetric images
-			{
-				for(int k = idToProjectile[g->second.creature->idNumber]->ourImages.size()-2; k > 1; --k)
-				{
-					Cimage ci;
-					ci.bitmap = CSDL_Ext::rotate01(idToProjectile[g->second.creature->idNumber]->ourImages[k].bitmap);
-					ci.groupNumber = 0;
-					ci.imName = std::string();
-					idToProjectile[g->second.creature->idNumber]->ourImages.push_back(ci);
-				}
-			}
-			for(int s=0; s<idToProjectile[g->second.creature->idNumber]->ourImages.size(); ++s) //alpha transforming
-			{
-				CSDL_Ext::alphaTransform(idToProjectile[g->second.creature->idNumber]->ourImages[s].bitmap);
-			}
-		}
-	}
-
-
-	//preparing graphic with cell borders
-	cellBorders = CSDL_Ext::newSurface(background->w, background->h, cellBorder);
-	//copying palette
-	for(int g=0; g<cellBorder->format->palette->ncolors; ++g) //we assume that cellBorders->format->palette->ncolors == 256
-	{
-		cellBorders->format->palette->colors[g] = cellBorder->format->palette->colors[g];
-	}
-	//palette copied
-	for(int i=0; i<BFIELD_HEIGHT; ++i) //rows
-	{
-		for(int j=0; j<BFIELD_WIDTH-2; ++j) //columns
-		{
-			int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
-			int y = 86 + 42 * i;
-			for(int cellX = 0; cellX < cellBorder->w; ++cellX)
-			{
-				for(int cellY = 0; cellY < cellBorder->h; ++cellY)
-				{
-					if(y+cellY < cellBorders->h && x+cellX < cellBorders->w)
-						* ((Uint8*)cellBorders->pixels + (y+cellY) * cellBorders->pitch + (x+cellX)) |= * ((Uint8*)cellBorder->pixels + cellY * cellBorder->pitch + cellX);
-				}
-			}
-		}
-	}
-
-	backgroundWithHexes = CSDL_Ext::newSurface(background->w, background->h, screen);
-}
-
-CBattleInterface::~CBattleInterface()
-{
-	SDL_FreeSurface(background);
-	SDL_FreeSurface(menu);
-	SDL_FreeSurface(amountNormal);
-	SDL_FreeSurface(amountNegative);
-	SDL_FreeSurface(amountPositive);
-	SDL_FreeSurface(amountEffNeutral);
-	SDL_FreeSurface(cellBorders);
-	SDL_FreeSurface(backgroundWithHexes);
-	delete bOptions;
-	delete bSurrender;
-	delete bFlee;
-	delete bAutofight;
-	delete bSpell;
-	delete bWait;
-	delete bDefence;
-	delete bConsoleUp;
-	delete bConsoleDown;
-	delete console;
-	delete resWindow;
-	delete givenCommand;
-
-	delete attackingHero;
-	delete defendingHero;
-
-	SDL_FreeSurface(cellBorder);
-	SDL_FreeSurface(cellShade);
-
-	for(std::map< int, CCreatureAnimation * >::iterator g=creAnims.begin(); g!=creAnims.end(); ++g)
-		delete g->second;
-
-	for(std::map< int, CDefHandler * >::iterator g=idToProjectile.begin(); g!=idToProjectile.end(); ++g)
-		delete g->second;
-}
-
-void CBattleInterface::setPrintCellBorders(bool set)
-{
-	printCellBorders = set;
-	redrawBackgroundWithHexes(activeStack);
-}
-
-void CBattleInterface::setPrintStackRange(bool set)
-{
-	printStackRange = set;
-	redrawBackgroundWithHexes(activeStack);
-}
-
-void CBattleInterface::setPrintMouseShadow(bool set)
-{
-	printMouseShadow = set;
-}
-
-void CBattleInterface::activate()
-{
-	KeyInterested::activate();
-	MotionInterested::activate();
-	subInt = NULL;
-	bOptions->activate();
-	bSurrender->activate();
-	bFlee->activate();
-	bAutofight->activate();
-	bSpell->activate();
-	bWait->activate();
-	bDefence->activate();
-	bConsoleUp->activate();
-	bConsoleDown->activate();
-	for(int b=0; b<BFIELD_SIZE; ++b)
-	{
-		bfield[b].activate();
-	}
-	if(attackingHero)
-		attackingHero->activate();
-	if(defendingHero)
-		defendingHero->activate();
-}
-
-void CBattleInterface::deactivate()
-{
-	KeyInterested::deactivate();
-	MotionInterested::deactivate();
-	bOptions->deactivate();
-	bSurrender->deactivate();
-	bFlee->deactivate();
-	bAutofight->deactivate();
-	bSpell->deactivate();
-	bWait->deactivate();
-	bDefence->deactivate();
-	bConsoleUp->deactivate();
-	bConsoleDown->deactivate();
-	for(int b=0; b<BFIELD_SIZE; ++b)
-	{
-		bfield[b].deactivate();
-	}
-	if(attackingHero)
-		attackingHero->deactivate();
-	if(defendingHero)
-		defendingHero->deactivate();
-}
-
-void CBattleInterface::show(SDL_Surface * to)
-{
-	std::map<int, CStack> stacks = LOCPLINT->cb->battleGetStacks(); //used in a few places
-	++animCount;
-	if(!to) //"evaluating" to
-		to = screen;
-	
-	//printing background and hexes
-	if(activeStack != -1 && creAnims[activeStack]->getType() != 0) //show everything with range
-	{
-		blitAt(backgroundWithHexes, 0, 0, to);
-	}
-	else
-	{
-		//showing background
-		blitAt(background, 0, 0, to);
-		if(printCellBorders)
-		{
-			CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, to, NULL);
-		}
-	}
-	//printing hovered cell
-	if(printMouseShadow)
-	{
-		for(int b=0; b<BFIELD_SIZE; ++b)
-		{
-			if(bfield[b].strictHovered && bfield[b].hovered)
-			{
-				if(previouslyHoveredHex == -1) previouslyHoveredHex = b; //something to start with
-				if(currentlyHoveredHex == -1) currentlyHoveredHex = b; //something to start with
-				if(currentlyHoveredHex != b) //repair hover info
-				{
-					previouslyHoveredHex = currentlyHoveredHex;
-					currentlyHoveredHex = b;
-				}
-				//print shade
-				int x = 14 + ((b/BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(b%BFIELD_WIDTH);
-				int y = 86 + 42 * (b/BFIELD_WIDTH);
-				CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, to, &genRect(cellShade->h, cellShade->w, x, y));
-			}
-		}
-	}
-
-
-	//showing menu background and console
-	blitAt(menu, 0, 556, to);
-	console->show(to);
-
-	//showing buttons
-	bOptions->show(to);
-	bSurrender->show(to);
-	bFlee->show(to);
-	bAutofight->show(to);
-	bSpell->show(to);
-	bWait->show(to);
-	bDefence->show(to);
-	bConsoleUp->show(to);
-	bConsoleDown->show(to);
-
-	//showing hero animations
-	if(attackingHero)
-		attackingHero->show(to);
-	if(defendingHero)
-		defendingHero->show(to);
-
-	////showing units //a lot of work...
-	std::vector<int> stackAliveByHex[BFIELD_SIZE];
-	//double loop because dead stacks should be printed first
-	for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
-	{
-		if(j->second.alive())
-			stackAliveByHex[j->second.position].push_back(j->second.ID);
-	}
-	std::vector<int> stackDeadByHex[BFIELD_SIZE];
-	for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
-	{
-		if(!j->second.alive())
-			stackDeadByHex[j->second.position].push_back(j->second.ID);
-	}
-
-	attackingShowHelper(); // handle attack animation
-
-	for(int b=0; b<BFIELD_SIZE; ++b) //showing dead stacks
-	{
-		for(int v=0; v<stackDeadByHex[b].size(); ++v)
-		{
-			creAnims[stackDeadByHex[b][v]]->nextFrame(to, creAnims[stackDeadByHex[b][v]]->pos.x, creAnims[stackDeadByHex[b][v]]->pos.y, creDir[stackDeadByHex[b][v]], false, stackDeadByHex[b][v]==activeStack); //increment always when moving, never if stack died
-		}
-	}
-	for(int b=0; b<BFIELD_SIZE; ++b) //showing alive stacks
-	{
-		for(int v=0; v<stackAliveByHex[b].size(); ++v)
-		{
-			int animType = creAnims[stackAliveByHex[b][v]]->getType();
-			bool incrementFrame = (animCount%(4/animSpeed)==0) && animType!=0 && animType!=5 && animType!=20 && animType!=21 && animType!=3;
-			creAnims[stackAliveByHex[b][v]]->nextFrame(to, creAnims[stackAliveByHex[b][v]]->pos.x, creAnims[stackAliveByHex[b][v]]->pos.y, creDir[stackAliveByHex[b][v]], incrementFrame, stackAliveByHex[b][v]==activeStack); //increment always when moving, never if stack died
-			//printing amount
-			if(stacks[stackAliveByHex[b][v]].amount > 0) //don't print if stack is not alive
-			{
-				int xAdd = stacks[stackAliveByHex[b][v]].attackerOwned ? 220 : 202;
-
-				//blitting amoutn background box
-				SDL_Surface *amountBG = NULL;
-				if(stacks[stackAliveByHex[b][v]].effects.size() == 0)
-				{
-					amountBG = amountNormal;
-				}
-				else
-				{
-					int pos=0; //determining total positiveness of effects
-					for(int c=0; c<stacks[stackAliveByHex[b][v]].effects.size(); ++c)
-					{
-						pos += CGI->spellh->spells[ stacks[stackAliveByHex[b][v]].effects[c].id ].positiveness;
-					}
-					if(pos > 0)
-					{
-						amountBG = amountPositive;
-					}
-					else if(pos < 0)
-					{
-						amountBG = amountNegative;
-					}
-					else
-					{
-						amountBG = amountEffNeutral;
-					}
-				}
-				SDL_BlitSurface(amountBG, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + xAdd, creAnims[stackAliveByHex[b][v]]->pos.y + 260));
-				//blitting amount
-				std::stringstream ss;
-				ss<<stacks[stackAliveByHex[b][v]].amount;
-				CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackAliveByHex[b][v]]->pos.x + xAdd + 14, creAnims[stackAliveByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
-			}
-		}
-	}
-	//units shown
-	projectileShowHelper(to);//showing projectiles
-
-	//showing spell effects
-	if(battleEffects.size())
-	{
-		std::vector< std::list<SBattleEffect>::iterator > toErase;
-		for(std::list<SBattleEffect>::iterator it = battleEffects.begin(); it!=battleEffects.end(); ++it)
-		{
-			blitAt(it->anim->ourImages[(it->frame)%it->anim->ourImages.size()].bitmap, it->x, it->y, to);
-			++(it->frame);
-
-			if(it->frame == it->maxFrame)
-				toErase.push_back(it);
-		}
-		for(int b=0; b<toErase.size(); ++b)
-		{
-			delete toErase[b]->anim;
-			battleEffects.erase(toErase[b]);
-		}
-	}
-	
-
-	//showing queue of stacks
-	if(showStackQueue)
-	{
-		int xPos = screen->w/2 - ( stacks.size() * 37 )/2;
-		int yPos = 10;
-
-		std::vector<CStack> stacksSorted;
-		stacksSorted = LOCPLINT->cb->battleGetStackQueue();
-		int startFrom = -1;
-		for(int n=0; n<stacksSorted.size(); ++n)
-		{
-			if(stacksSorted[n].ID == activeStack)
-			{
-				startFrom = n;
-				break;
-			}
-		}
-		if(startFrom != -1)
-		{
-			for(int b=startFrom; b<stacksSorted.size()+startFrom; ++b)
-			{
-				SDL_BlitSurface(graphics->smallImgs[-2], NULL, to, &genRect(32, 32, xPos, yPos));
-				//printing colored border
-				for(int xFrom = xPos-1; xFrom<xPos+33; ++xFrom)
-				{
-					for(int yFrom = yPos-1; yFrom<yPos+33; ++yFrom)
-					{
-						if(xFrom == xPos-1 || xFrom == xPos+32 || yFrom == yPos-1 || yFrom == yPos+32)
-						{
-							SDL_Color pc;
-							if(stacksSorted[b % stacksSorted.size()].owner != 255)
-							{
-								pc = graphics->playerColors[stacksSorted[b % stacksSorted.size()].owner];
-							}
-							else
-							{
-								pc = *graphics->neutralColor;
-							}
-							CSDL_Ext::SDL_PutPixelWithoutRefresh(to, xFrom, yFrom, pc.r, pc.g, pc.b);
-						}
-					}
-				}
-				//colored border printed
-				SDL_BlitSurface(graphics->smallImgs[stacksSorted[b % stacksSorted.size()].creature->idNumber], NULL, to, &genRect(32, 32, xPos, yPos));
-				xPos += 37;
-			}
-		}
-	}
-
-	//showing window with result of battle
-	if(resWindow)
-	{
-		resWindow->show(to);
-	}
-}
-void CBattleInterface::keyPressed(const SDL_KeyboardEvent & key)
-{
-	if(key.keysym.sym == SDLK_q)
-		showStackQueue = key.state==SDL_PRESSED;
-}
-void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
-{
-	if(activeStack>=0 && !spellDestSelectMode)
-	{
-		int myNumber = -1; //number of hovered tile
-		for(int g=0; g<BFIELD_SIZE; ++g)
-		{
-			if(bfield[g].hovered && bfield[g].strictHovered)
-			{
-				myNumber = g;
-				break;
-			}
-		}
-		if(myNumber == -1)
-		{
-			CGI->curh->changeGraphic(1, 6);
-		}
-		else
-		{
-			if(std::find(shadedHexes.begin(),shadedHexes.end(),myNumber) == shadedHexes.end())
-			{
-				CStack *shere = LOCPLINT->cb->battleGetStackByPos(myNumber);
-				if(shere)
-				{
-					if(shere->owner == LOCPLINT->playerID) //our stack
-						CGI->curh->changeGraphic(1,5);
-					else if(LOCPLINT->cb->battleCanShoot(activeStack,myNumber)) //we can shoot enemy
-						CGI->curh->changeGraphic(1,3);
-					else if(isTileAttackable(myNumber)) //available enemy (melee attackable)
-					{
-						int fromHex = previouslyHoveredHex;
-						if(fromHex!=-1 && fromHex%17!=0 && fromHex%17!=16 && vstd::contains(shadedHexes, fromHex))
-						{
-							switch(BattleInfo::mutualPosition(fromHex, myNumber))
-							{
-							case 0:
-								CGI->curh->changeGraphic(1,12);
-								break;
-							case 1:
-								CGI->curh->changeGraphic(1,7);
-								break;
-							case 2:
-								CGI->curh->changeGraphic(1,8);
-								break;
-							case 3:
-								CGI->curh->changeGraphic(1,9);
-								break;
-							case 4:
-								CGI->curh->changeGraphic(1,10);
-								break;
-							case 5:
-								CGI->curh->changeGraphic(1,11);
-								break;
-							}
-						}
-					}
-					else //unavailable enemy
-						CGI->curh->changeGraphic(1,0);
-				}
-				else //empty unavailable tile
-					CGI->curh->changeGraphic(1,0);
-			}
-			else //available tile
-			{
-				if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isFlying())
-					CGI->curh->changeGraphic(1,2);
-				else
-					CGI->curh->changeGraphic(1,1);
-			}
-		}
-	}
-	else if(spellDestSelectMode)
-	{
-		int myNumber = -1; //number of hovered tile
-		for(int g=0; g<BFIELD_SIZE; ++g)
-		{
-			if(bfield[g].hovered && bfield[g].strictHovered)
-			{
-				myNumber = g;
-				break;
-			}
-		}
-		if(myNumber == -1)
-		{
-			CGI->curh->changeGraphic(1, 0);
-		}
-		else
-		{
-			switch(spellSelMode)
-			{
-			case 0:
-				CGI->curh->changeGraphic(3, 0);
-				break;
-			case 1:
-				if(LOCPLINT->cb->battleGetStackByPos(myNumber) && LOCPLINT->playerID == LOCPLINT->cb->battleGetStackByPos(myNumber)->owner )
-					CGI->curh->changeGraphic(3, 0);
-				else
-					CGI->curh->changeGraphic(1, 0);
-				break;
-			case 2:
-				if(LOCPLINT->cb->battleGetStackByPos(myNumber) && LOCPLINT->playerID != LOCPLINT->cb->battleGetStackByPos(myNumber)->owner )
-					CGI->curh->changeGraphic(3, 0);
-				else
-					CGI->curh->changeGraphic(1, 0);
-				break;
-			case 3:
-				if(LOCPLINT->cb->battleGetStackByPos(myNumber))
-					CGI->curh->changeGraphic(3, 0);
-				else
-					CGI->curh->changeGraphic(1, 0);
-				break;
-			case 4: //TODO: implement this case
-				break;
-			}
-		}
-	}
-}
-
-bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
-{
-	if(creAnims[number]==NULL)
-		return false; //there is no such creature
-	creAnims[number]->setType(8);
-	int firstFrame = creAnims[number]->getFrame();
-	for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(8) + firstFrame - 1; ++g)
-	{
-		show();
-		CSDL_Ext::update();
-		SDL_framerateDelay(LOCPLINT->mainFPSmng);
-	}
-	creDir[number] = !creDir[number];
-
-	CStack curs = *LOCPLINT->cb->battleGetStackByID(number);
-	std::pair <int, int> coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs.creature);
-	creAnims[number]->pos.x = coords.first;
-	//creAnims[number]->pos.y = coords.second;
-
-	if(wideTrick && curs.creature->isDoubleWide())
-	{
-		if(curs.attackerOwned)
-		{
-			if(!creDir[number])
-				creAnims[number]->pos.x -= 44;
-		}
-		else
-		{
-			if(creDir[number])
-				creAnims[number]->pos.x += 44;
-		}
-	}
-
-	creAnims[number]->setType(7);
-	firstFrame = creAnims[number]->getFrame();
-	for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(7) + firstFrame - 1; ++g)
-	{
-		show();
-		CSDL_Ext::update();
-		SDL_framerateDelay(LOCPLINT->mainFPSmng);
-	}
-	creAnims[number]->setType(2);
-
-	return true;
-}
-
-void CBattleInterface::bOptionsf()
-{
-	CGI->curh->changeGraphic(0,0);
-	deactivate();
-
-	SDL_Rect temp_rect = genRect(431, 481, 160, 84);
-	CBattleOptionsWindow * optionsWin = new CBattleOptionsWindow(temp_rect, this);
-	optionsWin->activate();
-	LOCPLINT->objsToBlit.push_back(optionsWin);
-}
-
-void CBattleInterface::bSurrenderf()
-{
-}
-
-void CBattleInterface::bFleef()
-{
-	CFunctionList<void()> ony = boost::bind(&CBattleInterface::activate,this);
-	ony += boost::bind(&CBattleInterface::reallyFlee,this);
-	LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[28],std::vector<SComponent*>(), ony, boost::bind(&CBattleInterface::activate,this), true, false);
-}
-
-void CBattleInterface::reallyFlee()
-{
-	giveCommand(4,0,0);
-	CGI->curh->changeGraphic(0, 0);
-}
-
-void CBattleInterface::bAutofightf()
-{
-}
-
-void CBattleInterface::bSpellf()
-{
-	CGI->curh->changeGraphic(0,0);
-	deactivate();
-
-	const CGHeroInstance * chi = NULL;
-	if(attackingHeroInstance->tempOwner == LOCPLINT->playerID)
-		chi = attackingHeroInstance;
-	else
-		chi = defendingHeroInstance;
-	CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, 90, 2), chi);
-	spellWindow->activate();
-	LOCPLINT->objsToBlit.push_back(spellWindow);
-}
-
-void CBattleInterface::bWaitf()
-{
-	giveCommand(8,0,activeStack);
-}
-
-void CBattleInterface::bDefencef()
-{
-	giveCommand(3,0,activeStack);
-}
-
-void CBattleInterface::bConsoleUpf()
-{
-	console->scrollUp();
-}
-
-void CBattleInterface::bConsoleDownf()
-{
-	console->scrollDown();
-}
-
-void CBattleInterface::newStack(CStack stack)
-{
-	creAnims[stack.ID] = new CCreatureAnimation(stack.creature->animDefName);
-	creAnims[stack.ID]->setType(2);
-	creDir[stack.ID] = stack.owner==attackingHeroInstance->tempOwner;
-}
-
-void CBattleInterface::stackRemoved(CStack stack)
-{
-	delete creAnims[stack.ID];
-	creAnims.erase(stack.ID);
-}
-
-void CBattleInterface::stackActivated(int number)
-{
-	//givenCommand = NULL;
-	activeStack = number;
-	myTurn = true;
-	redrawBackgroundWithHexes(number);
-	bWait->block(vstd::contains(LOCPLINT->cb->battleGetStackByID(number)->state,WAITING)); //block waiting button if stack has been already waiting
-}
-
-void CBattleInterface::stackMoved(int number, int destHex, bool endMoving)
-{
-	bool startMoving = creAnims[number]->type==20;
-	//a few useful variables
-	int curStackPos = LOCPLINT->cb->battleGetPos(number);
-	int steps = creAnims[number]->framesInGroup(0)*getAnimSpeedMultiplier()-1;
-	int hexWbase = 44, hexHbase = 42;
-	bool twoTiles = LOCPLINT->cb->battleGetCreature(number).isDoubleWide();
-
-	if(startMoving) //animation of starting move; some units don't have this animation (ie. halberdier)
-	{
-		CGI->curh->hide();
-		for(int i=0; i<creAnims[number]->framesInGroup(20)*getAnimSpeedMultiplier()-1; ++i)
-		{
-			show();
-			CSDL_Ext::update();
-			SDL_framerateDelay(LOCPLINT->mainFPSmng);
-			if((animCount+1)%(4/animSpeed)==0)
-				creAnims[number]->incrementFrame();
-		}
-	}
-
-	int mutPos = BattleInfo::mutualPosition(curStackPos, destHex);
-
-	{
-		switch(mutPos) //reverse unit if necessary
-		{
-		case 0:	case 4:	case 5:
-			if(creDir[number] == true)
-				reverseCreature(number, curStackPos, twoTiles);
-			break;
-		case 1:	case 2: case 3:
-			if(creDir[number] == false)
-				reverseCreature(number, curStackPos, twoTiles);
-			break;
-		}
-		//moving instructions
-		creAnims[number]->setType(0);
-		float posX = creAnims[number]->pos.x, posY = creAnims[number]->pos.y; // for precise calculations ;]
-		for(int i=0; i<steps; ++i)
-		{
-			switch(mutPos)
-			{
-			case 0:
-				posX -= ((float)hexWbase)/(2.0f*steps);
-				creAnims[number]->pos.x = posX;
-				posY -= ((float)hexHbase)/((float)steps);
-				creAnims[number]->pos.y = posY;
-				break;
-			case 1:
-				posX += ((float)hexWbase)/(2.0f*steps);
-				creAnims[number]->pos.x = posX;
-				posY -= ((float)hexHbase)/((float)steps);
-				creAnims[number]->pos.y = posY;
-				break;
-			case 2:
-				posX += ((float)hexWbase)/((float)steps);
-				creAnims[number]->pos.x = posX;
-				break;
-			case 3:
-				posX += ((float)hexWbase)/(2.0f*steps);
-				creAnims[number]->pos.x = posX;
-				posY += ((float)hexHbase)/((float)steps);
-				creAnims[number]->pos.y = posY;
-				break;
-			case 4:
-				posX -= ((float)hexWbase)/(2.0f*steps);
-				creAnims[number]->pos.x = posX;
-				posY += ((float)hexHbase)/((float)steps);
-				creAnims[number]->pos.y = posY;
-				break;
-			case 5:
-				posX -= ((float)hexWbase)/((float)steps);
-				creAnims[number]->pos.x = posX;
-				break;
-			}
-			show();
-			CSDL_Ext::update();
-			SDL_framerateDelay(LOCPLINT->mainFPSmng);
-			if((animCount+1)%(4/animSpeed)==0)
-				creAnims[number]->incrementFrame();
-		}
-	}
-
-	if(endMoving) //animation of ending move
-	{
-		if(creAnims[number]->framesInGroup(21)!=0) // some units don't have this animation (ie. halberdier)
-		{
-			creAnims[number]->setType(21);
-			for(int i=0; i<creAnims[number]->framesInGroup(21)*getAnimSpeedMultiplier()-1; ++i)
-			{
-				show();
-				CSDL_Ext::update();
-				SDL_framerateDelay(LOCPLINT->mainFPSmng);
-				if((animCount+1)%(4/animSpeed)==0)
-					creAnims[number]->incrementFrame();
-			}
-		}
-		creAnims[number]->setType(2); //resetting to default
-		CGI->curh->show();
-	}
-
-	CStack curs = *LOCPLINT->cb->battleGetStackByID(number);
-	if(endMoving) //resetting to default
-	{
-		if(creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))
-			reverseCreature(number, destHex, twoTiles);	
-	}
-	std::pair <int, int> coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], curs.creature);
-	creAnims[number]->pos.x = coords.first;
-	if(!endMoving && twoTiles && (creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))) //big creature is reversed
-		creAnims[number]->pos.x -= 44;
-	creAnims[number]->pos.y = coords.second;
-}
-
-void CBattleInterface::stacksAreAttacked(std::vector<CBattleInterface::SStackAttackedInfo> attackedInfos)
-{
-	//restoring default state of battleWindow by calling show func
-	while(true)
-	{
-		show();
-		CSDL_Ext::update();
-		SDL_framerateDelay(LOCPLINT->mainFPSmng);
-
-		//checking break conditions
-		bool break_loop = true;
-		for(int g=0; g<attackedInfos.size(); ++g)
-		{
-			if(creAnims[attackedInfos[g].ID]->getType() != 2)
-				break_loop = false;
-			if(attackingInfo && attackingInfo->IDby == attackedInfos[g].IDby)
-				break_loop = false;
-		}
-		if(break_loop) break;
-	}
-	if(attackedInfos.size() == 1 && attackedInfos[0].byShooting) //delay hit animation
-	{
-		CStack attacker = *LOCPLINT->cb->battleGetStackByID(attackedInfos[0].IDby);
-		while(true)
-		{
-			bool found = false;
-			for(std::list<SProjectileInfo>::const_iterator it = projectiles.begin(); it!=projectiles.end(); ++it)
-			{
-				if(it->creID == attacker.creature->idNumber)
-				{
-					found = true;
-					break;
-				}
-			}
-			if(!found)
-				break;
-			else
-			{
-				show();
-				CSDL_Ext::update();
-				SDL_framerateDelay(LOCPLINT->mainFPSmng);
-			}
-		}
-	}
-	//initializing
-	std::map<int, int> animLengths;
-	std::map<int, int> increments;
-	int maxLen = 0;
-	for(int g=0; g<attackedInfos.size(); ++g)
-	{
-		int animLen;
-		if(attackedInfos[g].killed)
-		{
-			creAnims[attackedInfos[g].ID]->setType(5); //death
-			animLen = creAnims[attackedInfos[g].ID]->framesInGroup(5);
-		}
-		else
-		{
-			creAnims[attackedInfos[g].ID]->setType(3); //getting hit
-			animLen = creAnims[attackedInfos[g].ID]->framesInGroup(3);
-		}
-		animLengths.insert(std::make_pair(attackedInfos[g].ID, animLen));
-		increments.insert(std::make_pair(attackedInfos[g].ID, 0));
-		if(animLen > maxLen)
-		{
-			maxLen = animLen;
-		}
-	}
-	//main showing loop
-	bool continueLoop = true;
-	while(continueLoop)
-	{
-		show();
-		CSDL_Ext::update();
-		SDL_framerateDelay(LOCPLINT->mainFPSmng);
-		for(int g=0; g<attackedInfos.size(); ++g)
-		{
-			if((animCount+1)%(4/animSpeed)==0 && increments[attackedInfos[g].ID]<animLengths[attackedInfos[g].ID])
-			{
-				creAnims[attackedInfos[g].ID]->incrementFrame();
-				++(increments[attackedInfos[g].ID]);
-			}
-			if(increments[attackedInfos[g].ID]>=animLengths[attackedInfos[g].ID] && creAnims[attackedInfos[g].ID]->getType() == 3)
-				creAnims[attackedInfos[g].ID]->setType(2);
-		}
-		bool isAnotherOne = false; //if true, there is a stack whose hit/death anim must be continued
-		for(int g=0; g<attackedInfos.size(); ++g)
-		{
-			if(increments[attackedInfos[g].ID] < animLengths[attackedInfos[g].ID]-1)
-			{
-				isAnotherOne = true;
-				break;
-			}
-		}
-		if(!isAnotherOne)
-			continueLoop = false;
-	}
-	//restoring animType
-	for(int g=0; g<attackedInfos.size(); ++g)
-	{
-		if(creAnims[attackedInfos[g].ID]->getType() == 3)
-			creAnims[attackedInfos[g].ID]->setType(2);
-	}
-
-	//printing info to console
-	for(int g=0; g<attackedInfos.size(); ++g)
-	{
-		if(attackedInfos[g].IDby!=-1)
-			printConsoleAttacked(attackedInfos[g].ID, attackedInfos[g].dmg, attackedInfos[g].amountKilled, attackedInfos[g].IDby);
-	}
-}
-
-void CBattleInterface::stackAttacking(int ID, int dest)
-{
-	while(attackingInfo != NULL || creAnims[ID]->getType()!=2)
-	{
-		show();
-		CSDL_Ext::update();
-		SDL_framerateDelay(LOCPLINT->mainFPSmng);
-	}
-	CStack aStack = *LOCPLINT->cb->battleGetStackByID(ID); //attacking stack
-	int reversedShift = 0; //shift of attacking stack's position due to reversing
-	if(aStack.attackerOwned)
-	{
-		if(aStack.creature->isDoubleWide())
-		{
-			switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
-			{
-				case 0:
-					//reverseCreature(ID, aStack.position, true);
-					break;
-				case 1:
-					break;
-				case 2:
-					break;
-				case 3:
-					break;
-				case 4:
-					//reverseCreature(ID, aStack.position, true);
-					break;
-				case 5:
-					reverseCreature(ID, aStack.position, true);
-					break;
-				case -1:
-					if(BattleInfo::mutualPosition(aStack.position + (aStack.attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest
-					{
-						reverseCreature(ID, aStack.position, true);
-						reversedShift = (aStack.attackerOwned ? -1 : 1);
-					}
-					break;
-			}
-		}
-		else //else for if(aStack.creature->isDoubleWide())
-		{
-			switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
-			{
-				case 0:
-					reverseCreature(ID, aStack.position, true);
-					break;
-				case 1:
-					break;
-				case 2:
-					break;
-				case 3:
-					break;
-				case 4:
-					reverseCreature(ID, aStack.position, true);
-					break;
-				case 5:
-					reverseCreature(ID, aStack.position, true);
-					break;
-			}
-		}
-	}
-	else //if(aStack.attackerOwned)
-	{
-		if(aStack.creature->isDoubleWide())
-		{
-			switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
-			{
-				case 0:
-					//reverseCreature(ID, aStack.position, true);
-					break;
-				case 1:
-					break;
-				case 2:
-					reverseCreature(ID, aStack.position, true);
-					break;
-				case 3:
-					break;
-				case 4:
-					//reverseCreature(ID, aStack.position, true);
-					break;
-				case 5:
-					//reverseCreature(ID, aStack.position, true);
-					break;
-				case -1:
-					if(BattleInfo::mutualPosition(aStack.position + (aStack.attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest
-					{
-						reverseCreature(ID, aStack.position, true);
-						reversedShift = (aStack.attackerOwned ? -1 : 1);
-					}
-					break;
-			}
-		}
-		else //else for if(aStack.creature->isDoubleWide())
-		{
-			switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
-			{
-				case 0:
-					//reverseCreature(ID, aStack.position, true);
-					break;
-				case 1:
-					reverseCreature(ID, aStack.position, true);
-					break;
-				case 2:
-					reverseCreature(ID, aStack.position, true);
-					break;
-				case 3:
-					reverseCreature(ID, aStack.position, true);
-					break;
-				case 4:
-					//reverseCreature(ID, aStack.position, true);
-					break;
-				case 5:
-					//reverseCreature(ID, aStack.position, true);
-					break;
-			}
-		}
-	}
-
-	attackingInfo = new CAttHelper;
-	attackingInfo->dest = dest;
-	attackingInfo->frame = 0;
-	attackingInfo->hitCount = 0;
-	attackingInfo->ID = ID;
-	attackingInfo->IDby = LOCPLINT->cb->battleGetStackByPos(dest)->ID;
-	attackingInfo->reversing = false;
-	attackingInfo->posShiftDueToDist = reversedShift;
-	attackingInfo->shooting = false;
-
-	switch(BattleInfo::mutualPosition(aStack.position + reversedShift, dest)) //attack direction
-	{
-		case 0:
-			attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
-			break;
-		case 1:
-			attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
-			break;
-		case 2:
-			attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
-			break;
-		case 3:
-			attackingInfo->maxframe = creAnims[ID]->framesInGroup(13);
-			break;
-		case 4:
-			attackingInfo->maxframe = creAnims[ID]->framesInGroup(13);
-			break;
-		case 5:
-			attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
-			break;
-		default:
-			tlog1<<"Critical Error! Wrong dest in stackAttacking!"<<std::endl;
-	}
-}
-
-void CBattleInterface::newRound(int number)
-{
-	console->addText(CGI->generaltexth->allTexts[412]);
-}
-
-void CBattleInterface::giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional)
-{
-	BattleAction * ba = new BattleAction(); //is deleted in CPlayerInterface::activeStack()
-	ba->side = defendingHeroInstance ? (LOCPLINT->playerID == defendingHeroInstance->tempOwner) : false;
-	ba->actionType = action;
-	ba->destinationTile = tile;
-	ba->stackNumber = stack;
-	ba->additionalInfo = additional;
-	givenCommand->setn(ba);
-	myTurn = false;
-	activeStack = -1;
-}
-
-bool CBattleInterface::isTileAttackable(const int & number) const
-{
-	for(int b=0; b<shadedHexes.size(); ++b)
-	{
-		if(BattleInfo::mutualPosition(shadedHexes[b], number) != -1 || shadedHexes[b] == number)
-			return true;
-	}
-	return false;
-}
-
-void CBattleInterface::hexLclicked(int whichOne)
-{
-	if((whichOne%BFIELD_WIDTH)!=0 && (whichOne%BFIELD_WIDTH)!=(BFIELD_WIDTH-1)) //if player is trying to attack enemey unit or move creature stack
-	{
-		if(!myTurn)
-			return; //we are not permit to do anything
-		if(spellDestSelectMode)
-		{
-			//checking destination
-			bool allowCasting = true;
-			switch(spellSelMode)
-			{
-			case 1:
-				if(!LOCPLINT->cb->battleGetStackByPos(whichOne) || LOCPLINT->playerID != LOCPLINT->cb->battleGetStackByPos(whichOne)->owner )
-					allowCasting = false;
-				break;
-			case 2:
-				if(!LOCPLINT->cb->battleGetStackByPos(whichOne) || LOCPLINT->playerID == LOCPLINT->cb->battleGetStackByPos(whichOne)->owner )
-					allowCasting = false;
-				break;
-			case 3:
-				if(!LOCPLINT->cb->battleGetStackByPos(whichOne))
-					allowCasting = false;
-				break;
-			case 4: //TODO: implement this case
-				break;
-			}
-			//destination checked
-			if(allowCasting)
-			{
-				spellToCast->destinationTile = whichOne;
-				LOCPLINT->cb->battleMakeAction(spellToCast);
-				delete spellToCast;
-				spellToCast = NULL;
-				spellDestSelectMode = false;
-				CGI->curh->changeGraphic(1, 6);
-			}
-		}
-		else
-		{
-			CStack* dest = LOCPLINT->cb->battleGetStackByPos(whichOne); //creature at destination tile; -1 if there is no one
-			if(!dest || !dest->alive()) //no creature at that tile
-			{
-				if(std::find(shadedHexes.begin(),shadedHexes.end(),whichOne)!=shadedHexes.end())// and it's in our range
-				{
-					CGI->curh->changeGraphic(1, 6); //cursor should be changed
-					giveCommand(2,whichOne,activeStack);
-				}
-			}
-			else if(dest->owner != attackingHeroInstance->tempOwner
-				&& LOCPLINT->cb->battleCanShoot(activeStack, whichOne) ) //shooting
-			{
-				CGI->curh->changeGraphic(1, 6); //cursor should be changed
-				giveCommand(7,whichOne,activeStack);
-			}
-			else if(dest->owner != attackingHeroInstance->tempOwner) //attacking
-			{
-				switch(CGI->curh->number)
-				{
-				case 12:
-					giveCommand(6,whichOne + ( (whichOne/17)%2 ? 17 : 18 ),activeStack,whichOne);
-					break;
-				case 7:
-					giveCommand(6,whichOne + ( (whichOne/17)%2 ? 16 : 17 ),activeStack,whichOne);
-					break;
-				case 8:
-					giveCommand(6,whichOne - 1,activeStack,whichOne);
-					break;
-				case 9:
-					giveCommand(6,whichOne - ( (whichOne/17)%2 ? 18 : 17 ),activeStack,whichOne);
-					break;
-				case 10:
-					giveCommand(6,whichOne - ( (whichOne/17)%2 ? 17 : 16 ),activeStack,whichOne);
-					break;
-				case 11:
-					giveCommand(6,whichOne + 1,activeStack,whichOne);
-					break;
-				}
-				CGI->curh->changeGraphic(1, 6); //cursor should be changed
-			}
-		}
-	}
-}
-
-void CBattleInterface::stackIsShooting(int ID, int dest)
-{
-	if(attackingInfo != NULL)
-	{
-		return; //something went wrong
-	}
-	//projectile
-	float projectileAngle; //in radians; if positive, projectiles goes up
-	float straightAngle = 0.2f; //maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value)
-	int fromHex = LOCPLINT->cb->battleGetPos(ID);
-	projectileAngle = atan2(float(abs(dest - fromHex)/17), float(abs(dest - fromHex)%17));
-	if(fromHex < dest)
-		projectileAngle = -projectileAngle;
-
-	SProjectileInfo spi;
-	spi.creID = LOCPLINT->cb->battleGetStackByID(ID)->creature->idNumber;
-
-	spi.step = 0;
-	spi.frameNum = 0;
-	spi.spin = CGI->creh->idToProjectileSpin[spi.creID];
-
-	std::pair<int, int> xycoord = CBattleHex::getXYUnitAnim(LOCPLINT->cb->battleGetPos(ID), true, &LOCPLINT->cb->battleGetCreature(ID));
-	std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(dest, false, &LOCPLINT->cb->battleGetCreature(ID)); 
-	destcoord.first += 250; destcoord.second += 210; //TODO: find a better place to shoot
-
-	if(projectileAngle > straightAngle) //upper shot
-	{
-		spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetX;
-		spi.y = xycoord.second + 100 - LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetY;
-	}
-	else if(projectileAngle < -straightAngle) //lower shot
-	{
-		spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetX;
-		spi.y = xycoord.second + 150 - LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetY;
-	}
-	else //straight shot
-	{
-		spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetX;
-		spi.y = xycoord.second + 125 - LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetY;
-	}
-	spi.lastStep = sqrt((float)((destcoord.first - spi.x)*(destcoord.first - spi.x) + (destcoord.second - spi.y) * (destcoord.second - spi.y))) / 40;
-	if(spi.lastStep == 0)
-		spi.lastStep = 1;
-	spi.dx = (destcoord.first - spi.x) / spi.lastStep;
-	spi.dy = (destcoord.second - spi.y) / spi.lastStep;
-	//set starting frame
-	if(spi.spin)
-	{
-		spi.frameNum = 0;
-	}
-	else
-	{
-		spi.frameNum = ((M_PI/2.0f - projectileAngle) / (2.0f *M_PI) + 1/((float)(2*(idToProjectile[spi.creID]->ourImages.size()-1)))) * (idToProjectile[spi.creID]->ourImages.size()-1);
-	}
-	//set delay
-	spi.animStartDelay = CGI->creh->creatures[spi.creID].attackClimaxFrame;
-	projectiles.push_back(spi);
-
-	//attack aniamtion
-	attackingInfo = new CAttHelper;
-	attackingInfo->dest = dest;
-	attackingInfo->frame = 0;
-	attackingInfo->hitCount = 0;
-	attackingInfo->ID = ID;
-	attackingInfo->reversing = false;
-	attackingInfo->posShiftDueToDist = 0;
-	attackingInfo->shooting = true;
-	if(projectileAngle > straightAngle) //upper shot
-		attackingInfo->shootingGroup = 14;
-	else if(projectileAngle < -straightAngle) //lower shot
-		attackingInfo->shootingGroup = 16;
-	else //straight shot
-		attackingInfo->shootingGroup = 15;
-	attackingInfo->maxframe = creAnims[ID]->framesInGroup(attackingInfo->shootingGroup);
-}
-
-void CBattleInterface::battleFinished(const BattleResult& br)
-{
-	deactivate();
-	CGI->curh->changeGraphic(0,0);
-	
-	SDL_Rect temp_rect = genRect(561, 470, 165, 19);
-	resWindow = new CBattleReslutWindow(br, temp_rect, this);
-	resWindow->activate();
-}
-
-void CBattleInterface::spellCasted(SpellCasted * sc)
-{
-	std::vector< std::string > anims; //for magic arrow and ice bolt
-	switch(sc->id)
-	{
-	case 15: //magic arrow
-		{
-			//initialization of anims
-			anims.push_back("C20SPX0.DEF"); anims.push_back("C20SPX1.DEF"); anims.push_back("C20SPX2.DEF"); anims.push_back("C20SPX3.DEF"); anims.push_back("C20SPX4.DEF");
-		}
-	case 16: //ice bolt
-		{
-			if(anims.size() == 0) //initialiaztion of anims
-			{
-				anims.push_back("C08SPW0.DEF"); anims.push_back("C08SPW1.DEF"); anims.push_back("C08SPW2.DEF"); anims.push_back("C08SPW3.DEF"); anims.push_back("C08SPW4.DEF");
-			}
-		} //end of ice bolt only part
-		{ //common ice bolt and magic arrow part
-			//initial variables
-			std::string animToDisplay;
-			std::pair<int, int> srccoord = sc->side ? std::make_pair(770, 60) : std::make_pair(30, 60);
-			std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(sc->tile, !sc->side, LOCPLINT->cb->battleGetStackByPos(sc->tile)->creature); //position attacked by arrow
-			destcoord.first += 250; destcoord.second += 240;
-
-			//animation angle
-			float angle = atan2(float(destcoord.first - srccoord.first), float(destcoord.second - srccoord.second));
-
-			//choosing animation by angle
-			if(angle > 1.50)
-				animToDisplay = anims[0];
-			else if(angle > 1.20)
-				animToDisplay = anims[1];
-			else if(angle > 0.90)
-				animToDisplay = anims[2];
-			else if(angle > 0.60)
-				animToDisplay = anims[3];
-			else
-				animToDisplay = anims[4];
-
-			//displaying animation
-			int steps = sqrt((float)((destcoord.first - srccoord.first)*(destcoord.first - srccoord.first) + (destcoord.second - srccoord.second) * (destcoord.second - srccoord.second))) / 40;
-			if(steps <= 0)
-				steps = 1;
-
-			CDefHandler * animDef = CDefHandler::giveDef(animToDisplay);
-
-			int dx = (destcoord.first - srccoord.first - animDef->ourImages[0].bitmap->w)/steps, dy = (destcoord.second - srccoord.second - animDef->ourImages[0].bitmap->h)/steps;
-
-			for(int g=0; g<steps; ++g)
-			{
-				show();
-				SDL_Rect & srcr = animDef->ourImages[g%animDef->ourImages.size()].bitmap->clip_rect;
-				SDL_Rect dstr = genRect(srcr.h, srcr.w, srccoord.first + g*dx, srccoord.second + g*dy);
-				SDL_BlitSurface(animDef->ourImages[g%animDef->ourImages.size()].bitmap, &srcr, screen, &dstr);
-				CSDL_Ext::update();
-				SDL_framerateDelay(LOCPLINT->mainFPSmng);
-			}
-
-			int b=0;
-			break; //for 15 and 16 cases
-		}
-	case 17: //lightning bolt
-		{
-			displayEffect(1, sc->tile);
-			break;
-		}
-	case 18: //implosion
-		{
-			displayEffect(10, sc->tile);
-			break;
-		}
-	case 27: //shield
-		{
-			displayEffect(27, sc->tile);
-			break;
-		}
-	case 28: //air shield
-		{
-			displayEffect(2, sc->tile);
-			break;
-		}
-	case 41: //bless
-		{
-			displayEffect(36, sc->tile);
-			break;
-		}
-	case 42: //curse
-		{
-			displayEffect(40, sc->tile);
-			break;
-		}
-	case 43: //bloodlust
-		{
-			displayEffect(4, sc->tile); //TODO: give better animation for this spell
-			break;
-		}
-	case 45: //weakness
-		{
-			displayEffect(56, sc->tile); //TODO: give better animation for this spell
-			break;
-		}
-	case 46: //stone skin
-		{
-			displayEffect(54, sc->tile);
-			break;
-		}
-	case 48: //prayer
-		{
-			displayEffect(0, sc->tile);
-			break;
-		}
-	case 53: //haste
-		{
-			displayEffect(31, sc->tile);
-			break;
-		}
-	case 54: //slow
-		{
-			displayEffect(19, sc->tile);
-			break;
-		}
-	case 56: //frenzy
-		{
-			displayEffect(17, sc->tile);
-			break;
-		}
-	case 61: //forgetfulness
-		{
-			displayEffect(42, sc->tile);
-			break;
-		}
-	}
-}
-
-void CBattleInterface::castThisSpell(int spellID)
-{
-	BattleAction * ba = new BattleAction;
-	ba->actionType = 1;
-	ba->additionalInfo = spellID; //spell number
-	ba->destinationTile = -1;
-	ba->stackNumber = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? -1 : -2;
-	ba->side = defendingHeroInstance ? (LOCPLINT->playerID == defendingHeroInstance->tempOwner) : false;
-	spellToCast = ba;
-	spellDestSelectMode = true;
-
-	//choosing possible tragets
-	const CGHeroInstance * castingHero = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? attackingHeroInstance : attackingHeroInstance;
-	spellSelMode = 0;
-	if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET") != std::string::npos)
-	{
-		switch(CGI->spellh->spells[spellID].positiveness)
-		{
-		case -1 :
-			spellSelMode = 2;
-			break;
-		case 0:
-			spellSelMode = 3;
-			break;
-		case 1:
-			spellSelMode = 1;
-			break;
-		}
-	}
-	if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET_2") != std::string::npos)
-	{
-		if(castingHero && castingHero->getSpellSecLevel(spellID) < 3)
-		{
-			switch(CGI->spellh->spells[spellID].positiveness)
-			{
-			case -1 :
-				spellSelMode = 2;
-				break;
-			case 0:
-				spellSelMode = 3;
-				break;
-			case 1:
-				spellSelMode = 1;
-				break;
-			}
-		}
-		else
-		{
-			spellSelMode = -1;
-		}
-	}
-	CGI->curh->changeGraphic(3, 0); 
-}
-
-void CBattleInterface::displayEffect(ui32 effect, int destTile)
-{
-	if(graphics->battleACToDef[effect].size() != 0)
-	{
-		SBattleEffect be;
-		be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]);
-		be.frame = 0;
-		be.maxFrame = be.anim->ourImages.size();
-		be.x = 22 * ( ((destTile/BFIELD_WIDTH) + 1)%2 ) + 44 * (destTile % BFIELD_WIDTH) + 45;
-		be.y = 105 + 42 * (destTile/BFIELD_WIDTH);
-
-		if(effect != 1 && effect != 0)
-		{
-			be.x -= be.anim->ourImages[0].bitmap->w/2;
-			be.y -= be.anim->ourImages[0].bitmap->h/2;
-		}
-		else if(effect == 1)
-		{
-			be.x -= be.anim->ourImages[0].bitmap->w;
-			be.y -= be.anim->ourImages[0].bitmap->h;
-		}
-		else if (effect == 0)
-		{
-			be.x -= be.anim->ourImages[0].bitmap->w/2;
-			be.y -= be.anim->ourImages[0].bitmap->h;
-		}
-
-		battleEffects.push_back(be);
-	}
-	//battleEffects 
-}
-
-void CBattleInterface::setAnimSpeed(int set)
-{
-	animSpeed = set;
-}
-
-int CBattleInterface::getAnimSpeed() const
-{
-	return animSpeed;
-}
-
-float CBattleInterface::getAnimSpeedMultiplier() const
-{
-	switch(animSpeed)
-	{
-	case 1:
-		return 3.5f;
-	case 2:
-		return 2.2f;
-	case 4:
-		return 1.0f;
-	default:
-		return 0.0f;
-	}
-}
-
-void CBattleInterface::attackingShowHelper()
-{
-	if(attackingInfo && !attackingInfo->reversing)
-	{
-		if(attackingInfo->frame == 0)
-		{
-			CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
-			if(attackingInfo->shooting)
-			{
-				creAnims[attackingInfo->ID]->setType(attackingInfo->shootingGroup);
-			}
-			else
-			{
-				if(aStack.creature->isDoubleWide())
-				{
-					switch(BattleInfo::mutualPosition(aStack.position+attackingInfo->posShiftDueToDist, attackingInfo->dest)) //attack direction
-					{
-						case 0:
-							creAnims[attackingInfo->ID]->setType(11);
-							break;
-						case 1:
-							creAnims[attackingInfo->ID]->setType(11);
-							break;
-						case 2:
-							creAnims[attackingInfo->ID]->setType(12);
-							break;
-						case 3:
-							creAnims[attackingInfo->ID]->setType(13);
-							break;
-						case 4:
-							creAnims[attackingInfo->ID]->setType(13);
-							break;
-						case 5:
-							creAnims[attackingInfo->ID]->setType(12);
-							break;
-					}
-				}
-				else //else for if(aStack.creature->isDoubleWide())
-				{
-					switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
-					{
-						case 0:
-							creAnims[attackingInfo->ID]->setType(11);
-							break;
-						case 1:
-							creAnims[attackingInfo->ID]->setType(11);
-							break;
-						case 2:
-							creAnims[attackingInfo->ID]->setType(12);
-							break;
-						case 3:
-							creAnims[attackingInfo->ID]->setType(13);
-							break;
-						case 4:
-							creAnims[attackingInfo->ID]->setType(13);
-							break;
-						case 5:
-							creAnims[attackingInfo->ID]->setType(12);
-							break;
-					}
-				}
-			}
-		}
-		else if(attackingInfo->frame == (attackingInfo->maxframe - 1))
-		{
-			attackingInfo->reversing = true;
-
-			CStack* aStackp = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
-			if(aStackp == NULL)
-				return;
-			CStack aStack = *aStackp;
-			if(aStack.attackerOwned)
-			{
-				if(aStack.creature->isDoubleWide())
-				{
-					switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
-					{
-						case 0:
-							//reverseCreature(ID, aStack.position, true);
-							break;
-						case 1:
-							break;
-						case 2:
-							break;
-						case 3:
-							break;
-						case 4:
-							//reverseCreature(ID, aStack.position, true);
-							break;
-						case 5:
-							reverseCreature(attackingInfo->ID, aStack.position, true);
-							break;
-						case -1:
-							if(attackingInfo->posShiftDueToDist) //if reversing stack will make its position adjacent to dest
-							{
-								reverseCreature(attackingInfo->ID, aStack.position, true);
-							}
-							break;
-					}
-				}
-				else //else for if(aStack.creature->isDoubleWide())
-				{
-					switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
-					{
-						case 0:
-							reverseCreature(attackingInfo->ID, aStack.position, true);
-							break;
-						case 1:
-							break;
-						case 2:
-							break;
-						case 3:
-							break;
-						case 4:
-							reverseCreature(attackingInfo->ID, aStack.position, true);
-							break;
-						case 5:
-							reverseCreature(attackingInfo->ID, aStack.position, true);
-							break;
-					}
-				}
-			}
-			else //if(aStack.attackerOwned)
-			{
-				if(aStack.creature->isDoubleWide())
-				{
-					switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
-					{
-						case 0:
-							//reverseCreature(ID, aStack.position, true);
-							break;
-						case 1:
-							break;
-						case 2:
-							reverseCreature(attackingInfo->ID, aStack.position, true);
-							break;
-						case 3:
-							break;
-						case 4:
-							//reverseCreature(ID, aStack.position, true);
-							break;
-						case 5:
-							//reverseCreature(ID, aStack.position, true);
-							break;
-						case -1:
-							if(attackingInfo->posShiftDueToDist) //if reversing stack will make its position adjacent to dest
-							{
-								reverseCreature(attackingInfo->ID, aStack.position, true);
-							}
-							break;
-					}
-				}
-				else //else for if(aStack.creature->isDoubleWide())
-				{
-					switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
-					{
-						case 0:
-							//reverseCreature(ID, aStack.position, true);
-							break;
-						case 1:
-							reverseCreature(attackingInfo->ID, aStack.position, true);
-							break;
-						case 2:
-							reverseCreature(attackingInfo->ID, aStack.position, true);
-							break;
-						case 3:
-							reverseCreature(attackingInfo->ID, aStack.position, true);
-							break;
-						case 4:
-							//reverseCreature(ID, aStack.position, true);
-							break;
-						case 5:
-							//reverseCreature(ID, aStack.position, true);
-							break;
-					}
-				}
-			}
-			attackingInfo->reversing = false;
-			creAnims[attackingInfo->ID]->setType(2);
-			delete attackingInfo;
-			attackingInfo = NULL;
-		}
-		if(attackingInfo)
-		{
-			attackingInfo->hitCount++;
-			if(attackingInfo->hitCount%(4/animSpeed) == 0)
-				attackingInfo->frame++;
-		}
-	}
-}
-
-void CBattleInterface::redrawBackgroundWithHexes(int activeStack)
-{
-	shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(activeStack);
-
-	//preparating background graphic with hexes and shaded hexes
-	blitAt(background, 0, 0, backgroundWithHexes);
-	if(printCellBorders)
-		CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, backgroundWithHexes, NULL);
-
-	if(printStackRange)
-	{
-		for(int m=0; m<shadedHexes.size(); ++m) //rows
-		{
-			int i = shadedHexes[m]/17; //row
-			int j = shadedHexes[m]%17-1; //column
-			int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
-			int y = 86 + 42 * i;
-			CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, backgroundWithHexes, &genRect(cellShade->h, cellShade->w, x, y));
-		}
-	}
-}
-
-void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDby)
-{
-	char tabh[200];
-	CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby);
-	CStack defender = *LOCPLINT->cb->battleGetStackByID(ID);
-	int end = sprintf(tabh, CGI->generaltexth->allTexts[attacker.amount > 1 ? 377 : 376].c_str(),
-		(attacker.amount > 1 ? attacker.creature->namePl.c_str() : attacker.creature->nameSing.c_str()),
-		dmg);
-	if(killed > 0)
-	{
-		if(killed > 1)
-		{
-			sprintf(tabh + end, CGI->generaltexth->allTexts[379].c_str(), killed, defender.creature->namePl.c_str());
-		}
-		else //killed == 1
-		{
-			sprintf(tabh + end, CGI->generaltexth->allTexts[378].c_str(), defender.creature->nameSing.c_str());
-		}
-	}
-
-	console->addText(std::string(tabh));
-}
-
-void CBattleInterface::projectileShowHelper(SDL_Surface * to)
-{
-	if(to == NULL)
-		to = screen;
-	std::list< std::list<SProjectileInfo>::iterator > toBeDeleted;
-	for(std::list<SProjectileInfo>::iterator it=projectiles.begin(); it!=projectiles.end(); ++it)
-	{
-		if(it->animStartDelay>0)
-		{
-			--(it->animStartDelay);
-			continue;
-		}
-		SDL_Rect dst;
-		dst.h = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->h;
-		dst.w = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->w;
-		dst.x = it->x;
-		dst.y = it->y;
-		CSDL_Ext::blit8bppAlphaTo24bpp(idToProjectile[it->creID]->ourImages[it->frameNum].bitmap, NULL, to, &dst);
-		//actualizing projectile
-		++it->step;
-		if(it->step == it->lastStep)
-		{
-			toBeDeleted.insert(toBeDeleted.end(), it);
-		}
-		else
-		{
-			it->x += it->dx;
-			it->y += it->dy;
-			if(it->spin)
-			{
-				++(it->frameNum);
-				it->frameNum %= idToProjectile[it->creID]->ourImages.size();
-			}
-		}
-	}
-	for(std::list< std::list<SProjectileInfo>::iterator >::iterator it = toBeDeleted.begin(); it!= toBeDeleted.end(); ++it)
-	{
-		projectiles.erase(*it);
-	}
-}
-
-void CBattleHero::show(SDL_Surface *to)
-{
-	//animation of flag
-	if(flip)
-	{
-		CSDL_Ext::blit8bppAlphaTo24bpp(flag->ourImages[flagAnim].bitmap, NULL, screen, &genRect(flag->ourImages[flagAnim].bitmap->h, flag->ourImages[flagAnim].bitmap->w, 752, 39));
-	}
-	else
-	{
-		CSDL_Ext::blit8bppAlphaTo24bpp(flag->ourImages[flagAnim].bitmap, NULL, screen, &genRect(flag->ourImages[flagAnim].bitmap->h, flag->ourImages[flagAnim].bitmap->w, 31, 39));
-	}
-	++flagAnimCount;
-	if(flagAnimCount%4==0)
-	{
-		++flagAnim;
-		flagAnim %= flag->ourImages.size();
-	}
-	//animation of hero
-	int tick=-1;
-	for(int i=0; i<dh->ourImages.size(); ++i)
-	{
-		if(dh->ourImages[i].groupNumber==phase)
-			++tick;
-		if(tick==image)
-		{
-			SDL_Rect posb = pos;
-			CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb);
-			++image;
-			if(dh->ourImages[(i+1)%dh->ourImages.size()].groupNumber!=phase) //back to appropriate frame
-			{
-				image = 0;
-			}
-			break;
-		}
-	}
-}
-
-void CBattleHero::activate()
-{
-	ClickableL::activate();
-}
-void CBattleHero::deactivate()
-{
-	ClickableL::deactivate();
-}
-
-void CBattleHero::setPhase(int newPhase)
-{
-	phase = newPhase;
-	image = 0;
-}
-
-void CBattleHero::clickLeft(boost::logic::tribool down)
-{
-	if(!down && myHero)
-	{
-		for(int it=0; it<BFIELD_SIZE; ++it) //do nothing when any hex is hovered - hero's animation overlaps battlefield
-		{
-			if(myOwner->bfield[it].hovered && myOwner->bfield[it].strictHovered)
-				return;
-		}
-		CGI->curh->changeGraphic(0,0);
-		LOCPLINT->curint->deactivate();
-
-		CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, 90, 2), myHero);
-		spellWindow->activate();
-		LOCPLINT->objsToBlit.push_back(spellWindow);
-	}
-}
-
-CBattleHero::CBattleHero(const std::string & defName, int phaseG, int imageG, bool flipG, unsigned char player, const CGHeroInstance * hero, const CBattleInterface * owner): phase(phaseG), image(imageG), flip(flipG), flagAnim(0), myHero(hero), myOwner(owner)
-{
-	dh = CDefHandler::giveDef( defName );
-	for(int i=0; i<dh->ourImages.size(); ++i) //transforming images
-	{
-		if(flip)
-		{
-			SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap);
-			SDL_FreeSurface(dh->ourImages[i].bitmap);
-			dh->ourImages[i].bitmap = hlp;
-		}
-		dh->ourImages[i].bitmap = CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap);
-	}
-	dh->alphaTransformed = true;
-
-	if(flip)
-		flag = CDefHandler::giveDef("CMFLAGR.DEF");
-	else
-		flag = CDefHandler::giveDef("CMFLAGL.DEF");
-
-	//coloring flag and adding transparency
-	for(int i=0; i<flag->ourImages.size(); ++i)
-	{
-		flag->ourImages[i].bitmap = CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap);
-		graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player);
-	}
-}
-
-CBattleHero::~CBattleHero()
-{
-	delete dh;
-	delete flag;
-}
-
-std::pair<int, int> CBattleHex::getXYUnitAnim(const int & hexNum, const bool & attacker, const CCreature * creature)
-{
-	std::pair<int, int> ret = std::make_pair(-500, -500); //returned value
-	ret.second = -139 + 42 * (hexNum/BFIELD_WIDTH); //counting y
-	//counting x
-	if(attacker)
-	{
-		ret.first = -160 + 22 * ( ((hexNum/BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % BFIELD_WIDTH);
-	}
-	else
-	{
-		ret.first = -219 + 22 * ( ((hexNum/BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % BFIELD_WIDTH);
-	}
-	//shifting position for double - hex creatures
-	if(creature && creature->isDoubleWide())
-	{
-		if(attacker)
-		{
-			ret.first -= 42;
-		}
-		else
-		{
-			ret.first += 42;
-		}
-	}
-	//returning
-	return ret;
-}
-void CBattleHex::activate()
-{
-	Hoverable::activate();
-	MotionInterested::activate();
-	ClickableL::activate();
-	ClickableR::activate();
-}
-
-void CBattleHex::deactivate()
-{
-	Hoverable::deactivate();
-	MotionInterested::deactivate();
-	ClickableL::deactivate();
-	ClickableR::deactivate();
-}
-
-void CBattleHex::hover(bool on)
-{
-	hovered = on;
-	Hoverable::hover(on);
-	if(!on && setAlterText)
-	{
-		myInterface->console->alterTxt = std::string();
-		setAlterText = false;
-	}
-}
-
-CBattleHex::CBattleHex() : myNumber(-1), accesible(true), hovered(false), strictHovered(false), myInterface(NULL), setAlterText(false)
-{
-}
-
-void CBattleHex::mouseMoved(const SDL_MouseMotionEvent &sEvent)
-{
-	if(myInterface->cellShade)
-	{
-		if(CSDL_Ext::SDL_GetPixel(myInterface->cellShade, sEvent.x-pos.x, sEvent.y-pos.y) == 0) //hovered pixel is outside hex
-		{
-			strictHovered = false;
-		}
-		else //hovered pixel is inside hex
-		{
-			strictHovered = true;
-		}
-	}
-
-	if(hovered && strictHovered) //print attacked creature to console
-	{
-		if(myInterface->console->alterTxt.size() == 0 && LOCPLINT->cb->battleGetStack(myNumber) != -1 &&
-			LOCPLINT->cb->battleGetStackByPos(myNumber)->owner != LOCPLINT->playerID &&
-			LOCPLINT->cb->battleGetStackByPos(myNumber)->alive())
-		{
-			char tabh[160];
-			CStack attackedStack = *LOCPLINT->cb->battleGetStackByPos(myNumber);
-			const std::string & attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl;
-			sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str());
-			myInterface->console->alterTxt = std::string(tabh);
-			setAlterText = true;
-		}
-	}
-	else if(setAlterText)
-	{
-		myInterface->console->alterTxt = std::string();
-		setAlterText = false;
-	}
-}
-
-void CBattleHex::clickLeft(boost::logic::tribool down)
-{
-	if(!down && hovered && strictHovered) //we've been really clicked!
-	{
-		myInterface->hexLclicked(myNumber);
-	}
-}
-
-void CBattleHex::clickRight(boost::logic::tribool down)
-{
-	int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile
-	if(hovered && strictHovered && stID!=-1)
-	{
-		CStack myst = *LOCPLINT->cb->battleGetStackByID(stID); //stack info
-		if(!myst.alive()) return;
-		StackState *pom = NULL;
-		if(down)
-		{
-			pom = new StackState();
-			const CGHeroInstance *h = myst.owner == myInterface->attackingHeroInstance->tempOwner ? myInterface->attackingHeroInstance : myInterface->defendingHeroInstance;
-			if(h)
-			{
-				pom->attackBonus = h->getPrimSkillLevel(0);
-				pom->defenseBonus = h->getPrimSkillLevel(1);
-				pom->luck = h->getCurrentLuck();
-				pom->morale = h->getCurrentMorale();
-				pom->shotsLeft = myst.shots;
-				for(int vb=0; vb<myst.effects.size(); ++vb)
-				{
-					pom->effects.insert(myst.effects[vb].id);
-				}
-			}
-			pom->currentHealth = myst.firstHPleft;
-			(new CCreInfoWindow(myst.creature->idNumber,0,myst.amount,pom,boost::function<void()>(),boost::function<void()>(),NULL))
-					->activate();
-		}
-		delete pom;
-	}
-}
-
-CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt("")
-{
-}
-
-CBattleConsole::~CBattleConsole()
-{
-	texts.clear();
-}
-
-void CBattleConsole::show(SDL_Surface * to)
-{
-	if(alterTxt.size())
-	{
-		CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
-	}
-	else if(texts.size())
-	{
-		if(texts.size()==1)
-		{
-			CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
-		}
-		else
-		{
-			CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
-			CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 26, GEOR13, 80, zwykly, to);
-		}
-	}
-}
-
-bool CBattleConsole::addText(const std::string & text)
-{
-	if(text.size()>70)
-		return false; //text too long!
-	int firstInToken = 0;
-	for(int i=0; i<text.size(); ++i) //tokenize
-	{
-		if(text[i] == 10)
-		{
-			texts.push_back( text.substr(firstInToken, i-firstInToken) );
-			firstInToken = i+1;
-		}
-	}
-
-	texts.push_back( text.substr(firstInToken, text.size()) );
-	lastShown = texts.size()-1;
-	return true;
-}
-
-void CBattleConsole::eraseText(unsigned int pos)
-{
-	if(pos < texts.size())
-	{
-		texts.erase(texts.begin() + pos);
-		if(lastShown == texts.size())
-			--lastShown;
-	}
-}
-
-void CBattleConsole::changeTextAt(const std::string & text, unsigned int pos)
-{
-	if(pos >= texts.size()) //no such pos
-		return;
-	texts[pos] = text;
-}
-
-void CBattleConsole::scrollUp(unsigned int by)
-{
-	if(lastShown > by)
-		lastShown -= by;
-}
-
-void CBattleConsole::scrollDown(unsigned int by)
-{
-	if(lastShown + by < texts.size())
-		lastShown += by;
-}
-
-CBattleReslutWindow::CBattleReslutWindow(const BattleResult &br, const SDL_Rect & pos, const CBattleInterface * owner)
-{
-	this->pos = pos;
-	background = BitmapHandler::loadBitmap("CPRESULT.BMP", true);
-	graphics->blueToPlayersAdv(background, LOCPLINT->playerID);
-	SDL_Surface * pom = SDL_ConvertSurface(background, screen->format, screen->flags);
-	SDL_FreeSurface(background);
-	background = pom;
-	exit = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleReslutWindow::bExitf,this), 549, 524, "iok6432.def", SDLK_RETURN);
-
-	if(br.winner==0) //attacker won
-	{
-		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 60, 122, GEOR13, zwykly, background);
-		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 410, 122, GEOR13, zwykly, background);
-	}
-	else //if(br.winner==1)
-	{
-		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 60, 122, GEOR13, zwykly, background);
-		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 410, 122, GEOR13, zwykly, background);
-	}
-
-	
-	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[407], 235, 299, GEOR16, tytulowy, background);
-	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[408], 235, 329, GEOR16, zwykly, background);
-	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[409], 235, 426, GEOR16, zwykly, background);
-
-	std::string attackerName, defenderName;
-
-	if(owner->attackingHeroInstance) //a hero attacked
-	{
-		SDL_BlitSurface(graphics->portraitLarge[owner->attackingHeroInstance->portrait], NULL, background, &genRect(64, 58, 21, 38));
-		//setting attackerName
-		attackerName = owner->attackingHeroInstance->name;
-	}
-	else //a monster attacked
-	{
-		int bestMonsterID = -1;
-		int bestPower = 0;
-		for(std::map<si32,std::pair<ui32,si32> >::const_iterator it = owner->army1->slots.begin(); it!=owner->army1->slots.end(); ++it)
-		{
-			if( CGI->creh->creatures[it->first].AIValue > bestPower)
-			{
-				bestPower = CGI->creh->creatures[it->first].AIValue;
-				bestMonsterID = it->first;
-			}
-		}
-		SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &genRect(64, 58, 21, 38));
-		//setting attackerName
-		attackerName =  CGI->creh->creatures[bestMonsterID].namePl;
-	}
-	if(owner->defendingHeroInstance) //a hero defended
-	{
-		SDL_BlitSurface(graphics->portraitLarge[owner->defendingHeroInstance->portrait], NULL, background, &genRect(64, 58, 391, 38));
-		//setting defenderName
-		defenderName = owner->defendingHeroInstance->name;
-	}
-	else //a monster defended
-	{
-		int bestMonsterID = -1;
-		int bestPower = 0;
-		for(std::map<si32,std::pair<ui32,si32> >::const_iterator it = owner->army2->slots.begin(); it!=owner->army2->slots.end(); ++it)
-		{
-			if( CGI->creh->creatures[it->second.first].AIValue > bestPower)
-			{
-				bestPower = CGI->creh->creatures[it->second.first].AIValue;
-				bestMonsterID = it->second.first;
-			}
-		}
-		SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &genRect(64, 58, 391, 38));
-		//setting defenderName
-		defenderName =  CGI->creh->creatures[bestMonsterID].namePl;
-	}
-
-	//printing attacker and defender's names
-	CSDL_Ext::printAtMiddle(attackerName, 156, 44, GEOR16, zwykly, background);
-	CSDL_Ext::printAtMiddle(defenderName, 314, 44, GEOR16, zwykly, background);
-	//printing casualities
-	for(int step = 0; step < 2; ++step)
-	{
-		if(br.casualties[step].size()==0)
-		{
-			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[523], 235, 360 + 97*step, GEOR16, zwykly, background);
-		}
-		else
-		{
-			int xPos = 235 - (br.casualties[step].size()*32 + (br.casualties[step].size() - 1)*10)/2; //increment by 42 with each picture
-			int yPos = 344 + step*97;
-			for(std::set<std::pair<ui32,si32> >::const_iterator it=br.casualties[step].begin(); it!=br.casualties[step].end(); ++it)
-			{
-				blitAt(graphics->smallImgs[it->first], xPos, yPos, background);
-				std::stringstream amount;
-				amount<<it->second;
-				CSDL_Ext::printAtMiddle(amount.str(), xPos+16, yPos + 42, GEOR13, zwykly, background);
-				xPos += 42;
-			}
-		}
-	}
-	//printing result description
-	bool weAreAttacker = (LOCPLINT->playerID == owner->attackingHeroInstance->tempOwner);
-	switch(br.result)
-	{
-	case 0: //normal victory
-		if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won
-		{
-			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[304], 235, 235, GEOR13, zwykly, background);
-		}
-		else
-		{
-			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[311], 235, 235, GEOR13, zwykly, background);
-		}
-		break;
-	case 1: //flee
-		if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won
-		{
-			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[303], 235, 235, GEOR13, zwykly, background);
-		}
-		else
-		{
-			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[310], 235, 235, GEOR13, zwykly, background);
-		}
-		break;
-	case 2: //surrender
-		if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won
-		{
-			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[302], 235, 235, GEOR13, zwykly, background);
-		}
-		else
-		{
-			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[309], 235, 235, GEOR13, zwykly, background);
-		}
-		break;
-	}
-}
-
-CBattleReslutWindow::~CBattleReslutWindow()
-{
-	SDL_FreeSurface(background);
-}
-
-void CBattleReslutWindow::activate()
-{
-	LOCPLINT->showingDialog->set(true);
-	exit->activate();
-}
-
-void CBattleReslutWindow::deactivate()
-{
-	exit->deactivate();
-}
-
-void CBattleReslutWindow::show(SDL_Surface *to)
-{
-	//evaluating to
-	if(!to)
-		to = screen;
-
-	SDL_BlitSurface(background, NULL, to, &pos);
-	exit->show(to);
-}
-
-void CBattleReslutWindow::bExitf()
-{
-	LOCPLINT->battleResultQuited();
-}
-
-CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface *owner): myInt(owner)
-{
-	pos = position;
-	background = BitmapHandler::loadBitmap("comopbck.bmp", true);
-	graphics->blueToPlayersAdv(background, LOCPLINT->playerID);
-
-	viewGrid = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintCellBorders, owner, true), boost::bind(&CBattleInterface::setPrintCellBorders, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[427].first)(3,CGI->generaltexth->zelp[427].first), CGI->generaltexth->zelp[427].second, false, "sysopchk.def", NULL, 185, 140, false);
-	viewGrid->select(owner->printCellBorders);
-	movementShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintStackRange, owner, true), boost::bind(&CBattleInterface::setPrintStackRange, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[428].first)(3,CGI->generaltexth->zelp[428].first), CGI->generaltexth->zelp[428].second, false, "sysopchk.def", NULL, 185, 173, false);
-	movementShadow->select(owner->printStackRange);
-	mouseShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintMouseShadow, owner, true), boost::bind(&CBattleInterface::setPrintMouseShadow, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[429].first)(3,CGI->generaltexth->zelp[429].first), CGI->generaltexth->zelp[429].second, false, "sysopchk.def", NULL, 185, 207, false);
-	mouseShadow->select(owner->printMouseShadow);
-
-	animSpeeds = new CHighlightableButtonsGroup(0);
-	animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[422].first),CGI->generaltexth->zelp[422].second, "sysopb9.def",188, 309, 1);
-	animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[423].first),CGI->generaltexth->zelp[423].second, "sysob10.def",252, 309, 2);
-	animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[424].first),CGI->generaltexth->zelp[424].second, "sysob11.def",315, 309, 4);
-	animSpeeds->select(owner->getAnimSpeed(), 1);
-	animSpeeds->onChange = boost::bind(&CBattleInterface::setAnimSpeed, owner, _1);
-
-	setToDefault = new AdventureMapButton (CGI->generaltexth->zelp[392].first, CGI->generaltexth->zelp[392].second, boost::bind(&CBattleOptionsWindow::bDefaultf,this), 405, 443, "codefaul.def");
-	std::swap(setToDefault->imgs[0][0], setToDefault->imgs[0][1]);
-	exit = new AdventureMapButton (CGI->generaltexth->zelp[393].first, CGI->generaltexth->zelp[393].second, boost::bind(&CBattleOptionsWindow::bExitf,this), 516, 443, "soretrn.def",SDLK_RETURN);
-	std::swap(exit->imgs[0][0], exit->imgs[0][1]);
-
-	//printing texts to background
-	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[392], 240, 32, GEOR16, tytulowy, background); //window title
-	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[393], 122, 211, GEOR16, tytulowy, background); //animation speed
-	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[394], 122, 292, GEOR16, tytulowy, background); //music volume
-	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[395], 122, 358, GEOR16, tytulowy, background); //effects' volume
-	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[396], 353, 64, GEOR16, tytulowy, background); //auto - combat options
-	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[397], 353, 264, GEOR16, tytulowy, background); //creature info
-
-		//auto - combat options
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[398], 283, 87, GEOR16, zwykly, background); //creatures
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[399], 283, 117, GEOR16, zwykly, background); //spells
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[400], 283, 147, GEOR16, zwykly, background); //catapult
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[151], 283, 177, GEOR16, zwykly, background); //ballista
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[401], 283, 207, GEOR16, zwykly, background); //first aid tent
-
-		//creature info
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[402], 283, 286, GEOR16, zwykly, background); //all stats
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[403], 283, 316, GEOR16, zwykly, background); //spells only
-	
-		//general options
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[404], 61, 58, GEOR16, zwykly, background); //hex grid
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[405], 61, 91, GEOR16, zwykly, background); //movement shadow
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[406], 61, 124, GEOR16, zwykly, background); //cursor shadow
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[577], 61, 157, GEOR16, zwykly, background); //spellbook animation
-	//texts printed
-}
-
-CBattleOptionsWindow::~CBattleOptionsWindow()
-{
-	SDL_FreeSurface(background);
-
-	delete setToDefault;
-	delete exit;
-
-	delete viewGrid;
-	delete movementShadow;
-	delete animSpeeds;
-	delete mouseShadow;
-}
-
-void CBattleOptionsWindow::activate()
-{
-	setToDefault->activate();
-	exit->activate();
-	viewGrid->activate();
-	movementShadow->activate();
-	animSpeeds->activate();
-	mouseShadow->activate();
-}
-
-void CBattleOptionsWindow::deactivate()
-{
-	setToDefault->deactivate();
-	exit->deactivate();
-	viewGrid->deactivate();
-	movementShadow->deactivate();
-	animSpeeds->deactivate();
-	mouseShadow->deactivate();
-}
-
-void CBattleOptionsWindow::show(SDL_Surface *to)
-{
-	if(!to) //"evaluating" to
-		to = screen;
-
-	SDL_BlitSurface(background, NULL, to, &pos);
-
-	setToDefault->show(to);
-	exit->show(to);
-	viewGrid->show(to);
-	movementShadow->show(to);
-	animSpeeds->show(to);
-	mouseShadow->show(to);
-}
-
-void CBattleOptionsWindow::bDefaultf()
-{
-}
-
-void CBattleOptionsWindow::bExitf()
-{
-	deactivate();
-
-	for(int g=0; g<LOCPLINT->objsToBlit.size(); ++g)
-	{
-		if(dynamic_cast<CBattleOptionsWindow*>(LOCPLINT->objsToBlit[g]))
-		{
-			LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
-			break;
-		}
-	}
-
-	delete this;
-	LOCPLINT->curint->activate();
-}
+#include "CBattleInterface.h"
+#include "CGameInfo.h"
+#include "hch/CLodHandler.h"
+#include "SDL_Extensions.h"
+#include "CAdvmapInterface.h"
+#include "AdventureMapButton.h"
+#include "hch/CObjectHandler.h"
+#include "hch/CHeroHandler.h"
+#include "hch/CDefHandler.h"
+#include "hch/CSpellHandler.h"
+#include "CCursorHandler.h"
+#include "CCallback.h"
+#include "CGameState.h"
+#include "hch/CGeneralTextHandler.h"
+#include "client/CCreatureAnimation.h"
+#include "client/Graphics.h"
+#include "client/CSpellWindow.h"
+#include <queue>
+#include <sstream>
+#include "lib/CondSh.h"
+#include "lib/NetPacks.h"
+#include <boost/assign/list_of.hpp>
+#ifndef __GNUC__
+const double M_PI = 3.14159265358979323846;
+#else
+#define _USE_MATH_DEFINES
+#include <cmath>
+#endif
+
+extern SDL_Surface * screen;
+extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
+extern SDL_Color zwykly;
+
+struct CMP_stack2
+{
+	inline bool operator ()(const CStack& a, const CStack& b)
+	{
+		return (a.speed())>(b.speed());
+	}
+} cmpst2 ;
+
+CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2)
+: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL),
+	attackingInfo(NULL), myTurn(false), resWindow(NULL), showStackQueue(false), animSpeed(2), printStackRange(true),
+	printMouseShadow(true), spellDestSelectMode(false), spellToCast(NULL), previouslyHoveredHex(-1)
+{
+	strongInterest = true;
+	givenCommand = new CondSh<BattleAction *>(NULL);
+	//initializing armies
+	this->army1 = army1;
+	this->army2 = army2;
+	std::map<int, CStack> stacks = LOCPLINT->cb->battleGetStacks();
+	for(std::map<int, CStack>::iterator b=stacks.begin(); b!=stacks.end(); ++b)
+	{
+		std::pair <int, int> coords = CBattleHex::getXYUnitAnim(b->second.position, b->second.owner == attackingHeroInstance->tempOwner, b->second.creature);
+		creAnims[b->second.ID] = (new CCreatureAnimation(b->second.creature->animDefName));
+		creAnims[b->second.ID]->setType(2);
+		creAnims[b->second.ID]->pos = genRect(creAnims[b->second.ID]->fullHeight, creAnims[b->second.ID]->fullWidth, coords.first, coords.second);
+		creDir[b->second.ID] = b->second.owner==attackingHeroInstance->tempOwner;
+	}
+	//preparing menu background and terrain
+	std::vector< std::string > & backref = graphics->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ];
+	background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] );
+	menu = BitmapHandler::loadBitmap("CBAR.BMP");
+	graphics->blueToPlayersAdv(menu, hero1->tempOwner);
+
+	//preparing graphics for displaying amounts of creatures
+	amountNormal = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
+	CSDL_Ext::alphaTransform(amountNormal);
+	for(int g=0; g<amountNormal->format->palette->ncolors; ++g)
+	{
+		if((amountNormal->format->palette->colors+g)->b != 132 &&
+			(amountNormal->format->palette->colors+g)->g != 231 &&
+			(amountNormal->format->palette->colors+g)->r != 255) //it's not yellow border
+		{
+			(amountNormal->format->palette->colors+g)->r = (float)((amountNormal->format->palette->colors+g)->r) * 0.54f;
+			(amountNormal->format->palette->colors+g)->g = (float)((amountNormal->format->palette->colors+g)->g) * 0.19f;
+			(amountNormal->format->palette->colors+g)->b = (float)((amountNormal->format->palette->colors+g)->b) * 0.93f;
+		}
+	}
+	amountPositive = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
+	CSDL_Ext::alphaTransform(amountPositive);
+	for(int g=0; g<amountPositive->format->palette->ncolors; ++g)
+	{
+		if((amountPositive->format->palette->colors+g)->b != 132 &&
+			(amountPositive->format->palette->colors+g)->g != 231 &&
+			(amountPositive->format->palette->colors+g)->r != 255) //it's not yellow border
+		{
+			(amountPositive->format->palette->colors+g)->r = (float)((amountPositive->format->palette->colors+g)->r) * 0.18f;
+			(amountPositive->format->palette->colors+g)->g = (float)((amountPositive->format->palette->colors+g)->g) * 1.00f;
+			(amountPositive->format->palette->colors+g)->b = (float)((amountPositive->format->palette->colors+g)->b) * 0.18f;
+		}
+	}
+	amountNegative = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
+	CSDL_Ext::alphaTransform(amountNegative);
+	for(int g=0; g<amountNegative->format->palette->ncolors; ++g)
+	{
+		if((amountNegative->format->palette->colors+g)->b != 132 &&
+			(amountNegative->format->palette->colors+g)->g != 231 &&
+			(amountNegative->format->palette->colors+g)->r != 255) //it's not yellow border
+		{
+			(amountNegative->format->palette->colors+g)->r = (float)((amountNegative->format->palette->colors+g)->r) * 1.00f;
+			(amountNegative->format->palette->colors+g)->g = (float)((amountNegative->format->palette->colors+g)->g) * 0.18f;
+			(amountNegative->format->palette->colors+g)->b = (float)((amountNegative->format->palette->colors+g)->b) * 0.18f;
+		}
+	}
+	amountEffNeutral = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
+	CSDL_Ext::alphaTransform(amountNegative);
+	for(int g=0; g<amountNegative->format->palette->ncolors; ++g)
+	{
+		if((amountNegative->format->palette->colors+g)->b != 132 &&
+			(amountNegative->format->palette->colors+g)->g != 231 &&
+			(amountNegative->format->palette->colors+g)->r != 255) //it's not yellow border
+		{
+			(amountNegative->format->palette->colors+g)->r = (float)((amountNegative->format->palette->colors+g)->r) * 1.00f;
+			(amountNegative->format->palette->colors+g)->g = (float)((amountNegative->format->palette->colors+g)->g) * 1.00f;
+			(amountNegative->format->palette->colors+g)->b = (float)((amountNegative->format->palette->colors+g)->b) * 0.18f;
+		}
+	}
+
+	////blitting menu background and terrain
+	blitAt(background, 0, 0);
+	blitAt(menu, 0, 556);
+	CSDL_Ext::update();
+
+	//preparing buttons and console
+	bOptions = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bOptionsf,this), 3, 561, "icm003.def", SDLK_o);
+	bSurrender = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSurrenderf,this), 54, 561, "icm001.def", SDLK_s);
+	bFlee = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bFleef,this), 105, 561, "icm002.def", SDLK_r);
+	bAutofight  = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bAutofightf,this), 157, 561, "icm004.def", SDLK_a);
+	bSpell = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSpellf,this), 645, 561, "icm005.def", SDLK_c);
+	bWait = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bWaitf,this), 696, 561, "icm006.def", SDLK_w);
+	bDefence = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bDefencef,this), 747, 561, "icm007.def", SDLK_d);
+	bDefence->assignedKeys.insert(SDLK_SPACE);
+	bConsoleUp = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624, 561, "ComSlide.def", SDLK_UP);
+	bConsoleDown = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624, 580, "ComSlide.def", SDLK_DOWN);
+	bConsoleDown->bitmapOffset = 2;
+	console = new CBattleConsole();
+	console->pos.x = 211;
+	console->pos.y = 560;
+	console->pos.w = 406;
+	console->pos.h = 38;
+
+	//loading hero animations
+	if(hero1) // attacking hero
+	{
+		attackingHero = new CBattleHero(graphics->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner, hero1->tempOwner == LOCPLINT->playerID ? hero1 : NULL, this);
+		attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40, 0);
+	}
+	else
+	{
+		attackingHero = NULL;
+	}
+	if(hero2) // defending hero
+	{
+		defendingHero = new CBattleHero(graphics->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner, hero2->tempOwner == LOCPLINT->playerID ? hero2 : NULL, this);
+		defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690, 0);
+	}
+	else
+	{
+		defendingHero = NULL;
+	}
+
+	//preparing cells and hexes
+	cellBorder = BitmapHandler::loadBitmap("CCELLGRD.BMP");
+	CSDL_Ext::alphaTransform(cellBorder);
+	cellShade = BitmapHandler::loadBitmap("CCELLSHD.BMP");
+	CSDL_Ext::alphaTransform(cellShade);
+	for(int h=0; h<BFIELD_SIZE; ++h)
+	{
+		bfield[h].myNumber = h;
+
+		int x = 14 + ((h/BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(h%BFIELD_WIDTH);
+		int y = 86 + 42 * (h/BFIELD_WIDTH);
+		bfield[h].pos = genRect(cellShade->h, cellShade->w, x, y);
+		bfield[h].accesible = true;
+		bfield[h].myInterface = this;
+	}
+	//locking occupied positions on batlefield
+	for(std::map<int, CStack>::iterator it = stacks.begin(); it!=stacks.end(); ++it) //stacks gained at top of this function
+	{
+		bfield[it->second.position].accesible = false;
+	}
+
+	//loading projectiles for units
+	for(std::map<int, CStack>::iterator g = stacks.begin(); g != stacks.end(); ++g)
+	{
+		if(g->second.creature->isShooting() && CGI->creh->idToProjectile[g->second.creature->idNumber] != std::string())
+		{
+			idToProjectile[g->second.creature->idNumber] = CDefHandler::giveDef(CGI->creh->idToProjectile[g->second.creature->idNumber]);
+
+			if(idToProjectile[g->second.creature->idNumber]->ourImages.size() > 2) //add symmetric images
+			{
+				for(int k = idToProjectile[g->second.creature->idNumber]->ourImages.size()-2; k > 1; --k)
+				{
+					Cimage ci;
+					ci.bitmap = CSDL_Ext::rotate01(idToProjectile[g->second.creature->idNumber]->ourImages[k].bitmap);
+					ci.groupNumber = 0;
+					ci.imName = std::string();
+					idToProjectile[g->second.creature->idNumber]->ourImages.push_back(ci);
+				}
+			}
+			for(int s=0; s<idToProjectile[g->second.creature->idNumber]->ourImages.size(); ++s) //alpha transforming
+			{
+				CSDL_Ext::alphaTransform(idToProjectile[g->second.creature->idNumber]->ourImages[s].bitmap);
+			}
+		}
+	}
+
+
+	//preparing graphic with cell borders
+	cellBorders = CSDL_Ext::newSurface(background->w, background->h, cellBorder);
+	//copying palette
+	for(int g=0; g<cellBorder->format->palette->ncolors; ++g) //we assume that cellBorders->format->palette->ncolors == 256
+	{
+		cellBorders->format->palette->colors[g] = cellBorder->format->palette->colors[g];
+	}
+	//palette copied
+	for(int i=0; i<BFIELD_HEIGHT; ++i) //rows
+	{
+		for(int j=0; j<BFIELD_WIDTH-2; ++j) //columns
+		{
+			int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
+			int y = 86 + 42 * i;
+			for(int cellX = 0; cellX < cellBorder->w; ++cellX)
+			{
+				for(int cellY = 0; cellY < cellBorder->h; ++cellY)
+				{
+					if(y+cellY < cellBorders->h && x+cellX < cellBorders->w)
+						* ((Uint8*)cellBorders->pixels + (y+cellY) * cellBorders->pitch + (x+cellX)) |= * ((Uint8*)cellBorder->pixels + cellY * cellBorder->pitch + cellX);
+				}
+			}
+		}
+	}
+
+	backgroundWithHexes = CSDL_Ext::newSurface(background->w, background->h, screen);
+}
+
+CBattleInterface::~CBattleInterface()
+{
+	SDL_FreeSurface(background);
+	SDL_FreeSurface(menu);
+	SDL_FreeSurface(amountNormal);
+	SDL_FreeSurface(amountNegative);
+	SDL_FreeSurface(amountPositive);
+	SDL_FreeSurface(amountEffNeutral);
+	SDL_FreeSurface(cellBorders);
+	SDL_FreeSurface(backgroundWithHexes);
+	delete bOptions;
+	delete bSurrender;
+	delete bFlee;
+	delete bAutofight;
+	delete bSpell;
+	delete bWait;
+	delete bDefence;
+	delete bConsoleUp;
+	delete bConsoleDown;
+	delete console;
+	delete resWindow;
+	delete givenCommand;
+
+	delete attackingHero;
+	delete defendingHero;
+
+	SDL_FreeSurface(cellBorder);
+	SDL_FreeSurface(cellShade);
+
+	for(std::map< int, CCreatureAnimation * >::iterator g=creAnims.begin(); g!=creAnims.end(); ++g)
+		delete g->second;
+
+	for(std::map< int, CDefHandler * >::iterator g=idToProjectile.begin(); g!=idToProjectile.end(); ++g)
+		delete g->second;
+}
+
+void CBattleInterface::setPrintCellBorders(bool set)
+{
+	printCellBorders = set;
+	redrawBackgroundWithHexes(activeStack);
+}
+
+void CBattleInterface::setPrintStackRange(bool set)
+{
+	printStackRange = set;
+	redrawBackgroundWithHexes(activeStack);
+}
+
+void CBattleInterface::setPrintMouseShadow(bool set)
+{
+	printMouseShadow = set;
+}
+
+void CBattleInterface::activate()
+{
+	KeyInterested::activate();
+	MotionInterested::activate();
+	subInt = NULL;
+	bOptions->activate();
+	bSurrender->activate();
+	bFlee->activate();
+	bAutofight->activate();
+	bSpell->activate();
+	bWait->activate();
+	bDefence->activate();
+	bConsoleUp->activate();
+	bConsoleDown->activate();
+	for(int b=0; b<BFIELD_SIZE; ++b)
+	{
+		bfield[b].activate();
+	}
+	if(attackingHero)
+		attackingHero->activate();
+	if(defendingHero)
+		defendingHero->activate();
+}
+
+void CBattleInterface::deactivate()
+{
+	KeyInterested::deactivate();
+	MotionInterested::deactivate();
+	bOptions->deactivate();
+	bSurrender->deactivate();
+	bFlee->deactivate();
+	bAutofight->deactivate();
+	bSpell->deactivate();
+	bWait->deactivate();
+	bDefence->deactivate();
+	bConsoleUp->deactivate();
+	bConsoleDown->deactivate();
+	for(int b=0; b<BFIELD_SIZE; ++b)
+	{
+		bfield[b].deactivate();
+	}
+	if(attackingHero)
+		attackingHero->deactivate();
+	if(defendingHero)
+		defendingHero->deactivate();
+}
+
+void CBattleInterface::show(SDL_Surface * to)
+{
+	std::map<int, CStack> stacks = LOCPLINT->cb->battleGetStacks(); //used in a few places
+	++animCount;
+	if(!to) //"evaluating" to
+		to = screen;
+	
+	//printing background and hexes
+	if(activeStack != -1 && creAnims[activeStack]->getType() != 0) //show everything with range
+	{
+		blitAt(backgroundWithHexes, 0, 0, to);
+	}
+	else
+	{
+		//showing background
+		blitAt(background, 0, 0, to);
+		if(printCellBorders)
+		{
+			CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, to, NULL);
+		}
+	}
+	//printing hovered cell
+	if(printMouseShadow)
+	{
+		for(int b=0; b<BFIELD_SIZE; ++b)
+		{
+			if(bfield[b].strictHovered && bfield[b].hovered)
+			{
+				if(previouslyHoveredHex == -1) previouslyHoveredHex = b; //something to start with
+				if(currentlyHoveredHex == -1) currentlyHoveredHex = b; //something to start with
+				if(currentlyHoveredHex != b) //repair hover info
+				{
+					previouslyHoveredHex = currentlyHoveredHex;
+					currentlyHoveredHex = b;
+				}
+				//print shade
+				int x = 14 + ((b/BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(b%BFIELD_WIDTH);
+				int y = 86 + 42 * (b/BFIELD_WIDTH);
+				CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, to, &genRect(cellShade->h, cellShade->w, x, y));
+			}
+		}
+	}
+
+
+	//showing menu background and console
+	blitAt(menu, 0, 556, to);
+	console->show(to);
+
+	//showing buttons
+	bOptions->show(to);
+	bSurrender->show(to);
+	bFlee->show(to);
+	bAutofight->show(to);
+	bSpell->show(to);
+	bWait->show(to);
+	bDefence->show(to);
+	bConsoleUp->show(to);
+	bConsoleDown->show(to);
+
+	//showing hero animations
+	if(attackingHero)
+		attackingHero->show(to);
+	if(defendingHero)
+		defendingHero->show(to);
+
+	////showing units //a lot of work...
+	std::vector<int> stackAliveByHex[BFIELD_SIZE];
+	//double loop because dead stacks should be printed first
+	for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
+	{
+		if(j->second.alive())
+			stackAliveByHex[j->second.position].push_back(j->second.ID);
+	}
+	std::vector<int> stackDeadByHex[BFIELD_SIZE];
+	for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
+	{
+		if(!j->second.alive())
+			stackDeadByHex[j->second.position].push_back(j->second.ID);
+	}
+
+	attackingShowHelper(); // handle attack animation
+
+	for(int b=0; b<BFIELD_SIZE; ++b) //showing dead stacks
+	{
+		for(size_t v=0; v<stackDeadByHex[b].size(); ++v)
+		{
+			creAnims[stackDeadByHex[b][v]]->nextFrame(to, creAnims[stackDeadByHex[b][v]]->pos.x, creAnims[stackDeadByHex[b][v]]->pos.y, creDir[stackDeadByHex[b][v]], false, stackDeadByHex[b][v]==activeStack); //increment always when moving, never if stack died
+		}
+	}
+	for(int b=0; b<BFIELD_SIZE; ++b) //showing alive stacks
+	{
+		for(size_t v=0; v<stackAliveByHex[b].size(); ++v)
+		{
+			int animType = creAnims[stackAliveByHex[b][v]]->getType();
+			bool incrementFrame = (animCount%(4/animSpeed)==0) && animType!=0 && animType!=5 && animType!=20 && animType!=21 && animType!=3;
+			creAnims[stackAliveByHex[b][v]]->nextFrame(to, creAnims[stackAliveByHex[b][v]]->pos.x, creAnims[stackAliveByHex[b][v]]->pos.y, creDir[stackAliveByHex[b][v]], incrementFrame, stackAliveByHex[b][v]==activeStack); //increment always when moving, never if stack died
+			//printing amount
+			if(stacks[stackAliveByHex[b][v]].amount > 0) //don't print if stack is not alive
+			{
+				int xAdd = stacks[stackAliveByHex[b][v]].attackerOwned ? 220 : 202;
+
+				//blitting amoutn background box
+				SDL_Surface *amountBG = NULL;
+				if(stacks[stackAliveByHex[b][v]].effects.size() == 0)
+				{
+					amountBG = amountNormal;
+				}
+				else
+				{
+					int pos=0; //determining total positiveness of effects
+					for(int c=0; c<stacks[stackAliveByHex[b][v]].effects.size(); ++c)
+					{
+						pos += CGI->spellh->spells[ stacks[stackAliveByHex[b][v]].effects[c].id ].positiveness;
+					}
+					if(pos > 0)
+					{
+						amountBG = amountPositive;
+					}
+					else if(pos < 0)
+					{
+						amountBG = amountNegative;
+					}
+					else
+					{
+						amountBG = amountEffNeutral;
+					}
+				}
+				SDL_BlitSurface(amountBG, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + xAdd, creAnims[stackAliveByHex[b][v]]->pos.y + 260));
+				//blitting amount
+				std::stringstream ss;
+				ss<<stacks[stackAliveByHex[b][v]].amount;
+				CSDL_Ext::printAtMiddleWB(
+                                        ss.str(),
+                                        creAnims[stackAliveByHex[b][v]]->pos.x + xAdd + 14,
+                                        creAnims[stackAliveByHex[b][v]]->pos.y + 260 + 4,
+                                        GEOR13,
+                                        20,
+                                        zwykly,
+                                        to
+                );
+			}
+		}
+	}
+	//units shown
+	projectileShowHelper(to);//showing projectiles
+
+	//showing spell effects
+	if(battleEffects.size())
+	{
+		std::vector< std::list<SBattleEffect>::iterator > toErase;
+		for(std::list<SBattleEffect>::iterator it = battleEffects.begin(); it!=battleEffects.end(); ++it)
+		{
+			blitAt(it->anim->ourImages[(it->frame)%it->anim->ourImages.size()].bitmap, it->x, it->y, to);
+			++(it->frame);
+
+			if(it->frame == it->maxFrame) {
+				toErase.push_back(it);
+                        }
+		}
+		for(size_t b=0; b<toErase.size(); ++b)
+		{
+			delete toErase[b]->anim;
+			battleEffects.erase(toErase[b]);
+		}
+	}
+	
+
+	//showing queue of stacks
+	if(showStackQueue)
+	{
+		int xPos = screen->w/2 - ( stacks.size() * 37 )/2;
+		int yPos = 10;
+
+		std::vector<CStack> stacksSorted;
+		stacksSorted = LOCPLINT->cb->battleGetStackQueue();
+		int startFrom = -1;
+		for(size_t n=0; n<stacksSorted.size(); ++n)
+		{
+			if(stacksSorted[n].ID == activeStack)
+			{
+				startFrom = n;
+				break;
+			}
+		}
+		if(startFrom != -1)
+		{
+			for(size_t b=startFrom; b<stacksSorted.size()+startFrom; ++b)
+			{
+				SDL_BlitSurface(graphics->smallImgs[-2], NULL, to, &genRect(32, 32, xPos, yPos));
+				//printing colored border
+				for(int xFrom = xPos-1; xFrom<xPos+33; ++xFrom)
+				{
+					for(int yFrom = yPos-1; yFrom<yPos+33; ++yFrom)
+					{
+						if(xFrom == xPos-1 || xFrom == xPos+32 || yFrom == yPos-1 || yFrom == yPos+32)
+						{
+							SDL_Color pc;
+							if(stacksSorted[b % stacksSorted.size()].owner != 255)
+							{
+								pc = graphics->playerColors[stacksSorted[b % stacksSorted.size()].owner];
+							}
+							else
+							{
+								pc = *graphics->neutralColor;
+							}
+							CSDL_Ext::SDL_PutPixelWithoutRefresh(to, xFrom, yFrom, pc.r, pc.g, pc.b);
+						}
+					}
+				}
+				//colored border printed
+				SDL_BlitSurface(graphics->smallImgs[stacksSorted[b % stacksSorted.size()].creature->idNumber], NULL, to, &genRect(32, 32, xPos, yPos));
+				xPos += 37;
+			}
+		}
+	}
+
+	//showing window with result of battle
+	if(resWindow)
+	{
+		resWindow->show(to);
+	}
+}
+void CBattleInterface::keyPressed(const SDL_KeyboardEvent & key)
+{
+	if(key.keysym.sym == SDLK_q) {
+		showStackQueue = key.state==SDL_PRESSED;
+        }
+}
+void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
+{
+	if(activeStack>=0 && !spellDestSelectMode)
+	{
+		int myNumber = -1; //number of hovered tile
+		for(int g=0; g<BFIELD_SIZE; ++g)
+		{
+			if(bfield[g].hovered && bfield[g].strictHovered)
+			{
+				myNumber = g;
+				break;
+			}
+		}
+		if(myNumber == -1)
+		{
+			CGI->curh->changeGraphic(1, 6);
+		}
+		else
+		{
+			if(std::find(shadedHexes.begin(),shadedHexes.end(),myNumber) == shadedHexes.end())
+			{
+				CStack *shere = LOCPLINT->cb->battleGetStackByPos(myNumber);
+				if(shere)
+				{
+					if(shere->owner == LOCPLINT->playerID) //our stack
+						CGI->curh->changeGraphic(1,5);
+					else if(LOCPLINT->cb->battleCanShoot(activeStack,myNumber)) //we can shoot enemy
+						CGI->curh->changeGraphic(1,3);
+					else if(isTileAttackable(myNumber)) //available enemy (melee attackable)
+					{
+						int fromHex = previouslyHoveredHex;
+						if(fromHex!=-1 && fromHex%17!=0 && fromHex%17!=16 && vstd::contains(shadedHexes, fromHex))
+						{
+							switch(BattleInfo::mutualPosition(fromHex, myNumber))
+							{
+							case 0:
+								CGI->curh->changeGraphic(1,12);
+								break;
+							case 1:
+								CGI->curh->changeGraphic(1,7);
+								break;
+							case 2:
+								CGI->curh->changeGraphic(1,8);
+								break;
+							case 3:
+								CGI->curh->changeGraphic(1,9);
+								break;
+							case 4:
+								CGI->curh->changeGraphic(1,10);
+								break;
+							case 5:
+								CGI->curh->changeGraphic(1,11);
+								break;
+							}
+						}
+					}
+					else //unavailable enemy
+						CGI->curh->changeGraphic(1,0);
+				}
+				else //empty unavailable tile
+					CGI->curh->changeGraphic(1,0);
+			}
+			else //available tile
+			{
+				if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isFlying())
+					CGI->curh->changeGraphic(1,2);
+				else
+					CGI->curh->changeGraphic(1,1);
+			}
+		}
+	}
+	else if(spellDestSelectMode)
+	{
+		int myNumber = -1; //number of hovered tile
+		for(int g=0; g<BFIELD_SIZE; ++g)
+		{
+			if(bfield[g].hovered && bfield[g].strictHovered)
+			{
+				myNumber = g;
+				break;
+			}
+		}
+		if(myNumber == -1)
+		{
+			CGI->curh->changeGraphic(1, 0);
+		}
+		else
+		{
+			switch(spellSelMode)
+			{
+			case 0:
+				CGI->curh->changeGraphic(3, 0);
+				break;
+			case 1:
+				if(LOCPLINT->cb->battleGetStackByPos(myNumber) && LOCPLINT->playerID == LOCPLINT->cb->battleGetStackByPos(myNumber)->owner )
+					CGI->curh->changeGraphic(3, 0);
+				else
+					CGI->curh->changeGraphic(1, 0);
+				break;
+			case 2:
+				if(LOCPLINT->cb->battleGetStackByPos(myNumber) && LOCPLINT->playerID != LOCPLINT->cb->battleGetStackByPos(myNumber)->owner )
+					CGI->curh->changeGraphic(3, 0);
+				else
+					CGI->curh->changeGraphic(1, 0);
+				break;
+			case 3:
+				if(LOCPLINT->cb->battleGetStackByPos(myNumber))
+					CGI->curh->changeGraphic(3, 0);
+				else
+					CGI->curh->changeGraphic(1, 0);
+				break;
+			case 4: //TODO: implement this case
+				break;
+			}
+		}
+	}
+}
+
+bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
+{
+	if(creAnims[number]==NULL)
+		return false; //there is no such creature
+	creAnims[number]->setType(8);
+	int firstFrame = creAnims[number]->getFrame();
+	for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(8) + firstFrame - 1; ++g)
+	{
+		show();
+		CSDL_Ext::update();
+		SDL_framerateDelay(LOCPLINT->mainFPSmng);
+	}
+	creDir[number] = !creDir[number];
+
+	CStack curs = *LOCPLINT->cb->battleGetStackByID(number);
+	std::pair <int, int> coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs.creature);
+	creAnims[number]->pos.x = coords.first;
+	//creAnims[number]->pos.y = coords.second;
+
+	if(wideTrick && curs.creature->isDoubleWide())
+	{
+		if(curs.attackerOwned)
+		{
+			if(!creDir[number])
+				creAnims[number]->pos.x -= 44;
+		}
+		else
+		{
+			if(creDir[number])
+				creAnims[number]->pos.x += 44;
+		}
+	}
+
+	creAnims[number]->setType(7);
+	firstFrame = creAnims[number]->getFrame();
+	for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(7) + firstFrame - 1; ++g)
+	{
+		show();
+		CSDL_Ext::update();
+		SDL_framerateDelay(LOCPLINT->mainFPSmng);
+	}
+	creAnims[number]->setType(2);
+
+	return true;
+}
+
+void CBattleInterface::bOptionsf()
+{
+	CGI->curh->changeGraphic(0,0);
+	deactivate();
+
+	SDL_Rect temp_rect = genRect(431, 481, 160, 84);
+	CBattleOptionsWindow * optionsWin = new CBattleOptionsWindow(temp_rect, this);
+	optionsWin->activate();
+	LOCPLINT->objsToBlit.push_back(optionsWin);
+}
+
+void CBattleInterface::bSurrenderf()
+{
+}
+
+void CBattleInterface::bFleef()
+{
+	CFunctionList<void()> ony = boost::bind(&CBattleInterface::activate,this);
+	ony += boost::bind(&CBattleInterface::reallyFlee,this);
+	LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[28],std::vector<SComponent*>(), ony, boost::bind(&CBattleInterface::activate,this), true, false);
+}
+
+void CBattleInterface::reallyFlee()
+{
+	giveCommand(4,0,0);
+	CGI->curh->changeGraphic(0, 0);
+}
+
+void CBattleInterface::bAutofightf()
+{
+}
+
+void CBattleInterface::bSpellf()
+{
+	CGI->curh->changeGraphic(0,0);
+	deactivate();
+
+	const CGHeroInstance * chi = NULL;
+	if(attackingHeroInstance->tempOwner == LOCPLINT->playerID)
+		chi = attackingHeroInstance;
+	else
+		chi = defendingHeroInstance;
+	CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, 90, 2), chi);
+	spellWindow->activate();
+	LOCPLINT->objsToBlit.push_back(spellWindow);
+}
+
+void CBattleInterface::bWaitf()
+{
+	giveCommand(8,0,activeStack);
+}
+
+void CBattleInterface::bDefencef()
+{
+	giveCommand(3,0,activeStack);
+}
+
+void CBattleInterface::bConsoleUpf()
+{
+	console->scrollUp();
+}
+
+void CBattleInterface::bConsoleDownf()
+{
+	console->scrollDown();
+}
+
+void CBattleInterface::newStack(CStack stack)
+{
+	creAnims[stack.ID] = new CCreatureAnimation(stack.creature->animDefName);
+	creAnims[stack.ID]->setType(2);
+	creDir[stack.ID] = stack.owner==attackingHeroInstance->tempOwner;
+}
+
+void CBattleInterface::stackRemoved(CStack stack)
+{
+	delete creAnims[stack.ID];
+	creAnims.erase(stack.ID);
+}
+
+void CBattleInterface::stackActivated(int number)
+{
+	//givenCommand = NULL;
+	activeStack = number;
+	myTurn = true;
+	redrawBackgroundWithHexes(number);
+	bWait->block(vstd::contains(LOCPLINT->cb->battleGetStackByID(number)->state,WAITING)); //block waiting button if stack has been already waiting
+}
+
+void CBattleInterface::stackMoved(int number, int destHex, bool endMoving)
+{
+	bool startMoving = creAnims[number]->type==20;
+	//a few useful variables
+	int curStackPos = LOCPLINT->cb->battleGetPos(number);
+	int steps = creAnims[number]->framesInGroup(0)*getAnimSpeedMultiplier()-1;
+	int hexWbase = 44, hexHbase = 42;
+	bool twoTiles = LOCPLINT->cb->battleGetCreature(number).isDoubleWide();
+
+	if(startMoving) //animation of starting move; some units don't have this animation (ie. halberdier)
+	{
+		CGI->curh->hide();
+		for(int i=0; i<creAnims[number]->framesInGroup(20)*getAnimSpeedMultiplier()-1; ++i)
+		{
+			show();
+			CSDL_Ext::update();
+			SDL_framerateDelay(LOCPLINT->mainFPSmng);
+			if((animCount+1)%(4/animSpeed)==0)
+				creAnims[number]->incrementFrame();
+		}
+	}
+
+	int mutPos = BattleInfo::mutualPosition(curStackPos, destHex);
+
+	{
+		switch(mutPos) //reverse unit if necessary
+		{
+		case 0:	case 4:	case 5:
+			if(creDir[number] == true)
+				reverseCreature(number, curStackPos, twoTiles);
+			break;
+		case 1:	case 2: case 3:
+			if(creDir[number] == false)
+				reverseCreature(number, curStackPos, twoTiles);
+			break;
+		}
+		//moving instructions
+		creAnims[number]->setType(0);
+		float posX = creAnims[number]->pos.x, posY = creAnims[number]->pos.y; // for precise calculations ;]
+		for(int i=0; i<steps; ++i)
+		{
+			switch(mutPos)
+			{
+			case 0:
+				posX -= ((float)hexWbase)/(2.0f*steps);
+				creAnims[number]->pos.x = posX;
+				posY -= ((float)hexHbase)/((float)steps);
+				creAnims[number]->pos.y = posY;
+				break;
+			case 1:
+				posX += ((float)hexWbase)/(2.0f*steps);
+				creAnims[number]->pos.x = posX;
+				posY -= ((float)hexHbase)/((float)steps);
+				creAnims[number]->pos.y = posY;
+				break;
+			case 2:
+				posX += ((float)hexWbase)/((float)steps);
+				creAnims[number]->pos.x = posX;
+				break;
+			case 3:
+				posX += ((float)hexWbase)/(2.0f*steps);
+				creAnims[number]->pos.x = posX;
+				posY += ((float)hexHbase)/((float)steps);
+				creAnims[number]->pos.y = posY;
+				break;
+			case 4:
+				posX -= ((float)hexWbase)/(2.0f*steps);
+				creAnims[number]->pos.x = posX;
+				posY += ((float)hexHbase)/((float)steps);
+				creAnims[number]->pos.y = posY;
+				break;
+			case 5:
+				posX -= ((float)hexWbase)/((float)steps);
+				creAnims[number]->pos.x = posX;
+				break;
+			}
+			show();
+			CSDL_Ext::update();
+			SDL_framerateDelay(LOCPLINT->mainFPSmng);
+			if((animCount+1)%(4/animSpeed)==0)
+				creAnims[number]->incrementFrame();
+		}
+	}
+
+	if(endMoving) //animation of ending move
+	{
+		if(creAnims[number]->framesInGroup(21)!=0) // some units don't have this animation (ie. halberdier)
+		{
+			creAnims[number]->setType(21);
+			for(int i=0; i<creAnims[number]->framesInGroup(21)*getAnimSpeedMultiplier()-1; ++i)
+			{
+				show();
+				CSDL_Ext::update();
+				SDL_framerateDelay(LOCPLINT->mainFPSmng);
+				if((animCount+1)%(4/animSpeed)==0)
+					creAnims[number]->incrementFrame();
+			}
+		}
+		creAnims[number]->setType(2); //resetting to default
+		CGI->curh->show();
+	}
+
+	CStack curs = *LOCPLINT->cb->battleGetStackByID(number);
+	if(endMoving) //resetting to default
+	{
+		if(creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))
+			reverseCreature(number, destHex, twoTiles);	
+	}
+	std::pair <int, int> coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], curs.creature);
+	creAnims[number]->pos.x = coords.first;
+	if(!endMoving && twoTiles && (creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))) //big creature is reversed
+		creAnims[number]->pos.x -= 44;
+	creAnims[number]->pos.y = coords.second;
+}
+
+void CBattleInterface::stacksAreAttacked(std::vector<CBattleInterface::SStackAttackedInfo> attackedInfos)
+{
+	//restoring default state of battleWindow by calling show func
+	while(true)
+	{
+		show();
+		CSDL_Ext::update();
+		SDL_framerateDelay(LOCPLINT->mainFPSmng);
+
+		//checking break conditions
+		bool break_loop = true;
+		for(size_t g=0; g<attackedInfos.size(); ++g)
+		{
+			if(creAnims[attackedInfos[g].ID]->getType() != 2) {
+				break_loop = false;
+                        }
+			if(attackingInfo && attackingInfo->IDby == attackedInfos[g].IDby) {
+				break_loop = false;
+                        }
+		}
+		if(break_loop) break;
+	}
+	if(attackedInfos.size() == 1 && attackedInfos[0].byShooting) //delay hit animation
+	{
+		CStack attacker = *LOCPLINT->cb->battleGetStackByID(attackedInfos[0].IDby);
+		while(true)
+		{
+			bool found = false;
+			for(std::list<SProjectileInfo>::const_iterator it = projectiles.begin(); it!=projectiles.end(); ++it)
+			{
+				if(it->creID == attacker.creature->idNumber)
+				{
+					found = true;
+					break;
+				}
+			}
+			if(!found)
+				break;
+			else
+			{
+				show();
+				CSDL_Ext::update();
+				SDL_framerateDelay(LOCPLINT->mainFPSmng);
+			}
+		}
+	}
+	//initializing
+	std::map<int, int> animLengths;
+	std::map<int, int> increments;
+	int maxLen = 0;
+	for(size_t g=0; g<attackedInfos.size(); ++g)
+	{
+		int animLen;
+		if(attackedInfos[g].killed)
+		{
+			creAnims[attackedInfos[g].ID]->setType(5); //death
+			animLen = creAnims[attackedInfos[g].ID]->framesInGroup(5);
+		}
+		else
+		{
+			creAnims[attackedInfos[g].ID]->setType(3); //getting hit
+			animLen = creAnims[attackedInfos[g].ID]->framesInGroup(3);
+		}
+		animLengths.insert(std::make_pair(attackedInfos[g].ID, animLen));
+		increments.insert(std::make_pair(attackedInfos[g].ID, 0));
+		if(animLen > maxLen)
+		{
+			maxLen = animLen;
+		}
+	}
+	//main showing loop
+	bool continueLoop = true;
+	while(continueLoop)
+	{
+		show();
+		CSDL_Ext::update();
+		SDL_framerateDelay(LOCPLINT->mainFPSmng);
+		for(size_t g=0; g<attackedInfos.size(); ++g)
+		{
+			if((animCount+1)%(4/animSpeed)==0 && increments[attackedInfos[g].ID]<animLengths[attackedInfos[g].ID])
+			{
+				creAnims[attackedInfos[g].ID]->incrementFrame();
+				++(increments[attackedInfos[g].ID]);
+			}
+			if(increments[attackedInfos[g].ID]>=animLengths[attackedInfos[g].ID] && creAnims[attackedInfos[g].ID]->getType() == 3)
+				creAnims[attackedInfos[g].ID]->setType(2);
+		}
+		bool isAnotherOne = false; //if true, there is a stack whose hit/death anim must be continued
+		for(size_t g=0; g<attackedInfos.size(); ++g)
+		{
+			if(increments[attackedInfos[g].ID] < animLengths[attackedInfos[g].ID]-1)
+			{
+				isAnotherOne = true;
+				break;
+			}
+		}
+		if(!isAnotherOne)
+			continueLoop = false;
+	}
+	//restoring animType
+	for(size_t g=0; g<attackedInfos.size(); ++g)
+	{
+		if(creAnims[attackedInfos[g].ID]->getType() == 3)
+			creAnims[attackedInfos[g].ID]->setType(2);
+	}
+
+	//printing info to console
+	for(size_t g=0; g<attackedInfos.size(); ++g)
+	{
+		if(attackedInfos[g].IDby!=-1)
+			printConsoleAttacked(attackedInfos[g].ID, attackedInfos[g].dmg, attackedInfos[g].amountKilled, attackedInfos[g].IDby);
+	}
+}
+
+void CBattleInterface::stackAttacking(int ID, int dest)
+{
+	while(attackingInfo != NULL || creAnims[ID]->getType()!=2)
+	{
+		show();
+		CSDL_Ext::update();
+		SDL_framerateDelay(LOCPLINT->mainFPSmng);
+	}
+	CStack aStack = *LOCPLINT->cb->battleGetStackByID(ID); //attacking stack
+	int reversedShift = 0; //shift of attacking stack's position due to reversing
+	if(aStack.attackerOwned)
+	{
+		if(aStack.creature->isDoubleWide())
+		{
+			switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
+			{
+				case 0:
+					//reverseCreature(ID, aStack.position, true);
+					break;
+				case 1:
+					break;
+				case 2:
+					break;
+				case 3:
+					break;
+				case 4:
+					//reverseCreature(ID, aStack.position, true);
+					break;
+				case 5:
+					reverseCreature(ID, aStack.position, true);
+					break;
+				case -1:
+					if(BattleInfo::mutualPosition(aStack.position + (aStack.attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest
+					{
+						reverseCreature(ID, aStack.position, true);
+						reversedShift = (aStack.attackerOwned ? -1 : 1);
+					}
+					break;
+			}
+		}
+		else //else for if(aStack.creature->isDoubleWide())
+		{
+			switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
+			{
+				case 0:
+					reverseCreature(ID, aStack.position, true);
+					break;
+				case 1:
+					break;
+				case 2:
+					break;
+				case 3:
+					break;
+				case 4:
+					reverseCreature(ID, aStack.position, true);
+					break;
+				case 5:
+					reverseCreature(ID, aStack.position, true);
+					break;
+			}
+		}
+	}
+	else //if(aStack.attackerOwned)
+	{
+		if(aStack.creature->isDoubleWide())
+		{
+			switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
+			{
+				case 0:
+					//reverseCreature(ID, aStack.position, true);
+					break;
+				case 1:
+					break;
+				case 2:
+					reverseCreature(ID, aStack.position, true);
+					break;
+				case 3:
+					break;
+				case 4:
+					//reverseCreature(ID, aStack.position, true);
+					break;
+				case 5:
+					//reverseCreature(ID, aStack.position, true);
+					break;
+				case -1:
+					if(BattleInfo::mutualPosition(aStack.position + (aStack.attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest
+					{
+						reverseCreature(ID, aStack.position, true);
+						reversedShift = (aStack.attackerOwned ? -1 : 1);
+					}
+					break;
+			}
+		}
+		else //else for if(aStack.creature->isDoubleWide())
+		{
+			switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
+			{
+				case 0:
+					//reverseCreature(ID, aStack.position, true);
+					break;
+				case 1:
+					reverseCreature(ID, aStack.position, true);
+					break;
+				case 2:
+					reverseCreature(ID, aStack.position, true);
+					break;
+				case 3:
+					reverseCreature(ID, aStack.position, true);
+					break;
+				case 4:
+					//reverseCreature(ID, aStack.position, true);
+					break;
+				case 5:
+					//reverseCreature(ID, aStack.position, true);
+					break;
+			}
+		}
+	}
+
+	attackingInfo = new CAttHelper;
+	attackingInfo->dest = dest;
+	attackingInfo->frame = 0;
+	attackingInfo->hitCount = 0;
+	attackingInfo->ID = ID;
+	attackingInfo->IDby = LOCPLINT->cb->battleGetStackByPos(dest)->ID;
+	attackingInfo->reversing = false;
+	attackingInfo->posShiftDueToDist = reversedShift;
+	attackingInfo->shooting = false;
+
+	switch(BattleInfo::mutualPosition(aStack.position + reversedShift, dest)) //attack direction
+	{
+		case 0:
+			attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
+			break;
+		case 1:
+			attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
+			break;
+		case 2:
+			attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
+			break;
+		case 3:
+			attackingInfo->maxframe = creAnims[ID]->framesInGroup(13);
+			break;
+		case 4:
+			attackingInfo->maxframe = creAnims[ID]->framesInGroup(13);
+			break;
+		case 5:
+			attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
+			break;
+		default:
+			tlog1<<"Critical Error! Wrong dest in stackAttacking!"<<std::endl;
+	}
+}
+
+void CBattleInterface::newRound(int number)
+{
+	console->addText(CGI->generaltexth->allTexts[412]);
+}
+
+void CBattleInterface::giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional)
+{
+	BattleAction * ba = new BattleAction(); //is deleted in CPlayerInterface::activeStack()
+	ba->side = defendingHeroInstance ? (LOCPLINT->playerID == defendingHeroInstance->tempOwner) : false;
+	ba->actionType = action;
+	ba->destinationTile = tile;
+	ba->stackNumber = stack;
+	ba->additionalInfo = additional;
+	givenCommand->setn(ba);
+	myTurn = false;
+	activeStack = -1;
+}
+
+bool CBattleInterface::isTileAttackable(const int & number) const
+{
+	for(size_t b=0; b<shadedHexes.size(); ++b)
+	{
+		if(BattleInfo::mutualPosition(shadedHexes[b], number) != -1 || shadedHexes[b] == number)
+			return true;
+	}
+	return false;
+}
+
+void CBattleInterface::hexLclicked(int whichOne)
+{
+	if((whichOne%BFIELD_WIDTH)!=0 && (whichOne%BFIELD_WIDTH)!=(BFIELD_WIDTH-1)) //if player is trying to attack enemey unit or move creature stack
+	{
+		if(!myTurn)
+			return; //we are not permit to do anything
+		if(spellDestSelectMode)
+		{
+			//checking destination
+			bool allowCasting = true;
+			switch(spellSelMode)
+			{
+			case 1:
+				if(!LOCPLINT->cb->battleGetStackByPos(whichOne) || LOCPLINT->playerID != LOCPLINT->cb->battleGetStackByPos(whichOne)->owner )
+					allowCasting = false;
+				break;
+			case 2:
+				if(!LOCPLINT->cb->battleGetStackByPos(whichOne) || LOCPLINT->playerID == LOCPLINT->cb->battleGetStackByPos(whichOne)->owner )
+					allowCasting = false;
+				break;
+			case 3:
+				if(!LOCPLINT->cb->battleGetStackByPos(whichOne))
+					allowCasting = false;
+				break;
+			case 4: //TODO: implement this case
+				break;
+			}
+			//destination checked
+			if(allowCasting)
+			{
+				spellToCast->destinationTile = whichOne;
+				LOCPLINT->cb->battleMakeAction(spellToCast);
+				delete spellToCast;
+				spellToCast = NULL;
+				spellDestSelectMode = false;
+				CGI->curh->changeGraphic(1, 6);
+			}
+		}
+		else
+		{
+			CStack* dest = LOCPLINT->cb->battleGetStackByPos(whichOne); //creature at destination tile; -1 if there is no one
+			if(!dest || !dest->alive()) //no creature at that tile
+			{
+				if(std::find(shadedHexes.begin(),shadedHexes.end(),whichOne)!=shadedHexes.end())// and it's in our range
+				{
+					CGI->curh->changeGraphic(1, 6); //cursor should be changed
+					giveCommand(2,whichOne,activeStack);
+				}
+			}
+			else if(dest->owner != attackingHeroInstance->tempOwner
+				&& LOCPLINT->cb->battleCanShoot(activeStack, whichOne) ) //shooting
+			{
+				CGI->curh->changeGraphic(1, 6); //cursor should be changed
+				giveCommand(7,whichOne,activeStack);
+			}
+			else if(dest->owner != attackingHeroInstance->tempOwner) //attacking
+			{
+				switch(CGI->curh->number)
+				{
+				case 12:
+					giveCommand(6,whichOne + ( (whichOne/17)%2 ? 17 : 18 ),activeStack,whichOne);
+					break;
+				case 7:
+					giveCommand(6,whichOne + ( (whichOne/17)%2 ? 16 : 17 ),activeStack,whichOne);
+					break;
+				case 8:
+					giveCommand(6,whichOne - 1,activeStack,whichOne);
+					break;
+				case 9:
+					giveCommand(6,whichOne - ( (whichOne/17)%2 ? 18 : 17 ),activeStack,whichOne);
+					break;
+				case 10:
+					giveCommand(6,whichOne - ( (whichOne/17)%2 ? 17 : 16 ),activeStack,whichOne);
+					break;
+				case 11:
+					giveCommand(6,whichOne + 1,activeStack,whichOne);
+					break;
+				}
+				CGI->curh->changeGraphic(1, 6); //cursor should be changed
+			}
+		}
+	}
+}
+
+void CBattleInterface::stackIsShooting(int ID, int dest)
+{
+	if(attackingInfo != NULL)
+	{
+		return; //something went wrong
+	}
+	//projectile
+	float projectileAngle; //in radians; if positive, projectiles goes up
+	float straightAngle = 0.2f; //maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value)
+	int fromHex = LOCPLINT->cb->battleGetPos(ID);
+	projectileAngle = atan2(float(abs(dest - fromHex)/17), float(abs(dest - fromHex)%17));
+	if(fromHex < dest)
+		projectileAngle = -projectileAngle;
+
+	SProjectileInfo spi;
+	spi.creID = LOCPLINT->cb->battleGetStackByID(ID)->creature->idNumber;
+
+	spi.step = 0;
+	spi.frameNum = 0;
+	spi.spin = CGI->creh->idToProjectileSpin[spi.creID];
+
+	std::pair<int, int> xycoord = CBattleHex::getXYUnitAnim(LOCPLINT->cb->battleGetPos(ID), true, &LOCPLINT->cb->battleGetCreature(ID));
+	std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(dest, false, &LOCPLINT->cb->battleGetCreature(ID)); 
+	destcoord.first += 250; destcoord.second += 210; //TODO: find a better place to shoot
+
+	if(projectileAngle > straightAngle) //upper shot
+	{
+		spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetX;
+		spi.y = xycoord.second + 100 - LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetY;
+	}
+	else if(projectileAngle < -straightAngle) //lower shot
+	{
+		spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetX;
+		spi.y = xycoord.second + 150 - LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetY;
+	}
+	else //straight shot
+	{
+		spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetX;
+		spi.y = xycoord.second + 125 - LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetY;
+	}
+	spi.lastStep = sqrt((float)((destcoord.first - spi.x)*(destcoord.first - spi.x) + (destcoord.second - spi.y) * (destcoord.second - spi.y))) / 40;
+	if(spi.lastStep == 0)
+		spi.lastStep = 1;
+	spi.dx = (destcoord.first - spi.x) / spi.lastStep;
+	spi.dy = (destcoord.second - spi.y) / spi.lastStep;
+	//set starting frame
+	if(spi.spin)
+	{
+		spi.frameNum = 0;
+	}
+	else
+	{
+		spi.frameNum = ((M_PI/2.0f - projectileAngle) / (2.0f *M_PI) + 1/((float)(2*(idToProjectile[spi.creID]->ourImages.size()-1)))) * (idToProjectile[spi.creID]->ourImages.size()-1);
+	}
+	//set delay
+	spi.animStartDelay = CGI->creh->creatures[spi.creID].attackClimaxFrame;
+	projectiles.push_back(spi);
+
+	//attack aniamtion
+	attackingInfo = new CAttHelper;
+	attackingInfo->dest = dest;
+	attackingInfo->frame = 0;
+	attackingInfo->hitCount = 0;
+	attackingInfo->ID = ID;
+	attackingInfo->reversing = false;
+	attackingInfo->posShiftDueToDist = 0;
+	attackingInfo->shooting = true;
+	if(projectileAngle > straightAngle) //upper shot
+		attackingInfo->shootingGroup = 14;
+	else if(projectileAngle < -straightAngle) //lower shot
+		attackingInfo->shootingGroup = 16;
+	else //straight shot
+		attackingInfo->shootingGroup = 15;
+	attackingInfo->maxframe = creAnims[ID]->framesInGroup(attackingInfo->shootingGroup);
+}
+
+void CBattleInterface::battleFinished(const BattleResult& br)
+{
+	deactivate();
+	CGI->curh->changeGraphic(0,0);
+	
+	SDL_Rect temp_rect = genRect(561, 470, 165, 19);
+	resWindow = new CBattleReslutWindow(br, temp_rect, this);
+	resWindow->activate();
+}
+
+void CBattleInterface::spellCasted(SpellCasted * sc)
+{
+	std::vector< std::string > anims; //for magic arrow and ice bolt
+	switch(sc->id)
+	{
+	case 15: //magic arrow
+		{
+			//initialization of anims
+			anims.push_back("C20SPX0.DEF"); anims.push_back("C20SPX1.DEF"); anims.push_back("C20SPX2.DEF"); anims.push_back("C20SPX3.DEF"); anims.push_back("C20SPX4.DEF");
+		}
+	case 16: //ice bolt
+		{
+			if(anims.size() == 0) //initialiaztion of anims
+			{
+				anims.push_back("C08SPW0.DEF"); anims.push_back("C08SPW1.DEF"); anims.push_back("C08SPW2.DEF"); anims.push_back("C08SPW3.DEF"); anims.push_back("C08SPW4.DEF");
+			}
+		} //end of ice bolt only part
+		{ //common ice bolt and magic arrow part
+			//initial variables
+			std::string animToDisplay;
+			std::pair<int, int> srccoord = sc->side ? std::make_pair(770, 60) : std::make_pair(30, 60);
+			std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(sc->tile, !sc->side, LOCPLINT->cb->battleGetStackByPos(sc->tile)->creature); //position attacked by arrow
+			destcoord.first += 250; destcoord.second += 240;
+
+			//animation angle
+			float angle = atan2(float(destcoord.first - srccoord.first), float(destcoord.second - srccoord.second));
+
+			//choosing animation by angle
+			if(angle > 1.50)
+				animToDisplay = anims[0];
+			else if(angle > 1.20)
+				animToDisplay = anims[1];
+			else if(angle > 0.90)
+				animToDisplay = anims[2];
+			else if(angle > 0.60)
+				animToDisplay = anims[3];
+			else
+				animToDisplay = anims[4];
+
+			//displaying animation
+			int steps = sqrt((float)((destcoord.first - srccoord.first)*(destcoord.first - srccoord.first) + (destcoord.second - srccoord.second) * (destcoord.second - srccoord.second))) / 40;
+			if(steps <= 0)
+				steps = 1;
+
+			CDefHandler * animDef = CDefHandler::giveDef(animToDisplay);
+
+			int dx = (destcoord.first - srccoord.first - animDef->ourImages[0].bitmap->w)/steps, dy = (destcoord.second - srccoord.second - animDef->ourImages[0].bitmap->h)/steps;
+
+			for(int g=0; g<steps; ++g)
+			{
+				show();
+				SDL_Rect & srcr = animDef->ourImages[g%animDef->ourImages.size()].bitmap->clip_rect;
+				SDL_Rect dstr = genRect(srcr.h, srcr.w, srccoord.first + g*dx, srccoord.second + g*dy);
+				SDL_BlitSurface(animDef->ourImages[g%animDef->ourImages.size()].bitmap, &srcr, screen, &dstr);
+				CSDL_Ext::update();
+				SDL_framerateDelay(LOCPLINT->mainFPSmng);
+			}
+
+			int b=0; //TODO use me
+			break; //for 15 and 16 cases
+		}
+	case 17: //lightning bolt
+		{
+			displayEffect(1, sc->tile);
+			break;
+		}
+	case 18: //implosion
+		{
+			displayEffect(10, sc->tile);
+			break;
+		}
+	case 27: //shield
+		{
+			displayEffect(27, sc->tile);
+			break;
+		}
+	case 28: //air shield
+		{
+			displayEffect(2, sc->tile);
+			break;
+		}
+	case 41: //bless
+		{
+			displayEffect(36, sc->tile);
+			break;
+		}
+	case 42: //curse
+		{
+			displayEffect(40, sc->tile);
+			break;
+		}
+	case 43: //bloodlust
+		{
+			displayEffect(4, sc->tile); //TODO: give better animation for this spell
+			break;
+		}
+	case 45: //weakness
+		{
+			displayEffect(56, sc->tile); //TODO: give better animation for this spell
+			break;
+		}
+	case 46: //stone skin
+		{
+			displayEffect(54, sc->tile);
+			break;
+		}
+	case 48: //prayer
+		{
+			displayEffect(0, sc->tile);
+			break;
+		}
+	case 53: //haste
+		{
+			displayEffect(31, sc->tile);
+			break;
+		}
+	case 54: //slow
+		{
+			displayEffect(19, sc->tile);
+			break;
+		}
+	case 56: //frenzy
+		{
+			displayEffect(17, sc->tile);
+			break;
+		}
+	case 61: //forgetfulness
+		{
+			displayEffect(42, sc->tile);
+			break;
+		}
+	}
+}
+
+void CBattleInterface::castThisSpell(int spellID)
+{
+	BattleAction * ba = new BattleAction;
+	ba->actionType = 1;
+	ba->additionalInfo = spellID; //spell number
+	ba->destinationTile = -1;
+	ba->stackNumber = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? -1 : -2;
+	ba->side = defendingHeroInstance ? (LOCPLINT->playerID == defendingHeroInstance->tempOwner) : false;
+	spellToCast = ba;
+	spellDestSelectMode = true;
+
+	//choosing possible tragets
+	const CGHeroInstance * castingHero = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? attackingHeroInstance : attackingHeroInstance;
+	spellSelMode = 0;
+	if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET") != std::string::npos)
+	{
+		switch(CGI->spellh->spells[spellID].positiveness)
+		{
+		case -1 :
+			spellSelMode = 2;
+			break;
+		case 0:
+			spellSelMode = 3;
+			break;
+		case 1:
+			spellSelMode = 1;
+			break;
+		}
+	}
+	if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET_2") != std::string::npos)
+	{
+		if(castingHero && castingHero->getSpellSecLevel(spellID) < 3)
+		{
+			switch(CGI->spellh->spells[spellID].positiveness)
+			{
+			case -1 :
+				spellSelMode = 2;
+				break;
+			case 0:
+				spellSelMode = 3;
+				break;
+			case 1:
+				spellSelMode = 1;
+				break;
+			}
+		}
+		else
+		{
+			spellSelMode = -1;
+		}
+	}
+	CGI->curh->changeGraphic(3, 0); 
+}
+
+void CBattleInterface::displayEffect(ui32 effect, int destTile)
+{
+	if(graphics->battleACToDef[effect].size() != 0)
+	{
+		SBattleEffect be;
+		be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]);
+		be.frame = 0;
+		be.maxFrame = be.anim->ourImages.size();
+		be.x = 22 * ( ((destTile/BFIELD_WIDTH) + 1)%2 ) + 44 * (destTile % BFIELD_WIDTH) + 45;
+		be.y = 105 + 42 * (destTile/BFIELD_WIDTH);
+
+		if(effect != 1 && effect != 0)
+		{
+			be.x -= be.anim->ourImages[0].bitmap->w/2;
+			be.y -= be.anim->ourImages[0].bitmap->h/2;
+		}
+		else if(effect == 1)
+		{
+			be.x -= be.anim->ourImages[0].bitmap->w;
+			be.y -= be.anim->ourImages[0].bitmap->h;
+		}
+		else if (effect == 0)
+		{
+			be.x -= be.anim->ourImages[0].bitmap->w/2;
+			be.y -= be.anim->ourImages[0].bitmap->h;
+		}
+
+		battleEffects.push_back(be);
+	}
+	//battleEffects 
+}
+
+void CBattleInterface::setAnimSpeed(int set)
+{
+	animSpeed = set;
+}
+
+int CBattleInterface::getAnimSpeed() const
+{
+	return animSpeed;
+}
+
+float CBattleInterface::getAnimSpeedMultiplier() const
+{
+	switch(animSpeed)
+	{
+	case 1:
+		return 3.5f;
+	case 2:
+		return 2.2f;
+	case 4:
+		return 1.0f;
+	default:
+		return 0.0f;
+	}
+}
+
+void CBattleInterface::attackingShowHelper()
+{
+	if(attackingInfo && !attackingInfo->reversing)
+	{
+		if(attackingInfo->frame == 0)
+		{
+			CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
+			if(attackingInfo->shooting)
+			{
+				creAnims[attackingInfo->ID]->setType(attackingInfo->shootingGroup);
+			}
+			else
+			{
+				if(aStack.creature->isDoubleWide())
+				{
+					switch(BattleInfo::mutualPosition(aStack.position+attackingInfo->posShiftDueToDist, attackingInfo->dest)) //attack direction
+					{
+						case 0:
+							creAnims[attackingInfo->ID]->setType(11);
+							break;
+						case 1:
+							creAnims[attackingInfo->ID]->setType(11);
+							break;
+						case 2:
+							creAnims[attackingInfo->ID]->setType(12);
+							break;
+						case 3:
+							creAnims[attackingInfo->ID]->setType(13);
+							break;
+						case 4:
+							creAnims[attackingInfo->ID]->setType(13);
+							break;
+						case 5:
+							creAnims[attackingInfo->ID]->setType(12);
+							break;
+					}
+				}
+				else //else for if(aStack.creature->isDoubleWide())
+				{
+					switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
+					{
+						case 0:
+							creAnims[attackingInfo->ID]->setType(11);
+							break;
+						case 1:
+							creAnims[attackingInfo->ID]->setType(11);
+							break;
+						case 2:
+							creAnims[attackingInfo->ID]->setType(12);
+							break;
+						case 3:
+							creAnims[attackingInfo->ID]->setType(13);
+							break;
+						case 4:
+							creAnims[attackingInfo->ID]->setType(13);
+							break;
+						case 5:
+							creAnims[attackingInfo->ID]->setType(12);
+							break;
+					}
+				}
+			}
+		}
+		else if(attackingInfo->frame == (attackingInfo->maxframe - 1))
+		{
+			attackingInfo->reversing = true;
+
+			CStack* aStackp = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
+			if(aStackp == NULL)
+				return;
+			CStack aStack = *aStackp;
+			if(aStack.attackerOwned)
+			{
+				if(aStack.creature->isDoubleWide())
+				{
+					switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
+					{
+						case 0:
+							//reverseCreature(ID, aStack.position, true);
+							break;
+						case 1:
+							break;
+						case 2:
+							break;
+						case 3:
+							break;
+						case 4:
+							//reverseCreature(ID, aStack.position, true);
+							break;
+						case 5:
+							reverseCreature(attackingInfo->ID, aStack.position, true);
+							break;
+						case -1:
+							if(attackingInfo->posShiftDueToDist) //if reversing stack will make its position adjacent to dest
+							{
+								reverseCreature(attackingInfo->ID, aStack.position, true);
+							}
+							break;
+					}
+				}
+				else //else for if(aStack.creature->isDoubleWide())
+				{
+					switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
+					{
+						case 0:
+							reverseCreature(attackingInfo->ID, aStack.position, true);
+							break;
+						case 1:
+							break;
+						case 2:
+							break;
+						case 3:
+							break;
+						case 4:
+							reverseCreature(attackingInfo->ID, aStack.position, true);
+							break;
+						case 5:
+							reverseCreature(attackingInfo->ID, aStack.position, true);
+							break;
+					}
+				}
+			}
+			else //if(aStack.attackerOwned)
+			{
+				if(aStack.creature->isDoubleWide())
+				{
+					switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
+					{
+						case 0:
+							//reverseCreature(ID, aStack.position, true);
+							break;
+						case 1:
+							break;
+						case 2:
+							reverseCreature(attackingInfo->ID, aStack.position, true);
+							break;
+						case 3:
+							break;
+						case 4:
+							//reverseCreature(ID, aStack.position, true);
+							break;
+						case 5:
+							//reverseCreature(ID, aStack.position, true);
+							break;
+						case -1:
+							if(attackingInfo->posShiftDueToDist) //if reversing stack will make its position adjacent to dest
+							{
+								reverseCreature(attackingInfo->ID, aStack.position, true);
+							}
+							break;
+					}
+				}
+				else //else for if(aStack.creature->isDoubleWide())
+				{
+					switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
+					{
+						case 0:
+							//reverseCreature(ID, aStack.position, true);
+							break;
+						case 1:
+							reverseCreature(attackingInfo->ID, aStack.position, true);
+							break;
+						case 2:
+							reverseCreature(attackingInfo->ID, aStack.position, true);
+							break;
+						case 3:
+							reverseCreature(attackingInfo->ID, aStack.position, true);
+							break;
+						case 4:
+							//reverseCreature(ID, aStack.position, true);
+							break;
+						case 5:
+							//reverseCreature(ID, aStack.position, true);
+							break;
+					}
+				}
+			}
+			attackingInfo->reversing = false;
+			creAnims[attackingInfo->ID]->setType(2);
+			delete attackingInfo;
+			attackingInfo = NULL;
+		}
+		if(attackingInfo)
+		{
+			attackingInfo->hitCount++;
+			if(attackingInfo->hitCount%(4/animSpeed) == 0)
+				attackingInfo->frame++;
+		}
+	}
+}
+
+void CBattleInterface::redrawBackgroundWithHexes(int activeStack)
+{
+	shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(activeStack);
+
+	//preparating background graphic with hexes and shaded hexes
+	blitAt(background, 0, 0, backgroundWithHexes);
+	if(printCellBorders)
+		CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, backgroundWithHexes, NULL);
+
+	if(printStackRange)
+	{
+		for(size_t m=0; m<shadedHexes.size(); ++m) //rows
+		{
+			int i = shadedHexes[m]/17; //row
+			int j = shadedHexes[m]%17-1; //column
+			int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
+			int y = 86 + 42 * i;
+			CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, backgroundWithHexes, &genRect(cellShade->h, cellShade->w, x, y));
+		}
+	}
+}
+
+void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDby)
+{
+	char tabh[200];
+	CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby);
+	CStack defender = *LOCPLINT->cb->battleGetStackByID(ID);
+	int end = sprintf(tabh, CGI->generaltexth->allTexts[attacker.amount > 1 ? 377 : 376].c_str(),
+		(attacker.amount > 1 ? attacker.creature->namePl.c_str() : attacker.creature->nameSing.c_str()),
+		dmg);
+	if(killed > 0)
+	{
+		if(killed > 1)
+		{
+			sprintf(tabh + end, CGI->generaltexth->allTexts[379].c_str(), killed, defender.creature->namePl.c_str());
+		}
+		else //killed == 1
+		{
+			sprintf(tabh + end, CGI->generaltexth->allTexts[378].c_str(), defender.creature->nameSing.c_str());
+		}
+	}
+
+	console->addText(std::string(tabh));
+}
+
+void CBattleInterface::projectileShowHelper(SDL_Surface * to)
+{
+	if(to == NULL)
+		to = screen;
+	std::list< std::list<SProjectileInfo>::iterator > toBeDeleted;
+	for(std::list<SProjectileInfo>::iterator it=projectiles.begin(); it!=projectiles.end(); ++it)
+	{
+		if(it->animStartDelay>0)
+		{
+			--(it->animStartDelay);
+			continue;
+		}
+		SDL_Rect dst;
+		dst.h = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->h;
+		dst.w = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->w;
+		dst.x = it->x;
+		dst.y = it->y;
+		CSDL_Ext::blit8bppAlphaTo24bpp(idToProjectile[it->creID]->ourImages[it->frameNum].bitmap, NULL, to, &dst);
+		//actualizing projectile
+		++it->step;
+		if(it->step == it->lastStep)
+		{
+			toBeDeleted.insert(toBeDeleted.end(), it);
+		}
+		else
+		{
+			it->x += it->dx;
+			it->y += it->dy;
+			if(it->spin)
+			{
+				++(it->frameNum);
+				it->frameNum %= idToProjectile[it->creID]->ourImages.size();
+			}
+		}
+	}
+	for(std::list< std::list<SProjectileInfo>::iterator >::iterator it = toBeDeleted.begin(); it!= toBeDeleted.end(); ++it)
+	{
+		projectiles.erase(*it);
+	}
+}
+
+void CBattleHero::show(SDL_Surface *to)
+{
+	//animation of flag
+	if(flip)
+	{
+		CSDL_Ext::blit8bppAlphaTo24bpp(
+                        flag->ourImages[flagAnim].bitmap,
+                        NULL,
+                        screen,
+                        &genRect(
+                                flag->ourImages[flagAnim].bitmap->h,
+                                flag->ourImages[flagAnim].bitmap->w,
+                                752,
+                                39
+                        )
+                );
+	}
+	else
+	{
+		CSDL_Ext::blit8bppAlphaTo24bpp(
+                        flag->ourImages[flagAnim].bitmap,
+                        NULL,
+                        screen,
+                        &genRect(
+                                flag->ourImages[flagAnim].bitmap->h,
+                                flag->ourImages[flagAnim].bitmap->w,
+                                31,
+                                39
+                        )
+                );
+	}
+	++flagAnimCount;
+	if(flagAnimCount%4==0)
+	{
+		++flagAnim;
+		flagAnim %= flag->ourImages.size();
+	}
+	//animation of hero
+	int tick=-1;
+	for(int i=0; i<dh->ourImages.size(); ++i)
+	{
+		if(dh->ourImages[i].groupNumber==phase)
+			++tick;
+		if(tick==image)
+		{
+			SDL_Rect posb = pos;
+			CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb);
+			++image;
+			if(dh->ourImages[(i+1)%dh->ourImages.size()].groupNumber!=phase) //back to appropriate frame
+			{
+				image = 0;
+			}
+			break;
+		}
+	}
+}
+
+void CBattleHero::activate()
+{
+	ClickableL::activate();
+}
+void CBattleHero::deactivate()
+{
+	ClickableL::deactivate();
+}
+
+void CBattleHero::setPhase(int newPhase)
+{
+	phase = newPhase;
+	image = 0;
+}
+
+void CBattleHero::clickLeft(boost::logic::tribool down)
+{
+	if(!down && myHero)
+	{
+		for(int it=0; it<BFIELD_SIZE; ++it) //do nothing when any hex is hovered - hero's animation overlaps battlefield
+		{
+			if(myOwner->bfield[it].hovered && myOwner->bfield[it].strictHovered)
+				return;
+		}
+		CGI->curh->changeGraphic(0,0);
+		LOCPLINT->curint->deactivate();
+
+		CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, 90, 2), myHero);
+		spellWindow->activate();
+		LOCPLINT->objsToBlit.push_back(spellWindow);
+	}
+}
+
+CBattleHero::CBattleHero(const std::string & defName, int phaseG, int imageG, bool flipG, unsigned char player, const CGHeroInstance * hero, const CBattleInterface * owner): phase(phaseG), image(imageG), flip(flipG), flagAnim(0), myHero(hero), myOwner(owner)
+{
+	dh = CDefHandler::giveDef( defName );
+	for(int i=0; i<dh->ourImages.size(); ++i) //transforming images
+	{
+		if(flip)
+		{
+			SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap);
+			SDL_FreeSurface(dh->ourImages[i].bitmap);
+			dh->ourImages[i].bitmap = hlp;
+		}
+		dh->ourImages[i].bitmap = CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap);
+	}
+	dh->alphaTransformed = true;
+
+	if(flip)
+		flag = CDefHandler::giveDef("CMFLAGR.DEF");
+	else
+		flag = CDefHandler::giveDef("CMFLAGL.DEF");
+
+	//coloring flag and adding transparency
+	for(int i=0; i<flag->ourImages.size(); ++i)
+	{
+		flag->ourImages[i].bitmap = CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap);
+		graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player);
+	}
+}
+
+CBattleHero::~CBattleHero()
+{
+	delete dh;
+	delete flag;
+}
+
+std::pair<int, int> CBattleHex::getXYUnitAnim(const int & hexNum, const bool & attacker, const CCreature * creature)
+{
+	std::pair<int, int> ret = std::make_pair(-500, -500); //returned value
+	ret.second = -139 + 42 * (hexNum/BFIELD_WIDTH); //counting y
+	//counting x
+	if(attacker)
+	{
+		ret.first = -160 + 22 * ( ((hexNum/BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % BFIELD_WIDTH);
+	}
+	else
+	{
+		ret.first = -219 + 22 * ( ((hexNum/BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % BFIELD_WIDTH);
+	}
+	//shifting position for double - hex creatures
+	if(creature && creature->isDoubleWide())
+	{
+		if(attacker)
+		{
+			ret.first -= 42;
+		}
+		else
+		{
+			ret.first += 42;
+		}
+	}
+	//returning
+	return ret;
+}
+void CBattleHex::activate()
+{
+	Hoverable::activate();
+	MotionInterested::activate();
+	ClickableL::activate();
+	ClickableR::activate();
+}
+
+void CBattleHex::deactivate()
+{
+	Hoverable::deactivate();
+	MotionInterested::deactivate();
+	ClickableL::deactivate();
+	ClickableR::deactivate();
+}
+
+void CBattleHex::hover(bool on)
+{
+	hovered = on;
+	Hoverable::hover(on);
+	if(!on && setAlterText)
+	{
+		myInterface->console->alterTxt = std::string();
+		setAlterText = false;
+	}
+}
+
+CBattleHex::CBattleHex() : myNumber(-1), accesible(true), hovered(false), strictHovered(false), myInterface(NULL), setAlterText(false)
+{
+}
+
+void CBattleHex::mouseMoved(const SDL_MouseMotionEvent &sEvent)
+{
+	if(myInterface->cellShade)
+	{
+		if(CSDL_Ext::SDL_GetPixel(myInterface->cellShade, sEvent.x-pos.x, sEvent.y-pos.y) == 0) //hovered pixel is outside hex
+		{
+			strictHovered = false;
+		}
+		else //hovered pixel is inside hex
+		{
+			strictHovered = true;
+		}
+	}
+
+	if(hovered && strictHovered) //print attacked creature to console
+	{
+		if(myInterface->console->alterTxt.size() == 0 && LOCPLINT->cb->battleGetStack(myNumber) != -1 &&
+			LOCPLINT->cb->battleGetStackByPos(myNumber)->owner != LOCPLINT->playerID &&
+			LOCPLINT->cb->battleGetStackByPos(myNumber)->alive())
+		{
+			char tabh[160];
+			CStack attackedStack = *LOCPLINT->cb->battleGetStackByPos(myNumber);
+			const std::string & attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl;
+			sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str());
+			myInterface->console->alterTxt = std::string(tabh);
+			setAlterText = true;
+		}
+	}
+	else if(setAlterText)
+	{
+		myInterface->console->alterTxt = std::string();
+		setAlterText = false;
+	}
+}
+
+void CBattleHex::clickLeft(boost::logic::tribool down)
+{
+	if(!down && hovered && strictHovered) //we've been really clicked!
+	{
+		myInterface->hexLclicked(myNumber);
+	}
+}
+
+void CBattleHex::clickRight(boost::logic::tribool down)
+{
+	int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile
+	if(hovered && strictHovered && stID!=-1)
+	{
+		CStack myst = *LOCPLINT->cb->battleGetStackByID(stID); //stack info
+		if(!myst.alive()) return;
+		StackState *pom = NULL;
+		if(down)
+		{
+			pom = new StackState();
+			const CGHeroInstance *h = myst.owner == myInterface->attackingHeroInstance->tempOwner ? myInterface->attackingHeroInstance : myInterface->defendingHeroInstance;
+			if(h)
+			{
+				pom->attackBonus = h->getPrimSkillLevel(0);
+				pom->defenseBonus = h->getPrimSkillLevel(1);
+				pom->luck = h->getCurrentLuck();
+				pom->morale = h->getCurrentMorale();
+				pom->shotsLeft = myst.shots;
+				for(int vb=0; vb<myst.effects.size(); ++vb)
+				{
+					pom->effects.insert(myst.effects[vb].id);
+				}
+			}
+			pom->currentHealth = myst.firstHPleft;
+			(new CCreInfoWindow(myst.creature->idNumber,0,myst.amount,pom,boost::function<void()>(),boost::function<void()>(),NULL))
+					->activate();
+		}
+		delete pom;
+	}
+}
+
+CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt("")
+{
+}
+
+CBattleConsole::~CBattleConsole()
+{
+	texts.clear();
+}
+
+void CBattleConsole::show(SDL_Surface * to)
+{
+	if(alterTxt.size())
+	{
+		CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
+	}
+	else if(texts.size())
+	{
+		if(texts.size()==1)
+		{
+			CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
+		}
+		else
+		{
+			CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
+			CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 26, GEOR13, 80, zwykly, to);
+		}
+	}
+}
+
+bool CBattleConsole::addText(const std::string & text)
+{
+	if(text.size()>70)
+		return false; //text too long!
+	int firstInToken = 0;
+	for(int i=0; i<text.size(); ++i) //tokenize
+	{
+		if(text[i] == 10)
+		{
+			texts.push_back( text.substr(firstInToken, i-firstInToken) );
+			firstInToken = i+1;
+		}
+	}
+
+	texts.push_back( text.substr(firstInToken, text.size()) );
+	lastShown = texts.size()-1;
+	return true;
+}
+
+void CBattleConsole::eraseText(unsigned int pos)
+{
+	if(pos < texts.size())
+	{
+		texts.erase(texts.begin() + pos);
+		if(lastShown == texts.size())
+			--lastShown;
+	}
+}
+
+void CBattleConsole::changeTextAt(const std::string & text, unsigned int pos)
+{
+	if(pos >= texts.size()) //no such pos
+		return;
+	texts[pos] = text;
+}
+
+void CBattleConsole::scrollUp(unsigned int by)
+{
+	if(lastShown > by)
+		lastShown -= by;
+}
+
+void CBattleConsole::scrollDown(unsigned int by)
+{
+	if(lastShown + by < texts.size())
+		lastShown += by;
+}
+
+CBattleReslutWindow::CBattleReslutWindow(const BattleResult &br, const SDL_Rect & pos, const CBattleInterface * owner)
+{
+	this->pos = pos;
+	background = BitmapHandler::loadBitmap("CPRESULT.BMP", true);
+	graphics->blueToPlayersAdv(background, LOCPLINT->playerID);
+	SDL_Surface * pom = SDL_ConvertSurface(background, screen->format, screen->flags);
+	SDL_FreeSurface(background);
+	background = pom;
+	exit = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleReslutWindow::bExitf,this), 549, 524, "iok6432.def", SDLK_RETURN);
+
+	if(br.winner==0) //attacker won
+	{
+		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 60, 122, GEOR13, zwykly, background);
+		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 410, 122, GEOR13, zwykly, background);
+	}
+	else //if(br.winner==1)
+	{
+		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 60, 122, GEOR13, zwykly, background);
+		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 410, 122, GEOR13, zwykly, background);
+	}
+
+	
+	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[407], 235, 299, GEOR16, tytulowy, background);
+	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[408], 235, 329, GEOR16, zwykly, background);
+	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[409], 235, 426, GEOR16, zwykly, background);
+
+	std::string attackerName, defenderName;
+
+	if(owner->attackingHeroInstance) //a hero attacked
+	{
+		SDL_BlitSurface(graphics->portraitLarge[owner->attackingHeroInstance->portrait], NULL, background, &genRect(64, 58, 21, 38));
+		//setting attackerName
+		attackerName = owner->attackingHeroInstance->name;
+	}
+	else //a monster attacked
+	{
+		int bestMonsterID = -1;
+		int bestPower = 0;
+		for(std::map<si32,std::pair<ui32,si32> >::const_iterator it = owner->army1->slots.begin(); it!=owner->army1->slots.end(); ++it)
+		{
+			if( CGI->creh->creatures[it->first].AIValue > bestPower)
+			{
+				bestPower = CGI->creh->creatures[it->first].AIValue;
+				bestMonsterID = it->first;
+			}
+		}
+		SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &genRect(64, 58, 21, 38));
+		//setting attackerName
+		attackerName =  CGI->creh->creatures[bestMonsterID].namePl;
+	}
+	if(owner->defendingHeroInstance) //a hero defended
+	{
+		SDL_BlitSurface(graphics->portraitLarge[owner->defendingHeroInstance->portrait], NULL, background, &genRect(64, 58, 391, 38));
+		//setting defenderName
+		defenderName = owner->defendingHeroInstance->name;
+	}
+	else //a monster defended
+	{
+		int bestMonsterID = -1;
+		int bestPower = 0;
+		for(std::map<si32,std::pair<ui32,si32> >::const_iterator it = owner->army2->slots.begin(); it!=owner->army2->slots.end(); ++it)
+		{
+			if( CGI->creh->creatures[it->second.first].AIValue > bestPower)
+			{
+				bestPower = CGI->creh->creatures[it->second.first].AIValue;
+				bestMonsterID = it->second.first;
+			}
+		}
+		SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &genRect(64, 58, 391, 38));
+		//setting defenderName
+		defenderName =  CGI->creh->creatures[bestMonsterID].namePl;
+	}
+
+	//printing attacker and defender's names
+	CSDL_Ext::printAtMiddle(attackerName, 156, 44, GEOR16, zwykly, background);
+	CSDL_Ext::printAtMiddle(defenderName, 314, 44, GEOR16, zwykly, background);
+	//printing casualities
+	for(int step = 0; step < 2; ++step)
+	{
+		if(br.casualties[step].size()==0)
+		{
+			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[523], 235, 360 + 97*step, GEOR16, zwykly, background);
+		}
+		else
+		{
+			int xPos = 235 - (br.casualties[step].size()*32 + (br.casualties[step].size() - 1)*10)/2; //increment by 42 with each picture
+			int yPos = 344 + step*97;
+			for(std::set<std::pair<ui32,si32> >::const_iterator it=br.casualties[step].begin(); it!=br.casualties[step].end(); ++it)
+			{
+				blitAt(graphics->smallImgs[it->first], xPos, yPos, background);
+				std::stringstream amount;
+				amount<<it->second;
+				CSDL_Ext::printAtMiddle(amount.str(), xPos+16, yPos + 42, GEOR13, zwykly, background);
+				xPos += 42;
+			}
+		}
+	}
+	//printing result description
+	bool weAreAttacker = (LOCPLINT->playerID == owner->attackingHeroInstance->tempOwner);
+	switch(br.result)
+	{
+	case 0: //normal victory
+		if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won
+		{
+			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[304], 235, 235, GEOR13, zwykly, background);
+		}
+		else
+		{
+			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[311], 235, 235, GEOR13, zwykly, background);
+		}
+		break;
+	case 1: //flee
+		if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won
+		{
+			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[303], 235, 235, GEOR13, zwykly, background);
+		}
+		else
+		{
+			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[310], 235, 235, GEOR13, zwykly, background);
+		}
+		break;
+	case 2: //surrender
+		if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won
+		{
+			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[302], 235, 235, GEOR13, zwykly, background);
+		}
+		else
+		{
+			CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[309], 235, 235, GEOR13, zwykly, background);
+		}
+		break;
+	}
+}
+
+CBattleReslutWindow::~CBattleReslutWindow()
+{
+	SDL_FreeSurface(background);
+}
+
+void CBattleReslutWindow::activate()
+{
+	LOCPLINT->showingDialog->set(true);
+	exit->activate();
+}
+
+void CBattleReslutWindow::deactivate()
+{
+	exit->deactivate();
+}
+
+void CBattleReslutWindow::show(SDL_Surface *to)
+{
+	//evaluating to
+	if(!to)
+		to = screen;
+
+	SDL_BlitSurface(background, NULL, to, &pos);
+	exit->show(to);
+}
+
+void CBattleReslutWindow::bExitf()
+{
+	LOCPLINT->battleResultQuited();
+}
+
+CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface *owner): myInt(owner)
+{
+	pos = position;
+	background = BitmapHandler::loadBitmap("comopbck.bmp", true);
+	graphics->blueToPlayersAdv(background, LOCPLINT->playerID);
+
+	viewGrid = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintCellBorders, owner, true), boost::bind(&CBattleInterface::setPrintCellBorders, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[427].first)(3,CGI->generaltexth->zelp[427].first), CGI->generaltexth->zelp[427].second, false, "sysopchk.def", NULL, 185, 140, false);
+	viewGrid->select(owner->printCellBorders);
+	movementShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintStackRange, owner, true), boost::bind(&CBattleInterface::setPrintStackRange, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[428].first)(3,CGI->generaltexth->zelp[428].first), CGI->generaltexth->zelp[428].second, false, "sysopchk.def", NULL, 185, 173, false);
+	movementShadow->select(owner->printStackRange);
+	mouseShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintMouseShadow, owner, true), boost::bind(&CBattleInterface::setPrintMouseShadow, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[429].first)(3,CGI->generaltexth->zelp[429].first), CGI->generaltexth->zelp[429].second, false, "sysopchk.def", NULL, 185, 207, false);
+	mouseShadow->select(owner->printMouseShadow);
+
+	animSpeeds = new CHighlightableButtonsGroup(0);
+	animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[422].first),CGI->generaltexth->zelp[422].second, "sysopb9.def",188, 309, 1);
+	animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[423].first),CGI->generaltexth->zelp[423].second, "sysob10.def",252, 309, 2);
+	animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[424].first),CGI->generaltexth->zelp[424].second, "sysob11.def",315, 309, 4);
+	animSpeeds->select(owner->getAnimSpeed(), 1);
+	animSpeeds->onChange = boost::bind(&CBattleInterface::setAnimSpeed, owner, _1);
+
+	setToDefault = new AdventureMapButton (CGI->generaltexth->zelp[392].first, CGI->generaltexth->zelp[392].second, boost::bind(&CBattleOptionsWindow::bDefaultf,this), 405, 443, "codefaul.def");
+	std::swap(setToDefault->imgs[0][0], setToDefault->imgs[0][1]);
+	exit = new AdventureMapButton (CGI->generaltexth->zelp[393].first, CGI->generaltexth->zelp[393].second, boost::bind(&CBattleOptionsWindow::bExitf,this), 516, 443, "soretrn.def",SDLK_RETURN);
+	std::swap(exit->imgs[0][0], exit->imgs[0][1]);
+
+	//printing texts to background
+	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[392], 240, 32, GEOR16, tytulowy, background); //window title
+	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[393], 122, 211, GEOR16, tytulowy, background); //animation speed
+	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[394], 122, 292, GEOR16, tytulowy, background); //music volume
+	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[395], 122, 358, GEOR16, tytulowy, background); //effects' volume
+	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[396], 353, 64, GEOR16, tytulowy, background); //auto - combat options
+	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[397], 353, 264, GEOR16, tytulowy, background); //creature info
+
+		//auto - combat options
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[398], 283, 87, GEOR16, zwykly, background); //creatures
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[399], 283, 117, GEOR16, zwykly, background); //spells
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[400], 283, 147, GEOR16, zwykly, background); //catapult
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[151], 283, 177, GEOR16, zwykly, background); //ballista
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[401], 283, 207, GEOR16, zwykly, background); //first aid tent
+
+		//creature info
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[402], 283, 286, GEOR16, zwykly, background); //all stats
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[403], 283, 316, GEOR16, zwykly, background); //spells only
+	
+		//general options
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[404], 61, 58, GEOR16, zwykly, background); //hex grid
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[405], 61, 91, GEOR16, zwykly, background); //movement shadow
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[406], 61, 124, GEOR16, zwykly, background); //cursor shadow
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[577], 61, 157, GEOR16, zwykly, background); //spellbook animation
+	//texts printed
+}
+
+CBattleOptionsWindow::~CBattleOptionsWindow()
+{
+	SDL_FreeSurface(background);
+
+	delete setToDefault;
+	delete exit;
+
+	delete viewGrid;
+	delete movementShadow;
+	delete animSpeeds;
+	delete mouseShadow;
+}
+
+void CBattleOptionsWindow::activate()
+{
+	setToDefault->activate();
+	exit->activate();
+	viewGrid->activate();
+	movementShadow->activate();
+	animSpeeds->activate();
+	mouseShadow->activate();
+}
+
+void CBattleOptionsWindow::deactivate()
+{
+	setToDefault->deactivate();
+	exit->deactivate();
+	viewGrid->deactivate();
+	movementShadow->deactivate();
+	animSpeeds->deactivate();
+	mouseShadow->deactivate();
+}
+
+void CBattleOptionsWindow::show(SDL_Surface *to)
+{
+	if(!to) //"evaluating" to
+		to = screen;
+
+	SDL_BlitSurface(background, NULL, to, &pos);
+
+	setToDefault->show(to);
+	exit->show(to);
+	viewGrid->show(to);
+	movementShadow->show(to);
+	animSpeeds->show(to);
+	mouseShadow->show(to);
+}
+
+void CBattleOptionsWindow::bDefaultf()
+{
+}
+
+void CBattleOptionsWindow::bExitf()
+{
+	deactivate();
+
+	for(size_t g=0; g<LOCPLINT->objsToBlit.size(); ++g)
+	{
+		if(dynamic_cast<CBattleOptionsWindow*>(LOCPLINT->objsToBlit[g]))
+		{
+			LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
+			break;
+		}
+	}
+
+	delete this;
+	LOCPLINT->curint->activate();
+}

+ 8 - 0
CBattleInterface.h

@@ -1,4 +1,11 @@
+#ifndef CBATTLEINTERFACE_H
+#define CBATTLEINTERFACE_H
+
+#ifdef _MSC_VER
 #pragma once
+#endif
+
+
 #include "global.h"
 #include "CPlayerInterface.h"
 #include <list>
@@ -251,3 +258,4 @@ public:
 	friend class CBattleReslutWindow;
 	friend class CPlayerInterface;
 };
+#endif //CBATTLEINTERFACE_H

+ 24 - 20
CCallback.cpp

@@ -61,7 +61,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
 	}
 	else if (idtype==1 && player>=0) //looking for it in local area
 	{
-		for (int i=0; i<gs->players[player].heroes.size();i++)
+		for (size_t i=0; i < gs->players[player].heroes.size(); ++i)
 		{
 			if (gs->players[player].heroes[i]->type->ID == ID)
 				hero = gs->players[player].heroes[i];
@@ -72,7 +72,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
 
 		for(std::map<ui8, PlayerState>::iterator j=gs->players.begin(); j!=gs->players.end(); ++j)
 		{
-			for (int i=0; i<(*j).second.heroes.size();i++)
+			for (size_t i=0; i < (*j).second.heroes.size(); ++i)
 			{
 				if ((*j).second.heroes[i]->type->ID == ID)
 				{
@@ -193,19 +193,23 @@ int CCallback::howManyHeroes() const
 }
 const CGHeroInstance * CCallback::getHeroInfo(int val, int mode) const //mode = 0 -> val = serial; mode = 1 -> val = ID
 {
-	boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
+	boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //TODO use me?
 	//if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info
 	//	return NULL;
 	if (!mode) //esrial id
-		if(val<gs->players[player].heroes.size())
+		if(val<gs->players[player].heroes.size()) {
 			return gs->players[player].heroes[val];
-		else return NULL;
+        }
+		else {
+            return NULL;
+        }
 	else if(mode==1) //it's hero type id
 	{
-		for (int i=0; i<gs->players[player].heroes.size();i++)
+		for (size_t i=0; i < gs->players[player].heroes.size(); ++i)
 		{
-			if (gs->players[player].heroes[i]->type->ID==val)
+			if (gs->players[player].heroes[i]->type->ID==val) {
 				return gs->players[player].heroes[i];
+            }
 		}
 	}
 	else //object id
@@ -242,7 +246,7 @@ std::vector < std::string > CCallback::getObjDescriptions(int3 pos) const
 }
 bool CCallback::verifyPath(CPath * path, bool blockSea) const
 {
-	for (int i=0;i<path->nodes.size();i++)
+	for (size_t i=0; i < path->nodes.size(); ++i)
 	{
 		if ( CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->blocked 
 			&& (! (CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->visitable)))
@@ -292,7 +296,7 @@ std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur) cons
 	std::vector < const CGTownInstance *> ret = std::vector < const CGTownInstance *>();
 	for ( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
 	{
-		for (int j=0;j<(*i).second.towns.size();j++)
+		for (size_t j=0; j < (*i).second.towns.size(); ++j)
 		{
 			if ( ( isVisible((*i).second.towns[j],player) ) || (*i).first==player)
 			{
@@ -306,7 +310,7 @@ std::vector < const CGHeroInstance *> CCallback::getHeroesInfo(bool onlyOur) con
 {
 	boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
 	std::vector < const CGHeroInstance *> ret;
-	for(int i=0;i<gs->map->heroes.size();i++)
+	for(size_t i=0;i<gs->map->heroes.size();i++)
 	{
 		if(	 (gs->map->heroes[i]->tempOwner==player) ||
 		   (isVisible(gs->map->heroes[i]->getPosition(false),player) && !onlyOur)	)
@@ -346,7 +350,7 @@ int CCallback::getMyColor() const
 int CCallback::getHeroSerial(const CGHeroInstance * hero) const
 {
 	boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
-	for (int i=0; i<gs->players[player].heroes.size();i++)
+	for (size_t i=0; i<gs->players[player].heroes.size();i++)
 	{
 		if (gs->players[player].heroes[i]==hero)
 			return i;
@@ -467,7 +471,7 @@ CStack* CCallback::battleGetStackByPos(int pos)
 int CCallback::battleGetPos(int stack)
 {
 	boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
-	for(int g=0; g<gs->curB->stacks.size(); ++g)
+	for(size_t g=0; g<gs->curB->stacks.size(); ++g)
 	{
 		if(gs->curB->stacks[g]->ID == stack)
 			return gs->curB->stacks[g]->position;
@@ -484,7 +488,7 @@ std::map<int, CStack> CCallback::battleGetStacks()
 		return ret;
 	}
 
-	for(int g=0; g<gs->curB->stacks.size(); ++g)
+	for(size_t g=0; g<gs->curB->stacks.size(); ++g)
 	{
 		ret[gs->curB->stacks[g]->ID] = *(gs->curB->stacks[g]);
 	}
@@ -498,8 +502,8 @@ std::vector<CStack> CCallback::battleGetStackQueue()
 
 CCreature CCallback::battleGetCreature(int number)
 {
-	boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
-	for(int h=0; h<gs->curB->stacks.size(); ++h)
+	boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //TODO use me?
+	for(size_t h=0; h<gs->curB->stacks.size(); ++h)
 	{
 		if(gs->curB->stacks[h]->ID == number) //creature found
 			return *(gs->curB->stacks[h]->creature);
@@ -520,8 +524,8 @@ std::vector<int> CCallback::battleGetAvailableHexes(int ID)
 
 bool CCallback::battleIsStackMine(int ID)
 {
-	boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
-	for(int h=0; h<gs->curB->stacks.size(); ++h)
+	boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //TODO use me ?
+	for(size_t h=0; h<gs->curB->stacks.size(); ++h)
 	{
 		if(gs->curB->stacks[h]->ID == ID) //creature found
 			return gs->curB->stacks[h]->owner == player;
@@ -530,11 +534,11 @@ bool CCallback::battleIsStackMine(int ID)
 }
 bool CCallback::battleCanShoot(int ID, int dest)
 {
-	boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
+	boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //TODO use me?
 	CStack *our = battleGetStackByID(ID), *dst = battleGetStackByPos(dest);
 	if(!our || !dst) return false; 
 
-	for(int g=0; g<our->effects.size(); ++g)
+	for(size_t g=0; g<our->effects.size(); ++g)
 	{
 		if(61 == our->effects[g].id) //forgetfulness
 			return false;
@@ -611,7 +615,7 @@ std::vector < const CGObjectInstance * > CCallback::getFlaggableObjects(int3 pos
 	std::vector < const CGObjectInstance * > ret;
 
 	std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > & objs = CGI->mh->ttiles[pos.x][pos.y][pos.z].objects;
-	for(int b=0; b<objs.size(); ++b)
+	for(size_t b=0; b<objs.size(); ++b)
 	{
 		if(objs[b].first->tempOwner!=254 && !((objs[b].first->defInfo->blockMap[pos.y - objs[b].first->pos.y + 5] >> (objs[b].first->pos.x - pos.x)) & 1))
 			ret.push_back(CGI->mh->ttiles[pos.x][pos.y][pos.z].objects[b].first);

+ 5 - 3
CCallback.h

@@ -5,7 +5,9 @@
 #ifdef _WIN32
 #include "tchar.h"
 #else
-#include "tchar_amigaos4.h"
+#include "tchar_amigaos4.h" //XXX this is mingw header are we need this for something? for 'true'
+//support of unicode we should use ICU or some boost wraper areound it
+//(boost using this lib during compilation i dont know what for exactly)
 #endif
 #include "CGameState.h"
 
@@ -101,7 +103,7 @@ struct HeroMoveDetails
 class CCallback : public ICallback
 {
 private:
-	CCallback(CGameState * GS, int Player, CClient *C):gs(GS),player(Player),cl(C){};
+	CCallback(CGameState * GS, int Player, CClient *C):gs(GS), cl(C), player(Player){};
 	CGameState * gs;
 	CClient *cl;
 	bool isVisible(int3 pos, int Player) const;
@@ -175,7 +177,7 @@ public:
 	bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest
 
 
-
+//XXX hmmm _tmain on _GNUC_ wtf?
 //friends
 	friend class CClient;
 #ifndef __GNUC__

+ 55 - 40
CCastleInterface.cpp

@@ -27,7 +27,7 @@ using namespace CSDL_Ext;
 
 extern TTF_Font * GEOR16;
 CBuildingRect::CBuildingRect(Structure *Str)
-:str(Str), moi(false), offset(0)
+:moi(false), offset(0), str(Str)
 {
 	def = CDefHandler::giveDef(Str->defName);
 	max = def->ourImages.size();
@@ -49,14 +49,18 @@ CBuildingRect::CBuildingRect(Structure *Str)
 		area = border = NULL;
 		return;
 	}
-	if (border = BitmapHandler::loadBitmap(str->borderName))
+	if (border = BitmapHandler::loadBitmap(str->borderName)) {//FIXME hmmm if '=' use () else '==' fatal mistake
 		SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
-	else
+        }
+	else {
 		tlog2 << "Warning: no border for "<<Str->ID<<std::endl;
-	if (area = BitmapHandler::loadBitmap(str->areaName))
+        }
+	if (area = BitmapHandler::loadBitmap(str->areaName)) { //FIXME look up
 		;//SDL_SetColorKey(area,SDL_SRCCOLORKEY,SDL_MapRGB(area->format,0,255,255));
-	else
+        }
+	else {
 		tlog2 << "Warning: no area for "<<Str->ID<<std::endl;
+        }
 }
 
 CBuildingRect::~CBuildingRect()
@@ -297,7 +301,7 @@ CHeroGSlot::CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, CCastl
 CHeroGSlot::~CHeroGSlot()
 {
 }
-std::string getBgName(int type) //TODO - co z tym zrobiæ?
+std::string getBgName(int type) //TODO - co z tym zrobi�?
 {
 	switch (type)
 	{
@@ -438,7 +442,7 @@ CCastleInterface::~CCastleInterface()
 	delete townlist;
 	delete statusbar;
 	delete resdatabar;
-	for(int i=0;i<buildings.size();i++)
+	for(size_t i=0;i<buildings.size();i++)
 	{
 		delete buildings[i];
 	}
@@ -676,7 +680,7 @@ void CCastleInterface::show(SDL_Surface * to)
 
 
 	//blit buildings
-	for(int i=0;i<buildings.size();i++)
+	for(size_t i=0;i<buildings.size();i++)
 	{
 		int frame = ((animval)%(buildings[i]->max - buildings[i]->offset)) + buildings[i]->offset;
 		if(frame)
@@ -706,8 +710,9 @@ void CCastleInterface::activate()
 	LOCPLINT->statusbar = statusbar;
 	exit->activate();
 	split->activate();
-	for(int i=0;i<buildings.size();i++)
+	for(size_t i=0;i<buildings.size();i++) { //XXX pls use iterators or at() but not []
 		buildings[i]->activate();
+        }
 	hslotdown.activate();
 	hslotup.activate();
 	showAll(0,true);
@@ -724,8 +729,9 @@ void CCastleInterface::deactivate()
 	garr->deactivate();
 	exit->deactivate();
 	split->deactivate();
-	for(int i=0;i<buildings.size();i++)
+	for(size_t i=0;i<buildings.size();i++) { //XXX iterators
 		buildings[i]->deactivate();
+        }
 	hslotdown.deactivate();
 	hslotup.deactivate();
 }
@@ -746,7 +752,7 @@ void CCastleInterface::removeBuilding(int bid)
 
 void CCastleInterface::recreateBuildings()
 {
-	for(int i=0;i<buildings.size();i++)
+	for(size_t i=0;i<buildings.size();i++)
 	{
 		if(showing)
 			buildings[i]->deactivate();
@@ -784,14 +790,14 @@ void CCastleInterface::recreateBuildings()
 					{
 						if((*(CGI->townh->structures[town->subID][obecny->second])) < (*(CGI->townh->structures[town->subID][st->ID]))) //we have to replace old building with current one
 						{
-							for(int itpb = 0; itpb<buildings.size(); itpb++)
+							for(size_t itpb = 0; itpb<buildings.size(); itpb++)
 							{
 								if(buildings[itpb]->str->ID == obecny->second)
 								{
 									delete buildings[itpb];
 									buildings.erase(buildings.begin() + itpb);
 									#ifndef __GNUC__
-									obecny->second = st->ID;
+									obecny->second = st->ID; //XXX look closer!
 									#else
 									*(const_cast<int*>(&(obecny->second))) = st->ID;
 									#endif
@@ -818,7 +824,7 @@ void CCastleInterface::recreateBuildings()
 	if((town->subID == 5) && (town->builtBuildings.find(21)!=town->builtBuildings.end()))
 	{
 		CBuildingRect *vortex = NULL;
-		for(int i=0;i<buildings.size();i++)
+		for(size_t i=0;i<buildings.size();i++)
 		{
 			if(buildings[i]->str->ID==21)
 			{
@@ -841,7 +847,7 @@ void CCastleInterface::recreateBuildings()
 	else if((town->subID == 0) && (town->builtBuildings.find(6)!=town->builtBuildings.end()))
 	{
 		CBuildingRect *shipyard = NULL;
-		for(int i=0;i<buildings.size();i++)
+		for(size_t i=0;i<buildings.size();i++)
 		{
 			if(buildings[i]->str->ID==6)
 			{
@@ -995,11 +1001,11 @@ CHallInterface::CHallInterface(CCastleInterface * owner)
 
 	//preparing boxes with buildings//
 	boxes.resize(5);
-	for(int i=0;i<5;i++) //for each row
+	for(size_t i=0;i<5;i++) //for each row
 	{
-		for(int j=0; j<CGI->buildh->hall[owner->town->subID].second[i].size();j++) //for each box
+		for(size_t j=0; j<CGI->buildh->hall[owner->town->subID].second[i].size();j++) //for each box
 		{
-			int k=0;
+			size_t k=0;
 			for(;k<CGI->buildh->hall[owner->town->subID].second[i][j].size();k++)//we are looking for the first not build structure
 			{
 				if(
@@ -1064,9 +1070,9 @@ CHallInterface::~CHallInterface()
 	delete bars;
 	delete status;
 	SDL_FreeSurface(bg);
-	for(int i=0;i<boxes.size();i++)
-		for(int j=0;j<boxes[i].size();j++)
-			delete boxes[i][j];
+	for(size_t i=0;i<boxes.size();i++)
+		for(size_t j=0;j<boxes[i].size();j++)
+			delete boxes[i][j]; //TODO whats wrong with smartpointers?
 	delete exit;
 }
 void CHallInterface::close()
@@ -1076,29 +1082,30 @@ void CHallInterface::close()
 	delete this;
 	LOCPLINT->castleInt->activate();
 }
-void CHallInterface::show(SDL_Surface * to)
+void CHallInterface::show(SDL_Surface * to) //TODO use me
 {
 	blitAt(bg,pos);
 	resdatabar.show();
 	exit->show();
 	for(int i=0; i<5; i++)
 	{
-		for(int j=0;j<boxes[i].size();j++)
+		for(size_t j=0;j<boxes[i].size(); ++j)
 			boxes[i][j]->show();
 	}
 }
 void CHallInterface::activate()
 {
 	for(int i=0;i<5;i++)
-		for(int j=0;j<boxes[i].size();j++)
+		for(size_t j=0; j < boxes[i].size(); ++j) {
 			boxes[i][j]->activate();
+                }
 	exit->activate();
 }
 void CHallInterface::deactivate()
 {
 	for(int i=0;i<5;i++)
 	{
-		for(int j=0;j<boxes[i].size();j++)
+		for(size_t j=0;j<boxes[i].size();++j)
 		{
 			boxes[i][j]->deactivate();
 		}
@@ -1187,7 +1194,7 @@ std::string CHallInterface::CBuildWindow::getTextForState(int state)
 			}
 			while(true)
 			{
-				int czystych=0;
+				size_t czystych=0;
 				for(std::set<int>::iterator i=reqs.begin();i!=reqs.end();i++)
 				{
 					if(used.find(*i)==used.end()) //we haven't added requirements for this building
@@ -1223,7 +1230,7 @@ std::string CHallInterface::CBuildWindow::getTextForState(int state)
 	return ret;
 }
 CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mode)
-:tid(Tid),bid(Bid),mode(Mode), state(State)
+:tid(Tid), bid(Bid), state(State), mode(Mode)
 {
 	SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPUBUILD.bmp");
 	graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID);
@@ -1237,7 +1244,13 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod
 	CSDL_Ext::printAtMiddleWB(CGI->buildh->buildings[tid][bid]->description,197,168,GEOR16,40,zwykly,bitmap);
 	CSDL_Ext::printAtMiddleWB(getTextForState(state),197,248,GEOR13,50,zwykly,bitmap);
 	CSDL_Ext::printAtMiddle(CSDL_Ext::processStr(CGI->townh->hcommands[7],pom),197,30,GEOR16,tytulowy,bitmap);
-	int resamount=0; for(int i=0;i<7;i++) if(CGI->buildh->buildings[tid][bid]->resources[i]) resamount++;
+	int resamount=0; 
+        
+        for(int i=0;i<7;i++) {
+            if(CGI->buildh->buildings[tid][bid]->resources[i]) {
+                resamount++;
+            }
+        }
 	int ah = (resamount>4) ? 304 : 341;
 	int cn=-1, it=0;
 	int row1w = std::min(resamount,4) * 32 + (std::min(resamount,4)-1) * 45,
@@ -1286,9 +1299,9 @@ CHallInterface::CBuildWindow::~CBuildWindow()
 CFortScreen::~CFortScreen()
 {
 	LOCPLINT->curint->subInt = NULL;
-	for(int i=0;i<crePics.size();i++)
+	for(size_t i=0;i<crePics.size();i++)
 		delete crePics[i];
-	for (int i=0;i<recAreas.size();i++)
+	for (size_t i=0;i<recAreas.size();i++)
 		delete recAreas[i];
 	SDL_FreeSurface(bg);
 	delete exit;
@@ -1312,7 +1325,7 @@ void CFortScreen::activate()
 {
 	LOCPLINT->curint->subInt = this;
 	exit->activate();
-	for (int i=0;i<recAreas.size();i++)
+	for (size_t i=0;i<recAreas.size(); ++i)
 	{
 		recAreas[i]->activate();
 	}
@@ -1323,7 +1336,7 @@ void CFortScreen::activate()
 void CFortScreen::deactivate()
 {
 	exit->deactivate();
-	for (int i=0;i<recAreas.size();i++)
+	for (size_t i=0;i<recAreas.size();i++)
 	{
 		recAreas[i]->deactivate();
 	}
@@ -1435,7 +1448,7 @@ void CFortScreen::RecArea::clickLeft (tribool down)
 	if(!down && pressedL)
 	{
 		LOCPLINT->curint->deactivate();
-		CRecrutationWindow *rw = LOCPLINT->castleInt->showRecruitmentWindow(bid);
+		//CRecrutationWindow *rw = LOCPLINT->castleInt->showRecruitmentWindow(bid); //TODO use me
 	}
 	ClickableL::clickLeft(down);
 }
@@ -1467,10 +1480,10 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner)
 	positions[3] += genRect(61,83,183,42), genRect(61,83,183,148), genRect(61,83,183,253);
 	positions[4] += genRect(61,83,491,325), genRect(61,83,591,325);
 	blitAt(view,332,76,bg);
-	for(int i=0; i<owner->town->town->mageLevel; i++)
+	for(size_t i=0; i<owner->town->town->mageLevel; i++)
 	{
-		int sp = owner->town->spellsAtLevel(i+1,false);
-		for(int j=0; j<sp; j++)
+		size_t sp = owner->town->spellsAtLevel(i+1,false); //spell at level with -1 hmmm?
+		for(size_t j=0; j<sp; j++)
 		{
 			if(i<owner->town->mageGuildLevel() && owner->town->spells[i].size()>j)
 			{
@@ -1485,7 +1498,7 @@ CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner)
 		}
 	}
 	SDL_FreeSurface(view);
-	for(int i=0;i<spells.size();i++)
+	for(size_t i=0;i<spells.size();i++)
 	{
 		spells[i].pos.x += pos.x;
 		spells[i].pos.y += pos.y;
@@ -1505,7 +1518,7 @@ void CMageGuildScreen::close()
 	LOCPLINT->castleInt->subInt = NULL;
 	LOCPLINT->castleInt->activate();
 }
-void CMageGuildScreen::show(SDL_Surface * to)
+void CMageGuildScreen::show(SDL_Surface * to) //TODO use me
 {
 	blitAt(bg,pos);
 	resdatabar.show();
@@ -1517,15 +1530,17 @@ void CMageGuildScreen::activate()
 	LOCPLINT->objsToBlit += this;
 	LOCPLINT->castleInt->subInt = this;
 	exit->activate();
-	for(int i=0;i<spells.size();i++)
+	for(size_t i=0;i<spells.size();i++) {
 		spells[i].activate();
+        }
 }
 void CMageGuildScreen::deactivate()
 {
 	LOCPLINT->objsToBlit -= this;
 	exit->deactivate();
-	for(int i=0;i<spells.size();i++)
+	for(size_t i=0;i<spells.size();i++) {
 		spells[i].deactivate();
+        }
 }
 void CMageGuildScreen::Scroll::clickLeft (tribool down)
 {

+ 10 - 2
CCastleInterface.h

@@ -1,6 +1,13 @@
+#ifndef CCASTLEINTERFACE_H
+#define CCASTLEINTERFACE_H
+
+#ifdef _MSC_VER
 #pragma once
+#endif
+
+
 #include "global.h"
-#include "SDL.h"
+#include <SDL.h>
 #include "CPlayerInterface.h"
 //#include "boost/tuple/tuple.hpp"
 class CGTownInstance;
@@ -220,4 +227,5 @@ public:
 	void show(SDL_Surface * to=NULL);
 	void activate();
 	void deactivate();
-};
+};
+#endif //CCASTLEINTERFACE_H

+ 1 - 1
CCursorHandler.cpp

@@ -43,7 +43,7 @@ void CCursorHandler::draw1()
 		x-=12;
 		y-=10;
 	}
-	SDL_BlitSurface(screen,&genRect(32,32,x,y),help,&genRect(32,32,0,0));
+	SDL_BlitSurface(screen, &genRect(32,32,x,y), help, &genRect(32,32,0,0));
 	blitAt(cursors[mode]->ourImages[number].bitmap,x,y);
 }
 void CCursorHandler::draw2()

+ 2 - 2
CGameInterface.cpp

@@ -27,8 +27,8 @@ CGlobalAI * CAIHandler::getNewAI(CCallback * cb, std::string dllname)
 	char temp[50];
 	dllname = "AI/"+dllname;
 	CGlobalAI * ret=NULL;
-	CGlobalAI*(*getAI)();
-	void(*getName)(char*);
+	CGlobalAI*(*getAI)(); //TODO use me
+	void(*getName)(char*); //TODO use me
 
 #ifdef _WIN32
 	HINSTANCE dll = LoadLibraryA(dllname.c_str());

+ 36 - 32
CHeroWindow.cpp

@@ -131,23 +131,25 @@ CHeroWindow::~CHeroWindow()
 	delete leftArtRoll;
 	delete rightArtRoll;
 
-	for(int g=0; g<heroListMi.size(); ++g)
+	for(size_t g=0; g<heroListMi.size(); ++g) {
 		delete heroListMi[g];
+        }
 
-	if(curBack)
+	if(curBack) {
 		SDL_FreeSurface(curBack);
+        }
 
 	delete flags;
 
 	delete garInt;
 	delete ourBar;
 
-	for(int g=0; g<artWorn.size(); ++g)
+	for(size_t g=0; g<artWorn.size(); ++g)
 	{
 		delete artWorn[g];
 	}
 	artWorn.clear();
-	for(int g=0; g<backpack.size(); ++g)
+	for(size_t g=0; g<backpack.size(); ++g)
 	{
 		delete backpack[g];
 	}
@@ -156,11 +158,11 @@ CHeroWindow::~CHeroWindow()
 	delete portraitArea;
 	delete expArea;
 	delete spellPointsArea;
-	for(int v=0; v<primSkillAreas.size(); ++v)
+	for(size_t v=0; v<primSkillAreas.size(); ++v)
 	{
 		delete primSkillAreas[v];
 	}
-	for(int v=0; v<secSkillAreas.size(); ++v)
+	for(size_t v=0; v<secSkillAreas.size(); ++v)
 	{
 		delete secSkillAreas[v];
 	}
@@ -184,11 +186,11 @@ void CHeroWindow::show(SDL_Surface *to)
 	garInt->show();
 	ourBar->show();
 
-	for(int d=0; d<artWorn.size(); ++d)
+	for(size_t d=0; d<artWorn.size(); ++d)
 	{
 		artWorn[d]->show(to);
 	}
-	for(int d=0; d<backpack.size(); ++d)
+	for(size_t d=0; d<backpack.size(); ++d)
 	{
 		backpack[d]->show(to);
 	}
@@ -223,11 +225,11 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
 	garInt->update = false;
 	gar4button->callback =  boost::bind(&CGarrisonInt::splitClick,garInt);//actualization of callback function
 
-	for(int g=0; g<primSkillAreas.size(); ++g)
+	for(size_t g=0; g<primSkillAreas.size(); ++g)
 	{
 		primSkillAreas[g]->bonus = hero->getPrimSkillLevel(g);
 	}
-	for(int g=0; g<hero->secSkills.size(); ++g)
+	for(size_t g=0; g<hero->secSkills.size(); ++g)
 	{
 		secSkillAreas[g]->type = hero->secSkills[g].first;
 		secSkillAreas[g]->bonus = hero->secSkills[g].second;
@@ -244,11 +246,11 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
 	sprintf(bufor, CGI->generaltexth->allTexts[205].substr(1, CGI->generaltexth->allTexts[205].size()-2).c_str(), hero->name.c_str(), hero->mana, hero->getPrimSkillLevel(3)*10);
 	spellPointsArea->text = std::string(bufor);
 
-	for(int g=0; g<artWorn.size(); ++g)
+	for(size_t g=0; g<artWorn.size(); ++g)
 	{
 		delete artWorn[g];
 	}
-	for(int g=0; g<backpack.size(); ++g)
+	for(size_t g=0; g<backpack.size(); ++g)
 	{
 		delete backpack[g];
 	}
@@ -273,7 +275,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
 		artWorn[g]->ourWindow = this;
 	}
 
-	for(int g=0; g<artWorn.size(); ++g)
+	for(size_t g=0; g<artWorn.size(); ++g)
 	{
 		artWorn[g]->slotID = g;
 		if(artWorn[g]->ourArt)
@@ -287,7 +289,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
 		}
 	}
 
-	for(int s=0; s<5; ++s)
+	for(size_t s=0; s<5; ++s)
 	{
 		CArtPlace * add;
 		if( s < curHero->artifacts.size() )
@@ -304,10 +306,12 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
 		add->pos.x = pos.x + 403 + 46*s;
 		add->pos.y = pos.y + 365;
 		add->pos.h = add->pos.w = 44;
-		if(s<hero->artifacts.size() && hero->artifacts[s])
+		if(s<hero->artifacts.size() && hero->artifacts[s]) {
 			add->text = hero->getArt(19+s)->Description();
-		else
+                }
+		else {
 			add->text = std::string();
+                }
 		add->ourWindow = this;
 		add->slotID = 19+s;
 		backpack.push_back(add);
@@ -347,12 +351,12 @@ void CHeroWindow::quit()
 	SDL_FreeSurface(curBack);
 	curBack = NULL;
 
-	for(int g=0; g<artWorn.size(); ++g)
+	for(size_t g=0; g<artWorn.size(); ++g)
 	{
 		delete artWorn[g];
 		artWorn[g] = NULL;
 	}
-	for(int g=0; g<backpack.size(); ++g)
+	for(size_t g=0; g<backpack.size(); ++g)
 	{
 		delete backpack[g];
 		backpack[g] = NULL;
@@ -379,27 +383,27 @@ void CHeroWindow::activate()
 	garInt->activate();
 	LOCPLINT->statusbar = ourBar;
 
-	for(int v=0; v<primSkillAreas.size(); ++v)
+	for(size_t v=0; v<primSkillAreas.size(); ++v)
 	{
 		primSkillAreas[v]->activate();
 	}
-	for(int v=0; v<curHero->secSkills.size(); ++v)
+	for(size_t v=0; v<curHero->secSkills.size(); ++v)
 	{
 		secSkillAreas[v]->activate();
 	}
 	redrawCurBack();
 
-	for(int f=0; f<artWorn.size(); ++f)
+	for(size_t f=0; f<artWorn.size(); ++f)
 	{
 		if(artWorn[f])
 			artWorn[f]->activate();
 	}
-	for(int f=0; f<backpack.size(); ++f)
+	for(size_t f=0; f<backpack.size(); ++f)
 	{
 		if(backpack[f])
 			backpack[f]->activate();
 	}
-	for(int e=0; e<heroListMi.size(); ++e)
+	for(size_t e=0; e<heroListMi.size(); ++e)
 	{
 		heroListMi[e]->activate();
 	}
@@ -423,26 +427,26 @@ void CHeroWindow::deactivate()
 
 	garInt->deactivate();
 
-	for(int v=0; v<primSkillAreas.size(); ++v)
+	for(size_t v=0; v<primSkillAreas.size(); ++v)
 	{
 		primSkillAreas[v]->deactivate();
 	}
-	for(int v=0; v<curHero->secSkills.size(); ++v)
+	for(size_t v=0; v<curHero->secSkills.size(); ++v)
 	{
 		secSkillAreas[v]->deactivate();
 	}
 
-	for(int f=0; f<artWorn.size(); ++f)
+	for(size_t f=0; f<artWorn.size(); ++f)
 	{
 		if(artWorn[f])
 			artWorn[f]->deactivate();
 	}
-	for(int f=0; f<backpack.size(); ++f)
+	for(size_t f=0; f<backpack.size(); ++f)
 	{
 		if(backpack[f])
 			backpack[f]->deactivate();
 	}
-	for(int e=0; e<heroListMi.size(); ++e)
+	for(size_t e=0; e<heroListMi.size(); ++e)
 	{
 		heroListMi[e]->deactivate();
 	}
@@ -464,7 +468,7 @@ void CHeroWindow::leftArtRoller()
 	{
 		backpackPos+=curHero->artifacts.size()-1; //set new offset
 
-		for(int s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
+		for(size_t s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
 		{
 			backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]];
 			if(backpack[s]->ourArt)
@@ -481,7 +485,7 @@ void CHeroWindow::rightArtRoller()
 	{
 		backpackPos+=1; //set new offset
 
-		for(int s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
+		for(size_t s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
 		{
 			backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ] ];
 			if(backpack[s]->ourArt)
@@ -665,7 +669,7 @@ void CHeroWindow::redrawCurBack()
 	CSDL_Ext::printAt(manastr.str(), 212, 247, GEOR16, zwykly, curBack);
 }
 
-CArtPlace::CArtPlace(const CArtifact* Art): ourArt(Art), active(false), clicked(false)/*,
+CArtPlace::CArtPlace(const CArtifact* Art): active(false), clicked(false), ourArt(Art)/*,
 	spellBook(false), warMachine1(false), warMachine2(false), warMachine3(false),
 	warMachine4(false),misc1(false), misc2(false), misc3(false), misc4(false),
 	misc5(false), feet(false), lRing(false), rRing(false), torso(false),
@@ -733,7 +737,7 @@ void CArtPlace::clickLeft(boost::logic::tribool down)
 			else
 			{
 				int backID = -1;
-				for(int g=0; g<ourWindow->backpack.size(); ++g)
+				for(size_t g=0; g<ourWindow->backpack.size(); ++g)
 				{
 					if(ourWindow->backpack[g]==this) //if user wants to put something to backpack
 					{

+ 7 - 0
CHeroWindow.h

@@ -1,4 +1,10 @@
+#ifndef CHEROWINDOW_H
+#define CHEROWINDOW_H
+
+#ifdef _MSC_VER
 #pragma once
+#endif
+
 #include "CPlayerInterface.h"
 
 class AdventureMapButton;
@@ -127,3 +133,4 @@ public:
 	friend void CArtPlace::clickLeft(tribool down);
 	friend class CPlayerInterface;
 };
+#endif //CHEROWINDOW_H

+ 7 - 5
CMT.cpp

@@ -11,8 +11,8 @@
 #include <boost/interprocess/mapped_region.hpp>
 #include <boost/interprocess/shared_memory_object.hpp>
 #include <boost/thread.hpp>
-#include "SDL_ttf.h"
-#include "SDL_mixer.h"
+#include <SDL_ttf.h>
+#include <SDL_mixer.h>
 #include "SDL_Extensions.h"
 #include "SDL_framerate.h"
 #include "CGameInfo.h"
@@ -45,6 +45,8 @@
 #include "lib/Connection.h"
 #include "lib/Interprocess.h"
 #include "lib/VCMI_Lib.h"
+#include <cstdlib>
+
 std::string NAME = NAME_VER + std::string(" (client)");
 DLL_EXPORT void initDLL(CLodHandler *b);
 SDL_Surface * screen, * screen2;
@@ -210,7 +212,7 @@ int main(int argc, char** argv)
 				LOCPLINT->pim->lock();
 				SDL_Delay(750);
 				tlog0 << "Ending...\n";
-				exit(0);
+				exit(EXIT_SUCCESS);
 			}
 			eventsM.lock();
 			events.push(ev);
@@ -232,11 +234,11 @@ void processCommand(const std::string &message, CClient *&client)
 	readed >> cn;
 	int3 src, dst;
 
-	int heronum;
+//	int heronum;//TODO use me
 	int3 dest;
 
 	if(message==std::string("die, fool"))
-		exit(0);
+		exit(EXIT_SUCCESS);
 	else if(cn==std::string("activate"))
 	{
 		int what;

+ 39 - 33
CMessage.cpp

@@ -51,12 +51,12 @@ void CMessage::init()
 			piecesOfBox.push_back(n);
 			if (i==1)
 			{
-				for (int j=0;j<bluePieces->ourImages.size();j++)
+				for (size_t j=0;j<bluePieces->ourImages.size();++j)
 				{
 					piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
 				}
 			}
-			for (int j=0;j<bluePieces->ourImages.size();j++)
+			for (size_t j=0;j<bluePieces->ourImages.size();++j)
 			{
 				graphics->blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i);
 				piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap);
@@ -74,7 +74,7 @@ void CMessage::dispose()
 {
 	for (int i=0;i<PLAYER_LIMIT;i++)
 	{
-		for (int j=0;j<piecesOfBox[i].size();j++)
+		for (size_t j=0; j<piecesOfBox[i].size(); ++j)
 		{
 			SDL_FreeSurface(piecesOfBox[i][j]);
 		}
@@ -89,21 +89,22 @@ SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor) //draws box for
 	SDL_Surface * ret = SDL_CreateRGBSurface(screen->flags, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
 	for (int i=0; i<h; i+=background->h)//background
 	{
-		for (int j=0; j<w; j+=background->w-1)
-			SDL_BlitSurface(background,&genRect(background->h,background->w-1,1,0),ret,&genRect(h,w,j,i));
+		for (int j=0; j<w; j+=background->w-1) {
+			SDL_BlitSurface(background,&genRect(background->h,background->w-1,1,0),ret,&genRect(h,w,j,i)); //FIXME taking address of temporary
+                }
 	}
 	drawBorder(playerColor, ret, w, h);
 	return ret;
 }
 
-std::vector<std::string> * CMessage::breakText(std::string text, int line, bool userBreak, bool ifor)
+std::vector<std::string> * CMessage::breakText(std::string text, size_t line, bool userBreak, bool ifor) //TODO userBreak -- use me
 {
 	std::vector<std::string> * ret = new std::vector<std::string>();
 	while (text.length()>line)
 	{
 		int whereCut = -1, braces=0;
 		bool pom = true, opened=false;
-		for (int i=0; i<line+braces; i++)
+		for (size_t i=0; i<line+braces; i++)
 		{
 			if (text[i]==10) //end of line sign
 			{
@@ -111,7 +112,7 @@ std::vector<std::string> * CMessage::breakText(std::string text, int line, bool
 				pom=false;
 				break;
 			}
-			else if (ifor && (text[i]=='{') || (text[i]=='}')) // ignore braces
+			else if (ifor && ((text[i]=='{') || (text[i]=='}'))) // ignore braces
 			{
 				if (text[i]=='{')
 					opened=true;
@@ -141,7 +142,7 @@ std::vector<std::string> * CMessage::breakText(std::string text, int line, bool
 			text.insert(0,"{");
 		}
 	}
-	for (int i=0;i<text.length();i++)
+	for (size_t i=0;i<text.length();i++)
 	{
 		if (text[i]==10) //end of line sign
 		{
@@ -152,7 +153,7 @@ std::vector<std::string> * CMessage::breakText(std::string text, int line, bool
 	}
 	if (text.length() > 0)
 		ret->push_back(text);
-	for (int i=0; i<ret->size(); i++)
+	for (size_t i=0; i<ret->size(); i++)
 	{
 		boost::algorithm::trim((*ret)[i]);
 	}
@@ -161,11 +162,11 @@ std::vector<std::string> * CMessage::breakText(std::string text, int line, bool
 std::pair<int, int> CMessage::getMaxSizes(std::vector< std::vector<SComponent*> > * komp)
 {
 	std::pair<int,int> ret;
-	for (int i=0;i<komp->size();i++)
+	for (size_t i=0;i<komp->size();i++)
 	{
 		int sumaw=0;
 		int maxh=0;
-		for(int j=0;j<(*komp)[i].size();j++)
+		for(size_t j=0;j<(*komp)[i].size();j++)
 		{
 			sumaw += (*komp)[i][j]->getImg()->w;
 			if (maxh < (*komp)[i][j]->getImg()->h)
@@ -184,10 +185,10 @@ std::pair<int,int> CMessage::getMaxSizes(std::vector<std::vector<SDL_Surface*> >
 	std::pair<int,int> ret;
 	ret.first = -1;
 	ret.second=0;
-	for (int i=0; i<txtg->size();i++) //szukamy najszerszej linii i lacznej wysokosci
+	for (size_t i=0; i<txtg->size();i++) //szukamy najszerszej linii i lacznej wysokosci
 	{
 		int lw=0;
-		for (int j=0;j<(*txtg)[i].size();j++)
+		for (size_t j=0;j<(*txtg)[i].size();j++)
 		{
 			lw+=(*txtg)[i][j]->w;
 			ret.second+=(*txtg)[i][j]->h;
@@ -201,16 +202,16 @@ std::pair<int,int> CMessage::getMaxSizes(std::vector<std::vector<SDL_Surface*> >
 }
 SDL_Surface * CMessage::blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int & curh, SDL_Surface * ret)
 {
-	for (int i=0; i<txtg->size();i++)
+	for (size_t i=0; i<txtg->size();i++)
 	{
 		int lw=0;
-		for (int j=0;j<(*txtg)[i].size();j++)
+		for (size_t j=0;j<(*txtg)[i].size();j++)
 			lw+=(*txtg)[i][j]->w; //lw - laczna szerokosc linii
 		int pw = ret->w/2;
 		pw -= lw/2; //poczatek tekstu (x)
 
 		int tw = pw;
-		for (int j=0;j<(*txtg)[i].size();j++) //blit text
+		for (size_t j=0;j<(*txtg)[i].size();j++) //blit text
 		{
 			blitAt((*txtg)[i][j],tw,curh+i*19,ret);
 			tw+=(*txtg)[i][j]->w;
@@ -223,15 +224,17 @@ SDL_Surface * CMessage::blitTextOnSur(std::vector<std::vector<SDL_Surface*> > *
 SDL_Surface * CMessage::blitCompsOnSur(std::vector<SComponent*> & comps, int maxw, int inter, int & curh, SDL_Surface * ret)
 {
 	std::vector<std::string> * brdtext;
-	if (comps.size())
+	if (comps.size()) {
 		brdtext = breakText(comps[0]->subtitle,12,true,true);
-	else
+        }
+	else {
 		brdtext = NULL;
+        }
 	comps[0]->pos.x = (ret->w/2) - ((comps[0]->getImg()->w)/2);
 	comps[0]->pos.y = curh;
 	blitAt(comps[0]->getImg(),comps[0]->pos.x,comps[0]->pos.y,ret);
 	curh += comps[0]->getImg()->h + 5; //obrazek + przerwa
-	for (int i=0; i<brdtext->size();i++) //descr.
+	for (size_t i=0; i < brdtext->size(); ++i) //descr.
 	{
 		SDL_Surface * tesu = TTF_RenderText_Blended(GEOR13,(*brdtext)[i].c_str(),zwykly);
 		blitAt(tesu,((comps[0]->getImg()->w - tesu->w)/2)+comps[0]->pos.x,curh,ret);
@@ -242,23 +245,26 @@ SDL_Surface * CMessage::blitCompsOnSur(std::vector<SComponent*> & comps, int max
 }
 SDL_Surface* CMessage::blitCompsOnSur(SDL_Surface * _or, std::vector< std::vector<SComponent*> > *  komp, int inter, int &curh, SDL_Surface *ret)
 {
-	for (int i=0;i<komp->size();i++)
+	for (size_t i=0;i<komp->size();i++)
 	{
 		int totalw=0, maxh=0;
-		for(int j=0;j<(*komp)[i].size();j++)
+		for(size_t j=0;j<(*komp)[i].size();j++)
 		{
 			totalw+=(*komp)[i][j]->getImg()->w;
-			if(maxh<(*komp)[i][j]->getImg()->h)
+			if(maxh<(*komp)[i][j]->getImg()->h) {
 				maxh=(*komp)[i][j]->getImg()->h;
+                        }
 		}
-		if(_or)
+		if(_or) {
 			totalw += (inter*2+_or->w) * ((*komp)[i].size() - 1);
-		else
+                }
+		else {
 			totalw += (inter) * ((*komp)[i].size() - 1);
+                }
 
 		curh+=maxh/2;
 		int curw = (ret->w/2)-(totalw/2);
-		for(int j=0;j<(*komp)[i].size();j++)
+		for(size_t j=0;j<(*komp)[i].size();j++)
 		{
 			blitAt((*komp)[i][j]->getImg(),curw,curh-((*komp)[i][j]->getImg()->h/2),ret);
 			(*komp)[i][j]->pos.x = curw;
@@ -285,11 +291,11 @@ std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::st
 {
 	std::vector<std::vector<SDL_Surface*> > * txtg = new std::vector<std::vector<SDL_Surface*> >();
 	txtg->resize(brtext->size());
-	for (int i=0; i<brtext->size();i++) //foreach line
+	for (size_t i=0; i<brtext->size();i++) //foreach line
 	{
 		while((*brtext)[i].length()) //jesli zostalo cos
 		{
-			int z=0; bool br=true;
+			size_t z=0; bool br=true;
 			while( ((*brtext)[i][z]) != ('{') )
 			{
 				if (z >= (((*brtext)[i].length())-1))
@@ -339,7 +345,7 @@ std::vector< std::vector<SComponent*> > * CMessage::breakComps(std::vector<SComp
 	ret->resize(1);
 	int rvi = 0;
 	int curw = 0;
-	for(int i=0;i<comps.size();i++)
+	for(size_t i=0;i<comps.size();i++)
 	{
 		curw += (comps[i]->getImg()->w + 12 + (_or ? _or->w : 0));
 		if (curw > maxw)
@@ -421,17 +427,17 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player, int
 	{
 		curh += 20; //to buttton
 		int bw = 20*(ret->buttons.size()-1); //total width of buttons - start with distance between them
-		for(int i=0; i<ret->buttons.size(); i++) //and add buttons width
+		for(size_t i=0; i<ret->buttons.size(); i++) //and add buttons width
 			bw+=ret->buttons[i]->imgs[0][0]->w; 
 		bw = (ret->bitmap->w/2) - (bw/2);
-		for(int i=0; i<ret->buttons.size(); i++)
+		for(size_t i=0; i<ret->buttons.size(); i++)
 		{
 			ret->buttons[i]->pos.x = bw + ret->pos.x;
 			ret->buttons[i]->pos.y = curh + ret->pos.y;
 			bw += ret->buttons[i]->imgs[0][0]->w + 20;
 		}
 	}
-	for(int i=0; i<ret->components.size(); i++)
+	for(size_t i=0; i<ret->components.size(); i++)
 	{
 		ret->components[i]->pos.x += ret->pos.x;
 		ret->components[i]->pos.y += ret->pos.y;
@@ -510,7 +516,7 @@ SDL_Surface * CMessage::genMessage
 		SDL_FreeSurface(titleText);
 	}
 	//draw text
-	for (int i=0; i<tekst->size(); i++)
+	for (size_t i=0; i<tekst->size(); i++)
 	{
 		int by = 37+i*21;
 		if (title.length()) by+=40;

+ 2 - 2
CMessage.h

@@ -3,7 +3,7 @@
 
 #include "global.h"
 #include <SDL_ttf.h>
-#include "SDL.h"
+#include <SDL.h>
 #include "CPreGame.h"
 
 enum EWindowType {infoOnly, infoOK, yesOrNO};
@@ -41,7 +41,7 @@ public:
 	static SDL_Surface * drawBox1(int w, int h, int playerColor=1);
 	static void drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x=0, int y=0);
 	static SDL_Surface * drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline=30, int imgToBmp=55);
-	static std::vector<std::string> * breakText(std::string text, int line=30, bool userBreak=true, bool ifor=true); //line - chars per line
+	static std::vector<std::string> * breakText(std::string text, size_t line=30, bool userBreak=true, bool ifor=true); //line - chars per line
 	CMessage();
 	static void init();
 	static void dispose();

+ 13 - 8
CPathfinder.cpp

@@ -49,28 +49,33 @@ CPath * CPathfinder::getPath(int3 src, int3 dest, const CGHeroInstance * hero, u
 
 	//graph initialization
 	graph.resize(CGI->mh->sizes.x);
-	for(int i=0; i<graph.size(); ++i)
+	for(size_t i=0; i<graph.size(); ++i)
 	{
 		graph[i].resize(CGI->mh->sizes.y);
-		for(int j=0; j<graph[i].size(); ++j)
+		for(size_t j=0; j<graph[i].size(); ++j)
 		{
 			graph[i][j].accesible = !CGI->mh->ttiles[i][j][src.z].tileInfo->blocked;
-			if(i==dest.x && j==dest.y && CGI->mh->ttiles[i][j][src.z].tileInfo->visitable)
+			if(i==dest.x && j==dest.y && CGI->mh->ttiles[i][j][src.z].tileInfo->visitable) {
 				graph[i][j].accesible = true; //for allowing visiting objects
+                        }
 			graph[i][j].dist = -1;
 			graph[i][j].theNodeBefore = NULL;
 			graph[i][j].visited = false;
 			graph[i][j].coord.x = i;
 			graph[i][j].coord.y = j;
 			graph[i][j].coord.z = dest.z;
-			if (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype==rock)
+			if (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype==rock) {
 				graph[i][j].accesible = false;
-			if ((blockLandSea) && (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype==water))
+                        }
+			if ((blockLandSea) && (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype==water)) {
 				graph[i][j].accesible = false;
-			else if ((!blockLandSea) && (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype!=water))
+                        }
+			else if ((!blockLandSea) && (CGI->mh->ttiles[i][j][src.z].tileInfo->tertype!=water)) {
 				graph[i][j].accesible = false;
-			if(graph[i][j].accesible)
+                        }
+			if(graph[i][j].accesible) {
 				graph[i][j].accesible = CGI->state->players[hero->tempOwner].fogOfWarMap[i][j][src.z];
+                        }
 		}
 	}
 
@@ -81,7 +86,7 @@ CPath * CPathfinder::getPath(int3 src, int3 dest, const CGHeroInstance * hero, u
 	std::queue<CPathNode> mq;
 	mq.push(graph[src.x][src.y]);
 
-	unsigned int curDist = 4000000000;
+	unsigned int curDist = 4000000000; //XXX 2 147 483 648 // only in C90 //but numeric limit shows 0-4294967295...confused
 
 	while(!mq.empty())
 	{

+ 12 - 7
CPlayerInterface.cpp

@@ -311,14 +311,16 @@ CGarrisonInt::~CGarrisonInt()
 {
 	if(sup)
 	{
-		for(int i=0;i<sup->size();i++)
+		for(size_t i=0;i<sup->size();i++) {
 			delete (*sup)[i];
+                }
 		delete sup;
 	}
 	if(sdown)
 	{
-		for(int i=0;i<sdown->size();i++)
-			delete (*sdown)[i];
+		for(size_t i=0;i<sdown->size();i++) {
+			delete (*sdown)[i]; //XXX what about smartpointers? boost or auto_ptr from std
+                }
 		delete sdown;
 	}
 }
@@ -327,15 +329,18 @@ void CGarrisonInt::show()
 {
 	if(sup)
 	{
-		for(int i = 0; i<sup->size(); i++)
-			if((*sup)[i])
+		for(size_t i = 0; i<sup->size(); i++)
+			if((*sup)[i]) {
 				(*sup)[i]->show();
+                        }
 	}
 	if(sdown)
 	{
-		for(int i = 0; i<sdown->size(); i++)
-			if((*sdown)[i])
+		for(size_t i = 0; i<sdown->size(); i++) {
+			if((*sdown)[i]){
 				(*sdown)[i]->show();
+                        }
+                }
 	}
 }
 void CGarrisonInt::deactiveteSlots()

+ 98 - 45
CPreGame.cpp

@@ -1,11 +1,11 @@
 #include "stdafx.h"
 #include "CPreGame.h"
 #include "hch/CDefHandler.h"
-#include "SDL.h"
-#include "boost/filesystem.hpp"   // includes all needed Boost.Filesystem declarations
-#include "boost/algorithm/string.hpp"
+#include <SDL.h>
+#include <boost/filesystem.hpp>   // includes all needed Boost.Filesystem declarations
+#include <boost/algorithm/string.hpp>
 //#include "boost/foreach.hpp"
-#include "zlib.h"
+#include <zlib.h>
 #include "timeHandler.h"
 #include <sstream>
 #include "SDL_Extensions.h"
@@ -19,9 +19,12 @@
 #include "client/Graphics.h"
 #include <boost/thread.hpp>
 #include <boost/bind.hpp>
+#include <cstdlib>
+
 extern SDL_Surface * screen;
 extern SDL_Color tytulowy, tlo, zwykly ;
 extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
+
 #ifdef min
 #undef min
 #endif
@@ -270,7 +273,10 @@ void Slider::handleIt(SDL_Event sEvent)
 		case (SDLK_DOWN):
 			CPG->ourScenSel->mapsel.moveByOne(false);
 			break;
-		}
+                default:
+                    //TODO do something nasty here like logs entry..
+                break;
+                }
 	}
 	else if (moving && sEvent.type==SDL_MOUSEMOTION)
 	{
@@ -538,13 +544,13 @@ void Options::OptionSwitch::press(bool down)
 void Options::PlayerFlag::press(bool down)
 {
 	HighButton::press(down);
-	int i=0;
+	size_t i=0;
 	for(;i<CPG->ret.playerInfos.size();i++)
 		if(CPG->ret.playerInfos[i].color==color)
 			break;
 	if (CPG->ret.playerInfos[i].human || (!CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].players[CPG->ret.playerInfos[i].color].canHumanPlay))
 		return; //if this is already human player, or if human is forbidden
-	int j=0;
+	size_t j=0;
 	for(;j<CPG->ret.playerInfos.size();j++)
 		if(CPG->ret.playerInfos[j].human)
 			break;
@@ -583,7 +589,7 @@ void Options::showIcon (int what, int nr, bool abs) //what: -1=castle, 0=hero, 1
 	else
 	{
 		ab = nr;
-		for (int i=0; i<CPG->ret.playerInfos.size();i++)
+		for (size_t i=0; i<CPG->ret.playerInfos.size();++i)
 		{
 			if (CPG->ret.playerInfos[i].color==nr)
 			{
@@ -661,11 +667,15 @@ void Options::showIcon (int what, int nr, bool abs) //what: -1=castle, 0=hero, 1
 }
 Options::~Options()
 {
-	if (!inited) return;
-	for (int i=0; i<bgs.size();i++)
+	if (!inited) {
+            return;
+        }
+	for (size_t i=0; i<bgs.size();i++) {
 		SDL_FreeSurface(bgs[i]);
-	for (int i=0; i<flags.size();i++)
+        }
+	for (size_t i=0; i<flags.size();i++) {
 		delete flags[i];
+        }
 	SDL_FreeSurface(bg);
 	SDL_FreeSurface(rHero);
 	SDL_FreeSurface(rCastle);
@@ -716,7 +726,7 @@ void Options::show()
 	MapSel & ms = CPG->ourScenSel->mapsel;
 	blitAt(bg,3,6);
 	CPG->ourScenSel->listShowed=false;
-	for (int i=0;i<CPG->btns.size();i++)
+	for (size_t i=0; i < CPG->btns.size(); ++i)
 	{
 		if (CPG->btns[i]->ID!=10) //leave only right panel buttons
 		{
@@ -728,12 +738,13 @@ void Options::show()
 	CSDL_Ext::printAtMiddle("Advanced Options",225,35,GEORXX);
 	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[521],224,544,GEOR13); // Player Turn Duration
 	int playersSoFar=0;
-	for (int i=0;i<PLAYER_LIMIT;i++)
+	for (size_t i=0; i < PLAYER_LIMIT; ++i)
 	{
 		if (!(ms.ourMaps[ms.selected].players[i].canComputerPlay || ms.ourMaps[ms.selected].players[i].canComputerPlay))
 			continue;
-		for (int hi=0; hi<ms.ourMaps[ms.selected].players[i].heroesNames.size(); hi++)
+		for (size_t hi=0; hi<ms.ourMaps[ms.selected].players[i].heroesNames.size(); hi++) {
 			usedHeroes.insert(ms.ourMaps[ms.selected].players[i].heroesNames[hi].heroID);
+                }
 		blitAt(bgs[i],57,128+playersSoFar*50);
 		poptions.push_back(new PlayerOptions(playersSoFar,i));
 		poptions[poptions.size()-1]->nr=playersSoFar;
@@ -755,14 +766,17 @@ void Options::show()
 		{
 			poptions[poptions.size()-1]->flag.show();
 			CPG->btns.push_back(&poptions[poptions.size()-1]->flag);
-			if (ms.ourMaps[ms.selected].players[i].canComputerPlay)
+			if (ms.ourMaps[ms.selected].players[i].canComputerPlay) {
 				CSDL_Ext::printAtMiddleWB("Human or CPU",86,163+playersSoFar*50,GEORM,7,zwykly);
-			else
+                        }
+			else {
 				CSDL_Ext::printAtMiddleWB("Human",86,163+playersSoFar*50,GEORM,6,zwykly);
+                        }
 
 		}
-		else
+		else {
 			CSDL_Ext::printAtMiddleWB("CPU",86,163+playersSoFar*50,GEORM,6,zwykly);
+                }
 		playersSoFar++;
 	}
 	CSDL_Ext::printAtMiddleWB(CGI->generaltexth->allTexts[516],221,63,GEOR13,55,zwykly);
@@ -771,8 +785,9 @@ void Options::show()
 	CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[260].second),275,109,GEOR13,10);
 	CSDL_Ext::printAtMiddleWB(CGI->generaltexth->getTitle(CGI->generaltexth->zelp[261].second),354,109,GEOR13,10);
 	turnLength->activate();
-	for (int i=0;i<poptions.size();i++)
+	for (size_t i=0; i < poptions.size(); ++i) {
 		showIcon(-2,i,false);
+        }
 	for(int i=0;i<12;i++)
 		turnLength->moveDown();
 	//SDL_Flip(screen);
@@ -780,23 +795,28 @@ void Options::show()
 }
 void Options::hide()
 {
-	if (!showed) return;
+	if (!showed) {
+            return;
+        }
 	PreGameTab::hide();
-	for (int i=0; i<CPG->btns.size();i++)
+	for (size_t i=0; i < CPG->btns.size(); ++i)
 		if (CPG->btns[i]->ID==7)
 			CPG->btns.erase(CPG->btns.begin()+i--);
-	for (int i=0;i<poptions.size();i++)
+	for (size_t i=0;i<poptions.size();i++) {
 		delete poptions[i];
+        }
 	poptions.clear();
 	turnLength->deactivate();
 }
 MapSel::~MapSel()
 {
 	SDL_FreeSurface(bg);
-	for (int i=0;i<scenImgs.size();i++)
+	for (size_t i=0; i < scenImgs.size(); ++i) {
 		SDL_FreeSurface(scenImgs[i]);
-	for (int i=0;i<scenList.size();i++)
+        }
+	for (size_t i=0; i < scenList.size(); ++i) {
 		delete scenList[i];
+        }
 	delete sFlags;
 }
 int MapSel::countWL()
@@ -804,9 +824,12 @@ int MapSel::countWL()
 	int ret=0;
 	for (int i=0;i<ourMaps.size();i++)
 	{
-		if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
+		if (sizeFilter && ((ourMaps[i].width) != sizeFilter)) {
 			continue;
-		else ret++;
+                }
+		else {
+                    ret++;
+                }
 	}
 	return ret;
 }
@@ -815,11 +838,14 @@ void MapSel::printMaps(int from, int to, int at, bool abs)
 	if (true)//
 	{
 		int help=-1;
-		for (int i=0;i<ourMaps.size();i++)
+		for (size_t i=0; i < ourMaps.size(); ++i)
 		{
-			if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
+			if (sizeFilter && ((ourMaps[i].width) != sizeFilter)) {
 				continue;
-			else help++;
+                        }
+			else {
+                            help++;
+                        }
 			if (help==from)
 			{
 				from=i;
@@ -1468,7 +1494,7 @@ void CPreGame::showScenSel()
 		ourScenSel->mapsel.select(0,false);
 
 
-		for (int i=0;i<btns.size();i++)
+		for (size_t i=0; i < btns.size(); ++i)
 		{
 			btns[i]->pos.w=btns[i]->imgs->ourImages[0].bitmap->w;
 			btns[i]->pos.h=btns[i]->imgs->ourImages[0].bitmap->h;
@@ -1704,7 +1730,7 @@ void CPreGame::hideBox ()
 	SDL_BlitSurface(behindCurMes,NULL,screen,currentMessage);
 	SDL_UpdateRect
 		(screen,currentMessage->x,currentMessage->y,currentMessage->w,currentMessage->h);
-	for (int i=0;i<btns.size();i++)
+	for (size_t i=0; i < btns.size(); ++i)
 	{
 		if (btns[i]->ID==2)
 		{
@@ -1742,7 +1768,7 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent)
 
 	if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT))
 	{
-		for (int i=0;i<btns.size(); i++)
+		for (size_t i=0; i < btns.size(); ++i)
 		{
 			if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
 			{
@@ -1766,7 +1792,7 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent)
 			ourScenSel->pressed->press(false);
 			ourScenSel->pressed=NULL;
 		}
-		for (int i=0;i<btns.size(); i++)
+		for (size_t i=0; i < btns.size(); ++i)
 		{
 			if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
 			{
@@ -1802,7 +1828,7 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent)
 				highlighted = NULL;
 			}
 		}
-		for (int i=0;i<btns.size();i++)
+		for (size_t i=0; i < btns.size(); ++i)
 		{
 			if (!btns[i]->highlightable)
 				continue;
@@ -1829,11 +1855,12 @@ StartInfo CPreGame::runLoop()
 				menuItems * current = currentItems();
 				if(sEvent.type==SDL_QUIT)
 				{
-					exit(0);
+					exit(EXIT_SUCCESS);
 					return ret;
 				}
-				for (int i=0;i<interested.size();i++)
+				for (size_t i=0; i < interested.size(); ++i) {
 					interested[i]->handleIt(sEvent);
+                }
 				if (!current)
 				{
 					(this->*handleOther)(sEvent);
@@ -1842,11 +1869,11 @@ StartInfo CPreGame::runLoop()
 				{
 					if (sEvent.key.keysym.sym==SDLK_q)
 					{
-						exit(0);
+						exit(EXIT_SUCCESS);
 					}
 					if(sEvent.key.keysym.sym==SDLK_F4 && (sEvent.key.keysym.mod & KMOD_LALT)) //Alt+F4
 					{
-						exit(0);
+						exit(EXIT_SUCCESS);
 					}
 					/*if (state==EState::newGame)
 					{
@@ -1972,7 +1999,7 @@ StartInfo CPreGame::runLoop()
 				else if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT))
 				{
 					mush->playClick();
-					for (int i=0;i<btns.size(); i++)
+					for (size_t i=0; i < btns.size(); ++i)
 					{
 						if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
 						{
@@ -2010,7 +2037,7 @@ StartInfo CPreGame::runLoop()
 				}
 				else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
 				{
-					for (int i=0;i<btns.size(); i++)
+					for (size_t i=0; i < btns.size(); ++i)
 					{
 						if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
 						((Button*)btns[i])->fun();
@@ -2312,12 +2339,38 @@ ScenSel::ScenSel()
 	selectedDiff=-77;
 	difficulty->gdzie = &selectedDiff;
 
-	for (int i=0; i<bScens.imgs->ourImages.size(); i++)
-		CSDL_Ext::printAt(CGI->generaltexth->allTexts[500],25+i,2+i,GEOR13,zwykly,bScens.imgs->ourImages[i].bitmap); //"Show Available Scenarios"
-	for (int i=0; i<bRandom.imgs->ourImages.size(); i++)
-		CSDL_Ext::printAt(CGI->generaltexth->allTexts[740],25+i,2+i,GEOR13,zwykly,bRandom.imgs->ourImages[i].bitmap);
-	for (int i=0; i<bOptions.imgs->ourImages.size(); i++)
-		CSDL_Ext::printAt(CGI->generaltexth->allTexts[501],25+i,2+i,GEOR13,zwykly,bOptions.imgs->ourImages[i].bitmap); //"Show Advanced Options"
+	for (size_t i=0; i < bScens.imgs->ourImages.size(); ++i) {
+		CSDL_Ext::printAt(
+            CGI->generaltexth->allTexts[500],
+                25+i,
+                2+i,
+                GEOR13,
+                zwykly,
+                bScens.imgs->ourImages[i].bitmap
+        ); //"Show Available Scenarios"
+    }
+
+    for (size_t i=0; i < bRandom.imgs->ourImages.size(); ++i) {
+		CSDL_Ext::printAt(
+            CGI->generaltexth->allTexts[740],
+            25+i,
+            2+i,
+            GEOR13,
+            zwykly,
+            bRandom.imgs->ourImages[i].bitmap
+        );
+    }
+	
+    for (size_t i=0; i < bOptions.imgs->ourImages.size(); ++i) {
+		CSDL_Ext::printAt(
+            CGI->generaltexth->allTexts[501],
+            25+i,
+            2+i,
+            GEOR13,
+            zwykly,
+            bOptions.imgs->ourImages[i].bitmap
+        ); //"Show Advanced Options"
+    }
 }
 
 ScenSel::~ScenSel()

+ 5 - 3
CPreGame.h

@@ -2,13 +2,15 @@
 #define CPREGAME_H
 #include "global.h"
 #include <set>
-#include "SDL.h"
+#include <SDL.h>
 #include "StartInfo.h"
 #include "CMessage.h"
 #include "map.h"
 #include "hch/CMusicHandler.h"
 #include <boost/function.hpp>
 #include <boost/bind.hpp>
+#include <cstdlib>
+
 class CPreGame;
 class CDefHandler;
 extern CPreGame * CPG;
@@ -94,7 +96,7 @@ public:
 class CPoinGroup :public CGroup
 {
 public:
-	int * gdzie; //where (po polsku, bo by by³o s³owo kluczowe :/)
+	int * gdzie; //where (po polsku, bo by by�o s�owo kluczowe :/)
 	void setYour(IntSelBut * your);
 };
 struct IntSelBut: public Button
@@ -268,7 +270,7 @@ public:
 	void scenHandleEv(SDL_Event& sEvent);
 	void begin(){run=false;ret.difficulty=ourScenSel->selectedDiff;};
 	void quitAskBox();
-	void quit(){exit(0);};
+	void quit(){exit(EXIT_SUCCESS);};
 	void initScenSel();
 	void showScenSel();
 	void showScenList();

+ 4 - 0
CThreadHelper.h

@@ -1,3 +1,6 @@
+#ifndef CTHREADHELPER_H
+#define CTHREADHELPER_H
+
 #include "global.h"
 #include <boost/function.hpp>
 #include <boost/thread.hpp>
@@ -36,3 +39,4 @@ template <typename T> inline void setData(T * data, boost::function<T()> func)
 	(GET_DATA \
 		(CDefEssential*,DESTINATION,\
 		boost::function<CDefEssential*()>(boost::bind(CDefHandler::giveDefEss,DEF_NAME,(CLodHandler*)NULL))))
+#endif //CTHREADHELPER_H

+ 9 - 8
SDL_Extensions.cpp

@@ -74,18 +74,19 @@ void CSDL_Ext::printAtMiddleWB(const std::string & text, int x, int y, TTF_Font
 	std::vector<std::string> * ws = CMessage::breakText(text,charpr);
 	std::vector<SDL_Surface*> wesu;
 	wesu.resize(ws->size());
-	for (int i=0;i<wesu.size();i++)
+	for (size_t i=0; i < wesu.size(); ++i) {
 		wesu[i]=TTF_RenderText_Blended(font,(*ws)[i].c_str(),kolor);
+    }
 
 	int tox=0, toy=0;
-	for (int i=0;i<wesu.size();i++)
+	for (size_t i=0; i < wesu.size(); ++i)
 	{
 		toy+=wesu[i]->h;
 		if (tox < wesu[i]->w)
 			tox=wesu[i]->w;
 	}
 	int evx, evy = y - (toy/2);
-	for (int i=0;i<wesu.size();i++)
+	for (size_t i=0; i < wesu.size(); ++i)
 	{
 		evx = (x - (tox/2)) + ((tox-wesu[i]->w)/2);
 		blitAt(wesu[i],evx,evy,dst);
@@ -93,7 +94,7 @@ void CSDL_Ext::printAtMiddleWB(const std::string & text, int x, int y, TTF_Font
 	}
 
 
-	for (int i=0;i<wesu.size();i++)
+	for (size_t i=0; i < wesu.size(); ++i)
 		SDL_FreeSurface(wesu[i]);
 	delete ws;
 }
@@ -102,17 +103,17 @@ void CSDL_Ext::printAtWB(const std::string & text, int x, int y, TTF_Font * font
 	std::vector<std::string> * ws = CMessage::breakText(text,charpr);
 	std::vector<SDL_Surface*> wesu;
 	wesu.resize(ws->size());
-	for (int i=0;i<wesu.size();i++)
+	for (size_t i=0; i < wesu.size(); ++i)
 		wesu[i]=TTF_RenderText_Blended(font,(*ws)[i].c_str(),kolor);
 
 	int evy = y;
-	for (int i=0;i<wesu.size();i++)
+	for (size_t i=0; i < wesu.size(); ++i)
 	{
 		blitAt(wesu[i],x,evy,dst);
 		evy+=wesu[i]->h;
 	}
 
-	for (int i=0;i<wesu.size();i++)
+	for (size_t i=0; i < wesu.size(); ++i)
 		SDL_FreeSurface(wesu[i]);
 	delete ws;
 }
@@ -783,7 +784,7 @@ int readNormalNr (std::istream &in, int bytCon)
 
 std::string CSDL_Ext::processStr(std::string str, std::vector<std::string> & tor)
 {
-	for (int i=0;(i<tor.size())&&(boost::find_first(str,"%s"));i++)
+	for (size_t i=0; (i<tor.size())&&(boost::find_first(str,"%s")); ++i)
 	{
 		boost::replace_first(str,"%s",tor[i]);
 	}

+ 4 - 4
client/CBitmapHandler.cpp

@@ -55,7 +55,7 @@ void CPCXConv::convert()
 	BMPHeader bh;
 	BMPPalette pal[256];
 	Epcxformat format;
-	int fSize,i,y;
+	int fSize,y;//,i; //TODO use me 'i'
 	bool check1, check2;
 	unsigned char add;
 	int it=0;
@@ -157,7 +157,7 @@ void CPCXConv::convert()
 	std::string temp = out.str();
 	bmp = new unsigned char[temp.length()];
 	bmps=temp.length();
-	for (int a=0;a<temp.length();a++)
+	for (size_t a=0;a<temp.length();++a)
 	{
 		bmp[a]=temp[a];
 	}
@@ -169,7 +169,7 @@ SDL_Surface * CPCXConv::getSurface()
 
 	BMPHeader bh;
 	Epcxformat format;
-	int fSize,i,y;
+	int fSize,y;//,i; //TODO use me 'i'
 	bool check1, check2;
 	unsigned char add;
 	int it=0;
@@ -314,7 +314,7 @@ SDL_Surface * BitmapHandler::loadBitmap(std::string fname, bool setKey)
 					CPCXConv cp;
 					pcx = new unsigned char[e->realSize];
 					memcpy(pcx,sign,3);
-					int res = fread((char*)pcx+3, 1, e->realSize-3, f);
+					int res = fread((char*)pcx+3, 1, e->realSize-3, f); //TODO use me
 					fclose(f);
 					cp.openPCX((char*)pcx,e->realSize);
 					return cp.getSurface();

+ 9 - 1
client/CBitmapHandler.h

@@ -1,4 +1,11 @@
+#ifndef CBITMAPHANDLER_H
+#define CBITMAPHANDLER_H
+
+#ifdef _MSC_VER
 #pragma once
+#endif
+
+
 #include "../global.h"
 struct SDL_Surface;
 class CLodHandler;
@@ -36,4 +43,5 @@ namespace BitmapHandler
 {
 	extern CLodHandler *bitmaph;
 	SDL_Surface * loadBitmap(std::string fname, bool setKey=false);
-};
+};
+#endif //CBITMAPHANDLER_H

+ 4 - 1
client/CConfigHandler.h

@@ -1,3 +1,5 @@
+#ifndef CCONFIGHANDLER_H
+#define CCONFIGHANDLER_H
 #pragma once
 #include "../global.h"
 class CAdvMapInt;
@@ -61,4 +63,5 @@ namespace config
 		~CConfigHandler(void);
 	};
 }
-extern config::CConfigHandler conf;
+extern config::CConfigHandler conf;
+#endif //CCONFIGHANDLER_H

+ 20 - 13
client/CCreatureAnimation.cpp

@@ -14,7 +14,7 @@ void CCreatureAnimation::setType(int type)
 		if(SEntries[curFrame].group!=type) //rewind
 		{
 			int j=-1; //first frame in displayed group
-			for(int g=0; g<SEntries.size(); ++g)
+			for(size_t g=0; g<SEntries.size(); ++g)
 			{
 				if(SEntries[g].group==type && j==-1)
 				{
@@ -22,14 +22,16 @@ void CCreatureAnimation::setType(int type)
 					break;
 				}
 			}
-			if(curFrame!=-1)
+			if(curFrame != -1) {
 				curFrame = j;
+                        }
 		}
 	}
 	else
 	{
-		if(curFrame>=frames)
+		if(curFrame>=frames) {
 			curFrame = 0;
+                }
 	}
 }
 
@@ -67,8 +69,8 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL)
 			SEntries.push_back(SEntry());
 			SEntries[j].group = group;
 		}
-		int unknown2 = readNormalNr(i,4); i+=4;
-		int unknown3 = readNormalNr(i,4); i+=4;
+		int unknown2 = readNormalNr(i,4); i+=4; //TODO use me
+		int unknown3 = readNormalNr(i,4); i+=4; //TODO use me
 		for (j=0; j<totalInBlock; j++)
 		{
 			for (int k=0;k<13;k++) Buffer[k]=FDef[i+k]; 
@@ -78,7 +80,7 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL)
 		for (j=0; j<totalInBlock; j++)
 		{ 
 			SEntries[totalEntries+j].offset = readNormalNr(i,4);
-			int unknown4 = readNormalNr(i,4); i+=4;
+			int unknown4 = readNormalNr(i,4); i+=4; //TODO use me
 		}
 		//totalEntries+=totalInBlock;
 		for(int hh=0; hh<totalInBlock; ++hh)
@@ -132,7 +134,7 @@ void CCreatureAnimation::incrementFrame()
 		if(curFrame==SEntries.size() || SEntries[curFrame].group!=type) //rewind
 		{
 			int j=-1; //first frame in displayed group
-			for(int g=0; g<SEntries.size(); ++g)
+			for(size_t g=0; g<SEntries.size(); ++g)
 			{
 				if(SEntries[g].group==type)
 				{
@@ -175,7 +177,7 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
 	unsigned char SegmentType, SegmentLength;
 	
 	i=BaseOffset=SEntries[SIndex].offset;
-	int prSize=readNormalNr(i,4,FDef);i+=4;
+	int prSize=readNormalNr(i,4,FDef);i+=4;//TODO use me
 	int defType2 = readNormalNr(i,4,FDef);i+=4;
 	FullWidth = readNormalNr(i,4,FDef);i+=4;
 	FullHeight = readNormalNr(i,4,FDef);i+=4;
@@ -261,7 +263,7 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
 int CCreatureAnimation::framesInGroup(int group) const
 {
 	int ret = 0; //number of frames in given group
-	for(int g=0; g<SEntries.size(); ++g)
+	for(size_t g=0; g<SEntries.size(); ++g)
 	{
 		if(SEntries[g].group == group)
 			++ret;
@@ -276,10 +278,15 @@ CCreatureAnimation::~CCreatureAnimation()
 		delete [] RLEntries;
 }
 
-void CCreatureAnimation::putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const
-{
-	if(palc!=0)
-	{
+inline void CCreatureAnimation::putPixel(
+        SDL_Surface * dest,
+        const int & ftcp,
+        const BMPPalette & color,
+        const unsigned char & palc,
+        const bool & yellowBorder
+) const {
+	
+    if(palc!=0) {
 		Uint8 * p = (Uint8*)dest->pixels + ftcp*3;
 		if(palc > 7) //normal color
 		{

+ 15 - 2
client/CCreatureAnimation.h

@@ -1,4 +1,10 @@
+#ifndef CCREATUREANIMATION_H
+#define CCREATUREANIMATION_H
+
+#ifdef _MSC_VER
 #pragma once
+#endif
+
 #include "../global.h"
 #include "../CPlayerInterface.h"
 #include "../hch/CDefHandler.h"
@@ -19,12 +25,18 @@ private:
 	std::vector<SEntry> SEntries ;
 	std::string defName, curDir;
 	int readNormalNr (int pos, int bytCon, unsigned char * str=NULL) const;
-	void inline putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const;
+	void putPixel(
+                SDL_Surface * dest,
+                const int & ftcp,
+                const BMPPalette & color,
+                const unsigned char & palc,
+                const bool & yellowBorder
+        ) const;
 
 	////////////
 
 	unsigned char * FDef; //animation raw data
-	unsigned int curFrame; //number of currently displayed frame
+	int curFrame; //number of currently displayed frame
 	unsigned int frames; //number of frames
 public:
 	int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
@@ -42,3 +54,4 @@ public:
 
 	int framesInGroup(int group) const; //retirns number of fromes in given group
 };
+#endif //CCREATUREANIMATION_H

+ 16 - 9
client/CSpellWindow.cpp

@@ -65,9 +65,14 @@ void SpellbookInteractiveArea::deactivate()
 	Hoverable::deactivate();
 }
 
-CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHero): selectedTab(4), spellSite(0), battleSpellsOnly(true)
+CSpellWindow::CSpellWindow(
+        const SDL_Rect & myRect,
+        const CGHeroInstance * myHero):
+        battleSpellsOnly(true),
+        selectedTab(4),
+        spellSite(0)
 {
-	//for testing only
+	//XXX for testing only
 	//mySpells = myHero->spells;
 	for(ui32 v=0; v<CGI->spellh->spells.size(); ++v)
 	{
@@ -76,7 +81,7 @@ CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHer
 	}
 
 	for(int b=0; b<4; ++b) schoolLvls[b] = 0;
-	for(int b=0; b<myHero->secSkills.size(); ++b)
+	for(size_t b=0; b<myHero->secSkills.size(); ++b)
 	{
 		switch(myHero->secSkills[b].first)
 		{
@@ -304,7 +309,7 @@ void CSpellWindow::fexitb()
 {
 	deactivate();
 
-	for(int g=0; g<LOCPLINT->objsToBlit.size(); ++g)
+	for(size_t g=0; g<LOCPLINT->objsToBlit.size(); ++g) //TODO what about
 	{
 		if(dynamic_cast<CSpellWindow*>(LOCPLINT->objsToBlit[g]))
 		{
@@ -415,7 +420,7 @@ void CSpellWindow::show(SDL_Surface *to)
 	{
 		if(spellAreas[b]->mySpell == -1)
 			continue;
-		int b2 = -1;
+		//int b2 = -1; //TODO use me
 
 		blitAt(spells->ourImages[spellAreas[b]->mySpell].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to);
 
@@ -540,19 +545,21 @@ void CSpellWindow::computeSpellsPerArea()
 	//applying
 	if(selectedTab == 4 || spellSite != 0)
 	{
-		for(int c=0; c<12; ++c)
+		for(size_t c=0; c<12; ++c)
 		{
-			if(c<spellsCurSite.size())
+			if(c<spellsCurSite.size()) {
 				spellAreas[c]->mySpell = spellsCurSite[c];
-			else
+                        }
+			else {
 				spellAreas[c]->mySpell = -1;
+                        }
 		}
 	}
 	else
 	{
 		spellAreas[0]->mySpell = -1;
 		spellAreas[1]->mySpell = -1;
-		for(int c=0; c<10; ++c)
+		for(size_t c=0; c<10; ++c)
 		{
 			if(c<spellsCurSite.size())
 				spellAreas[c+2]->mySpell = spellsCurSite[c];

+ 7 - 0
client/CSpellWindow.h

@@ -1,4 +1,10 @@
+#ifndef CSPELLWINDOW_H
+#define CSPELLWINDOW_H
+
+#ifdef _MSC_VER
 #pragma once
+#endif
+
 #include "../global.h"
 #include "../CPlayerInterface.h"
 
@@ -86,3 +92,4 @@ public:
 	void deactivate();
 	void show(SDL_Surface * to = NULL);
 };
+#endif //CSPELLWINDOW_H

+ 15 - 9
client/Client.cpp

@@ -23,7 +23,7 @@ CSharedCond<std::set<IPack*> > mess(new std::set<IPack*>);
 std::string toString(MetaString &ms)
 {
 	std::string ret;
-	for(int i=0;i<ms.message.size();i++)
+	for(size_t i=0;i<ms.message.size();++i)
 	{
 		if(ms.message[i]>0)
 		{
@@ -87,7 +87,7 @@ std::string toString(MetaString &ms)
 			}
 		}
 	}
-	for(int i=0;i<ms.replacements.size();i++)
+	for(size_t i=0; i < ms.replacements.size(); ++i)
 	{
 		ret.replace(ret.find("%s"),2,ms.replacements[i]);
 	}
@@ -111,8 +111,9 @@ CClient::CClient(CConnection *con, StartInfo *si)
 	c >> pom8;
 	if(pom8) throw "Server cannot open the map!";
 	c << ui8(si->playerInfos.size()+1); //number of players + neutral
-	for(int i=0;i<si->playerInfos.size();i++)
+	for(size_t i=0;i<si->playerInfos.size();i++) {
 		c << ui8(si->playerInfos[i].color); //players
+        }
 	c << ui8(255); // neutrals
 
 
@@ -144,14 +145,16 @@ CClient::CClient(CConnection *con, StartInfo *si)
 	CGI->mh->init();
 	tlog0 <<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
 
-	for (int i=0; i<CGI->state->scenarioOps->playerInfos.size();i++) //initializing interfaces for players
+	for (size_t i=0; i<CGI->state->scenarioOps->playerInfos.size();++i) //initializing interfaces for players
 	{ 
 		ui8 color = gs->scenarioOps->playerInfos[i].color;
 		CCallback *cb = new CCallback(gs,color,this);
-		if(!gs->scenarioOps->playerInfos[i].human)
+		if(!gs->scenarioOps->playerInfos[i].human) {
 			playerint[color] = static_cast<CGameInterface*>(CAIHandler::getNewAI(cb,conf.cc.defaultAI));
-		else 
+                }
+		else {
 			playerint[color] = new CPlayerInterface(color,i);
+                }
 		gs->currentPlayer = color;
 		playerint[color]->init(cb);
 	}
@@ -200,8 +203,9 @@ void CClient::process(int what)
 			InfoWindow iw;
 			*serv >> iw;
 			std::vector<Component*> comps;
-			for(int i=0;i<iw.components.size();i++)
+			for(size_t i=0;i<iw.components.size();i++) {
 				comps.push_back(&iw.components[i]);
+                        }
 			std::string str = toString(iw.text);
 			playerint[iw.player]->showInfoDialog(str,comps);
 			break;
@@ -496,8 +500,9 @@ void CClient::process(int what)
 			*serv >> sd;
 			tlog5 << "Showing selection dialog " <<std::endl;
 			std::vector<Component*> comps;
-			for(int i=0;i<sd.components.size();i++)
+			for(size_t i=0; i < sd.components.size(); ++i) {
 				comps.push_back(&sd.components[i]);
+                        }
 			std::string str = toString(sd.text);
 			playerint[sd.player]->showSelDialog(str,comps,sd.id);
 			break;
@@ -508,8 +513,9 @@ void CClient::process(int what)
 			*serv >> ynd;
 			tlog5 << "Showing yes/no dialog " <<std::endl;
 			std::vector<Component*> comps;
-			for(int i=0;i<ynd.components.size();i++)
+			for(size_t i=0; i < ynd.components.size(); ++i) {
 				comps.push_back(&ynd.components[i]);
+                        }
 			std::string str = toString(ynd.text);
 			playerint[ynd.player]->showYesNoDialog(str,comps,ynd.id);
 			break;

+ 7 - 0
client/Client.h

@@ -1,4 +1,10 @@
+#ifndef CLIENT_H
+#define CLIENT_H
+
+#ifdef _MSC_VER
 #pragma once
+#endif
+
 #include "../global.h"
 #include <boost/thread.hpp>
 struct StartInfo;
@@ -56,3 +62,4 @@ public:
 	friend class CScriptCallback; //for objects scripts
 	friend void processCommand(const std::string &message, CClient *&client); //handling console
 };
+#endif //CLIENT_H

+ 15 - 4
client/FunctionList.h

@@ -1,4 +1,10 @@
+#ifndef FUNCTIONLIST_H
+#define FUNCTIONLIST_H
+
+#ifdef _MSC_VER
 #pragma  once
+#endif
+
 #include <boost/function.hpp>
 
 template<typename Signature>
@@ -38,15 +44,17 @@ public:
 	void operator()() const
 	{
 		std::vector<boost::function<Signature> > funcs2 = funcs; //backup
-		for(int i=0;i<funcs2.size(); i++)
+		for(size_t i=0;i<funcs2.size(); ++i) {
 			funcs2[i]();
+                }
 	}
 	template <typename Arg> 
 	void operator()(const Arg & a) const
 	{
 		std::vector<boost::function<Signature> > funcs2 = funcs; //backup
-		for(int i=0;i<funcs2.size(); i++)
+		for(int i=0;i<funcs2.size(); i++) {
 			funcs2[i](a);
+                }
 	}
 };
 
@@ -88,7 +96,10 @@ public:
 	void operator()(const Arg & a) const
 	{
 		std::vector<boost::function<Signature> > funcs2 = funcs; //backup
-		for(int i=0;i<funcs2.size(); i++)
+		for(size_t i=0;i<funcs2.size(); ++i) {
 			funcs2[i](a);
+                }
 	}
-};
+};
+
+#endif //FUNCTIONLISt_H

+ 10 - 10
client/Graphics.cpp

@@ -236,13 +236,13 @@ Graphics::Graphics()
 
 	//handling 32x32px imgs
 	smi->notFreeImgs = true;
-	for (int i=0; i<smi->ourImages.size(); i++)
+	for (size_t i=0; i<smi->ourImages.size(); ++i)
 	{
 		smallImgs[i-2] = smi->ourImages[i].bitmap;
 	}
 	delete smi;
 	smi2->notFreeImgs = true;
-	for (int i=0; i<smi2->ourImages.size(); i++)
+	for (size_t i=0; i<smi2->ourImages.size(); ++i)
 	{
 		bigImgs[i-2] = smi2->ourImages[i].bitmap;
 	}
@@ -260,7 +260,7 @@ void Graphics::loadHeroPortraits()
 		std::string path;
 		of>>path;
 		portraitSmall.push_back(BitmapHandler::loadBitmap(path));
-		for(int ff=0; ff<path.size(); ++ff) //size letter is usually third one, but there are exceptions an it should fix the problem
+		for(size_t ff=0; ff<path.size(); ++ff) //size letter is usually third one, but there are exceptions an it should fix the problem
 		{
 			if(path[ff]=='S')
 			{
@@ -279,7 +279,7 @@ void Graphics::loadHeroAnim(std::vector<CDefHandler **> & anims)
 	std::vector<std::pair<int,int> > rotations; //first - group number to be rotated1, second - group number after rotation1
 	rotations += std::make_pair(6,10), std::make_pair(7,11), std::make_pair(8,12), std::make_pair(1,13),
 		std::make_pair(2,14), std::make_pair(3,15);
-	for(int i=0; i<anims.size();i++)
+	for(size_t i=0; i<anims.size(); ++i)
 	{
 		std::stringstream nm;
 		nm << "AH" << std::setw(2) << std::setfill('0') << i << "_.DEF";
@@ -312,7 +312,7 @@ void Graphics::loadHeroAnim(std::vector<CDefHandler **> & anims)
 				}
 			}
 		}
-		for(int ff=0; ff<(*anims[i])->ourImages.size(); ++ff)
+		for(size_t ff=0; ff<(*anims[i])->ourImages.size(); ++ff)
 		{
 			CSDL_Ext::alphaTransform((*anims[i])->ourImages[ff].bitmap);
 		}
@@ -328,9 +328,9 @@ void Graphics::loadHeroFlags(std::pair<std::vector<CDefHandler *> Graphics::*, s
 	rotations += std::make_pair(6,10), std::make_pair(7,11), std::make_pair(8,12);
 	for(int q=0; q<8; ++q)
 	{
-		for(int o=0; o<(this->*pr.first)[q]->ourImages.size(); ++o)
+		for(size_t o=0; o<(this->*pr.first)[q]->ourImages.size(); ++o)
 		{
-			for(int p=0;p<rotations.size();p++)
+			for(size_t p=0;p<rotations.size();p++)
 			{
 				if((this->*pr.first)[q]->ourImages[o].groupNumber==rotations[p].first)
 				{
@@ -348,7 +348,7 @@ void Graphics::loadHeroFlags(std::pair<std::vector<CDefHandler *> Graphics::*, s
 		}
 		if (mode)
 		{
-			for(int o=0; o<flags4[q]->ourImages.size(); ++o)
+			for(size_t o=0; o<flags4[q]->ourImages.size(); ++o)
 			{
 				if(flags4[q]->ourImages[o].groupNumber==1)
 				{
@@ -388,7 +388,7 @@ void Graphics::loadHeroFlags(std::pair<std::vector<CDefHandler *> Graphics::*, s
 				}
 			}
 		}
-		for(int ff=0; ff<(this->*pr.first)[q]->ourImages.size(); ++ff)
+		for(size_t ff=0; ff<(this->*pr.first)[q]->ourImages.size(); ++ff)
 		{
 			SDL_SetColorKey((this->*pr.first)[q]->ourImages[ff].bitmap, SDL_SRCCOLORKEY,
 				SDL_MapRGB((this->*pr.first)[q]->ourImages[ff].bitmap->format, 0, 255, 255)
@@ -402,7 +402,7 @@ void Graphics::loadHeroFlags()
 {
 	using namespace boost::assign;
 	timeHandler th;
-	std::vector<CDefHandler *> Graphics::*point;
+//	std::vector<CDefHandler *> Graphics::*point; //TODO use me
 	std::pair<std::vector<CDefHandler *> Graphics::*, std::vector<const char *> > pr[4];
 	pr[0].first = &Graphics::flags1;
 	pr[0].second+=("ABF01L.DEF"),("ABF01G.DEF"),("ABF01R.DEF"),("ABF01D.DEF"),("ABF01B.DEF"),

+ 10 - 1
client/Graphics.h

@@ -1,5 +1,13 @@
+#ifndef GRAPHICS_H
+#define GRAPHICS_H
+
+#ifdef _MSC_VER
 #pragma once
+#endif
+
 #include "../global.h"
+
+
 class CDefEssential;
 struct SDL_Surface;
 class CGHeroInstance;
@@ -57,4 +65,5 @@ public:
 	void blueToPlayersAdv(SDL_Surface * sur, int player); //replaces blue interface colour with a color of player
 };
 
-extern Graphics * graphics;
+extern Graphics * graphics;
+#endif //GRAPHICS_H

+ 12 - 6
global.h

@@ -1,6 +1,7 @@
 #ifndef GLOBAL_H
 #define GLOBAL_H
 #include <iostream>
+#include <algorithm> //std::find
 #include <boost/logic/tribool.hpp>
 #include <boost/cstdint.hpp>
 typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes)
@@ -127,7 +128,7 @@ namespace vstd
 	template <typename T1, typename T2>
 	int findPos(const std::vector<T1> & c, const T2 &s)
 	{
-		for(int i=0;i<c.size();i++)
+		for(size_t i=0; i < c.size(); ++i)
 			if(c[i] == s)
 				return i;
 		return -1;
@@ -135,7 +136,7 @@ namespace vstd
 	template <typename T1, typename T2, typename Func>
 	int findPos(const std::vector<T1> & c, const T2 &s, const Func &f) //Func(T1,T2) must say if these elements matches
 	{
-		for(int i=0;i<c.size();i++)
+		for(size_t i=0; i < c.size(); ++i)
 			if(f(c[i],s))
 				return i;
 		return -1;
@@ -214,13 +215,17 @@ public:
 	template<typename T> 
 	CLogger<lvl> & operator<<(const T & data)
 	{
-		if(lvl < CONSOLE_LOGGING_LEVEL)
-			if(console)
+		if(lvl < CONSOLE_LOGGING_LEVEL) {
+			if(console) {
 				console->print(data,lvl);
-			else
+                        }
+			else {
 				std::cout << data << std::flush;
-		if((lvl < FILE_LOGGING_LEVEL) && logfile)
+                        }
+                }
+		if((lvl < FILE_LOGGING_LEVEL) && logfile) {
 			*logfile << data << std::flush;
+                }
 		return *this;
 	}
 };
@@ -232,6 +237,7 @@ extern DLL_EXPORT CLogger<3> tlog3; //yellow - minor warnings
 extern DLL_EXPORT CLogger<4> tlog4; //white - detailed log info
 extern DLL_EXPORT CLogger<5> tlog5; //gray - minor log info
 
+//XXX pls dont - 'debug macros' are usually more trubble then its worth
 #define HANDLE_EXCEPTION  \
 	catch (const std::exception& e) {	\
 	tlog1 << e.what() << std::endl;	\

+ 14 - 11
hch/CDefHandler.cpp

@@ -26,7 +26,7 @@ CDefHandler::~CDefHandler()
 		delete [] RWEntries;
 	if (notFreeImgs)
 		return;
-	for (int i=0; i<ourImages.size(); i++)
+	for (size_t i=0; i<ourImages.size(); ++i)
 	{
 		if (ourImages[i].bitmap)
 		{
@@ -37,7 +37,7 @@ CDefHandler::~CDefHandler()
 }
 CDefEssential::~CDefEssential()
 {
-	for(int i=0;i<ourImages.size();i++)
+	for(size_t i=0; i < ourImages.size(); ++i)
 		SDL_FreeSurface(ourImages[i].bitmap);
 }
 void CDefHandler::openDef(std::string name)
@@ -103,7 +103,7 @@ void CDefHandler::openDef(std::string name)
 	{
 		SEntries[j].name = SEntries[j].name.substr(0, SEntries[j].name.find('.')+4);
 	}
-	for(int i=0; i<SEntries.size(); ++i)
+	for(size_t i=0; i < SEntries.size(); ++i)
 	{
 		Cimage nimg;
 		nimg.bitmap = getSprite(i, FDef, palette);
@@ -140,12 +140,14 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name)
 	totalEntries=0;
 	for (int z=0; z<totalBlocks; z++)
 	{
-		int unknown1 = readNormalNr(i,4,table); i+=4;
+		int unknown1 = readNormalNr(i,4,table); i+=4; //TODO use me
 		totalInBlock = readNormalNr(i,4,table); i+=4;
 		for (j=SEntries.size(); j<totalEntries+totalInBlock; j++)
 			SEntries.push_back(SEntry());
-		int unknown2 = readNormalNr(i,4,table); i+=4;
-		int unknown3 = readNormalNr(i,4,table); i+=4;
+		int unknown2 = readNormalNr(i,4,table); //TODO use me
+        i+=4;
+		int unknown3 = readNormalNr(i,4,table); //TODO use me
+        i+=4;
 		for (j=0; j<totalInBlock; j++)
 		{
 			for (int k=0;k<13;k++) Buffer[k]=table[i+k]; 
@@ -155,7 +157,8 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name)
 		for (j=0; j<totalInBlock; j++)
 		{ 
 			SEntries[totalEntries+j].offset = readNormalNr(i,4,table);
-			int unknown4 = readNormalNr(i,4,table); i+=4;
+			int unknown4 = readNormalNr(i,4,table); //TODO use me
+            i+=4;
 		}
 		//totalEntries+=totalInBlock;
 		for(int hh=0; hh<totalInBlock; ++hh)
@@ -169,7 +172,7 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name)
 		SEntries[j].name = SEntries[j].name.substr(0, SEntries[j].name.find('.')+4);
 	}
 	RWEntries = new unsigned int[height];
-	for(int i=0; i<SEntries.size(); ++i)
+	for(size_t i=0; i < SEntries.size(); ++i)
 	{
 		Cimage nimg;
 		nimg.bitmap = getSprite(i, table, palette);
@@ -248,12 +251,12 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet
 		LeftMargin, RightMargin, TopMargin,BottomMargin,
 		i, add, FullHeight,FullWidth,
 		TotalRowLength, // dlugosc przeczytanego segmentu
-		NextSpriteOffset, RowAdd;
+		RowAdd;//, NextSpriteOffset; //TODO use me
 
-	unsigned char SegmentType, SegmentLength, BL, BR;
+	unsigned char SegmentType, SegmentLength;//, BL, BR; //TODO use me
 
 	i=BaseOffset=SEntries[SIndex].offset;
-	int prSize=readNormalNr(i,4,FDef);i+=4;
+//	int prSize=readNormalNr(i,4,FDef);i+=4; //TODO use me
 	int defType2 = readNormalNr(i,4,FDef);i+=4;
 	FullWidth = readNormalNr(i,4,FDef);i+=4;
 	FullHeight = readNormalNr(i,4,FDef);i+=4;

+ 1 - 1
hch/CMusicHandler.h

@@ -1,7 +1,7 @@
 #ifndef CMUSICHANDLER_H
 #define CMUSICHANDLER_H
 
-#include "SDL_mixer.h"
+#include <SDL_mixer.h>
 #include "CSndHandler.h"
 
 class CMusicHandler

+ 31 - 11
hch/CObjectHandler.cpp

@@ -19,16 +19,17 @@ extern boost::rand48 ran;
 void CObjectHandler::loadObjects()
 {
 	VLC->objh = this;
-	int ID=0;
+//	int ID=0; //TODO use me
 	tlog5 << "\t\tReading OBJNAMES \n";
 	std::string buf = bitmaph->getTextFile("OBJNAMES.TXT");
-	int it=0;
+	int it=0; //hope that -1 will not break this
 	while (it<buf.length()-1)
 	{
 		std::string nobj;
-		loadToIt(nobj,buf,it,3);
-		if(nobj.size() && (nobj[nobj.size()-1]==(char)10 || nobj[nobj.size()-1]==(char)13 || nobj[nobj.size()-1]==(char)9))
+		loadToIt(nobj, buf, it, 3);
+		if(nobj.size() && (nobj[nobj.size()-1]==(char)10 || nobj[nobj.size()-1]==(char)13 || nobj[nobj.size()-1]==(char)9)) {
 			nobj = nobj.substr(0, nobj.size()-1);
+                }
 		names.push_back(nobj);
 	}
 
@@ -39,8 +40,9 @@ void CObjectHandler::loadObjects()
 	while (it<buf.length()-1)
 	{
 		loadToIt(temp,buf,it,3);
-		if (temp[0]=='\"')
+		if (temp[0]=='\"') {
 			temp = temp.substr(1,temp.length()-2);
+                }
 		boost::algorithm::replace_all(temp,"\"\"","\"");
 		advobtxt.push_back(temp);
 	}
@@ -85,8 +87,9 @@ void CObjectHandler::loadObjects()
 
 	tlog5 << "\t\tReading cregens \n";
 	cregens.resize(110); //TODO: hardcoded value - change
-	for(int i=0; i<cregens.size();i++)
+	for(size_t i=0; i < cregens.size(); ++i) {
 		cregens[i]=-1;
+        }
 	std::ifstream ifs("config/cregens.txt");
 	while(!ifs.eof())
 	{
@@ -199,23 +202,34 @@ unsigned int CGHeroInstance::getTileCost(const EterrainType & ttype, const Eroad
 			if(ret>150)
 				ret = 150;
 			break;
+                default:
+                    //TODO do something nasty here throw maybe? or some def value asing
+                    break;
 		}
 		break;
 	case 2: //advanced
 		switch(ttype)
 		{
-		case rough: case sand: case snow:
+		case rough: 
+                case sand:
+                case snow:
 			ret = 100;
 			break;
 		case swamp:
 			if(ret>125)
 				ret = 125;
 			break;
+                default:
+                        //TODO look up
+                    break;
 		}
 		break;
 	case 3: //expert
 		ret = 100;
 		break;
+        default:
+            //TODO look up
+            break;
 	}
 
 	//calculating road influence
@@ -230,13 +244,16 @@ unsigned int CGHeroInstance::getTileCost(const EterrainType & ttype, const Eroad
 	case cobblestoneRoad:
 		ret*=0.5;
 		break;
+        default:
+            //TODO killllll me
+            break;
 	}
 	return ret;
 }
 unsigned int CGHeroInstance::getLowestCreatureSpeed()
 {
 	unsigned int sl = 100;
-	for(int h=0; h<army.slots.size(); ++h)
+	for(size_t h=0; h < army.slots.size(); ++h)
 	{
 		if(VLC->creh->creatures[army.slots[h].first].speed<sl)
 			sl = VLC->creh->creatures[army.slots[h].first].speed;
@@ -258,9 +275,12 @@ int3 CGHeroInstance::convertPosition(int3 src, bool toh3m) //toh3m=true: manifes
 }
 int3 CGHeroInstance::getPosition(bool h3m) const //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
 {
-	if (h3m)
+	if (h3m) {
 		return pos;
-	else return convertPosition(pos,false);
+        }
+	else {
+            return convertPosition(pos,false);
+        }
 }
 int CGHeroInstance::getSightDistance() const //returns sight distance of this hero
 {
@@ -307,7 +327,7 @@ int CGHeroInstance::getPrimSkillLevel(int id) const
 }
 int CGHeroInstance::getSecSkillLevel(const int & ID) const
 {
-	for(int i=0;i<secSkills.size();i++)
+	for(size_t i=0; i < secSkills.size(); ++i)
 		if(secSkills[i].first==ID)
 			return secSkills[i].second;
 	return 0;

+ 6 - 6
hch/CSndHandler.cpp

@@ -79,7 +79,7 @@ void CSndHandler::extract(std::string srcfile, std::string dstfile, bool caseSen
 {
 	if (caseSens)
 	{
-		for (int i=0;i<entries.size();i++)
+		for (size_t i=0;i<entries.size();++i)
 		{
 			if (entries[i].name==srcfile)
 				extract(i,dstfile);
@@ -88,7 +88,7 @@ void CSndHandler::extract(std::string srcfile, std::string dstfile, bool caseSen
 	else
 	{
 		std::transform(srcfile.begin(),srcfile.end(),srcfile.begin(),tolower);
-		for (int i=0;i<entries.size();i++)
+		for (size_t i=0;i<entries.size();++i)
 		{
 			if (entries[i].name==srcfile)
 			{
@@ -104,7 +104,7 @@ MemberFile CSndHandler::getFile(std::string name)
 {
 	MemberFile ret;
 	std::transform(name.begin(),name.end(),name.begin(),tolower);
-	for (int i=0;i<entries.size();i++)
+	for (size_t i=0;i<entries.size();++i)
 	{
 		if (entries[i].name==name)
 		{
@@ -219,7 +219,7 @@ void CVidHandler::extract(std::string srcfile, std::string dstfile, bool caseSen
 {
 	if (caseSens)
 	{
-		for (int i=0;i<entries.size();i++)
+		for (size_t i=0;i<entries.size();++i)
 		{
 			if (entries[i].name==srcfile)
 				extract(i,dstfile);
@@ -228,7 +228,7 @@ void CVidHandler::extract(std::string srcfile, std::string dstfile, bool caseSen
 	else
 	{
 		std::transform(srcfile.begin(),srcfile.end(),srcfile.begin(),tolower);
-		for (int i=0;i<entries.size();i++)
+		for (size_t i=0;i<entries.size();++i)
 		{
 			if (entries[i].name==srcfile)
 			{
@@ -244,7 +244,7 @@ MemberFile CVidHandler::getFile(std::string name)
 {
 	MemberFile ret;
 	std::transform(name.begin(),name.end(),name.begin(),tolower);
-	for (int i=0;i<entries.size();i++)
+	for (size_t i=0;i<entries.size();++i)
 	{
 		if (entries[i].name==name)
 		{

+ 10 - 7
int3.h

@@ -3,6 +3,8 @@
 #include <map>
 #include <vector>
 #include <cmath>
+
+
 class CCreature;
 class CCreatureSet //seven combined creatures
 {
@@ -10,14 +12,15 @@ public:
 	std::map<si32,std::pair<ui32,si32> > slots; //slots[slot_id]=> pair(creature_id,creature_quantity)
 	bool formation; //false - wide, true - tight
 	si32 getSlotFor(ui32 creature, ui32 slotsAmount=7) //returns -1 if no slot available
-	{
-		
-		for(std::map<si32,std::pair<ui32,si32> >::iterator i=slots.begin(); i!=slots.end(); i++)
-			if(i->second.first == creature)
+	{	
+		for(std::map<si32,std::pair<ui32,si32> >::iterator i=slots.begin(); i!=slots.end(); ++i)
+			if(i->second.first == creature) {
 				return i->first; //if there is already such creature we return its slot id
-		for(si32 i=0; i<slotsAmount; i++)
-			if(slots.find(i) == slots.end())
+                        }
+		for(ui32 i=0; i<slotsAmount; i++)
+			if(slots.find(i) == slots.end()) {
 				return i; //return first free slot
+            }
 		return -1; //no slot available
 	}
 	template <typename Handler> void serialize(Handler &h, const int version)
@@ -34,7 +37,7 @@ public:
 	inline int3(const si32 & X, const si32 & Y, const si32 & Z):x(X),y(Y),z(Z){}; //c-tor
 	inline int3(const int3 & val) : x(val.x), y(val.y), z(val.z){} //copy c-tor
 	inline int3 operator=(const int3 & val) {x = val.x; y = val.y; z = val.z; return *this;} //assignemt operator
-	inline ~int3(){} // d-tor - does nothing
+	~int3() {} // d-tor - does nothing
 	inline int3 operator+(const int3 & i) const //returns int3 with coordinates increased by corresponding coordinate of given int3
 		{return int3(x+i.x,y+i.y,z+i.z);}
 	inline int3 operator+(const si32 i) const //returns int3 with coordinates increased by given numer

+ 2 - 0
map.h

@@ -1,6 +1,8 @@
 #ifndef MAPD_H
 #define MAPD_H
+#ifdef _MSC_VER
 #pragma warning (disable : 4482)
+#endif
 #include <cstring>
 #include <vector>
 #include <map>

+ 29 - 22
mapHandler.cpp

@@ -70,6 +70,12 @@ std::string nameFromType (int typ)
 			return std::string("ROCKTL.DEF");		
 			break;
 		}
+                case border:
+                    //TODO use me
+                    break;
+                default:
+                        //TODO do something here
+                break;
 	}
 	return std::string();
 }
@@ -134,23 +140,24 @@ void CMapHandler::prepareFOWDefs()
 	partialHide->ourImages.push_back(nw);
 	//necessaary rotations added
 
-	for(int i=0; i<partialHide->ourImages.size(); ++i)
+	for(size_t i=0; i<partialHide->ourImages.size(); ++i)
 	{
 		CSDL_Ext::alphaTransform(partialHide->ourImages[i].bitmap);
 	}
 
 	hideBitmap.resize(CGI->mh->map->width);
-	for (int i=0;i<hideBitmap.size();i++)
+	for (size_t i=0;i<hideBitmap.size();i++)
 	{
 		hideBitmap[i].resize(CGI->mh->map->height);
 	}
-	for (int i=0; i<hideBitmap.size(); ++i)
+	for (size_t i=0; i<hideBitmap.size(); ++i)
 	{
-		for (int j=0; j<CGI->mh->map->height; ++j)
+		for (int j=0; j < CGI->mh->map->height; ++j)
 		{
 			hideBitmap[i][j].resize(CGI->mh->map->twoLevel+1);
-			for(int k=0; k<CGI->mh->map->twoLevel+1; ++k)
+			for(int k=0; k<CGI->mh->map->twoLevel+1; ++k) {
 				hideBitmap[i][j][k] = rand()%fullHide->ourImages.size();
+                        }
 		}
 	}
 }
@@ -166,16 +173,16 @@ void CMapHandler::roadsRiverTerrainInit()
 	staticRiverDefs.push_back(CDefHandler::giveDef("icyrvr.def"));
 	staticRiverDefs.push_back(CDefHandler::giveDef("mudrvr.def"));
 	staticRiverDefs.push_back(CDefHandler::giveDef("lavrvr.def"));
-	for(int g=0; g<staticRiverDefs.size(); ++g)
+	for(size_t g=0; g<staticRiverDefs.size(); ++g)
 	{
-		for(int h=0; h<staticRiverDefs[g]->ourImages.size(); ++h)
+		for(size_t h=0; h < staticRiverDefs[g]->ourImages.size(); ++h)
 		{
 			CSDL_Ext::alphaTransform(staticRiverDefs[g]->ourImages[h].bitmap);
 		}
 	}
-	for(int g=0; g<roadDefs.size(); ++g)
+	for(size_t g=0; g<roadDefs.size(); ++g)
 	{
-		for(int h=0; h<roadDefs[g]->ourImages.size(); ++h)
+		for(size_t h=0; h < roadDefs[g]->ourImages.size(); ++h)
 		{
 			CSDL_Ext::alphaTransform(roadDefs[g]->ourImages[h].bitmap);
 		}
@@ -280,7 +287,7 @@ void CMapHandler::borderAndTerrainBitmapInit()
 		CDefHandler *hlp = CDefHandler::giveDef(nameFromType(i));
 		terrainGraphics[i].resize(hlp->ourImages.size());
 		hlp->notFreeImgs = true;
-		for(int j=0; j<hlp->ourImages.size();j++)
+		for(size_t j=0; j < hlp->ourImages.size(); ++j)
 			terrainGraphics[i][j] = hlp->ourImages[j].bitmap;
 		delete hlp;
 	}
@@ -347,7 +354,7 @@ void CMapHandler::borderAndTerrainBitmapInit()
 void CMapHandler::initObjectRects()
 {
 	//initializing objects / rects
-	for(int f=0; f<map->objects.size(); ++f)
+	for(size_t f=0; f < map->objects.size(); ++f)
 	{
 		if((map->objects[f]->ID==34 && static_cast<CGHeroInstance*>(map->objects[f])->inTownGarrison)
 			|| !map->objects[f]->defInfo)
@@ -410,7 +417,7 @@ void processDef (CGDefInfo* def)
 		tlog3 << "\t\tMinor warning: lacking def info for " << def->id << " " << def->subid <<" " << def->name << std::endl;
 	if(!def->handler->alphaTransformed)
 	{
-		for(int yy=0; yy<def->handler->ourImages.size(); ++yy)
+		for(size_t yy=0; yy < def->handler->ourImages.size(); ++yy)
 		{
 			def->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(def->handler->ourImages[yy].bitmap);
 			def->handler->alphaTransformed = true;
@@ -462,7 +469,7 @@ void CMapHandler::init()
 
 	for(int i=0;i<PLAYER_LIMIT;i++)
 	{
-		for(int j=0; j<map->players[i].heroesNames.size();j++)
+		for(size_t j=0; j < map->players[i].heroesNames.size(); ++j)
 		{
 			usedHeroes.insert(map->players[i].heroesNames[j].heroID);
 		}
@@ -471,7 +478,7 @@ void CMapHandler::init()
 
 
 
-	for(int h=0; h<map->defy.size(); ++h) //initializing loaded def handler's info	{
+	for(size_t h=0; h<map->defy.size(); ++h) //initializing loaded def handler's info	{
 		CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler));
 	tlog0<<"\tCollecting loaded def's handlers: "<<th.getDif()<<std::endl;
 
@@ -582,7 +589,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 	{
 		for (int by=0; by<dy; by++)
 		{
-			for(int h=0; h<ttiles[x+bx][y+by][level].objects.size(); ++h)
+			for(int h=0; h < ttiles[x+bx][y+by][level].objects.size(); ++h)
 			{
 				SDL_Rect sr;
 				sr.w = 32;
@@ -605,7 +612,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 						continue;
 					std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages;
 
-					int gg;
+                    size_t gg;
 					for(gg=0; gg<iv.size(); ++gg)
 					{
 						if(iv[gg].groupNumber==getHeroFrameNum(themp->moveDir, !themp->isStanding))
@@ -628,8 +635,8 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 						continue;
 					std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages;
 
-					int gg;
-					for(gg=0; gg<iv.size(); ++gg)
+                    size_t gg;
+					for(gg=0; gg < iv.size(); ++gg)
 					{
 						if(iv[gg].groupNumber==getHeroFrameNum(themp->moveDir, !themp->isStanding))
 						{
@@ -752,7 +759,7 @@ SDL_Surface * CMapHandler::getVisBitmap(int x, int y, const std::vector< std::ve
 		d8 = (y>0) ? visibilityMap[x][y-1][lvl] : 0,			//456
 		d9 = (y>0 && x<size) ? visibilityMap[x+1][y-1][lvl] : 0,//123
 		d4 = (x>0) ? visibilityMap[x-1][y][lvl] : 0,
-		d5 = visibilityMap[x][y][lvl],
+		d5 = visibilityMap[x][y][lvl], //TODO use me - OMFG
 		d6 = (x<size) ? visibilityMap[x+1][y][lvl] : 0,
 		d1 = (x>0 && y<size) ? visibilityMap[x-1][y+1][lvl] : 0,
 		d2 = (y<size) ? visibilityMap[x][y+1][lvl] : 0,
@@ -1063,7 +1070,7 @@ bool CMapHandler::printObject(const CGObjectInstance *obj)
 			std::pair<const CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(obj, cr);
 			if((obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
 			{
-				TerrainTile2 & curt =
+				TerrainTile2 & curt = //TODO use me 
 					ttiles
 					  [obj->pos.x + fx - curd->ourImages[0].bitmap->w/32]
 				      [obj->pos.y + fy - curd->ourImages[0].bitmap->h/32]
@@ -1088,7 +1095,7 @@ bool CMapHandler::hideObject(const CGObjectInstance *obj)
 			if((obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
 			{
 				std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > & ctile = ttiles[obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][obj->pos.z].objects;
-				for(int dd=0; dd<ctile.size(); ++dd)
+				for(size_t dd=0; dd < ctile.size(); ++dd)
 				{
 					if(ctile[dd].first->id==obj->id)
 						ctile.erase(ctile.begin() + dd);
@@ -1247,7 +1254,7 @@ unsigned char CMapHandler::getDir(const int3 &a, const int3 &b)
 void CMapHandler::updateWater() //shift colors in palettes of water tiles
 {
 	SDL_Color palette[14];
-	for(int j=0; j<terrainGraphics[8].size(); j++)
+	for(size_t j=0; j < terrainGraphics[8].size(); ++j)
 	{
 		for(int i=0; i<12; ++i)
 		{

+ 7 - 1
stdafx.h

@@ -1,9 +1,13 @@
+#ifndef _ZJEBANYNAGLOWEKWINDOWEGOVISUALAKTORENIKTNIEUZYWA_H
+#define _ZJEBANYNAGLOWEKWINDOWEGOVISUALAKTORENIKTNIEUZYWA_H
+
 // stdafx.h : include file for standard system include files,
 // or project specific include files that are used frequently, but
 // are changed infrequently
 //
-
+#ifdef _MSC_VER
 #pragma once
+#endif
 
 #define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
 #include <cstdio>
@@ -19,3 +23,5 @@
 #include <fstream>
 #include "global.h"
 // TODO: reference additional headers your program requires here
+
+#endif //_ZJEBANYNAGLOWEKWINDOWEGOVISUALAKTORENIKTNIEUZYWA_H