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

pass object/hero parameters directly instead of passing query

This commit is contained in:
Ivan Savenko 2024-09-04 14:17:22 +00:00
parent 327ff01471
commit 29f87d6407
7 changed files with 43 additions and 30 deletions

View File

@ -3851,7 +3851,7 @@ bool CGameHandler::isValidObject(const CGObjectInstance *obj) const
bool CGameHandler::isBlockedByQueries(const CPack *pack, PlayerColor player) bool CGameHandler::isBlockedByQueries(const CPack *pack, PlayerColor player)
{ {
if (!strcmp(typeid(*pack).name(), typeid(PlayerMessage).name())) if (dynamic_cast<const PlayerMessage *>(pack) != nullptr)
return false; return false;
auto query = queries->topQuery(player); auto query = queries->topQuery(player);

View File

@ -23,12 +23,12 @@
#include "../../lib/networkPacks/PacksForServer.h" #include "../../lib/networkPacks/PacksForServer.h"
#include "../../lib/serializer/Cast.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); assert(result);
if(result) if(result)
objectVisit.visitedObject->battleFinished(objectVisit.visitingHero, *result); visitedObject->battleFinished(visitingHero, *result);
} }
CBattleQuery::CBattleQuery(CGameHandler * owner, const IBattleInfo * bi): CBattleQuery::CBattleQuery(CGameHandler * owner, const IBattleInfo * bi):

View File

@ -29,7 +29,7 @@ public:
CBattleQuery(CGameHandler * owner); CBattleQuery(CGameHandler * owner);
CBattleQuery(CGameHandler * owner, const IBattleInfo * Bi); //TODO 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; bool blocksPack(const CPack *pack) const override;
void onRemoval(PlayerColor color) override; void onRemoval(PlayerColor color) override;
void onExposure(QueryPtr topQuery) override; void onExposure(QueryPtr topQuery) override;

View File

@ -87,7 +87,7 @@ bool CQuery::blocksPack(const CPack * pack) const
return false; return false;
} }
void CQuery::notifyObjectAboutRemoval(const CObjectVisitQuery & objectVisit) const void CQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const
{ {
} }

View File

@ -14,6 +14,8 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
struct CPack; struct CPack;
class CGObjectInstance;
class CGHeroInstance;
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END
@ -40,18 +42,29 @@ public:
CQuery(CGameHandler * gh); 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) /// query is removed after player gives answer (like dialogs)
virtual void onAdding(PlayerColor color); //called just before query is pushed on stack virtual bool endsByPlayerAnswer() const;
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;
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<int32_t> reply); virtual void setReply(std::optional<int32_t> reply);
virtual std::string toString() const;
virtual ~CQuery(); virtual ~CQuery();
protected: protected:

View File

@ -71,14 +71,14 @@ void CObjectVisitQuery::onExposure(QueryPtr topQuery)
{ {
//Object may have been removed and deleted. //Object may have been removed and deleted.
if(gh->isValidObject(visitedObject)) if(gh->isValidObject(visitedObject))
topQuery->notifyObjectAboutRemoval(*this); topQuery->notifyObjectAboutRemoval(visitedObject, visitingHero);
owner->popIfTop(*this); 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): 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); return CDialogQuery::blocksPack(pack);
} }
void CBlockingDialogQuery::notifyObjectAboutRemoval(const CObjectVisitQuery & objectVisit) const void CBlockingDialogQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const
{ {
assert(answer); assert(answer);
objectVisit.visitedObject->blockingDialogAnswered(objectVisit.visitingHero, *answer); visitedObject->blockingDialogAnswered(visitingHero, *answer);
} }
CBlockingDialogQuery::CBlockingDialogQuery(CGameHandler * owner, const BlockingDialog & bd): CBlockingDialogQuery::CBlockingDialogQuery(CGameHandler * owner, const BlockingDialog & bd):
@ -223,12 +223,12 @@ bool OpenWindowQuery::blocksPack(const CPack *pack) const
return CDialogQuery::blocksPack(pack); 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! // do not change to dynamic_ptr_cast - SIGSEGV!
auto obj = dynamic_cast<const CGTeleport*>(objectVisit.visitedObject); auto obj = dynamic_cast<const CGTeleport*>(visitedObject);
if(obj) if(obj)
obj->teleportDialogAnswered(objectVisit.visitingHero, *answer, td.exits); obj->teleportDialogAnswered(visitingHero, *answer, td.exits);
else else
logGlobal->error("Invalid instance in teleport query"); logGlobal->error("Invalid instance in teleport query");
} }
@ -254,9 +254,9 @@ void CHeroLevelUpDialogQuery::onRemoval(PlayerColor color)
gh->levelUpHero(hero, hlu.skills[*answer]); 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): 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]); 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): CHeroMovementQuery::CHeroMovementQuery(CGameHandler * owner, const TryMoveHero & Tmh, const CGHeroInstance * Hero, bool VisitDestAfterVictory):

View File

@ -73,7 +73,7 @@ public:
std::array<const CArmedInstance *,2> exchangingArmies; std::array<const CArmedInstance *,2> exchangingArmies;
CGarrisonDialogQuery(CGameHandler * owner, const CArmedInstance *up, const CArmedInstance *down); 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; bool blocksPack(const CPack *pack) const override;
}; };
@ -85,7 +85,7 @@ public:
CBlockingDialogQuery(CGameHandler * owner, const BlockingDialog &bd); 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 class OpenWindowQuery : public CDialogQuery
@ -105,7 +105,7 @@ public:
CTeleportDialogQuery(CGameHandler * owner, const TeleportDialog &td); 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 class CHeroLevelUpDialogQuery : public CDialogQuery
@ -114,7 +114,7 @@ public:
CHeroLevelUpDialogQuery(CGameHandler * owner, const HeroLevelUp &Hlu, const CGHeroInstance * Hero); CHeroLevelUpDialogQuery(CGameHandler * owner, const HeroLevelUp &Hlu, const CGHeroInstance * Hero);
void onRemoval(PlayerColor color) override; void onRemoval(PlayerColor color) override;
void notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) const override; void notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const override;
HeroLevelUp hlu; HeroLevelUp hlu;
const CGHeroInstance * hero; const CGHeroInstance * hero;
@ -126,7 +126,7 @@ public:
CCommanderLevelUpDialogQuery(CGameHandler * owner, const CommanderLevelUp &Clu, const CGHeroInstance * Hero); CCommanderLevelUpDialogQuery(CGameHandler * owner, const CommanderLevelUp &Clu, const CGHeroInstance * Hero);
void onRemoval(PlayerColor color) override; void onRemoval(PlayerColor color) override;
void notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) const override; void notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const override;
CommanderLevelUp clu; CommanderLevelUp clu;
const CGHeroInstance * hero; const CGHeroInstance * hero;