mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-15 11:46:56 +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:
parent
eeff8f3ea4
commit
783dcfea2e
@ -67,6 +67,9 @@ void CMapGenOptions::setPlayerCount(si8 value)
|
|||||||
{
|
{
|
||||||
assert((value >= 1 && value <= PlayerColor::PLAYER_LIMIT_I) || value == RANDOM_SIZE);
|
assert((value >= 1 && value <= PlayerColor::PLAYER_LIMIT_I) || value == RANDOM_SIZE);
|
||||||
playerCount = value;
|
playerCount = value;
|
||||||
|
auto possibleCompPlayersCount = PlayerColor::PLAYER_LIMIT_I-value;
|
||||||
|
if(compOnlyPlayerCount > possibleCompPlayersCount)
|
||||||
|
setCompOnlyPlayerCount(possibleCompPlayersCount);
|
||||||
resetPlayersMap();
|
resetPlayersMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,11 +132,21 @@ void CMapGenOptions::resetPlayersMap()
|
|||||||
players.clear();
|
players.clear();
|
||||||
int realPlayersCnt = playerCount == RANDOM_SIZE ? static_cast<int>(PlayerColor::PLAYER_LIMIT_I) : playerCount;
|
int realPlayersCnt = playerCount == RANDOM_SIZE ? static_cast<int>(PlayerColor::PLAYER_LIMIT_I) : playerCount;
|
||||||
int realCompOnlyPlayersCnt = compOnlyPlayerCount == RANDOM_SIZE ? (PlayerColor::PLAYER_LIMIT_I - realPlayersCnt) : compOnlyPlayerCount;
|
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;
|
CPlayerSettings player;
|
||||||
player.setColor(PlayerColor(color));
|
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;
|
players[PlayerColor(color)] = player;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user