1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

fix castle replay

This commit is contained in:
Laserlicht 2024-02-28 22:25:14 +01:00
parent 8d86216332
commit b0b3b9bb84
3 changed files with 10 additions and 14 deletions

View File

@ -282,7 +282,7 @@ void BattleResultProcessor::endBattle(const CBattleInfoCallback & battle)
// in battles against neutrals attacker can ask to replay battle manually, additionally in battles against AI player human side can also ask for replay
if(onlyOnePlayerHuman)
{
auto battleDialogQuery = std::make_shared<CBattleDialogQuery>(gameHandler, battle.getBattle());
auto battleDialogQuery = std::make_shared<CBattleDialogQuery>(gameHandler, battle.getBattle(), battleQuery->result);
battleResult->queryID = battleDialogQuery->queryID;
gameHandler->queries->addQuery(battleDialogQuery);
}

View File

@ -19,17 +19,10 @@
#include "../../lib/battle/SideInBattle.h"
#include "../../lib/CPlayerState.h"
#include "../../lib/mapObjects/CGObjectInstance.h"
#include "../../lib/mapObjects/CGTownInstance.h"
#include "../../lib/networkPacks/PacksForServer.h"
#include "../../lib/serializer/Cast.h"
void CBattleQuery::notifyObjectAboutRemoval(const CObjectVisitQuery & objectVisit) const
{
assert(result);
if(result)
objectVisit.visitedObject->battleFinished(objectVisit.visitingHero, *result);
}
CBattleQuery::CBattleQuery(CGameHandler * owner, const IBattleInfo * bi):
CQuery(owner),
battleID(bi->getBattleID())
@ -75,9 +68,10 @@ void CBattleQuery::onExposure(QueryPtr topQuery)
owner->popQuery(*this);
}
CBattleDialogQuery::CBattleDialogQuery(CGameHandler * owner, const IBattleInfo * bi):
CBattleDialogQuery::CBattleDialogQuery(CGameHandler * owner, const IBattleInfo * bi, std::optional<BattleResult> Br):
CDialogQuery(owner),
bi(bi)
bi(bi),
result(Br)
{
addPlayer(bi->getSidePlayer(0));
addPlayer(bi->getSidePlayer(1));
@ -104,6 +98,9 @@ void CBattleDialogQuery::onRemoval(PlayerColor color)
}
else
{
if(result && bi->getDefendedTown())
bi->getDefendedTown()->battleFinished(bi->getSideHero(BattleSide::ATTACKER), *result);
gh->battles->endBattleConfirm(bi->getBattleID());
}
}

View File

@ -28,7 +28,6 @@ public:
CBattleQuery(CGameHandler * owner);
CBattleQuery(CGameHandler * owner, const IBattleInfo * Bi); //TODO
void notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) const override;
bool blocksPack(const CPack *pack) const override;
void onRemoval(PlayerColor color) override;
void onExposure(QueryPtr topQuery) override;
@ -37,9 +36,9 @@ public:
class CBattleDialogQuery : public CDialogQuery
{
public:
CBattleDialogQuery(CGameHandler * owner, const IBattleInfo * Bi);
CBattleDialogQuery(CGameHandler * owner, const IBattleInfo * Bi, std::optional<BattleResult> Br);
const IBattleInfo * bi;
std::optional<BattleResult> result;
void onRemoval(PlayerColor color) override;
};