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:
commit
bea80a60fb
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user