1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Simplified and fixed server restart procedure:

- Replaced several assertions with runtime_error's to detect them in
release builds
- Removed multiple dispatchMainThread calls in server shutdown code to
simplify debugging and code flow
- Moved handling of gameplay shutdown and score calculation from
PlayerInterface to ServerHandler (not perfect, but better than before)
This commit is contained in:
Ivan Savenko
2024-04-07 14:19:57 +03:00
parent 0a80c6c27b
commit 80acd7e77c
6 changed files with 119 additions and 102 deletions

View File

@ -1561,31 +1561,6 @@ void CPlayerInterface::gameOver(PlayerColor player, const EVictoryLossCheckResul
GH.curInt = previousInterface;
LOCPLINT = previousInterface;
if(CSH->howManyPlayerInterfaces() == 1 && !settings["session"]["spectate"].Bool()) //all human players eliminated
{
if(adventureInt)
{
GH.windows().popWindows(GH.windows().count());
adventureInt.reset();
}
}
if (victoryLossCheckResult.victory() && LOCPLINT == this)
{
// end game if current human player has won
CSH->sendClientDisconnecting();
requestReturningToMainMenu(true);
}
else if(CSH->howManyPlayerInterfaces() == 1 && !settings["session"]["spectate"].Bool())
{
//all human players eliminated
CSH->sendClientDisconnecting();
requestReturningToMainMenu(false);
}
if (GH.curInt == this)
GH.curInt = nullptr;
}
}
@ -1739,50 +1714,6 @@ void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj)
showShipyardDialog(obj);
}
void CPlayerInterface::requestReturningToMainMenu(bool won)
{
HighScoreParameter param;
param.difficulty = cb->getStartInfo()->difficulty;
param.day = cb->getDate();
param.townAmount = cb->howManyTowns();
param.usedCheat = cb->getPlayerState(*cb->getPlayerID())->cheated;
param.hasGrail = false;
for(const CGHeroInstance * h : cb->getHeroesInfo())
if(h->hasArt(ArtifactID::GRAIL))
param.hasGrail = true;
for(const CGTownInstance * t : cb->getTownsInfo())
if(t->builtBuildings.count(BuildingID::GRAIL))
param.hasGrail = true;
param.allDefeated = true;
for (PlayerColor player(0); player < PlayerColor::PLAYER_LIMIT; ++player)
{
auto ps = cb->getPlayerState(player, false);
if(ps && player != *cb->getPlayerID())
if(!ps->checkVanquished())
param.allDefeated = false;
}
param.scenarioName = cb->getMapHeader()->name.toString();
param.playerName = cb->getStartInfo()->playerInfos.find(*cb->getPlayerID())->second.name;
HighScoreCalculation highScoreCalc;
highScoreCalc.parameters.push_back(param);
highScoreCalc.isCampaign = false;
if(won && cb->getStartInfo()->campState)
CSH->startCampaignScenario(param, cb->getStartInfo()->campState);
else
{
GH.dispatchMainThread(
[won, highScoreCalc]()
{
CSH->endGameplay();
GH.defActionsDef = 63;
CMM->menu->switchToTab("main");
GH.windows().createAndPushWindow<CHighScoreInputScreen>(won, highScoreCalc);
}
);
}
}
void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al)
{
if(auto hero = cb->getHero(al.artHolder))