Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when generating random map with random number of players #500

Merged
merged 2 commits into from Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/Client.cpp
Expand Up @@ -321,7 +321,7 @@ void CClient::initMapHandler()

void CClient::initPlayerInterfaces()
{
for(auto & elem : CSH->si->playerInfos)
for(auto & elem : gs->scenarioOps->playerInfos)
{
PlayerColor color = elem.first;
if(!vstd::contains(CSH->getAllClientPlayers(CSH->c->connectionID), color))
Expand Down
14 changes: 11 additions & 3 deletions lib/rmg/CMapGenOptions.cpp
Expand Up @@ -71,8 +71,13 @@ void CMapGenOptions::setPlayerCount(si8 value)
if (compOnlyPlayerCount > possibleCompPlayersCount)
setCompOnlyPlayerCount(possibleCompPlayersCount);

if (getPlayerCount() != RANDOM_SIZE && getCompOnlyPlayerCount() != RANDOM_SIZE)
humanPlayersCount = getPlayerCount() - getCompOnlyPlayerCount();
if (getPlayerCount() != RANDOM_SIZE)
{
if (getCompOnlyPlayerCount() != RANDOM_SIZE)
humanPlayersCount = getPlayerCount() - getCompOnlyPlayerCount();
else
humanPlayersCount = getPlayerCount();
}

resetPlayersMap();
}
Expand Down Expand Up @@ -167,7 +172,10 @@ void CMapGenOptions::resetPlayersMap()
auto pc = PlayerColor(color);
player.setColor(pc);
auto playerType = EPlayerType::AI;
if ((getPlayerCount() != RANDOM_SIZE && color >= realPlayersCnt)
if (getPlayerCount() != RANDOM_SIZE && color < realPlayersCnt)
{
playerType = EPlayerType::HUMAN;
}else if ((getPlayerCount() != RANDOM_SIZE && color >= realPlayersCnt)
godric3 marked this conversation as resolved.
Show resolved Hide resolved
|| (compOnlyPlayerCount != RANDOM_SIZE && color >= (PlayerColor::PLAYER_LIMIT_I-compOnlyPlayerCount)))
{
playerType = EPlayerType::COMP_ONLY;
Expand Down