Skip to content

Commit

Permalink
Merge pull request #500 from godric3/rmgCrash
Browse files Browse the repository at this point in the history
Fix crash when generating random map with random number of players
  • Loading branch information
alexvins committed Oct 28, 2018
2 parents 1753298 + f563712 commit e814aca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/Client.cpp
Original file line number Diff line number Diff line change
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
15 changes: 12 additions & 3 deletions lib/rmg/CMapGenOptions.cpp
Original file line number Diff line number Diff line change
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,11 @@ 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)
|| (compOnlyPlayerCount != RANDOM_SIZE && color >= (PlayerColor::PLAYER_LIMIT_I-compOnlyPlayerCount)))
{
playerType = EPlayerType::COMP_ONLY;
Expand Down

0 comments on commit e814aca

Please sign in to comment.