浏览代码

* Added RMG tab to pregame(disabled by default, activate with: enableRMG=true in settings.json) * Fixed tab intendation * Renamed colors to more comprehensible names

beegee1 13 年之前
父节点
当前提交
c336abcf4a

+ 5 - 5
client/AdventureMapClasses.cpp

@@ -713,7 +713,7 @@ void CInfoBar::CVisibleInfo::loadDay()
 	else
 		labelText = CGI->generaltexth->allTexts[64] + " " + boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(1));
 
-	forceRefresh.push_back(new CLabel(95, 31, FONT_MEDIUM, CENTER, Colors::Cornsilk, labelText));
+	forceRefresh.push_back(new CLabel(95, 31, FONT_MEDIUM, CENTER, Colors::WHITE, labelText));
 }
 
 void CInfoBar::CVisibleInfo::loadEnemyTurn(int player)
@@ -763,8 +763,8 @@ void CInfoBar::CVisibleInfo::loadGameStatus()
 	//generate component
 	OBJ_CONSTRUCTION_CAPTURING_ALL;
 	new CPicture("ADSTATIN");
-	auto allyLabel  = new CLabel(10, 106, FONT_SMALL, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[390] + ":");
-	auto enemyLabel = new CLabel(10, 136, FONT_SMALL, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[391] + ":");
+	auto allyLabel  = new CLabel(10, 106, FONT_SMALL, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[390] + ":");
+	auto enemyLabel = new CLabel(10, 136, FONT_SMALL, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[391] + ":");
 
 	int posx = allyLabel->pos.w + allyLabel->pos.x - pos.x + 4;
 	BOOST_FOREACH(int & player, allies)
@@ -784,7 +784,7 @@ void CInfoBar::CVisibleInfo::loadGameStatus()
 	{
 		new CAnimImage("itmtl", i, 0, 6 + 42 * i , 11);
 		if (halls[i])
-			new CLabel( 26 + 42 * i, 64, FONT_SMALL, CENTER, Colors::Cornsilk, boost::lexical_cast<std::string>(halls[i]));
+			new CLabel( 26 + 42 * i, 64, FONT_SMALL, CENTER, Colors::WHITE, boost::lexical_cast<std::string>(halls[i]));
 	}
 }
 
@@ -799,7 +799,7 @@ void CInfoBar::CVisibleInfo::loadComponent(const Component & compToDisplay, std:
 	auto comp = new CComponent(compToDisplay);
 	comp->moveTo(Point(pos.x+47, pos.y+50));
 
-	new CTextBox(message, Rect(10, 4, 160, 50), 0, FONT_SMALL, CENTER, Colors::Cornsilk);
+	new CTextBox(message, Rect(10, 4, 160, 50), 0, FONT_SMALL, CENTER, Colors::WHITE);
 }
 
 void CInfoBar::CVisibleInfo::updateEnemyTurn(double progress)

+ 1 - 1
client/BattleInterface/CBattleInterface.cpp

@@ -2270,7 +2270,7 @@ void CBattleInterface::showAliveStack(const CStack *stack, SDL_Surface * to)
 			creAnims[ID]->pos.x + xAdd + 15,
 			creAnims[ID]->pos.y + yAdd + 5,
 			FONT_TINY,
-			Colors::Cornsilk,
+			Colors::WHITE,
 			to
 		);
 	}

+ 39 - 39
client/BattleInterface/CBattleInterfaceClasses.cpp

@@ -33,22 +33,22 @@ void CBattleConsole::showAll(SDL_Surface * to)
 {
 	if(ingcAlter.size())
 	{
-		CSDL_Ext::printAtMiddleWB(ingcAlter, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, Colors::Cornsilk, to);
+		CSDL_Ext::printAtMiddleWB(ingcAlter, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, Colors::WHITE, to);
 	}
 	else if(alterTxt.size())
 	{
-		CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, Colors::Cornsilk, to);
+		CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, Colors::WHITE, to);
 	}
 	else if(texts.size())
 	{
 		if(texts.size()==1)
 		{
-			CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, Colors::Cornsilk, to);
+			CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, Colors::WHITE, to);
 		}
 		else
 		{
-			CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, Colors::Cornsilk, to);
-			CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 27, FONT_SMALL, 80, Colors::Cornsilk, to);
+			CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 11, FONT_SMALL, 80, Colors::WHITE, to);
+			CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 27, FONT_SMALL, 80, Colors::WHITE, to);
 		}
 	}
 }
@@ -271,29 +271,29 @@ CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInt
 	exit->update();
 
 	//creating labels
-	labels.push_back(new CLabel(242,  32, FONT_BIG,    CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[392]));//window title
-	labels.push_back(new CLabel(122, 214, FONT_MEDIUM, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[393]));//animation speed
-	labels.push_back(new CLabel(122, 293, FONT_MEDIUM, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[394]));//music volume
-	labels.push_back(new CLabel(122, 359, FONT_MEDIUM, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[395]));//effects' volume
-	labels.push_back(new CLabel(353,  66, FONT_MEDIUM, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[396]));//auto - combat options
-	labels.push_back(new CLabel(353, 265, FONT_MEDIUM, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[397]));//creature info
+	labels.push_back(new CLabel(242,  32, FONT_BIG,    CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[392]));//window title
+	labels.push_back(new CLabel(122, 214, FONT_MEDIUM, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[393]));//animation speed
+	labels.push_back(new CLabel(122, 293, FONT_MEDIUM, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[394]));//music volume
+	labels.push_back(new CLabel(122, 359, FONT_MEDIUM, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[395]));//effects' volume
+	labels.push_back(new CLabel(353,  66, FONT_MEDIUM, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[396]));//auto - combat options
+	labels.push_back(new CLabel(353, 265, FONT_MEDIUM, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[397]));//creature info
 
 	//auto - combat options
-	labels.push_back(new CLabel(283,  86, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[398]));//creatures
-	labels.push_back(new CLabel(283, 116, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[399]));//spells
-	labels.push_back(new CLabel(283, 146, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[400]));//catapult
-	labels.push_back(new CLabel(283, 176, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[151]));//ballista
-	labels.push_back(new CLabel(283, 206, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[401]));//first aid tent
+	labels.push_back(new CLabel(283,  86, FONT_MEDIUM, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[398]));//creatures
+	labels.push_back(new CLabel(283, 116, FONT_MEDIUM, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[399]));//spells
+	labels.push_back(new CLabel(283, 146, FONT_MEDIUM, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[400]));//catapult
+	labels.push_back(new CLabel(283, 176, FONT_MEDIUM, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[151]));//ballista
+	labels.push_back(new CLabel(283, 206, FONT_MEDIUM, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[401]));//first aid tent
 
 	//creature info
-	labels.push_back(new CLabel(283, 285, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[402]));//all stats
-	labels.push_back(new CLabel(283, 315, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[403]));//spells only
+	labels.push_back(new CLabel(283, 285, FONT_MEDIUM, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[402]));//all stats
+	labels.push_back(new CLabel(283, 315, FONT_MEDIUM, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[403]));//spells only
 
 	//general options
-	labels.push_back(new CLabel(61,  57, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[404]));
-	labels.push_back(new CLabel(61,  90, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[405]));
-	labels.push_back(new CLabel(61, 123, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[406]));
-	labels.push_back(new CLabel(61, 156, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, CGI->generaltexth->allTexts[407]));
+	labels.push_back(new CLabel(61,  57, FONT_MEDIUM, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[404]));
+	labels.push_back(new CLabel(61,  90, FONT_MEDIUM, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[405]));
+	labels.push_back(new CLabel(61, 123, FONT_MEDIUM, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[406]));
+	labels.push_back(new CLabel(61, 156, FONT_MEDIUM, TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[407]));
 }
 
 void CBattleOptionsWindow::bDefaultf()
@@ -319,18 +319,18 @@ CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect
 
 	if(br.winner==0) //attacker won
 	{
-		new CLabel( 59, 124, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[410]);
-		new CLabel(408, 124, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[411]);
+		new CLabel( 59, 124, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[410]);
+		new CLabel(408, 124, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[411]);
 	}
 	else //if(br.winner==1)
 	{
-		new CLabel( 59, 124, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[411]);
-		new CLabel(412, 124, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[410]);
+		new CLabel( 59, 124, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[411]);
+		new CLabel(412, 124, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[410]);
 	}
 
-	new CLabel(232, 302, FONT_BIG, CENTER, Colors::Jasmine,  CGI->generaltexth->allTexts[407]);
-	new CLabel(232, 332, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[408]);
-	new CLabel(232, 428, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[409]);
+	new CLabel(232, 302, FONT_BIG, CENTER, Colors::YELLOW,  CGI->generaltexth->allTexts[407]);
+	new CLabel(232, 332, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[408]);
+	new CLabel(232, 428, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[409]);
 
 	std::string attackerName, defenderName;
 
@@ -380,16 +380,16 @@ CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect
 	}
 
 	//printing attacker and defender's names
-	new CLabel( 89, 37, FONT_SMALL, TOPLEFT, Colors::Cornsilk, attackerName);
+	new CLabel( 89, 37, FONT_SMALL, TOPLEFT, Colors::WHITE, attackerName);
 
-	new CLabel( 381, 53, FONT_SMALL, BOTTOMRIGHT, Colors::Cornsilk, defenderName);
+	new CLabel( 381, 53, FONT_SMALL, BOTTOMRIGHT, Colors::WHITE, defenderName);
 
 	//printing casualities
 	for(int step = 0; step < 2; ++step)
 	{
 		if(br.casualties[step].size()==0)
 		{
-			new CLabel( 235, 360 + 97*step, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[523]);
+			new CLabel( 235, 360 + 97*step, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[523]);
 		}
 		else
 		{
@@ -400,7 +400,7 @@ CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect
 				new CAnimImage("CPRSMALL", CGI->creh->creatures[it->first]->iconIndex, 0, xPos, yPos);
 				std::ostringstream amount;
 				amount<<it->second;
-				new CLabel( xPos+16, yPos + 42, FONT_SMALL, CENTER, Colors::Cornsilk, amount.str());
+				new CLabel( xPos+16, yPos + 42, FONT_SMALL, CENTER, Colors::WHITE, amount.str());
 				xPos += 42;
 			}
 		}
@@ -429,7 +429,7 @@ CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect
 			boost::algorithm::replace_first(str,"%d",boost::lexical_cast<std::string>(br.exp[weAreAttacker?0:1]));
 		}
 		
-		new CTextBox(str, Rect(69, 203, 330, 68), 0, FONT_SMALL, CENTER, Colors::Cornsilk);
+		new CTextBox(str, Rect(69, 203, 330, 68), 0, FONT_SMALL, CENTER, Colors::WHITE);
 	}
 	else // we lose
 	{
@@ -439,21 +439,21 @@ CBattleResultWindow::CBattleResultWindow(const BattleResult &br, const SDL_Rect
 			{
 				CCS->musich->playMusic("Music/LoseCombat", false);
 				CCS->videoh->open("LBSTART.BIK");
-				new CLabel(235, 235, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[311]);
+				new CLabel(235, 235, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[311]);
 				break;
 			}
 		case 1: //flee
 			{
 				CCS->musich->playMusic("Music/Retreat Battle", false);
 				CCS->videoh->open("RTSTART.BIK");
-				new CLabel(235, 235, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[310]);
+				new CLabel(235, 235, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[310]);
 				break;
 			}
 		case 2: //surrender
 			{
 				CCS->musich->playMusic("Music/Surrender Battle", false);
 				CCS->videoh->open("SURRENDER.BIK");
-				new CLabel(235, 235, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[309]);
+				new CLabel(235, 235, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[309]);
 				break;
 			}
 		}
@@ -683,9 +683,9 @@ void CStackQueue::StackBox::showAll(SDL_Surface * to)
 	CIntObject::showAll(to);
 
 	if(small)
-		printAtMiddleLoc(makeNumberShort(stack->count), pos.w/2, pos.h - 7, FONT_SMALL, Colors::Cornsilk, to);
+		printAtMiddleLoc(makeNumberShort(stack->count), pos.w/2, pos.h - 7, FONT_SMALL, Colors::WHITE, to);
 	else
-		printAtMiddleLoc(makeNumberShort(stack->count), pos.w/2, pos.h - 8, FONT_MEDIUM, Colors::Cornsilk, to);
+		printAtMiddleLoc(makeNumberShort(stack->count), pos.w/2, pos.h - 8, FONT_MEDIUM, Colors::WHITE, to);
 }
 
 void CStackQueue::StackBox::setStack( const CStack *stack )

+ 2 - 2
client/CAdvmapInterface.cpp

@@ -339,13 +339,13 @@ void CResDataBar::draw(SDL_Surface * to)
 	for (int i=0;i<7;i++)
 	{
 		SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
-		printAt(buf,txtpos[i].first,txtpos[i].second,FONT_SMALL,Colors::Cornsilk,to);
+		printAt(buf,txtpos[i].first,txtpos[i].second,FONT_SMALL,Colors::WHITE,to);
 	}
 	std::vector<std::string> temp;
 	SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
 	SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
 	SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
-	printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,FONT_SMALL,Colors::Cornsilk,to);
+	printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,FONT_SMALL,Colors::WHITE,to);
 	temp.clear();
 	//updateRect(&pos,screen);
 	delete[] buf;

+ 19 - 19
client/CCastleInterface.cpp

@@ -242,19 +242,19 @@ CDwellingInfoBox::CDwellingInfoBox(int centerX, int centerY, const CGTownInstanc
 
 	const CCreature * creature = CGI->creh->creatures[Town->creatures[level].second.back()];
 
-	title = new CLabel(80, 30, FONT_SMALL, CENTER, Colors::Cornsilk, creature->namePl);
+	title = new CLabel(80, 30, FONT_SMALL, CENTER, Colors::WHITE, creature->namePl);
 	animation =  new CCreaturePic(30, 44, creature, true, true);
 	
 	std::string text = boost::lexical_cast<std::string>(Town->creatures[level].first);
-	available = new CLabel(80,190, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[217] + text);
-	costPerTroop = new CLabel(80, 227, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[346]);
+	available = new CLabel(80,190, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[217] + text);
+	costPerTroop = new CLabel(80, 227, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[346]);
 	
 	for(int i = 0; i<GameConstants::RESOURCE_QUANTITY; i++)
 	{
 		if(creature->cost[i])
 		{
 			resPicture.push_back(new CAnimImage("RESOURCE", i, 0, 0, 0));
-			resAmount.push_back(new CLabel(0,0, FONT_SMALL, CENTER, Colors::Cornsilk, boost::lexical_cast<std::string>(creature->cost[i])));
+			resAmount.push_back(new CLabel(0,0, FONT_SMALL, CENTER, Colors::WHITE, boost::lexical_cast<std::string>(creature->cost[i])));
 		}
 	}
 
@@ -852,7 +852,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, const CGTownInst
 
 	garr = new CGarrisonInt(305, 387, 4, Point(0,96), panel->bg, Point(62,374), town->getUpperArmy(), town->visitingHero);
 	heroes = new HeroSlots(town, Point(241, 387), Point(241, 483), garr, true);
-	title = new CLabel(85, 387, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk, town->name);
+	title = new CLabel(85, 387, FONT_MEDIUM, TOPLEFT, Colors::WHITE, town->name);
 	income = new CLabel(195, 443, FONT_SMALL, CENTER);
 	icon = new CAnimImage("ITPT", 0, 0, 15, 387);
 
@@ -986,14 +986,14 @@ CCreaInfo::CCreaInfo(Point position, const CGTownInstance *Town, int Level, bool
 
 	if (compact)
 	{
-		label = new CLabel(40, 32, FONT_TINY, BOTTOMRIGHT, Colors::Cornsilk, value);
+		label = new CLabel(40, 32, FONT_TINY, BOTTOMRIGHT, Colors::WHITE, value);
 		pos.x += 8;
 		pos.w = 32;
 		pos.h = 32;
 	}
 	else
 	{
-		label = new CLabel(24, 40, FONT_SMALL, CENTER, Colors::Cornsilk, value);
+		label = new CLabel(24, 40, FONT_SMALL, CENTER, Colors::WHITE, value);
 		pos.w = 48;
 		pos.h = 48;
 	}
@@ -1275,7 +1275,7 @@ CHallInterface::CBuildingBox::CBuildingBox(int x, int y, const CGTownInstance *
 	panel = new CAnimImage("TPTHBAR", panelIndex[state], 0,   1, 73);
 	if ( iconIndex[state] >=0 )
 		icon  = new CAnimImage("TPTHCHK",  iconIndex[state], 0, 136, 56);
-	label = new CLabel(75, 81, FONT_SMALL, CENTER, Colors::Cornsilk, building->Name());
+	label = new CLabel(75, 81, FONT_SMALL, CENTER, Colors::WHITE, building->Name());
 }
 
 CHallInterface::CHallInterface(const CGTownInstance *Town):
@@ -1290,7 +1290,7 @@ CHallInterface::CHallInterface(const CGTownInstance *Town):
 	Rect barRect(5, 556, 740, 18);
 	statusBar = new CGStatusBar(new CPicture(*background, barRect, 5, 556, false));
 
-	title = new CLabel(399, 12, FONT_MEDIUM, CENTER, Colors::Cornsilk, town->town->buildings[town->hallLevel()+EBuilding::VILLAGE_HALL]->Name());
+	title = new CLabel(399, 12, FONT_MEDIUM, CENTER, Colors::WHITE, town->town->buildings[town->hallLevel()+EBuilding::VILLAGE_HALL]->Name());
 	exit = new CAdventureMapButton(CGI->generaltexth->hcommands[8], "", 
 	           boost::bind(&CHallInterface::close,this), 748, 556, "TPMAGE1.DEF", SDLK_RETURN);
 	exit->assignedKeys.insert(SDLK_ESCAPE);
@@ -1364,7 +1364,7 @@ CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Buildin
 	new CAnimImage(town->town->clientInfo.buildingsIcons, building->bid, 0, 125, 50);
 	new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
 
-	new CLabel(197, 30, FONT_MEDIUM, CENTER, Colors::Cornsilk,
+	new CLabel(197, 30, FONT_MEDIUM, CENTER, Colors::WHITE,
 	            boost::str(boost::format(CGI->generaltexth->hcommands[7]) % building->Name()));
 	new CTextBox(building->Description(), Rect(33, 135, 329, 67), 0, FONT_MEDIUM, CENTER);
 	new CTextBox(getTextForState(state),  Rect(33, 216, 329, 67), 0, FONT_SMALL,  CENTER);
@@ -1419,7 +1419,7 @@ CFortScreen::CFortScreen(const CGTownInstance * town):
 		fortSize--;
 	
 	const CBuilding *fortBuilding = town->town->buildings[town->fortLevel()+6];
-	title = new CLabel(400, 12, FONT_BIG, CENTER, Colors::Cornsilk, fortBuilding->Name());
+	title = new CLabel(400, 12, FONT_BIG, CENTER, Colors::WHITE, fortBuilding->Name());
 	
 	std::string text = boost::str(boost::format(CGI->generaltexth->fcommands[6]) % fortBuilding->Name());
 	exit = new CAdventureMapButton(text, "", boost::bind(&CFortScreen::close,this) ,748, 556, "TPMAGE1", SDLK_RETURN);
@@ -1494,8 +1494,8 @@ void LabeledValue::init(std::string nameText, std::string descr, int min, int ma
 		if (min != max)
 			valueText += '-' + boost::lexical_cast<std::string>(max);
 	}
-	name =  new CLabel(3, 0, FONT_SMALL, TOPLEFT, Colors::Cornsilk, nameText);
-	value = new CLabel(pos.w-3, pos.h-2, FONT_SMALL, BOTTOMRIGHT, Colors::Cornsilk, valueText);
+	name =  new CLabel(3, 0, FONT_SMALL, TOPLEFT, Colors::WHITE, nameText);
+	value = new CLabel(pos.w-3, pos.h-2, FONT_SMALL, BOTTOMRIGHT, Colors::WHITE, valueText);
 }
 
 void LabeledValue::hover(bool on)
@@ -1549,14 +1549,14 @@ CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance *
 	sizes.y+=20;
 	values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[194], CGI->generaltexth->fcommands[5], town->creatureGrowth(level)));
 
-	creatureName = new CLabel(78,  11, FONT_SMALL, CENTER, Colors::Cornsilk, creature->namePl);
-	dwellingName = new CLabel(78, 101, FONT_SMALL, CENTER, Colors::Cornsilk, town->town->buildings[buildingID]->Name());
+	creatureName = new CLabel(78,  11, FONT_SMALL, CENTER, Colors::WHITE, creature->namePl);
+	dwellingName = new CLabel(78, 101, FONT_SMALL, CENTER, Colors::WHITE, town->town->buildings[buildingID]->Name());
 
 	if (vstd::contains(town->builtBuildings, buildingID))
 	{
 		ui32 available = town->creatures[level].first;
 		std::string availableText = CGI->generaltexth->allTexts[217]+ boost::lexical_cast<std::string>(available);
-		availableCount = new CLabel(78, 119, FONT_SMALL, CENTER, Colors::Cornsilk, availableText);
+		availableCount = new CLabel(78, 119, FONT_SMALL, CENTER, Colors::WHITE, availableText);
 	}
 }
 
@@ -1687,10 +1687,10 @@ CBlacksmithDialog::CBlacksmithDialog(bool possible, int creMachineID, int aid, i
 	anim = new CCreatureAnim(64, 50, creature->animDefName, Rect());
 	anim->clipRect(113,125,200,150);
 	
-	title = new CLabel(165, 28, FONT_BIG, CENTER, Colors::Jasmine, 
+	title = new CLabel(165, 28, FONT_BIG, CENTER, Colors::YELLOW, 
 	            boost::str(boost::format(CGI->generaltexth->allTexts[274]) % creature->nameSing));
-	costText = new CLabel(165, 218, FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->jktexts[43]);
-	costValue = new CLabel(165, 290, FONT_MEDIUM, CENTER, Colors::Cornsilk,
+	costText = new CLabel(165, 218, FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->jktexts[43]);
+	costValue = new CLabel(165, 290, FONT_MEDIUM, CENTER, Colors::WHITE,
 	                boost::lexical_cast<std::string>(CGI->arth->artifacts[aid]->price));
 
 	std::string text = boost::str(boost::format(CGI->generaltexth->allTexts[595]) % creature->nameSing);

+ 17 - 17
client/CCreatureWindow.cpp

@@ -314,10 +314,10 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode *
 				break;
 		}
 		//print commander level
-		new CLabel(488, 62, FONT_MEDIUM, CENTER, Colors::Jasmine,
+		new CLabel(488, 62, FONT_MEDIUM, CENTER, Colors::YELLOW,
 		           boost::lexical_cast<std::string>((ui16)(commander->level)));
 
-		new CLabel(488, 82, FONT_SMALL, CENTER, Colors::Cornsilk,
+		new CLabel(488, 82, FONT_SMALL, CENTER, Colors::WHITE,
 		           boost::lexical_cast<std::string>(stack->experience));
 	}
 	else
@@ -346,8 +346,8 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode *
 		if (CGI->modh->modules.STACK_EXP && type < COMMANDER)
 		{
 			int rank = std::min(stack->getExpRank(), 10); //hopefully nobody adds more
-			new CLabel(488, 82, FONT_SMALL, CENTER, Colors::Cornsilk, boost::lexical_cast<std::string>(stack->experience));
-			new CLabel(488, 62, FONT_MEDIUM, CENTER, Colors::Jasmine,
+			new CLabel(488, 82, FONT_SMALL, CENTER, Colors::WHITE, boost::lexical_cast<std::string>(stack->experience));
+			new CLabel(488, 62, FONT_MEDIUM, CENTER, Colors::YELLOW,
 			           CGI->generaltexth->zcrexp[rank] + " [" + boost::lexical_cast<std::string>(rank) + "]");
 
 			if (type > BATTLE) //we need it only on adv. map
@@ -450,7 +450,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode *
 
 void CCreatureWindow::printLine(int nr, const std::string &text, int baseVal, int val/*=-1*/, bool range/*=false*/)
 {
-	new CLabel(162, 48 + nr*19, FONT_SMALL, TOPLEFT, Colors::Cornsilk, text);
+	new CLabel(162, 48 + nr*19, FONT_SMALL, TOPLEFT, Colors::WHITE, text);
 
 	std::string hlp;
 	if(range && baseVal != val)
@@ -460,7 +460,7 @@ void CCreatureWindow::printLine(int nr, const std::string &text, int baseVal, in
 	else
 		hlp = boost::lexical_cast<std::string>(baseVal);
 
-	new CLabel(325, 64 + nr*19, FONT_SMALL, BOTTOMRIGHT, Colors::Cornsilk, hlp);
+	new CLabel(325, 64 + nr*19, FONT_SMALL, BOTTOMRIGHT, Colors::WHITE, hlp);
 }
 
 void CCreatureWindow::recreateSkillList(int Pos)
@@ -509,7 +509,7 @@ void CCreatureWindow::showAll(SDL_Surface * to)
 {
 	CIntObject::showAll(to);
 
-	printAtMiddleLoc((type >= COMMANDER ? c->nameSing : c->namePl), 180, 30, FONT_SMALL, Colors::Jasmine, to); //creature name
+	printAtMiddleLoc((type >= COMMANDER ? c->nameSing : c->namePl), 180, 30, FONT_SMALL, Colors::YELLOW, to); //creature name
 
 	printLine(0, CGI->generaltexth->primarySkillNames[0], c->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), stackNode->Attack());
 	printLine(1, CGI->generaltexth->primarySkillNames[1], c->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE), stackNode->Defense());
@@ -523,13 +523,13 @@ void CCreatureWindow::showAll(SDL_Surface * to)
 	}
 	if (stackNode->valOfBonuses(Bonus::CASTS))
 	{
-		printAtMiddleLoc(CGI->generaltexth->allTexts[399], 356, 62, FONT_SMALL, Colors::Cornsilk, to);
+		printAtMiddleLoc(CGI->generaltexth->allTexts[399], 356, 62, FONT_SMALL, Colors::WHITE, to);
 		std::string casts;
 		if (type == BATTLE)
 			casts = boost::lexical_cast<std::string>((ui16)dynamic_cast<const CStack*>(stackNode)->casts); //ui8 is converted to char :(
 		else
 			casts = boost::lexical_cast<std::string>(stackNode->valOfBonuses(Bonus::CASTS));
-		printAtMiddleLoc(casts, 356, 82, FONT_SMALL, Colors::Cornsilk, to);
+		printAtMiddleLoc(casts, 356, 82, FONT_SMALL, Colors::WHITE, to);
 	}
 
 	//TODO
@@ -563,7 +563,7 @@ void CCreatureWindow::showAll(SDL_Surface * to)
 void CCreatureWindow::show(SDL_Surface * to)
 {
 	if (count.size()) //army stack
-		printTo(count, pos.x + 114, pos.y + 174,FONT_TIMES, Colors::Cornsilk, to);
+		printTo(count, pos.x + 114, pos.y + 174,FONT_TIMES, Colors::WHITE, to);
 }
 
 
@@ -710,8 +710,8 @@ void CBonusItem::showAll (SDL_Surface * to)
 {
 	if (visible)
 	{
-		printAt(name, pos.x + 72, pos.y + 6, FONT_SMALL, Colors::Jasmine, to);
-		printAt(description, pos.x + 72, pos.y + 30, FONT_SMALL, Colors::Cornsilk, to);
+		printAt(name, pos.x + 72, pos.y + 6, FONT_SMALL, Colors::YELLOW, to);
+		printAt(description, pos.x + 72, pos.y + 30, FONT_SMALL, Colors::WHITE, to);
 		if (bonusGraphics && bonusGraphics->bg)
 			blitAtLoc(bonusGraphics->bg, 12, 2, to);
 	}
@@ -807,7 +807,7 @@ CCreInfoWindow::~CCreInfoWindow()
 
 void CCreInfoWindow::printLine(int position, const std::string &text, int baseVal, int val/*=-1*/, bool range/*=false*/)
 {
-	infoTexts[position].first = new CLabel(155, 48 + position*19, FONT_SMALL, TOPLEFT, Colors::Cornsilk, text);
+	infoTexts[position].first = new CLabel(155, 48 + position*19, FONT_SMALL, TOPLEFT, Colors::WHITE, text);
 	std::string valueStr;
 
 	if(range && baseVal != val)
@@ -819,7 +819,7 @@ void CCreInfoWindow::printLine(int position, const std::string &text, int baseVa
 	else
 		valueStr = boost::lexical_cast<std::string>(baseVal);
 
-	infoTexts[position].second = new CLabel(276, 63 + position*19, FONT_SMALL, BOTTOMRIGHT, Colors::Cornsilk, valueStr);
+	infoTexts[position].second = new CLabel(276, 63 + position*19, FONT_SMALL, BOTTOMRIGHT, Colors::WHITE, valueStr);
 }
 
 void CCreInfoWindow::init(const CCreature *creature, const CBonusSystemNode *stackNode, const CGHeroInstance *heroOwner, int count, bool LClicked)
@@ -834,9 +834,9 @@ void CCreInfoWindow::init(const CCreature *creature, const CBonusSystemNode *sta
 	animation = new CCreaturePic(21, 48, creature);
 
 	std::string countStr = boost::lexical_cast<std::string>(count);
-	creatureCount = new CLabel(114, 174, FONT_TIMES, BOTTOMRIGHT, Colors::Cornsilk, countStr);
+	creatureCount = new CLabel(114, 174, FONT_TIMES, BOTTOMRIGHT, Colors::WHITE, countStr);
 
-	creatureName = new CLabel(149, 30, FONT_SMALL, CENTER, Colors::Jasmine, creature->namePl);
+	creatureName = new CLabel(149, 30, FONT_SMALL, CENTER, Colors::YELLOW, creature->namePl);
 
 	printLine(0, CGI->generaltexth->primarySkillNames[0], creature->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), stackNode->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK));
 	printLine(1, CGI->generaltexth->primarySkillNames[1], creature->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE), stackNode->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE));
@@ -862,7 +862,7 @@ void CCreInfoWindow::init(const CCreature *creature, const CBonusSystemNode *sta
 
 	if(!LClicked)
 	{
-		abilityText = new CLabel(17, 231, FONT_SMALL, TOPLEFT, Colors::Cornsilk, creature->abilityText);
+		abilityText = new CLabel(17, 231, FONT_SMALL, TOPLEFT, Colors::WHITE, creature->abilityText);
 	}
 	else
 	{

+ 21 - 21
client/CHeroWindow.cpp

@@ -324,41 +324,41 @@ void CHeroWindow::showAll(SDL_Surface * to)
 	CIntObject::showAll(to);
 	 
 	//printing hero's name
-	printAtMiddleLoc(curHero->name, 190, 38, FONT_BIG, Colors::Jasmine, to);
+	printAtMiddleLoc(curHero->name, 190, 38, FONT_BIG, Colors::YELLOW, to);
 	 
 	//printing hero's level
 	std::string secondLine= CGI->generaltexth->allTexts[342];
 	boost::algorithm::replace_first(secondLine,"%d",boost::lexical_cast<std::string>(curHero->level));
 	boost::algorithm::replace_first(secondLine,"%s",curHero->type->heroClass->name);
-	printAtMiddleLoc(secondLine, 190, 65, FONT_MEDIUM, Colors::Cornsilk, to);
+	printAtMiddleLoc(secondLine, 190, 65, FONT_MEDIUM, Colors::WHITE, to);
 	 	
 	//primary skills names
-	printAtMiddleLoc(CGI->generaltexth->jktexts[1], 52, 99, FONT_SMALL, Colors::Jasmine, to);
-	printAtMiddleLoc(CGI->generaltexth->jktexts[2], 123, 99, FONT_SMALL, Colors::Jasmine, to);
-	printAtMiddleLoc(CGI->generaltexth->jktexts[3], 193, 99, FONT_SMALL, Colors::Jasmine, to);
-	printAtMiddleLoc(CGI->generaltexth->jktexts[4], 262, 99, FONT_SMALL, Colors::Jasmine, to);
+	printAtMiddleLoc(CGI->generaltexth->jktexts[1], 52, 99, FONT_SMALL, Colors::YELLOW, to);
+	printAtMiddleLoc(CGI->generaltexth->jktexts[2], 123, 99, FONT_SMALL, Colors::YELLOW, to);
+	printAtMiddleLoc(CGI->generaltexth->jktexts[3], 193, 99, FONT_SMALL, Colors::YELLOW, to);
+	printAtMiddleLoc(CGI->generaltexth->jktexts[4], 262, 99, FONT_SMALL, Colors::YELLOW, to);
 	 
 	//dismiss / quest log
 	std::vector<std::string> toPrin = CMessage::breakText(CGI->generaltexth->jktexts[8]);
 	if(toPrin.size()==1)
 	{
-	 	printAtLoc(toPrin[0], 372, 439, FONT_SMALL, Colors::Cornsilk, to);
+	 	printAtLoc(toPrin[0], 372, 439, FONT_SMALL, Colors::WHITE, to);
 	}
 	else
 	{
-	 	printAtLoc(toPrin[0], 372, 430, FONT_SMALL, Colors::Cornsilk, to);
-	 	printAtLoc(toPrin[1], 372, 446, FONT_SMALL, Colors::Cornsilk, to);
+	 	printAtLoc(toPrin[0], 372, 430, FONT_SMALL, Colors::WHITE, to);
+	 	printAtLoc(toPrin[1], 372, 446, FONT_SMALL, Colors::WHITE, to);
 	}
 	 
 	toPrin = CMessage::breakText(CGI->generaltexth->jktexts[9]);
 	if(toPrin.size()==1)
 	{
-	 	printAtLoc(toPrin[0], 512, 439, FONT_SMALL, Colors::Cornsilk, to);
+	 	printAtLoc(toPrin[0], 512, 439, FONT_SMALL, Colors::WHITE, to);
 	}
 	else
 	{
-	 	printAtLoc(toPrin[0], 512, 430, FONT_SMALL, Colors::Cornsilk, to);
-	 	printAtLoc(toPrin[1], 512, 446, FONT_SMALL, Colors::Cornsilk, to);
+	 	printAtLoc(toPrin[0], 512, 430, FONT_SMALL, Colors::WHITE, to);
+	 	printAtLoc(toPrin[1], 512, 446, FONT_SMALL, Colors::WHITE, to);
 	}
 	 
 	//printing primary skills' amounts
@@ -366,27 +366,27 @@ void CHeroWindow::showAll(SDL_Surface * to)
 	{
 	 	std::ostringstream primarySkill;
 	 	primarySkill << primSkillAreas[m]->bonusValue;
-	 	printAtMiddleLoc(primarySkill.str(), 53 + 70 * m, 166, FONT_SMALL, Colors::Cornsilk, to);
+	 	printAtMiddleLoc(primarySkill.str(), 53 + 70 * m, 166, FONT_SMALL, Colors::WHITE, to);
 	}
 	 
 	//secondary skills
 	for(size_t v=0; v<std::min(secSkillAreas.size(), curHero->secSkills.size()); ++v)
 	{
-	 	printAtLoc(CGI->generaltexth->levels[curHero->secSkills[v].second-1], (v%2) ? 212 : 68, 280 + 48 * (v/2), FONT_SMALL, Colors::Cornsilk, to);
-	 	printAtLoc(CGI->generaltexth->skillName[curHero->secSkills[v].first], (v%2) ? 212 : 68, 300 + 48 * (v/2), FONT_SMALL, Colors::Cornsilk, to);
+	 	printAtLoc(CGI->generaltexth->levels[curHero->secSkills[v].second-1], (v%2) ? 212 : 68, 280 + 48 * (v/2), FONT_SMALL, Colors::WHITE, to);
+	 	printAtLoc(CGI->generaltexth->skillName[curHero->secSkills[v].first], (v%2) ? 212 : 68, 300 + 48 * (v/2), FONT_SMALL, Colors::WHITE, to);
 	}
 	 
 	//printing special ability
-	printAtLoc(CGI->generaltexth->jktexts[5].substr(1, CGI->generaltexth->jktexts[5].size()-2), 69, 183, FONT_SMALL, Colors::Jasmine, to);
-	printAtLoc(CGI->generaltexth->hTxts[curHero->subID].bonusName, 69, 205, FONT_SMALL, Colors::Cornsilk, to);
+	printAtLoc(CGI->generaltexth->jktexts[5].substr(1, CGI->generaltexth->jktexts[5].size()-2), 69, 183, FONT_SMALL, Colors::YELLOW, to);
+	printAtLoc(CGI->generaltexth->hTxts[curHero->subID].bonusName, 69, 205, FONT_SMALL, Colors::WHITE, to);
 	 
 	//printing necessery texts
-	printAtLoc(CGI->generaltexth->jktexts[6].substr(1, CGI->generaltexth->jktexts[6].size()-2), 69, 232, FONT_SMALL, Colors::Jasmine, to);
+	printAtLoc(CGI->generaltexth->jktexts[6].substr(1, CGI->generaltexth->jktexts[6].size()-2), 69, 232, FONT_SMALL, Colors::YELLOW, to);
 	std::ostringstream expstr;
 	expstr << curHero->exp;
-	printAtLoc(expstr.str(), 68, 252, FONT_SMALL, Colors::Cornsilk, to);
-	printAtLoc(CGI->generaltexth->jktexts[7].substr(1, CGI->generaltexth->jktexts[7].size()-2), 213, 232, FONT_SMALL, Colors::Jasmine, to);
+	printAtLoc(expstr.str(), 68, 252, FONT_SMALL, Colors::WHITE, to);
+	printAtLoc(CGI->generaltexth->jktexts[7].substr(1, CGI->generaltexth->jktexts[7].size()-2), 213, 232, FONT_SMALL, Colors::YELLOW, to);
 	std::ostringstream manastr;
 	manastr << curHero->mana << '/' << heroWArt.manaLimit();
-	printAtLoc(manastr.str(), 211, 252, FONT_SMALL, Colors::Cornsilk, to);
+	printAtLoc(manastr.str(), 211, 252, FONT_SMALL, Colors::WHITE, to);
 }

+ 18 - 18
client/CKingdomInterface.cpp

@@ -47,21 +47,21 @@ InfoBox::InfoBox(Point position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data)
 	pos = image->pos;
 
 	if (infoPos == POS_CORNER)
-		value = new CLabel(pos.w, pos.h, font, BOTTOMRIGHT, Colors::Cornsilk, data->getValueText());
+		value = new CLabel(pos.w, pos.h, font, BOTTOMRIGHT, Colors::WHITE, data->getValueText());
 
 	if (infoPos == POS_INSIDE)
-		value = new CLabel(pos.w/2, pos.h-6, font, CENTER, Colors::Cornsilk, data->getValueText());
+		value = new CLabel(pos.w/2, pos.h-6, font, CENTER, Colors::WHITE, data->getValueText());
 
 	if (infoPos == POS_UP_DOWN || infoPos == POS_DOWN)
-		value = new CLabel(pos.w/2, pos.h+8, font, CENTER, Colors::Cornsilk, data->getValueText());
+		value = new CLabel(pos.w/2, pos.h+8, font, CENTER, Colors::WHITE, data->getValueText());
 
 	if (infoPos == POS_UP_DOWN)
-		name = new CLabel(pos.w/2, -12, font, CENTER, Colors::Cornsilk, data->getNameText());
+		name = new CLabel(pos.w/2, -12, font, CENTER, Colors::WHITE, data->getNameText());
 
 	if (infoPos == POS_RIGHT)
 	{
-		name = new CLabel(pos.w+6, 6, font, TOPLEFT, Colors::Cornsilk, data->getNameText());
-		value = new CLabel(pos.w+6, pos.h-16, font, TOPLEFT, Colors::Cornsilk, data->getValueText());
+		name = new CLabel(pos.w+6, 6, font, TOPLEFT, Colors::WHITE, data->getNameText());
+		value = new CLabel(pos.w+6, pos.h-16, font, TOPLEFT, Colors::WHITE, data->getValueText());
 	}
 	pos = image->pos;
 	if (name)
@@ -604,7 +604,7 @@ void CKingdomInterface::generateMinesList(const std::vector<const CGObjectInstan
 	incomeArea = new CHoverableArea;
 	incomeArea->pos = Rect(pos.x+580, pos.y+31+footerPos, 136, 68);
 	incomeArea->hoverText = CGI->generaltexth->allTexts[255];
-	incomeAmount = new CLabel(628, footerPos + 70, FONT_SMALL, TOPLEFT, Colors::Cornsilk, boost::lexical_cast<std::string>(totalIncome));
+	incomeAmount = new CLabel(628, footerPos + 70, FONT_SMALL, TOPLEFT, Colors::WHITE, boost::lexical_cast<std::string>(totalIncome));
 }
 
 void CKingdomInterface::generateButtons()
@@ -689,8 +689,8 @@ CKingdHeroList::CKingdHeroList(size_t maxSize)
 	OBJ_CONSTRUCTION_CAPTURING_ALL;
 	title = new CPicture("OVTITLE",16,0);
 	title->colorize(LOCPLINT->playerID);
-	heroLabel =   new CLabel(150, 10, FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->overview[0]);
-	skillsLabel = new CLabel(500, 10, FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->overview[1]);
+	heroLabel =   new CLabel(150, 10, FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->overview[0]);
+	skillsLabel = new CLabel(500, 10, FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->overview[1]);
 
 	ui32 townCount = LOCPLINT->cb->howManyHeroes(false);
 	ui32 size = conf.go()->ac.overviewSize*116 + 19;
@@ -741,9 +741,9 @@ CKingdTownList::CKingdTownList(size_t maxSize)
 	OBJ_CONSTRUCTION_CAPTURING_ALL;
 	title = new CPicture("OVTITLE",16,0);
 	title->colorize(LOCPLINT->playerID);
-	townLabel   = new CLabel(146,10,FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->overview[3]);
-	garrHeroLabel  = new CLabel(375,10,FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->overview[4]);
-	visitHeroLabel = new CLabel(608,10,FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->overview[5]);
+	townLabel   = new CLabel(146,10,FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->overview[3]);
+	garrHeroLabel  = new CLabel(375,10,FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->overview[4]);
+	visitHeroLabel = new CLabel(608,10,FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->overview[5]);
 
 	ui32 townCount = LOCPLINT->cb->howManyTowns();
 	ui32 size = conf.go()->ac.overviewSize*116 + 19;
@@ -788,9 +788,9 @@ CTownItem::CTownItem(const CGTownInstance* Town):
 {
 	OBJ_CONSTRUCTION_CAPTURING_ALL;
 	background =  new CAnimImage("OVSLOT", 6);
-	name = new CLabel(74, 8, FONT_SMALL, TOPLEFT, Colors::Cornsilk, town->name);
+	name = new CLabel(74, 8, FONT_SMALL, TOPLEFT, Colors::WHITE, town->name);
 
-	income = new CLabel( 190, 60, FONT_SMALL, CENTER, Colors::Cornsilk, boost::lexical_cast<std::string>(town->dailyIncome()));
+	income = new CLabel( 190, 60, FONT_SMALL, CENTER, Colors::WHITE, boost::lexical_cast<std::string>(town->dailyIncome()));
 	hall = new CTownInfo( 69, 31, town, true);
 	fort = new CTownInfo(111, 31, town, false);
 
@@ -886,7 +886,7 @@ CHeroItem::CHeroItem(const CGHeroInstance* Hero, CArtifactsOfHero::SCommonPart *
 	arts2->recActions = DISPOSE | SHARE_POS;
 	backpack->recActions = DISPOSE | SHARE_POS;
 
-	name = new CLabel(75, 7, FONT_SMALL, TOPLEFT, Colors::Cornsilk, hero->name);
+	name = new CLabel(75, 7, FONT_SMALL, TOPLEFT, Colors::WHITE, hero->name);
 
 	std::vector<CArtPlace*> arts;
 	arts.insert(arts.end(), arts1->arts.begin(), arts1->arts.end());
@@ -910,7 +910,7 @@ CHeroItem::CHeroItem(const CGHeroInstance* Hero, CArtifactsOfHero::SCommonPart *
 		size_t begin = overlay.find('{');
 		size_t end   = overlay.find('}', begin);
 		overlay = overlay.substr(begin+1, end - begin);
-		artButtons->buttons[it]->addTextOverlay(overlay, FONT_SMALL, Colors::Jasmine);
+		artButtons->buttons[it]->addTextOverlay(overlay, FONT_SMALL, Colors::YELLOW);
 	}
 	artButtons->onChange += boost::bind(&CTabbedInt::setActive, artsTabs, _1);
 	artButtons->onChange += boost::bind(&CHeroItem::onArtChange, this, _1);
@@ -921,8 +921,8 @@ CHeroItem::CHeroItem(const CGHeroInstance* Hero, CArtifactsOfHero::SCommonPart *
 	portrait = new CAnimImage("PortraitsLarge", hero->subID, 0, 5, 6);
 	heroArea = new CHeroArea(5, 6, hero);
 
-	name = new CLabel(73, 7, FONT_SMALL, TOPLEFT, Colors::Cornsilk, hero->name);
-	artsText = new CLabel(320, 55, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->overview[2]);
+	name = new CLabel(73, 7, FONT_SMALL, TOPLEFT, Colors::WHITE, hero->name);
+	artsText = new CLabel(320, 55, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->overview[2]);
 
 	for (size_t i=0; i<GameConstants::PRIMARY_SKILLS; i++)
 		heroInfo.push_back(new InfoBox(Point(78+i*36, 26), InfoBox::POS_DOWN, InfoBox::SIZE_SMALL, 

+ 5 - 5
client/CMessage.cpp

@@ -277,7 +277,7 @@ SDL_Surface * CMessage::blitTextOnSur(std::vector<std::vector<SDL_Surface*> > *
 	return ret;
 }
 
-SDL_Surface * FNT_RenderText (EFonts font, std::string text, SDL_Color kolor= Colors::Cornsilk)
+SDL_Surface * FNT_RenderText (EFonts font, std::string text, SDL_Color kolor= Colors::WHITE)
 {
 	if (graphics->fontsTrueType[font])
 		return TTF_RenderText_Blended(graphics->fontsTrueType[font], text.c_str(), kolor);
@@ -312,7 +312,7 @@ std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::st
 				z++;
 
 			if (z)
-				(*txtg)[i].push_back(FNT_RenderText(font, (*brtext)[i].substr(0,z), Colors::Cornsilk));
+				(*txtg)[i].push_back(FNT_RenderText(font, (*brtext)[i].substr(0,z), Colors::WHITE));
 			(*brtext)[i].erase(0,z);
 
 			if ((*brtext)[i].length() && (*brtext)[i][0] == '{')
@@ -329,7 +329,7 @@ std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::st
 				z++;
 
 			if (z)
-				(*txtg)[i].push_back(FNT_RenderText(font, (*brtext)[i].substr(0,z), Colors::Jasmine));
+				(*txtg)[i].push_back(FNT_RenderText(font, (*brtext)[i].substr(0,z), Colors::YELLOW));
 			(*brtext)[i].erase(0,z);
 
 			if ((*brtext)[i].length() && (*brtext)[i][0] == '}')
@@ -363,7 +363,7 @@ SDL_Surface * CMessage::drawBoxTextBitmapSub( int player, std::string text, SDL_
 	curh += imgToBmp;
 	blitAt(bitmap,(ret->w/2)-(bitmap->w/2),curh,ret);
 	curh += bitmap->h + 5;
-	CSDL_Ext::printAtMiddle(sub,ret->w/2,curh+10,FONT_SMALL,Colors::Cornsilk,ret);
+	CSDL_Ext::printAtMiddle(sub,ret->w/2,curh+10,FONT_SMALL,Colors::WHITE,ret);
 	delete txtg;
 	return ret;
 }
@@ -373,7 +373,7 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player)
 	SDL_Surface * _or = NULL;
 
 	if(dynamic_cast<CSelWindow*>(ret)) //it's selection window, so we'll blit "or" between components
-		_or = FNT_RenderText(FONT_MEDIUM,CGI->generaltexth->allTexts[4],Colors::Cornsilk);
+		_or = FNT_RenderText(FONT_MEDIUM,CGI->generaltexth->allTexts[4],Colors::WHITE);
 
 	const int sizes[][2] = {{400, 125}, {500, 150}, {600, 200}, {480, 400}};
 

+ 313 - 82
client/CPreGame.cpp

@@ -101,8 +101,8 @@ static void do_quit()
 
 static CMapInfo *mapInfoFromGame()
 {
-    CMapInfo * ret = new CMapInfo();
-    ret->mapHeader = std::unique_ptr<CMapHeader>(new CMapHeader(*LOCPLINT->cb->getMapHeader()));
+	CMapInfo * ret = new CMapInfo();
+	ret->mapHeader = std::unique_ptr<CMapHeader>(new CMapHeader(*LOCPLINT->cb->getMapHeader()));
 	return ret;
 }
 
@@ -390,7 +390,7 @@ CreditsScreen::CreditsScreen()
 	std::string text((char*)textFile.first.get(), textFile.second);
 	size_t firstQuote = text.find('\"')+1;
 	text = text.substr(firstQuote, text.find('\"', firstQuote) - firstQuote );
-	credits = new CTextBox(text, Rect(pos.w - 350, 600, 350, 32000), 0, FONT_CREDITS, CENTER, Colors::Cornsilk);
+	credits = new CTextBox(text, Rect(pos.w - 350, 600, 350, 32000), 0, FONT_CREDITS, CENTER, Colors::WHITE);
 	credits->pos.h = credits->maxH;
 }
 
@@ -595,6 +595,9 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMulti
 	{
 		opt = new OptionsTab(); //scenario options tab
 		opt->recActions = DISPOSE;
+
+		randMapTab = new RandomMapTab;
+		randMapTab->recActions = DISPOSE;
 	}
 	sel = new SelectionTab(screenType, bind(&CSelectionScreen::changeSelection, this, _1), multiPlayer); //scenario selection tab
 	sel->recActions = DISPOSE;
@@ -611,8 +614,12 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMulti
 			CAdventureMapButton *opts = new CAdventureMapButton(CGI->generaltexth->zelp[46], bind(&CSelectionScreen::toggleTab, this, opt), 411, 510, "GSPBUTT.DEF", SDLK_a);
 			opts->addTextOverlay(CGI->generaltexth->allTexts[501], FONT_SMALL);
 
-			CAdventureMapButton *random = new CAdventureMapButton(CGI->generaltexth->zelp[47], bind(&CSelectionScreen::toggleTab, this, sel), 411, 105, "GSPBUTT.DEF", SDLK_r);
-			random->addTextOverlay(CGI->generaltexth->allTexts[740], FONT_SMALL);
+			CAdventureMapButton * randomBtn = new CAdventureMapButton(CGI->generaltexth->zelp[47], 0, 411, 105, "GSPBUTT.DEF", SDLK_r);
+			randomBtn->addTextOverlay(CGI->generaltexth->allTexts[740], FONT_SMALL);
+			if(settings["general"]["enableRMG"].Bool())
+			{
+				randomBtn->callback = bind(&CSelectionScreen::toggleTab, this, randMapTab);
+			}
 
 			start  = new CAdventureMapButton(CGI->generaltexth->zelp[103], bind(&CSelectionScreen::startGame, this), 411, 535, "SCNRBEG.DEF", SDLK_b);
 
@@ -624,10 +631,10 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMulti
 				if(multiPlayer == CMenuScreen::MULTI_NETWORK_GUEST)
 				{
 					SDL_Color orange = {232, 184, 32, 0};
-					select->text->color = opts->text->color = random->text->color = orange;
+					select->text->color = opts->text->color = randomBtn->text->color = orange;
 					select->block(true);
 					opts->block(true);
-					random->block(true);
+					randomBtn->block(true);
 					start->block(true);
 				}
 			}
@@ -735,6 +742,8 @@ void CSelectionScreen::toggleTab(CIntObject *tab)
 			pga.action = PregameGuiAction::OPEN_OPTIONS;
 		else if(tab == sel)
 			pga.action = PregameGuiAction::OPEN_SCENARIO_LIST;
+		else if(tab == randMapTab)
+			pga.action = PregameGuiAction::OPEN_RANDOM_MAP_OPTIONS;
 
 		*serv << &pga;
 	}
@@ -771,7 +780,7 @@ void CSelectionScreen::changeSelection( const CMapInfo *to )
 	   SEL->sInfo.difficulty = to->scenarioOpts->difficulty;
 	if(screenType != CMenuScreen::campaignList)
 	{
-        updateStartInfo(to ? to->fileURI : "", sInfo, to ? to->mapHeader.get() : NULL);
+		updateStartInfo(to ? to->fileURI : "", sInfo, to ? to->mapHeader.get() : NULL);
 	}
 	card->changeSelection(to);
 	if(screenType != CMenuScreen::campaignList)
@@ -1027,7 +1036,7 @@ std::vector<ResourceID> SelectionTab::getFiles(std::string dirURI, int resType)
 	auto iterator = CResourceHandler::get()->getIterator([&](const ResourceID & ident)
 	{
 		return ident.getType() == resType
-		    && boost::algorithm::starts_with(ident.getName(), dirURI);
+			&& boost::algorithm::starts_with(ident.getName(), dirURI);
 	});
 
 	while (iterator.hasNext())
@@ -1041,8 +1050,8 @@ std::vector<ResourceID> SelectionTab::getFiles(std::string dirURI, int resType)
 
 void SelectionTab::parseMaps(const std::vector<ResourceID> & files)
 {
-    allItems.clear();
-    for(int i = 0; i < files.size(); ++i)
+	allItems.clear();
+	for(int i = 0; i < files.size(); ++i)
 	{
 		try
 		{
@@ -1276,7 +1285,7 @@ void SelectionTab::select( int position )
 	if(txt)
 	{
 		std::string filename = CResourceHandler::get()->getResourceName(
-		                           ResourceID(curItems[py]->fileURI, EResType::LIB_SAVEGAME));
+								   ResourceID(curItems[py]->fileURI, EResType::LIB_SAVEGAME));
 		txt->setTxt(CFileInfo(filename).getBaseName());
 	}
 
@@ -1322,9 +1331,9 @@ void SelectionTab::printMaps(SDL_Surface *to)
 		CMapInfo *currentItem = curItems[elemIdx];
 
 		if (elemIdx == selectionPos)
-			itemColor=Colors::Jasmine;
+			itemColor=Colors::YELLOW;
 		else
-			itemColor=Colors::Cornsilk;
+			itemColor=Colors::WHITE;
 
 		if(tabType != CMenuScreen::campaignList)
 		{
@@ -1355,16 +1364,16 @@ void SelectionTab::printMaps(SDL_Surface *to)
 			int temp=-1;
 			switch (currentItem->mapHeader->version)
 			{
-            case EMapFormat::ROE:
+			case EMapFormat::ROE:
 				temp=0;
 				break;
-            case EMapFormat::AB:
+			case EMapFormat::AB:
 				temp=1;
 				break;
-            case EMapFormat::SOD:
+			case EMapFormat::SOD:
 				temp=2;
 				break;
-            case EMapFormat::WOG:
+			case EMapFormat::WOG:
 				temp=3;
 				break;
 			default:
@@ -1410,7 +1419,7 @@ void SelectionTab::printMaps(SDL_Surface *to)
 		else
 		{
 			name = CFileInfo(CResourceHandler::get()->getResourceName(
-			                     ResourceID(currentItem->fileURI, EResType::LIB_SAVEGAME))).getBaseName();
+								 ResourceID(currentItem->fileURI, EResType::LIB_SAVEGAME))).getBaseName();
 		}
 
 		//print name
@@ -1441,10 +1450,10 @@ void SelectionTab::showAll(SDL_Surface * to)
 		break;
 	}
 
-	CSDL_Ext::printAtMiddle(title, pos.x+205, pos.y+28, FONT_MEDIUM, Colors::Jasmine, to); //Select a Scenario to Play
+	CSDL_Ext::printAtMiddle(title, pos.x+205, pos.y+28, FONT_MEDIUM, Colors::YELLOW, to); //Select a Scenario to Play
 	if(tabType != CMenuScreen::campaignList)
 	{
-		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[510], pos.x+87, pos.y+62, FONT_SMALL, Colors::Jasmine, to); //Map sizes
+		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[510], pos.x+87, pos.y+62, FONT_SMALL, Colors::YELLOW, to); //Map sizes
 	}
 }
 
@@ -1527,7 +1536,226 @@ void SelectionTab::selectFName( std::string fname )
 	selectAbs(0);
 }
 
+RandomMapTab::RandomMapTab()
+{
+	OBJ_CONSTRUCTION;
+	bg = new CPicture("RANMAPBK", 0, 6);
+
+	// Map Size
+	mapSizeBtnGroup = new CHighlightableButtonsGroup(0);
+	mapSizeBtnGroup->pos.y = 81;
+	mapSizeBtnGroup->pos.x = 158;
+	const std::vector<std::string> mapSizeBtns = boost::assign::list_of("RANSIZS")("RANSIZM")("RANSIZL")("RANSIZX");
+	addButtonsToGroup(mapSizeBtnGroup, mapSizeBtns, 0, 3, 47, 198);
+	mapSizeBtnGroup->select(1, false);
+	mapSizeBtnGroup->onChange = [&](int btnId)
+	{
+		options.setMapSize(static_cast<EMapSize::EMapSize>(btnId));
+	};
+
+	// Two levels
+	twoLevelsBtn = new CHighlightableButton(0, 0, std::map<int,std::string>(),
+		CGI->generaltexth->zelp[202].second, false, "RANUNDR", nullptr, 346, 81);
+	twoLevelsBtn->callback = [&]() { options.setHasTwoLevels(true); };
+	twoLevelsBtn->callback2 = [&]() { options.setHasTwoLevels(false); };
+	twoLevelsBtn->select(true);
+
+	// Create number defs list
+	std::vector<std::string> numberDefs;
+	for(int i = 0; i <= 8; ++i)
+	{
+		numberDefs.push_back("RANNUM" + boost::lexical_cast<std::string>(i));
+	}
+
+	const int NUMBERS_WIDTH = 32;
+	const int BTNS_GROUP_LEFT_MARGIN = 67;
+	// Amount of players
+	playersCntGroup = new CHighlightableButtonsGroup(0);
+	playersCntGroup->pos.y = 153;
+	playersCntGroup->pos.x = BTNS_GROUP_LEFT_MARGIN;
+	addButtonsWithRandToGroup(playersCntGroup, numberDefs, 1, 8, NUMBERS_WIDTH, 204, 212);
+	playersCntGroup->onChange = [&](int btnId)
+	{
+		options.setPlayersCnt(btnId);
+		deactivateButtonsFrom(teamsCntGroup, btnId);
+		deactivateButtonsFrom(compOnlyPlayersCntGroup, 8 - btnId + 1);
+		validatePlayersCnt(btnId);
+	};
+
+	// Amount of teams
+	teamsCntGroup = new CHighlightableButtonsGroup(0);
+	teamsCntGroup->pos.y = 219;
+	teamsCntGroup->pos.x = BTNS_GROUP_LEFT_MARGIN;
+	addButtonsWithRandToGroup(teamsCntGroup, numberDefs, 0, 7, NUMBERS_WIDTH, 214, 222);
+	teamsCntGroup->onChange = [&](int btnId)
+	{
+		options.setTeamsCnt(btnId);
+	};
+
+	// Computer only players
+	compOnlyPlayersCntGroup = new CHighlightableButtonsGroup(0);
+	compOnlyPlayersCntGroup->pos.y = 285;
+	compOnlyPlayersCntGroup->pos.x = BTNS_GROUP_LEFT_MARGIN;
+	addButtonsWithRandToGroup(compOnlyPlayersCntGroup, numberDefs, 0, 7, NUMBERS_WIDTH, 224, 232);
+	compOnlyPlayersCntGroup->onChange = [&](int btnId)
+	{
+		options.setCompOnlyPlayersCnt(btnId);
+		deactivateButtonsFrom(compOnlyTeamsCntGroup, btnId);
+		validateCompOnlyPlayersCnt(btnId);
+	};
+
+	// Computer only teams
+	compOnlyTeamsCntGroup = new CHighlightableButtonsGroup(0);
+	compOnlyTeamsCntGroup->pos.y = 351;
+	compOnlyTeamsCntGroup->pos.x = BTNS_GROUP_LEFT_MARGIN;
+	addButtonsWithRandToGroup(compOnlyTeamsCntGroup, numberDefs, 0, 6, NUMBERS_WIDTH, 234, 241);
+	compOnlyTeamsCntGroup->onChange = [&](int btnId)
+	{
+		options.setCompOnlyTeamsCnt(btnId);
+	};
+
+	const int WIDE_BTN_WIDTH = 85;
+	// Water content
+	waterContentGroup = new CHighlightableButtonsGroup(0);
+	waterContentGroup->pos.y = 419;
+	waterContentGroup->pos.x = BTNS_GROUP_LEFT_MARGIN;
+	const std::vector<std::string> waterContentBtns = boost::assign::list_of("RANNONE")("RANNORM")("RANISLD");
+	addButtonsWithRandToGroup(waterContentGroup, waterContentBtns, 0, 2, WIDE_BTN_WIDTH, 243, 246);
+	waterContentGroup->onChange = [&](int btnId)
+	{
+		options.setWaterContent(static_cast<EWaterContent::EWaterContent>(btnId));
+	};
+
+	// Monster strength
+	monsterStrengthGroup = new CHighlightableButtonsGroup(0);
+	monsterStrengthGroup->pos.y = 485;
+	monsterStrengthGroup->pos.x = BTNS_GROUP_LEFT_MARGIN;
+	const std::vector<std::string> monsterStrengthBtns = boost::assign::list_of("RANWEAK")("RANNORM")("RANSTRG");
+	addButtonsWithRandToGroup(monsterStrengthGroup, monsterStrengthBtns, 0, 2, WIDE_BTN_WIDTH, 248, 251);
+	monsterStrengthGroup->onChange = [&](int btnId)
+	{
+		options.setMonsterStrength(static_cast<EMonsterStrength::EMonsterStrength>(btnId));
+	};
+
+	// Show random maps btn
+	showRandMaps = new CAdventureMapButton("", CGI->generaltexth->zelp[252].second, 0, 54, 535, "RANSHOW");
+}
+
+void RandomMapTab::addButtonsWithRandToGroup(CHighlightableButtonsGroup * group, const std::vector<std::string> & defs, int nStart, int nEnd, int btnWidth, int helpStartIndex, int helpRandIndex) const
+{
+	addButtonsToGroup(group, defs, nStart, nEnd, btnWidth, helpStartIndex);
+
+	// Add rand button and select rand if help text index is given
+	const std::string randomDef = "RANRAND";
+	if (helpRandIndex != -1)
+	{
+		// Buttons are relative to button group, TODO better solution?
+		SObjectConstruction obj__i(group);
+
+		group->addButton(new CHighlightableButton("", CGI->generaltexth->zelp[helpRandIndex].second, 0, 256, 0, randomDef, -1));
+		group->select(-1, true);
+	}
+}
+
+void RandomMapTab::addButtonsToGroup(CHighlightableButtonsGroup * group, const std::vector<std::string> & defs, int nStart, int nEnd, int btnWidth, int helpStartIndex) const
+{
+	// Buttons are relative to button group, TODO better solution?
+	SObjectConstruction obj__i(group);
+
+	const int cnt = nEnd - nStart + 1;
+
+	// Buttons
+	for(int i = 0; i < cnt; ++i)
+	{
+		group->addButton(new CHighlightableButton("", CGI->generaltexth->zelp[helpStartIndex + i].second, 0, i * btnWidth, 0, defs[i + nStart], i + nStart));
+	}
+}
+
+void RandomMapTab::deactivateButtonsFrom(CHighlightableButtonsGroup * group, int startId)
+{
+	BOOST_FOREACH(CHighlightableButton * btn, group->buttons)
+	{
+		if(startId == -1 || btn->ID < startId)
+		{
+			if(btn->isBlocked())
+			{
+				btn->setOffset(0);
+				btn->setState(CButtonBase::NORMAL);
+			}
+		}
+		else
+		{
+			// Blocked state looks like frame 'selected'=1
+			btn->setOffset(-1);
+			btn->setState(CButtonBase::BLOCKED);
+		}
+	}
+}
+
+void RandomMapTab::validatePlayersCnt(int playersCnt)
+{
+	if(playersCnt == -1)
+	{
+		return;
+	}
+
+	if(options.getTeamsCnt() >= playersCnt)
+	{
+		options.setTeamsCnt(playersCnt - 1);
+		teamsCntGroup->select(options.getTeamsCnt(), true);
+	}
+	if(options.getCompOnlyPlayersCnt() > 8 - playersCnt)
+	{
+		options.setCompOnlyPlayersCnt(8 - playersCnt);
+		compOnlyPlayersCntGroup->select(options.getCompOnlyPlayersCnt(), true);
+	}
+
+	validateCompOnlyPlayersCnt(options.getCompOnlyPlayersCnt());
+}
+
+void RandomMapTab::validateCompOnlyPlayersCnt(int compOnlyPlayersCnt)
+{
+	if(compOnlyPlayersCnt == -1)
+	{
+		return;
+	}
 
+	if(options.getCompOnlyTeamsCnt() >= compOnlyPlayersCnt)
+	{
+		options.setCompOnlyTeamsCnt(compOnlyPlayersCnt - 1);
+		compOnlyTeamsCntGroup->select(options.getCompOnlyTeamsCnt(), true);
+	}
+}
+
+void RandomMapTab::showAll(SDL_Surface * to)
+{
+	CIntObject::showAll(to);
+
+	// Headline
+	printAtMiddleLoc(CGI->generaltexth->allTexts[738], 222, 36, FONT_BIG, Colors::YELLOW, to);
+	printAtMiddleLoc(CGI->generaltexth->allTexts[739], 222, 56, FONT_SMALL, Colors::WHITE, to);
+
+	// Map size
+	printAtMiddleLoc(CGI->generaltexth->allTexts[752], 104, 97, FONT_SMALL, Colors::WHITE, to);
+
+	// Players cnt
+	printAtLoc(CGI->generaltexth->allTexts[753], 68, 133, FONT_SMALL, Colors::WHITE, to);
+
+	// Teams cnt
+	printAtLoc(CGI->generaltexth->allTexts[754], 68, 199, FONT_SMALL, Colors::WHITE, to);
+
+	// Computer only players cnt
+	printAtLoc(CGI->generaltexth->allTexts[755], 68, 265, FONT_SMALL, Colors::WHITE, to);
+
+	// Computer only teams cnt
+	printAtLoc(CGI->generaltexth->allTexts[756], 68, 331, FONT_SMALL, Colors::WHITE, to);
+
+	// Water content
+	printAtLoc(CGI->generaltexth->allTexts[757], 68, 398, FONT_SMALL, Colors::WHITE, to);
+
+	// Monster strength
+	printAtLoc(CGI->generaltexth->allTexts[758], 68, 465, FONT_SMALL, Colors::WHITE, to);
+}
 
 CChatBox::CChatBox(const Rect &rect)
 {
@@ -1634,17 +1862,17 @@ void InfoCard::showAll(SDL_Surface * to)
 	//blit texts
 	if(SEL->screenType != CMenuScreen::campaignList)
 	{
-		printAtLoc(CGI->generaltexth->allTexts[390] + ":", 24, 400, FONT_SMALL, Colors::Cornsilk, to); //Allies
-		printAtLoc(CGI->generaltexth->allTexts[391] + ":", 190, 400, FONT_SMALL, Colors::Cornsilk, to); //Enemies
-		printAtLoc(CGI->generaltexth->allTexts[494], 33, 430, FONT_SMALL, Colors::Jasmine, to);//"Map Diff:"
-		printAtLoc(CGI->generaltexth->allTexts[492] + ":", 133,430, FONT_SMALL, Colors::Jasmine, to); //player difficulty
-		printAtLoc(CGI->generaltexth->allTexts[218] + ":", 290,430, FONT_SMALL, Colors::Jasmine, to); //"Rating:"
-		printAtLoc(CGI->generaltexth->allTexts[495], 26, 22, FONT_SMALL, Colors::Jasmine, to); //Scenario Name:
+		printAtLoc(CGI->generaltexth->allTexts[390] + ":", 24, 400, FONT_SMALL, Colors::WHITE, to); //Allies
+		printAtLoc(CGI->generaltexth->allTexts[391] + ":", 190, 400, FONT_SMALL, Colors::WHITE, to); //Enemies
+		printAtLoc(CGI->generaltexth->allTexts[494], 33, 430, FONT_SMALL, Colors::YELLOW, to);//"Map Diff:"
+		printAtLoc(CGI->generaltexth->allTexts[492] + ":", 133,430, FONT_SMALL, Colors::YELLOW, to); //player difficulty
+		printAtLoc(CGI->generaltexth->allTexts[218] + ":", 290,430, FONT_SMALL, Colors::YELLOW, to); //"Rating:"
+		printAtLoc(CGI->generaltexth->allTexts[495], 26, 22, FONT_SMALL, Colors::YELLOW, to); //Scenario Name:
 		if(!chatOn)
 		{
-			printAtLoc(CGI->generaltexth->allTexts[496], 26, 132, FONT_SMALL, Colors::Jasmine, to); //Scenario Description:
-			printAtLoc(CGI->generaltexth->allTexts[497], 26, 283, FONT_SMALL, Colors::Jasmine, to); //Victory Condition:
-			printAtLoc(CGI->generaltexth->allTexts[498], 26, 339, FONT_SMALL, Colors::Jasmine, to); //Loss Condition:
+			printAtLoc(CGI->generaltexth->allTexts[496], 26, 132, FONT_SMALL, Colors::YELLOW, to); //Scenario Description:
+			printAtLoc(CGI->generaltexth->allTexts[497], 26, 283, FONT_SMALL, Colors::YELLOW, to); //Victory Condition:
+			printAtLoc(CGI->generaltexth->allTexts[498], 26, 339, FONT_SMALL, Colors::YELLOW, to); //Loss Condition:
 		}
 		else //players list
 		{
@@ -1654,7 +1882,7 @@ void InfoCard::showAll(SDL_Surface * to)
 			{
 				if(i->second.human)
 				{
-					printAtLoc(i->second.name, 24, 285 + playerSoFar++ * graphics->fonts[FONT_SMALL]->height, FONT_SMALL, Colors::Cornsilk, to);
+					printAtLoc(i->second.name, 24, 285 + playerSoFar++ * graphics->fonts[FONT_SMALL]->height, FONT_SMALL, Colors::WHITE, to);
 					playerNames.erase(i->second.human);
 				}
 			}
@@ -1662,7 +1890,7 @@ void InfoCard::showAll(SDL_Surface * to)
 			playerSoFar = 0;
 			for (auto i = playerNames.cbegin(); i != playerNames.cend(); i++)
 			{
-				printAtLoc(i->second, 193, 285 + playerSoFar++ * graphics->fonts[FONT_SMALL]->height, FONT_SMALL, Colors::Cornsilk, to);
+				printAtLoc(i->second, 193, 285 + playerSoFar++ * graphics->fonts[FONT_SMALL]->height, FONT_SMALL, Colors::WHITE, to);
 			}
 
 		}
@@ -1681,7 +1909,7 @@ void InfoCard::showAll(SDL_Surface * to)
 				if (temp>20) temp=0;
 				std::string sss = CGI->generaltexth->victoryConditions[temp];
 				if (temp && SEL->current->mapHeader->victoryCondition.allowNormalVictory) sss+= "/" + CGI->generaltexth->victoryConditions[0];
-				printAtLoc(sss, 60, 307, FONT_SMALL, Colors::Cornsilk, to);
+				printAtLoc(sss, 60, 307, FONT_SMALL, Colors::WHITE, to);
 
 				temp = SEL->current->mapHeader->victoryCondition.condition;
 				if (temp>12) temp=11;
@@ -1691,7 +1919,7 @@ void InfoCard::showAll(SDL_Surface * to)
 				temp = SEL->current->mapHeader->lossCondition.typeOfLossCon+1;
 				if (temp>20) temp=0;
 				sss = CGI->generaltexth->lossCondtions[temp];
-				printAtLoc(sss, 60, 366, FONT_SMALL, Colors::Cornsilk, to);
+				printAtLoc(sss, 60, 366, FONT_SMALL, Colors::WHITE, to);
 
 				temp=SEL->current->mapHeader->lossCondition.typeOfLossCon;
 				if (temp>12) temp=3;
@@ -1701,7 +1929,7 @@ void InfoCard::showAll(SDL_Surface * to)
 			//difficulty
 			assert(SEL->current->mapHeader->difficulty <= 4);
 			std::string &diff = CGI->generaltexth->arraytxt[142 + SEL->current->mapHeader->difficulty];
-			printAtMiddleLoc(diff, 62, 472, FONT_SMALL, Colors::Cornsilk, to);
+			printAtMiddleLoc(diff, 62, 472, FONT_SMALL, Colors::WHITE, to);
 
 			//selecting size icon
 			switch (SEL->current->mapHeader->width)
@@ -1726,7 +1954,7 @@ void InfoCard::showAll(SDL_Surface * to)
 
 
 			if(SEL->screenType == CMenuScreen::loadGame)
-				printToLoc((static_cast<const CMapInfo*>(SEL->current))->date,308,34, FONT_SMALL, Colors::Cornsilk, to);
+				printToLoc((static_cast<const CMapInfo*>(SEL->current))->date,308,34, FONT_SMALL, Colors::WHITE, to);
 
 			//print flags
 			int fx = 34  + graphics->fonts[FONT_SMALL]->getWidth(CGI->generaltexth->allTexts[390].c_str());
@@ -1765,7 +1993,7 @@ void InfoCard::showAll(SDL_Surface * to)
 				tob="200%";
 				break;
 			}
-			printAtMiddleLoc(tob, 311, 472, FONT_SMALL, Colors::Cornsilk, to);
+			printAtMiddleLoc(tob, 311, 472, FONT_SMALL, Colors::WHITE, to);
 		}
 
 		//blit description
@@ -1782,9 +2010,9 @@ void InfoCard::showAll(SDL_Surface * to)
 
 		//name
 		if (name.length())
-			printAtLoc(CSDL_Ext::trimToFit(name, 300, FONT_BIG), 26, 39, FONT_BIG, Colors::Jasmine, to);
+			printAtLoc(CSDL_Ext::trimToFit(name, 300, FONT_BIG), 26, 39, FONT_BIG, Colors::YELLOW, to);
 		else
-			printAtLoc("Unnamed", 26, 39, FONT_BIG, Colors::Jasmine, to);
+			printAtLoc("Unnamed", 26, 39, FONT_BIG, Colors::YELLOW, to);
 	}
 }
 
@@ -1815,14 +2043,14 @@ void InfoCard::clickRight( tribool down, bool previousState )
 void InfoCard::showTeamsPopup()
 {
 	SDL_Surface *bmp = CMessage::drawDialogBox(256, 90 + 50 * SEL->current->mapHeader->howManyTeams);
-	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[657], 128, 30, FONT_MEDIUM, Colors::Jasmine, bmp); //{Team Alignments}
+	CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[657], 128, 30, FONT_MEDIUM, Colors::YELLOW, bmp); //{Team Alignments}
 
 	for(int i = 0; i < SEL->current->mapHeader->howManyTeams; i++)
 	{
 		std::vector<ui8> flags;
 		std::string hlp = CGI->generaltexth->allTexts[656]; //Team %d
 		hlp.replace(hlp.find("%d"), 2, boost::lexical_cast<std::string>(i+1));
-		CSDL_Ext::printAtMiddle(hlp, 128, 65 + 50*i, FONT_SMALL, Colors::Cornsilk, bmp);
+		CSDL_Ext::printAtMiddle(hlp, 128, 65 + 50*i, FONT_SMALL, Colors::WHITE, bmp);
 
 		for(int j = 0; j < GameConstants::PLAYER_LIMIT; j++)
 			if((SEL->current->mapHeader->players[j].canHumanPlay || SEL->current->mapHeader->players[j].canComputerPlay)
@@ -1888,15 +2116,15 @@ OptionsTab::~OptionsTab()
 void OptionsTab::showAll(SDL_Surface * to)
 {
 	CIntObject::showAll(to);
-	printAtMiddleLoc(CGI->generaltexth->allTexts[515], 222, 30, FONT_BIG, Colors::Jasmine, to);
-	printAtMiddleWBLoc(CGI->generaltexth->allTexts[516], 222, 58, FONT_SMALL, 55, Colors::Cornsilk, to); //Select starting options, handicap, and name for each player in the game.
-	printAtMiddleWBLoc(CGI->generaltexth->allTexts[517], 107, 102, FONT_SMALL, 14, Colors::Jasmine, to); //Player Name Handicap Type
-	printAtMiddleWBLoc(CGI->generaltexth->allTexts[518], 197, 102, FONT_SMALL, 10, Colors::Jasmine, to); //Starting Town
-	printAtMiddleWBLoc(CGI->generaltexth->allTexts[519], 273, 102, FONT_SMALL, 10, Colors::Jasmine, to); //Starting Hero
-	printAtMiddleWBLoc(CGI->generaltexth->allTexts[520], 349, 102, FONT_SMALL, 10, Colors::Jasmine, to); //Starting Bonus
-	printAtMiddleLoc(CGI->generaltexth->allTexts[521], 222, 538, FONT_SMALL, Colors::Jasmine, to); // Player Turn Duration
+	printAtMiddleLoc(CGI->generaltexth->allTexts[515], 222, 30, FONT_BIG, Colors::YELLOW, to);
+	printAtMiddleWBLoc(CGI->generaltexth->allTexts[516], 222, 58, FONT_SMALL, 55, Colors::WHITE, to); //Select starting options, handicap, and name for each player in the game.
+	printAtMiddleWBLoc(CGI->generaltexth->allTexts[517], 107, 102, FONT_SMALL, 14, Colors::YELLOW, to); //Player Name Handicap Type
+	printAtMiddleWBLoc(CGI->generaltexth->allTexts[518], 197, 102, FONT_SMALL, 10, Colors::YELLOW, to); //Starting Town
+	printAtMiddleWBLoc(CGI->generaltexth->allTexts[519], 273, 102, FONT_SMALL, 10, Colors::YELLOW, to); //Starting Hero
+	printAtMiddleWBLoc(CGI->generaltexth->allTexts[520], 349, 102, FONT_SMALL, 10, Colors::YELLOW, to); //Starting Bonus
+	printAtMiddleLoc(CGI->generaltexth->allTexts[521], 222, 538, FONT_SMALL, Colors::YELLOW, to); // Player Turn Duration
 	if (turnDuration)
-		printAtMiddleLoc(CGI->generaltexth->turnDurations[turnDuration->value], 319,559, FONT_SMALL, Colors::Cornsilk, to);//Turn duration value
+		printAtMiddleLoc(CGI->generaltexth->turnDurations[turnDuration->value], 319,559, FONT_SMALL, Colors::WHITE, to);//Turn duration value
 }
 
 void OptionsTab::nextCastle( int player, int dir )
@@ -2008,8 +2236,8 @@ bool OptionsTab::canUseThisHero( int ID )
 	//		return false;
 
 	return CGI->heroh->heroes.size() > ID
-	    && !vstd::contains(usedHeroes, ID)
-	    && SEL->current->mapHeader->allowedHeroes[ID];
+		&& !vstd::contains(usedHeroes, ID)
+		&& SEL->current->mapHeader->allowedHeroes[ID];
 }
 
 void OptionsTab::nextBonus( int player, int dir )
@@ -2059,9 +2287,9 @@ void OptionsTab::recreate()
 	for(auto it = SEL->sInfo.playerInfos.begin(); it != SEL->sInfo.playerInfos.end(); ++it)
 	{
 		entries.insert(std::make_pair(it->first, new PlayerOptionsEntry(this, it->second)));
-        const std::vector<SHeroName> &heroes = SEL->current->mapHeader->players[it->first].heroesNames;
+		const std::vector<SHeroName> &heroes = SEL->current->mapHeader->players[it->first].heroesNames;
 		for(size_t hi=0; hi<heroes.size(); hi++)
-            usedHeroes.insert(heroes[hi].heroId);
+			usedHeroes.insert(heroes[hi].heroId);
 	}
 
 }
@@ -2227,8 +2455,8 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry( OptionsTab *owner, PlayerSet
 void OptionsTab::PlayerOptionsEntry::showAll(SDL_Surface * to)
 {
 	CIntObject::showAll(to);
-	printAtMiddleLoc(s.name, 55, 10, FONT_SMALL, Colors::Cornsilk, to);
-	printAtMiddleWBLoc(CGI->generaltexth->arraytxt[206+whoCanPlay], 28, 34, FONT_TINY, 8, Colors::Cornsilk, to);
+	printAtMiddleLoc(s.name, 55, 10, FONT_SMALL, Colors::WHITE, to);
+	printAtMiddleWBLoc(CGI->generaltexth->arraytxt[206+whoCanPlay], 28, 34, FONT_TINY, 8, Colors::WHITE, to);
 }
 
 void OptionsTab::PlayerOptionsEntry::selectButtons()
@@ -2278,7 +2506,7 @@ void OptionsTab::SelectedBox::showAll(SDL_Surface * to)
 	SDL_Surface *toBlit = getImg();
 	const std::string *toPrint = getText();
 	blitAt(toBlit, pos, to);
-	printAtMiddleLoc(*toPrint, 23, 39, FONT_TINY, Colors::Cornsilk, to);
+	printAtMiddleLoc(*toPrint, 23, 39, FONT_TINY, Colors::WHITE, to);
 }
 
 OptionsTab::SelectedBox::SelectedBox( SelType Which, ui8 Player )
@@ -2503,7 +2731,7 @@ void OptionsTab::SelectedBox::clickRight( tribool down, bool previousState )
 		}
 
 		if(description)
-			CSDL_Ext::printAtMiddleWB(*description, 125, 145, FONT_SMALL, 37, Colors::Cornsilk, bmp);
+			CSDL_Ext::printAtMiddleWB(*description, 125, 145, FONT_SMALL, 37, Colors::WHITE, bmp);
 	}
 	else if(val == -2)
 	{
@@ -2514,7 +2742,7 @@ void OptionsTab::SelectedBox::clickRight( tribool down, bool previousState )
 		bmp = CMessage::drawDialogBox(256, 319);
 		title = &CGI->generaltexth->allTexts[80];
 
-		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[79], 135, 137, FONT_MEDIUM, Colors::Jasmine, bmp);
+		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[79], 135, 137, FONT_MEDIUM, Colors::YELLOW, bmp);
 
 		const CTown &t = CGI->townh->towns[val];
 		//print creatures
@@ -2523,7 +2751,7 @@ void OptionsTab::SelectedBox::clickRight( tribool down, bool previousState )
 		{
 			int c = t.creatures[i][0];
 			blitAt(graphics->smallImgs[c], x, y, bmp);
-			CSDL_Ext::printAtMiddleWB(CGI->creh->creatures[c]->nameSing, x + 16, y + 45, FONT_TINY, 10, Colors::Cornsilk, bmp);
+			CSDL_Ext::printAtMiddleWB(CGI->creh->creatures[c]->nameSing, x + 16, y + 45, FONT_TINY, 10, Colors::WHITE, bmp);
 
 			if(i == 2)
 			{
@@ -2543,24 +2771,24 @@ void OptionsTab::SelectedBox::clickRight( tribool down, bool previousState )
 		bmp = CMessage::drawDialogBox(320, 255);
 		title = &CGI->generaltexth->allTexts[77];
 
-		CSDL_Ext::printAtMiddle(*title, 167, 36, FONT_MEDIUM, Colors::Jasmine, bmp);
-		CSDL_Ext::printAtMiddle(*subTitle + " - " + h->heroClass->name, 160, 99, FONT_SMALL, Colors::Cornsilk, bmp);
+		CSDL_Ext::printAtMiddle(*title, 167, 36, FONT_MEDIUM, Colors::YELLOW, bmp);
+		CSDL_Ext::printAtMiddle(*subTitle + " - " + h->heroClass->name, 160, 99, FONT_SMALL, Colors::WHITE, bmp);
 
 		blitAt(getImg(), 136, 56, bmp);
 
 		//print specialty
-		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[78], 166, 132, FONT_MEDIUM, Colors::Jasmine, bmp);
+		CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[78], 166, 132, FONT_MEDIUM, Colors::YELLOW, bmp);
 		blitAt(graphics->un44->ourImages[val].bitmap, 140, 150, bmp);
-		CSDL_Ext::printAtMiddle(CGI->generaltexth->hTxts[val].bonusName, 166, 203, FONT_SMALL, Colors::Cornsilk, bmp);
+		CSDL_Ext::printAtMiddle(CGI->generaltexth->hTxts[val].bonusName, 166, 203, FONT_SMALL, Colors::WHITE, bmp);
 
 		GH.pushInt(new CInfoPopup(bmp, true));
 		return;
 	}
 
 	if(title)
-		CSDL_Ext::printAtMiddle(*title, 135, 36, FONT_MEDIUM, Colors::Jasmine, bmp);
+		CSDL_Ext::printAtMiddle(*title, 135, 36, FONT_MEDIUM, Colors::YELLOW, bmp);
 	if(subTitle)
-		CSDL_Ext::printAtMiddle(*subTitle, 127, 103, FONT_SMALL, Colors::Cornsilk, bmp);
+		CSDL_Ext::printAtMiddle(*subTitle, 127, 103, FONT_SMALL, Colors::WHITE, bmp);
 
 	blitAt(getImg(), 104, 60, bmp);
 
@@ -2607,8 +2835,8 @@ CScenarioInfo::~CScenarioInfo()
 
 bool mapSorter::operator()(const CMapInfo *aaa, const CMapInfo *bbb)
 {
-    const CMapHeader * a = aaa->mapHeader.get(),
-            * b = bbb->mapHeader.get();
+	const CMapHeader * a = aaa->mapHeader.get(),
+			* b = bbb->mapHeader.get();
 	if(a && b) //if we are sorting scenarios
 	{
 		switch (sortBy)
@@ -2710,7 +2938,7 @@ CHotSeatPlayers::CHotSeatPlayers(const std::string &firstPlayer)
 	std::string text = CGI->generaltexth->allTexts[446];
 	boost::replace_all(text, "\t","\n");
 	Rect boxRect(25, 20, 315, 50);
-	title = new CTextBox(text, boxRect, 0, FONT_BIG, CENTER, Colors::Cornsilk);//HOTSEAT	Please enter names
+	title = new CTextBox(text, boxRect, 0, FONT_BIG, CENTER, Colors::WHITE);//HOTSEAT	Please enter names
 
 	for(int i = 0; i < ARRAY_COUNT(txt); i++)
 	{
@@ -2780,16 +3008,16 @@ void CBonusSelection::init()
 
 	//campaign name
 	if (ourCampaign->camp->header.name.length())
-		CSDL_Ext::printAt(ourCampaign->camp->header.name, 481, 28, FONT_BIG, Colors::Jasmine, background);
+		CSDL_Ext::printAt(ourCampaign->camp->header.name, 481, 28, FONT_BIG, Colors::YELLOW, background);
 	else
-		CSDL_Ext::printAt("Unnamed", 481, 28, FONT_BIG, Colors::Jasmine, background);
+		CSDL_Ext::printAt("Unnamed", 481, 28, FONT_BIG, Colors::YELLOW, background);
 
 	//map size icon
 	sizes = CDefHandler::giveDef("SCNRMPSZ.DEF");
 
 
 	//campaign description
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[38], 481, 63, FONT_SMALL, Colors::Jasmine, background);
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[38], 481, 63, FONT_SMALL, Colors::YELLOW, background);
 
 	cmpgDesc = new CTextBox(ourCampaign->camp->header.description, Rect(480, 86, 286, 117), 1);
 	//cmpgDesc->showAll(background);
@@ -2798,7 +3026,7 @@ void CBonusSelection::init()
 	mapDesc = new CTextBox("", Rect(480, 280, 286, 117), 1);
 
 	//bonus choosing
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[71], 511, 432, FONT_MEDIUM, Colors::Cornsilk, background); //Choose a bonus:
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[71], 511, 432, FONT_MEDIUM, Colors::WHITE, background); //Choose a bonus:
 	bonuses = new CHighlightableButtonsGroup(bind(&CBonusSelection::selectBonus, this, _1));
 
 	//set left part of window
@@ -2831,15 +3059,15 @@ void CBonusSelection::init()
 // 	}
 
 	//allies / enemies
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[390] + ":", 486, 407, FONT_SMALL, Colors::Cornsilk, background); //Allies
-	CSDL_Ext::printAt(CGI->generaltexth->allTexts[391] + ":", 619, 407, FONT_SMALL, Colors::Cornsilk, background); //Enemies
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[390] + ":", 486, 407, FONT_SMALL, Colors::WHITE, background); //Allies
+	CSDL_Ext::printAt(CGI->generaltexth->allTexts[391] + ":", 619, 407, FONT_SMALL, Colors::WHITE, background); //Enemies
 
 	SDL_FreeSurface(panel);
 
 	//difficulty
 	std::vector<std::string> difficulty;
 	boost::split(difficulty, CGI->generaltexth->allTexts[492], boost::is_any_of(" "));
-	CSDL_Ext::printAt(difficulty.back(), 689, 432, FONT_MEDIUM, Colors::Cornsilk, background); //Difficulty
+	CSDL_Ext::printAt(difficulty.back(), 689, 432, FONT_MEDIUM, Colors::WHITE, background); //Difficulty
 
 	//difficulty pics
 	for (int b=0; b<ARRAY_COUNT(diffPics); ++b)
@@ -2945,9 +3173,9 @@ void CBonusSelection::selectMap( int whichOne )
 
 	//get header
 	delete ourHeader;
-    std::string & headerStr = ourCampaign->camp->mapPieces.find(whichOne)->second;
-    auto buffer = reinterpret_cast<const ui8 *>(headerStr.data());
-    ourHeader = CMapService::loadMapHeader(buffer, headerStr.size()).release();
+	std::string & headerStr = ourCampaign->camp->mapPieces.find(whichOne)->second;
+	auto buffer = reinterpret_cast<const ui8 *>(headerStr.data());
+	ourHeader = CMapService::loadMapHeader(buffer, headerStr.size()).release();
 
 	std::map<TPlayerColor, std::string> names;
 	names[1] = settings["general"]["playerName"].String();
@@ -2968,12 +3196,12 @@ void CBonusSelection::show(SDL_Surface * to)
 	std::string mapName = ourHeader->name;
 
 	if (mapName.length())
-		printAtLoc(mapName, 481, 219, FONT_BIG, Colors::Jasmine, to);
+		printAtLoc(mapName, 481, 219, FONT_BIG, Colors::YELLOW, to);
 	else
-		printAtLoc("Unnamed", 481, 219, FONT_BIG, Colors::Jasmine, to);
+		printAtLoc("Unnamed", 481, 219, FONT_BIG, Colors::YELLOW, to);
 
 	//map description
-	printAtLoc(CGI->generaltexth->allTexts[496], 481, 253, FONT_SMALL, Colors::Jasmine, to);
+	printAtLoc(CGI->generaltexth->allTexts[496], 481, 253, FONT_SMALL, Colors::YELLOW, to);
 
 	mapDesc->showAll(to); //showAll because CTextBox has no show()
 
@@ -3485,6 +3713,9 @@ void PregameGuiAction::apply(CSelectionScreen *selScreen)
 	case OPEN_SCENARIO_LIST:
 		selScreen->toggleTab(selScreen->sel);
 		break;
+	case OPEN_RANDOM_MAP_OPTIONS:
+		selScreen->toggleTab(selScreen->randMapTab);
+		break;
 	}
 }
 
@@ -3585,7 +3816,7 @@ CCampaignScreen::CCampaignButton::CCampaignButton(const JsonNode &config )
 		addUsedEvents(LCLICK | HOVER);
 		image = new CPicture(config["image"].String());
 
-		hoverLabel = new CLabel(pos.w / 2, pos.h + 20, FONT_MEDIUM, CENTER, Colors::Jasmine, "");
+		hoverLabel = new CLabel(pos.w / 2, pos.h + 20, FONT_MEDIUM, CENTER, Colors::YELLOW, "");
 		parent->addChild(hoverLabel);
 	}
 

+ 104 - 1
client/CPreGame.h

@@ -6,6 +6,7 @@
 #include "GUIClasses.h"
 #include "FunctionList.h"
 #include "../lib/Map/CMapInfo.h"
+#include "../lib/RMG/CMapGenOptions.h"
 
 /*
  * CPreGame.h, part of VCMI engine
@@ -178,7 +179,7 @@ public:
 	void keyPressed(const SDL_KeyboardEvent & key);
 	void onDoubleClick();
 	SelectionTab(CMenuScreen::EState Type, const boost::function<void(CMapInfo *)> &OnSelect, CMenuScreen::EMultiMode MultiPlayer = CMenuScreen::SINGLE_PLAYER);
-	~SelectionTab();
+    ~SelectionTab();
 };
 
 /// The options tab which is shown at the map selection phase.
@@ -249,6 +250,107 @@ public:
 	bool canUseThisHero( int ID );
 };
 
+/**
+ * The random map tab shows options for generating a random map.
+ */
+class RandomMapTab : public CIntObject
+{
+public:
+    /**
+     * C-tor.
+     */
+    RandomMapTab();
+
+    /**
+     * Shows the interface and the visual representation of this tab.
+     *
+     * @param to where the graphics should be inserted
+     */
+    void showAll(SDL_Surface * to);
+
+private:
+    /**
+     * Adds buttons specified by the defs list to the given buttons group.
+     *
+     * @param group the button group where the buttons should be added to
+     * @param defs the names of the button defs
+     * @param startIndex start index of the defs vector
+     * @param endIndex end index of the defs vector
+     * @param btnWidth width of one button(fixed width)
+     * @param helpStartIndex the index of the first help msg entry
+     */
+    void addButtonsToGroup(CHighlightableButtonsGroup * group, const std::vector<std::string> & defs, int startIndex, int endIndex, int btnWidth, int helpStartIndex) const;
+
+    /**
+     * Adds buttons specified by the defs list and the random button to the given buttons group. Auto-selects the
+     * random button.
+     *
+     * @param group the button group where the buttons should be added to
+     * @param defs the names of the button defs
+     * @param startIndex start index of the defs vector
+     * @param endIndex end index of the defs vector
+     * @param btnWidth width of one button(fixed width)
+     * @param helpStartIndex the index of the first help msg entry
+     * @param helpRandIndex the index of the random help msg entry
+     */
+    void addButtonsWithRandToGroup(CHighlightableButtonsGroup * group, const std::vector<std::string> & defs, int startIndex, int endIndex, int btnWidth, int helpStartIndex, int helpRandIndex) const;
+
+    /**
+     * Deactives buttons of a highlightable button group beginning from startId. Buttons with a id
+     * lower than startId will be activated/reseted.
+     *
+     * @param group the associated highlightable button group
+     * @param startId the id of the first button to deactivate
+     */
+    void deactivateButtonsFrom(CHighlightableButtonsGroup * group, int startId);
+
+    /**
+     * Validates players count and updates teams count, comp only players/teams count if necessary.
+     *
+     * @param playersCnt the players count to validate
+     */
+    void validatePlayersCnt(int playersCnt);
+
+    /**
+     * Validates computer only players count and updates comp only teams count if necessary.
+     *
+     * @param compOnlyPlayersCnt the computer only players count to validate
+     */
+    void validateCompOnlyPlayersCnt(int compOnlyPlayersCnt);
+
+    /** the background image of the rmg options tab */
+    CPicture * bg;
+
+    /** the map size buttons group */
+    CHighlightableButtonsGroup * mapSizeBtnGroup;
+
+    /** the two levels highlightable button */
+    CHighlightableButton * twoLevelsBtn;
+
+    /** the players count group */
+    CHighlightableButtonsGroup * playersCntGroup;
+
+    /** the teams count group */
+    CHighlightableButtonsGroup * teamsCntGroup;
+
+    /** the computer only players count group */
+    CHighlightableButtonsGroup * compOnlyPlayersCntGroup;
+
+    /** the computer only teams count group */
+    CHighlightableButtonsGroup * compOnlyTeamsCntGroup;
+
+    /** the water content group */
+    CHighlightableButtonsGroup * waterContentGroup;
+
+    /** the monster strength group */
+    CHighlightableButtonsGroup * monsterStrengthGroup;
+
+    CAdventureMapButton * showRandMaps;
+
+    /** the map options selected by the user */
+    CMapGenOptions options;
+};
+
 /// Interface for selecting a map.
 class ISelectionScreenInfo
 {
@@ -283,6 +385,7 @@ public:
 	CPicture *bg; //general bg image
 	InfoCard *card;
 	OptionsTab *opt;
+    RandomMapTab * randMapTab;
 	CAdventureMapButton *start, *back;
 
 	SelectionTab *sel;

+ 2 - 2
client/CQuestLog.cpp

@@ -130,7 +130,7 @@ CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests) :
 void CQuestLog::init()
 {
 	minimap = new CQuestMinimap (Rect (47, 33, 144, 144));
-	description = new CTextBox ("", Rect(245, 33, 350, 355), 1, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk);
+	description = new CTextBox ("", Rect(245, 33, 350, 355), 1, FONT_MEDIUM, TOPLEFT, Colors::WHITE);
 	ok = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second, boost::bind(&CQuestLog::close,this), 547, 401, "IOKAY.DEF", SDLK_RETURN);
 
 	if (quests.size() > QUEST_COUNT)
@@ -142,7 +142,7 @@ void CQuestLog::init()
 		quests[i].quest->getRolloverText (text, false);
 		if (quests[i].obj)
 			text.addReplacement (quests[i].obj->getHoverText()); //get name of the object
-		CQuestLabel * label = new CQuestLabel (28, 199 + i * 24, FONT_SMALL, TOPLEFT, Colors::Cornsilk, text.toString());
+		CQuestLabel * label = new CQuestLabel (28, 199 + i * 24, FONT_SMALL, TOPLEFT, Colors::WHITE, text.toString());
 		label->callback = boost::bind(&CQuestLog::selectQuest, this, i);
 		label->setBounds (172, 30);
 		labels.push_back(label);

+ 2 - 2
client/CQuestLog.h

@@ -38,8 +38,8 @@ class CQuestLabel : public LRClickableAreaWText, public CBoundedLabel
 public:
 	boost::function<void()> callback;
 
-	CQuestLabel (int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::Cornsilk, const std::string &Text =  "")
-		: CBoundedLabel (x, y, FONT_SMALL, TOPLEFT, Colors::Cornsilk, Text){};
+	CQuestLabel (int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::WHITE, const std::string &Text =  "")
+		: CBoundedLabel (x, y, FONT_SMALL, TOPLEFT, Colors::WHITE, Text){};
 	void clickLeft(tribool down, bool previousState);
 	void showAll(SDL_Surface * to);
 };

+ 4 - 4
client/CSpellWindow.cpp

@@ -321,7 +321,7 @@ void CSpellWindow::showAll(SDL_Surface * to)
 
 	std::ostringstream mana;
 	mana<<myHero->mana;
-	CSDL_Ext::printAtMiddle(mana.str(), pos.x+435, pos.y +426, FONT_SMALL, Colors::Jasmine, to);
+	CSDL_Ext::printAtMiddle(mana.str(), pos.x+435, pos.y +426, FONT_SMALL, Colors::YELLOW, to);
 	
 	statusBar->showAll(to);
 
@@ -841,13 +841,13 @@ void CSpellWindow::SpellArea::showAll(SDL_Surface * to)
 	if(spellCost > owner->myHero->mana) //hero cannot cast this spell
 	{
 		static const SDL_Color unavailableSpell = {239, 189, 33, 0};
-		firstLineColor = Colors::Cornsilk;
+		firstLineColor = Colors::WHITE;
 		secondLineColor = unavailableSpell;
 	}
 	else
 	{
-		firstLineColor = Colors::Jasmine;
-		secondLineColor = Colors::Cornsilk;
+		firstLineColor = Colors::YELLOW;
+		secondLineColor = Colors::WHITE;
 	}
 	//printing spell's name
 	CSDL_Ext::printAtMiddle(spell->name, pos.x + 39, pos.y + 70, FONT_TINY, firstLineColor, to);

+ 82 - 82
client/GUIClasses.cpp

@@ -69,7 +69,7 @@ void CArmyTooltip::init(const InfoAboutArmy &army)
 {
 	OBJ_CONSTRUCTION_CAPTURING_ALL;
 
-	new CLabel(66, 2, FONT_SMALL, TOPLEFT, Colors::Cornsilk, army.name);
+	new CLabel(66, 2, FONT_SMALL, TOPLEFT, Colors::WHITE, army.name);
 
 	std::vector<Point> slotsPos;
 	slotsPos.push_back(Point(36,73));
@@ -100,7 +100,7 @@ void CArmyTooltip::init(const InfoAboutArmy &army)
 				subtitle = CGI->generaltexth->arraytxt[171 + 3*(slot.second.count)];
 		}
 
-		new CLabel(slotsPos[slot.first].x + 17, slotsPos[slot.first].y + 41, FONT_TINY, CENTER, Colors::Cornsilk, subtitle);
+		new CLabel(slotsPos[slot.first].x + 17, slotsPos[slot.first].y + 41, FONT_TINY, CENTER, Colors::WHITE, subtitle);
 	}
 
 }
@@ -125,10 +125,10 @@ void CHeroTooltip::init(const InfoAboutHero &hero)
 	if(hero.details)
 	{
 		for (size_t i = 0; i < hero.details->primskills.size(); i++)
-			new CLabel(75 + 28 * i, 58, FONT_SMALL, CENTER, Colors::Cornsilk,
+			new CLabel(75 + 28 * i, 58, FONT_SMALL, CENTER, Colors::WHITE,
 			           boost::lexical_cast<std::string>(hero.details->primskills[i]));
 
-		new CLabel(158, 98, FONT_TINY, CENTER, Colors::Cornsilk,
+		new CLabel(158, 98, FONT_TINY, CENTER, Colors::WHITE,
 		           boost::lexical_cast<std::string>(hero.details->mana));
 
 		new CAnimImage("IMRL22", hero.details->morale + 3, 0, 5, 74);
@@ -169,7 +169,7 @@ void CTownTooltip::init(const InfoAboutTown &town)
 			new CAnimImage("ITMTLS", town.details->hallLevel, 0, 67, 31);
 
 		if (town.details->goldIncome)
-			new CLabel(157, 58, FONT_TINY, CENTER, Colors::Cornsilk,
+			new CLabel(157, 58, FONT_TINY, CENTER, Colors::WHITE,
 		               boost::lexical_cast<std::string>(town.details->goldIncome));
 
 		if(town.details->garrisonedHero) //garrisoned hero icon
@@ -474,7 +474,7 @@ void CGarrisonSlot::showAll(SDL_Surface * to)
 		creatureImage->showAll(to);
 		char buf[15];
 		SDL_itoa(count,buf,10);
-		printTo(buf, pos.x+pos.w, pos.y+pos.h+1, owner->smallIcons ? FONT_TINY : FONT_MEDIUM, Colors::Cornsilk, to);
+		printTo(buf, pos.x+pos.w, pos.y+pos.h+1, owner->smallIcons ? FONT_TINY : FONT_MEDIUM, Colors::WHITE, to);
 
 		if((owner->highlighted==this)
 			|| (owner->splitting && owner->highlighted->creature == creature))
@@ -608,7 +608,7 @@ CInfoWindow::CInfoWindow(std::string Text, int player, const TCompsInfo &comps,
 		buttons.push_back(button);
 	}
 
-	text = new CTextBox(Text, Rect(0, 0, 250, 100), 0, FONT_MEDIUM, CENTER, Colors::Cornsilk);
+	text = new CTextBox(Text, Rect(0, 0, 250, 100), 0, FONT_MEDIUM, CENTER, Colors::WHITE);
 	if(!text->slider)
 	{
 		text->pos.w = text->maxW;
@@ -817,7 +817,7 @@ void CComponent::init(Etype Type, int Subtype, int Val, ESize imageSize)
 	BOOST_FOREACH(auto & line, textLines)
 	{
 		int height = graphics->fonts[FONT_SMALL]->height;
-		CLabel * label = new CLabel(pos.w/2, pos.h + height/2, FONT_SMALL, CENTER, Colors::Cornsilk, line);
+		CLabel * label = new CLabel(pos.w/2, pos.h + height/2, FONT_SMALL, CENTER, Colors::WHITE, line);
 
 		pos.h += height;
 		if (label->pos.w > pos.w)
@@ -1129,7 +1129,7 @@ void CComponentBox::placeComponents(bool selectable)
 				{
 					Point orPos = Point(currentX, currentY) + getOrTextPos(prevComp, *iter);
 
-					new CLabel(orPos.x, orPos.y, FONT_MEDIUM, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[4]);
+					new CLabel(orPos.x, orPos.y, FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[4]);
 				}
 				currentX += getDistance(prevComp, *iter);
 			}
@@ -1205,7 +1205,7 @@ CSelWindow::CSelWindow(const std::string &Text, int player, int charperline, con
 		buttons[i]->callback += boost::bind(&CInfoWindow::close,this); //each button will close the window apart from call-defined actions
 	}
 
-	text = new CTextBox(Text, Rect(0, 0, 250, 100), 0, FONT_MEDIUM, CENTER, Colors::Cornsilk);
+	text = new CTextBox(Text, Rect(0, 0, 250, 100), 0, FONT_MEDIUM, CENTER, Colors::WHITE);
 
 	buttons.front()->assignedKeys.insert(SDLK_RETURN); //first button - reacts on enter
 	buttons.back()->assignedKeys.insert(SDLK_ESCAPE); //last button - reacts on escape
@@ -1309,7 +1309,7 @@ CRecruitmentWindow::CCostBox::CCostBox(Rect position, std::string title)
 	type |= REDRAW_PARENT;
 	pos = position + pos;
 	OBJ_CONSTRUCTION_CAPTURING_ALL;
-	new CLabel(pos.w/2, 10, FONT_SMALL, CENTER, Colors::Cornsilk, title);
+	new CLabel(pos.w/2, 10, FONT_SMALL, CENTER, Colors::WHITE, title);
 }
 
 void CRecruitmentWindow::CCostBox::set(TResources res)
@@ -1336,7 +1336,7 @@ void CRecruitmentWindow::CCostBox::createItems(TResources res)
 	while (iter.valid())
 	{
 		CAnimImage * image = new CAnimImage("RESOURCE", iter->resType);
-		CLabel * text = new CLabel(15, 43, FONT_SMALL, CENTER, Colors::Cornsilk, "0");
+		CLabel * text = new CLabel(15, 43, FONT_SMALL, CENTER, Colors::WHITE, "0");
 
 		resources.insert(std::make_pair(iter->resType, std::make_pair(text, image)));
 		iter++;
@@ -1461,15 +1461,15 @@ CRecruitmentWindow::CRecruitmentWindow(const CGDwelling *Dwelling, int Level, co
 	buyButton = new CAdventureMapButton(CGI->generaltexth->zelp[554],boost::bind(&CRecruitmentWindow::buy,this),212,313,"IBY6432.DEF",SDLK_RETURN);
 	cancelButton = new CAdventureMapButton(CGI->generaltexth->zelp[555],boost::bind(&CRecruitmentWindow::close,this),290,313,"ICN6432.DEF",SDLK_ESCAPE);
 
-	title = new CLabel(243, 32, FONT_BIG, CENTER, Colors::Jasmine);
-	availableValue = new CLabel(205, 253, FONT_SMALL, CENTER, Colors::Cornsilk);
-	toRecruitValue = new CLabel(279, 253, FONT_SMALL, CENTER, Colors::Cornsilk);
+	title = new CLabel(243, 32, FONT_BIG, CENTER, Colors::YELLOW);
+	availableValue = new CLabel(205, 253, FONT_SMALL, CENTER, Colors::WHITE);
+	toRecruitValue = new CLabel(279, 253, FONT_SMALL, CENTER, Colors::WHITE);
 
 	costPerTroopValue =  new CCostBox(Rect(65, 222, 97, 74), CGI->generaltexth->allTexts[346]);
 	totalCostValue = new CCostBox(Rect(323, 222, 97, 74), CGI->generaltexth->allTexts[466]);
 
-	new CLabel(205, 233, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[465]); //available t
-	new CLabel(279, 233, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[16]); //recruit t
+	new CLabel(205, 233, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[465]); //available t
+	new CLabel(279, 233, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[16]); //recruit t
 
 	availableCreaturesChanged();
 }
@@ -1590,7 +1590,7 @@ CSplitWindow::CSplitWindow(const CCreature * creature, boost::function<void(int,
 
 	std::string title = CGI->generaltexth->allTexts[256];
 	boost::algorithm::replace_first(title,"%s", creature->namePl);
-	new CLabel(150, 34, FONT_BIG, CENTER, Colors::Jasmine, title);
+	new CLabel(150, 34, FONT_BIG, CENTER, Colors::YELLOW, title);
 }
 
 void CSplitWindow::setAmountText(std::string text, bool left)
@@ -1638,16 +1638,16 @@ CLevelWindow::CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<u
 	new CAdventureMapButton("", "", boost::bind(&CLevelWindow::close, this), 297, 413, "IOKAY", SDLK_RETURN);
 
 	//%s has gained a level.
-	new CLabel(192, 33, FONT_MEDIUM, CENTER, Colors::Cornsilk,
+	new CLabel(192, 33, FONT_MEDIUM, CENTER, Colors::WHITE,
 	           boost::str(boost::format(CGI->generaltexth->allTexts[444]) % hero->name));
 
 	//%s is now a level %d %s.
-	new CLabel(192, 162, FONT_MEDIUM, CENTER, Colors::Cornsilk,
+	new CLabel(192, 162, FONT_MEDIUM, CENTER, Colors::WHITE,
 	           boost::str(boost::format(CGI->generaltexth->allTexts[445]) % hero->name % hero->level % hero->type->heroClass->name));
 
 	new CAnimImage("PSKIL42", pskill, 0, 174, 190);
 
-	new CLabel(192, 253, FONT_MEDIUM, CENTER, Colors::Cornsilk,
+	new CLabel(192, 253, FONT_MEDIUM, CENTER, Colors::WHITE,
 	           CGI->generaltexth->primarySkillNames[pskill] + " +1");
 
 	if (!skills.empty())
@@ -1688,7 +1688,7 @@ void CMinorResDataBar::showAll(SDL_Surface * to)
 	for (int i=0;i<7;i++)
 	{
 		SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
-		CSDL_Ext::printAtMiddle(buf,pos.x + 50 + 76*i,pos.y+pos.h/2,FONT_SMALL,Colors::Cornsilk,to);
+		CSDL_Ext::printAtMiddle(buf,pos.x + 50 + 76*i,pos.y+pos.h/2,FONT_SMALL,Colors::WHITE,to);
 	}
 	std::vector<std::string> temp;
 	SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp.push_back(std::string(buf));
@@ -1701,7 +1701,7 @@ void CMinorResDataBar::showAll(SDL_Surface * to)
 	+ ": %s, "
 		+	CGI->generaltexth->allTexts[64]
 	+ ": %s",temp)
-		,pos.x+545+(pos.w-545)/2,pos.y+pos.h/2,FONT_SMALL,Colors::Cornsilk,to);
+		,pos.x+545+(pos.w-545)/2,pos.y+pos.h/2,FONT_SMALL,Colors::WHITE,to);
 }
 
 CMinorResDataBar::CMinorResDataBar()
@@ -1729,7 +1729,7 @@ CObjectListWindow::CItem::CItem(CObjectListWindow *_parent, size_t _id, std::str
 	addUsedEvents(LCLICK);
 	type |= REDRAW_PARENT;
 
-	text = new CLabel(pos.w/2, pos.h/2, FONT_SMALL, CENTER, Colors::Cornsilk, _text);
+	text = new CLabel(pos.w/2, pos.h/2, FONT_SMALL, CENTER, Colors::WHITE, _text);
 	select(index == parent->selected);
 }
 
@@ -1779,8 +1779,8 @@ void CObjectListWindow::init(CPicture * titlePic, std::string _title, std::strin
 {
 	OBJ_CONSTRUCTION_CAPTURING_ALL;
 
-	title = new CLabel(152, 27, FONT_BIG, CENTER, Colors::Jasmine, _title);
-	descr = new CLabel(145, 133, FONT_SMALL, CENTER, Colors::Cornsilk, _descr);
+	title = new CLabel(152, 27, FONT_BIG, CENTER, Colors::YELLOW, _title);
+	descr = new CLabel(145, 133, FONT_SMALL, CENTER, Colors::WHITE, _descr);
 
 	ok = new CAdventureMapButton("","",boost::bind(&CObjectListWindow::elementSelected, this),15,402,"IOKAY.DEF", SDLK_RETURN);
 	ok->block(true);
@@ -1916,7 +1916,7 @@ void CTradeWindow::CTradeableItem::showAll(SDL_Surface * to)
 	if(SDL_Surface *hlp = getSurface())
 		blitAt(hlp, pos + posToBitmap, to);
 
-	printAtMiddleLoc(subtitle, posToSubCenter, FONT_SMALL, Colors::Cornsilk, to);
+	printAtMiddleLoc(subtitle, posToSubCenter, FONT_SMALL, Colors::WHITE, to);
 }
 
 void CTradeWindow::CTradeableItem::clickLeft(tribool down, bool previousState)
@@ -2462,7 +2462,7 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan
 		}
 	}
 
-	new CLabel(300, 27, FONT_BIG, CENTER, Colors::Jasmine, title);
+	new CLabel(300, 27, FONT_BIG, CENTER, Colors::YELLOW, title);
 
 	initItems(false);
 	initItems(true);
@@ -2494,17 +2494,17 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan
 	case EMarketMode::RESOURCE_RESOURCE:
 	case EMarketMode::RESOURCE_PLAYER:
 	case EMarketMode::RESOURCE_ARTIFACT:
-		new CLabel(154, 148, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[270]);
+		new CLabel(154, 148, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[270]);
 		break;
 
 	case EMarketMode::CREATURE_RESOURCE:
 		//%s's Creatures
-		new CLabel(152, 102, FONT_SMALL, CENTER, Colors::Cornsilk,
+		new CLabel(152, 102, FONT_SMALL, CENTER, Colors::WHITE,
 		           boost::str(boost::format(CGI->generaltexth->allTexts[272]) % hero->name));
 		break;
 	case EMarketMode::ARTIFACT_RESOURCE:
 		//%s's Artifacts
-		new CLabel(152, 102, FONT_SMALL, CENTER, Colors::Cornsilk,
+		new CLabel(152, 102, FONT_SMALL, CENTER, Colors::WHITE,
 		           boost::str(boost::format(CGI->generaltexth->allTexts[272]) % hero->name));
 		break;
 	}
@@ -2516,11 +2516,11 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket *Market, const CGHeroInstan
 	case EMarketMode::CREATURE_RESOURCE:
 	case EMarketMode::RESOURCE_ARTIFACT:
 	case EMarketMode::ARTIFACT_RESOURCE:
-		new CLabel(445, 148, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[168]);
+		new CLabel(445, 148, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[168]);
 		traderTextRect = Rect(316, 48, 260, 75);
 		break;
 	case EMarketMode::RESOURCE_PLAYER:
-		new CLabel(445, 55, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->allTexts[169]);
+		new CLabel(445, 55, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[169]);
 		traderTextRect = Rect(28, 48, 260, 75);
 		break;
 	}
@@ -2872,14 +2872,14 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*=
 	if(Mode == EMarketMode::CREATURE_EXP)
 	{
 		//%s's Creatures
-		new CLabel(155, 30, FONT_SMALL, CENTER, Colors::Jasmine,
+		new CLabel(155, 30, FONT_SMALL, CENTER, Colors::YELLOW,
 		           boost::str(boost::format(CGI->generaltexth->allTexts[272]) % hero->name));
 
 		//Altar of Sacrifice
-		new CLabel(450, 30, FONT_SMALL, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[479]);
+		new CLabel(450, 30, FONT_SMALL, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[479]);
 
 		 //To sacrifice creatures, move them from your army on to the Altar and click Sacrifice
-		new CTextBox(CGI->generaltexth->allTexts[480], Rect(320, 56, 256, 40), 0, FONT_SMALL, CENTER, Colors::Jasmine);
+		new CTextBox(CGI->generaltexth->allTexts[480], Rect(320, 56, 256, 40), 0, FONT_SMALL, CENTER, Colors::YELLOW);
 
 		slider = new CSlider(231,481,137,0,0,0);
 		slider->moved = boost::bind(&CAltarWindow::sliderMoved,this,_1);
@@ -2895,9 +2895,9 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*=
 	else
 	{
 		//Sacrifice artifacts for experience
-		new CLabel(450, 34, FONT_SMALL, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[477]);
+		new CLabel(450, 34, FONT_SMALL, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[477]);
 		//%s's Creatures
-		new CLabel(302, 423, FONT_SMALL, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[478]);
+		new CLabel(302, 423, FONT_SMALL, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[478]);
 
 		sacrificeAll = new CAdventureMapButton(CGI->generaltexth->zelp[571], boost::bind(&CAltarWindow::SacrificeAll,this),393,520,"ALTFILL.DEF");
 		sacrificeAll->block(hero->artifactsInBackpack.empty() && hero->artifactsWorn.empty());
@@ -2912,9 +2912,9 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*=
 	}
 
 	//Experience needed to reach next level
-	new CTextBox(CGI->generaltexth->allTexts[475], Rect(15, 415, 125, 50), 0, FONT_SMALL, CENTER, Colors::Jasmine);
+	new CTextBox(CGI->generaltexth->allTexts[475], Rect(15, 415, 125, 50), 0, FONT_SMALL, CENTER, Colors::YELLOW);
 	//Total experience on the Altar
-	new CTextBox(CGI->generaltexth->allTexts[476], Rect(15, 495, 125, 40), 0, FONT_SMALL, CENTER, Colors::Jasmine);
+	new CTextBox(CGI->generaltexth->allTexts[476], Rect(15, 495, 125, 40), 0, FONT_SMALL, CENTER, Colors::YELLOW);
 
 	new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
 
@@ -3215,7 +3215,7 @@ void CAltarWindow::showAll(SDL_Surface * to)
 
 		int dmp, val;
 		market->getOffer(arts->commonInfo->src.art->artType->id, 0, dmp, val, EMarketMode::ARTIFACT_EXP);
-		printAtMiddleLoc(boost::lexical_cast<std::string>(val), 304, 498, FONT_SMALL, Colors::Cornsilk, to);
+		printAtMiddleLoc(boost::lexical_cast<std::string>(val), 304, 498, FONT_SMALL, Colors::WHITE, to);
 	}
 }
 
@@ -3310,10 +3310,10 @@ CSystemOptionsWindow::CSystemOptionsWindow():
 	static const std::string rsHelp = "{Select resolution}\n\n Change in-game screen resolution. Will only affect adventure map. Game restart required to apply new resolution.";
 
 	OBJ_CONSTRUCTION_CAPTURING_ALL;
-	title = new CLabel(242, 32, FONT_BIG, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[568]);
+	title = new CLabel(242, 32, FONT_BIG, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[568]);
 
 	//left window section
-	leftGroup =  new CLabelGroup(FONT_MEDIUM, CENTER, Colors::Jasmine);
+	leftGroup =  new CLabelGroup(FONT_MEDIUM, CENTER, Colors::YELLOW);
 	leftGroup->add(122,  64, CGI->generaltexth->allTexts[569]);
 	leftGroup->add(122, 130, CGI->generaltexth->allTexts[570]);
 	leftGroup->add(122, 196, CGI->generaltexth->allTexts[571]);
@@ -3322,7 +3322,7 @@ CSystemOptionsWindow::CSystemOptionsWindow():
 	leftGroup->add(122, 412, CGI->generaltexth->allTexts[395]);
 
 	//right section
-	rightGroup = new CLabelGroup(FONT_MEDIUM, TOPLEFT, Colors::Cornsilk);
+	rightGroup = new CLabelGroup(FONT_MEDIUM, TOPLEFT, Colors::WHITE);
 	rightGroup->add(282, 57,  CGI->generaltexth->allTexts[572]);
 	rightGroup->add(282, 89,  CGI->generaltexth->allTexts[573]);
 	rightGroup->add(282, 121, CGI->generaltexth->allTexts[574]);
@@ -3414,7 +3414,7 @@ CSystemOptionsWindow::CSystemOptionsWindow():
 	resText += boost::lexical_cast<std::string>(settings["video"]["screenRes"]["width"].Float());
 	resText += "x";
 	resText += boost::lexical_cast<std::string>(settings["video"]["screenRes"]["height"].Float());
-	gameResLabel = new CLabel(170, 292, FONT_MEDIUM, CENTER, Colors::Jasmine, resText);
+	gameResLabel = new CLabel(170, 292, FONT_MEDIUM, CENTER, Colors::YELLOW, resText);
 
 }
 
@@ -3528,9 +3528,9 @@ CTavernWindow::CTavernWindow(const CGObjectInstance *TavernObj):
 		selected = -1;
 	oldSelected = -1;
 
-	new CLabel(200, 35, FONT_BIG, CENTER, Colors::Jasmine, CGI->generaltexth->jktexts[37]);
-	new CLabel(320, 328, FONT_SMALL, CENTER, Colors::Cornsilk, "2500");
-	new CTextBox(LOCPLINT->cb->getTavernGossip(tavernObj), Rect(32, 190, 330, 68), 0, FONT_SMALL, CENTER, Colors::Cornsilk);
+	new CLabel(200, 35, FONT_BIG, CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[37]);
+	new CLabel(320, 328, FONT_SMALL, CENTER, Colors::WHITE, "2500");
+	new CTextBox(LOCPLINT->cb->getTavernGossip(tavernObj), Rect(32, 190, 330, 68), 0, FONT_SMALL, CENTER, Colors::WHITE);
 
 	new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
 	cancel = new CAdventureMapButton(CGI->generaltexth->tavernInfo[7],"", boost::bind(&CTavernWindow::close, this), 310, 428, "ICANCEL.DEF", SDLK_ESCAPE);
@@ -3599,7 +3599,7 @@ void CTavernWindow::show(SDL_Surface * to)
 			boost::algorithm::replace_first(recruit->hoverTexts[0],"%s",sel->h->type->heroClass->name);
 		}
 
-		printAtMiddleWB(sel->descr,pos.x+146,pos.y+389,FONT_SMALL,40,Colors::Cornsilk,to);
+		printAtMiddleWB(sel->descr,pos.x+146,pos.y+389,FONT_SMALL,40,Colors::WHITE,to);
 		CSDL_Ext::drawBorder(to,sel->pos.x-2,sel->pos.y-2,sel->pos.w+4,sel->pos.h+4,int3(247,223,123));
 	}
 }
@@ -3879,7 +3879,7 @@ CGarrisonWindow::CGarrisonWindow( const CArmedInstance *up, const CGHeroInstance
 		titleText = CGI->generaltexth->allTexts[35];
 		boost::algorithm::replace_first(titleText, "%s", garr->armedObjs[0]->Slots().begin()->second->type->namePl);
 	}
-	new CLabel(275, 30, FONT_BIG, CENTER, Colors::Jasmine, titleText);
+	new CLabel(275, 30, FONT_BIG, CENTER, Colors::YELLOW, titleText);
 
 	new CAnimImage("CREST58", garr->armedObjs[0]->getOwner(), 0, 28, 124);
 	new CAnimImage("PortraitsLarge", dynamic_cast<const CGHeroInstance*>(garr->armedObjs[1])->portrait, 0, 29, 222);
@@ -4827,8 +4827,8 @@ void CExchangeWindow::prepareBackground()
 	                      % h->name % h->level % h->type->heroClass->name);
 	};
 
-	new CLabel(147, 25, FONT_SMALL, CENTER, Colors::Cornsilk, genTitle(heroInst[0]));
-	new CLabel(653, 25, FONT_SMALL, CENTER, Colors::Cornsilk, genTitle(heroInst[1]));
+	new CLabel(147, 25, FONT_SMALL, CENTER, Colors::WHITE, genTitle(heroInst[0]));
+	new CLabel(653, 25, FONT_SMALL, CENTER, Colors::WHITE, genTitle(heroInst[1]));
 
 	//printing primary skills
 	for(int g=0; g<4; ++g)
@@ -4840,7 +4840,7 @@ void CExchangeWindow::prepareBackground()
 		CHeroWithMaybePickedArtifact heroWArt = CHeroWithMaybePickedArtifact(this, heroInst[b]);
 		//printing primary skills' amounts
 		for(int m=0; m<4; ++m)
-			new CLabel(352 + 93 * b, 35 + 36 * m, FONT_SMALL, CENTER, Colors::Cornsilk,
+			new CLabel(352 + 93 * b, 35 + 36 * m, FONT_SMALL, CENTER, Colors::WHITE,
 		               boost::lexical_cast<std::string>(heroWArt.getPrimSkillLevel(m)));
 
 		//printing secondary skills
@@ -4856,11 +4856,11 @@ void CExchangeWindow::prepareBackground()
 
 		//experience
 		new CAnimImage("PSKIL32", 4, 0, 103 + 490*b, 45);
-		new CLabel(119 + 490*b, 71, FONT_SMALL, CENTER, Colors::Cornsilk, makeNumberShort(heroInst[b]->exp));
+		new CLabel(119 + 490*b, 71, FONT_SMALL, CENTER, Colors::WHITE, makeNumberShort(heroInst[b]->exp));
 
 		//mana points
 		new CAnimImage("PSKIL32", 5, 0, 139 + 490*b, 45);
-		new CLabel(155 + 490*b, 71, FONT_SMALL, CENTER, Colors::Cornsilk, makeNumberShort(heroInst[b]->mana));
+		new CLabel(155 + 490*b, 71, FONT_SMALL, CENTER, Colors::WHITE, makeNumberShort(heroInst[b]->mana));
 	}
 
 	//printing portraits
@@ -4991,8 +4991,8 @@ CShipyardWindow::CShipyardWindow(const std::vector<si32> &cost, int state, int b
 	std::string goldValue = boost::lexical_cast<std::string>(cost[Res::GOLD]);
 	std::string woodValue = boost::lexical_cast<std::string>(cost[Res::WOOD]);
 
-	goldCost = new CLabel(118, 294, FONT_SMALL, CENTER, Colors::Cornsilk, goldValue);
-	woodCost = new CLabel(212, 294, FONT_SMALL, CENTER, Colors::Cornsilk, woodValue);
+	goldCost = new CLabel(118, 294, FONT_SMALL, CENTER, Colors::WHITE, goldValue);
+	woodCost = new CLabel(212, 294, FONT_SMALL, CENTER, Colors::WHITE, woodValue);
 
 	goldPic = new CAnimImage("RESOURCE", Res::GOLD, 0, 100, 244);
 	woodPic = new CAnimImage("RESOURCE", Res::WOOD, 0, 196, 244);
@@ -5012,8 +5012,8 @@ CShipyardWindow::CShipyardWindow(const std::vector<si32> &cost, int state, int b
 
 	statusBar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
 
-	title =     new CLabel(164, 27,  FONT_BIG,    CENTER, Colors::Jasmine, CGI->generaltexth->jktexts[13]);
-	costLabel = new CLabel(164, 220, FONT_MEDIUM, CENTER, Colors::Cornsilk,   CGI->generaltexth->jktexts[14]);
+	title =     new CLabel(164, 27,  FONT_BIG,    CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[13]);
+	costLabel = new CLabel(164, 220, FONT_MEDIUM, CENTER, Colors::WHITE,   CGI->generaltexth->jktexts[14]);
 }
 
 CPuzzleWindow::CPuzzleWindow(const int3 &GrailPos, double discoveredRatio):
@@ -5030,7 +5030,7 @@ CPuzzleWindow::CPuzzleWindow(const int3 &GrailPos, double discoveredRatio):
 	quitb->borderEnabled = true;
 
 	new CPicture("PUZZLOGO", 607, 3);
-	new CLabel(700, 95, FONT_BIG, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[463]);
+	new CLabel(700, 95, FONT_BIG, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[463]);
 	new CResDataBar("ZRESBAR.bmp", 3, 575, 32, 2, 85, 85);
 
 	int faction = LOCPLINT->cb->getStartInfo()->playerInfos.find(LOCPLINT->playerID)->second.castle;
@@ -5122,7 +5122,7 @@ CTransformerWindow::CItem::CItem(CTransformerWindow * parent, int size, int id):
 	pos.x += 45  + (id%3)*83 + id/6*83;
 	pos.y += 109 + (id/3)*98;
 	icon = new CAnimImage("TWCRPORT", parent->army->getCreature(id)->idNumber + 2);
-	new CLabel(28, 76,FONT_SMALL, CENTER, Colors::Cornsilk, boost::lexical_cast<std::string>(size));//stack size
+	new CLabel(28, 76,FONT_SMALL, CENTER, Colors::WHITE, boost::lexical_cast<std::string>(size));//stack size
 }
 
 void CTransformerWindow::makeDeal()
@@ -5168,10 +5168,10 @@ CTransformerWindow::CTransformerWindow(const CGHeroInstance * _hero, const CGTow
 	cancel = new CAdventureMapButton(CGI->generaltexth->zelp[592],boost::bind(&CTransformerWindow::close, this),392,416,"ICANCEL.DEF",SDLK_ESCAPE);
 	bar    = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
 
-	new CLabel(153, 29,FONT_SMALL, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[485]);//holding area
-	new CLabel(153+295, 29, FONT_SMALL, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[486]);//transformer
-	new CTextBox(CGI->generaltexth->allTexts[487], Rect(26,  56, 255, 40), 0, FONT_MEDIUM, CENTER, Colors::Jasmine);//move creatures to create skeletons
-	new CTextBox(CGI->generaltexth->allTexts[488], Rect(320, 56, 255, 40), 0, FONT_MEDIUM, CENTER, Colors::Jasmine);//creatures here will become skeletons
+	new CLabel(153, 29,FONT_SMALL, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[485]);//holding area
+	new CLabel(153+295, 29, FONT_SMALL, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[486]);//transformer
+	new CTextBox(CGI->generaltexth->allTexts[487], Rect(26,  56, 255, 40), 0, FONT_MEDIUM, CENTER, Colors::YELLOW);//move creatures to create skeletons
+	new CTextBox(CGI->generaltexth->allTexts[488], Rect(320, 56, 255, 40), 0, FONT_MEDIUM, CENTER, Colors::YELLOW);//creatures here will become skeletons
 
 }
 
@@ -5240,8 +5240,8 @@ void CUniversityWindow::CItem::showAll(SDL_Surface * to)
 
 	blitAtLoc(bar->bg, -28, -22, to);
 	blitAtLoc(bar->bg, -28,  48, to);
-	printAtMiddleLoc  (CGI->generaltexth->skillName[ID], 22, -13, FONT_SMALL, Colors::Cornsilk,to);//Name
-	printAtMiddleLoc  (CGI->generaltexth->levels[0], 22, 57, FONT_SMALL, Colors::Cornsilk,to);//Level(always basic)
+	printAtMiddleLoc  (CGI->generaltexth->skillName[ID], 22, -13, FONT_SMALL, Colors::WHITE,to);//Name
+	printAtMiddleLoc  (CGI->generaltexth->levels[0], 22, 57, FONT_SMALL, Colors::WHITE,to);//Level(always basic)
 
 	CAnimImage::showAll(to);
 }
@@ -5283,10 +5283,10 @@ CUniversityWindow::CUniversityWindow(const CGHeroInstance * _hero, const IMarket
 		titlePic->center(Point(232 + pos.x, 76 + pos.y));
 
 	//Clerk speech
-	new CTextBox(CGI->generaltexth->allTexts[603], Rect(24, 129, 413, 70), 0, FONT_SMALL, CENTER, Colors::Cornsilk);
+	new CTextBox(CGI->generaltexth->allTexts[603], Rect(24, 129, 413, 70), 0, FONT_SMALL, CENTER, Colors::WHITE);
 
 	//University
-	new CLabel(231, 26, FONT_MEDIUM, CENTER, Colors::Jasmine, CGI->generaltexth->allTexts[602]);
+	new CLabel(231, 26, FONT_MEDIUM, CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[602]);
 
 	std::vector<int> list = market->availableItemsIds(EMarketMode::RESOURCE_SKILL);
 
@@ -5312,14 +5312,14 @@ CUnivConfirmWindow::CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bo
 	boost::replace_first(text, "%s", CGI->generaltexth->skillName[SKILL]);
 	boost::replace_first(text, "%d", "2000");
 
-	new CTextBox(text, Rect(24, 129, 413, 70), 0, FONT_SMALL, CENTER, Colors::Cornsilk);//Clerk speech
+	new CTextBox(text, Rect(24, 129, 413, 70), 0, FONT_SMALL, CENTER, Colors::WHITE);//Clerk speech
 
-	new CLabel(230, 37,  FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth-> skillName[SKILL]);//Skill name
+	new CLabel(230, 37,  FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth-> skillName[SKILL]);//Skill name
 	new CAnimImage("SECSKILL", SKILL*3+3, 0, 211, 51);//skill
-	new CLabel(230, 107, FONT_SMALL, CENTER, Colors::Cornsilk, CGI->generaltexth->levels[1]);//Skill level
+	new CLabel(230, 107, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->levels[1]);//Skill level
 
 	new CAnimImage("RESOURCE", Res::GOLD, 0, 210, 210);//gold
-	new CLabel(230, 267, FONT_SMALL, CENTER, Colors::Cornsilk, "2000");//Cost
+	new CLabel(230, 267, FONT_SMALL, CENTER, Colors::WHITE, "2000");//Cost
 
 	std::string hoverText = CGI->generaltexth->allTexts[609];
 	boost::replace_first(hoverText, "%s", CGI->generaltexth->levels[0]+ " " + CGI->generaltexth->skillName[SKILL]);
@@ -5354,7 +5354,7 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance *visitor, const CGObjectIn
 	slotsCount=7;
 	resources =  CDefHandler::giveDefEss("SMALRES.DEF");
 
-	new CLabel(325, 32, FONT_BIG, CENTER, Colors::Jasmine, fort->hoverName);//Hill Fort
+	new CLabel(325, 32, FONT_BIG, CENTER, Colors::YELLOW, fort->hoverName);//Hill Fort
 
 	heroPic = new CHeroArea(30, 60, hero);
 
@@ -5457,14 +5457,14 @@ void CHillFortWindow::showAll (SDL_Surface *to)
 					if(!val) continue;
 
 					blitAtLoc(resources->ourImages[j].bitmap, 104+76*i, curY, to);
-					printToLoc(boost::lexical_cast<std::string>(val), 168+76*i, curY+16, FONT_SMALL, Colors::Cornsilk, to);
+					printToLoc(boost::lexical_cast<std::string>(val), 168+76*i, curY+16, FONT_SMALL, Colors::WHITE, to);
 					curY += 20;
 				}
 			}
 			else//free upgrade - print gold image and "Free" text
 			{
 				blitAtLoc(resources->ourImages[6].bitmap, 104+76*i, 128, to);
-				printToLoc(CGI->generaltexth->allTexts[344], 168+76*i, 144, FONT_SMALL, Colors::Cornsilk, to);
+				printToLoc(CGI->generaltexth->allTexts[344], 168+76*i, 144, FONT_SMALL, Colors::WHITE, to);
 			}
 		}
 	}
@@ -5473,7 +5473,7 @@ void CHillFortWindow::showAll (SDL_Surface *to)
 		if (totalSumm[i])//this resource is used - display it
 		{
 			blitAtLoc(resources->ourImages[i].bitmap, 104+76*i, 237, to);
-			printToLoc(boost::lexical_cast<std::string>(totalSumm[i]), 166+76*i, 253, FONT_SMALL, Colors::Cornsilk, to);
+			printToLoc(boost::lexical_cast<std::string>(totalSumm[i]), 166+76*i, 253, FONT_SMALL, Colors::WHITE, to);
 		}
 	}
 }
@@ -5563,14 +5563,14 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner):
 
 		std::string text = CGI->generaltexth->jktexts[24+g];
 		boost::algorithm::trim_if(text,boost::algorithm::is_any_of("\""));
-		new CLabel(135, y, FONT_MEDIUM, CENTER, Colors::Jasmine, text);
+		new CLabel(135, y, FONT_MEDIUM, CENTER, Colors::YELLOW, text);
 	}
 
 	for(int g=1; g<tgi.playerColors.size(); ++g)
 		new CAnimImage("PRSTRIPS", g-1, 0, 250 + 66*g, 7);
 
 	for(int g=0; g<tgi.playerColors.size(); ++g)
-		new CLabel(283 + 66*g, 24, FONT_BIG, CENTER, Colors::Jasmine, CGI->generaltexth->jktexts[16+g]);
+		new CLabel(283 + 66*g, 24, FONT_BIG, CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[16+g]);
 
 	//printing flags
 	for(int g = 0; g < ARRAY_COUNT(fields); ++g) //by lines
@@ -5618,10 +5618,10 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner):
 			if(iter.second.details)
 			{
 				new CTextBox(CGI->generaltexth->allTexts[184], Rect(260 + 66*counter, 396, 52, 64),
-				             0, FONT_TINY, TOPLEFT, Colors::Cornsilk);
+				             0, FONT_TINY, TOPLEFT, Colors::WHITE);
 				for (int i=0; i<iter.second.details->primskills.size(); ++i)
 				{
-					new CLabel(310 + 66 * counter, 407 + 11*i, FONT_TINY, BOTTOMRIGHT, Colors::Cornsilk,
+					new CLabel(310 + 66 * counter, 407 + 11*i, FONT_TINY, BOTTOMRIGHT, Colors::WHITE,
 					           boost::lexical_cast<std::string>(iter.second.details->primskills[i]));
 				}
 			}
@@ -5652,7 +5652,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner):
             text = CGI->generaltexth->arraytxt[168 + it.second];
         }
 
-		new CLabel(283 + 66*counter, 459, FONT_SMALL, CENTER, Colors::Cornsilk, text);
+		new CLabel(283 + 66*counter, 459, FONT_SMALL, CENTER, Colors::WHITE, text);
 
 		counter++;
 	}

+ 0 - 5
client/UIFramework/CGuiHandler.h

@@ -129,11 +129,6 @@ struct SSetCaptureState
 	~SSetCaptureState();
 };
 
-namespace Colors
-{
-
-}
-
 #define OBJ_CONSTRUCTION SObjectConstruction obj__i(this)
 #define OBJ_CONSTRUCTION_CAPTURING_ALL defActions = 255; SSetCaptureState obj__i1(true, 255); SObjectConstruction obj__i(this)
 #define BLOCK_CAPTURING SSetCaptureState obj__i(false, 0)

+ 2 - 2
client/UIFramework/CIntObject.cpp

@@ -127,12 +127,12 @@ CIntObject::~CIntObject()
 		parent_m->removeChild(this);
 }
 
-void CIntObject::printAtLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::Cornsilk*/, SDL_Surface * dst/*=screen*/ )
+void CIntObject::printAtLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::WHITE*/, SDL_Surface * dst/*=screen*/ )
 {
 	CSDL_Ext::printAt(text, pos.x + x, pos.y + y, font, kolor, dst);
 }
 
-void CIntObject::printAtMiddleLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::Cornsilk*/, SDL_Surface * dst/*=screen*/ )
+void CIntObject::printAtMiddleLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::WHITE*/, SDL_Surface * dst/*=screen*/ )
 {
 	CSDL_Ext::printAtMiddle(text, pos.x + x, pos.y + y, font, kolor, dst);
 }

+ 6 - 6
client/UIFramework/CIntObjectClasses.cpp

@@ -1147,7 +1147,7 @@ void CStatusBar::show(SDL_Surface * to)
 	SDL_Rect srcRect = genRect(pos.h,pos.w,0,0);
 	SDL_Rect dstRect = genRect(pos.h,pos.w,pos.x,pos.y);
 	CSDL_Ext::blitSurface(bg,&srcRect,to,&dstRect);
-	CSDL_Ext::printAtMiddle(current,middlex,middley,FONT_SMALL,Colors::Cornsilk,to);
+	CSDL_Ext::printAtMiddle(current,middlex,middley,FONT_SMALL,Colors::WHITE,to);
 }
 
 std::string CStatusBar::getCurrent()
@@ -1218,7 +1218,7 @@ void CLabel::showAll(SDL_Surface * to)
 	printer[alignment](toPrint, pos.x + textOffset.x, pos.y + textOffset.y, font, color, to);
 }
 
-CLabel::CLabel(int x, int y, EFonts Font /*= FONT_SMALL*/, EAlignment Align, const SDL_Color &Color /*= Colors::Cornsilk*/, const std::string &Text /*= ""*/)
+CLabel::CLabel(int x, int y, EFonts Font /*= FONT_SMALL*/, EAlignment Align, const SDL_Color &Color /*= Colors::WHITE*/, const std::string &Text /*= ""*/)
 :alignment(Align), font(Font), color(Color), text(Text)
 {
 	autoRedraw = true;
@@ -1279,7 +1279,7 @@ void CBoundedLabel::blitLine(SDL_Surface *to, Point where, std::string what)
 		end = what.find_first_of(delimeters[currDelimeter % 2], begin);
 		std::string toPrint = what.substr(begin, end);
 		if (currDelimeter % 2)
-			CSDL_Ext::printAt(toPrint, where.x, where.y, font, Colors::Jasmine, to);
+			CSDL_Ext::printAt(toPrint, where.x, where.y, font, Colors::YELLOW, to);
 		else
 			CSDL_Ext::printAt(toPrint, where.x, where.y, font, color, to);
 		begin = end;
@@ -1344,7 +1344,7 @@ void CLabelGroup::add(int x, int y, const std::string &text)
 	new CLabel(x, y, font, align, color, text);
 }
 
-CTextBox::CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= TOPLEFT*/, const SDL_Color &Color /*= Colors::Cornsilk*/)
+CTextBox::CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= TOPLEFT*/, const SDL_Color &Color /*= Colors::WHITE*/)
 :CBoundedLabel(rect.x, rect.y, Font, Align, Color, Text), sliderStyle(SliderStyle), slider(NULL)
 {
 	type |= REDRAW_PARENT;
@@ -1436,13 +1436,13 @@ std::string CGStatusBar::getCurrent()
 	return text;
 }
 
-//CGStatusBar::CGStatusBar(int x, int y, EFonts Font /*= FONT_SMALL*/, EAlignment Align, const SDL_Color &Color /*= Colors::Cornsilk*/, const std::string &Text /*= ""*/)
+//CGStatusBar::CGStatusBar(int x, int y, EFonts Font /*= FONT_SMALL*/, EAlignment Align, const SDL_Color &Color /*= Colors::WHITE*/, const std::string &Text /*= ""*/)
 //: CLabel(x, y, Font, Align, Color, Text)
 //{
 //	init();
 //}
 
-CGStatusBar::CGStatusBar(CPicture *BG, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= CENTER*/, const SDL_Color &Color /*= Colors::Cornsilk*/)
+CGStatusBar::CGStatusBar(CPicture *BG, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= CENTER*/, const SDL_Color &Color /*= Colors::WHITE*/)
 : CLabel(BG->pos.x, BG->pos.y, Font, Align, Color, "")
 {
 	init();

+ 8 - 8
client/UIFramework/CIntObjectClasses.h

@@ -99,7 +99,7 @@ public:
 	bool swappedImages,//fix for some buttons: normal and pressed image are swapped
 		keepFrame; // don't change visual representation
 
-	void addTextOverlay(const std::string &Text, EFonts font, SDL_Color color = Colors::Cornsilk);
+    void addTextOverlay(const std::string &Text, EFonts font, SDL_Color color = Colors::WHITE);
 	void update();//to refresh button after image or text change
 
 	void setOffset(int newOffset);
@@ -347,7 +347,7 @@ public:
 
 	virtual void setTxt(const std::string &Txt);
 	void showAll(SDL_Surface * to); //shows statusbar (with current text)
-	CLabel(int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::Cornsilk, const std::string &Text =  "");
+    CLabel(int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::WHITE, const std::string &Text =  "");
 };
 
 class CBoundedLabel : public CLabel
@@ -361,7 +361,7 @@ public:
 
 	std::vector<std::string> lines;
 
-	CBoundedLabel(int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::Cornsilk, const std::string &Text =  "")
+    CBoundedLabel(int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::WHITE, const std::string &Text =  "")
 		: CLabel (x, y, Font, Align, Color, Text){};
 	void setTxt(const std::string &Txt);
 	void setBounds(int limitW, int limitH);
@@ -377,7 +377,7 @@ class CLabelGroup : public CIntObject
 	EAlignment align;
 	const SDL_Color &color;
 public:
-	CLabelGroup(EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::Cornsilk);
+    CLabelGroup(EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::WHITE);
 	void add(int x=0, int y=0, const std::string &text =  "");
 };
 
@@ -391,8 +391,8 @@ public:
 	std::vector<CAnimImage* > effects;
 	CSlider *slider;
 
-	//CTextBox( std::string Text, const Point &Pos, int w, int h, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::Cornsilk);
-	CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::Cornsilk);
+    //CTextBox( std::string Text, const Point &Pos, int w, int h, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::WHITE);
+    CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = Colors::WHITE);
 	void showAll(SDL_Surface * to); //shows statusbar (with current text)
 	void recalculateLines(const std::string &Txt);
 
@@ -412,8 +412,8 @@ public:
 	std::string getCurrent(); //returns currently displayed text
 	void show(SDL_Surface * to); //shows statusbar (with current text)
 
-	//CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = Colors::Cornsilk, const std::string &Text =  "");
-	CGStatusBar(CPicture *BG, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = Colors::Cornsilk); //given CPicture will be captured by created sbar and it's pos will be used as pos for sbar
+    //CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = Colors::WHITE, const std::string &Text =  "");
+    CGStatusBar(CPicture *BG, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = Colors::WHITE); //given CPicture will be captured by created sbar and it's pos will be used as pos for sbar
 	CGStatusBar(int x, int y, std::string name, int maxw=-1); 
 
 	~CGStatusBar();

+ 22 - 17
client/UIFramework/SDL_Extensions.cpp

@@ -24,6 +24,11 @@ SDL_Color Colors::createColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a /*= 0*/)
 	return temp;
 }
 
+const SDL_Color Colors::YELLOW = createColor(229, 215, 123, 0);
+const SDL_Color Colors::WHITE = createColor(255, 243, 222, 0);
+const SDL_Color Colors::MetallicGold = createColor(173, 142, 66);
+const SDL_Color Colors::Maize = createColor(242, 226, 110);
+
 SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given
 {
 	SDL_Surface * ret = SDL_CreateRGBSurface(mod->flags,w,h,mod->format->BitsPerPixel,mod->format->Rmask,mod->format->Gmask,mod->format->Bmask,mod->format->Amask);
@@ -155,7 +160,7 @@ void CSDL_Ext::printAtWB(const std::string & text, int x, int y, EFonts font, in
 }
 
 
-void CSDL_Ext::printAtMiddleWB( const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor/*=Colors::Jasmine*/, SDL_Surface * dst/*=screen*/ )
+void CSDL_Ext::printAtMiddleWB( const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor/*=Colors::YELLOW*/, SDL_Surface * dst/*=screen*/ )
 {
 	if (graphics->fontsTrueType[font])
 	{
@@ -204,7 +209,7 @@ void printAtMiddle(const std::string & text, int x, int y, TTF_Font * font, SDL_
 	SDL_FreeSurface(temp);
 }
 
-void CSDL_Ext::printAtMiddle( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::Cornsilk*/, SDL_Surface * dst/*=screen*/ )
+void CSDL_Ext::printAtMiddle( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::WHITE*/, SDL_Surface * dst/*=screen*/ )
 {
 	if (graphics->fontsTrueType[font])
 	{
@@ -351,7 +356,7 @@ void printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color
 	SDL_FreeSurface(temp);
 }
 
-void CSDL_Ext::printTo( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::Cornsilk*/, SDL_Surface * dst/*=screen*/ )
+void CSDL_Ext::printTo( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=Colors::WHITE*/, SDL_Surface * dst/*=screen*/ )
 {
 	if (graphics->fontsTrueType[font])
 	{
@@ -612,18 +617,18 @@ void CSDL_Ext::blitWithRotate2(const SDL_Surface *src, const SDL_Rect * srcRect,
 template<int bpp>
 void CSDL_Ext::blitWithRotate3(const SDL_Surface *src, const SDL_Rect * srcRect, SDL_Surface * dst, const SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24/32 bpp dests
 {
- 	Uint8 *sp = (Uint8 *)src->pixels + (src->h - srcRect->h - srcRect->y)*src->pitch + (src->w - srcRect->w - srcRect->x);
- 	Uint8 *dporg = (Uint8 *)dst->pixels +(dstRect->y + dstRect->h - 1)*dst->pitch + (dstRect->x+dstRect->w)*bpp;
- 	const SDL_Color * const colors = src->format->palette->colors;
+	Uint8 *sp = (Uint8 *)src->pixels + (src->h - srcRect->h - srcRect->y)*src->pitch + (src->w - srcRect->w - srcRect->x);
+	Uint8 *dporg = (Uint8 *)dst->pixels +(dstRect->y + dstRect->h - 1)*dst->pitch + (dstRect->x+dstRect->w)*bpp;
+	const SDL_Color * const colors = src->format->palette->colors;
 
- 	for(int i=dstRect->h; i>0; i--, dporg -= dst->pitch)
- 	{
- 		Uint8 *dp = dporg;
- 		for(int j=dstRect->w; j>0; j--, sp++)
+	for(int i=dstRect->h; i>0; i--, dporg -= dst->pitch)
+	{
+		Uint8 *dp = dporg;
+		for(int j=dstRect->w; j>0; j--, sp++)
 			ColorPutter<bpp, -1>::PutColor(dp, colors[*sp]);
 
 		sp += src->w - dstRect->w;
- 	}
+	}
 }
 
 template<int bpp>
@@ -1123,7 +1128,7 @@ template<int bpp>
 void scaleSurfaceFastInternal(SDL_Surface *surf, SDL_Surface *ret)
 {
 	const float factorX = float(surf->w) / float(ret->w),
-	            factorY = float(surf->h) / float(ret->h);
+				factorY = float(surf->h) / float(ret->h);
 
 	for(int y = 0; y < ret->h; y++)
 	{
@@ -1131,7 +1136,7 @@ void scaleSurfaceFastInternal(SDL_Surface *surf, SDL_Surface *ret)
 		{
 			//coordinates we want to calculate
 			int origX = floor(factorX * x),
-			    origY = floor(factorY * y);
+				origY = floor(factorY * y);
 
 			// Get pointers to source pixels
 			Uint8 *srcPtr = (Uint8*)surf->pixels + origY * surf->pitch + origX * bpp;
@@ -1167,7 +1172,7 @@ template<int bpp>
 void scaleSurfaceInternal(SDL_Surface *surf, SDL_Surface *ret)
 {
 	const float factorX = float(surf->w - 1) / float(ret->w),
-	            factorY = float(surf->h - 1) / float(ret->h);
+				factorY = float(surf->h - 1) / float(ret->h);
 
 	for(int y = 0; y < ret->h; y++)
 	{
@@ -1175,10 +1180,10 @@ void scaleSurfaceInternal(SDL_Surface *surf, SDL_Surface *ret)
 		{
 			//coordinates we want to interpolate
 			float origX = factorX * x,
-			      origY = factorY * y;
+				  origY = factorY * y;
 
 			float x1 = floor(origX), x2 = floor(origX+1),
-			      y1 = floor(origY), y2 = floor(origY+1);
+				  y1 = floor(origY), y2 = floor(origY+1);
 			//assert( x1 >= 0 && y1 >= 0 && x2 < surf->w && y2 < surf->h);//All pixels are in range
 
 			// Calculate weights of each source pixel
@@ -1312,4 +1317,4 @@ std::string CSDL_Ext::trimToFit(std::string text, int widthLimit, EFonts font)
 
 template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<2>(int, int);
 template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<3>(int, int);
-template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<4>(int, int);
+template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<4>(int, int);

+ 32 - 14
client/UIFramework/SDL_Extensions.h

@@ -38,15 +38,33 @@ void blitAt(SDL_Surface * src, const SDL_Rect & pos, SDL_Surface * dst=screen);
 void updateRect (SDL_Rect * rect, SDL_Surface * scr = screen);
 bool isItIn(const SDL_Rect * rect, int x, int y);
 
-namespace Colors
+/**
+ * The colors class defines color constants of type SDL_Color.
+ */
+class Colors
 {
-	SDL_Color createColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a = 0);
-
-	const SDL_Color	Jasmine = createColor(229, 215, 123, 0); // http://en.wikipedia.org/wiki/Jasmine_%28color%29
-	const SDL_Color Cornsilk = createColor(255, 243, 222, 0); // http://en.wikipedia.org/wiki/Shades_of_white
-	const SDL_Color MetallicGold = createColor(173, 142, 66); // http://en.wikipedia.org/wiki/Gold_%28color%29
-	const SDL_Color Maize = createColor(242, 226, 110); // http://en.wikipedia.org/wiki/Maize_%28color%29
-}
+public:
+	/** the h3 yellow color, typically used for headlines */
+	static const SDL_Color YELLOW;
+
+	/** the standard h3 white color */
+	static const SDL_Color WHITE;
+
+	static const SDL_Color MetallicGold;
+	static const SDL_Color Maize;
+
+private:
+	/**
+	 * Creates a SDL_Color object.
+	 *
+	 * @param r the red value ranging from 0 to 255
+	 * @param g the green value ranging from 0 to 255
+	 * @param b the blue value ranging from 0 to 255
+	 * @param a the alpha value ranging from 0(opaque) to 255(transparent)
+	 * @return the created SDL_Color object
+	 */
+	static SDL_Color createColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a = 0);
+};
 
 //MSVC gives an error when calling abs with ui64 -> we add template that will match calls with unsigned arg and return it
 template<typename T>
@@ -109,7 +127,7 @@ namespace CSDL_Ext
 		SDL_Rect oldRect;
 	public:
 		CClipRectGuard(SDL_Surface * surface, const SDL_Rect & rect):
-		    surf(surface)
+			surf(surface)
 		{
 			SDL_GetClipRect(surf, &oldRect);
 			SDL_SetClipRect(surf, &rect);
@@ -164,11 +182,11 @@ namespace CSDL_Ext
 	int blit8bppAlphaTo24bpp(const SDL_Surface * src, const SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface
 	Uint32 colorToUint32(const SDL_Color * color); //little endian only
 
-	void printAtWB(const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor=Colors::Cornsilk, SDL_Surface * dst=screen);
-	void printAt(const std::string & text, int x, int y, EFonts font, SDL_Color kolor=Colors::Cornsilk, SDL_Surface * dst=screen);
-	void printTo(const std::string & text, int x, int y, EFonts font, SDL_Color kolor=Colors::Cornsilk, SDL_Surface * dst=screen);
-	void printAtMiddle(const std::string & text, int x, int y, EFonts font, SDL_Color kolor=Colors::Cornsilk, SDL_Surface * dst=screen);
-	void printAtMiddleWB(const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor=Colors::Jasmine, SDL_Surface * dst=screen);
+	void printAtWB(const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor=Colors::WHITE, SDL_Surface * dst=screen);
+	void printAt(const std::string & text, int x, int y, EFonts font, SDL_Color kolor=Colors::WHITE, SDL_Surface * dst=screen);
+	void printTo(const std::string & text, int x, int y, EFonts font, SDL_Color kolor=Colors::WHITE, SDL_Surface * dst=screen);
+	void printAtMiddle(const std::string & text, int x, int y, EFonts font, SDL_Color kolor=Colors::WHITE, SDL_Surface * dst=screen);
+	void printAtMiddleWB(const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor=Colors::YELLOW, SDL_Surface * dst=screen);
 
 	void update(SDL_Surface * what = screen); //updates whole surface (default - main screen)
 	void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const int3 &color);

+ 5 - 1
config/defaultSettings.json

@@ -23,7 +23,11 @@
 			"sound" : {
 				"type" : "number",
 				"default" : 88
-			}
+            },
+            "enableRMG" : {
+                "type" : "bool",
+                "default" : false
+            }
 		},
 		"default" : {}
 	},

+ 20 - 1
lib/CMakeLists.txt

@@ -17,6 +17,7 @@ set(lib_SRCS
         Map/CMap.cpp
         Map/CMapInfo.cpp
         Map/CMapService.cpp
+   		RMG/CMapGenOptions.cpp
         BattleAction.cpp
         BattleHex.cpp
         BattleState.cpp
@@ -48,7 +49,25 @@ set(lib_SRCS
         VCMI_Lib.cpp
 )
 
-add_library(vcmi SHARED ${lib_SRCS})
+set(lib_HEADERS
+		AI_Base.h
+		CondSh.h
+		ConstTransitivePtr.h
+		CScriptingModule.h
+		CStopWatch.h
+		GameConstants.h
+		IGameEventsReceiver.h
+		int3.h
+		Interprocess.h
+		NetPacks.h
+		RegisterTypes.h
+		StartInfo.h
+		UnlockGuard.h
+		VCMIDirs.h
+		vcmi_endian.h
+)
+
+add_library(vcmi SHARED ${lib_SRCS} ${lib_HEADERS})
 target_link_libraries(vcmi ${Boost_LIBRARIES} ${SDL_LIBRARY} ${ZLIB_LIBRARIES})
 
 install(TARGETS vcmi DESTINATION ${LIB_DIR})

+ 1 - 1
lib/Filesystem/CBinaryReader.cpp

@@ -39,7 +39,7 @@ CInputStream * CBinaryReader::getStream()
 
 void CBinaryReader::setStream(CInputStream * stream)
 {
-    this->stream = stream;
+	this->stream = stream;
 }
 
 si64 CBinaryReader::read(ui8 * data, si64 size)

+ 5 - 5
lib/Filesystem/CCompressedStream.cpp

@@ -6,11 +6,11 @@
 static const int inflateBlockSize = 10000;
 
 CCompressedStream::CCompressedStream(std::unique_ptr<CInputStream> stream, bool gzip, size_t decompressedSize):
-    gzipStream(std::move(stream)),
-    buffer(decompressedSize),
-    decompressedSize(0),
-    compressedBuffer(inflateBlockSize),
-    position(0)
+	gzipStream(std::move(stream)),
+	buffer(decompressedSize),
+	decompressedSize(0),
+	compressedBuffer(inflateBlockSize),
+	position(0)
 {
 	assert(gzipStream);
 

+ 11 - 11
lib/Filesystem/CMemoryStream.cpp

@@ -2,36 +2,36 @@
 #include "CMemoryStream.h"
 
 CMemoryStream::CMemoryStream(const ui8 * data, si64 size) :
-    data(data), size(size), position(0)
+	data(data), size(size), position(0)
 {
 
 }
 
 si64 CMemoryStream::read(ui8 * data, si64 size)
 {
-    si64 toRead = std::min(this->size - tell(), size);
-    std::copy(this->data + position, this->data + position + toRead, data);
+	si64 toRead = std::min(this->size - tell(), size);
+	std::copy(this->data + position, this->data + position + toRead, data);
 	position += size;
-    return toRead;
+	return toRead;
 }
 
 si64 CMemoryStream::seek(si64 position)
 {
-    si64 origin = tell();
-    this->position = std::min(position, size);
-    return tell() - origin;
+	si64 origin = tell();
+	this->position = std::min(position, size);
+	return tell() - origin;
 }
 
 si64 CMemoryStream::tell()
 {
-    return this->position;
+	return this->position;
 }
 
 si64 CMemoryStream::skip(si64 delta)
 {
-    si64 origin = tell();
-    this->position += std::min(size - origin, delta);
-    return tell() - origin;
+	si64 origin = tell();
+	this->position += std::min(size - origin, delta);
+	return tell() - origin;
 }
 
 si64 CMemoryStream::getSize()

+ 5 - 5
lib/Filesystem/CMemoryStream.h

@@ -20,12 +20,12 @@ class DLL_LINKAGE CMemoryStream : public CInputStream
 {
 public:
 	/**
-     * C-tor. The data buffer won't be free'd. (no ownership)
+	 * C-tor. The data buffer won't be free'd. (no ownership)
 	 *
-     * @param data a pointer to the data array.
+	 * @param data a pointer to the data array.
 	 * @param size The size in bytes of the array.
 	 */
-    CMemoryStream(const ui8 * data, si64 size);
+	CMemoryStream(const ui8 * data, si64 size);
 
 	/**
 	 * Reads n bytes from the stream into the data buffer.
@@ -67,8 +67,8 @@ public:
 	si64 getSize();
 
 private:
-    /** A pointer to the data array. */
-    const ui8 * data;
+	/** A pointer to the data array. */
+	const ui8 * data;
 
 	/** The size in bytes of the array. */
 	si64 size;

+ 123 - 123
lib/Map/CMap.cpp

@@ -11,48 +11,48 @@ SHeroName::SHeroName() : heroId(-1)
 }
 
 PlayerInfo::PlayerInfo(): p7(0), p8(0), p9(0), powerPlaceholders(-1),
-    canHumanPlay(false), canComputerPlay(false),
-    aiTactic(EAiTactic::RANDOM), isFactionRandom(false), mainHeroPortrait(0), hasMainTown(false),
-    generateHeroAtMainTown(false), team(255), generateHero(false)
+	canHumanPlay(false), canComputerPlay(false),
+	aiTactic(EAiTactic::RANDOM), isFactionRandom(false), mainHeroPortrait(0), hasMainTown(false),
+	generateHeroAtMainTown(false), team(255), generateHero(false)
 {
 
 }
 
 si8 PlayerInfo::defaultCastle() const
 {
-    assert(!allowedFactions.empty()); // impossible?
+	assert(!allowedFactions.empty()); // impossible?
 
-    if(allowedFactions.size() == 1)
-    {
-        // only one faction is available - pick it
-        return *allowedFactions.begin();
-    }
+	if(allowedFactions.size() == 1)
+	{
+		// only one faction is available - pick it
+		return *allowedFactions.begin();
+	}
 
-    // set to random
-    return -1;
+	// set to random
+	return -1;
 }
 
 si8 PlayerInfo::defaultHero() const
 {
-    // we will generate hero in front of main town
-    if((generateHeroAtMainTown && hasMainTown) || p8)
-    {
-        //random hero
-        return -1;
-    }
+	// we will generate hero in front of main town
+	if((generateHeroAtMainTown && hasMainTown) || p8)
+	{
+		//random hero
+		return -1;
+	}
 
-    return -2;
+	return -2;
 }
 
 LossCondition::LossCondition() : typeOfLossCon(ELossConditionType::LOSSSTANDARD),
-    pos(int3(-1, -1, -1)), timeLimit(-1), obj(nullptr)
+	pos(int3(-1, -1, -1)), timeLimit(-1), obj(nullptr)
 {
 
 }
 
 VictoryCondition::VictoryCondition() : condition(EVictoryConditionType::WINSTANDARD),
-    allowNormalVictory(false), appliesToAI(false), pos(int3(-1, -1, -1)), objectId(0),
-    count(0), obj(nullptr)
+	allowNormalVictory(false), appliesToAI(false), pos(int3(-1, -1, -1)), objectId(0),
+	count(0), obj(nullptr)
 {
 
 }
@@ -63,19 +63,19 @@ DisposedHero::DisposedHero() : heroId(0), portrait(255), players(0)
 }
 
 CMapEvent::CMapEvent() : players(0), humanAffected(0), computerAffected(0),
-    firstOccurence(0), nextOccurence(0)
+	firstOccurence(0), nextOccurence(0)
 {
 
 }
 
 bool CMapEvent::earlierThan(const CMapEvent & other) const
 {
-    return firstOccurence < other.firstOccurence;
+	return firstOccurence < other.firstOccurence;
 }
 
 bool CMapEvent::earlierThanOrEqual(const CMapEvent & other) const
 {
-    return firstOccurence <= other.firstOccurence;
+	return firstOccurence <= other.firstOccurence;
 }
 
 CCastleEvent::CCastleEvent() : town(nullptr)
@@ -84,51 +84,51 @@ CCastleEvent::CCastleEvent() : town(nullptr)
 }
 
 TerrainTile::TerrainTile() : terType(ETerrainType::BORDER), terView(0), riverType(ERiverType::NO_RIVER),
-    riverDir(0), roadType(ERoadType::NO_ROAD), roadDir(0), extTileFlags(0), visitable(false),
-    blocked(false)
+	riverDir(0), roadType(ERoadType::NO_ROAD), roadDir(0), extTileFlags(0), visitable(false),
+	blocked(false)
 {
 
 }
 
 bool TerrainTile::entrableTerrain(const TerrainTile * from /*= NULL*/) const
 {
-    return entrableTerrain(from ? from->terType != ETerrainType::WATER : true, from ? from->terType == ETerrainType::WATER : true);
+	return entrableTerrain(from ? from->terType != ETerrainType::WATER : true, from ? from->terType == ETerrainType::WATER : true);
 }
 
 bool TerrainTile::entrableTerrain(bool allowLand, bool allowSea) const
 {
-    return terType != ETerrainType::ROCK
-        && ((allowSea && terType == ETerrainType::WATER)  ||  (allowLand && terType != ETerrainType::WATER));
+	return terType != ETerrainType::ROCK
+		&& ((allowSea && terType == ETerrainType::WATER)  ||  (allowLand && terType != ETerrainType::WATER));
 }
 
 bool TerrainTile::isClear(const TerrainTile *from /*= NULL*/) const
 {
-    return entrableTerrain(from) && !blocked;
+	return entrableTerrain(from) && !blocked;
 }
 
 int TerrainTile::topVisitableId() const
 {
-    return visitableObjects.size() ? visitableObjects.back()->ID : -1;
+	return visitableObjects.size() ? visitableObjects.back()->ID : -1;
 }
 
 bool TerrainTile::isCoastal() const
 {
-    return extTileFlags & 64;
+	return extTileFlags & 64;
 }
 
 bool TerrainTile::hasFavourableWinds() const
 {
-    return extTileFlags & 128;
+	return extTileFlags & 128;
 }
 
 bool TerrainTile::isWater() const
 {
-    return terType == ETerrainType::WATER;
+	return terType == ETerrainType::WATER;
 }
 
 CMapHeader::CMapHeader() : version(EMapFormat::INVALID), areAnyPlayers(false),
-    height(-1), width(-1), twoLevel(-1), difficulty(0), levelLimit(0),
-    howManyTeams(0)
+	height(-1), width(-1), twoLevel(-1), difficulty(0), levelLimit(0),
+	howManyTeams(0)
 {
 
 }
@@ -145,136 +145,136 @@ CMap::CMap() : checksum(0), terrain(nullptr), grailRadious(0)
 
 CMap::~CMap()
 {
-    if(terrain)
-    {
-        for(int ii=0;ii<width;ii++)
-        {
-            for(int jj=0;jj<height;jj++)
-                delete [] terrain[ii][jj];
-            delete [] terrain[ii];
-        }
-        delete [] terrain;
-    }
+	if(terrain)
+	{
+		for(int ii=0;ii<width;ii++)
+		{
+			for(int jj=0;jj<height;jj++)
+				delete [] terrain[ii][jj];
+			delete [] terrain[ii];
+		}
+		delete [] terrain;
+	}
 
-    for(std::list<ConstTransitivePtr<CMapEvent> >::iterator i = events.begin(); i != events.end(); i++)
-    {
-        i->dellNull();
-    }
+	for(std::list<ConstTransitivePtr<CMapEvent> >::iterator i = events.begin(); i != events.end(); i++)
+	{
+		i->dellNull();
+	}
 }
 
 void CMap::removeBlockVisTiles(CGObjectInstance * obj, bool total)
 {
-    for(int fx=0; fx<8; ++fx)
-    {
-        for(int fy=0; fy<6; ++fy)
-        {
-            int xVal = obj->pos.x + fx - 7;
-            int yVal = obj->pos.y + fy - 5;
-            int zVal = obj->pos.z;
-            if(xVal>=0 && xVal<width && yVal>=0 && yVal<height)
-            {
-                TerrainTile & curt = terrain[xVal][yVal][zVal];
-                if(total || ((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1))
-                {
-                    curt.visitableObjects -= obj;
-                    curt.visitable = curt.visitableObjects.size();
-                }
-                if(total || !((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
-                {
-                    curt.blockingObjects -= obj;
-                    curt.blocked = curt.blockingObjects.size();
-                }
-            }
-        }
-    }
+	for(int fx=0; fx<8; ++fx)
+	{
+		for(int fy=0; fy<6; ++fy)
+		{
+			int xVal = obj->pos.x + fx - 7;
+			int yVal = obj->pos.y + fy - 5;
+			int zVal = obj->pos.z;
+			if(xVal>=0 && xVal<width && yVal>=0 && yVal<height)
+			{
+				TerrainTile & curt = terrain[xVal][yVal][zVal];
+				if(total || ((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1))
+				{
+					curt.visitableObjects -= obj;
+					curt.visitable = curt.visitableObjects.size();
+				}
+				if(total || !((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
+				{
+					curt.blockingObjects -= obj;
+					curt.blocked = curt.blockingObjects.size();
+				}
+			}
+		}
+	}
 }
 void CMap::addBlockVisTiles(CGObjectInstance * obj)
 {
-    for(int fx=0; fx<8; ++fx)
-    {
-        for(int fy=0; fy<6; ++fy)
-        {
-            int xVal = obj->pos.x + fx - 7;
-            int yVal = obj->pos.y + fy - 5;
-            int zVal = obj->pos.z;
-            if(xVal>=0 && xVal<width && yVal>=0 && yVal<height)
-            {
-                TerrainTile & curt = terrain[xVal][yVal][zVal];
-                if(((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1))
-                {
-                    curt.visitableObjects.push_back(obj);
-                    curt.visitable = true;
-                }
-                if(!((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
-                {
-                    curt.blockingObjects.push_back(obj);
-                    curt.blocked = true;
-                }
-            }
-        }
-    }
+	for(int fx=0; fx<8; ++fx)
+	{
+		for(int fy=0; fy<6; ++fy)
+		{
+			int xVal = obj->pos.x + fx - 7;
+			int yVal = obj->pos.y + fy - 5;
+			int zVal = obj->pos.z;
+			if(xVal>=0 && xVal<width && yVal>=0 && yVal<height)
+			{
+				TerrainTile & curt = terrain[xVal][yVal][zVal];
+				if(((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1))
+				{
+					curt.visitableObjects.push_back(obj);
+					curt.visitable = true;
+				}
+				if(!((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
+				{
+					curt.blockingObjects.push_back(obj);
+					curt.blocked = true;
+				}
+			}
+		}
+	}
 }
 
 CGHeroInstance * CMap::getHero(int heroID)
 {
-    for(ui32 i=0; i<heroes.size();i++)
-        if(heroes[i]->subID == heroID)
-            return heroes[i];
-    return nullptr;
+	for(ui32 i=0; i<heroes.size();i++)
+		if(heroes[i]->subID == heroID)
+			return heroes[i];
+	return nullptr;
 }
 
 bool CMap::isInTheMap(const int3 &pos) const
 {
-    if(pos.x<0 || pos.y<0 || pos.z<0 || pos.x >= width || pos.y >= height || pos.z > twoLevel)
-        return false;
-    else return true;
+	if(pos.x<0 || pos.y<0 || pos.z<0 || pos.x >= width || pos.y >= height || pos.z > twoLevel)
+		return false;
+	else return true;
 }
 
 TerrainTile & CMap::getTile( const int3 & tile )
 {
-    return terrain[tile.x][tile.y][tile.z];
+	return terrain[tile.x][tile.y][tile.z];
 }
 
 const TerrainTile & CMap::getTile( const int3 & tile ) const
 {
-    return terrain[tile.x][tile.y][tile.z];
+	return terrain[tile.x][tile.y][tile.z];
 }
 
 bool CMap::isWaterTile(const int3 &pos) const
 {
-    return isInTheMap(pos) && getTile(pos).terType == ETerrainType::WATER;
+	return isInTheMap(pos) && getTile(pos).terType == ETerrainType::WATER;
 }
 
 const CGObjectInstance *CMap::getObjectiveObjectFrom(int3 pos, bool lookForHero)
 {
-    const std::vector <CGObjectInstance *> & objs = getTile(pos).visitableObjects;
-    assert(objs.size());
-    if(objs.size() > 1 && lookForHero && objs.front()->ID != Obj::HERO)
-    {
-        assert(objs.back()->ID == Obj::HERO);
-        return objs.back();
-    }
-    else
-        return objs.front();
+	const std::vector <CGObjectInstance *> & objs = getTile(pos).visitableObjects;
+	assert(objs.size());
+	if(objs.size() > 1 && lookForHero && objs.front()->ID != Obj::HERO)
+	{
+		assert(objs.back()->ID == Obj::HERO);
+		return objs.back();
+	}
+	else
+		return objs.front();
 }
 
 void CMap::checkForObjectives()
 {
-    if(isInTheMap(victoryCondition.pos))
-        victoryCondition.obj = getObjectiveObjectFrom(victoryCondition.pos, victoryCondition.condition == EVictoryConditionType::BEATHERO);
+	if(isInTheMap(victoryCondition.pos))
+		victoryCondition.obj = getObjectiveObjectFrom(victoryCondition.pos, victoryCondition.condition == EVictoryConditionType::BEATHERO);
 
-    if(isInTheMap(lossCondition.pos))
-        lossCondition.obj = getObjectiveObjectFrom(lossCondition.pos, lossCondition.typeOfLossCon == ELossConditionType::LOSSHERO);
+	if(isInTheMap(lossCondition.pos))
+		lossCondition.obj = getObjectiveObjectFrom(lossCondition.pos, lossCondition.typeOfLossCon == ELossConditionType::LOSSHERO);
 }
 
 void CMap::addNewArtifactInstance( CArtifactInstance *art )
 {
-    art->id = artInstances.size();
-    artInstances.push_back(art);
+	art->id = artInstances.size();
+	artInstances.push_back(art);
 }
 
 void CMap::eraseArtifactInstance(CArtifactInstance *art)
 {
-    assert(artInstances[art->id] == art);
-    artInstances[art->id].dellNull();
+	assert(artInstances[art->id] == art);
+	artInstances[art->id].dellNull();
 }

+ 698 - 698
lib/Map/CMap.h

@@ -38,37 +38,37 @@ class CInputStream;
  */
 struct DLL_LINKAGE SHeroName
 {
-    /**
-     * Default c-tor.
-     */
-    SHeroName();
-
-    /** the id of the hero */
-    int heroId;
-
-    /** the name of the hero */
-    std::string heroName;
-
-    /**
-     * Serialize method.
-     */
-    template <typename Handler>
-    void serialize(Handler & h, const int version)
-    {
-        h & heroId & heroName;
-    }
+	/**
+	 * Default c-tor.
+	 */
+	SHeroName();
+
+	/** the id of the hero */
+	int heroId;
+
+	/** the name of the hero */
+	std::string heroName;
+
+	/**
+	 * Serialize method.
+	 */
+	template <typename Handler>
+	void serialize(Handler & h, const int version)
+	{
+		h & heroId & heroName;
+	}
 };
 
 namespace EAiTactic
 {
-    enum EAiTactic
-    {
-        NONE = -1,
-        RANDOM,
-        WARRIOR,
-        BUILDER,
-        EXPLORER
-    };
+	enum EAiTactic
+	{
+		NONE = -1,
+		RANDOM,
+		WARRIOR,
+		BUILDER,
+		EXPLORER
+	};
 }
 
 /**
@@ -77,86 +77,86 @@ namespace EAiTactic
  */
 struct DLL_LINKAGE PlayerInfo
 {
-    /**
-     * Default constructor.
-     */
-    PlayerInfo();
+	/**
+	 * Default constructor.
+	 */
+	PlayerInfo();
 
-    /**
-     * Gets the default faction id or -1 for a random faction.
-     *
-     * @return the default faction id or -1 for a random faction
-     */
-    si8 defaultCastle() const;
+	/**
+	 * Gets the default faction id or -1 for a random faction.
+	 *
+	 * @return the default faction id or -1 for a random faction
+	 */
+	si8 defaultCastle() const;
 
-    /**
-     * Gets -1 for random hero.
-     *
-     * @return -1 for random hero
-     */
-    si8 defaultHero() const;
+	/**
+	 * Gets -1 for random hero.
+	 *
+	 * @return -1 for random hero
+	 */
+	si8 defaultHero() const;
 
-    /** unknown, unused */
-    si32 p7;
+	/** unknown, unused */
+	si32 p7;
 
-    /** TODO ? */
-    si32 p8;
+	/** TODO ? */
+	si32 p8;
 
-    /** TODO ? */
-    si32 p9;
+	/** TODO ? */
+	si32 p9;
 
-    /** TODO unused, q-ty of hero placeholders containing hero type, WARNING: powerPlaceholders sometimes gives false 0 (eg. even if there is one placeholder), maybe different meaning??? */
-    ui8 powerPlaceholders;
+	/** TODO unused, q-ty of hero placeholders containing hero type, WARNING: powerPlaceholders sometimes gives false 0 (eg. even if there is one placeholder), maybe different meaning??? */
+	ui8 powerPlaceholders;
 
-    /** true if player can be played by a human */
-    bool canHumanPlay;
+	/** true if player can be played by a human */
+	bool canHumanPlay;
 
-    /** true if player can be played by the computer */
-    bool canComputerPlay;
+	/** true if player can be played by the computer */
+	bool canComputerPlay;
 
-    /** defines the tactical setting of the AI */
-    EAiTactic::EAiTactic aiTactic;
+	/** defines the tactical setting of the AI */
+	EAiTactic::EAiTactic aiTactic;
 
-    /** IDs of allowed factions */
-    std::set<ui32> allowedFactions;
+	/** IDs of allowed factions */
+	std::set<ui32> allowedFactions;
 
-    /** unused. is the faction random */
-    bool isFactionRandom;
+	/** unused. is the faction random */
+	bool isFactionRandom;
 
-    /** specifies the ID of hero with chosen portrait; 255 if standard */
-    ui32 mainHeroPortrait;
+	/** specifies the ID of hero with chosen portrait; 255 if standard */
+	ui32 mainHeroPortrait;
 
-    /** the name of the main hero */
-    std::string mainHeroName;
+	/** the name of the main hero */
+	std::string mainHeroName;
 
-    /** list of available heroes */
-    std::vector<SHeroName> heroesNames;
+	/** list of available heroes */
+	std::vector<SHeroName> heroesNames;
 
-    /** true if the player has a main town */
-    bool hasMainTown;
+	/** true if the player has a main town */
+	bool hasMainTown;
 
-    /** true if the hero should be generated at the main town */
-    bool generateHeroAtMainTown;
+	/** true if the hero should be generated at the main town */
+	bool generateHeroAtMainTown;
 
-    /** the position of the main town */
-    int3 posOfMainTown;
+	/** the position of the main town */
+	int3 posOfMainTown;
 
-    /** the team id to which the player belongs to */
-    ui8 team;
+	/** the team id to which the player belongs to */
+	ui8 team;
 
-    /** unused. true if a hero should be generated */
-    bool generateHero;
+	/** unused. true if a hero should be generated */
+	bool generateHero;
 
-    /**
-     * Serialize method.
-     */
-    template <typename Handler>
-    void serialize(Handler & h, const int version)
-    {
-        h & p7 & p8 & p9 & canHumanPlay & canComputerPlay & aiTactic & allowedFactions & isFactionRandom &
-            mainHeroPortrait & mainHeroName & heroesNames & hasMainTown & generateHeroAtMainTown &
-            posOfMainTown & team & generateHero;
-    }
+	/**
+	 * Serialize method.
+	 */
+	template <typename Handler>
+	void serialize(Handler & h, const int version)
+	{
+		h & p7 & p8 & p9 & canHumanPlay & canComputerPlay & aiTactic & allowedFactions & isFactionRandom &
+			mainHeroPortrait & mainHeroName & heroesNames & hasMainTown & generateHeroAtMainTown &
+			posOfMainTown & team & generateHero;
+	}
 };
 
 /**
@@ -164,31 +164,31 @@ struct DLL_LINKAGE PlayerInfo
  */
 struct DLL_LINKAGE LossCondition
 {
-    /**
-     * Default constructor.
-     */
-    LossCondition();
-
-    /** specifies the condition type */
-    ELossConditionType::ELossConditionType typeOfLossCon;
-
-    /** the position of an object which mustn't be lost */
-    int3 pos;
-
-    /** time limit in days, -1 if not used */
-    si32 timeLimit;
-
-    /** set during map parsing: hero/town (depending on typeOfLossCon); nullptr if not used */
-    const CGObjectInstance * obj;
-
-    /**
-     * Serialize method.
-     */
-    template <typename Handler>
-    void serialize(Handler & h, const int version)
-    {
-        h & typeOfLossCon & pos & timeLimit & obj;
-    }
+	/**
+	 * Default constructor.
+	 */
+	LossCondition();
+
+	/** specifies the condition type */
+	ELossConditionType::ELossConditionType typeOfLossCon;
+
+	/** the position of an object which mustn't be lost */
+	int3 pos;
+
+	/** time limit in days, -1 if not used */
+	si32 timeLimit;
+
+	/** set during map parsing: hero/town (depending on typeOfLossCon); nullptr if not used */
+	const CGObjectInstance * obj;
+
+	/**
+	 * Serialize method.
+	 */
+	template <typename Handler>
+	void serialize(Handler & h, const int version)
+	{
+		h & typeOfLossCon & pos & timeLimit & obj;
+	}
 };
 
 /**
@@ -197,40 +197,40 @@ struct DLL_LINKAGE LossCondition
  */
 struct DLL_LINKAGE VictoryCondition
 {
-    /**
-     * Default constructor.
-     */
-    VictoryCondition();
+	/**
+	 * Default constructor.
+	 */
+	VictoryCondition();
 
-    /** specifies the condition type */
-    EVictoryConditionType::EVictoryConditionType condition;
+	/** specifies the condition type */
+	EVictoryConditionType::EVictoryConditionType condition;
 
-    /** true if a normal victory is allowed (defeat all enemy towns, heroes) */
-    bool allowNormalVictory;
+	/** true if a normal victory is allowed (defeat all enemy towns, heroes) */
+	bool allowNormalVictory;
 
-    /** true if this victory condition also applies to the AI */
-    bool appliesToAI;
+	/** true if this victory condition also applies to the AI */
+	bool appliesToAI;
 
-    /** pos of city to upgrade (3); pos of town to build grail, {-1,-1,-1} if not relevant (4); hero pos (5); town pos(6); monster pos (7); destination pos(8) */
-    int3 pos;
+	/** pos of city to upgrade (3); pos of town to build grail, {-1,-1,-1} if not relevant (4); hero pos (5); town pos(6); monster pos (7); destination pos(8) */
+	int3 pos;
 
-    /** artifact ID (0); monster ID (1); resource ID (2); needed fort level in upgraded town (3); artifact ID (8) */
-    si32 objectId;
+	/** artifact ID (0); monster ID (1); resource ID (2); needed fort level in upgraded town (3); artifact ID (8) */
+	si32 objectId;
 
-    /** needed count for creatures (1) / resource (2); upgraded town hall level (3);  */
-    si32 count;
+	/** needed count for creatures (1) / resource (2); upgraded town hall level (3);  */
+	si32 count;
 
-    /** object of specific monster / city / hero instance (NULL if not used); set during map parsing */
-    const CGObjectInstance * obj;
+	/** object of specific monster / city / hero instance (NULL if not used); set during map parsing */
+	const CGObjectInstance * obj;
 
-    /**
-     * Serialize method.
-     */
-    template <typename Handler>
-    void serialize(Handler & h, const int version)
-    {
-        h & condition & allowNormalVictory & appliesToAI & pos & objectId & count & obj;
-    }
+	/**
+	 * Serialize method.
+	 */
+	template <typename Handler>
+	void serialize(Handler & h, const int version)
+	{
+		h & condition & allowNormalVictory & appliesToAI & pos & objectId & count & obj;
+	}
 };
 
 /**
@@ -238,20 +238,20 @@ struct DLL_LINKAGE VictoryCondition
  */
 struct DLL_LINKAGE Rumor
 {
-    /** the name of the rumor */
-    std::string name;
-
-    /** the content of the rumor */
-    std::string text;
-
-    /**
-     * Serialize method.
-     */
-    template <typename Handler>
-    void serialize(Handler & h, const int version)
-    {
-        h & name & text;
-    }
+	/** the name of the rumor */
+	std::string name;
+
+	/** the content of the rumor */
+	std::string text;
+
+	/**
+	 * Serialize method.
+	 */
+	template <typename Handler>
+	void serialize(Handler & h, const int version)
+	{
+		h & name & text;
+	}
 };
 
 /**
@@ -259,31 +259,31 @@ struct DLL_LINKAGE Rumor
  */
 struct DLL_LINKAGE DisposedHero
 {
-    /**
-     * Default c-tor.
-     */
-    DisposedHero();
-
-    /** the id of the hero */
-    ui32 heroId;
-
-    /** the portrait id of the hero, 0xFF is default */
-    ui16 portrait;
-
-    /** the name of the hero */
-    std::string name;
-
-    /** who can hire this hero (bitfield) */
-    ui8 players;
-
-    /**
-     * Serialize method.
-     */
-    template <typename Handler>
-    void serialize(Handler & h, const int version)
-    {
-        h & heroId & portrait & name & players;
-    }
+	/**
+	 * Default c-tor.
+	 */
+	DisposedHero();
+
+	/** the id of the hero */
+	ui32 heroId;
+
+	/** the portrait id of the hero, 0xFF is default */
+	ui16 portrait;
+
+	/** the name of the hero */
+	std::string name;
+
+	/** who can hire this hero (bitfield) */
+	ui8 players;
+
+	/**
+	 * Serialize method.
+	 */
+	template <typename Handler>
+	void serialize(Handler & h, const int version)
+	{
+		h & heroId & portrait & name & players;
+	}
 };
 
 /// Class which manages map events.
@@ -295,60 +295,60 @@ struct DLL_LINKAGE DisposedHero
 class DLL_LINKAGE CMapEvent
 {
 public:
-    /**
-     * Default c-tor.
-     */
-    CMapEvent();
-
-    /**
-     * Returns true if this map event occurs earlier than the other map event for the first time.
-     *
-     * @param other the other map event to compare with
-     * @return true if this event occurs earlier than the other map event, false if not
-     */
-    bool earlierThan(const CMapEvent & other) const;
-
-    /**
-     * Returns true if this map event occurs earlier than or at the same day than the other map event for the first time.
-     *
-     * @param other the other map event to compare with
-     * @return true if this event occurs earlier than or at the same day than the other map event, false if not
-     */
-    bool earlierThanOrEqual(const CMapEvent & other) const;
-
-    /** the name of the event */
-    std::string name;
-
-    /** the message to display */
-    std::string message;
-
-    /** gained or taken resources */
-    TResources resources;
-
-    /** affected players */
-    ui8 players;
-
-    /** affected humans */
-    ui8 humanAffected;
-
-    /** affacted computer players */
-    ui8 computerAffected;
-
-    /** the day counted continously when the event happens */
-    ui32 firstOccurence;
-
-    /** specifies after how many days the event will occur the next time; 0 if event occurs only one time */
-    ui32 nextOccurence;
-
-    /**
-     * Serialize method.
-     */
-    template <typename Handler>
-    void serialize(Handler & h, const int version)
-    {
-        h & name & message & resources
-            & players & humanAffected & computerAffected & firstOccurence & nextOccurence;
-    }
+	/**
+	 * Default c-tor.
+	 */
+	CMapEvent();
+
+	/**
+	 * Returns true if this map event occurs earlier than the other map event for the first time.
+	 *
+	 * @param other the other map event to compare with
+	 * @return true if this event occurs earlier than the other map event, false if not
+	 */
+	bool earlierThan(const CMapEvent & other) const;
+
+	/**
+	 * Returns true if this map event occurs earlier than or at the same day than the other map event for the first time.
+	 *
+	 * @param other the other map event to compare with
+	 * @return true if this event occurs earlier than or at the same day than the other map event, false if not
+	 */
+	bool earlierThanOrEqual(const CMapEvent & other) const;
+
+	/** the name of the event */
+	std::string name;
+
+	/** the message to display */
+	std::string message;
+
+	/** gained or taken resources */
+	TResources resources;
+
+	/** affected players */
+	ui8 players;
+
+	/** affected humans */
+	ui8 humanAffected;
+
+	/** affacted computer players */
+	ui8 computerAffected;
+
+	/** the day counted continously when the event happens */
+	ui32 firstOccurence;
+
+	/** specifies after how many days the event will occur the next time; 0 if event occurs only one time */
+	ui32 nextOccurence;
+
+	/**
+	 * Serialize method.
+	 */
+	template <typename Handler>
+	void serialize(Handler & h, const int version)
+	{
+		h & name & message & resources
+			& players & humanAffected & computerAffected & firstOccurence & nextOccurence;
+	}
 };
 
 /**
@@ -357,54 +357,54 @@ public:
 class DLL_LINKAGE CCastleEvent: public CMapEvent
 {
 public:
-    /**
-     * Default c-tor.
-     */
-    CCastleEvent();
-
-    /** build specific buildings */
-    std::set<si32> buildings;
-
-    /** additional creatures in i-th level dwelling */
-    std::vector<si32> creatures;
-
-    /** owner of this event */
-    CGTownInstance * town;
-
-    /**
-     * Serialize method.
-     */
-    template <typename Handler>
-    void serialize(Handler & h, const int version)
-    {
-        h & static_cast<CMapEvent &>(*this);
-        h & buildings & creatures;
-    }
+	/**
+	 * Default c-tor.
+	 */
+	CCastleEvent();
+
+	/** build specific buildings */
+	std::set<si32> buildings;
+
+	/** additional creatures in i-th level dwelling */
+	std::vector<si32> creatures;
+
+	/** owner of this event */
+	CGTownInstance * town;
+
+	/**
+	 * Serialize method.
+	 */
+	template <typename Handler>
+	void serialize(Handler & h, const int version)
+	{
+		h & static_cast<CMapEvent &>(*this);
+		h & buildings & creatures;
+	}
 };
 
 namespace ETerrainType
 {
-    enum ETerrainType
-    {
-        BORDER = -1, DIRT, SAND, GRASS, SNOW, SWAMP,
-        ROUGH, SUBTERRANEAN, LAVA, WATER, ROCK
-    };
+	enum ETerrainType
+	{
+		BORDER = -1, DIRT, SAND, GRASS, SNOW, SWAMP,
+		ROUGH, SUBTERRANEAN, LAVA, WATER, ROCK
+	};
 }
 
 namespace ERiverType
 {
-    enum ERiverType
-    {
-        NO_RIVER, CLEAR_RIVER, ICY_RIVER, MUDDY_RIVER, LAVA_RIVER
-    };
+	enum ERiverType
+	{
+		NO_RIVER, CLEAR_RIVER, ICY_RIVER, MUDDY_RIVER, LAVA_RIVER
+	};
 }
 
 namespace ERoadType
 {
-    enum ERoadType
-    {
-        NO_ROAD, DIRT_ROAD, GRAVEL_ROAD, COBBLESTONE_ROAD
-    };
+	enum ERoadType
+	{
+		NO_ROAD, DIRT_ROAD, GRAVEL_ROAD, COBBLESTONE_ROAD
+	};
 }
 
 /**
@@ -413,122 +413,122 @@ namespace ERoadType
  */
 struct DLL_LINKAGE TerrainTile
 {
-    /**
-     * Default c-tor.
-     */
-    TerrainTile();
-
-    /**
-     * Gets true if the terrain is not a rock. If from is water/land, same type is also required.
-     *
-     * @param from
-     * @return
-     */
-    bool entrableTerrain(const TerrainTile * from = NULL) const;
-
-    /**
-     * Gets true if the terrain is not a rock. If from is water/land, same type is also required.
-     *
-     * @param allowLand
-     * @param allowSea
-     * @return
-     */
-    bool entrableTerrain(bool allowLand, bool allowSea) const;
-
-    /**
-     * Checks for blocking objects and terraint type (water / land).
-     *
-     * @param from
-     * @return
-     */
-    bool isClear(const TerrainTile * from = NULL) const;
-
-    /**
-     * Gets the ID of the top visitable object or -1 if there is none.
-     *
-     * @return the ID of the top visitable object or -1 if there is none
-     */
-    int topVisitableId() const;
-
-    /**
-     * Gets true if the terrain type is water.
-     *
-     * @return true if the terrain type is water
-     */
-    bool isWater() const;
-
-    /**
-     * Gets true if the terrain tile is coastal.
-     *
-     * @return true if the terrain tile is coastal
-     */
-    bool isCoastal() const;
-
-    /**
-     * Gets true if the terrain tile has favourable winds.
-     *
-     * @return true if the terrain tile has favourable winds
-     */
-    bool hasFavourableWinds() const;
-
-    /** the type of terrain */
-    ETerrainType::ETerrainType terType;
-
-    /** the visual representation of the terrain */
-    ui8 terView;
-
-    /** the type of the river. 0 if there is no river */
-    ERiverType::ERiverType riverType;
-
-    /** the direction of the river */
-    ui8 riverDir;
-
-    /** the type of the road. 0 if there is no river */
-    ERoadType::ERoadType roadType;
-
-    /** the direction of the road */
-    ui8 roadDir;
-
-    /**
-     * first two bits - how to rotate terrain graphic (next two - river graphic, next two - road);
-     * 7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favourable Winds effect
-     */
-    ui8 extTileFlags;
-
-    /** true if it is visitable, false if not */
-    bool visitable;
-
-    /** true if it is blocked, false if not */
-    bool blocked;
-
-    /** pointers to objects which the hero can visit while being on this tile */
-    std::vector<CGObjectInstance *> visitableObjects;
-
-    /** pointers to objects that are blocking this tile */
-    std::vector<CGObjectInstance *> blockingObjects;
-
-    /**
-     * Serialize method.
-     */
-    template <typename Handler>
-    void serialize(Handler & h, const int version)
-    {
-        h & terType & terView & riverType & riverDir & roadType &roadDir & extTileFlags & blocked;
-
-        if(!h.saving)
-        {
-            visitable = false;
-            //these flags (and obj vectors) will be restored in map serialization
-        }
-    }
+	/**
+	 * Default c-tor.
+	 */
+	TerrainTile();
+
+	/**
+	 * Gets true if the terrain is not a rock. If from is water/land, same type is also required.
+	 *
+	 * @param from
+	 * @return
+	 */
+	bool entrableTerrain(const TerrainTile * from = NULL) const;
+
+	/**
+	 * Gets true if the terrain is not a rock. If from is water/land, same type is also required.
+	 *
+	 * @param allowLand
+	 * @param allowSea
+	 * @return
+	 */
+	bool entrableTerrain(bool allowLand, bool allowSea) const;
+
+	/**
+	 * Checks for blocking objects and terraint type (water / land).
+	 *
+	 * @param from
+	 * @return
+	 */
+	bool isClear(const TerrainTile * from = NULL) const;
+
+	/**
+	 * Gets the ID of the top visitable object or -1 if there is none.
+	 *
+	 * @return the ID of the top visitable object or -1 if there is none
+	 */
+	int topVisitableId() const;
+
+	/**
+	 * Gets true if the terrain type is water.
+	 *
+	 * @return true if the terrain type is water
+	 */
+	bool isWater() const;
+
+	/**
+	 * Gets true if the terrain tile is coastal.
+	 *
+	 * @return true if the terrain tile is coastal
+	 */
+	bool isCoastal() const;
+
+	/**
+	 * Gets true if the terrain tile has favourable winds.
+	 *
+	 * @return true if the terrain tile has favourable winds
+	 */
+	bool hasFavourableWinds() const;
+
+	/** the type of terrain */
+	ETerrainType::ETerrainType terType;
+
+	/** the visual representation of the terrain */
+	ui8 terView;
+
+	/** the type of the river. 0 if there is no river */
+	ERiverType::ERiverType riverType;
+
+	/** the direction of the river */
+	ui8 riverDir;
+
+	/** the type of the road. 0 if there is no river */
+	ERoadType::ERoadType roadType;
+
+	/** the direction of the road */
+	ui8 roadDir;
+
+	/**
+	 * first two bits - how to rotate terrain graphic (next two - river graphic, next two - road);
+	 * 7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favourable Winds effect
+	 */
+	ui8 extTileFlags;
+
+	/** true if it is visitable, false if not */
+	bool visitable;
+
+	/** true if it is blocked, false if not */
+	bool blocked;
+
+	/** pointers to objects which the hero can visit while being on this tile */
+	std::vector<CGObjectInstance *> visitableObjects;
+
+	/** pointers to objects that are blocking this tile */
+	std::vector<CGObjectInstance *> blockingObjects;
+
+	/**
+	 * Serialize method.
+	 */
+	template <typename Handler>
+	void serialize(Handler & h, const int version)
+	{
+		h & terType & terView & riverType & riverDir & roadType &roadDir & extTileFlags & blocked;
+
+		if(!h.saving)
+		{
+			visitable = false;
+			//these flags (and obj vectors) will be restored in map serialization
+		}
+	}
 };
 
 namespace EMapFormat
 {
-    enum EMapFormat
-    {
-        INVALID, WOG=0x33, AB=0x15, ROE=0x0e, SOD=0x1c
-    };
+	enum EMapFormat
+	{
+		INVALID, WOG=0x33, AB=0x15, ROE=0x0e, SOD=0x1c
+	};
 }
 
 /**
@@ -538,70 +538,70 @@ namespace EMapFormat
 class DLL_LINKAGE CMapHeader
 {
 public:
-    /**
-     * Default constructor.
-     */
-    CMapHeader();
+	/**
+	 * Default constructor.
+	 */
+	CMapHeader();
 
-    /**
-     * D-tor.
-     */
-    virtual ~CMapHeader();
+	/**
+	 * D-tor.
+	 */
+	virtual ~CMapHeader();
 
-    /** the version of the map */
-    EMapFormat::EMapFormat version;
+	/** the version of the map */
+	EMapFormat::EMapFormat version;
 
-    /** unused. if there are any playable players on the map */
-    bool areAnyPlayers;
+	/** unused. if there are any playable players on the map */
+	bool areAnyPlayers;
 
-    /** the height of the map */
-    si32 height;
+	/** the height of the map */
+	si32 height;
 
-    /** the width of the map */
-    si32 width;
+	/** the width of the map */
+	si32 width;
 
-    /** specifies if the map has two levels */
-    si32 twoLevel;
+	/** specifies if the map has two levels */
+	si32 twoLevel;
 
-    /** the name of the map */
-    std::string name;
+	/** the name of the map */
+	std::string name;
 
-    /** the description of the map */
-    std::string description;
+	/** the description of the map */
+	std::string description;
 
-    /** specifies the difficulty of the map ranging from 0 easy to 4 impossible */
-    ui8 difficulty;
+	/** specifies the difficulty of the map ranging from 0 easy to 4 impossible */
+	ui8 difficulty;
 
-    /** specifies the maximum level to reach for a hero */
-    ui8 levelLimit;
+	/** specifies the maximum level to reach for a hero */
+	ui8 levelLimit;
 
-    /** the loss condition */
-    LossCondition lossCondition;
+	/** the loss condition */
+	LossCondition lossCondition;
 
-    /** the victory condition */
-    VictoryCondition victoryCondition;
+	/** the victory condition */
+	VictoryCondition victoryCondition;
 
-    /** list of player information */
-    std::vector<PlayerInfo> players;
+	/** list of player information */
+	std::vector<PlayerInfo> players;
 
-    /** number of teams */
-    ui8 howManyTeams;
+	/** number of teams */
+	ui8 howManyTeams;
 
-    /** list of allowed heroes, index is hero id */
-    std::vector<ui8> allowedHeroes;
+	/** list of allowed heroes, index is hero id */
+	std::vector<ui8> allowedHeroes;
 
-    /** list of placeholded heroes, index is id of heroes types */
-    std::vector<ui16> placeholdedHeroes;
+	/** list of placeholded heroes, index is id of heroes types */
+	std::vector<ui16> placeholdedHeroes;
 
-    /**
-     * Serialize method.
-     */
-    template <typename Handler>
-    void serialize(Handler & h, const int Version)
-    {
-        h & version & name & description & width & height & twoLevel & difficulty & levelLimit & areAnyPlayers;
-        h & players & lossCondition & victoryCondition & howManyTeams & allowedHeroes;
-    }
+	/**
+	 * Serialize method.
+	 */
+	template <typename Handler>
+	void serialize(Handler & h, const int Version)
+	{
+		h & version & name & description & width & height & twoLevel & difficulty & levelLimit & areAnyPlayers;
+		h & players & lossCondition & victoryCondition & howManyTeams & allowedHeroes;
+	}
 };
 
 /**
@@ -611,276 +611,276 @@ public:
 class DLL_LINKAGE CMap : public CMapHeader
 {
 public:
-    /**
-     * Default constructor.
-     */
-    CMap();
-
-    /**
-     * Destructor.
-     */
-    ~CMap();
-
-    /**
-     * Erases an artifact instance.
-     *
-     * @param art the artifact to erase
-     */
-    void eraseArtifactInstance(CArtifactInstance * art);
-
-    /**
-     * Gets the topmost object or the lowermost object depending on the flag
-     * lookForHero from the specified position.
-     *
-     * @param pos the position of the tile
-     * @param lookForHero true if you want to get the lowermost object, false if
-     *        you want to get the topmost object
-     * @return the object at the given position and level
-     */
-    const CGObjectInstance * getObjectiveObjectFrom(int3 pos, bool lookForHero);
-
-    /**
-     * Sets the victory/loss condition objectives.
-     */
-    void checkForObjectives();
-
-    /**
-     * Adds an visitable/blocking object to a terrain tile.
-     *
-     * @param obj the visitable/blocking object to add to a tile
-     */
-    void addBlockVisTiles(CGObjectInstance * obj);
-
-    /**
-     * Removes an visitable/blocking object from a terrain tile.
-     *
-     * @param obj the visitable/blocking object to remove from a tile
-     * @param total
-     */
-    void removeBlockVisTiles(CGObjectInstance * obj, bool total = false);
-
-    /**
-     * Gets the terrain tile of the specified position.
-     *
-     * @param tile the position of the tile
-     * @return the terrain tile of the specified position
-     */
-    TerrainTile & getTile(const int3 & tile);
-
-    /**
-     * Gets the terrain tile as a const of the specified position.
-     *
-     * @param tile the position of the tile
-     * @return the terrain tile as a const of the specified position
-     */
-    const TerrainTile & getTile(const int3 & tile) const;
-
-    /**
-     * Gets the hero with the given id.
-     * @param heroId the hero id
-     * @return the hero with the given id
-     */
-    CGHeroInstance * getHero(int heroId);
-
-    /**
-     * Validates if the position is in the bounds of the map.
-     *
-     * @param pos the position to test
-     * @return true if the position is in the bounds of the map
-     */
-    bool isInTheMap(const int3 & pos) const;
-
-    /**
-     * Validates if the tile at the given position is a water terrain type.
-     *
-     * @param pos the position to test
-     * @return true if the tile at the given position is a water terrain type
-     */
-    bool isWaterTile(const int3 & pos) const;
-
-    /**
-     * Adds the specified artifact instance to the list of artifacts of this map.
-     *
-     * @param art the artifact which should be added to the list of artifacts
-     */
-    void addNewArtifactInstance(CArtifactInstance * art);
-
-    /** the checksum of the map */
-    ui32 checksum;
-
-    /** a 3-dimensional array of terrain tiles, access is as follows: x, y, level */
-    TerrainTile*** terrain;
-
-    /** list of rumors */
-    std::vector<Rumor> rumors;
-
-    /** list of disposed heroes */
-    std::vector<DisposedHero> disposedHeroes;
-
-    /** list of predefined heroes */
-    std::vector<ConstTransitivePtr<CGHeroInstance> > predefinedHeroes;
-
-    /** list of .def files with definitions from .h3m (may be custom) */
-    std::vector<ConstTransitivePtr<CGDefInfo> > customDefs;
-
-    /** list of allowed spells, index is the spell id */
-    std::vector<ui8> allowedSpell;
-
-    /** list of allowed artifacts, index is the artifact id */
-    std::vector<ui8> allowedArtifact;
-
-    /** list of allowed abilities, index is the ability id */
-    std::vector<ui8> allowedAbilities;
-
-    /** list of map events */
-    std::list<ConstTransitivePtr<CMapEvent> > events;
-
-    /** specifies the position of the grail */
-    int3 grailPos;
-
-    /** specifies the radius of the grail */
-    int grailRadious;
-
-    /** list of objects */
-    std::vector< ConstTransitivePtr<CGObjectInstance> > objects;
-
-    /** list of heroes */
-    std::vector< ConstTransitivePtr<CGHeroInstance> > heroes;
-
-    /** list of towns */
-    std::vector< ConstTransitivePtr<CGTownInstance> > towns;
-
-    /** list of artifacts */
-    std::vector< ConstTransitivePtr<CArtifactInstance> > artInstances;
-
-    /** list of quests */
-    std::vector< ConstTransitivePtr<CQuest> > quests;
-
-    /** associative list to identify which hero/creature id belongs to which object id(index for objects) */
-    bmap<si32, si32> questIdentifierToId;
-
-    /**
-     * Serialize method.
-     */
-    template <typename Handler>
-    void serialize(Handler &h, const int formatVersion)
-    {
-        h & static_cast<CMapHeader&>(*this);
-        h & rumors & allowedSpell & allowedAbilities & allowedArtifact & events & grailPos;
-        h & artInstances & quests;
-        h & questIdentifierToId;
-
-        //TODO: viccondetails
-        if(h.saving)
-        {
-            // Save terrain
-            for(int i = 0; i < width ; ++i)
-            {
-                for(int j = 0; j < height ; ++j)
-                {
-                    for(int k = 0; k <= twoLevel; ++k)
-                    {
-                        h & terrain[i][j][k];
-                    }
-                }
-            }
-        }
-        else
-        {
-            // Load terrain
-            terrain = new TerrainTile**[width];
-            for(int ii = 0; ii < width; ++ii)
-            {
-                terrain[ii] = new TerrainTile*[height];
-                for(int jj = 0; jj < height; ++jj)
-                {
-                    terrain[ii][jj] = new TerrainTile[twoLevel + 1];
-                }
-            }
-            for(int i = 0; i < width ; ++i)
-            {
-                for(int j = 0; j < height ; ++j)
-                {
-                    for(int k = 0; k <= twoLevel ; ++k)
-                    {
-                        h & terrain[i][j][k];
-                    }
-                }
-            }
-        }
-
-        h & customDefs & objects;
-
-        // static members
-        h & CGTeleport::objs;
-        h & CGTeleport::gates;
-        h & CGKeys::playerKeyMap;
-        h & CGMagi::eyelist;
-        h & CGObelisk::obeliskCount & CGObelisk::visited;
-        h & CGTownInstance::merchantArtifacts;
-
-        if(!h.saving)
-        {
-            for(ui32 i = 0; i < objects.size(); ++i)
-            {
-                if(!objects[i]) continue;
-
-                switch (objects[i]->ID)
-                {
-                    case Obj::HERO:
-                        heroes.push_back (static_cast<CGHeroInstance*>(+objects[i]));
-                        break;
-                    case Obj::TOWN:
-                        towns.push_back (static_cast<CGTownInstance*>(+objects[i]));
-                        break;
-                }
-
-                // recreate blockvis map
-                addBlockVisTiles(objects[i]);
-            }
-
-            // if hero is visiting/garrisoned in town set appropriate pointers
-            for(ui32 i = 0; i < heroes.size(); ++i)
-            {
-                int3 vistile = heroes[i]->pos;
-                vistile.x++;
-                for(ui32 j = 0; j < towns.size(); ++j)
-                {
-                    // hero stands on the town entrance
-                    if(vistile == towns[j]->pos)
-                    {
-                        if(heroes[i]->inTownGarrison)
-                        {
-                            towns[j]->garrisonHero = heroes[i];
-                            removeBlockVisTiles(heroes[i]);
-                        }
-                        else
-                        {
-                            towns[j]->visitingHero = heroes[i];
-                        }
-
-                        heroes[i]->visitedTown = towns[j];
-                        break;
-                    }
-                }
-
-                vistile.x -= 2; //manifest pos
-                const TerrainTile & t = getTile(vistile);
-                if(t.terType != ETerrainType::WATER) continue;
-
-                //hero stands on the water - he must be in the boat
-                for(ui32 j = 0; j < t.visitableObjects.size(); ++j)
-                {
-                    if(t.visitableObjects[j]->ID == Obj::BOAT)
-                    {
-                        CGBoat * b = static_cast<CGBoat *>(t.visitableObjects[j]);
-                        heroes[i]->boat = b;
-                        b->hero = heroes[i];
-                        removeBlockVisTiles(b);
-                        break;
-                    }
-                }
-            }
-        }
-    }
+	/**
+	 * Default constructor.
+	 */
+	CMap();
+
+	/**
+	 * Destructor.
+	 */
+	~CMap();
+
+	/**
+	 * Erases an artifact instance.
+	 *
+	 * @param art the artifact to erase
+	 */
+	void eraseArtifactInstance(CArtifactInstance * art);
+
+	/**
+	 * Gets the topmost object or the lowermost object depending on the flag
+	 * lookForHero from the specified position.
+	 *
+	 * @param pos the position of the tile
+	 * @param lookForHero true if you want to get the lowermost object, false if
+	 *        you want to get the topmost object
+	 * @return the object at the given position and level
+	 */
+	const CGObjectInstance * getObjectiveObjectFrom(int3 pos, bool lookForHero);
+
+	/**
+	 * Sets the victory/loss condition objectives.
+	 */
+	void checkForObjectives();
+
+	/**
+	 * Adds an visitable/blocking object to a terrain tile.
+	 *
+	 * @param obj the visitable/blocking object to add to a tile
+	 */
+	void addBlockVisTiles(CGObjectInstance * obj);
+
+	/**
+	 * Removes an visitable/blocking object from a terrain tile.
+	 *
+	 * @param obj the visitable/blocking object to remove from a tile
+	 * @param total
+	 */
+	void removeBlockVisTiles(CGObjectInstance * obj, bool total = false);
+
+	/**
+	 * Gets the terrain tile of the specified position.
+	 *
+	 * @param tile the position of the tile
+	 * @return the terrain tile of the specified position
+	 */
+	TerrainTile & getTile(const int3 & tile);
+
+	/**
+	 * Gets the terrain tile as a const of the specified position.
+	 *
+	 * @param tile the position of the tile
+	 * @return the terrain tile as a const of the specified position
+	 */
+	const TerrainTile & getTile(const int3 & tile) const;
+
+	/**
+	 * Gets the hero with the given id.
+	 * @param heroId the hero id
+	 * @return the hero with the given id
+	 */
+	CGHeroInstance * getHero(int heroId);
+
+	/**
+	 * Validates if the position is in the bounds of the map.
+	 *
+	 * @param pos the position to test
+	 * @return true if the position is in the bounds of the map
+	 */
+	bool isInTheMap(const int3 & pos) const;
+
+	/**
+	 * Validates if the tile at the given position is a water terrain type.
+	 *
+	 * @param pos the position to test
+	 * @return true if the tile at the given position is a water terrain type
+	 */
+	bool isWaterTile(const int3 & pos) const;
+
+	/**
+	 * Adds the specified artifact instance to the list of artifacts of this map.
+	 *
+	 * @param art the artifact which should be added to the list of artifacts
+	 */
+	void addNewArtifactInstance(CArtifactInstance * art);
+
+	/** the checksum of the map */
+	ui32 checksum;
+
+	/** a 3-dimensional array of terrain tiles, access is as follows: x, y, level */
+	TerrainTile*** terrain;
+
+	/** list of rumors */
+	std::vector<Rumor> rumors;
+
+	/** list of disposed heroes */
+	std::vector<DisposedHero> disposedHeroes;
+
+	/** list of predefined heroes */
+	std::vector<ConstTransitivePtr<CGHeroInstance> > predefinedHeroes;
+
+	/** list of .def files with definitions from .h3m (may be custom) */
+	std::vector<ConstTransitivePtr<CGDefInfo> > customDefs;
+
+	/** list of allowed spells, index is the spell id */
+	std::vector<ui8> allowedSpell;
+
+	/** list of allowed artifacts, index is the artifact id */
+	std::vector<ui8> allowedArtifact;
+
+	/** list of allowed abilities, index is the ability id */
+	std::vector<ui8> allowedAbilities;
+
+	/** list of map events */
+	std::list<ConstTransitivePtr<CMapEvent> > events;
+
+	/** specifies the position of the grail */
+	int3 grailPos;
+
+	/** specifies the radius of the grail */
+	int grailRadious;
+
+	/** list of objects */
+	std::vector< ConstTransitivePtr<CGObjectInstance> > objects;
+
+	/** list of heroes */
+	std::vector< ConstTransitivePtr<CGHeroInstance> > heroes;
+
+	/** list of towns */
+	std::vector< ConstTransitivePtr<CGTownInstance> > towns;
+
+	/** list of artifacts */
+	std::vector< ConstTransitivePtr<CArtifactInstance> > artInstances;
+
+	/** list of quests */
+	std::vector< ConstTransitivePtr<CQuest> > quests;
+
+	/** associative list to identify which hero/creature id belongs to which object id(index for objects) */
+	bmap<si32, si32> questIdentifierToId;
+
+	/**
+	 * Serialize method.
+	 */
+	template <typename Handler>
+	void serialize(Handler &h, const int formatVersion)
+	{
+		h & static_cast<CMapHeader&>(*this);
+		h & rumors & allowedSpell & allowedAbilities & allowedArtifact & events & grailPos;
+		h & artInstances & quests;
+		h & questIdentifierToId;
+
+		//TODO: viccondetails
+		if(h.saving)
+		{
+			// Save terrain
+			for(int i = 0; i < width ; ++i)
+			{
+				for(int j = 0; j < height ; ++j)
+				{
+					for(int k = 0; k <= twoLevel; ++k)
+					{
+						h & terrain[i][j][k];
+					}
+				}
+			}
+		}
+		else
+		{
+			// Load terrain
+			terrain = new TerrainTile**[width];
+			for(int ii = 0; ii < width; ++ii)
+			{
+				terrain[ii] = new TerrainTile*[height];
+				for(int jj = 0; jj < height; ++jj)
+				{
+					terrain[ii][jj] = new TerrainTile[twoLevel + 1];
+				}
+			}
+			for(int i = 0; i < width ; ++i)
+			{
+				for(int j = 0; j < height ; ++j)
+				{
+					for(int k = 0; k <= twoLevel ; ++k)
+					{
+						h & terrain[i][j][k];
+					}
+				}
+			}
+		}
+
+		h & customDefs & objects;
+
+		// static members
+		h & CGTeleport::objs;
+		h & CGTeleport::gates;
+		h & CGKeys::playerKeyMap;
+		h & CGMagi::eyelist;
+		h & CGObelisk::obeliskCount & CGObelisk::visited;
+		h & CGTownInstance::merchantArtifacts;
+
+		if(!h.saving)
+		{
+			for(ui32 i = 0; i < objects.size(); ++i)
+			{
+				if(!objects[i]) continue;
+
+				switch (objects[i]->ID)
+				{
+					case Obj::HERO:
+						heroes.push_back (static_cast<CGHeroInstance*>(+objects[i]));
+						break;
+					case Obj::TOWN:
+						towns.push_back (static_cast<CGTownInstance*>(+objects[i]));
+						break;
+				}
+
+				// recreate blockvis map
+				addBlockVisTiles(objects[i]);
+			}
+
+			// if hero is visiting/garrisoned in town set appropriate pointers
+			for(ui32 i = 0; i < heroes.size(); ++i)
+			{
+				int3 vistile = heroes[i]->pos;
+				vistile.x++;
+				for(ui32 j = 0; j < towns.size(); ++j)
+				{
+					// hero stands on the town entrance
+					if(vistile == towns[j]->pos)
+					{
+						if(heroes[i]->inTownGarrison)
+						{
+							towns[j]->garrisonHero = heroes[i];
+							removeBlockVisTiles(heroes[i]);
+						}
+						else
+						{
+							towns[j]->visitingHero = heroes[i];
+						}
+
+						heroes[i]->visitedTown = towns[j];
+						break;
+					}
+				}
+
+				vistile.x -= 2; //manifest pos
+				const TerrainTile & t = getTile(vistile);
+				if(t.terType != ETerrainType::WATER) continue;
+
+				//hero stands on the water - he must be in the boat
+				for(ui32 j = 0; j < t.visitableObjects.size(); ++j)
+				{
+					if(t.visitableObjects[j]->ID == Obj::BOAT)
+					{
+						CGBoat * b = static_cast<CGBoat *>(t.visitableObjects[j]);
+						heroes[i]->boat = b;
+						b->hero = heroes[i];
+						removeBlockVisTiles(b);
+						break;
+					}
+				}
+			}
+		}
+	}
 };

+ 23 - 23
lib/Map/CMapInfo.cpp

@@ -9,41 +9,41 @@
 
 void CMapInfo::countPlayers()
 {
-    actualHumanPlayers = playerAmnt = humanPlayers = 0;
-    for(int i=0;i<GameConstants::PLAYER_LIMIT;i++)
-    {
-        if(mapHeader->players[i].canHumanPlay)
-        {
-            playerAmnt++;
-            humanPlayers++;
-        }
-        else if(mapHeader->players[i].canComputerPlay)
-        {
-            playerAmnt++;
-        }
-    }
-
-    if(scenarioOpts)
-        for (auto i = scenarioOpts->playerInfos.cbegin(); i != scenarioOpts->playerInfos.cend(); i++)
-            if(i->second.human)
-                actualHumanPlayers++;
+	actualHumanPlayers = playerAmnt = humanPlayers = 0;
+	for(int i=0;i<GameConstants::PLAYER_LIMIT;i++)
+	{
+		if(mapHeader->players[i].canHumanPlay)
+		{
+			playerAmnt++;
+			humanPlayers++;
+		}
+		else if(mapHeader->players[i].canComputerPlay)
+		{
+			playerAmnt++;
+		}
+	}
+
+	if(scenarioOpts)
+		for (auto i = scenarioOpts->playerInfos.cbegin(); i != scenarioOpts->playerInfos.cend(); i++)
+			if(i->second.human)
+				actualHumanPlayers++;
 }
 
 CMapInfo::CMapInfo() :
-    scenarioOpts(nullptr)
+	scenarioOpts(nullptr)
 {
 
 }
 
 void CMapInfo::mapInit(const std::string & fname)
 {
-    fileURI = fname;
-    mapHeader = CMapService::loadMapHeader(fname);
-    countPlayers();
+	fileURI = fname;
+	mapHeader = CMapService::loadMapHeader(fname);
+	countPlayers();
 }
 
 void CMapInfo::campaignInit()
 {
-    campaignHeader = std::unique_ptr<CCampaignHeader>(new CCampaignHeader(CCampaignHandler::getHeader(fileURI)));
+	campaignHeader = std::unique_ptr<CCampaignHeader>(new CCampaignHeader(CCampaignHandler::getHeader(fileURI)));
 }
 

+ 17 - 17
lib/Map/CMapInfo.h

@@ -22,23 +22,23 @@ class DLL_LINKAGE CMapInfo
 public:
 	//FIXME: unique_ptr won't work here with gcc-4.5. (can't move into vector at CPregame.cpp, SelectionTab::parseMaps() method)
 	//Needs some workaround or wait till there is no need to support 4.5
-    shared_ptr<CMapHeader> mapHeader; //may be nullptr if campaign
-    shared_ptr<CCampaignHeader> campaignHeader; //may be nullptr if scenario
-    StartInfo * scenarioOpts; //options with which scenario has been started (used only with saved games)
-    std::string fileURI;
-    std::string date;
-    int playerAmnt; //players in map
-    int humanPlayers; //players ALLOWED to be controlled by human
-    int actualHumanPlayers; // >1 if multiplayer game
+	shared_ptr<CMapHeader> mapHeader; //may be nullptr if campaign
+	shared_ptr<CCampaignHeader> campaignHeader; //may be nullptr if scenario
+	StartInfo * scenarioOpts; //options with which scenario has been started (used only with saved games)
+	std::string fileURI;
+	std::string date;
+	int playerAmnt; //players in map
+	int humanPlayers; //players ALLOWED to be controlled by human
+	int actualHumanPlayers; // >1 if multiplayer game
 
-    CMapInfo();
-    void mapInit(const std::string & fname);
-    void campaignInit();
-    void countPlayers();
+	CMapInfo();
+	void mapInit(const std::string & fname);
+	void campaignInit();
+	void countPlayers();
 
-    template <typename Handler> void serialize(Handler &h, const int Version)
-    {
-        h & mapHeader & campaignHeader & scenarioOpts & fileURI & date & playerAmnt & humanPlayers;
-        h & actualHumanPlayers;
-    }
+	template <typename Handler> void serialize(Handler &h, const int Version)
+	{
+		h & mapHeader & campaignHeader & scenarioOpts & fileURI & date & playerAmnt & humanPlayers;
+		h & actualHumanPlayers;
+	}
 };

+ 2350 - 2350
lib/Map/CMapService.cpp

@@ -16,2530 +16,2530 @@
 
 std::unique_ptr<CMap> CMapService::loadMap(const std::string & name)
 {
-    auto stream = getStreamFromFS(name);
-    return getMapLoader(stream)->loadMap();
+	auto stream = getStreamFromFS(name);
+	return getMapLoader(stream)->loadMap();
 }
 
 std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const std::string & name)
 {
-    auto stream = getStreamFromFS(name);
-    return getMapLoader(stream)->loadMapHeader();
+	auto stream = getStreamFromFS(name);
+	return getMapLoader(stream)->loadMapHeader();
 }
 
 std::unique_ptr<CMap> CMapService::loadMap(const ui8 * buffer, int size)
 {
-    auto stream = getStreamFromMem(buffer, size);
-    return getMapLoader(stream)->loadMap();
+	auto stream = getStreamFromMem(buffer, size);
+	return getMapLoader(stream)->loadMap();
 }
 
 std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ui8 * buffer, int size)
 {
-    auto stream = getStreamFromMem(buffer, size);
-    return getMapLoader(stream)->loadMapHeader();
+	auto stream = getStreamFromMem(buffer, size);
+	return getMapLoader(stream)->loadMapHeader();
 }
 
 std::unique_ptr<CInputStream> CMapService::getStreamFromFS(const std::string & name)
 {
-    return CResourceHandler::get()->load(ResourceID(name, EResType::MAP));
+	return CResourceHandler::get()->load(ResourceID(name, EResType::MAP));
 }
 
 std::unique_ptr<CInputStream> CMapService::getStreamFromMem(const ui8 * buffer, int size)
 {
-    return std::unique_ptr<CInputStream>(new CMemoryStream(buffer, size));
+	return std::unique_ptr<CInputStream>(new CMemoryStream(buffer, size));
 }
 
 std::unique_ptr<IMapLoader> CMapService::getMapLoader(std::unique_ptr<CInputStream> & stream)
 {
-    // Read map header
-    CBinaryReader reader(stream.get());
-    ui32 header = reader.readUInt32();
-    reader.getStream()->seek(0);
-
-    // Check which map format is used
-    // gzip header is 3 bytes only in size
-    switch(header & 0xffffff)
-    {
-        // gzip header magic number, reversed for LE
-        case 0x00088B1F:
-            stream = std::unique_ptr<CInputStream>(new CCompressedStream(std::move(stream), true));
-            return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
-        case EMapFormat::WOG :
-        case EMapFormat::AB  :
-        case EMapFormat::ROE :
-        case EMapFormat::SOD :
-            return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
-        default :
-            throw std::runtime_error("Unknown map format");
-    }
+	// Read map header
+	CBinaryReader reader(stream.get());
+	ui32 header = reader.readUInt32();
+	reader.getStream()->seek(0);
+
+	// Check which map format is used
+	// gzip header is 3 bytes only in size
+	switch(header & 0xffffff)
+	{
+		// gzip header magic number, reversed for LE
+		case 0x00088B1F:
+			stream = std::unique_ptr<CInputStream>(new CCompressedStream(std::move(stream), true));
+			return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
+		case EMapFormat::WOG :
+		case EMapFormat::AB  :
+		case EMapFormat::ROE :
+		case EMapFormat::SOD :
+			return std::unique_ptr<IMapLoader>(new CMapLoaderH3M(stream.get()));
+		default :
+			throw std::runtime_error("Unknown map format");
+	}
 }
 
 const bool CMapLoaderH3M::IS_PROFILING_ENABLED = false;
 
 CMapLoaderH3M::CMapLoaderH3M(CInputStream * stream) : map(nullptr), buffer(nullptr), pos(-1), size(-1)
 {
-    initBuffer(stream);
+	initBuffer(stream);
 }
 
 CMapLoaderH3M::~CMapLoaderH3M()
 {
-    delete buffer;
+	delete buffer;
 }
 
 void CMapLoaderH3M::initBuffer(CInputStream * stream)
 {
-    // Read map data into memory completely
-    // TODO Replace with CBinaryReader later... (no need for reading whole
-    // file in memory at once, storing pos & size separately...)
-    stream->seek(0);
-    size = stream->getSize();
-    buffer = new ui8[size];
-    stream->read(buffer, size);
+	// Read map data into memory completely
+	// TODO Replace with CBinaryReader later... (no need for reading whole
+	// file in memory at once, storing pos & size separately...)
+	stream->seek(0);
+	size = stream->getSize();
+	buffer = new ui8[size];
+	stream->read(buffer, size);
 }
 
 std::unique_ptr<CMap> CMapLoaderH3M::loadMap()
 {
-    // Init map object by parsing the input buffer
-    map = new CMap;
-    mapHeader = std::unique_ptr<CMapHeader>(dynamic_cast<CMapHeader *>(map));
-    init();
+	// Init map object by parsing the input buffer
+	map = new CMap;
+	mapHeader = std::unique_ptr<CMapHeader>(dynamic_cast<CMapHeader *>(map));
+	init();
 
-    return std::unique_ptr<CMap>(dynamic_cast<CMap *>(mapHeader.release()));;
+	return std::unique_ptr<CMap>(dynamic_cast<CMap *>(mapHeader.release()));;
 }
 
 std::unique_ptr<CMapHeader> CMapLoaderH3M::loadMapHeader()
 {
-    // Read header
-    mapHeader = std::unique_ptr<CMapHeader>(new CMapHeader);
-    readHeader();
+	// Read header
+	mapHeader = std::unique_ptr<CMapHeader>(new CMapHeader);
+	readHeader();
 
-    return std::move(mapHeader);
+	return std::move(mapHeader);
 }
 
 void CMapLoaderH3M::init()
 {
-    // Compute checksum
-    boost::crc_32_type  result;
-    result.process_bytes(buffer, size);
-    map->checksum = result.checksum();
+	// Compute checksum
+	boost::crc_32_type  result;
+	result.process_bytes(buffer, size);
+	map->checksum = result.checksum();
 
-    CStopWatch sw;
+	CStopWatch sw;
 
-    struct MapLoadingTime
-    {
-        std::string name;
-        si64 time;
+	struct MapLoadingTime
+	{
+		std::string name;
+		si64 time;
 
-        MapLoadingTime(std::string name, si64 time) : name(name),
-            time(time)
-        {
+		MapLoadingTime(std::string name, si64 time) : name(name),
+			time(time)
+		{
 
-        }
-    };
-    std::vector<MapLoadingTime> times;
+		}
+	};
+	std::vector<MapLoadingTime> times;
 
-    readHeader();
-    times.push_back(MapLoadingTime("header", sw.getDiff()));
+	readHeader();
+	times.push_back(MapLoadingTime("header", sw.getDiff()));
 
-    readDisposedHeroes();
-    times.push_back(MapLoadingTime("disposed heroes", sw.getDiff()));
+	readDisposedHeroes();
+	times.push_back(MapLoadingTime("disposed heroes", sw.getDiff()));
 
-    readAllowedArtifacts();
-    times.push_back(MapLoadingTime("allowed artifacts", sw.getDiff()));
+	readAllowedArtifacts();
+	times.push_back(MapLoadingTime("allowed artifacts", sw.getDiff()));
 
-    readAllowedSpellsAbilities();
-    times.push_back(MapLoadingTime("allowed spells and abilities", sw.getDiff()));
+	readAllowedSpellsAbilities();
+	times.push_back(MapLoadingTime("allowed spells and abilities", sw.getDiff()));
 
-    readRumors();
-    times.push_back(MapLoadingTime("rumors", sw.getDiff()));
+	readRumors();
+	times.push_back(MapLoadingTime("rumors", sw.getDiff()));
 
-    readPredefinedHeroes();
-    times.push_back(MapLoadingTime("predefined heroes", sw.getDiff()));
+	readPredefinedHeroes();
+	times.push_back(MapLoadingTime("predefined heroes", sw.getDiff()));
 
-    readTerrain();
-    times.push_back(MapLoadingTime("terrain", sw.getDiff()));
+	readTerrain();
+	times.push_back(MapLoadingTime("terrain", sw.getDiff()));
 
-    readDefInfo();
-    times.push_back(MapLoadingTime("def info", sw.getDiff()));
+	readDefInfo();
+	times.push_back(MapLoadingTime("def info", sw.getDiff()));
 
-    readObjects();
-    times.push_back(MapLoadingTime("objects", sw.getDiff()));
+	readObjects();
+	times.push_back(MapLoadingTime("objects", sw.getDiff()));
 
-    readEvents();
-    times.push_back(MapLoadingTime("events", sw.getDiff()));
+	readEvents();
+	times.push_back(MapLoadingTime("events", sw.getDiff()));
 
-    // Calculate blocked / visitable positions
-    for(int f = 0; f < map->objects.size(); ++f)
-    {
-        if(!map->objects[f]->defInfo) continue;
-        addBlockVisibleTiles(map->objects[f]);
-    }
-    times.push_back(MapLoadingTime("blocked/visitable tiles", sw.getDiff()));
+	// Calculate blocked / visitable positions
+	for(int f = 0; f < map->objects.size(); ++f)
+	{
+		if(!map->objects[f]->defInfo) continue;
+		addBlockVisibleTiles(map->objects[f]);
+	}
+	times.push_back(MapLoadingTime("blocked/visitable tiles", sw.getDiff()));
 
-    // Print profiling times
-    if(IS_PROFILING_ENABLED)
-    {
-        BOOST_FOREACH(MapLoadingTime & mlt, times)
-        {
-            tlog0 << "\tReading " << mlt.name << " took " << mlt.time << " ms." << std::endl;
-        }
-    }
+	// Print profiling times
+	if(IS_PROFILING_ENABLED)
+	{
+		BOOST_FOREACH(MapLoadingTime & mlt, times)
+		{
+			tlog0 << "\tReading " << mlt.name << " took " << mlt.time << " ms." << std::endl;
+		}
+	}
 }
 
 void CMapLoaderH3M::readHeader()
 {
-    pos = 0;
-
-    // Check map for validity
-    if(size < 50  || !buffer[4])
-    {
-        throw std::runtime_error("Corrupted map file.");
-    }
-
-    // Map version
-    mapHeader->version = (EMapFormat::EMapFormat)(read_le_u32(buffer + pos));
-    pos += 4;
-    if(mapHeader->version != EMapFormat::ROE && mapHeader->version != EMapFormat::AB && mapHeader->version != EMapFormat::SOD
-            && mapHeader->version != EMapFormat::WOG)
-    {
-        throw std::runtime_error("Invalid map format!");
-    }
-
-    // Read map name, description, dimensions,...
-    mapHeader->areAnyPlayers = static_cast<bool>(readChar(buffer, pos));
-    mapHeader->height = mapHeader->width = (read_le_u32(buffer + pos));
-    pos += 4;
-    mapHeader->twoLevel = readChar(buffer, pos);
-    mapHeader->name = readString(buffer, pos);
-    mapHeader->description = readString(buffer, pos);
-    mapHeader->difficulty = readChar(buffer, pos);
-    if(mapHeader->version != EMapFormat::ROE)
-    {
-        mapHeader->levelLimit = readChar(buffer, pos);
-    }
-    else
-    {
-        mapHeader->levelLimit = 0;
-    }
-
-    readPlayerInfo();
-    readVictoryLossConditions();
-    readTeamInfo();
-    readAllowedHeroes();
+	pos = 0;
+
+	// Check map for validity
+	if(size < 50  || !buffer[4])
+	{
+		throw std::runtime_error("Corrupted map file.");
+	}
+
+	// Map version
+	mapHeader->version = (EMapFormat::EMapFormat)(read_le_u32(buffer + pos));
+	pos += 4;
+	if(mapHeader->version != EMapFormat::ROE && mapHeader->version != EMapFormat::AB && mapHeader->version != EMapFormat::SOD
+			&& mapHeader->version != EMapFormat::WOG)
+	{
+		throw std::runtime_error("Invalid map format!");
+	}
+
+	// Read map name, description, dimensions,...
+	mapHeader->areAnyPlayers = static_cast<bool>(readChar(buffer, pos));
+	mapHeader->height = mapHeader->width = (read_le_u32(buffer + pos));
+	pos += 4;
+	mapHeader->twoLevel = readChar(buffer, pos);
+	mapHeader->name = readString(buffer, pos);
+	mapHeader->description = readString(buffer, pos);
+	mapHeader->difficulty = readChar(buffer, pos);
+	if(mapHeader->version != EMapFormat::ROE)
+	{
+		mapHeader->levelLimit = readChar(buffer, pos);
+	}
+	else
+	{
+		mapHeader->levelLimit = 0;
+	}
+
+	readPlayerInfo();
+	readVictoryLossConditions();
+	readTeamInfo();
+	readAllowedHeroes();
 }
 
 void CMapLoaderH3M::readPlayerInfo()
 {
-    mapHeader->players.resize(8);
-    for(int i = 0; i < 8; ++i)
-    {
-        mapHeader->players[i].canHumanPlay = static_cast<bool>(buffer[pos++]);
-        mapHeader->players[i].canComputerPlay = static_cast<bool>(buffer[pos++]);
-
-        // If nobody can play with this player
-        if((!(mapHeader->players[i].canHumanPlay || mapHeader->players[i].canComputerPlay)))
-        {
-            switch(mapHeader->version)
-            {
-            case EMapFormat::SOD:
-            case EMapFormat::WOG:
-                pos += 13;
-                break;
-            case EMapFormat::AB:
-                pos += 12;
-                break;
-            case EMapFormat::ROE:
-                pos += 6;
-                break;
-            }
-            continue;
-        }
-
-        mapHeader->players[i].aiTactic = static_cast<EAiTactic::EAiTactic>(buffer[pos++]);
-
-        if(mapHeader->version == EMapFormat::SOD || mapHeader->version == EMapFormat::WOG)
-        {
-            mapHeader->players[i].p7 = buffer[pos++];
-        }
-        else
-        {
-            mapHeader->players[i].p7 = -1;
-        }
-
-        // Factions this player can choose
-        ui16 allowedFactions = buffer[pos++];
-        if(mapHeader->version != EMapFormat::ROE)
-        {
-            allowedFactions += (buffer[pos++]) * 256;
-        }
-
-        for(int fact = 0; fact < 16; ++fact)
-        {
-            if(allowedFactions & (1 << fact))
-            {
-                mapHeader->players[i].allowedFactions.insert(fact);
-            }
-        }
-
-        mapHeader->players[i].isFactionRandom = static_cast<bool>(buffer[pos++]);
-        mapHeader->players[i].hasMainTown = static_cast<bool>(buffer[pos++]);
-        if(mapHeader->players[i].hasMainTown)
-        {
-            if(mapHeader->version != EMapFormat::ROE)
-            {
-                mapHeader->players[i].generateHeroAtMainTown = static_cast<bool>(buffer[pos++]);
-                mapHeader->players[i].generateHero = static_cast<bool>(buffer[pos++]);
-            }
-            else
-            {
-                mapHeader->players[i].generateHeroAtMainTown = true;
-                mapHeader->players[i].generateHero = false;
-            }
-
-            mapHeader->players[i].posOfMainTown.x = buffer[pos++];
-            mapHeader->players[i].posOfMainTown.y = buffer[pos++];
-            mapHeader->players[i].posOfMainTown.z = buffer[pos++];
-        }
-
-        mapHeader->players[i].p8 = buffer[pos++];
-        mapHeader->players[i].p9 = buffer[pos++];
-        if(mapHeader->players[i].p9 != 0xff)
-        {
-            mapHeader->players[i].mainHeroPortrait = buffer[pos++];
-            mapHeader->players[i].mainHeroName = readString(buffer, pos);
-        }
-
-        if(mapHeader->version != EMapFormat::ROE)
-        {
-            mapHeader->players[i].powerPlaceholders = buffer[pos++]; //unknown byte
-            int heroCount = buffer[pos++];
-            pos += 3;
-            for(int pp = 0; pp < heroCount; ++pp)
-            {
-                SHeroName vv;
-                vv.heroId = buffer[pos++];
-                int hnl = buffer[pos++];
-                pos += 3;
-                for(int zz = 0; zz < hnl; ++zz)
-                {
-                    vv.heroName += buffer[pos++];
-                }
-                mapHeader->players[i].heroesNames.push_back(vv);
-            }
-        }
-    }
+	mapHeader->players.resize(8);
+	for(int i = 0; i < 8; ++i)
+	{
+		mapHeader->players[i].canHumanPlay = static_cast<bool>(buffer[pos++]);
+		mapHeader->players[i].canComputerPlay = static_cast<bool>(buffer[pos++]);
+
+		// If nobody can play with this player
+		if((!(mapHeader->players[i].canHumanPlay || mapHeader->players[i].canComputerPlay)))
+		{
+			switch(mapHeader->version)
+			{
+			case EMapFormat::SOD:
+			case EMapFormat::WOG:
+				pos += 13;
+				break;
+			case EMapFormat::AB:
+				pos += 12;
+				break;
+			case EMapFormat::ROE:
+				pos += 6;
+				break;
+			}
+			continue;
+		}
+
+		mapHeader->players[i].aiTactic = static_cast<EAiTactic::EAiTactic>(buffer[pos++]);
+
+		if(mapHeader->version == EMapFormat::SOD || mapHeader->version == EMapFormat::WOG)
+		{
+			mapHeader->players[i].p7 = buffer[pos++];
+		}
+		else
+		{
+			mapHeader->players[i].p7 = -1;
+		}
+
+		// Factions this player can choose
+		ui16 allowedFactions = buffer[pos++];
+		if(mapHeader->version != EMapFormat::ROE)
+		{
+			allowedFactions += (buffer[pos++]) * 256;
+		}
+
+		for(int fact = 0; fact < 16; ++fact)
+		{
+			if(allowedFactions & (1 << fact))
+			{
+				mapHeader->players[i].allowedFactions.insert(fact);
+			}
+		}
+
+		mapHeader->players[i].isFactionRandom = static_cast<bool>(buffer[pos++]);
+		mapHeader->players[i].hasMainTown = static_cast<bool>(buffer[pos++]);
+		if(mapHeader->players[i].hasMainTown)
+		{
+			if(mapHeader->version != EMapFormat::ROE)
+			{
+				mapHeader->players[i].generateHeroAtMainTown = static_cast<bool>(buffer[pos++]);
+				mapHeader->players[i].generateHero = static_cast<bool>(buffer[pos++]);
+			}
+			else
+			{
+				mapHeader->players[i].generateHeroAtMainTown = true;
+				mapHeader->players[i].generateHero = false;
+			}
+
+			mapHeader->players[i].posOfMainTown.x = buffer[pos++];
+			mapHeader->players[i].posOfMainTown.y = buffer[pos++];
+			mapHeader->players[i].posOfMainTown.z = buffer[pos++];
+		}
+
+		mapHeader->players[i].p8 = buffer[pos++];
+		mapHeader->players[i].p9 = buffer[pos++];
+		if(mapHeader->players[i].p9 != 0xff)
+		{
+			mapHeader->players[i].mainHeroPortrait = buffer[pos++];
+			mapHeader->players[i].mainHeroName = readString(buffer, pos);
+		}
+
+		if(mapHeader->version != EMapFormat::ROE)
+		{
+			mapHeader->players[i].powerPlaceholders = buffer[pos++]; //unknown byte
+			int heroCount = buffer[pos++];
+			pos += 3;
+			for(int pp = 0; pp < heroCount; ++pp)
+			{
+				SHeroName vv;
+				vv.heroId = buffer[pos++];
+				int hnl = buffer[pos++];
+				pos += 3;
+				for(int zz = 0; zz < hnl; ++zz)
+				{
+					vv.heroName += buffer[pos++];
+				}
+				mapHeader->players[i].heroesNames.push_back(vv);
+			}
+		}
+	}
 }
 
 void CMapLoaderH3M::readVictoryLossConditions()
 {
-    mapHeader->victoryCondition.obj = nullptr;
-    mapHeader->victoryCondition.condition = (EVictoryConditionType::EVictoryConditionType)buffer[pos++];
-
-    // Specific victory conditions
-    if(mapHeader->victoryCondition.condition != EVictoryConditionType::WINSTANDARD)
-    {
-        // Read victory conditions
-        int nr = 0;
-        switch(mapHeader->victoryCondition.condition)
-        {
-        case EVictoryConditionType::ARTIFACT:
-            {
-                mapHeader->victoryCondition.objectId = buffer[pos + 2];
-                nr = (mapHeader->version == EMapFormat::ROE ? 1 : 2);
-                break;
-            }
-        case EVictoryConditionType::GATHERTROOP:
-            {
-                mapHeader->victoryCondition.objectId = buffer[pos + 2];
-                mapHeader->victoryCondition.count = read_le_u32(buffer + pos + (mapHeader->version == EMapFormat::ROE ? 3 : 4));
-                nr = (mapHeader->version == EMapFormat::ROE ? 5 : 6);
-                break;
-            }
-        case EVictoryConditionType::GATHERRESOURCE:
-            {
-                mapHeader->victoryCondition.objectId = buffer[pos + 2];
-                mapHeader->victoryCondition.count = read_le_u32(buffer + pos + 3);
-                nr = 5;
-                break;
-            }
-        case EVictoryConditionType::BUILDCITY:
-            {
-                mapHeader->victoryCondition.pos.x = buffer[pos + 2];
-                mapHeader->victoryCondition.pos.y = buffer[pos + 3];
-                mapHeader->victoryCondition.pos.z = buffer[pos + 4];
-                mapHeader->victoryCondition.count = buffer[pos + 5];
-                mapHeader->victoryCondition.objectId = buffer[pos + 6];
-                nr = 5;
-                break;
-            }
-        case EVictoryConditionType::BUILDGRAIL:
-            {
-                if(buffer[pos + 4] > 2)
-                {
-                    mapHeader->victoryCondition.pos = int3(-1,-1,-1);
-                }
-                else
-                {
-                    mapHeader->victoryCondition.pos.x = buffer[pos + 2];
-                    mapHeader->victoryCondition.pos.y = buffer[pos + 3];
-                    mapHeader->victoryCondition.pos.z = buffer[pos + 4];
-                }
-                nr = 3;
-                break;
-            }
-        case EVictoryConditionType::BEATHERO:
-        case EVictoryConditionType::CAPTURECITY:
-        case EVictoryConditionType::BEATMONSTER:
-            {
-                mapHeader->victoryCondition.pos.x = buffer[pos + 2];
-                mapHeader->victoryCondition.pos.y = buffer[pos + 3];
-                mapHeader->victoryCondition.pos.z = buffer[pos + 4];
-                nr = 3;
-                break;
-            }
-        case EVictoryConditionType::TAKEDWELLINGS:
-        case EVictoryConditionType::TAKEMINES:
-            {
-                nr = 0;
-                break;
-            }
-        case EVictoryConditionType::TRANSPORTITEM:
-            {
-                mapHeader->victoryCondition.objectId =  buffer[pos + 2];
-                mapHeader->victoryCondition.pos.x = buffer[pos + 3];
-                mapHeader->victoryCondition.pos.y = buffer[pos + 4];
-                mapHeader->victoryCondition.pos.z = buffer[pos + 5];
-                nr = 4;
-                break;
-            }
-        default:
-            assert(0);
-        }
-        mapHeader->victoryCondition.allowNormalVictory = static_cast<bool>(buffer[pos++]);
-        mapHeader->victoryCondition.appliesToAI = static_cast<bool>(buffer[pos++]);
-        pos += nr;
-    }
-
-    // Read loss conditions
-    mapHeader->lossCondition.typeOfLossCon = (ELossConditionType::ELossConditionType)buffer[pos++];
-    switch(mapHeader->lossCondition.typeOfLossCon)
-    {
-    case ELossConditionType::LOSSCASTLE:
-    case ELossConditionType::LOSSHERO:
-        {
-            mapHeader->lossCondition.pos.x = buffer[pos++];
-            mapHeader->lossCondition.pos.y = buffer[pos++];
-            mapHeader->lossCondition.pos.z = buffer[pos++];
-            break;
-        }
-    case ELossConditionType::TIMEEXPIRES:
-        {
-            mapHeader->lossCondition.timeLimit = read_le_u16(buffer + pos);
-            pos += 2;
-            break;
-        }
-    }
+	mapHeader->victoryCondition.obj = nullptr;
+	mapHeader->victoryCondition.condition = (EVictoryConditionType::EVictoryConditionType)buffer[pos++];
+
+	// Specific victory conditions
+	if(mapHeader->victoryCondition.condition != EVictoryConditionType::WINSTANDARD)
+	{
+		// Read victory conditions
+		int nr = 0;
+		switch(mapHeader->victoryCondition.condition)
+		{
+		case EVictoryConditionType::ARTIFACT:
+			{
+				mapHeader->victoryCondition.objectId = buffer[pos + 2];
+				nr = (mapHeader->version == EMapFormat::ROE ? 1 : 2);
+				break;
+			}
+		case EVictoryConditionType::GATHERTROOP:
+			{
+				mapHeader->victoryCondition.objectId = buffer[pos + 2];
+				mapHeader->victoryCondition.count = read_le_u32(buffer + pos + (mapHeader->version == EMapFormat::ROE ? 3 : 4));
+				nr = (mapHeader->version == EMapFormat::ROE ? 5 : 6);
+				break;
+			}
+		case EVictoryConditionType::GATHERRESOURCE:
+			{
+				mapHeader->victoryCondition.objectId = buffer[pos + 2];
+				mapHeader->victoryCondition.count = read_le_u32(buffer + pos + 3);
+				nr = 5;
+				break;
+			}
+		case EVictoryConditionType::BUILDCITY:
+			{
+				mapHeader->victoryCondition.pos.x = buffer[pos + 2];
+				mapHeader->victoryCondition.pos.y = buffer[pos + 3];
+				mapHeader->victoryCondition.pos.z = buffer[pos + 4];
+				mapHeader->victoryCondition.count = buffer[pos + 5];
+				mapHeader->victoryCondition.objectId = buffer[pos + 6];
+				nr = 5;
+				break;
+			}
+		case EVictoryConditionType::BUILDGRAIL:
+			{
+				if(buffer[pos + 4] > 2)
+				{
+					mapHeader->victoryCondition.pos = int3(-1,-1,-1);
+				}
+				else
+				{
+					mapHeader->victoryCondition.pos.x = buffer[pos + 2];
+					mapHeader->victoryCondition.pos.y = buffer[pos + 3];
+					mapHeader->victoryCondition.pos.z = buffer[pos + 4];
+				}
+				nr = 3;
+				break;
+			}
+		case EVictoryConditionType::BEATHERO:
+		case EVictoryConditionType::CAPTURECITY:
+		case EVictoryConditionType::BEATMONSTER:
+			{
+				mapHeader->victoryCondition.pos.x = buffer[pos + 2];
+				mapHeader->victoryCondition.pos.y = buffer[pos + 3];
+				mapHeader->victoryCondition.pos.z = buffer[pos + 4];
+				nr = 3;
+				break;
+			}
+		case EVictoryConditionType::TAKEDWELLINGS:
+		case EVictoryConditionType::TAKEMINES:
+			{
+				nr = 0;
+				break;
+			}
+		case EVictoryConditionType::TRANSPORTITEM:
+			{
+				mapHeader->victoryCondition.objectId =  buffer[pos + 2];
+				mapHeader->victoryCondition.pos.x = buffer[pos + 3];
+				mapHeader->victoryCondition.pos.y = buffer[pos + 4];
+				mapHeader->victoryCondition.pos.z = buffer[pos + 5];
+				nr = 4;
+				break;
+			}
+		default:
+			assert(0);
+		}
+		mapHeader->victoryCondition.allowNormalVictory = static_cast<bool>(buffer[pos++]);
+		mapHeader->victoryCondition.appliesToAI = static_cast<bool>(buffer[pos++]);
+		pos += nr;
+	}
+
+	// Read loss conditions
+	mapHeader->lossCondition.typeOfLossCon = (ELossConditionType::ELossConditionType)buffer[pos++];
+	switch(mapHeader->lossCondition.typeOfLossCon)
+	{
+	case ELossConditionType::LOSSCASTLE:
+	case ELossConditionType::LOSSHERO:
+		{
+			mapHeader->lossCondition.pos.x = buffer[pos++];
+			mapHeader->lossCondition.pos.y = buffer[pos++];
+			mapHeader->lossCondition.pos.z = buffer[pos++];
+			break;
+		}
+	case ELossConditionType::TIMEEXPIRES:
+		{
+			mapHeader->lossCondition.timeLimit = read_le_u16(buffer + pos);
+			pos += 2;
+			break;
+		}
+	}
 }
 
 void CMapLoaderH3M::readTeamInfo()
 {
-    mapHeader->howManyTeams = buffer[pos++];
-    if(mapHeader->howManyTeams > 0)
-    {
-        // Teams
-        for(int i = 0; i < 8; ++i)
-        {
-            mapHeader->players[i].team = buffer[pos++];
-        }
-    }
-    else
-    {
-        // No alliances
-        for(int i = 0; i < GameConstants::PLAYER_LIMIT; i++)
-        {
-            if(mapHeader->players[i].canComputerPlay || mapHeader->players[i].canHumanPlay)
-            {
-                mapHeader->players[i].team = mapHeader->howManyTeams++;
-            }
-        }
-    }
+	mapHeader->howManyTeams = buffer[pos++];
+	if(mapHeader->howManyTeams > 0)
+	{
+		// Teams
+		for(int i = 0; i < 8; ++i)
+		{
+			mapHeader->players[i].team = buffer[pos++];
+		}
+	}
+	else
+	{
+		// No alliances
+		for(int i = 0; i < GameConstants::PLAYER_LIMIT; i++)
+		{
+			if(mapHeader->players[i].canComputerPlay || mapHeader->players[i].canHumanPlay)
+			{
+				mapHeader->players[i].team = mapHeader->howManyTeams++;
+			}
+		}
+	}
 }
 
 void CMapLoaderH3M::readAllowedHeroes()
 {
-    int pom = pos;
-    mapHeader->allowedHeroes.resize(GameConstants::HEROES_QUANTITY, false);
-    for(; pos < pom + (mapHeader->version == EMapFormat::ROE ? 16 : 20) ; ++pos)
-    {
-        ui8 c = buffer[pos];
-        for(int yy = 0; yy < 8; ++yy)
-        {
-            if((pos - pom) * 8 + yy < GameConstants::HEROES_QUANTITY)
-            {
-                if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-                {
-                    mapHeader->allowedHeroes[(pos - pom) * 8 + yy] = true;
-                }
-            }
-        }
-    }
-
-    // Probably reserved for further heroes
-    if(mapHeader->version > EMapFormat::ROE)
-    {
-        int placeholdersQty = read_le_u32(buffer + pos);
-        pos += 4;
-        for(int p = 0; p < placeholdersQty; ++p)
-        {
-            mapHeader->placeholdedHeroes.push_back(buffer[pos++]);
-        }
-    }
+	int pom = pos;
+	mapHeader->allowedHeroes.resize(GameConstants::HEROES_QUANTITY, false);
+	for(; pos < pom + (mapHeader->version == EMapFormat::ROE ? 16 : 20) ; ++pos)
+	{
+		ui8 c = buffer[pos];
+		for(int yy = 0; yy < 8; ++yy)
+		{
+			if((pos - pom) * 8 + yy < GameConstants::HEROES_QUANTITY)
+			{
+				if(c == (c | static_cast<ui8>(std::pow(2., yy))))
+				{
+					mapHeader->allowedHeroes[(pos - pom) * 8 + yy] = true;
+				}
+			}
+		}
+	}
+
+	// Probably reserved for further heroes
+	if(mapHeader->version > EMapFormat::ROE)
+	{
+		int placeholdersQty = read_le_u32(buffer + pos);
+		pos += 4;
+		for(int p = 0; p < placeholdersQty; ++p)
+		{
+			mapHeader->placeholdedHeroes.push_back(buffer[pos++]);
+		}
+	}
 }
 
 void CMapLoaderH3M::readDisposedHeroes()
 {
-    // Reading disposed heroes (20 bytes)
-    ui8 disp = 0;
-    if(map->version >= EMapFormat::SOD)
-    {
-        disp = buffer[pos++];
-        map->disposedHeroes.resize(disp);
-        for(int g = 0; g < disp; ++g)
-        {
-            map->disposedHeroes[g].heroId = buffer[pos++];
-            map->disposedHeroes[g].portrait = buffer[pos++];
-            int lenbuf = read_le_u32(buffer + pos);
-            pos += 4;
-            for(int zz = 0; zz < lenbuf; zz++)
-            {
-                map->disposedHeroes[g].name += buffer[pos++];
-            }
-            map->disposedHeroes[g].players = buffer[pos++];
-        }
-    }
-
-    //omitting NULLS
-    pos += 31;
+	// Reading disposed heroes (20 bytes)
+	ui8 disp = 0;
+	if(map->version >= EMapFormat::SOD)
+	{
+		disp = buffer[pos++];
+		map->disposedHeroes.resize(disp);
+		for(int g = 0; g < disp; ++g)
+		{
+			map->disposedHeroes[g].heroId = buffer[pos++];
+			map->disposedHeroes[g].portrait = buffer[pos++];
+			int lenbuf = read_le_u32(buffer + pos);
+			pos += 4;
+			for(int zz = 0; zz < lenbuf; zz++)
+			{
+				map->disposedHeroes[g].name += buffer[pos++];
+			}
+			map->disposedHeroes[g].players = buffer[pos++];
+		}
+	}
+
+	//omitting NULLS
+	pos += 31;
 }
 
 void CMapLoaderH3M::readAllowedArtifacts()
 {
-    map->allowedArtifact.resize(GameConstants::ARTIFACTS_QUANTITY);
-    for(ui32 x = 0; x < map->allowedArtifact.size(); x++)
-    {
-        map->allowedArtifact[x] = true;
-    }
-
-    // Reading allowed artifacts:  17 or 18 bytes
-    if(map->version != EMapFormat::ROE)
-    {
-        // Starting i for loop
-        int ist = pos;
-        for(; pos < ist + (map->version == EMapFormat::AB ? 17 : 18); ++pos)
-        {
-            ui8 c = buffer[pos];
-            for(int yy = 0; yy < 8; ++yy)
-            {
-                if((pos - ist) * 8 + yy < GameConstants::ARTIFACTS_QUANTITY)
-                {
-                    if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-                    {
-                        map->allowedArtifact[(pos - ist) * 8 + yy] = false;
-                    }
-                }
-            }
-        }
-    }
-
-    // ban combo artifacts
-    if (map->version == EMapFormat::ROE || map->version == EMapFormat::AB)
-    {
-        BOOST_FOREACH(CArtifact * artifact, VLC->arth->artifacts)
-        {
-            // combo
-            if (artifact->constituents)
-            {
-                map->allowedArtifact[artifact->id] = false;
-            }
-        }
-        if (map->version == EMapFormat::ROE)
-        {
-            // Armageddon's Blade
-            map->allowedArtifact[128] = false;
-        }
-    }
-
-    // Messy, but needed
-    if(map->victoryCondition.condition == EVictoryConditionType::ARTIFACT
-            || map->victoryCondition.condition == EVictoryConditionType::TRANSPORTITEM)
-    {
-        map->allowedArtifact[map->victoryCondition.objectId] = false;
-    }
+	map->allowedArtifact.resize(GameConstants::ARTIFACTS_QUANTITY);
+	for(ui32 x = 0; x < map->allowedArtifact.size(); x++)
+	{
+		map->allowedArtifact[x] = true;
+	}
+
+	// Reading allowed artifacts:  17 or 18 bytes
+	if(map->version != EMapFormat::ROE)
+	{
+		// Starting i for loop
+		int ist = pos;
+		for(; pos < ist + (map->version == EMapFormat::AB ? 17 : 18); ++pos)
+		{
+			ui8 c = buffer[pos];
+			for(int yy = 0; yy < 8; ++yy)
+			{
+				if((pos - ist) * 8 + yy < GameConstants::ARTIFACTS_QUANTITY)
+				{
+					if(c == (c | static_cast<ui8>(std::pow(2., yy))))
+					{
+						map->allowedArtifact[(pos - ist) * 8 + yy] = false;
+					}
+				}
+			}
+		}
+	}
+
+	// ban combo artifacts
+	if (map->version == EMapFormat::ROE || map->version == EMapFormat::AB)
+	{
+		BOOST_FOREACH(CArtifact * artifact, VLC->arth->artifacts)
+		{
+			// combo
+			if (artifact->constituents)
+			{
+				map->allowedArtifact[artifact->id] = false;
+			}
+		}
+		if (map->version == EMapFormat::ROE)
+		{
+			// Armageddon's Blade
+			map->allowedArtifact[128] = false;
+		}
+	}
+
+	// Messy, but needed
+	if(map->victoryCondition.condition == EVictoryConditionType::ARTIFACT
+			|| map->victoryCondition.condition == EVictoryConditionType::TRANSPORTITEM)
+	{
+		map->allowedArtifact[map->victoryCondition.objectId] = false;
+	}
 }
 
 void CMapLoaderH3M::readAllowedSpellsAbilities()
 {
-    // Read allowed spells
-    map->allowedSpell.resize(GameConstants::SPELLS_QUANTITY);
-    for(ui32 x = 0; x < map->allowedSpell.size(); x++)
-    {
-        map->allowedSpell[x] = true;
-    }
-
-    // Read allowed abilities
-    map->allowedAbilities.resize(GameConstants::SKILL_QUANTITY);
-    for(ui32 x = 0; x < map->allowedAbilities.size(); x++)
-    {
-        map->allowedAbilities[x] = true;
-    }
-
-    if(map->version >= EMapFormat::SOD)
-    {
-        // Reading allowed spells (9 bytes)
-        int ist = pos;
-        for(; pos < ist + 9; ++pos)
-        {
-            ui8 c = buffer[pos];
-            for(int yy = 0; yy < 8; ++yy)
-            {
-                if((pos - ist) * 8 + yy < GameConstants::SPELLS_QUANTITY)
-                {
-                    if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-                    {
-                        map->allowedSpell[(pos - ist) * 8 + yy] = false;
-                    }
-                }
-            }
-        }
-
-
-        // Allowed hero's abilities (4 bytes)
-        ist = pos;
-        for(; pos < ist + 4; ++pos)
-        {
-            ui8 c = buffer[pos];
-            for(int yy = 0; yy < 8; ++yy)
-            {
-                if((pos - ist) * 8 + yy < GameConstants::SKILL_QUANTITY)
-                {
-                    if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-                    {
-                        map->allowedAbilities[(pos - ist) * 8 + yy] = false;
-                    }
-                }
-            }
-        }
-    }
+	// Read allowed spells
+	map->allowedSpell.resize(GameConstants::SPELLS_QUANTITY);
+	for(ui32 x = 0; x < map->allowedSpell.size(); x++)
+	{
+		map->allowedSpell[x] = true;
+	}
+
+	// Read allowed abilities
+	map->allowedAbilities.resize(GameConstants::SKILL_QUANTITY);
+	for(ui32 x = 0; x < map->allowedAbilities.size(); x++)
+	{
+		map->allowedAbilities[x] = true;
+	}
+
+	if(map->version >= EMapFormat::SOD)
+	{
+		// Reading allowed spells (9 bytes)
+		int ist = pos;
+		for(; pos < ist + 9; ++pos)
+		{
+			ui8 c = buffer[pos];
+			for(int yy = 0; yy < 8; ++yy)
+			{
+				if((pos - ist) * 8 + yy < GameConstants::SPELLS_QUANTITY)
+				{
+					if(c == (c | static_cast<ui8>(std::pow(2., yy))))
+					{
+						map->allowedSpell[(pos - ist) * 8 + yy] = false;
+					}
+				}
+			}
+		}
+
+
+		// Allowed hero's abilities (4 bytes)
+		ist = pos;
+		for(; pos < ist + 4; ++pos)
+		{
+			ui8 c = buffer[pos];
+			for(int yy = 0; yy < 8; ++yy)
+			{
+				if((pos - ist) * 8 + yy < GameConstants::SKILL_QUANTITY)
+				{
+					if(c == (c | static_cast<ui8>(std::pow(2., yy))))
+					{
+						map->allowedAbilities[(pos - ist) * 8 + yy] = false;
+					}
+				}
+			}
+		}
+	}
 }
 
 void CMapLoaderH3M::readRumors()
 {
-    int rumNr = read_le_u32(buffer + pos);
-    pos += 4;
-
-    for(int it = 0; it < rumNr; it++)
-    {
-        Rumor ourRumor;
-
-        // Read rumor name and text
-        int nameL = read_le_u32(buffer + pos);
-        pos += 4;
-        for(int zz = 0; zz < nameL; zz++)
-        {
-            ourRumor.name += buffer[pos++];
-        }
-
-        nameL = read_le_u32(buffer + pos);
-        pos += 4;
-        for(int zz = 0; zz < nameL; zz++)
-        {
-            ourRumor.text += buffer[pos++];
-        }
-
-        map->rumors.push_back(ourRumor);
-    }
+	int rumNr = read_le_u32(buffer + pos);
+	pos += 4;
+
+	for(int it = 0; it < rumNr; it++)
+	{
+		Rumor ourRumor;
+
+		// Read rumor name and text
+		int nameL = read_le_u32(buffer + pos);
+		pos += 4;
+		for(int zz = 0; zz < nameL; zz++)
+		{
+			ourRumor.name += buffer[pos++];
+		}
+
+		nameL = read_le_u32(buffer + pos);
+		pos += 4;
+		for(int zz = 0; zz < nameL; zz++)
+		{
+			ourRumor.text += buffer[pos++];
+		}
+
+		map->rumors.push_back(ourRumor);
+	}
 }
 
 void CMapLoaderH3M::readPredefinedHeroes()
 {
-    switch(map->version)
-    {
-    case EMapFormat::WOG:
-    case EMapFormat::SOD:
-        {
-            // Disposed heroes
-            for(int z = 0; z < GameConstants::HEROES_QUANTITY; z++)
-            {
-                int custom =  buffer[pos++];
-                if(!custom) continue;
-
-                CGHeroInstance * hero = new CGHeroInstance;
-                hero->ID = Obj::HERO;
-                hero->subID = z;
-
-                // True if hore's experience is greater than 0
-                if(readChar(buffer, pos))
-                {
-                    hero->exp = read_le_u32(buffer + pos);
-                    pos += 4;
-                }
-                else
-                {
-                    hero->exp = 0;
-                }
-
-                // True if hero has specified abilities
-                if(readChar(buffer, pos))
-                {
-                    int howMany = read_le_u32(buffer + pos);
-                    pos += 4;
-                    hero->secSkills.resize(howMany);
-                    for(int yy = 0; yy < howMany; ++yy)
-                    {
-                        hero->secSkills[yy].first = buffer[pos];
-                        ++pos;
-                        hero->secSkills[yy].second = buffer[pos];
-                        ++pos;
-                    }
-                }
-
-                loadArtifactsOfHero(hero);
-
-                // custom bio
-                if(readChar(buffer, pos))
-                {
-                    hero->biography = readString(buffer, pos);
-                }
-
-                // 0xFF is default, 00 male, 01 female
-                hero->sex = buffer[pos++];
-
-                // are spells
-                if(readChar(buffer, pos))
-                {
-                    int ist = pos;
-                    for(; pos < ist + 9; ++pos)
-                    {
-                        ui8 c = buffer[pos];
-                        for(int yy = 0; yy < 8; ++yy)
-                        {
-                            if((pos - ist) * 8 + yy < GameConstants::SPELLS_QUANTITY)
-                            {
-                                if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-                                {
-                                    hero->spells.insert((pos - ist) * 8 + yy);
-                                }
-                            }
-                        }
-                    }
-                }
-
-                // customPrimSkills
-                if(readChar(buffer, pos))
-                {
-                    for(int xx = 0; xx < GameConstants::PRIMARY_SKILLS; xx++)
-                    {
-                        hero->pushPrimSkill(xx, buffer[pos++]);
-                    }
-                }
-                map->predefinedHeroes.push_back(hero);
-            }
-            break;
-        }
-    case EMapFormat::ROE:
-        pos+=0;
-        break;
-    }
+	switch(map->version)
+	{
+	case EMapFormat::WOG:
+	case EMapFormat::SOD:
+		{
+			// Disposed heroes
+			for(int z = 0; z < GameConstants::HEROES_QUANTITY; z++)
+			{
+				int custom =  buffer[pos++];
+				if(!custom) continue;
+
+				CGHeroInstance * hero = new CGHeroInstance;
+				hero->ID = Obj::HERO;
+				hero->subID = z;
+
+				// True if hore's experience is greater than 0
+				if(readChar(buffer, pos))
+				{
+					hero->exp = read_le_u32(buffer + pos);
+					pos += 4;
+				}
+				else
+				{
+					hero->exp = 0;
+				}
+
+				// True if hero has specified abilities
+				if(readChar(buffer, pos))
+				{
+					int howMany = read_le_u32(buffer + pos);
+					pos += 4;
+					hero->secSkills.resize(howMany);
+					for(int yy = 0; yy < howMany; ++yy)
+					{
+						hero->secSkills[yy].first = buffer[pos];
+						++pos;
+						hero->secSkills[yy].second = buffer[pos];
+						++pos;
+					}
+				}
+
+				loadArtifactsOfHero(hero);
+
+				// custom bio
+				if(readChar(buffer, pos))
+				{
+					hero->biography = readString(buffer, pos);
+				}
+
+				// 0xFF is default, 00 male, 01 female
+				hero->sex = buffer[pos++];
+
+				// are spells
+				if(readChar(buffer, pos))
+				{
+					int ist = pos;
+					for(; pos < ist + 9; ++pos)
+					{
+						ui8 c = buffer[pos];
+						for(int yy = 0; yy < 8; ++yy)
+						{
+							if((pos - ist) * 8 + yy < GameConstants::SPELLS_QUANTITY)
+							{
+								if(c == (c | static_cast<ui8>(std::pow(2., yy))))
+								{
+									hero->spells.insert((pos - ist) * 8 + yy);
+								}
+							}
+						}
+					}
+				}
+
+				// customPrimSkills
+				if(readChar(buffer, pos))
+				{
+					for(int xx = 0; xx < GameConstants::PRIMARY_SKILLS; xx++)
+					{
+						hero->pushPrimSkill(xx, buffer[pos++]);
+					}
+				}
+				map->predefinedHeroes.push_back(hero);
+			}
+			break;
+		}
+	case EMapFormat::ROE:
+		pos+=0;
+		break;
+	}
 }
 
 void CMapLoaderH3M::loadArtifactsOfHero(CGHeroInstance * hero)
 {
-    bool artSet = buffer[pos];
-    ++pos;
-
-    // True if artifact set is not default (hero has some artifacts)
-    if(artSet)
-    {
-        for(int pom = 0; pom < 16; pom++)
-        {
-            loadArtifactToSlot(hero, pom);
-        }
-
-        // misc5 art //17
-        if(map->version >= EMapFormat::SOD)
-        {
-            if(!loadArtifactToSlot(hero, ArtifactPosition::MACH4))
-            {
-                // catapult by default
-                hero->putArtifact(ArtifactPosition::MACH4, createArtifact(GameConstants::ID_CATAPULT));
-            }
-        }
-
-        loadArtifactToSlot(hero, ArtifactPosition::SPELLBOOK);
-
-        // 19 //???what is that? gap in file or what? - it's probably fifth slot..
-        if(map->version > EMapFormat::ROE)
-        {
-            loadArtifactToSlot(hero, ArtifactPosition::MISC5);
-        }
-        else
-        {
-            ++pos;
-        }
-
-        // bag artifacts //20
-        // number of artifacts in hero's bag
-        int amount = read_le_u16(buffer + pos);
-        pos += 2;
-        for(int ss = 0; ss < amount; ++ss)
-        {
-            loadArtifactToSlot(hero, GameConstants::BACKPACK_START + hero->artifactsInBackpack.size());
-        }
-    }
+	bool artSet = buffer[pos];
+	++pos;
+
+	// True if artifact set is not default (hero has some artifacts)
+	if(artSet)
+	{
+		for(int pom = 0; pom < 16; pom++)
+		{
+			loadArtifactToSlot(hero, pom);
+		}
+
+		// misc5 art //17
+		if(map->version >= EMapFormat::SOD)
+		{
+			if(!loadArtifactToSlot(hero, ArtifactPosition::MACH4))
+			{
+				// catapult by default
+				hero->putArtifact(ArtifactPosition::MACH4, createArtifact(GameConstants::ID_CATAPULT));
+			}
+		}
+
+		loadArtifactToSlot(hero, ArtifactPosition::SPELLBOOK);
+
+		// 19 //???what is that? gap in file or what? - it's probably fifth slot..
+		if(map->version > EMapFormat::ROE)
+		{
+			loadArtifactToSlot(hero, ArtifactPosition::MISC5);
+		}
+		else
+		{
+			++pos;
+		}
+
+		// bag artifacts //20
+		// number of artifacts in hero's bag
+		int amount = read_le_u16(buffer + pos);
+		pos += 2;
+		for(int ss = 0; ss < amount; ++ss)
+		{
+			loadArtifactToSlot(hero, GameConstants::BACKPACK_START + hero->artifactsInBackpack.size());
+		}
+	}
 }
 
 bool CMapLoaderH3M::loadArtifactToSlot(CGHeroInstance * hero, int slot)
 {
-    const int artmask = map->version == EMapFormat::ROE ? 0xff : 0xffff;
-    int aid;
-
-    if(map->version == EMapFormat::ROE)
-    {
-        aid = buffer[pos];
-        pos++;
-    }
-    else
-    {
-        aid = read_le_u16(buffer + pos);
-        pos += 2;
-    }
-
-    bool isArt  =  aid != artmask;
-    if(isArt)
-    {
-        if(vstd::contains(VLC->arth->bigArtifacts, aid) && slot >= GameConstants::BACKPACK_START)
-        {
-            tlog3 << "Warning: A big artifact (war machine) in hero's backpack, ignoring..." << std::endl;
-            return false;
-        }
-        if(aid == 0 && slot == ArtifactPosition::MISC5)
-        {
-            //TODO: check how H3 handles it -> art 0 in slot 18 in AB map
-            tlog3 << "Spellbook to MISC5 slot? Putting it spellbook place. AB format peculiarity ? (format "
-                  << static_cast<int>(map->version) << ")" << std::endl;
-            slot = ArtifactPosition::SPELLBOOK;
-        }
-
-        hero->putArtifact(slot, createArtifact(aid));
-    }
-
-    return isArt;
+	const int artmask = map->version == EMapFormat::ROE ? 0xff : 0xffff;
+	int aid;
+
+	if(map->version == EMapFormat::ROE)
+	{
+		aid = buffer[pos];
+		pos++;
+	}
+	else
+	{
+		aid = read_le_u16(buffer + pos);
+		pos += 2;
+	}
+
+	bool isArt  =  aid != artmask;
+	if(isArt)
+	{
+		if(vstd::contains(VLC->arth->bigArtifacts, aid) && slot >= GameConstants::BACKPACK_START)
+		{
+			tlog3 << "Warning: A big artifact (war machine) in hero's backpack, ignoring..." << std::endl;
+			return false;
+		}
+		if(aid == 0 && slot == ArtifactPosition::MISC5)
+		{
+			//TODO: check how H3 handles it -> art 0 in slot 18 in AB map
+			tlog3 << "Spellbook to MISC5 slot? Putting it spellbook place. AB format peculiarity ? (format "
+				  << static_cast<int>(map->version) << ")" << std::endl;
+			slot = ArtifactPosition::SPELLBOOK;
+		}
+
+		hero->putArtifact(slot, createArtifact(aid));
+	}
+
+	return isArt;
 }
 
 CArtifactInstance * CMapLoaderH3M::createArtifact(int aid, int spellID /*= -1*/)
 {
-    CArtifactInstance * a = nullptr;
-    if(aid >= 0)
-    {
-        if(spellID < 0)
-        {
-            a = CArtifactInstance::createNewArtifactInstance(aid);
-        }
-        else
-        {
-            a = CArtifactInstance::createScroll(VLC->spellh->spells[spellID]);
-        }
-    }
-    else
-    {
-        a = new CArtifactInstance;
-    }
-
-    addNewArtifactInstance(a);
-
-    //TODO make it nicer
-    if(a->artType && a->artType->constituents)
-    {
-        CCombinedArtifactInstance * comb = dynamic_cast<CCombinedArtifactInstance *>(a);
-        BOOST_FOREACH(CCombinedArtifactInstance::ConstituentInfo & ci, comb->constituentsInfo)
-        {
-            addNewArtifactInstance(ci.art);
-        }
-    }
-
-    return a;
+	CArtifactInstance * a = nullptr;
+	if(aid >= 0)
+	{
+		if(spellID < 0)
+		{
+			a = CArtifactInstance::createNewArtifactInstance(aid);
+		}
+		else
+		{
+			a = CArtifactInstance::createScroll(VLC->spellh->spells[spellID]);
+		}
+	}
+	else
+	{
+		a = new CArtifactInstance;
+	}
+
+	addNewArtifactInstance(a);
+
+	//TODO make it nicer
+	if(a->artType && a->artType->constituents)
+	{
+		CCombinedArtifactInstance * comb = dynamic_cast<CCombinedArtifactInstance *>(a);
+		BOOST_FOREACH(CCombinedArtifactInstance::ConstituentInfo & ci, comb->constituentsInfo)
+		{
+			addNewArtifactInstance(ci.art);
+		}
+	}
+
+	return a;
 }
 
 void CMapLoaderH3M::addNewArtifactInstance(CArtifactInstance * art)
 {
-    art->id = map->artInstances.size();
-    map->artInstances.push_back(art);
+	art->id = map->artInstances.size();
+	map->artInstances.push_back(art);
 }
 
 void CMapLoaderH3M::readTerrain()
 {
-    // Allocate memory for terrain data
-    map->terrain = new TerrainTile**[map->width];
-    for(int ii = 0; ii < map->width; ii++)
-    {
-        map->terrain[ii] = new TerrainTile*[map->height];
-        for(int jj = 0; jj < map->height; jj++)
-        {
-            map->terrain[ii][jj] = new TerrainTile[map->twoLevel + 1];
-        }
-    }
-
-    // Read terrain
-    for(int a = 0; a < 2; ++a)
-    {
-        if(a == 1 && !map->twoLevel)
-        {
-            break;
-        }
-
-        for(int c = 0; c < map->width; c++)
-        {
-            for(int z = 0; z < map->height; z++)
-            {
-                map->terrain[z][c][a].terType = static_cast<ETerrainType::ETerrainType>(buffer[pos++]);
-                map->terrain[z][c][a].terView = buffer[pos++];
-                map->terrain[z][c][a].riverType = static_cast<ERiverType::ERiverType>(buffer[pos++]);
-                map->terrain[z][c][a].riverDir = buffer[pos++];
-                map->terrain[z][c][a].roadType = static_cast<ERoadType::ERoadType>(buffer[pos++]);
-                map->terrain[z][c][a].roadDir = buffer[pos++];
-                map->terrain[z][c][a].extTileFlags = buffer[pos++];
-                map->terrain[z][c][a].blocked = (map->terrain[z][c][a].terType == ETerrainType::ROCK ? 1 : 0); //underground tiles are always blocked
-                map->terrain[z][c][a].visitable = 0;
-            }
-        }
-    }
+	// Allocate memory for terrain data
+	map->terrain = new TerrainTile**[map->width];
+	for(int ii = 0; ii < map->width; ii++)
+	{
+		map->terrain[ii] = new TerrainTile*[map->height];
+		for(int jj = 0; jj < map->height; jj++)
+		{
+			map->terrain[ii][jj] = new TerrainTile[map->twoLevel + 1];
+		}
+	}
+
+	// Read terrain
+	for(int a = 0; a < 2; ++a)
+	{
+		if(a == 1 && !map->twoLevel)
+		{
+			break;
+		}
+
+		for(int c = 0; c < map->width; c++)
+		{
+			for(int z = 0; z < map->height; z++)
+			{
+				map->terrain[z][c][a].terType = static_cast<ETerrainType::ETerrainType>(buffer[pos++]);
+				map->terrain[z][c][a].terView = buffer[pos++];
+				map->terrain[z][c][a].riverType = static_cast<ERiverType::ERiverType>(buffer[pos++]);
+				map->terrain[z][c][a].riverDir = buffer[pos++];
+				map->terrain[z][c][a].roadType = static_cast<ERoadType::ERoadType>(buffer[pos++]);
+				map->terrain[z][c][a].roadDir = buffer[pos++];
+				map->terrain[z][c][a].extTileFlags = buffer[pos++];
+				map->terrain[z][c][a].blocked = (map->terrain[z][c][a].terType == ETerrainType::ROCK ? 1 : 0); //underground tiles are always blocked
+				map->terrain[z][c][a].visitable = 0;
+			}
+		}
+	}
 }
 
 void CMapLoaderH3M::readDefInfo()
 {
-    int defAmount = read_le_u32(buffer + pos);
-    pos += 4;
-    map->customDefs.reserve(defAmount + 8);
-
-    // Read custom defs
-    for(int idd = 0; idd < defAmount; ++idd)
-    {
-        CGDefInfo * defInfo = new CGDefInfo;
-
-        // Read name
-        int nameLength = read_le_u32(buffer + pos);
-        pos += 4;
-        defInfo->name.reserve(nameLength);
-        for(int cd = 0; cd < nameLength; ++cd)
-        {
-            defInfo->name += buffer[pos++];
-        }
-        std::transform(defInfo->name.begin(),defInfo->name.end(),defInfo->name.begin(),(int(*)(int))toupper);
-
-        ui8 bytes[12];
-        for(int v = 0; v < 12; ++v)
-        {
-            bytes[v] = buffer[pos++];
-        }
-
-        defInfo->terrainAllowed = read_le_u16(buffer + pos);
-        pos += 2;
-        defInfo->terrainMenu = read_le_u16(buffer + pos);
-        pos += 2;
-        defInfo->id = read_le_u32(buffer + pos);
-        pos += 4;
-        defInfo->subid = read_le_u32(buffer + pos);
-        pos += 4;
-        defInfo->type = buffer[pos++];
-        defInfo->printPriority = buffer[pos++];
-        for(int zi = 0; zi < 6; ++zi)
-        {
-            defInfo->blockMap[zi] = reverse(bytes[zi]);
-        }
-        for(int zi = 0; zi < 6; ++zi)
-        {
-            defInfo->visitMap[zi] = reverse(bytes[6 + zi]);
-        }
-        pos += 16;
-        if(defInfo->id != Obj::HERO && defInfo->id != 70)
-        {
-            CGDefInfo * h = VLC->dobjinfo->gobjs[defInfo->id][defInfo->subid];
-            if(!h)
-            {
-                //remove fake entry
-                VLC->dobjinfo->gobjs[defInfo->id].erase(defInfo->subid);
-                if(VLC->dobjinfo->gobjs[defInfo->id].size())
-                {
-                    VLC->dobjinfo->gobjs.erase(defInfo->id);
-                }
-                tlog2 << "\t\tWarning: no defobjinfo entry for object ID="
-                      << defInfo->id << " subID=" << defInfo->subid << std::endl;
-            }
-            else
-            {
-                defInfo->visitDir = VLC->dobjinfo->gobjs[defInfo->id][defInfo->subid]->visitDir;
-            }
-        }
-        else
-        {
-            defInfo->visitDir = 0xff;
-        }
-
-        if(defInfo->id == Obj::EVENT)
-        {
-            std::memset(defInfo->blockMap, 255, 6);
-        }
-
-        //calculating coverageMap
-        defInfo->fetchInfoFromMSK();
-
-        map->customDefs.push_back(defInfo);
-    }
-
-    //add holes - they always can appear
-    for(int i = 0; i < 8 ; ++i)
-    {
-        map->customDefs.push_back(VLC->dobjinfo->gobjs[124][i]);
-    }
+	int defAmount = read_le_u32(buffer + pos);
+	pos += 4;
+	map->customDefs.reserve(defAmount + 8);
+
+	// Read custom defs
+	for(int idd = 0; idd < defAmount; ++idd)
+	{
+		CGDefInfo * defInfo = new CGDefInfo;
+
+		// Read name
+		int nameLength = read_le_u32(buffer + pos);
+		pos += 4;
+		defInfo->name.reserve(nameLength);
+		for(int cd = 0; cd < nameLength; ++cd)
+		{
+			defInfo->name += buffer[pos++];
+		}
+		std::transform(defInfo->name.begin(),defInfo->name.end(),defInfo->name.begin(),(int(*)(int))toupper);
+
+		ui8 bytes[12];
+		for(int v = 0; v < 12; ++v)
+		{
+			bytes[v] = buffer[pos++];
+		}
+
+		defInfo->terrainAllowed = read_le_u16(buffer + pos);
+		pos += 2;
+		defInfo->terrainMenu = read_le_u16(buffer + pos);
+		pos += 2;
+		defInfo->id = read_le_u32(buffer + pos);
+		pos += 4;
+		defInfo->subid = read_le_u32(buffer + pos);
+		pos += 4;
+		defInfo->type = buffer[pos++];
+		defInfo->printPriority = buffer[pos++];
+		for(int zi = 0; zi < 6; ++zi)
+		{
+			defInfo->blockMap[zi] = reverse(bytes[zi]);
+		}
+		for(int zi = 0; zi < 6; ++zi)
+		{
+			defInfo->visitMap[zi] = reverse(bytes[6 + zi]);
+		}
+		pos += 16;
+		if(defInfo->id != Obj::HERO && defInfo->id != 70)
+		{
+			CGDefInfo * h = VLC->dobjinfo->gobjs[defInfo->id][defInfo->subid];
+			if(!h)
+			{
+				//remove fake entry
+				VLC->dobjinfo->gobjs[defInfo->id].erase(defInfo->subid);
+				if(VLC->dobjinfo->gobjs[defInfo->id].size())
+				{
+					VLC->dobjinfo->gobjs.erase(defInfo->id);
+				}
+				tlog2 << "\t\tWarning: no defobjinfo entry for object ID="
+					  << defInfo->id << " subID=" << defInfo->subid << std::endl;
+			}
+			else
+			{
+				defInfo->visitDir = VLC->dobjinfo->gobjs[defInfo->id][defInfo->subid]->visitDir;
+			}
+		}
+		else
+		{
+			defInfo->visitDir = 0xff;
+		}
+
+		if(defInfo->id == Obj::EVENT)
+		{
+			std::memset(defInfo->blockMap, 255, 6);
+		}
+
+		//calculating coverageMap
+		defInfo->fetchInfoFromMSK();
+
+		map->customDefs.push_back(defInfo);
+	}
+
+	//add holes - they always can appear
+	for(int i = 0; i < 8 ; ++i)
+	{
+		map->customDefs.push_back(VLC->dobjinfo->gobjs[124][i]);
+	}
 }
 
 void CMapLoaderH3M::readObjects()
 {
-    int howManyObjs = read_le_u32(buffer + pos);
-    pos += 4;
-
-    for(int ww = 0; ww < howManyObjs; ++ww)
-    {
-        CGObjectInstance * nobj = 0;
-
-        int3 objPos;
-        objPos.x = buffer[pos++];
-        objPos.y = buffer[pos++];
-        objPos.z = buffer[pos++];
-
-        int defnum = read_le_u32(buffer + pos);
-        pos += 4;
-        int idToBeGiven = map->objects.size();
-
-        CGDefInfo * defInfo = map->customDefs.at(defnum);
-        pos += 5;
-
-        switch(defInfo->id)
-        {
-        case Obj::EVENT:
-            {
-                CGEvent * evnt = new CGEvent();
-                nobj = evnt;
-
-                bool guardMess = buffer[pos];
-                ++pos;
-                if(guardMess)
-                {
-                    int messLong = read_le_u32(buffer + pos);
-                    pos += 4;
-                    if(messLong > 0)
-                    {
-                        for(int yy = 0; yy < messLong; ++yy)
-                        {
-                            evnt->message += buffer[pos + yy];
-                        }
-                        pos += messLong;
-                    }
-                    if(buffer[pos++])
-                    {
-                        readCreatureSet(evnt, 7, map->version > EMapFormat::ROE);
-                    }
-                    pos += 4;
-                }
-                evnt->gainedExp = read_le_u32(buffer + pos);
-                pos += 4;
-                evnt->manaDiff = read_le_u32(buffer + pos);
-                pos += 4;
-                evnt->moraleDiff = static_cast<char>(buffer[pos]);
-                ++pos;
-                evnt->luckDiff = static_cast<char>(buffer[pos]);
-                ++pos;
-
-                evnt->resources.resize(GameConstants::RESOURCE_QUANTITY);
-                for(int x = 0; x < 7; ++x)
-                {
-                    evnt->resources[x] = read_le_u32(buffer + pos);
-                    pos += 4;
-                }
-
-                evnt->primskills.resize(GameConstants::PRIMARY_SKILLS);
-                for(int x = 0; x < 4; ++x)
-                {
-                    evnt->primskills[x] = buffer[pos];
-                    ++pos;
-                }
-
-                int gabn; // Number of gained abilities
-                gabn = buffer[pos];
-                ++pos;
-                for(int oo = 0; oo < gabn; ++oo)
-                {
-                    evnt->abilities.push_back(buffer[pos]);
-                    ++pos;
-                    evnt->abilityLevels.push_back(buffer[pos]);
-                    ++pos;
-                }
-
-                int gart = buffer[pos]; // Number of gained artifacts
-                ++pos;
-                for(int oo = 0; oo < gart; ++oo)
-                {
-                    if(map->version == EMapFormat::ROE)
-                    {
-                        evnt->artifacts.push_back(buffer[pos]);
-                        ++pos;
-                    }
-                    else
-                    {
-                        evnt->artifacts.push_back(read_le_u16(buffer + pos));
-                        pos += 2;
-                    }
-                }
-
-                int gspel = buffer[pos]; // Number of gained spells
-                ++pos;
-                for(int oo = 0; oo < gspel; ++oo)
-                {
-                    evnt->spells.push_back(buffer[pos]);
-                    ++pos;
-                }
-
-                int gcre = buffer[pos]; //number of gained creatures
-                ++pos;
-                readCreatureSet(&evnt->creatures, gcre, map->version > EMapFormat::ROE);
-
-                pos += 8;
-                evnt->availableFor = buffer[pos];
-                ++pos;
-                evnt->computerActivate = buffer[pos];
-                ++pos;
-                evnt->removeAfterVisit = buffer[pos];
-                ++pos;
-                evnt->humanActivate = true;
-
-                pos += 4;
-                break;
-            }
-        case 34: case 70: case 62: //34 - hero; 70 - random hero; 62 - prison
-            {
-                nobj = readHero(idToBeGiven);
-                break;
-            }
-        case 4: //Arena
-        case 51: //Mercenary Camp
-        case 23: //Marletto Tower
-        case 61: // Star Axis
-        case 32: // Garden of Revelation
-        case 100: //Learning Stone
-        case 102: //Tree of Knowledge
-        case 41: //Library of Enlightenment
-        case 47: //School of Magic
-        case 107: //School of War
-            {
-                nobj = new CGVisitableOPH;
-                break;
-            }
-        case 55: //mystical garden
-        case 112://windmill
-        case 109://water wheel
-            {
-                nobj = new CGVisitableOPW;
-                break;
-            }
-        case 43: //teleport
-        case 44: //teleport
-        case 45: //teleport
-        case 103://subterranean gate
-        case 111://Whirlpool
-            {
-                nobj = new CGTeleport;
-                break;
-            }
-        case 12: //campfire
-        case 29: //Flotsam
-        case 82: //Sea Chest
-        case 86: //Shipwreck Survivor
-        case 101://treasure chest
-            {
-                nobj = new CGPickable;
-                break;
-            }
-        case 54:  //Monster
-        case 71: case 72: case 73: case 74: case 75:	// Random Monster 1 - 4
-        case 162: case 163: case 164:					// Random Monster 5 - 7
-            {
-                CGCreature * cre = new CGCreature;
-                nobj = cre;
-
-                if(map->version > EMapFormat::ROE)
-                {
-                    cre->identifier = read_le_u32(buffer + pos);
-                    pos += 4;
-                    map->questIdentifierToId[cre->identifier] = idToBeGiven;
-                }
-
-                CStackInstance * hlp = new CStackInstance;
-                hlp->count = read_le_u16(buffer + pos);
-                pos += 2;
-
-                //type will be set during initialization
-                cre->putStack(0, hlp);
-
-                cre->character = buffer[pos];
-                ++pos;
-                bool isMesTre = buffer[pos]; //true if there is message or treasury
-                ++pos;
-                if(isMesTre)
-                {
-                    cre->message = readString(buffer, pos);
-                    cre->resources.resize(GameConstants::RESOURCE_QUANTITY);
-                    for(int j = 0; j < 7; ++j)
-                    {
-                        cre->resources[j] = read_le_u32(buffer + pos);
-                        pos += 4;
-                    }
-
-                    int artID;
-                    if (map->version == EMapFormat::ROE)
-                    {
-                        artID = buffer[pos];
-                        ++pos;
-                    }
-                    else
-                    {
-                        artID = read_le_u16(buffer + pos);
-                        pos += 2;
-                    }
-
-                    if(map->version == EMapFormat::ROE)
-                    {
-                        if(artID != 0xff)
-                        {
-                            cre->gainedArtifact = artID;
-                        }
-                        else
-                        {
-                            cre->gainedArtifact = -1;
-                        }
-                    }
-                    else
-                    {
-                        if(artID != 0xffff)
-                        {
-                            cre->gainedArtifact = artID;
-                        }
-                        else
-                        {
-                            cre->gainedArtifact = -1;
-                        }
-                    }
-                }
-                cre->neverFlees = buffer[pos];
-                ++pos;
-                cre->notGrowingTeam = buffer[pos];
-                ++pos;
-                pos += 2;
-                break;
-            }
-        case 59: case 91: //ocean bottle and sign
-            {
-                CGSignBottle * sb = new CGSignBottle;
-                nobj = sb;
-                sb->message = readString(buffer, pos);
-                pos += 4;
-                break;
-            }
-        case 83: //seer's hut
-            {
-                nobj = readSeerHut();
-                addQuest(nobj);
-                break;
-            }
-        case 113: //witch hut
-            {
-                CGWitchHut * wh = new CGWitchHut;
-                nobj = wh;
-
-                // in reo we cannot specify it - all are allowed (I hope)
-                if(map->version > EMapFormat::ROE)
-                {
-                    int ist=pos;
-                    for(; pos < ist + 4; ++pos)
-                    {
-                        ui8 c = buffer[pos];
-                        for(int yy = 0; yy < 8; ++yy)
-                        {
-                            if((pos - ist) * 8 + yy < GameConstants::SKILL_QUANTITY)
-                            {
-                                if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-                                {
-                                    wh->allowedAbilities.push_back((pos - ist) * 8 + yy);
-                                }
-                            }
-                        }
-                    }
-                }
-                else
-                {
-                    // RoE map
-                    for(int gg = 0; gg < GameConstants::SKILL_QUANTITY; ++gg)
-                    {
-                        wh->allowedAbilities.push_back(gg);
-                    }
-                }
-                break;
-            }
-        case 81: //scholar
-            {
-                CGScholar * sch = new CGScholar;
-                nobj = sch;
-                sch->bonusType = buffer[pos++];
-                sch->bonusID = buffer[pos++];
-                pos += 6;
-                break;
-            }
-        case 33: case 219: //garrison
-            {
-                CGGarrison * gar = new CGGarrison;
-                nobj = gar;
-                nobj->setOwner(buffer[pos++]);
-                pos += 3;
-                readCreatureSet(gar, 7, map->version > EMapFormat::ROE);
-                if(map->version > EMapFormat::ROE)
-                {
-                    gar->removableUnits = buffer[pos];
-                    ++pos;
-                }
-                else
-                {
-                    gar->removableUnits = true;
-                }
-                pos += 8;
-                break;
-            }
-        case 5: //artifact
-        case 65: case 66: case 67: case 68: case 69: //random artifact
-        case 93: //spell scroll
-            {
-                int artID = -1;
-                int spellID = -1;
-                CGArtifact * art = new CGArtifact;
-                nobj = art;
-
-                bool areSettings = buffer[pos++];
-                if(areSettings)
-                {
-                    art->message = readString(buffer, pos);
-                    bool areGuards = buffer[pos++];
-                    if(areGuards)
-                    {
-                        readCreatureSet(art, 7, map->version > EMapFormat::ROE);
-                    }
-                    pos += 4;
-                }
-
-                if(defInfo->id == 93)
-                {
-                    spellID = read_le_u32(buffer + pos);
-                    pos += 4;
-                    artID = 1;
-                }
-                else if(defInfo->id == 5)
-                {
-                    //specific artifact
-                    artID = defInfo->subid;
-                }
-
-                art->storedArtifact = createArtifact(artID, spellID);
-                break;
-            }
-        case 76: case 79: //random resource; resource
-            {
-                CGResource * res = new CGResource;
-                nobj = res;
-
-                bool isMessGuard = buffer[pos];
-                ++pos;
-                if(isMessGuard)
-                {
-                    res->message = readString(buffer, pos);
-                    if(buffer[pos++])
-                    {
-                        readCreatureSet(res, 7, map->version > EMapFormat::ROE);
-                    }
-                    pos += 4;
-                }
-                res->amount = read_le_u32(buffer + pos);
-                pos += 4;
-                if(defInfo->subid == 6)
-                {
-                    // Gold is multiplied by 100.
-                    res->amount *= 100;
-                }
-                pos += 4;
-
-                break;
-            }
-        case 77: case 98: //random town; town
-            {
-                nobj = readTown(defInfo->subid);
-                break;
-            }
-        case 53:
-        case 220://mine (?)
-            {
-                nobj = new CGMine;
-                nobj->setOwner(buffer[pos++]);
-                pos += 3;
-                break;
-            }
-        case 17: case 18: case 19: case 20: //dwellings
-            {
-                nobj = new CGDwelling;
-                nobj->setOwner(buffer[pos++]);
-                pos += 3;
-                break;
-            }
-        case 78: //Refugee Camp
-        case 106: //War Machine Factory
-            {
-                nobj = new CGDwelling;
-                break;
-            }
-        case 88: case 89: case 90: //spell shrine
-            {
-                CGShrine * shr = new CGShrine;
-                nobj = shr;
-                shr->spell = buffer[pos];
-                pos += 4;
-                break;
-            }
-        case 6: //pandora's box
-            {
-                CGPandoraBox * box = new CGPandoraBox;
-                nobj = box;
-                bool messg = buffer[pos];
-                ++pos;
-                if(messg)
-                {
-                    box->message = readString(buffer, pos);
-                    if(buffer[pos++])
-                    {
-                        readCreatureSet(box, 7, map->version > EMapFormat::ROE);
-                    }
-                    pos += 4;
-                }
-
-                box->gainedExp = read_le_u32(buffer + pos);
-                pos += 4;
-                box->manaDiff = read_le_u32(buffer + pos);
-                pos += 4;
-                box->moraleDiff = static_cast<si8>(buffer[pos]);
-                ++pos;
-                box->luckDiff = static_cast<si8>(buffer[pos]);
-                ++pos;
-
-                box->resources.resize(GameConstants::RESOURCE_QUANTITY);
-                for(int x = 0; x < 7; ++x)
-                {
-                    box->resources[x] = read_le_u32(buffer + pos);
-                    pos += 4;
-                }
-
-                box->primskills.resize(GameConstants::PRIMARY_SKILLS);
-                for(int x = 0; x < 4; ++x)
-                {
-                    box->primskills[x] = buffer[pos];
-                    ++pos;
-                }
-
-                int gabn; //number of gained abilities
-                gabn = buffer[pos];
-                ++pos;
-                for(int oo = 0; oo < gabn; ++oo)
-                {
-                    box->abilities.push_back(buffer[pos]);
-                    ++pos;
-                    box->abilityLevels.push_back(buffer[pos]);
-                    ++pos;
-                }
-                int gart = buffer[pos]; //number of gained artifacts
-                ++pos;
-                for(int oo = 0; oo < gart; ++oo)
-                {
-                    if(map->version > EMapFormat::ROE)
-                    {
-                        box->artifacts.push_back(read_le_u16(buffer + pos));
-                        pos += 2;
-                    }
-                    else
-                    {
-                        box->artifacts.push_back(buffer[pos]);
-                        ++pos;
-                    }
-                }
-                int gspel = buffer[pos]; //number of gained spells
-                ++pos;
-                for(int oo = 0; oo < gspel; ++oo)
-                {
-                    box->spells.push_back(buffer[pos]);
-                    ++pos;
-                }
-                int gcre = buffer[pos]; //number of gained creatures
-                ++pos;
-                readCreatureSet(&box->creatures, gcre, map->version > EMapFormat::ROE);
-                pos += 8;
-                break;
-            }
-        case 36: //grail
-            {
-                map->grailPos = objPos;
-                map->grailRadious = read_le_u32(buffer + pos);
-                pos += 4;
-                continue;
-            }
-        //dwellings
-        case 216: //same as castle + level range
-        case 217: //same as castle
-        case 218: //level range
-            {
-                nobj = new CGDwelling;
-                CSpecObjInfo * spec = nullptr;
-                switch(defInfo->id)
-                {
-                    break; case 216: spec = new CCreGenLeveledCastleInfo;
-                    break; case 217: spec = new CCreGenAsCastleInfo;
-                    break; case 218: spec = new CCreGenLeveledInfo;
-                }
-
-                spec->player = read_le_u32(buffer + pos);
-                pos += 4;
-
-                //216 and 217
-                if (auto castleSpec = dynamic_cast<CCreGenAsCastleInfo *>(spec))
-                {
-                    castleSpec->identifier =  read_le_u32(buffer + pos);
-                    pos += 4;
-                    if(!castleSpec->identifier)
-                    {
-                        castleSpec->asCastle = false;
-                        castleSpec->castles[0] = buffer[pos];
-                        ++pos;
-                        castleSpec->castles[1] = buffer[pos];
-                        ++pos;
-                    }
-                    else
-                    {
-                        castleSpec->asCastle = true;
-                    }
-                }
-
-                //216 and 218
-                if (auto lvlSpec = dynamic_cast<CCreGenLeveledInfo *>(spec))
-                {
-                    lvlSpec->minLevel = std::max(buffer[pos], ui8(1));
-                    ++pos;
-                    lvlSpec->maxLevel = std::min(buffer[pos], ui8(7));
-                    ++pos;
-                }
-                nobj->setOwner(spec->player);
-                static_cast<CGDwelling *>(nobj)->info = spec;
-                break;
-            }
-        case 215:
-            {
-                CGQuestGuard * guard = new CGQuestGuard;
-                addQuest(guard);
-                readQuest(guard);
-                nobj = guard;
-                break;
-            }
-        case 28: //faerie ring
-        case 14: //Swan pond
-        case 38: //idol of fortune
-        case 30: //Fountain of Fortune
-        case 64: //Rally Flag
-        case 56: //oasis
-        case 96: //temple
-        case 110://Watering Hole
-        case 31: //Fountain of Youth
-        case 11: //Buoy
-        case 52: //Mermaid
-        case 94: //Stables
-            {
-                nobj = new CGBonusingObject;
-                break;
-            }
-        case 49: //Magic Well
-            {
-                nobj = new CGMagicWell;
-                break;
-            }
-        case 15: //Cover of darkness
-        case 58: //Redwood Observatory
-        case 60: //Pillar of Fire
-            {
-                nobj = new CGObservatory;
-                break;
-            }
-        case 22: //Corpse
-        case 39: //Lean To
-        case 105://Wagon
-        case 108://Warrior's Tomb
-            {
-                nobj = new CGOnceVisitable;
-                break;
-            }
-        case 8: //Boat
-            {
-                nobj = new CGBoat;
-                break;
-            }
-        case 92: //Sirens
-            {
-                nobj = new CGSirens;
-                break;
-            }
-        case 87: //Shipyard
-            {
-                nobj = new CGShipyard;
-                nobj->setOwner(read_le_u32(buffer + pos));
-                pos += 4;
-                break;
-            }
-        case 214: //hero placeholder
-            {
-                CGHeroPlaceholder * hp = new CGHeroPlaceholder;
-                nobj = hp;
-
-                int a = buffer[pos++]; //unknown byte, seems to be always 0 (if not - scream!)
-                tlog2 << "Unhandled Hero Placeholder detected: " << a << std::endl;
-
-                int htid = buffer[pos++]; //hero type id
-                nobj->subID = htid;
-
-                if(htid == 0xff)
-                {
-                    hp->power = buffer[pos++];
-                }
-                else
-                {
-                    hp->power = 0;
-                }
-
-                break;
-            }
-        case 10: //Keymaster
-            {
-                nobj = new CGKeymasterTent;
-                break;
-            }
-        case 9: //Border Guard
-            {
-                nobj = new CGBorderGuard;
-                addQuest(nobj);
-                break;
-            }
-        case 212: //Border Gate
-            {
-                nobj = new CGBorderGate;
-                addQuest (nobj);
-                break;
-            }
-        case 27: case 37: //Eye and Hut of Magi
-            {
-                nobj = new CGMagi;
-                break;
-            }
-        case 16: case 24: case 25: case 84: case 85: //treasure bank
-            {
-                nobj = new CBank;
-                break;
-            }
-        case 63: //Pyramid
-            {
-                nobj = new CGPyramid;
-                break;
-            }
-        case 13: //Cartographer
-            {
-                nobj = new CCartographer;
-                break;
-            }
-        case 48: //Magic Spring
-            {
-                nobj = new CGMagicSpring;
-                break;
-            }
-        case 97: //den of thieves
-            {
-                nobj = new CGDenOfthieves;
-                break;
-            }
-        case 57: //Obelisk
-            {
-                nobj = new CGObelisk;
-                break;
-            }
-        case 42: //Lighthouse
-            {
-                nobj = new CGLighthouse;
-                nobj->tempOwner = read_le_u32(buffer + pos);
-                pos += 4;
-                break;
-            }
-        case 2: //Altar of Sacrifice
-        case 99: //Trading Post
-        case 213: //Freelancer's Guild
-        case 221: //Trading Post (snow)
-            {
-                nobj = new CGMarket;
-                break;
-            }
-        case 104: //University
-            {
-                nobj = new CGUniversity;
-                break;
-            }
-        case 7: //Black Market
-            {
-                nobj = new CGBlackMarket;
-                break;
-            }
-        default: //any other object
-            {
-                nobj = new CGObjectInstance;
-                break;
-            }
-        }
-
-        nobj->pos = objPos;
-        nobj->ID = defInfo->id;
-        nobj->id = idToBeGiven;
-        if(nobj->ID != Obj::HERO && nobj->ID != Obj::HERO_PLACEHOLDER && nobj->ID != Obj::PRISON)
-        {
-            nobj->subID = defInfo->subid;
-        }
-        nobj->defInfo = defInfo;
-        assert(idToBeGiven == map->objects.size());
-        map->objects.push_back(nobj);
-        if(nobj->ID == Obj::TOWN)
-        {
-            map->towns.push_back(static_cast<CGTownInstance *>(nobj));
-        }
-        if(nobj->ID == Obj::HERO)
-        {
-            map->heroes.push_back(static_cast<CGHeroInstance*>(nobj));
-        }
-    }
-
-    std::sort(map->heroes.begin(), map->heroes.end(), [](const ConstTransitivePtr<CGHeroInstance> & a, const ConstTransitivePtr<CGHeroInstance> & b)
-    {
-        return a->subID < b->subID;
-    });
+	int howManyObjs = read_le_u32(buffer + pos);
+	pos += 4;
+
+	for(int ww = 0; ww < howManyObjs; ++ww)
+	{
+		CGObjectInstance * nobj = 0;
+
+		int3 objPos;
+		objPos.x = buffer[pos++];
+		objPos.y = buffer[pos++];
+		objPos.z = buffer[pos++];
+
+		int defnum = read_le_u32(buffer + pos);
+		pos += 4;
+		int idToBeGiven = map->objects.size();
+
+		CGDefInfo * defInfo = map->customDefs.at(defnum);
+		pos += 5;
+
+		switch(defInfo->id)
+		{
+		case Obj::EVENT:
+			{
+				CGEvent * evnt = new CGEvent();
+				nobj = evnt;
+
+				bool guardMess = buffer[pos];
+				++pos;
+				if(guardMess)
+				{
+					int messLong = read_le_u32(buffer + pos);
+					pos += 4;
+					if(messLong > 0)
+					{
+						for(int yy = 0; yy < messLong; ++yy)
+						{
+							evnt->message += buffer[pos + yy];
+						}
+						pos += messLong;
+					}
+					if(buffer[pos++])
+					{
+						readCreatureSet(evnt, 7, map->version > EMapFormat::ROE);
+					}
+					pos += 4;
+				}
+				evnt->gainedExp = read_le_u32(buffer + pos);
+				pos += 4;
+				evnt->manaDiff = read_le_u32(buffer + pos);
+				pos += 4;
+				evnt->moraleDiff = static_cast<char>(buffer[pos]);
+				++pos;
+				evnt->luckDiff = static_cast<char>(buffer[pos]);
+				++pos;
+
+				evnt->resources.resize(GameConstants::RESOURCE_QUANTITY);
+				for(int x = 0; x < 7; ++x)
+				{
+					evnt->resources[x] = read_le_u32(buffer + pos);
+					pos += 4;
+				}
+
+				evnt->primskills.resize(GameConstants::PRIMARY_SKILLS);
+				for(int x = 0; x < 4; ++x)
+				{
+					evnt->primskills[x] = buffer[pos];
+					++pos;
+				}
+
+				int gabn; // Number of gained abilities
+				gabn = buffer[pos];
+				++pos;
+				for(int oo = 0; oo < gabn; ++oo)
+				{
+					evnt->abilities.push_back(buffer[pos]);
+					++pos;
+					evnt->abilityLevels.push_back(buffer[pos]);
+					++pos;
+				}
+
+				int gart = buffer[pos]; // Number of gained artifacts
+				++pos;
+				for(int oo = 0; oo < gart; ++oo)
+				{
+					if(map->version == EMapFormat::ROE)
+					{
+						evnt->artifacts.push_back(buffer[pos]);
+						++pos;
+					}
+					else
+					{
+						evnt->artifacts.push_back(read_le_u16(buffer + pos));
+						pos += 2;
+					}
+				}
+
+				int gspel = buffer[pos]; // Number of gained spells
+				++pos;
+				for(int oo = 0; oo < gspel; ++oo)
+				{
+					evnt->spells.push_back(buffer[pos]);
+					++pos;
+				}
+
+				int gcre = buffer[pos]; //number of gained creatures
+				++pos;
+				readCreatureSet(&evnt->creatures, gcre, map->version > EMapFormat::ROE);
+
+				pos += 8;
+				evnt->availableFor = buffer[pos];
+				++pos;
+				evnt->computerActivate = buffer[pos];
+				++pos;
+				evnt->removeAfterVisit = buffer[pos];
+				++pos;
+				evnt->humanActivate = true;
+
+				pos += 4;
+				break;
+			}
+		case 34: case 70: case 62: //34 - hero; 70 - random hero; 62 - prison
+			{
+				nobj = readHero(idToBeGiven);
+				break;
+			}
+		case 4: //Arena
+		case 51: //Mercenary Camp
+		case 23: //Marletto Tower
+		case 61: // Star Axis
+		case 32: // Garden of Revelation
+		case 100: //Learning Stone
+		case 102: //Tree of Knowledge
+		case 41: //Library of Enlightenment
+		case 47: //School of Magic
+		case 107: //School of War
+			{
+				nobj = new CGVisitableOPH;
+				break;
+			}
+		case 55: //mystical garden
+		case 112://windmill
+		case 109://water wheel
+			{
+				nobj = new CGVisitableOPW;
+				break;
+			}
+		case 43: //teleport
+		case 44: //teleport
+		case 45: //teleport
+		case 103://subterranean gate
+		case 111://Whirlpool
+			{
+				nobj = new CGTeleport;
+				break;
+			}
+		case 12: //campfire
+		case 29: //Flotsam
+		case 82: //Sea Chest
+		case 86: //Shipwreck Survivor
+		case 101://treasure chest
+			{
+				nobj = new CGPickable;
+				break;
+			}
+		case 54:  //Monster
+		case 71: case 72: case 73: case 74: case 75:	// Random Monster 1 - 4
+		case 162: case 163: case 164:					// Random Monster 5 - 7
+			{
+				CGCreature * cre = new CGCreature;
+				nobj = cre;
+
+				if(map->version > EMapFormat::ROE)
+				{
+					cre->identifier = read_le_u32(buffer + pos);
+					pos += 4;
+					map->questIdentifierToId[cre->identifier] = idToBeGiven;
+				}
+
+				CStackInstance * hlp = new CStackInstance;
+				hlp->count = read_le_u16(buffer + pos);
+				pos += 2;
+
+				//type will be set during initialization
+				cre->putStack(0, hlp);
+
+				cre->character = buffer[pos];
+				++pos;
+				bool isMesTre = buffer[pos]; //true if there is message or treasury
+				++pos;
+				if(isMesTre)
+				{
+					cre->message = readString(buffer, pos);
+					cre->resources.resize(GameConstants::RESOURCE_QUANTITY);
+					for(int j = 0; j < 7; ++j)
+					{
+						cre->resources[j] = read_le_u32(buffer + pos);
+						pos += 4;
+					}
+
+					int artID;
+					if (map->version == EMapFormat::ROE)
+					{
+						artID = buffer[pos];
+						++pos;
+					}
+					else
+					{
+						artID = read_le_u16(buffer + pos);
+						pos += 2;
+					}
+
+					if(map->version == EMapFormat::ROE)
+					{
+						if(artID != 0xff)
+						{
+							cre->gainedArtifact = artID;
+						}
+						else
+						{
+							cre->gainedArtifact = -1;
+						}
+					}
+					else
+					{
+						if(artID != 0xffff)
+						{
+							cre->gainedArtifact = artID;
+						}
+						else
+						{
+							cre->gainedArtifact = -1;
+						}
+					}
+				}
+				cre->neverFlees = buffer[pos];
+				++pos;
+				cre->notGrowingTeam = buffer[pos];
+				++pos;
+				pos += 2;
+				break;
+			}
+		case 59: case 91: //ocean bottle and sign
+			{
+				CGSignBottle * sb = new CGSignBottle;
+				nobj = sb;
+				sb->message = readString(buffer, pos);
+				pos += 4;
+				break;
+			}
+		case 83: //seer's hut
+			{
+				nobj = readSeerHut();
+				addQuest(nobj);
+				break;
+			}
+		case 113: //witch hut
+			{
+				CGWitchHut * wh = new CGWitchHut;
+				nobj = wh;
+
+				// in reo we cannot specify it - all are allowed (I hope)
+				if(map->version > EMapFormat::ROE)
+				{
+					int ist=pos;
+					for(; pos < ist + 4; ++pos)
+					{
+						ui8 c = buffer[pos];
+						for(int yy = 0; yy < 8; ++yy)
+						{
+							if((pos - ist) * 8 + yy < GameConstants::SKILL_QUANTITY)
+							{
+								if(c == (c | static_cast<ui8>(std::pow(2., yy))))
+								{
+									wh->allowedAbilities.push_back((pos - ist) * 8 + yy);
+								}
+							}
+						}
+					}
+				}
+				else
+				{
+					// RoE map
+					for(int gg = 0; gg < GameConstants::SKILL_QUANTITY; ++gg)
+					{
+						wh->allowedAbilities.push_back(gg);
+					}
+				}
+				break;
+			}
+		case 81: //scholar
+			{
+				CGScholar * sch = new CGScholar;
+				nobj = sch;
+				sch->bonusType = buffer[pos++];
+				sch->bonusID = buffer[pos++];
+				pos += 6;
+				break;
+			}
+		case 33: case 219: //garrison
+			{
+				CGGarrison * gar = new CGGarrison;
+				nobj = gar;
+				nobj->setOwner(buffer[pos++]);
+				pos += 3;
+				readCreatureSet(gar, 7, map->version > EMapFormat::ROE);
+				if(map->version > EMapFormat::ROE)
+				{
+					gar->removableUnits = buffer[pos];
+					++pos;
+				}
+				else
+				{
+					gar->removableUnits = true;
+				}
+				pos += 8;
+				break;
+			}
+		case 5: //artifact
+		case 65: case 66: case 67: case 68: case 69: //random artifact
+		case 93: //spell scroll
+			{
+				int artID = -1;
+				int spellID = -1;
+				CGArtifact * art = new CGArtifact;
+				nobj = art;
+
+				bool areSettings = buffer[pos++];
+				if(areSettings)
+				{
+					art->message = readString(buffer, pos);
+					bool areGuards = buffer[pos++];
+					if(areGuards)
+					{
+						readCreatureSet(art, 7, map->version > EMapFormat::ROE);
+					}
+					pos += 4;
+				}
+
+				if(defInfo->id == 93)
+				{
+					spellID = read_le_u32(buffer + pos);
+					pos += 4;
+					artID = 1;
+				}
+				else if(defInfo->id == 5)
+				{
+					//specific artifact
+					artID = defInfo->subid;
+				}
+
+				art->storedArtifact = createArtifact(artID, spellID);
+				break;
+			}
+		case 76: case 79: //random resource; resource
+			{
+				CGResource * res = new CGResource;
+				nobj = res;
+
+				bool isMessGuard = buffer[pos];
+				++pos;
+				if(isMessGuard)
+				{
+					res->message = readString(buffer, pos);
+					if(buffer[pos++])
+					{
+						readCreatureSet(res, 7, map->version > EMapFormat::ROE);
+					}
+					pos += 4;
+				}
+				res->amount = read_le_u32(buffer + pos);
+				pos += 4;
+				if(defInfo->subid == 6)
+				{
+					// Gold is multiplied by 100.
+					res->amount *= 100;
+				}
+				pos += 4;
+
+				break;
+			}
+		case 77: case 98: //random town; town
+			{
+				nobj = readTown(defInfo->subid);
+				break;
+			}
+		case 53:
+		case 220://mine (?)
+			{
+				nobj = new CGMine;
+				nobj->setOwner(buffer[pos++]);
+				pos += 3;
+				break;
+			}
+		case 17: case 18: case 19: case 20: //dwellings
+			{
+				nobj = new CGDwelling;
+				nobj->setOwner(buffer[pos++]);
+				pos += 3;
+				break;
+			}
+		case 78: //Refugee Camp
+		case 106: //War Machine Factory
+			{
+				nobj = new CGDwelling;
+				break;
+			}
+		case 88: case 89: case 90: //spell shrine
+			{
+				CGShrine * shr = new CGShrine;
+				nobj = shr;
+				shr->spell = buffer[pos];
+				pos += 4;
+				break;
+			}
+		case 6: //pandora's box
+			{
+				CGPandoraBox * box = new CGPandoraBox;
+				nobj = box;
+				bool messg = buffer[pos];
+				++pos;
+				if(messg)
+				{
+					box->message = readString(buffer, pos);
+					if(buffer[pos++])
+					{
+						readCreatureSet(box, 7, map->version > EMapFormat::ROE);
+					}
+					pos += 4;
+				}
+
+				box->gainedExp = read_le_u32(buffer + pos);
+				pos += 4;
+				box->manaDiff = read_le_u32(buffer + pos);
+				pos += 4;
+				box->moraleDiff = static_cast<si8>(buffer[pos]);
+				++pos;
+				box->luckDiff = static_cast<si8>(buffer[pos]);
+				++pos;
+
+				box->resources.resize(GameConstants::RESOURCE_QUANTITY);
+				for(int x = 0; x < 7; ++x)
+				{
+					box->resources[x] = read_le_u32(buffer + pos);
+					pos += 4;
+				}
+
+				box->primskills.resize(GameConstants::PRIMARY_SKILLS);
+				for(int x = 0; x < 4; ++x)
+				{
+					box->primskills[x] = buffer[pos];
+					++pos;
+				}
+
+				int gabn; //number of gained abilities
+				gabn = buffer[pos];
+				++pos;
+				for(int oo = 0; oo < gabn; ++oo)
+				{
+					box->abilities.push_back(buffer[pos]);
+					++pos;
+					box->abilityLevels.push_back(buffer[pos]);
+					++pos;
+				}
+				int gart = buffer[pos]; //number of gained artifacts
+				++pos;
+				for(int oo = 0; oo < gart; ++oo)
+				{
+					if(map->version > EMapFormat::ROE)
+					{
+						box->artifacts.push_back(read_le_u16(buffer + pos));
+						pos += 2;
+					}
+					else
+					{
+						box->artifacts.push_back(buffer[pos]);
+						++pos;
+					}
+				}
+				int gspel = buffer[pos]; //number of gained spells
+				++pos;
+				for(int oo = 0; oo < gspel; ++oo)
+				{
+					box->spells.push_back(buffer[pos]);
+					++pos;
+				}
+				int gcre = buffer[pos]; //number of gained creatures
+				++pos;
+				readCreatureSet(&box->creatures, gcre, map->version > EMapFormat::ROE);
+				pos += 8;
+				break;
+			}
+		case 36: //grail
+			{
+				map->grailPos = objPos;
+				map->grailRadious = read_le_u32(buffer + pos);
+				pos += 4;
+				continue;
+			}
+		//dwellings
+		case 216: //same as castle + level range
+		case 217: //same as castle
+		case 218: //level range
+			{
+				nobj = new CGDwelling;
+				CSpecObjInfo * spec = nullptr;
+				switch(defInfo->id)
+				{
+					break; case 216: spec = new CCreGenLeveledCastleInfo;
+					break; case 217: spec = new CCreGenAsCastleInfo;
+					break; case 218: spec = new CCreGenLeveledInfo;
+				}
+
+				spec->player = read_le_u32(buffer + pos);
+				pos += 4;
+
+				//216 and 217
+				if (auto castleSpec = dynamic_cast<CCreGenAsCastleInfo *>(spec))
+				{
+					castleSpec->identifier =  read_le_u32(buffer + pos);
+					pos += 4;
+					if(!castleSpec->identifier)
+					{
+						castleSpec->asCastle = false;
+						castleSpec->castles[0] = buffer[pos];
+						++pos;
+						castleSpec->castles[1] = buffer[pos];
+						++pos;
+					}
+					else
+					{
+						castleSpec->asCastle = true;
+					}
+				}
+
+				//216 and 218
+				if (auto lvlSpec = dynamic_cast<CCreGenLeveledInfo *>(spec))
+				{
+					lvlSpec->minLevel = std::max(buffer[pos], ui8(1));
+					++pos;
+					lvlSpec->maxLevel = std::min(buffer[pos], ui8(7));
+					++pos;
+				}
+				nobj->setOwner(spec->player);
+				static_cast<CGDwelling *>(nobj)->info = spec;
+				break;
+			}
+		case 215:
+			{
+				CGQuestGuard * guard = new CGQuestGuard;
+				addQuest(guard);
+				readQuest(guard);
+				nobj = guard;
+				break;
+			}
+		case 28: //faerie ring
+		case 14: //Swan pond
+		case 38: //idol of fortune
+		case 30: //Fountain of Fortune
+		case 64: //Rally Flag
+		case 56: //oasis
+		case 96: //temple
+		case 110://Watering Hole
+		case 31: //Fountain of Youth
+		case 11: //Buoy
+		case 52: //Mermaid
+		case 94: //Stables
+			{
+				nobj = new CGBonusingObject;
+				break;
+			}
+		case 49: //Magic Well
+			{
+				nobj = new CGMagicWell;
+				break;
+			}
+		case 15: //Cover of darkness
+		case 58: //Redwood Observatory
+		case 60: //Pillar of Fire
+			{
+				nobj = new CGObservatory;
+				break;
+			}
+		case 22: //Corpse
+		case 39: //Lean To
+		case 105://Wagon
+		case 108://Warrior's Tomb
+			{
+				nobj = new CGOnceVisitable;
+				break;
+			}
+		case 8: //Boat
+			{
+				nobj = new CGBoat;
+				break;
+			}
+		case 92: //Sirens
+			{
+				nobj = new CGSirens;
+				break;
+			}
+		case 87: //Shipyard
+			{
+				nobj = new CGShipyard;
+				nobj->setOwner(read_le_u32(buffer + pos));
+				pos += 4;
+				break;
+			}
+		case 214: //hero placeholder
+			{
+				CGHeroPlaceholder * hp = new CGHeroPlaceholder;
+				nobj = hp;
+
+				int a = buffer[pos++]; //unknown byte, seems to be always 0 (if not - scream!)
+				tlog2 << "Unhandled Hero Placeholder detected: " << a << std::endl;
+
+				int htid = buffer[pos++]; //hero type id
+				nobj->subID = htid;
+
+				if(htid == 0xff)
+				{
+					hp->power = buffer[pos++];
+				}
+				else
+				{
+					hp->power = 0;
+				}
+
+				break;
+			}
+		case 10: //Keymaster
+			{
+				nobj = new CGKeymasterTent;
+				break;
+			}
+		case 9: //Border Guard
+			{
+				nobj = new CGBorderGuard;
+				addQuest(nobj);
+				break;
+			}
+		case 212: //Border Gate
+			{
+				nobj = new CGBorderGate;
+				addQuest (nobj);
+				break;
+			}
+		case 27: case 37: //Eye and Hut of Magi
+			{
+				nobj = new CGMagi;
+				break;
+			}
+		case 16: case 24: case 25: case 84: case 85: //treasure bank
+			{
+				nobj = new CBank;
+				break;
+			}
+		case 63: //Pyramid
+			{
+				nobj = new CGPyramid;
+				break;
+			}
+		case 13: //Cartographer
+			{
+				nobj = new CCartographer;
+				break;
+			}
+		case 48: //Magic Spring
+			{
+				nobj = new CGMagicSpring;
+				break;
+			}
+		case 97: //den of thieves
+			{
+				nobj = new CGDenOfthieves;
+				break;
+			}
+		case 57: //Obelisk
+			{
+				nobj = new CGObelisk;
+				break;
+			}
+		case 42: //Lighthouse
+			{
+				nobj = new CGLighthouse;
+				nobj->tempOwner = read_le_u32(buffer + pos);
+				pos += 4;
+				break;
+			}
+		case 2: //Altar of Sacrifice
+		case 99: //Trading Post
+		case 213: //Freelancer's Guild
+		case 221: //Trading Post (snow)
+			{
+				nobj = new CGMarket;
+				break;
+			}
+		case 104: //University
+			{
+				nobj = new CGUniversity;
+				break;
+			}
+		case 7: //Black Market
+			{
+				nobj = new CGBlackMarket;
+				break;
+			}
+		default: //any other object
+			{
+				nobj = new CGObjectInstance;
+				break;
+			}
+		}
+
+		nobj->pos = objPos;
+		nobj->ID = defInfo->id;
+		nobj->id = idToBeGiven;
+		if(nobj->ID != Obj::HERO && nobj->ID != Obj::HERO_PLACEHOLDER && nobj->ID != Obj::PRISON)
+		{
+			nobj->subID = defInfo->subid;
+		}
+		nobj->defInfo = defInfo;
+		assert(idToBeGiven == map->objects.size());
+		map->objects.push_back(nobj);
+		if(nobj->ID == Obj::TOWN)
+		{
+			map->towns.push_back(static_cast<CGTownInstance *>(nobj));
+		}
+		if(nobj->ID == Obj::HERO)
+		{
+			map->heroes.push_back(static_cast<CGHeroInstance*>(nobj));
+		}
+	}
+
+	std::sort(map->heroes.begin(), map->heroes.end(), [](const ConstTransitivePtr<CGHeroInstance> & a, const ConstTransitivePtr<CGHeroInstance> & b)
+	{
+		return a->subID < b->subID;
+	});
 }
 
 void CMapLoaderH3M::readCreatureSet(CCreatureSet * out, int number, bool version)
 {
-    const int bytesPerCre = version ? 4 : 3;
-    const int maxID = version ? 0xffff : 0xff;
-
-    for(int ir = 0; ir < number; ++ir)
-    {
-        int creID;
-        int count;
-
-        if(version)
-        {
-            creID = read_le_u16(buffer + pos + ir * bytesPerCre);
-            count = read_le_u16(buffer + pos + ir * bytesPerCre + 2);
-        }
-        else
-        {
-            creID = buffer[pos + ir * bytesPerCre];
-            count = read_le_u16(buffer + pos + ir * bytesPerCre + 1);
-        }
-
-        // Empty slot
-        if(creID == maxID) continue;
-
-        CStackInstance * hlp = new CStackInstance;
-        hlp->count = count;
-
-        if(creID > maxID - 0xf)
-        {
-            //this will happen when random object has random army
-            creID = maxID + 1 - creID + VLC->creh->creatures.size();
-            hlp->idRand = creID;
-        }
-        else
-        {
-            hlp->setType(creID);
-        }
-
-        out->putStack(ir, hlp);
-    }
-
-    pos += number * bytesPerCre;
-    out->validTypes(true);
+	const int bytesPerCre = version ? 4 : 3;
+	const int maxID = version ? 0xffff : 0xff;
+
+	for(int ir = 0; ir < number; ++ir)
+	{
+		int creID;
+		int count;
+
+		if(version)
+		{
+			creID = read_le_u16(buffer + pos + ir * bytesPerCre);
+			count = read_le_u16(buffer + pos + ir * bytesPerCre + 2);
+		}
+		else
+		{
+			creID = buffer[pos + ir * bytesPerCre];
+			count = read_le_u16(buffer + pos + ir * bytesPerCre + 1);
+		}
+
+		// Empty slot
+		if(creID == maxID) continue;
+
+		CStackInstance * hlp = new CStackInstance;
+		hlp->count = count;
+
+		if(creID > maxID - 0xf)
+		{
+			//this will happen when random object has random army
+			creID = maxID + 1 - creID + VLC->creh->creatures.size();
+			hlp->idRand = creID;
+		}
+		else
+		{
+			hlp->setType(creID);
+		}
+
+		out->putStack(ir, hlp);
+	}
+
+	pos += number * bytesPerCre;
+	out->validTypes(true);
 }
 
 CGObjectInstance * CMapLoaderH3M::readHero(int idToBeGiven)
 {
-    CGHeroInstance * nhi = new CGHeroInstance;
-
-    int identifier = 0;
-    if(map->version > EMapFormat::ROE)
-    {
-        identifier = read_le_u32(buffer + pos);
-        pos += 4;
-        map->questIdentifierToId[identifier] = idToBeGiven;
-    }
-
-    ui8 owner = buffer[pos++];
-    nhi->subID = buffer[pos++];
-
-    for(int j = 0; j < map->predefinedHeroes.size(); ++j)
-    {
-        if(map->predefinedHeroes[j]->subID == nhi->subID)
-        {
-            tlog0 << "Hero " << nhi->subID << " will be taken from the predefined heroes list." << std::endl;
-            delete nhi;
-            nhi = map->predefinedHeroes[j];
-            break;
-        }
-    }
-    nhi->setOwner(owner);
-
-    nhi->portrait = nhi->subID;
-
-    for(int j = 0; j < map->disposedHeroes.size(); ++j)
-    {
-        if(map->disposedHeroes[j].heroId == nhi->subID)
-        {
-            nhi->name = map->disposedHeroes[j].name;
-            nhi->portrait = map->disposedHeroes[j].portrait;
-            break;
-        }
-    }
-
-    // True if hero has nonstandard name
-    if(readChar(buffer, pos))
-    {
-        nhi->name = readString(buffer, pos);
-    }
-    if(map->version > EMapFormat::AB)
-    {
-        // True if hero's experience is greater than 0
-        if(readChar(buffer, pos))
-        {
-            nhi->exp = read_le_u32(buffer + pos);
-            pos += 4;
-        }
-        else
-        {
-            nhi->exp = 0xffffffff;
-        }
-    }
-    else
-    {
-        nhi->exp = read_le_u32(buffer + pos);
-        pos += 4;
-
-        //0 means "not set" in <=AB maps
-        if(!nhi->exp)
-        {
-            nhi->exp = 0xffffffff;
-        }
-    }
-
-    bool portrait = buffer[pos];
-    ++pos;
-    if(portrait)
-    {
-        nhi->portrait = buffer[pos++];
-    }
-
-    // True if hero has specified abilities
-    if(readChar(buffer, pos))
-    {
-        int howMany = read_le_u32(buffer + pos);
-        pos += 4;
-        nhi->secSkills.resize(howMany);
-        for(int yy = 0; yy < howMany; ++yy)
-        {
-            nhi->secSkills[yy].first = buffer[pos++];
-            nhi->secSkills[yy].second = buffer[pos++];
-        }
-    }
-
-    // True if hero has nonstandard garrison
-    if(readChar(buffer, pos))
-    {
-        readCreatureSet(nhi, 7, map->version > EMapFormat::ROE);
-    }
-
-    nhi->formation = buffer[pos];
-    ++pos;
-    loadArtifactsOfHero(nhi);
-    nhi->patrol.patrolRadious = buffer[pos];
-    ++pos;
-    if(nhi->patrol.patrolRadious == 0xff)
-    {
-        nhi->patrol.patrolling = false;
-    }
-    else
-    {
-        nhi->patrol.patrolling = true;
-    }
-
-    if(map->version > EMapFormat::ROE)
-    {
-        // True if hero has nonstandard (mapmaker defined) biography
-        if(readChar(buffer, pos))
-        {
-            nhi->biography = readString(buffer, pos);
-        }
-        nhi->sex = buffer[pos];
-        ++pos;
-
-        // Remove trash
-        if (nhi->sex != 0xFF)
-        {
-            nhi->sex &= 1;
-        }
-    }
-    else
-    {
-        nhi->sex = 0xFF;
-    }
-
-    // Spells
-    if(map->version > EMapFormat::AB)
-    {
-        bool areSpells = buffer[pos];
-        ++pos;
-
-        if(areSpells)
-        {
-            nhi->spells.insert(0xffffffff); //placeholder "preset spells"
-            int ist = pos;
-            for(; pos < ist + 9; ++pos)
-            {
-                ui8 c = buffer[pos];
-                for(int yy = 0; yy < 8; ++yy)
-                {
-                    if((pos - ist) * 8 + yy < GameConstants::SPELLS_QUANTITY)
-                    {
-                        if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-                        {
-                            nhi->spells.insert((pos - ist) * 8 + yy);
-                        }
-                    }
-                }
-            }
-        }
-    }
-    else if(map->version == EMapFormat::AB)
-    {
-        //we can read one spell
-        ui8 buff = buffer[pos];
-        ++pos;
-        if(buff != 254)
-        {
-            nhi->spells.insert(0xffffffff); //placeholder "preset spells"
-            if(buff < 254) //255 means no spells
-            {
-                nhi->spells.insert(buff);
-            }
-        }
-    }
-
-    if(map->version > EMapFormat::AB)
-    {
-        //customPrimSkills
-        if(readChar(buffer, pos))
-        {
-            for(int xx = 0; xx < GameConstants::PRIMARY_SKILLS; ++xx)
-            {
-                nhi->pushPrimSkill(xx, buffer[pos++]);
-            }
-        }
-    }
-    pos += 16;
-
-    return nhi;
+	CGHeroInstance * nhi = new CGHeroInstance;
+
+	int identifier = 0;
+	if(map->version > EMapFormat::ROE)
+	{
+		identifier = read_le_u32(buffer + pos);
+		pos += 4;
+		map->questIdentifierToId[identifier] = idToBeGiven;
+	}
+
+	ui8 owner = buffer[pos++];
+	nhi->subID = buffer[pos++];
+
+	for(int j = 0; j < map->predefinedHeroes.size(); ++j)
+	{
+		if(map->predefinedHeroes[j]->subID == nhi->subID)
+		{
+			tlog0 << "Hero " << nhi->subID << " will be taken from the predefined heroes list." << std::endl;
+			delete nhi;
+			nhi = map->predefinedHeroes[j];
+			break;
+		}
+	}
+	nhi->setOwner(owner);
+
+	nhi->portrait = nhi->subID;
+
+	for(int j = 0; j < map->disposedHeroes.size(); ++j)
+	{
+		if(map->disposedHeroes[j].heroId == nhi->subID)
+		{
+			nhi->name = map->disposedHeroes[j].name;
+			nhi->portrait = map->disposedHeroes[j].portrait;
+			break;
+		}
+	}
+
+	// True if hero has nonstandard name
+	if(readChar(buffer, pos))
+	{
+		nhi->name = readString(buffer, pos);
+	}
+	if(map->version > EMapFormat::AB)
+	{
+		// True if hero's experience is greater than 0
+		if(readChar(buffer, pos))
+		{
+			nhi->exp = read_le_u32(buffer + pos);
+			pos += 4;
+		}
+		else
+		{
+			nhi->exp = 0xffffffff;
+		}
+	}
+	else
+	{
+		nhi->exp = read_le_u32(buffer + pos);
+		pos += 4;
+
+		//0 means "not set" in <=AB maps
+		if(!nhi->exp)
+		{
+			nhi->exp = 0xffffffff;
+		}
+	}
+
+	bool portrait = buffer[pos];
+	++pos;
+	if(portrait)
+	{
+		nhi->portrait = buffer[pos++];
+	}
+
+	// True if hero has specified abilities
+	if(readChar(buffer, pos))
+	{
+		int howMany = read_le_u32(buffer + pos);
+		pos += 4;
+		nhi->secSkills.resize(howMany);
+		for(int yy = 0; yy < howMany; ++yy)
+		{
+			nhi->secSkills[yy].first = buffer[pos++];
+			nhi->secSkills[yy].second = buffer[pos++];
+		}
+	}
+
+	// True if hero has nonstandard garrison
+	if(readChar(buffer, pos))
+	{
+		readCreatureSet(nhi, 7, map->version > EMapFormat::ROE);
+	}
+
+	nhi->formation = buffer[pos];
+	++pos;
+	loadArtifactsOfHero(nhi);
+	nhi->patrol.patrolRadious = buffer[pos];
+	++pos;
+	if(nhi->patrol.patrolRadious == 0xff)
+	{
+		nhi->patrol.patrolling = false;
+	}
+	else
+	{
+		nhi->patrol.patrolling = true;
+	}
+
+	if(map->version > EMapFormat::ROE)
+	{
+		// True if hero has nonstandard (mapmaker defined) biography
+		if(readChar(buffer, pos))
+		{
+			nhi->biography = readString(buffer, pos);
+		}
+		nhi->sex = buffer[pos];
+		++pos;
+
+		// Remove trash
+		if (nhi->sex != 0xFF)
+		{
+			nhi->sex &= 1;
+		}
+	}
+	else
+	{
+		nhi->sex = 0xFF;
+	}
+
+	// Spells
+	if(map->version > EMapFormat::AB)
+	{
+		bool areSpells = buffer[pos];
+		++pos;
+
+		if(areSpells)
+		{
+			nhi->spells.insert(0xffffffff); //placeholder "preset spells"
+			int ist = pos;
+			for(; pos < ist + 9; ++pos)
+			{
+				ui8 c = buffer[pos];
+				for(int yy = 0; yy < 8; ++yy)
+				{
+					if((pos - ist) * 8 + yy < GameConstants::SPELLS_QUANTITY)
+					{
+						if(c == (c | static_cast<ui8>(std::pow(2., yy))))
+						{
+							nhi->spells.insert((pos - ist) * 8 + yy);
+						}
+					}
+				}
+			}
+		}
+	}
+	else if(map->version == EMapFormat::AB)
+	{
+		//we can read one spell
+		ui8 buff = buffer[pos];
+		++pos;
+		if(buff != 254)
+		{
+			nhi->spells.insert(0xffffffff); //placeholder "preset spells"
+			if(buff < 254) //255 means no spells
+			{
+				nhi->spells.insert(buff);
+			}
+		}
+	}
+
+	if(map->version > EMapFormat::AB)
+	{
+		//customPrimSkills
+		if(readChar(buffer, pos))
+		{
+			for(int xx = 0; xx < GameConstants::PRIMARY_SKILLS; ++xx)
+			{
+				nhi->pushPrimSkill(xx, buffer[pos++]);
+			}
+		}
+	}
+	pos += 16;
+
+	return nhi;
 }
 
 CGSeerHut * CMapLoaderH3M::readSeerHut()
 {
-    CGSeerHut * hut = new CGSeerHut;
-
-    if(map->version > EMapFormat::ROE)
-    {
-        readQuest(hut);
-    }
-    else
-    {
-        //RoE
-        int artID = buffer[pos];
-        ++pos;
-        if (artID != 255)
-        {
-            //not none quest
-            hut->quest->m5arts.push_back (artID);
-            hut->quest->missionType = CQuest::MISSION_ART;
-        }
-        else
-        {
-            hut->quest->missionType = CQuest::MISSION_NONE;
-        }
-        hut->quest->lastDay = -1; //no timeout
-        hut->quest->isCustomFirst = hut->quest->isCustomNext = hut->quest->isCustomComplete = false;
-    }
-
-    if (hut->quest->missionType)
-    {
-        ui8 rewardType = buffer[pos];
-        ++pos;
-        hut->rewardType = rewardType;
-
-        switch(rewardType)
-        {
-        case 1:
-            {
-                hut->rVal = read_le_u32(buffer + pos);
-                pos += 4;
-                break;
-            }
-        case 2:
-            {
-                hut->rVal = read_le_u32(buffer + pos);
-                pos += 4;
-                break;
-            }
-        case 3:
-            {
-                hut->rVal = buffer[pos];
-                ++pos;
-                break;
-            }
-        case 4:
-            {
-                hut->rVal = buffer[pos];
-                ++pos;
-                break;
-            }
-        case 5:
-            {
-                hut->rID = buffer[pos];
-                ++pos;
-                // Only the first 3 bytes are used. Skip the 4th.
-                hut->rVal = read_le_u32(buffer + pos) & 0x00ffffff;
-                pos += 4;
-                break;
-            }
-        case 6:
-            {
-                hut->rID = buffer[pos];
-                ++pos;
-                hut->rVal = buffer[pos];
-                ++pos;
-                break;
-            }
-        case 7:
-            {
-                hut->rID = buffer[pos];
-                ++pos;
-                hut->rVal = buffer[pos];
-                ++pos;
-                break;
-            }
-        case 8:
-            {
-                if (map->version == EMapFormat::ROE)
-                {
-                    hut->rID = buffer[pos];
-                    ++pos;
-                }
-                else
-                {
-                    hut->rID = read_le_u16(buffer + pos);
-                    pos += 2;
-                }
-                break;
-            }
-        case 9:
-            {
-                hut->rID = buffer[pos];
-                ++pos;
-                break;
-            }
-        case 10:
-            {
-                if(map->version > EMapFormat::ROE)
-                {
-                    hut->rID = read_le_u16(buffer + pos);
-                    pos += 2;
-                    hut->rVal = read_le_u16(buffer + pos);
-                    pos += 2;
-                }
-                else
-                {
-                    hut->rID = buffer[pos];
-                    ++pos;
-                    hut->rVal = read_le_u16(buffer + pos);
-                    pos += 2;
-                }
-                break;
-            }
-        }
-        pos += 2;
-    }
-    else
-    {
-        // missionType==255
-        pos += 3;
-    }
-
-    return hut;
+	CGSeerHut * hut = new CGSeerHut;
+
+	if(map->version > EMapFormat::ROE)
+	{
+		readQuest(hut);
+	}
+	else
+	{
+		//RoE
+		int artID = buffer[pos];
+		++pos;
+		if (artID != 255)
+		{
+			//not none quest
+			hut->quest->m5arts.push_back (artID);
+			hut->quest->missionType = CQuest::MISSION_ART;
+		}
+		else
+		{
+			hut->quest->missionType = CQuest::MISSION_NONE;
+		}
+		hut->quest->lastDay = -1; //no timeout
+		hut->quest->isCustomFirst = hut->quest->isCustomNext = hut->quest->isCustomComplete = false;
+	}
+
+	if (hut->quest->missionType)
+	{
+		ui8 rewardType = buffer[pos];
+		++pos;
+		hut->rewardType = rewardType;
+
+		switch(rewardType)
+		{
+		case 1:
+			{
+				hut->rVal = read_le_u32(buffer + pos);
+				pos += 4;
+				break;
+			}
+		case 2:
+			{
+				hut->rVal = read_le_u32(buffer + pos);
+				pos += 4;
+				break;
+			}
+		case 3:
+			{
+				hut->rVal = buffer[pos];
+				++pos;
+				break;
+			}
+		case 4:
+			{
+				hut->rVal = buffer[pos];
+				++pos;
+				break;
+			}
+		case 5:
+			{
+				hut->rID = buffer[pos];
+				++pos;
+				// Only the first 3 bytes are used. Skip the 4th.
+				hut->rVal = read_le_u32(buffer + pos) & 0x00ffffff;
+				pos += 4;
+				break;
+			}
+		case 6:
+			{
+				hut->rID = buffer[pos];
+				++pos;
+				hut->rVal = buffer[pos];
+				++pos;
+				break;
+			}
+		case 7:
+			{
+				hut->rID = buffer[pos];
+				++pos;
+				hut->rVal = buffer[pos];
+				++pos;
+				break;
+			}
+		case 8:
+			{
+				if (map->version == EMapFormat::ROE)
+				{
+					hut->rID = buffer[pos];
+					++pos;
+				}
+				else
+				{
+					hut->rID = read_le_u16(buffer + pos);
+					pos += 2;
+				}
+				break;
+			}
+		case 9:
+			{
+				hut->rID = buffer[pos];
+				++pos;
+				break;
+			}
+		case 10:
+			{
+				if(map->version > EMapFormat::ROE)
+				{
+					hut->rID = read_le_u16(buffer + pos);
+					pos += 2;
+					hut->rVal = read_le_u16(buffer + pos);
+					pos += 2;
+				}
+				else
+				{
+					hut->rID = buffer[pos];
+					++pos;
+					hut->rVal = read_le_u16(buffer + pos);
+					pos += 2;
+				}
+				break;
+			}
+		}
+		pos += 2;
+	}
+	else
+	{
+		// missionType==255
+		pos += 3;
+	}
+
+	return hut;
 }
 
 void CMapLoaderH3M::readQuest(IQuestObject * guard)
 {
-    guard->quest->missionType = buffer[pos];
-    ++pos;
-
-    switch(guard->quest->missionType)
-    {
-    case 0:
-        return;
-    case 2:
-        {
-            guard->quest->m2stats.resize(4);
-            for(int x = 0; x < 4; ++x)
-            {
-                guard->quest->m2stats[x] = buffer[pos++];
-            }
-        }
-        break;
-    case 1:
-    case 3:
-    case 4:
-        {
-            guard->quest->m13489val = read_le_u32(buffer + pos);
-            pos += 4;
-            break;
-        }
-    case 5:
-        {
-            int artNumber = buffer[pos];
-            ++pos;
-            for(int yy = 0; yy < artNumber; ++yy)
-            {
-                int artid = read_le_u16(buffer + pos);
-                pos += 2;
-                guard->quest->m5arts.push_back(artid);
-                map->allowedArtifact[artid] = false; //these are unavailable for random generation
-            }
-            break;
-        }
-    case 6:
-        {
-            int typeNumber = buffer[pos];
-            ++pos;
-            guard->quest->m6creatures.resize(typeNumber);
-            for(int hh = 0; hh < typeNumber; ++hh)
-            {
-                guard->quest->m6creatures[hh].type = VLC->creh->creatures[read_le_u16(buffer + pos)];
-                pos += 2;
-                guard->quest->m6creatures[hh].count = read_le_u16(buffer + pos);
-                pos += 2;
-            }
-            break;
-        }
-    case 7:
-        {
-            guard->quest->m7resources.resize(7);
-            for(int x = 0; x < 7; ++x)
-            {
-                guard->quest->m7resources[x] = read_le_u32(buffer + pos);
-                pos += 4;
-            }
-            break;
-        }
-    case 8:
-    case 9:
-        {
-            guard->quest->m13489val = buffer[pos];
-            ++pos;
-            break;
-        }
-    }
-
-    int limit = read_le_u32(buffer + pos);
-    pos += 4;
-    if(limit == (static_cast<int>(0xffffffff)))
-    {
-        guard->quest->lastDay = -1;
-    }
-    else
-    {
-        guard->quest->lastDay = limit;
-    }
-    guard->quest->firstVisitText = readString(buffer, pos);
-    guard->quest->nextVisitText = readString(buffer, pos);
-    guard->quest->completedText = readString(buffer, pos);
-    guard->quest->isCustomFirst = guard->quest->firstVisitText.size() > 0;
-    guard->quest->isCustomNext = guard->quest->nextVisitText.size() > 0;
-    guard->quest->isCustomComplete = guard->quest->completedText.size() > 0;
+	guard->quest->missionType = buffer[pos];
+	++pos;
+
+	switch(guard->quest->missionType)
+	{
+	case 0:
+		return;
+	case 2:
+		{
+			guard->quest->m2stats.resize(4);
+			for(int x = 0; x < 4; ++x)
+			{
+				guard->quest->m2stats[x] = buffer[pos++];
+			}
+		}
+		break;
+	case 1:
+	case 3:
+	case 4:
+		{
+			guard->quest->m13489val = read_le_u32(buffer + pos);
+			pos += 4;
+			break;
+		}
+	case 5:
+		{
+			int artNumber = buffer[pos];
+			++pos;
+			for(int yy = 0; yy < artNumber; ++yy)
+			{
+				int artid = read_le_u16(buffer + pos);
+				pos += 2;
+				guard->quest->m5arts.push_back(artid);
+				map->allowedArtifact[artid] = false; //these are unavailable for random generation
+			}
+			break;
+		}
+	case 6:
+		{
+			int typeNumber = buffer[pos];
+			++pos;
+			guard->quest->m6creatures.resize(typeNumber);
+			for(int hh = 0; hh < typeNumber; ++hh)
+			{
+				guard->quest->m6creatures[hh].type = VLC->creh->creatures[read_le_u16(buffer + pos)];
+				pos += 2;
+				guard->quest->m6creatures[hh].count = read_le_u16(buffer + pos);
+				pos += 2;
+			}
+			break;
+		}
+	case 7:
+		{
+			guard->quest->m7resources.resize(7);
+			for(int x = 0; x < 7; ++x)
+			{
+				guard->quest->m7resources[x] = read_le_u32(buffer + pos);
+				pos += 4;
+			}
+			break;
+		}
+	case 8:
+	case 9:
+		{
+			guard->quest->m13489val = buffer[pos];
+			++pos;
+			break;
+		}
+	}
+
+	int limit = read_le_u32(buffer + pos);
+	pos += 4;
+	if(limit == (static_cast<int>(0xffffffff)))
+	{
+		guard->quest->lastDay = -1;
+	}
+	else
+	{
+		guard->quest->lastDay = limit;
+	}
+	guard->quest->firstVisitText = readString(buffer, pos);
+	guard->quest->nextVisitText = readString(buffer, pos);
+	guard->quest->completedText = readString(buffer, pos);
+	guard->quest->isCustomFirst = guard->quest->firstVisitText.size() > 0;
+	guard->quest->isCustomNext = guard->quest->nextVisitText.size() > 0;
+	guard->quest->isCustomComplete = guard->quest->completedText.size() > 0;
 }
 
 void CMapLoaderH3M::addQuest(CGObjectInstance * quest)
 {
-    auto q = dynamic_cast<IQuestObject *>(quest);
-    q->quest->qid = map->quests.size();
-    map->quests.push_back(q->quest);
+	auto q = dynamic_cast<IQuestObject *>(quest);
+	q->quest->qid = map->quests.size();
+	map->quests.push_back(q->quest);
 }
 
 CGTownInstance * CMapLoaderH3M::readTown(int castleID)
 {
-    CGTownInstance * nt = new CGTownInstance;
-    nt->identifier = 0;
-    if(map->version > EMapFormat::ROE)
-    {
-        nt->identifier = read_le_u32(buffer + pos);
-        pos += 4;
-    }
-    nt->tempOwner = buffer[pos];
-    ++pos;
-    if(readChar(buffer, pos))
-    {
-        // Has name
-        nt->name = readString(buffer, pos);
-    }
-
-    // True if garrison isn't empty
-    if(readChar(buffer, pos))
-    {
-        readCreatureSet(nt, 7, map->version > EMapFormat::ROE);
-    }
-    nt->formation = buffer[pos];
-    ++pos;
-
-    // Custom buildings info
-    if(readChar(buffer, pos))
-    {
-        // Built buildings
-        for(int byte = 0; byte < 6; ++byte)
-        {
-            for(int bit = 0; bit < 8; ++bit)
-            {
-                if(buffer[pos] & (1 << bit))
-                {
-                    nt->builtBuildings.insert(byte * 8 + bit);
-                }
-            }
-            ++pos;
-        }
-
-        // Forbidden buildings
-        for(int byte = 6; byte < 12; ++byte)
-        {
-            for(int bit = 0; bit < 8; ++bit)
-            {
-                if(buffer[pos] & (1 << bit))
-                {
-                    nt->forbiddenBuildings.insert((byte - 6) * 8 + bit);
-                }
-            }
-            ++pos;
-        }
-        nt->builtBuildings = convertBuildings(nt->builtBuildings, castleID);
-        nt->forbiddenBuildings = convertBuildings(nt->forbiddenBuildings, castleID);
-    }
-    // Standard buildings
-    else
-    {
-        if(readChar(buffer, pos))
-        {
-            // Has fort
-            nt->builtBuildings.insert(EBuilding::FORT);
-        }
-
-        //means that set of standard building should be included
-        nt->builtBuildings.insert(-50);
-    }
-
-    int ist = pos;
-    if(map->version > EMapFormat::ROE)
-    {
-        for(; pos < ist + 9; ++pos)
-        {
-            ui8 c = buffer[pos];
-            for(int yy = 0; yy < 8; ++yy)
-            {
-                if((pos - ist) * 8 + yy < GameConstants::SPELLS_QUANTITY)
-                {
-                    if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-                    {
-                        nt->obligatorySpells.push_back((pos - ist) * 8 + yy);
-                    }
-                }
-            }
-        }
-    }
-
-    ist = pos;
-    for(; pos < ist + 9; ++pos)
-    {
-        ui8 c = buffer[pos];
-        for(int yy = 0; yy < 8; ++yy)
-        {
-            if((pos - ist) * 8 + yy < GameConstants::SPELLS_QUANTITY)
-            {
-                if(c == (c | static_cast<ui8>(std::pow(2., yy))))
-                {
-                    nt->possibleSpells.push_back((pos - ist) * 8 + yy);
-                }
-            }
-        }
-    }
-
-    // Read castle events
-    int numberOfEvent = read_le_u32(buffer + pos);
-    pos += 4;
-
-    for(int gh = 0; gh < numberOfEvent; ++gh)
-    {
-        CCastleEvent * nce = new CCastleEvent;
-        nce->town = nt;
-        nce->name = readString(buffer, pos);
-        nce->message = readString(buffer, pos);
-        for(int x = 0; x < 7; ++x)
-        {
-            nce->resources[x] = read_le_u32(buffer + pos);
-            pos += 4;
-        }
-
-        nce->players = buffer[pos];
-        ++pos;
-        if(map->version > EMapFormat::AB)
-        {
-            nce->humanAffected = buffer[pos];
-            ++pos;
-        }
-        else
-        {
-            nce->humanAffected = true;
-        }
-
-        nce->computerAffected = buffer[pos];
-        ++pos;
-        nce->firstOccurence = read_le_u16(buffer + pos);
-        pos += 2;
-        nce->nextOccurence = buffer[pos];
-        ++pos;
-
-        pos += 17;
-
-        // New buildings
-        for(int byte = 0; byte < 6; ++byte)
-        {
-            for(int bit = 0; bit < 8; ++bit)
-            {
-                if(buffer[pos] & (1 << bit))
-                {
-                    nce->buildings.insert(byte * 8 + bit);
-                }
-            }
-            ++pos;
-        }
-        nce->buildings = convertBuildings(nce->buildings, castleID, false);
-
-        nce->creatures.resize(7);
-        for(int vv = 0; vv < 7; ++vv)
-        {
-            nce->creatures[vv] = read_le_u16(buffer + pos);
-            pos += 2;
-        }
-        pos += 4;
-        nt->events.push_back(nce);
-    }
-
-    if(map->version > EMapFormat::AB)
-    {
-        nt->alignment = buffer[pos];
-        ++pos;
-    }
-    else
-    {
-        nt->alignment = 0xff;
-    }
-    pos += 3;
-
-    nt->builded = 0;
-    nt->destroyed = 0;
-    nt->garrisonHero = nullptr;
-
-    return nt;
+	CGTownInstance * nt = new CGTownInstance;
+	nt->identifier = 0;
+	if(map->version > EMapFormat::ROE)
+	{
+		nt->identifier = read_le_u32(buffer + pos);
+		pos += 4;
+	}
+	nt->tempOwner = buffer[pos];
+	++pos;
+	if(readChar(buffer, pos))
+	{
+		// Has name
+		nt->name = readString(buffer, pos);
+	}
+
+	// True if garrison isn't empty
+	if(readChar(buffer, pos))
+	{
+		readCreatureSet(nt, 7, map->version > EMapFormat::ROE);
+	}
+	nt->formation = buffer[pos];
+	++pos;
+
+	// Custom buildings info
+	if(readChar(buffer, pos))
+	{
+		// Built buildings
+		for(int byte = 0; byte < 6; ++byte)
+		{
+			for(int bit = 0; bit < 8; ++bit)
+			{
+				if(buffer[pos] & (1 << bit))
+				{
+					nt->builtBuildings.insert(byte * 8 + bit);
+				}
+			}
+			++pos;
+		}
+
+		// Forbidden buildings
+		for(int byte = 6; byte < 12; ++byte)
+		{
+			for(int bit = 0; bit < 8; ++bit)
+			{
+				if(buffer[pos] & (1 << bit))
+				{
+					nt->forbiddenBuildings.insert((byte - 6) * 8 + bit);
+				}
+			}
+			++pos;
+		}
+		nt->builtBuildings = convertBuildings(nt->builtBuildings, castleID);
+		nt->forbiddenBuildings = convertBuildings(nt->forbiddenBuildings, castleID);
+	}
+	// Standard buildings
+	else
+	{
+		if(readChar(buffer, pos))
+		{
+			// Has fort
+			nt->builtBuildings.insert(EBuilding::FORT);
+		}
+
+		//means that set of standard building should be included
+		nt->builtBuildings.insert(-50);
+	}
+
+	int ist = pos;
+	if(map->version > EMapFormat::ROE)
+	{
+		for(; pos < ist + 9; ++pos)
+		{
+			ui8 c = buffer[pos];
+			for(int yy = 0; yy < 8; ++yy)
+			{
+				if((pos - ist) * 8 + yy < GameConstants::SPELLS_QUANTITY)
+				{
+					if(c == (c | static_cast<ui8>(std::pow(2., yy))))
+					{
+						nt->obligatorySpells.push_back((pos - ist) * 8 + yy);
+					}
+				}
+			}
+		}
+	}
+
+	ist = pos;
+	for(; pos < ist + 9; ++pos)
+	{
+		ui8 c = buffer[pos];
+		for(int yy = 0; yy < 8; ++yy)
+		{
+			if((pos - ist) * 8 + yy < GameConstants::SPELLS_QUANTITY)
+			{
+				if(c == (c | static_cast<ui8>(std::pow(2., yy))))
+				{
+					nt->possibleSpells.push_back((pos - ist) * 8 + yy);
+				}
+			}
+		}
+	}
+
+	// Read castle events
+	int numberOfEvent = read_le_u32(buffer + pos);
+	pos += 4;
+
+	for(int gh = 0; gh < numberOfEvent; ++gh)
+	{
+		CCastleEvent * nce = new CCastleEvent;
+		nce->town = nt;
+		nce->name = readString(buffer, pos);
+		nce->message = readString(buffer, pos);
+		for(int x = 0; x < 7; ++x)
+		{
+			nce->resources[x] = read_le_u32(buffer + pos);
+			pos += 4;
+		}
+
+		nce->players = buffer[pos];
+		++pos;
+		if(map->version > EMapFormat::AB)
+		{
+			nce->humanAffected = buffer[pos];
+			++pos;
+		}
+		else
+		{
+			nce->humanAffected = true;
+		}
+
+		nce->computerAffected = buffer[pos];
+		++pos;
+		nce->firstOccurence = read_le_u16(buffer + pos);
+		pos += 2;
+		nce->nextOccurence = buffer[pos];
+		++pos;
+
+		pos += 17;
+
+		// New buildings
+		for(int byte = 0; byte < 6; ++byte)
+		{
+			for(int bit = 0; bit < 8; ++bit)
+			{
+				if(buffer[pos] & (1 << bit))
+				{
+					nce->buildings.insert(byte * 8 + bit);
+				}
+			}
+			++pos;
+		}
+		nce->buildings = convertBuildings(nce->buildings, castleID, false);
+
+		nce->creatures.resize(7);
+		for(int vv = 0; vv < 7; ++vv)
+		{
+			nce->creatures[vv] = read_le_u16(buffer + pos);
+			pos += 2;
+		}
+		pos += 4;
+		nt->events.push_back(nce);
+	}
+
+	if(map->version > EMapFormat::AB)
+	{
+		nt->alignment = buffer[pos];
+		++pos;
+	}
+	else
+	{
+		nt->alignment = 0xff;
+	}
+	pos += 3;
+
+	nt->builded = 0;
+	nt->destroyed = 0;
+	nt->garrisonHero = nullptr;
+
+	return nt;
 }
 
 std::set<si32> CMapLoaderH3M::convertBuildings(const std::set<si32> h3m, int castleID, bool addAuxiliary /*= true*/)
 {
-    std::map<int, int> mapa;
-    std::set<si32> ret;
-
-    // Note: this file is parsed many times.
-    const JsonNode config(ResourceID("config/buildings5.json"));
-
-    BOOST_FOREACH(const JsonNode & entry, config["table"].Vector())
-    {
-        int town = entry["town"].Float();
-
-        if (town == castleID || town == -1)
-        {
-            mapa[entry["h3"].Float()] = entry["vcmi"].Float();
-        }
-    }
-
-    for(auto i = h3m.begin(); i != h3m.end(); ++i)
-    {
-        if(mapa[*i] >= 0)
-        {
-            ret.insert(mapa[*i]);
-        }
-        // horde buildings
-        else if(mapa[*i] >= (-GameConstants::CREATURES_PER_TOWN))
-        {
-            int level = (mapa[*i]);
-
-            //(-30)..(-36) - horde buildings (for game loading only), don't see other way to handle hordes in random towns
-            ret.insert(level - 30);
-        }
-        else
-        {
-            tlog3 << "Conversion warning: unknown building " << *i << " in castle "
-                  << castleID << std::endl;
-        }
-    }
-
-    if(addAuxiliary)
-    {
-        //village hall is always present
-        ret.insert(EBuilding::VILLAGE_HALL);
-    }
-
-    if(ret.find(EBuilding::CITY_HALL) != ret.end())
-    {
-        ret.insert(EBuilding::EXTRA_CITY_HALL);
-    }
-    if(ret.find(EBuilding::TOWN_HALL) != ret.end())
-    {
-        ret.insert(EBuilding::EXTRA_TOWN_HALL);
-    }
-    if(ret.find(EBuilding::CAPITOL) != ret.end())
-    {
-        ret.insert(EBuilding::EXTRA_CAPITOL);
-    }
-
-    return ret;
+	std::map<int, int> mapa;
+	std::set<si32> ret;
+
+	// Note: this file is parsed many times.
+	const JsonNode config(ResourceID("config/buildings5.json"));
+
+	BOOST_FOREACH(const JsonNode & entry, config["table"].Vector())
+	{
+		int town = entry["town"].Float();
+
+		if (town == castleID || town == -1)
+		{
+			mapa[entry["h3"].Float()] = entry["vcmi"].Float();
+		}
+	}
+
+	for(auto i = h3m.begin(); i != h3m.end(); ++i)
+	{
+		if(mapa[*i] >= 0)
+		{
+			ret.insert(mapa[*i]);
+		}
+		// horde buildings
+		else if(mapa[*i] >= (-GameConstants::CREATURES_PER_TOWN))
+		{
+			int level = (mapa[*i]);
+
+			//(-30)..(-36) - horde buildings (for game loading only), don't see other way to handle hordes in random towns
+			ret.insert(level - 30);
+		}
+		else
+		{
+			tlog3 << "Conversion warning: unknown building " << *i << " in castle "
+				  << castleID << std::endl;
+		}
+	}
+
+	if(addAuxiliary)
+	{
+		//village hall is always present
+		ret.insert(EBuilding::VILLAGE_HALL);
+	}
+
+	if(ret.find(EBuilding::CITY_HALL) != ret.end())
+	{
+		ret.insert(EBuilding::EXTRA_CITY_HALL);
+	}
+	if(ret.find(EBuilding::TOWN_HALL) != ret.end())
+	{
+		ret.insert(EBuilding::EXTRA_TOWN_HALL);
+	}
+	if(ret.find(EBuilding::CAPITOL) != ret.end())
+	{
+		ret.insert(EBuilding::EXTRA_CAPITOL);
+	}
+
+	return ret;
 }
 
 void CMapLoaderH3M::readEvents()
 {
-    int numberOfEvents = read_le_u32(buffer + pos);
-    pos += 4;
-    for(int yyoo = 0; yyoo < numberOfEvents; ++yyoo)
-    {
-        CMapEvent * ne = new CMapEvent;
-        ne->name = std::string();
-        ne->message = std::string();
-        int nameLen = read_le_u32(buffer + pos);
-        pos += 4;
-        for(int qq = 0; qq < nameLen; ++qq)
-        {
-            ne->name += buffer[pos];
-            ++pos;
-        }
-        int messLen = read_le_u32(buffer + pos);
-        pos += 4;
-        for(int qq = 0; qq < messLen; ++qq)
-        {
-            ne->message +=buffer[pos];
-            ++pos;
-        }
-        for(int k = 0; k < 7; ++k)
-        {
-            ne->resources[k] = read_le_u32(buffer + pos);
-            pos += 4;
-        }
-        ne->players = buffer[pos];
-        ++pos;
-        if(map->version > EMapFormat::AB)
-        {
-            ne->humanAffected = buffer[pos];
-            ++pos;
-        }
-        else
-        {
-            ne->humanAffected = true;
-        }
-        ne->computerAffected = buffer[pos];
-        ++pos;
-        ne->firstOccurence = read_le_u16(buffer + pos);
-        pos += 2;
-        ne->nextOccurence = buffer[pos];
-        ++pos;
-
-        char unknown[17];
-        memcpy(unknown, buffer + pos, 17);
-        pos += 17;
-
-        map->events.push_back(ne);
-    }
+	int numberOfEvents = read_le_u32(buffer + pos);
+	pos += 4;
+	for(int yyoo = 0; yyoo < numberOfEvents; ++yyoo)
+	{
+		CMapEvent * ne = new CMapEvent;
+		ne->name = std::string();
+		ne->message = std::string();
+		int nameLen = read_le_u32(buffer + pos);
+		pos += 4;
+		for(int qq = 0; qq < nameLen; ++qq)
+		{
+			ne->name += buffer[pos];
+			++pos;
+		}
+		int messLen = read_le_u32(buffer + pos);
+		pos += 4;
+		for(int qq = 0; qq < messLen; ++qq)
+		{
+			ne->message +=buffer[pos];
+			++pos;
+		}
+		for(int k = 0; k < 7; ++k)
+		{
+			ne->resources[k] = read_le_u32(buffer + pos);
+			pos += 4;
+		}
+		ne->players = buffer[pos];
+		++pos;
+		if(map->version > EMapFormat::AB)
+		{
+			ne->humanAffected = buffer[pos];
+			++pos;
+		}
+		else
+		{
+			ne->humanAffected = true;
+		}
+		ne->computerAffected = buffer[pos];
+		++pos;
+		ne->firstOccurence = read_le_u16(buffer + pos);
+		pos += 2;
+		ne->nextOccurence = buffer[pos];
+		++pos;
+
+		char unknown[17];
+		memcpy(unknown, buffer + pos, 17);
+		pos += 17;
+
+		map->events.push_back(ne);
+	}
 }
 
 void CMapLoaderH3M::addBlockVisibleTiles(CGObjectInstance * obj)
 {
-    for(int fx = 0; fx < 8; ++fx)
-    {
-        for(int fy = 0; fy < 6; ++fy)
-        {
-            int xVal = obj->pos.x + fx - 7;
-            int yVal = obj->pos.y + fy - 5;
-            int zVal = obj->pos.z;
-            if(xVal >= 0 && xVal < map->width && yVal >= 0 && yVal < map->height)
-            {
-                TerrainTile & curt = map->terrain[xVal][yVal][zVal];
-                if(((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1))
-                {
-                    curt.visitableObjects.push_back(obj);
-                    curt.visitable = true;
-                }
-                if(!((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
-                {
-                    curt.blockingObjects.push_back(obj);
-                    curt.blocked = true;
-                }
-            }
-        }
-    }
+	for(int fx = 0; fx < 8; ++fx)
+	{
+		for(int fy = 0; fy < 6; ++fy)
+		{
+			int xVal = obj->pos.x + fx - 7;
+			int yVal = obj->pos.y + fy - 5;
+			int zVal = obj->pos.z;
+			if(xVal >= 0 && xVal < map->width && yVal >= 0 && yVal < map->height)
+			{
+				TerrainTile & curt = map->terrain[xVal][yVal][zVal];
+				if(((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1))
+				{
+					curt.visitableObjects.push_back(obj);
+					curt.visitable = true;
+				}
+				if(!((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
+				{
+					curt.blockingObjects.push_back(obj);
+					curt.blocked = true;
+				}
+			}
+		}
+	}
 }
 
 ui8 CMapLoaderH3M::reverse(ui8 arg)
 {
-    ui8 ret = 0;
-    for(int i = 0; i < 8; ++i)
-    {
-        if((arg & (1 << i)) >> i)
-        {
-            ret |= (128 >> i);
-        }
-    }
-    return ret;
+	ui8 ret = 0;
+	for(int i = 0; i < 8; ++i)
+	{
+		if((arg & (1 << i)) >> i)
+		{
+			ret |= (128 >> i);
+		}
+	}
+	return ret;
 }

+ 310 - 310
lib/Map/CMapService.h

@@ -31,74 +31,74 @@ class IMapLoader;
 class DLL_LINKAGE CMapService
 {
 public:
-    /**
-     * Loads the VCMI/H3 map file specified by the name.
-     *
-     * @param name the name of the map
-     * @return a unique ptr to the loaded map class
-     */
-    static std::unique_ptr<CMap> loadMap(const std::string & name);
-
-    /**
-     * Loads the VCMI/H3 map header specified by the name.
-     *
-     * @param name the name of the map
-     * @return a unique ptr to the loaded map header class
-     */
-    static std::unique_ptr<CMapHeader> loadMapHeader(const std::string & name);
-
-    /**
-     * Loads the VCMI/H3 map file from a buffer. This method is temporarily
-     * in use to ease the transition to use the new map service.
-     *
-     * TODO Replace method params with a CampaignMapInfo struct which contains
-     * a campaign loading object + name of map.
-     *
-     * @param buffer a pointer to a buffer containing the map data
-     * @param size the size of the buffer
-     * @return a unique ptr to the loaded map class
-     */
-    static std::unique_ptr<CMap> loadMap(const ui8 * buffer, int size);
-
-    /**
-     * Loads the VCMI/H3 map header from a buffer. This method is temporarily
-     * in use to ease the transition to use the new map service.
-     *
-     * TODO Replace method params with a CampaignMapInfo struct which contains
-     * a campaign loading object + name of map.
-     *
-     * @param buffer a pointer to a buffer containing the map header data
-     * @param size the size of the buffer
-     * @return a unique ptr to the loaded map class
-     */
-    static std::unique_ptr<CMapHeader> loadMapHeader(const ui8 * buffer, int size);
+	/**
+	 * Loads the VCMI/H3 map file specified by the name.
+	 *
+	 * @param name the name of the map
+	 * @return a unique ptr to the loaded map class
+	 */
+	static std::unique_ptr<CMap> loadMap(const std::string & name);
+
+	/**
+	 * Loads the VCMI/H3 map header specified by the name.
+	 *
+	 * @param name the name of the map
+	 * @return a unique ptr to the loaded map header class
+	 */
+	static std::unique_ptr<CMapHeader> loadMapHeader(const std::string & name);
+
+	/**
+	 * Loads the VCMI/H3 map file from a buffer. This method is temporarily
+	 * in use to ease the transition to use the new map service.
+	 *
+	 * TODO Replace method params with a CampaignMapInfo struct which contains
+	 * a campaign loading object + name of map.
+	 *
+	 * @param buffer a pointer to a buffer containing the map data
+	 * @param size the size of the buffer
+	 * @return a unique ptr to the loaded map class
+	 */
+	static std::unique_ptr<CMap> loadMap(const ui8 * buffer, int size);
+
+	/**
+	 * Loads the VCMI/H3 map header from a buffer. This method is temporarily
+	 * in use to ease the transition to use the new map service.
+	 *
+	 * TODO Replace method params with a CampaignMapInfo struct which contains
+	 * a campaign loading object + name of map.
+	 *
+	 * @param buffer a pointer to a buffer containing the map header data
+	 * @param size the size of the buffer
+	 * @return a unique ptr to the loaded map class
+	 */
+	static std::unique_ptr<CMapHeader> loadMapHeader(const ui8 * buffer, int size);
 
 private:
-    /**
-     * Gets a map input stream object specified by a map name.
-     *
-     * @param name the name of the map
-     * @return a unique ptr to the input stream class
-     */
-    static std::unique_ptr<CInputStream> getStreamFromFS(const std::string & name);
-
-    /**
-     * Gets a map input stream from a buffer.
-     *
-     * @param buffer a pointer to a buffer containing the map data
-     * @param size the size of the buffer
-     * @return a unique ptr to the input stream class
-     */
-    static std::unique_ptr<CInputStream> getStreamFromMem(const ui8 * buffer, int size);
-
-    /**
-     * Gets a map loader from the given stream. It performs checks to test
-     * in which map format the map is.
-     *
-     * @param stream the input map stream
-     * @return the constructed map loader
-     */
-    static std::unique_ptr<IMapLoader> getMapLoader(std::unique_ptr<CInputStream> & stream);
+	/**
+	 * Gets a map input stream object specified by a map name.
+	 *
+	 * @param name the name of the map
+	 * @return a unique ptr to the input stream class
+	 */
+	static std::unique_ptr<CInputStream> getStreamFromFS(const std::string & name);
+
+	/**
+	 * Gets a map input stream from a buffer.
+	 *
+	 * @param buffer a pointer to a buffer containing the map data
+	 * @param size the size of the buffer
+	 * @return a unique ptr to the input stream class
+	 */
+	static std::unique_ptr<CInputStream> getStreamFromMem(const ui8 * buffer, int size);
+
+	/**
+	 * Gets a map loader from the given stream. It performs checks to test
+	 * in which map format the map is.
+	 *
+	 * @param stream the input map stream
+	 * @return the constructed map loader
+	 */
+	static std::unique_ptr<IMapLoader> getMapLoader(std::unique_ptr<CInputStream> & stream);
 };
 
 /**
@@ -107,255 +107,255 @@ private:
 class DLL_LINKAGE IMapLoader
 {
 public:
-    /**
-     * Loads the VCMI/H3 map file.
-     *
-     * @return a unique ptr of the loaded map class
-     */
-    virtual std::unique_ptr<CMap> loadMap() = 0;
-
-    /**
-     * Loads the VCMI/H3 map header.
-     *
-     * @return a unique ptr of the loaded map header class
-     */
-    virtual std::unique_ptr<CMapHeader> loadMapHeader() = 0;
+	/**
+	 * Loads the VCMI/H3 map file.
+	 *
+	 * @return a unique ptr of the loaded map class
+	 */
+	virtual std::unique_ptr<CMap> loadMap() = 0;
+
+	/**
+	 * Loads the VCMI/H3 map header.
+	 *
+	 * @return a unique ptr of the loaded map header class
+	 */
+	virtual std::unique_ptr<CMapHeader> loadMapHeader() = 0;
 };
 
 class DLL_LINKAGE CMapLoaderH3M : public IMapLoader
 {
 public:
-    /**
-     * Default constructor.
-     *
-     * @param stream a stream containing the map data
-     */
-    CMapLoaderH3M(CInputStream * stream);
-
-    /**
-     * Destructor.
-     */
-    ~CMapLoaderH3M();
-
-    /**
-     * Loads the VCMI/H3 map file.
-     *
-     * @return a unique ptr of the loaded map class
-     */
-    std::unique_ptr<CMap> loadMap();
-
-    /**
-     * Loads the VCMI/H3 map header.
-     *
-     * @return a unique ptr of the loaded map header class
-     */
-    std::unique_ptr<CMapHeader> loadMapHeader();
-
-    /** true if you want to enable the map loader profiler to see how long a specific part took; default=false */
-    static const bool IS_PROFILING_ENABLED;
+	/**
+	 * Default constructor.
+	 *
+	 * @param stream a stream containing the map data
+	 */
+	CMapLoaderH3M(CInputStream * stream);
+
+	/**
+	 * Destructor.
+	 */
+	~CMapLoaderH3M();
+
+	/**
+	 * Loads the VCMI/H3 map file.
+	 *
+	 * @return a unique ptr of the loaded map class
+	 */
+	std::unique_ptr<CMap> loadMap();
+
+	/**
+	 * Loads the VCMI/H3 map header.
+	 *
+	 * @return a unique ptr of the loaded map header class
+	 */
+	std::unique_ptr<CMapHeader> loadMapHeader();
+
+	/** true if you want to enable the map loader profiler to see how long a specific part took; default=false */
+	static const bool IS_PROFILING_ENABLED;
 
 private:
-    /**
-     * Initializes the map object from parsing the input buffer.
-     */
-    void init();
-
-    /**
-     * Reads the map header.
-     */
-    void readHeader();
-
-    /**
-     * Reads player information.
-     */
-    void readPlayerInfo();
-
-    /**
-     * Reads victory/loss conditions.
-     */
-    void readVictoryLossConditions();
-
-    /**
-     * Reads team information.
-     */
-    void readTeamInfo();
-
-    /**
-     * Reads the list of allowed heroes.
-     */
-    void readAllowedHeroes();
-
-    /**
-     * Reads the list of disposed heroes.
-     */
-    void readDisposedHeroes();
-
-    /**
-     * Reads the list of allowed artifacts.
-     */
-    void readAllowedArtifacts();
-
-    /**
-     * Reads the list of allowed spells and abilities.
-     */
-    void readAllowedSpellsAbilities();
-
-    /**
-     * Loads artifacts of a hero.
-     *
-     * @param hero the hero which should hold those artifacts
-     */
-    void loadArtifactsOfHero(CGHeroInstance * hero);
-
-    /**
-     * Loads an artifact to the given slot of the specified hero.
-     *
-     * @param hero the hero which should hold that artifact
-     * @param slot the artifact slot where to place that artifact
-     * @return true if it loaded an artifact
-     */
-    bool loadArtifactToSlot(CGHeroInstance * hero, int slot);
-
-    /**
-     * Creates an artifact instance.
-     *
-     * @param aid the id of the artifact
-     * @param spellID optional. the id of a spell if a spell scroll object should be created
-     * @return the created artifact instance
-     */
-    CArtifactInstance * createArtifact(int aid, int spellID = -1);
-
-    /**
-     * Adds the specified artifact instance to the list of artifacts of this map.
-     *
-     * @param art the artifact which should be added to the list of artifacts
-     */
-    void addNewArtifactInstance(CArtifactInstance * art);
-
-    /**
-     * Read rumors.
-     */
-    void readRumors();
-
-    /**
-     * Reads predefined heroes.
-     */
-    void readPredefinedHeroes();
-
-    /**
-     * Reads terrain data.
-     */
-    void readTerrain();
-
-    /**
-     * Reads custom(map) def information.
-     */
-    void readDefInfo();
-
-    /**
-     * Reads objects(towns, mines,...).
-     */
-    void readObjects();
-
-    /**
-     * Reads a creature set.
-     *
-     * @param out the loaded creature set
-     * @param number the count of creatures to read
-     * @param version true for > ROE maps
-     */
-    void readCreatureSet(CCreatureSet * out, int number, bool version);
-
-    /**
-     * Reads a hero.
-     *
-     * @param idToBeGiven the object id which should be set for the hero
-     * @return a object instance
-     */
-    CGObjectInstance * readHero(int idToBeGiven);
-
-    /**
-     * Reads a seer hut.
-     *
-     * @return the initialized seer hut object
-     */
-    CGSeerHut * readSeerHut();
-
-    /**
-     * Reads a quest for the given quest guard.
-     *
-     * @param guard the quest guard where that quest should be applied to
-     */
-    void readQuest(IQuestObject * guard);
-
-    /**
-     * Adds the specified quest instance to the list of quests.
-     *
-     * @param quest the quest object which should be added to the list of quests
-     */
-    void addQuest(CGObjectInstance * quest);
-
-    /**
-     * Reads a town.
-     *
-     * @param castleID the id of the castle type
-     * @return the loaded town object
-     */
-    CGTownInstance * readTown(int castleID);
-
-    /**
-     * Converts buildings to the specified castle id.
-     *
-     * @param h3m the ids of the buildings
-     * @param castleID the castle id
-     * @param addAuxiliary true if the village hall should be added
-     * @return the converted buildings
-     */
-    std::set<si32> convertBuildings(const std::set<si32> h3m, int castleID, bool addAuxiliary = true);
-
-    /**
-     * Reads events.
-     */
-    void readEvents();
-
-    /**
-     * Adds object instance to block visitable tiles.
-     *
-     * @param obj the object to add
-     */
-    void addBlockVisibleTiles(CGObjectInstance * obj);
-
-    /**
-     * Reverses the input argument.
-     *
-     * @param arg the input argument
-     * @return the reversed 8-bit integer
-     */
-    ui8 reverse(ui8 arg);
-
-    /**
-     * Init buffer / size.
-     *
-     * @param stream the stream which serves as the data input
-     */
-    void initBuffer(CInputStream * stream);
-
-    /** ptr to the map object which gets filled by data from the buffer */
-    CMap * map;
-
-    /**
-     * ptr to the map header object which gets filled by data from the buffer.
-     * (when loading a map then the mapHeader ptr points to the same object)
-     */
-    std::unique_ptr<CMapHeader> mapHeader;
-
-    /** pointer to the array containing the map data;
-     * TODO replace with CBinaryReader later (this makes pos & size redundant) */
-    ui8 * buffer;
-
-    /** current buffer reading position */
-    int pos;
-
-    /** size of the map in bytes */
-    int size;
+	/**
+	 * Initializes the map object from parsing the input buffer.
+	 */
+	void init();
+
+	/**
+	 * Reads the map header.
+	 */
+	void readHeader();
+
+	/**
+	 * Reads player information.
+	 */
+	void readPlayerInfo();
+
+	/**
+	 * Reads victory/loss conditions.
+	 */
+	void readVictoryLossConditions();
+
+	/**
+	 * Reads team information.
+	 */
+	void readTeamInfo();
+
+	/**
+	 * Reads the list of allowed heroes.
+	 */
+	void readAllowedHeroes();
+
+	/**
+	 * Reads the list of disposed heroes.
+	 */
+	void readDisposedHeroes();
+
+	/**
+	 * Reads the list of allowed artifacts.
+	 */
+	void readAllowedArtifacts();
+
+	/**
+	 * Reads the list of allowed spells and abilities.
+	 */
+	void readAllowedSpellsAbilities();
+
+	/**
+	 * Loads artifacts of a hero.
+	 *
+	 * @param hero the hero which should hold those artifacts
+	 */
+	void loadArtifactsOfHero(CGHeroInstance * hero);
+
+	/**
+	 * Loads an artifact to the given slot of the specified hero.
+	 *
+	 * @param hero the hero which should hold that artifact
+	 * @param slot the artifact slot where to place that artifact
+	 * @return true if it loaded an artifact
+	 */
+	bool loadArtifactToSlot(CGHeroInstance * hero, int slot);
+
+	/**
+	 * Creates an artifact instance.
+	 *
+	 * @param aid the id of the artifact
+	 * @param spellID optional. the id of a spell if a spell scroll object should be created
+	 * @return the created artifact instance
+	 */
+	CArtifactInstance * createArtifact(int aid, int spellID = -1);
+
+	/**
+	 * Adds the specified artifact instance to the list of artifacts of this map.
+	 *
+	 * @param art the artifact which should be added to the list of artifacts
+	 */
+	void addNewArtifactInstance(CArtifactInstance * art);
+
+	/**
+	 * Read rumors.
+	 */
+	void readRumors();
+
+	/**
+	 * Reads predefined heroes.
+	 */
+	void readPredefinedHeroes();
+
+	/**
+	 * Reads terrain data.
+	 */
+	void readTerrain();
+
+	/**
+	 * Reads custom(map) def information.
+	 */
+	void readDefInfo();
+
+	/**
+	 * Reads objects(towns, mines,...).
+	 */
+	void readObjects();
+
+	/**
+	 * Reads a creature set.
+	 *
+	 * @param out the loaded creature set
+	 * @param number the count of creatures to read
+	 * @param version true for > ROE maps
+	 */
+	void readCreatureSet(CCreatureSet * out, int number, bool version);
+
+	/**
+	 * Reads a hero.
+	 *
+	 * @param idToBeGiven the object id which should be set for the hero
+	 * @return a object instance
+	 */
+	CGObjectInstance * readHero(int idToBeGiven);
+
+	/**
+	 * Reads a seer hut.
+	 *
+	 * @return the initialized seer hut object
+	 */
+	CGSeerHut * readSeerHut();
+
+	/**
+	 * Reads a quest for the given quest guard.
+	 *
+	 * @param guard the quest guard where that quest should be applied to
+	 */
+	void readQuest(IQuestObject * guard);
+
+	/**
+	 * Adds the specified quest instance to the list of quests.
+	 *
+	 * @param quest the quest object which should be added to the list of quests
+	 */
+	void addQuest(CGObjectInstance * quest);
+
+	/**
+	 * Reads a town.
+	 *
+	 * @param castleID the id of the castle type
+	 * @return the loaded town object
+	 */
+	CGTownInstance * readTown(int castleID);
+
+	/**
+	 * Converts buildings to the specified castle id.
+	 *
+	 * @param h3m the ids of the buildings
+	 * @param castleID the castle id
+	 * @param addAuxiliary true if the village hall should be added
+	 * @return the converted buildings
+	 */
+	std::set<si32> convertBuildings(const std::set<si32> h3m, int castleID, bool addAuxiliary = true);
+
+	/**
+	 * Reads events.
+	 */
+	void readEvents();
+
+	/**
+	 * Adds object instance to block visitable tiles.
+	 *
+	 * @param obj the object to add
+	 */
+	void addBlockVisibleTiles(CGObjectInstance * obj);
+
+	/**
+	 * Reverses the input argument.
+	 *
+	 * @param arg the input argument
+	 * @return the reversed 8-bit integer
+	 */
+	ui8 reverse(ui8 arg);
+
+	/**
+	 * Init buffer / size.
+	 *
+	 * @param stream the stream which serves as the data input
+	 */
+	void initBuffer(CInputStream * stream);
+
+	/** ptr to the map object which gets filled by data from the buffer */
+	CMap * map;
+
+	/**
+	 * ptr to the map header object which gets filled by data from the buffer.
+	 * (when loading a map then the mapHeader ptr points to the same object)
+	 */
+	std::unique_ptr<CMapHeader> mapHeader;
+
+	/** pointer to the array containing the map data;
+	 * TODO replace with CBinaryReader later (this makes pos & size redundant) */
+	ui8 * buffer;
+
+	/** current buffer reading position */
+	int pos;
+
+	/** size of the map in bytes */
+	int size;
 };

+ 1 - 1
lib/NetPacks.h

@@ -2225,7 +2225,7 @@ struct UpdateStartOptions : public CPregamePackToPropagate
 
 struct PregameGuiAction : public CPregamePackToPropagate
 {
-	enum {NO_TAB, OPEN_OPTIONS, OPEN_SCENARIO_LIST};
+    enum {NO_TAB, OPEN_OPTIONS, OPEN_SCENARIO_LIST, OPEN_RANDOM_MAP_OPTIONS};
 
 	ui8 action;
 

+ 122 - 0
lib/RMG/CMapGenOptions.cpp

@@ -0,0 +1,122 @@
+#include "StdInc.h"
+#include "CMapGenOptions.h"
+
+CMapGenOptions::CMapGenOptions() : mapSize(EMapSize::MEDIUM), hasTwoLevels(true),
+	playersCnt(-1), teamsCnt(-1), compOnlyPlayersCnt(-1), compOnlyTeamsCnt(-1),
+	waterContent(EWaterContent::NORMAL), monsterStrength(EMonsterStrength::NORMAL)
+{
+
+}
+
+EMapSize::EMapSize CMapGenOptions::getMapSize() const
+{
+	return mapSize;
+}
+
+void CMapGenOptions::setMapSize(EMapSize::EMapSize value)
+{
+	mapSize = value;
+}
+
+bool CMapGenOptions::getHasTwoLevels() const
+{
+	return hasTwoLevels;
+}
+
+void CMapGenOptions::setHasTwoLevels(bool value)
+{
+	hasTwoLevels = value;
+}
+
+int CMapGenOptions::getPlayersCnt() const
+{
+	return playersCnt;
+}
+
+void CMapGenOptions::setPlayersCnt(int value)
+{
+	if((value >= 1 && value <= 8) || value == -1)
+	{
+		playersCnt = value;
+	}
+	else
+	{
+		throw std::runtime_error("Players count of RMG options should be between 1 and 8 or -1 for random.");
+	}
+}
+
+int CMapGenOptions::getTeamsCnt() const
+{
+	return teamsCnt;
+}
+
+void CMapGenOptions::setTeamsCnt(int value)
+{
+	if(playersCnt == -1 || (value >= 0 && value < playersCnt) || value == -1)
+	{
+		teamsCnt = value;
+	}
+	else
+	{
+		throw std::runtime_error("Teams count of RMG options should be between 0 and <" +
+			boost::lexical_cast<std::string>(playersCnt) + "(players count) - 1> or -1 for random.");
+	}
+}
+
+int CMapGenOptions::getCompOnlyPlayersCnt() const
+{
+	return compOnlyPlayersCnt;
+}
+
+void CMapGenOptions::setCompOnlyPlayersCnt(int value)
+{
+	if(value == -1 || (value >= 0 && value <= 8 - playersCnt))
+	{
+		compOnlyPlayersCnt = value;
+	}
+	else
+	{
+		throw std::runtime_error(std::string("Computer only players count of RMG options should be ") +
+			"between 0 and <8 - " + boost::lexical_cast<std::string>(playersCnt) +
+			"(playersCount)> or -1 for random.");
+	}
+}
+
+int CMapGenOptions::getCompOnlyTeamsCnt() const
+{
+	return compOnlyTeamsCnt;
+}
+
+void CMapGenOptions::setCompOnlyTeamsCnt(int value)
+{
+	if(value == -1 || compOnlyPlayersCnt == -1 || (value >= 0 && value <= compOnlyPlayersCnt - 1))
+	{
+		compOnlyTeamsCnt = value;
+	}
+	else
+	{
+		throw std::runtime_error(std::string("Computer only teams count of RMG options should be ") +
+			"between 0 and <" + boost::lexical_cast<std::string>(compOnlyPlayersCnt) +
+			"(compOnlyPlayersCnt) - 1> or -1 for random.");
+	}
+}
+
+EWaterContent::EWaterContent CMapGenOptions::getWaterContent() const
+{
+	return waterContent;
+}
+
+void CMapGenOptions::setWaterContent(EWaterContent::EWaterContent value)
+{
+	waterContent = value;
+}
+
+EMonsterStrength::EMonsterStrength CMapGenOptions::getMonsterStrength() const
+{
+	return monsterStrength;
+}
+
+void CMapGenOptions::setMonsterStrength(EMonsterStrength::EMonsterStrength value)
+{
+	monsterStrength = value;
+}

+ 195 - 0
lib/RMG/CMapGenOptions.h

@@ -0,0 +1,195 @@
+
+/*
+ * CMapGenOptions.h, part of VCMI engine
+ *
+ * Authors: listed in file AUTHORS in main folder
+ *
+ * License: GNU General Public License v2.0 or later
+ * Full text of license available in license.txt file, in main folder
+ *
+ */
+
+#pragma once
+
+namespace EMapSize
+{
+	enum EMapSize
+	{
+		SMALL,
+		MEDIUM,
+		LARGE,
+		EXTRA_LARGE
+	};
+}
+
+namespace EWaterContent
+{
+	enum EWaterContent
+	{
+		RANDOM = -1,
+		NONE,
+		NORMAL,
+		ISLANDS
+	};
+}
+
+namespace EMonsterStrength
+{
+	enum EMonsterStrength
+	{
+		RANDOM = -1,
+		WEAK,
+		NORMAL,
+		STRONG
+	};
+}
+
+/**
+ * The map gen options class holds values about general map
+ * generation settings e.g. the size of the map, the count of players,...
+ */
+class CMapGenOptions
+{
+public:
+	/**
+	 * C-tor.
+	 */
+	CMapGenOptions();
+
+	/**
+	 * Gets the size of the map.
+	 *
+	 * @return size of the map
+	 */
+	EMapSize::EMapSize getMapSize() const;
+
+	/**
+	 * Sets the size of the map.
+	 *
+	 * @param value the size of the map
+	 */
+	void setMapSize(EMapSize::EMapSize value);
+
+	/**
+	 * Gets the flag whether the map should be generated with two levels.
+	 *
+	 * @return true for two level map
+	 */
+	bool getHasTwoLevels() const;
+
+	/**
+	 * Sets the flag whether the map should be generated with two levels.
+	 *
+	 * @param value true for two level map
+	 */
+	void setHasTwoLevels(bool value);
+
+	/**
+	 * Gets the count of the players.
+	 *
+	 * @return the count of the players ranging from 1 to 8, -1 for random
+	 */
+	int getPlayersCnt() const;
+
+	/**
+	 * Sets the count of the players.
+	 *
+	 * @param value the count of the players ranging from 1 to 8, -1 for random
+	 */
+	void setPlayersCnt(int value);
+
+	/**
+	 * Gets the count of the teams.
+	 *
+	 * @return the count of the teams ranging from 0 to <players count - 1>, -1 for random
+	 */
+	int getTeamsCnt() const;
+
+	/**
+	 * Sets the count of the teams
+	 *
+	 * @param value the count of the teams ranging from 0 to <players count - 1>, -1 for random
+	 */
+	void setTeamsCnt(int value);
+
+	/**
+	 * Gets the count of the computer only players.
+	 *
+	 * @return the count of the computer only players ranging from 0 to <8 - players count>, -1 for random
+	 */
+	int getCompOnlyPlayersCnt() const;
+
+	/**
+	 * Sets the count of the computer only players.
+	 *
+	 * @param value the count of the computer only players ranging from 0 to <8 - players count>, -1 for random
+	 */
+	void setCompOnlyPlayersCnt(int value);
+
+	/**
+	 * Gets the count of the computer only teams.
+	 *
+	 * @return the count of the computer only teams ranging from 0 to <comp only players - 1>, -1 for random
+	 */
+	int getCompOnlyTeamsCnt() const;
+
+	/**
+	 * Sets the count of the computer only teams.
+	 *
+	 * @param value the count of the computer only teams ranging from 0 to <comp only players - 1>, -1 for random
+	 */
+	void setCompOnlyTeamsCnt(int value);
+
+	/**
+	 * Gets the water content.
+	 *
+	 * @return the water content
+	 */
+	EWaterContent::EWaterContent getWaterContent() const;
+
+	/**
+	 * Sets the water content.
+	 *
+	 * @param value the water content
+	 */
+	void setWaterContent(EWaterContent::EWaterContent value);
+
+	/**
+	 * Gets the strength of the monsters.
+	 *
+	 * @return the strenght of the monsters
+	 */
+	EMonsterStrength::EMonsterStrength getMonsterStrength() const;
+
+	/**
+	 * Sets the strength of the monsters.
+	 *
+	 * @param value the strenght of the monsters
+	 */
+	void setMonsterStrength(EMonsterStrength::EMonsterStrength value);
+
+private:
+	/** the size of the map */
+	EMapSize::EMapSize mapSize;
+
+	/** true if the map has two levels/underground */
+	bool hasTwoLevels;
+
+	/** the count of the players(human + computer); -1 if random */
+	int playersCnt;
+
+	/** the count of the teams; -1 if random */
+	int teamsCnt;
+
+	/** the count of computer only players; -1 if random */
+	int compOnlyPlayersCnt;
+
+	/** the count of computer only teams; -1 if random */
+	int compOnlyTeamsCnt;
+
+	/** the water content, -1 if random */
+	EWaterContent::EWaterContent waterContent;
+
+	/** the strength of the monsters, -1 if random */
+	EMonsterStrength::EMonsterStrength monsterStrength;
+};

+ 3 - 1
lib/VCMI_lib.vcxproj

@@ -254,6 +254,7 @@
     <ClCompile Include="Map\CMap.cpp" />
     <ClCompile Include="Map\CMapInfo.cpp" />
     <ClCompile Include="Map\CMapService.cpp" />
+    <ClCompile Include="RMG\CMapGenOptions.cpp" />
     <ClCompile Include="HeroBonus.cpp" />
     <ClCompile Include="CBattleCallback.cpp" />
     <ClCompile Include="IGameCallback.cpp" />
@@ -314,6 +315,7 @@
     <ClInclude Include="Map\CMap.h" />
     <ClInclude Include="Map\CMapInfo.h" />
     <ClInclude Include="Map\CMapService.h" />
+    <ClInclude Include="RMG\CMapGenOptions.h" />
     <ClInclude Include="GameConstants.h" />
     <ClInclude Include="HeroBonus.h" />
     <ClInclude Include="CBattleCallback.h" />
@@ -334,4 +336,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>