mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	CMapGenOptions: fix crash when computer only limit is used
Currently when there is computer only players set resetPlayersMap may try to change settings for more than 8 players which obviously cause crash. Now if any of "players and computer limit" or "computer limit" is set to random we automatically set total limit to 8 players.
This commit is contained in:
		| @@ -67,6 +67,9 @@ void CMapGenOptions::setPlayerCount(si8 value) | ||||
| { | ||||
| 	assert((value >= 1 && value <= PlayerColor::PLAYER_LIMIT_I) || value == RANDOM_SIZE); | ||||
| 	playerCount = value; | ||||
| 	auto possibleCompPlayersCount = PlayerColor::PLAYER_LIMIT_I-value; | ||||
| 	if(compOnlyPlayerCount > possibleCompPlayersCount) | ||||
| 		setCompOnlyPlayerCount(possibleCompPlayersCount); | ||||
| 	resetPlayersMap(); | ||||
| } | ||||
|  | ||||
| @@ -129,11 +132,21 @@ void CMapGenOptions::resetPlayersMap() | ||||
| 	players.clear(); | ||||
| 	int realPlayersCnt = playerCount == RANDOM_SIZE ? static_cast<int>(PlayerColor::PLAYER_LIMIT_I) : playerCount; | ||||
| 	int realCompOnlyPlayersCnt = compOnlyPlayerCount == RANDOM_SIZE ? (PlayerColor::PLAYER_LIMIT_I - realPlayersCnt) : compOnlyPlayerCount; | ||||
| 	for(int color = 0; color < (realPlayersCnt + realCompOnlyPlayersCnt); ++color) | ||||
| 	int totalPlayersLimit = realPlayersCnt + realCompOnlyPlayersCnt; | ||||
| 	if(playerCount == RANDOM_SIZE || compOnlyPlayerCount == RANDOM_SIZE) | ||||
| 		totalPlayersLimit = static_cast<int>(PlayerColor::PLAYER_LIMIT_I); | ||||
|  | ||||
| 	for(int color = 0; color < totalPlayersLimit; ++color) | ||||
| 	{ | ||||
| 		CPlayerSettings player; | ||||
| 		player.setColor(PlayerColor(color)); | ||||
| 		player.setPlayerType((color >= realPlayersCnt) ? EPlayerType::COMP_ONLY : EPlayerType::AI); | ||||
| 		auto playerType = EPlayerType::AI; | ||||
| 		if((playerCount != RANDOM_SIZE && color >= realPlayersCnt) | ||||
| 		   || (compOnlyPlayerCount != RANDOM_SIZE && color >= (PlayerColor::PLAYER_LIMIT_I-compOnlyPlayerCount))) | ||||
| 		{ | ||||
| 			playerType = EPlayerType::COMP_ONLY; | ||||
| 		} | ||||
| 		player.setPlayerType(playerType); | ||||
| 		players[PlayerColor(color)] = player; | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user