mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Merge pull request #4156 from IvanSavenko/crashfixes
[1.5.3] Crashfixes
This commit is contained in:
		| @@ -735,9 +735,18 @@ void CClient::removeGUI() const | ||||
| #ifdef VCMI_ANDROID | ||||
| extern "C" JNIEXPORT jboolean JNICALL Java_eu_vcmi_vcmi_NativeMethods_tryToSaveTheGame(JNIEnv * env, jclass cls) | ||||
| { | ||||
| 	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex); | ||||
|  | ||||
| 	logGlobal->info("Received emergency save game request"); | ||||
| 	if(!LOCPLINT || !LOCPLINT->cb) | ||||
| 	{ | ||||
| 		logGlobal->info("... but no active player interface found!"); | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| 	if (!CSH || !CSH->logicConnection) | ||||
| 	{ | ||||
| 		logGlobal->info("... but no active connection found!"); | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -62,17 +62,43 @@ auto HighScoreCalculation::calculate() | ||||
| 	return summary; | ||||
| } | ||||
|  | ||||
| struct HighScoreCreature | ||||
| { | ||||
| 	CreatureID creature; | ||||
| 	int min; | ||||
| 	int max; | ||||
| }; | ||||
|  | ||||
| static std::vector<HighScoreCreature> getHighscoreCreaturesList() | ||||
| { | ||||
| 	JsonNode configCreatures(JsonPath::builtin("CONFIG/highscoreCreatures.json")); | ||||
|  | ||||
| 	std::vector<HighScoreCreature> ret; | ||||
|  | ||||
| 	for(auto & json : configCreatures["creatures"].Vector()) | ||||
| 	{ | ||||
| 		HighScoreCreature entry; | ||||
| 		entry.creature = CreatureID::decode(json["creature"].String()); | ||||
| 		entry.max = json["max"].isNull() ? std::numeric_limits<int>::max() : json["max"].Integer(); | ||||
| 		entry.min = json["min"].isNull() ? std::numeric_limits<int>::min() : json["min"].Integer(); | ||||
|  | ||||
| 		ret.push_back(entry); | ||||
| 	} | ||||
|  | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| CreatureID HighScoreCalculation::getCreatureForPoints(int points, bool campaign) | ||||
| { | ||||
| 	static const JsonNode configCreatures(JsonPath::builtin("CONFIG/highscoreCreatures.json")); | ||||
| 	auto creatures = configCreatures["creatures"].Vector(); | ||||
| 	static const std::vector<HighScoreCreature> creatures = getHighscoreCreaturesList(); | ||||
|  | ||||
| 	int divide = campaign ? 5 : 1; | ||||
|  | ||||
| 	for(auto & creature : creatures) | ||||
| 		if(points / divide <= creature["max"].Integer() && points / divide >= creature["min"].Integer()) | ||||
| 			return CreatureID::decode(creature["creature"].String()); | ||||
| 		if(points / divide <= creature.max && points / divide >= creature.min) | ||||
| 			return creature.creature; | ||||
|  | ||||
| 	return -1; | ||||
| 	throw std::runtime_error("Unable to find creature for score " + std::to_string(points)); | ||||
| } | ||||
|  | ||||
| CHighScoreScreen::CHighScoreScreen(HighScorePage highscorepage, int highlighted) | ||||
|   | ||||
| @@ -235,7 +235,10 @@ void SDLImage::setFlagColor(PlayerColor player) | ||||
|  | ||||
| bool SDLImage::isTransparent(const Point & coords) const | ||||
| { | ||||
| 	return CSDL_Ext::isTransparent(surf, coords.x, coords.y); | ||||
| 	if (surf) | ||||
| 		return CSDL_Ext::isTransparent(surf, coords.x, coords.y); | ||||
| 	else | ||||
| 		return true; | ||||
| } | ||||
|  | ||||
| Point SDLImage::dimensions() const | ||||
|   | ||||
| @@ -637,6 +637,9 @@ CCreaturePic::CCreaturePic(int x, int y, const CCreature * cre, bool Big, bool A | ||||
|  | ||||
| 	assert(CGI->townh->size() > faction); | ||||
|  | ||||
| 	if (cre->animDefName.empty()) | ||||
| 		throw std::runtime_error("Creature " + cre->getJsonKey() + " has no valid combat animation!"); | ||||
|  | ||||
| 	if(Big) | ||||
| 		bg = std::make_shared<CPicture>((*CGI->townh)[faction]->creatureBg130); | ||||
| 	else | ||||
|   | ||||
| @@ -491,14 +491,21 @@ CTavernWindow::CTavernWindow(const CGObjectInstance * TavernObj, const std::func | ||||
| 	} | ||||
| 	else if(LOCPLINT->cb->howManyHeroes(true) >= CGI->settings()->getInteger(EGameSettings::HEROES_PER_PLAYER_TOTAL_CAP)) | ||||
| 	{ | ||||
| 		MetaString message; | ||||
| 		message.appendTextID("core.tvrninfo.1"); | ||||
| 		message.replaceNumber(LOCPLINT->cb->howManyHeroes(true)); | ||||
|  | ||||
| 		//Cannot recruit. You already have %d Heroes. | ||||
| 		recruit->addHoverText(EButtonState::NORMAL, boost::str(boost::format(CGI->generaltexth->tavernInfo[1]) % LOCPLINT->cb->howManyHeroes(true))); | ||||
| 		recruit->addHoverText(EButtonState::NORMAL, message.toString()); | ||||
| 		recruit->block(true); | ||||
| 	} | ||||
| 	else if(LOCPLINT->cb->howManyHeroes(false) >= CGI->settings()->getInteger(EGameSettings::HEROES_PER_PLAYER_ON_MAP_CAP)) | ||||
| 	{ | ||||
| 		//Cannot recruit. You already have %d Heroes. | ||||
| 		recruit->addHoverText(EButtonState::NORMAL, boost::str(boost::format(CGI->generaltexth->tavernInfo[1]) % LOCPLINT->cb->howManyHeroes(false))); | ||||
| 		MetaString message; | ||||
| 		message.appendTextID("core.tvrninfo.1"); | ||||
| 		message.replaceNumber(LOCPLINT->cb->howManyHeroes(false)); | ||||
|  | ||||
| 		recruit->addHoverText(EButtonState::NORMAL, message.toString()); | ||||
| 		recruit->block(true); | ||||
| 	} | ||||
| 	else if(dynamic_cast<const CGTownInstance *>(TavernObj) && dynamic_cast<const CGTownInstance *>(TavernObj)->visitingHero) | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|     "creatures": [ | ||||
|         { "min" : 1, "max" : 4, "creature": "imp" }, | ||||
|         {            "max" : 4, "creature": "imp" }, | ||||
|         { "min" : 5, "max" : 8, "creature": "gremlin" }, | ||||
|         { "min" : 9, "max" : 12, "creature": "gnoll" }, | ||||
|         { "min" : 13, "max" : 16, "creature": "troglodyte" }, | ||||
| @@ -117,6 +117,6 @@ | ||||
|         { "min" : 389, "max" : 391, "creature": "titan" }, | ||||
|         { "min" : 392, "max" : 394, "creature": "goldDragon" }, | ||||
|         { "min" : 395, "max" : 397, "creature": "blackDragon" }, | ||||
|         { "min" : 398, "max" : 500, "creature": "archangel" } | ||||
|         { "min" : 398,              "creature": "archangel" } | ||||
|     ] | ||||
| } | ||||
		Reference in New Issue
	
	Block a user