1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-25 21:38:59 +02:00

Fix headless mode

This commit is contained in:
Andrii Danylchenko 2023-12-03 18:39:25 +02:00
parent 6b760089a4
commit cc7fc4a2c6
5 changed files with 29 additions and 14 deletions

View File

@ -588,6 +588,8 @@ float RewardEvaluator::getSkillReward(const CGObjectInstance * target, const CGH
case Obj::PANDORAS_BOX:
//Can contains experience, spells, or skills (only on custom maps)
return 2.5f;
case Obj::PYRAMID:
return 3.0f;
case Obj::HERO:
return ai->cb->getPlayerRelations(target->tempOwner, ai->playerID) == PlayerRelations::ENEMIES
? enemyHeroEliminationSkillRewardRatio * dynamic_cast<const CGHeroInstance *>(target)->level

View File

@ -462,9 +462,9 @@ static void mainLoop()
{
if(CSH->client)
CSH->endGameplay();
}
GH.windows().clear();
GH.windows().clear();
}
CMM.reset();

View File

@ -617,7 +617,9 @@ bool CServerHandler::validateGameStart(bool allowOnlyAI) const
void CServerHandler::sendStartGame(bool allowOnlyAI) const
{
verifyStateBeforeStart(allowOnlyAI ? true : settings["session"]["onlyai"].Bool());
GH.windows().createAndPushWindow<CLoadingScreen>();
if(!settings["session"]["headless"].Bool())
GH.windows().createAndPushWindow<CLoadingScreen>();
LobbyStartGame lsg;
if(client)

View File

@ -411,7 +411,7 @@ void CClient::initPlayerEnvironments()
hasHumanPlayer = true;
}
if(!hasHumanPlayer)
if(!hasHumanPlayer && !settings["session"]["headless"].Bool())
{
Settings session = settings.write["session"];
session["spectate"].Bool() = true;
@ -436,7 +436,7 @@ void CClient::initPlayerInterfaces()
if(!vstd::contains(playerint, color))
{
logNetwork->info("Preparing interface for player %s", color.toString());
if(playerInfo.second.isControlledByAI())
if(playerInfo.second.isControlledByAI() || settings["session"]["onlyai"].Bool())
{
bool alliedToHuman = false;
for(auto & allyInfo : gs->scenarioOps->playerInfos)

View File

@ -157,6 +157,9 @@ void ApplyClientNetPackVisitor::visitSetMana(SetMana & pack)
const CGHeroInstance *h = cl.getHero(pack.hid);
callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroManaPointsChanged, h);
if(settings["session"]["headless"].Bool())
return;
for (auto window : GH.windows().findWindows<BattleWindow>())
window->heroManaPointsChanged(h);
}
@ -467,7 +470,8 @@ void ApplyFirstClientNetPackVisitor::visitRemoveObject(RemoveObject & pack)
i->second->objectRemoved(o, pack.initiator);
}
CGI->mh->waitForOngoingAnimations();
if(CGI->mh)
CGI->mh->waitForOngoingAnimations();
}
void ApplyClientNetPackVisitor::visitRemoveObject(RemoveObject & pack)
@ -553,9 +557,11 @@ void ApplyClientNetPackVisitor::visitNewStructures(NewStructures & pack)
}
// invalidate section of map view with our object and force an update
CGI->mh->onObjectInstantRemove(town, town->getOwner());
CGI->mh->onObjectInstantAdd(town, town->getOwner());
if(CGI->mh)
{
CGI->mh->onObjectInstantRemove(town, town->getOwner());
CGI->mh->onObjectInstantAdd(town, town->getOwner());
}
}
void ApplyClientNetPackVisitor::visitRazeStructures(RazeStructures & pack)
{
@ -566,8 +572,11 @@ void ApplyClientNetPackVisitor::visitRazeStructures(RazeStructures & pack)
}
// invalidate section of map view with our object and force an update
CGI->mh->onObjectInstantRemove(town, town->getOwner());
CGI->mh->onObjectInstantAdd(town, town->getOwner());
if(CGI->mh)
{
CGI->mh->onObjectInstantRemove(town, town->getOwner());
CGI->mh->onObjectInstantAdd(town, town->getOwner());
}
}
void ApplyClientNetPackVisitor::visitSetAvailableCreatures(SetAvailableCreatures & pack)
@ -651,7 +660,7 @@ void ApplyFirstClientNetPackVisitor::visitSetObjectProperty(SetObjectProperty &
}
// invalidate section of map view with our object and force an update with new flag color
if (pack.what == ObjProperty::OWNER)
if (pack.what == ObjProperty::OWNER && CGI->mh)
{
auto object = gs.getObjInstance(pack.id);
CGI->mh->onObjectInstantRemove(object, object->getOwner());
@ -668,7 +677,7 @@ void ApplyClientNetPackVisitor::visitSetObjectProperty(SetObjectProperty & pack)
}
// invalidate section of map view with our object and force an update with new flag color
if (pack.what == ObjProperty::OWNER)
if (pack.what == ObjProperty::OWNER && CGI->mh)
{
auto object = gs.getObjInstance(pack.id);
CGI->mh->onObjectInstantAdd(object, object->getOwner());
@ -1023,7 +1032,9 @@ void ApplyClientNetPackVisitor::visitNewObject(NewObject & pack)
if(gs.isVisible(obj, i->first))
i->second->newObject(obj);
}
CGI->mh->waitForOngoingAnimations();
if(CGI->mh)
CGI->mh->waitForOngoingAnimations();
}
void ApplyClientNetPackVisitor::visitSetAvailableArtifacts(SetAvailableArtifacts & pack)