From 2276af70dcd848387d31422797c9a8e5bdda89a9 Mon Sep 17 00:00:00 2001 From: ArseniyShestakov Date: Wed, 25 Nov 2015 07:25:44 +0300 Subject: [PATCH] PreGame: avoid crashing on random map options Options is still broken, but at least we shouldn't crash there. --- client/CPreGame.cpp | 8 ++++---- lib/rmg/CMapGenOptions.cpp | 7 ++++++- lib/rmg/CMapGenOptions.h | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index 51c1d1ea6..a0f7808fe 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -1875,9 +1875,9 @@ void CRandomMapTab::updateMapInfo() // Generate player information mapInfo->mapHeader->players.clear(); - int playersToGen = (mapGenOptions.getPlayerCount() == CMapGenOptions::RANDOM_SIZE - || mapGenOptions.getCompOnlyPlayerCount() == CMapGenOptions::RANDOM_SIZE) - ? 8 : mapGenOptions.getPlayerCount() + mapGenOptions.getCompOnlyPlayerCount(); + int playersToGen = PlayerColor::PLAYER_LIMIT_I; + if(mapGenOptions.getPlayerCount() != CMapGenOptions::RANDOM_SIZE) + playersToGen = mapGenOptions.getPlayerCount(); mapInfo->mapHeader->howManyTeams = playersToGen; for(int i = 0; i < playersToGen; ++i) @@ -1885,7 +1885,7 @@ void CRandomMapTab::updateMapInfo() PlayerInfo player; player.isFactionRandom = true; player.canComputerPlay = true; - if(i >= mapGenOptions.getPlayerCount() && mapGenOptions.getPlayerCount() != CMapGenOptions::RANDOM_SIZE) + if(i >= mapGenOptions.getHumanOnlyPlayerCount()) { player.canHumanPlay = false; } diff --git a/lib/rmg/CMapGenOptions.cpp b/lib/rmg/CMapGenOptions.cpp index 2ef064f45..657865df3 100644 --- a/lib/rmg/CMapGenOptions.cpp +++ b/lib/rmg/CMapGenOptions.cpp @@ -78,6 +78,11 @@ void CMapGenOptions::setPlayerCount(si8 value) resetPlayersMap(); } +si8 CMapGenOptions::getHumanOnlyPlayerCount() const +{ + return humanPlayersCount; +} + si8 CMapGenOptions::getTeamCount() const { return teamCount; @@ -96,7 +101,7 @@ si8 CMapGenOptions::getCompOnlyPlayerCount() const 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; if (getPlayerCount() != RANDOM_SIZE && getCompOnlyPlayerCount() != RANDOM_SIZE) diff --git a/lib/rmg/CMapGenOptions.h b/lib/rmg/CMapGenOptions.h index 7975c54f9..7846148cb 100644 --- a/lib/rmg/CMapGenOptions.h +++ b/lib/rmg/CMapGenOptions.h @@ -108,6 +108,8 @@ public: si8 getPlayerCount() const; void setPlayerCount(si8 value); + si8 getHumanOnlyPlayerCount() const; + /// The count of the teams ranging from 0 to or RANDOM_SIZE for random. si8 getTeamCount() const; void setTeamCount(si8 value);