1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #3644 from Laserlicht/fix_castle_replay

fix castle quick combat
This commit is contained in:
Ivan Savenko 2024-03-07 10:21:19 +02:00 committed by GitHub
commit bea80a60fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 32 additions and 6 deletions

View File

@ -4194,6 +4194,19 @@ const CGHeroInstance * CGameHandler::getVisitingHero(const CGObjectInstance *obj
return nullptr;
}
const CGObjectInstance * CGameHandler::getVisitingObject(const CGHeroInstance *hero)
{
assert(hero);
for(const auto & query : queries->allQueries())
{
auto visit = std::dynamic_pointer_cast<const CObjectVisitQuery>(query);
if (visit && visit->visitingHero == hero)
return visit->visitedObject;
}
return nullptr;
}
bool CGameHandler::isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero)
{
assert(obj);

View File

@ -154,6 +154,7 @@ public:
/// Returns hero that is currently visiting this object, or nullptr if no visit is active
const CGHeroInstance * getVisitingHero(const CGObjectInstance *obj);
const CGObjectInstance * getVisitingObject(const CGHeroInstance *hero);
bool isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero) override;
void setObjPropertyValue(ObjectInstanceID objid, ObjProperty prop, int32_t value) override;
void setObjPropertyID(ObjectInstanceID objid, ObjProperty prop, ObjPropertyID identifier) override;

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,6 +19,7 @@
#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"
@ -26,7 +27,7 @@ void CBattleQuery::notifyObjectAboutRemoval(const CObjectVisitQuery & objectVisi
{
assert(result);
if(result)
if(result && !isAiVsHuman)
objectVisit.visitedObject->battleFinished(objectVisit.visitingHero, *result);
}
@ -37,6 +38,8 @@ CBattleQuery::CBattleQuery(CGameHandler * owner, const IBattleInfo * bi):
belligerents[0] = bi->getSideArmy(0);
belligerents[1] = bi->getSideArmy(1);
isAiVsHuman = bi->getSidePlayer(1).isValidPlayer() && gh->getPlayerState(bi->getSidePlayer(0))->isHuman() != gh->getPlayerState(bi->getSidePlayer(1))->isHuman();
addPlayer(bi->getSidePlayer(0));
addPlayer(bi->getSidePlayer(1));
}
@ -75,9 +78,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 +108,13 @@ void CBattleDialogQuery::onRemoval(PlayerColor color)
}
else
{
auto hero = bi->getSideHero(BattleSide::ATTACKER);
auto visitingObj = bi->getDefendedTown() ? bi->getDefendedTown() : gh->getVisitingObject(hero);
bool isAiVsHuman = bi->getSidePlayer(1).isValidPlayer() && gh->getPlayerState(bi->getSidePlayer(0))->isHuman() != gh->getPlayerState(bi->getSidePlayer(1))->isHuman();
gh->battles->endBattleConfirm(bi->getBattleID());
if(visitingObj && result && isAiVsHuman)
visitingObj->battleFinished(hero, *result);
}
}

View File

@ -23,6 +23,7 @@ public:
std::array<const CArmedInstance *,2> belligerents;
std::array<int, 2> initialHeroMana;
bool isAiVsHuman;
BattleID battleID;
std::optional<BattleResult> result;
@ -37,9 +38,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;
};