Browse Source

fix spell research crash when no more spells can be researched due to map limit

kdmcser 11 months ago
parent
commit
2621d4f5bf

+ 1 - 0
Mods/vcmi/config/vcmi/chinese.json

@@ -85,6 +85,7 @@
 	"vcmi.spellResearch.research" : "研究此法术",
 	"vcmi.spellResearch.skip" : "跳过此法术",
 	"vcmi.spellResearch.abort" : "中止",
+	"vcmi.spellResearch.noMoreSpells" : "没有更多的法术可供研究。",
 
 	"vcmi.mainMenu.serverConnecting" : "连接中...",
 	"vcmi.mainMenu.serverAddressEnter" : "使用地址:",

+ 1 - 0
Mods/vcmi/config/vcmi/english.json

@@ -85,6 +85,7 @@
 	"vcmi.spellResearch.research" : "Research this Spell",
 	"vcmi.spellResearch.skip" : "Skip this Spell",
 	"vcmi.spellResearch.abort" : "Abort",
+	"vcmi.spellResearch.noMoreSpells" : "There are no more spells available for research.",
 
 	"vcmi.mainMenu.serverConnecting" : "Connecting...",
 	"vcmi.mainMenu.serverAddressEnter" : "Enter address:",

+ 8 - 1
client/windows/CCastleInterface.cpp

@@ -2054,7 +2054,14 @@ void CMageGuildScreen::Scroll::clickPressed(const Point & cursorPosition)
 		auto cost = costBase * std::pow(town->spellResearchAcceptedCounter + 1, costExponent);
 
 		std::vector<std::shared_ptr<CComponent>> resComps;
-		auto newSpell = town->spells[level].at(town->spellsAtLevel(level, false));
+
+		int index = town->spellsAtLevel(level, false);
+		if (index >= town->spells[level].size())
+		{
+			LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.spellResearch.noMoreSpells"));
+			return;
+		}
+		auto newSpell = town->spells[level].at(index);
 		resComps.push_back(std::make_shared<CComponent>(ComponentType::SPELL, spell->id));
 		resComps.push_back(std::make_shared<CComponent>(ComponentType::SPELL, newSpell));
 		resComps.back()->newLine = true;