diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index eab97a9db..5f2b8fd3d 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -3851,7 +3851,7 @@ bool CGameHandler::isValidObject(const CGObjectInstance *obj) const bool CGameHandler::isBlockedByQueries(const CPack *pack, PlayerColor player) { - if (!strcmp(typeid(*pack).name(), typeid(PlayerMessage).name())) + if (dynamic_cast(pack) != nullptr) return false; auto query = queries->topQuery(player); diff --git a/server/queries/BattleQueries.cpp b/server/queries/BattleQueries.cpp index 4fc0c25f0..a1fa45158 100644 --- a/server/queries/BattleQueries.cpp +++ b/server/queries/BattleQueries.cpp @@ -23,12 +23,12 @@ #include "../../lib/networkPacks/PacksForServer.h" #include "../../lib/serializer/Cast.h" -void CBattleQuery::notifyObjectAboutRemoval(const CObjectVisitQuery & objectVisit) const +void CBattleQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const { assert(result); if(result) - objectVisit.visitedObject->battleFinished(objectVisit.visitingHero, *result); + visitedObject->battleFinished(visitingHero, *result); } CBattleQuery::CBattleQuery(CGameHandler * owner, const IBattleInfo * bi): diff --git a/server/queries/BattleQueries.h b/server/queries/BattleQueries.h index 6916cb7f5..ae32b08b3 100644 --- a/server/queries/BattleQueries.h +++ b/server/queries/BattleQueries.h @@ -29,7 +29,7 @@ public: CBattleQuery(CGameHandler * owner); CBattleQuery(CGameHandler * owner, const IBattleInfo * Bi); //TODO - void notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) const override; + void notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const override; bool blocksPack(const CPack *pack) const override; void onRemoval(PlayerColor color) override; void onExposure(QueryPtr topQuery) override; diff --git a/server/queries/CQuery.cpp b/server/queries/CQuery.cpp index 02eb14762..f4f4508da 100644 --- a/server/queries/CQuery.cpp +++ b/server/queries/CQuery.cpp @@ -87,7 +87,7 @@ bool CQuery::blocksPack(const CPack * pack) const return false; } -void CQuery::notifyObjectAboutRemoval(const CObjectVisitQuery & objectVisit) const +void CQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const { } diff --git a/server/queries/CQuery.h b/server/queries/CQuery.h index 5773ecadd..2fde16295 100644 --- a/server/queries/CQuery.h +++ b/server/queries/CQuery.h @@ -14,6 +14,8 @@ VCMI_LIB_NAMESPACE_BEGIN struct CPack; +class CGObjectInstance; +class CGHeroInstance; VCMI_LIB_NAMESPACE_END @@ -40,18 +42,29 @@ public: CQuery(CGameHandler * gh); - virtual bool blocksPack(const CPack *pack) const; //query can block attempting actions by player. Eg. he can't move hero during the battle. + /// query can block attempting actions by player. Eg. he can't move hero during the battle. + virtual bool blocksPack(const CPack *pack) const; - virtual bool endsByPlayerAnswer() const; //query is removed after player gives answer (like dialogs) - virtual void onAdding(PlayerColor color); //called just before query is pushed on stack - virtual void onAdded(PlayerColor color); //called right after query is pushed on stack - virtual void onRemoval(PlayerColor color); //called after query is removed from stack - virtual void onExposure(QueryPtr topQuery);//called when query immediately above is removed and this is exposed (becomes top) - virtual std::string toString() const; + /// query is removed after player gives answer (like dialogs) + virtual bool endsByPlayerAnswer() const; - virtual void notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) const; + /// called just before query is pushed on stack + virtual void onAdding(PlayerColor color); + + /// called right after query is pushed on stack + virtual void onAdded(PlayerColor color); + + /// called after query is removed from stack + virtual void onRemoval(PlayerColor color); + + /// called when query immediately above is removed and this is exposed (becomes top) + virtual void onExposure(QueryPtr topQuery); + + /// called when this query is being removed and must report its result to currently visited object + virtual void notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const; virtual void setReply(std::optional reply); + virtual std::string toString() const; virtual ~CQuery(); protected: diff --git a/server/queries/MapQueries.cpp b/server/queries/MapQueries.cpp index 72f9bfbce..60942c88b 100644 --- a/server/queries/MapQueries.cpp +++ b/server/queries/MapQueries.cpp @@ -71,14 +71,14 @@ void CObjectVisitQuery::onExposure(QueryPtr topQuery) { //Object may have been removed and deleted. if(gh->isValidObject(visitedObject)) - topQuery->notifyObjectAboutRemoval(*this); + topQuery->notifyObjectAboutRemoval(visitedObject, visitingHero); owner->popIfTop(*this); } -void CGarrisonDialogQuery::notifyObjectAboutRemoval(const CObjectVisitQuery & objectVisit) const +void CGarrisonDialogQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const { - objectVisit.visitedObject->garrisonDialogClosed(objectVisit.visitingHero); + visitedObject->garrisonDialogClosed(visitingHero); } CGarrisonDialogQuery::CGarrisonDialogQuery(CGameHandler * owner, const CArmedInstance * up, const CArmedInstance * down): @@ -150,10 +150,10 @@ bool CGarrisonDialogQuery::blocksPack(const CPack * pack) const return CDialogQuery::blocksPack(pack); } -void CBlockingDialogQuery::notifyObjectAboutRemoval(const CObjectVisitQuery & objectVisit) const +void CBlockingDialogQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const { assert(answer); - objectVisit.visitedObject->blockingDialogAnswered(objectVisit.visitingHero, *answer); + visitedObject->blockingDialogAnswered(visitingHero, *answer); } CBlockingDialogQuery::CBlockingDialogQuery(CGameHandler * owner, const BlockingDialog & bd): @@ -223,12 +223,12 @@ bool OpenWindowQuery::blocksPack(const CPack *pack) const return CDialogQuery::blocksPack(pack); } -void CTeleportDialogQuery::notifyObjectAboutRemoval(const CObjectVisitQuery & objectVisit) const +void CTeleportDialogQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const { // do not change to dynamic_ptr_cast - SIGSEGV! - auto obj = dynamic_cast(objectVisit.visitedObject); + auto obj = dynamic_cast(visitedObject); if(obj) - obj->teleportDialogAnswered(objectVisit.visitingHero, *answer, td.exits); + obj->teleportDialogAnswered(visitingHero, *answer, td.exits); else logGlobal->error("Invalid instance in teleport query"); } @@ -254,9 +254,9 @@ void CHeroLevelUpDialogQuery::onRemoval(PlayerColor color) gh->levelUpHero(hero, hlu.skills[*answer]); } -void CHeroLevelUpDialogQuery::notifyObjectAboutRemoval(const CObjectVisitQuery & objectVisit) const +void CHeroLevelUpDialogQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const { - objectVisit.visitedObject->heroLevelUpDone(objectVisit.visitingHero); + visitedObject->heroLevelUpDone(visitingHero); } CCommanderLevelUpDialogQuery::CCommanderLevelUpDialogQuery(CGameHandler * owner, const CommanderLevelUp & Clu, const CGHeroInstance * Hero): @@ -273,9 +273,9 @@ void CCommanderLevelUpDialogQuery::onRemoval(PlayerColor color) gh->levelUpCommander(hero->commander, clu.skills[*answer]); } -void CCommanderLevelUpDialogQuery::notifyObjectAboutRemoval(const CObjectVisitQuery & objectVisit) const +void CCommanderLevelUpDialogQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const { - objectVisit.visitedObject->heroLevelUpDone(objectVisit.visitingHero); + visitedObject->heroLevelUpDone(visitingHero); } CHeroMovementQuery::CHeroMovementQuery(CGameHandler * owner, const TryMoveHero & Tmh, const CGHeroInstance * Hero, bool VisitDestAfterVictory): diff --git a/server/queries/MapQueries.h b/server/queries/MapQueries.h index 7a6cabf3c..e81c8a72b 100644 --- a/server/queries/MapQueries.h +++ b/server/queries/MapQueries.h @@ -73,7 +73,7 @@ public: std::array exchangingArmies; CGarrisonDialogQuery(CGameHandler * owner, const CArmedInstance *up, const CArmedInstance *down); - void notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) const override; + void notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const override; bool blocksPack(const CPack *pack) const override; }; @@ -85,7 +85,7 @@ public: CBlockingDialogQuery(CGameHandler * owner, const BlockingDialog &bd); - void notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) const override; + void notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const override; }; class OpenWindowQuery : public CDialogQuery @@ -105,7 +105,7 @@ public: CTeleportDialogQuery(CGameHandler * owner, const TeleportDialog &td); - void notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) const override; + void notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const override; }; class CHeroLevelUpDialogQuery : public CDialogQuery @@ -114,7 +114,7 @@ public: CHeroLevelUpDialogQuery(CGameHandler * owner, const HeroLevelUp &Hlu, const CGHeroInstance * Hero); void onRemoval(PlayerColor color) override; - void notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) const override; + void notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const override; HeroLevelUp hlu; const CGHeroInstance * hero; @@ -126,7 +126,7 @@ public: CCommanderLevelUpDialogQuery(CGameHandler * owner, const CommanderLevelUp &Clu, const CGHeroInstance * Hero); void onRemoval(PlayerColor color) override; - void notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) const override; + void notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const override; CommanderLevelUp clu; const CGHeroInstance * hero;