Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Robosturm committed Jan 8, 2025
1 parent 3a10537 commit 9104e63
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions objects/playerselection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,24 +484,26 @@ void PlayerSelection::updateInitialState(bool relaunchedLobby)
QStringList defaultAiList = getDefaultAiNames();
if (m_saveGame && m_pNetworkInterface.get() != nullptr && !Mainapp::getSlave())
{
for (qint32 i = 0; i < m_pMap->getPlayerCount(); i++)
if (getIsServerNetworkInterface())
{
Player *pPlayer = m_pMap->getPlayer(i);
DropDownmenu *pPlayerAi = getCastedObject<DropDownmenu>(OBJECT_AI_PREFIX + QString::number(i));
qint32 ai = pPlayer->getControlType();
if ((ai == GameEnums::AiTypes_Human &&
Settings::getInstance()->getUsername() != pPlayer->getPlayerNameId()) ||
ai == GameEnums::AiTypes_Open)
for (qint32 i = 0; i < m_pMap->getPlayerCount(); i++)
{
if (pPlayerAi != nullptr)
Player *pPlayer = m_pMap->getPlayer(i);
DropDownmenu *pPlayerAi = getCastedObject<DropDownmenu>(OBJECT_AI_PREFIX + QString::number(i));
qint32 ai = pPlayer->getControlType();
if ((ai == GameEnums::AiTypes_Human &&
Settings::getInstance()->getUsername() != pPlayer->getPlayerNameId()) ||
ai == GameEnums::AiTypes_Open)
{
pPlayerAi->setCurrentItem(aiList.size() - 1);
createInitialAi(pPlayerAi, GameEnums::AiTypes_Open, i);
if (pPlayerAi != nullptr)
{
selectPlayerAi(i, GameEnums::AiTypes_Open);
}
}
else
{
selectPlayerAi(i, static_cast<GameEnums::AiTypes>(ai));
}
}
else
{
createInitialAi(pPlayerAi, ai, i);
}
}
}
Expand Down Expand Up @@ -638,7 +640,7 @@ void PlayerSelection::createInitialAi(DropDownmenu *pPlayerAi, qint32 ai, qint32
Player *pPlayer = m_pMap->getPlayer(player);
// create initial selected ai's
QString displayName = pPlayer->getPlayerNameId();
if (pPlayerAi != nullptr)
if (pPlayerAi != nullptr && ai != GameEnums::AiTypes_Human)
{
displayName = pPlayerAi->getCurrentItemText();
pPlayer->setPlayerNameId(displayName);
Expand Down Expand Up @@ -1662,7 +1664,8 @@ void PlayerSelection::requestPlayer(quint64 socketID, QDataStream &stream)
auto *pPlayer = m_pMap->getPlayer(i);
if (pPlayer->getPlayerNameId() == username &&
pPlayer->getSocketId() == 0 &&
pPlayer->getControlType() == GameEnums::AiTypes::AiTypes_Human)
(pPlayer->getControlType() == GameEnums::AiTypes::AiTypes_Human ||
pPlayer->getControlType() == GameEnums::AiTypes::AiTypes_Open))
{
CONSOLE_PRINT("Player " + QString::number(i) + " username " + username + " rejoined lobby game.", GameConsole::eDEBUG);
remoteChangePlayerOwner(socketID, username, i, eAiType);
Expand Down Expand Up @@ -2289,7 +2292,9 @@ void PlayerSelection::updatePlayerData(qint32 player)
else
{
if (m_pNetworkInterface->getIsServer() || m_isServerGame ||
isOpenPlayer(player))
isOpenPlayer(player) ||
(pPlayer->getBaseGameInput() != nullptr &&
pPlayer->getBaseGameInput()->getAiType() == GameEnums::AiTypes_Human))
{
if (pDropDownmenuAI != nullptr)
{
Expand Down Expand Up @@ -2373,7 +2378,16 @@ void PlayerSelection::updatePlayerData(qint32 player)
{
if (pDropDownmenuAI != nullptr)
{
pDropDownmenuAI->setEnabled(false);
if (m_pNetworkInterface->getIsServer() || m_isServerGame ||
(pPlayer->getBaseGameInput() != nullptr &&
pPlayer->getBaseGameInput()->getAiType() == GameEnums::AiTypes_Human))
{
pDropDownmenuAI->setEnabled(true);
}
else
{
pDropDownmenuAI->setEnabled(false);
}
}
if (pDropDownmenuColor != nullptr)
{
Expand Down

0 comments on commit 9104e63

Please sign in to comment.