Przeglądaj źródła

- fixes #1105
- minor improvement to resolution selection dialog
- removed (hopefully) all cases where neutral faction uses id -1

Ivan Savenko 13 lat temu
rodzic
commit
b1557bc6c4
4 zmienionych plików z 28 dodań i 29 usunięć
  1. 21 9
      client/GUIClasses.cpp
  2. 1 0
      client/GUIClasses.h
  3. 5 19
      lib/CCreatureHandler.cpp
  4. 1 1
      lib/CModHandler.cpp

+ 21 - 9
client/GUIClasses.cpp

@@ -1246,11 +1246,10 @@ CCreaturePic::CCreaturePic(int x, int y, const CCreature *cre, bool Big, bool An
 	pos.x+=x;
 	pos.y+=y;
 
-	si8 faction = 0;//FIXME: support neutral faction
-	if (vstd::contains(CGI->townh->factions, cre->faction))
-	{
-		faction = cre->faction;
-	}
+	TFaction faction = cre->faction;
+
+	assert(vstd::contains(CGI->townh->factions, cre->faction));
+
 	if(Big)
 		bg = new CPicture(CGI->townh->factions[faction].creatureBg130);
 	else
@@ -2866,6 +2865,7 @@ void CMarketplaceWindow::updateTraderText()
 CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*= NULL*/, EMarketMode::EMarketMode Mode)
 	:CTradeWindow((Mode == EMarketMode::CREATURE_EXP ? "ALTARMON.bmp" : "ALTRART2.bmp"), Market, Hero, Mode)
 {
+	OBJ_CONSTRUCTION_CAPTURING_ALL;
 	if(Mode == EMarketMode::CREATURE_EXP)
 	{
 		//%s's Creatures
@@ -3302,7 +3302,7 @@ CSystemOptionsWindow::CSystemOptionsWindow():
 	static const std::string fsHelp  = "{Fullscreen}\n\n If selected, VCMI will run in fullscreen mode, othervice VCMI will run in window";
 	static const std::string cwLabel = "Classic creature window";
 	static const std::string cwHelp  = "{Classic creature window}\n\n Enable original Heroes 3 creature window instead of new window from VCMI";
-	static const std::string rsLabel = "Select resolution";
+	static const std::string rsLabel = "Resolution";
 	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;
@@ -3403,6 +3403,13 @@ CSystemOptionsWindow::CSystemOptionsWindow():
 	fullscreen->select(settings["video"]["fullscreen"].Bool());
 
 	gameResButton = new CAdventureMapButton("", rsHelp, boost::bind(&CSystemOptionsWindow::selectGameRes, this), 28, 275,"SYSOB12", SDLK_g);
+
+	std::string resText;
+	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);
+
 }
 
 void CSystemOptionsWindow::selectGameRes()
@@ -3426,9 +3433,8 @@ void CSystemOptionsWindow::selectGameRes()
 
 void CSystemOptionsWindow::setGameRes(int index)
 {
-	config::CConfigHandler::GuiOptionsMap::const_iterator iter = conf.guiOptions.begin();
-	while (index--)
-		iter++;
+	auto iter = conf.guiOptions.begin();
+	std::advance(iter, index);
 
 	//do not set resolution to illegal one (0x0)
 	assert(iter!=conf.guiOptions.end() && iter->first.first > 0 && iter->first.second > 0);
@@ -3436,6 +3442,12 @@ void CSystemOptionsWindow::setGameRes(int index)
 	Settings gameRes = settings.write["video"]["screenRes"];
 	gameRes["width"].Float() = iter->first.first;
 	gameRes["height"].Float() = iter->first.second;
+
+	std::string resText;
+	resText += boost::lexical_cast<std::string>(iter->first.first);
+	resText += "x";
+	resText += boost::lexical_cast<std::string>(iter->first.second);
+	gameResLabel->setTxt(resText);
 }
 
 void CSystemOptionsWindow::toggleReminder(bool on)

+ 1 - 0
client/GUIClasses.h

@@ -729,6 +729,7 @@ private:
 	CHighlightableButton * fullscreen;
 
 	CAdventureMapButton *gameResButton;
+	CLabel *gameResLabel;
 
 	void setMusicVolume( int newVolume );
 	void setSoundVolume( int newVolume );

+ 5 - 19
lib/CCreatureHandler.cpp

@@ -27,8 +27,8 @@ CCreatureHandler::CCreatureHandler()
 	// Set the faction alignments to the defaults:
 	// Good: Castle, Rampart, Tower
 	// Evil: Inferno, Necropolis, Dungeon
-	// Neutral: Stronghold, Fortess, Conflux
-	factionAlignments += 1, 1, 1, -1, -1, -1, 0, 0, 0;
+	// Neutral: Stronghold, Fortess, Conflux, neutrals
+	factionAlignments += 1, 1, 1, -1, -1, -1, 0, 0, 0, 0;
 	doubledCreatures +=  4, 14, 20, 28, 44, 60, 70, 72, 85, 86, 100, 104; //according to Strategija
 
 	allCreatures.setDescription("All creatures");
@@ -148,21 +148,7 @@ std::string CCreature::nodeName() const
 
 bool CCreature::isItNativeTerrain(int terrain) const
 {
-	return VLC->townh->factions[0].nativeTerrain == terrain; //FIXME: handle neutral faction properly
-}
-
-int readNumber(int & befi, int & i, int andame, std::string & buf) //helper function for void CCreatureHandler::loadCreatures() and loadUnitAnimInfo()
-{
-	befi=i;
-	for(; i<andame; ++i)
-	{
-		if(buf[i]=='\t')
-			break;
-	}
-	std::string tmp = buf.substr(befi, i-befi);
-	int ret = atoi(buf.substr(befi, i-befi).c_str());
-	++i;
-	return ret;
+	return VLC->townh->factions[faction].nativeTerrain == terrain;
 }
 
 /**
@@ -172,7 +158,7 @@ int readNumber(int & befi, int & i, int andame, std::string & buf) //helper func
  */
 bool CCreatureHandler::isGood (si8 faction) const
 {
-	return faction != -1 && factionAlignments[faction] == 1;
+	return factionAlignments[faction] == 1;
 }
 
 /**
@@ -182,7 +168,7 @@ bool CCreatureHandler::isGood (si8 faction) const
  */
 bool CCreatureHandler::isEvil (si8 faction) const
 {
-	return faction != -1 && factionAlignments[faction] == -1;
+	return factionAlignments[faction] == -1;
 }
 
 static void AddAbility(CCreature *cre, const JsonVector &ability_vec)

+ 1 - 1
lib/CModHandler.cpp

@@ -123,7 +123,7 @@ CCreature * CModHandler::loadCreature (const JsonNode &node)
 	cre->cost = Res::ResourceSet(node["cost"]);
 
 	cre->level = node["level"].Float();
-	cre->faction = -1; //neutral faction is 9 for now. Will be replaced by string -> id conversion
+	cre->faction = 9; //neutral faction is 9 for now. Will be replaced by string -> id conversion
 	//TODO: node["faction"].String() to id
 	cre->fightValue = node["fightValue"].Float();
 	cre->AIValue = node["aiValue"].Float();