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:
parent
327ff01471
commit
29f87d6407
@ -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<const PlayerMessage *>(pack) != nullptr)
|
||||
return false;
|
||||
|
||||
auto query = queries->topQuery(player);
|
||||
|
@ -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):
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -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<int32_t> reply);
|
||||
virtual std::string toString() const;
|
||||
|
||||
virtual ~CQuery();
|
||||
protected:
|
||||
|
@ -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<const CGTeleport*>(objectVisit.visitedObject);
|
||||
auto obj = dynamic_cast<const CGTeleport*>(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):
|
||||
|
@ -73,7 +73,7 @@ public:
|
||||
std::array<const CArmedInstance *,2> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user