|
@@ -401,18 +401,23 @@ void CClient::initPlayerEnvironments()
|
|
|
playerEnvironments.clear();
|
|
|
|
|
|
auto allPlayers = CSH->getAllClientPlayers(CSH->c->connectionID);
|
|
|
- if(allPlayers.empty())
|
|
|
- {
|
|
|
- Settings session = settings.write["session"];
|
|
|
- session["spectate"].Bool() = true;
|
|
|
- }
|
|
|
-
|
|
|
+ bool hasHumanPlayer = false;
|
|
|
for(auto & color : allPlayers)
|
|
|
{
|
|
|
logNetwork->info("Preparing environment for player %s", color.getStr());
|
|
|
playerEnvironments[color] = std::make_shared<CPlayerEnvironment>(color, this, std::make_shared<CCallback>(gs, color, this));
|
|
|
+
|
|
|
+ if(!hasHumanPlayer && gs->players[color].isHuman())
|
|
|
+ hasHumanPlayer = true;
|
|
|
}
|
|
|
|
|
|
+ if(!hasHumanPlayer)
|
|
|
+ {
|
|
|
+ Settings session = settings.write["session"];
|
|
|
+ session["spectate"].Bool() = true;
|
|
|
+ session["spectate-skip-battle-result"].Bool() = true;
|
|
|
+ }
|
|
|
+
|
|
|
if(settings["session"]["spectate"].Bool())
|
|
|
{
|
|
|
playerEnvironments[PlayerColor::SPECTATOR] = std::make_shared<CPlayerEnvironment>(PlayerColor::SPECTATOR, this, std::make_shared<CCallback>(gs, boost::none, this));
|
|
@@ -581,27 +586,29 @@ void CClient::battleStarted(const BattleInfo * info)
|
|
|
if(vstd::contains(playerint, rightSide.color) && playerint[rightSide.color]->human)
|
|
|
def = std::dynamic_pointer_cast<CPlayerInterface>(playerint[rightSide.color]);
|
|
|
|
|
|
+ auto spectratorInterface = std::dynamic_pointer_cast<CPlayerInterface>(playerint[PlayerColor::SPECTATOR]);
|
|
|
+
|
|
|
//Remove player interfaces for auto battle (quickCombat option)
|
|
|
if(att && att->isAutoFightOn)
|
|
|
{
|
|
|
att.reset();
|
|
|
def.reset();
|
|
|
+ spectratorInterface.reset();
|
|
|
}
|
|
|
-
|
|
|
- if(!settings["session"]["headless"].Bool())
|
|
|
+ else if(!settings["session"]["headless"].Bool())
|
|
|
{
|
|
|
if(!!att || !!def)
|
|
|
{
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*CPlayerInterface::pim);
|
|
|
CPlayerInterface::battleInt = std::make_shared<BattleInterface>(leftSide.armyObject, rightSide.armyObject, leftSide.hero, rightSide.hero, att, def);
|
|
|
}
|
|
|
- else if(settings["session"]["spectate"].Bool() && !settings["session"]["spectate-skip-battle"].Bool())
|
|
|
+ else if(false && settings["session"]["spectate"].Bool() && !settings["session"]["spectate-skip-battle"].Bool())
|
|
|
{
|
|
|
+ //spectator for AI-only battles
|
|
|
//TODO: This certainly need improvement
|
|
|
- auto spectratorInt = std::dynamic_pointer_cast<CPlayerInterface>(playerint[PlayerColor::SPECTATOR]);
|
|
|
- spectratorInt->cb->setBattle(info);
|
|
|
+ spectratorInterface->cb->setBattle(info);
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*CPlayerInterface::pim);
|
|
|
- CPlayerInterface::battleInt = std::make_shared<BattleInterface>(leftSide.armyObject, rightSide.armyObject, leftSide.hero, rightSide.hero, att, def, spectratorInt);
|
|
|
+ CPlayerInterface::battleInt = std::make_shared<BattleInterface>(leftSide.armyObject, rightSide.armyObject, leftSide.hero, rightSide.hero, att, def, spectratorInterface);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -637,7 +644,7 @@ void CClient::battleFinished()
|
|
|
if(battleCallbacks.count(side.color))
|
|
|
battleCallbacks[side.color]->setBattle(nullptr);
|
|
|
|
|
|
- if(settings["session"]["spectate"].Bool() && !settings["session"]["spectate-skip-battle"].Bool())
|
|
|
+ if(battleCallbacks[PlayerColor::SPECTATOR])
|
|
|
battleCallbacks[PlayerColor::SPECTATOR]->setBattle(nullptr);
|
|
|
|
|
|
setBattle(nullptr);
|