1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-07 07:10:04 +02:00

fix visiting objects other than town

This commit is contained in:
Laserlicht 2024-02-28 23:13:51 +01:00
parent b0b3b9bb84
commit 37f621abbd
3 changed files with 20 additions and 3 deletions

View File

@ -4194,6 +4194,19 @@ const CGHeroInstance * CGameHandler::getVisitingHero(const CGObjectInstance *obj
return nullptr; 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) bool CGameHandler::isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero)
{ {
assert(obj); assert(obj);

View File

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

View File

@ -98,9 +98,12 @@ void CBattleDialogQuery::onRemoval(PlayerColor color)
} }
else else
{ {
if(result && bi->getDefendedTown()) auto hero = bi->getSideHero(BattleSide::ATTACKER);
bi->getDefendedTown()->battleFinished(bi->getSideHero(BattleSide::ATTACKER), *result); auto visitingObj = bi->getDefendedTown() ? bi->getDefendedTown() : gh->getVisitingObject(hero);
gh->battles->endBattleConfirm(bi->getBattleID()); gh->battles->endBattleConfirm(bi->getBattleID());
if(visitingObj)
visitingObj->battleFinished(hero, *result);
} }
} }