mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
PreGame: avoid crashing on random map options
Options is still broken, but at least we shouldn't crash there.
This commit is contained in:
@ -1875,9 +1875,9 @@ void CRandomMapTab::updateMapInfo()
|
|||||||
|
|
||||||
// Generate player information
|
// Generate player information
|
||||||
mapInfo->mapHeader->players.clear();
|
mapInfo->mapHeader->players.clear();
|
||||||
int playersToGen = (mapGenOptions.getPlayerCount() == CMapGenOptions::RANDOM_SIZE
|
int playersToGen = PlayerColor::PLAYER_LIMIT_I;
|
||||||
|| mapGenOptions.getCompOnlyPlayerCount() == CMapGenOptions::RANDOM_SIZE)
|
if(mapGenOptions.getPlayerCount() != CMapGenOptions::RANDOM_SIZE)
|
||||||
? 8 : mapGenOptions.getPlayerCount() + mapGenOptions.getCompOnlyPlayerCount();
|
playersToGen = mapGenOptions.getPlayerCount();
|
||||||
mapInfo->mapHeader->howManyTeams = playersToGen;
|
mapInfo->mapHeader->howManyTeams = playersToGen;
|
||||||
|
|
||||||
for(int i = 0; i < playersToGen; ++i)
|
for(int i = 0; i < playersToGen; ++i)
|
||||||
@ -1885,7 +1885,7 @@ void CRandomMapTab::updateMapInfo()
|
|||||||
PlayerInfo player;
|
PlayerInfo player;
|
||||||
player.isFactionRandom = true;
|
player.isFactionRandom = true;
|
||||||
player.canComputerPlay = true;
|
player.canComputerPlay = true;
|
||||||
if(i >= mapGenOptions.getPlayerCount() && mapGenOptions.getPlayerCount() != CMapGenOptions::RANDOM_SIZE)
|
if(i >= mapGenOptions.getHumanOnlyPlayerCount())
|
||||||
{
|
{
|
||||||
player.canHumanPlay = false;
|
player.canHumanPlay = false;
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,11 @@ void CMapGenOptions::setPlayerCount(si8 value)
|
|||||||
resetPlayersMap();
|
resetPlayersMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
si8 CMapGenOptions::getHumanOnlyPlayerCount() const
|
||||||
|
{
|
||||||
|
return humanPlayersCount;
|
||||||
|
}
|
||||||
|
|
||||||
si8 CMapGenOptions::getTeamCount() const
|
si8 CMapGenOptions::getTeamCount() const
|
||||||
{
|
{
|
||||||
return teamCount;
|
return teamCount;
|
||||||
@ -96,7 +101,7 @@ si8 CMapGenOptions::getCompOnlyPlayerCount() const
|
|||||||
|
|
||||||
void CMapGenOptions::setCompOnlyPlayerCount(si8 value)
|
void CMapGenOptions::setCompOnlyPlayerCount(si8 value)
|
||||||
{
|
{
|
||||||
assert(value == RANDOM_SIZE || (value >= 0 && value <= getPlayerCount()));
|
assert(value == RANDOM_SIZE || (getPlayerCount() == RANDOM_SIZE || (value >= 0 && value <= getPlayerCount())));
|
||||||
compOnlyPlayerCount = value;
|
compOnlyPlayerCount = value;
|
||||||
|
|
||||||
if (getPlayerCount() != RANDOM_SIZE && getCompOnlyPlayerCount() != RANDOM_SIZE)
|
if (getPlayerCount() != RANDOM_SIZE && getCompOnlyPlayerCount() != RANDOM_SIZE)
|
||||||
|
@ -108,6 +108,8 @@ public:
|
|||||||
si8 getPlayerCount() const;
|
si8 getPlayerCount() const;
|
||||||
void setPlayerCount(si8 value);
|
void setPlayerCount(si8 value);
|
||||||
|
|
||||||
|
si8 getHumanOnlyPlayerCount() const;
|
||||||
|
|
||||||
/// The count of the teams ranging from 0 to <players count - 1> or RANDOM_SIZE for random.
|
/// The count of the teams ranging from 0 to <players count - 1> or RANDOM_SIZE for random.
|
||||||
si8 getTeamCount() const;
|
si8 getTeamCount() const;
|
||||||
void setTeamCount(si8 value);
|
void setTeamCount(si8 value);
|
||||||
|
Reference in New Issue
Block a user