2017-07-13 11:26:03 +03:00
|
|
|
/*
|
|
|
|
* CQuery.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2013-04-20 11:34:01 +00:00
|
|
|
#pragma once
|
2023-07-24 00:00:37 +03:00
|
|
|
|
2023-07-24 00:20:35 +03:00
|
|
|
#include "../../lib/GameConstants.h"
|
2023-07-24 00:46:29 +03:00
|
|
|
#include "../../lib/JsonNode.h"
|
2013-04-20 11:34:01 +00:00
|
|
|
|
2022-07-26 16:07:42 +03:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2023-07-24 00:46:29 +03:00
|
|
|
struct CPack;
|
2022-07-26 16:07:42 +03:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2013-04-20 11:34:01 +00:00
|
|
|
class CObjectVisitQuery;
|
2023-07-24 00:46:29 +03:00
|
|
|
class QueriesProcessor;
|
2013-04-20 11:34:01 +00:00
|
|
|
class CQuery;
|
|
|
|
|
2023-04-18 00:11:16 +03:00
|
|
|
using QueryPtr = std::shared_ptr<CQuery>;
|
2013-04-20 11:34:01 +00:00
|
|
|
|
|
|
|
// This class represents any kind of prolonged interaction that may need to do something special after it is over.
|
|
|
|
// It does not necessarily has to be "query" requiring player action, it can be also used internally within server.
|
|
|
|
// Examples:
|
2017-06-06 07:53:51 +03:00
|
|
|
// - all kinds of blocking dialog windows
|
|
|
|
// - battle
|
2013-04-20 11:34:01 +00:00
|
|
|
// - object visit
|
|
|
|
// - hero movement
|
|
|
|
// Queries can cause another queries, forming a stack of queries for each player. Eg: hero movement -> object visit -> dialog.
|
|
|
|
class CQuery
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::vector<PlayerColor> players; //players that are affected (often "blocked") by query
|
2013-05-27 10:53:28 +00:00
|
|
|
QueryID queryID;
|
2013-04-20 11:34:01 +00:00
|
|
|
|
2023-07-24 00:46:29 +03:00
|
|
|
CQuery(QueriesProcessor * Owner);
|
2013-04-20 11:34:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
virtual bool blocksPack(const CPack *pack) const; //query can block attempting actions by player. Eg. he can't move hero during the battle.
|
|
|
|
|
|
|
|
virtual bool endsByPlayerAnswer() const; //query is removed after player gives answer (like dialogs)
|
2017-06-06 07:53:51 +03:00
|
|
|
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)
|
2013-04-20 11:34:01 +00:00
|
|
|
virtual std::string toString() const;
|
|
|
|
|
|
|
|
virtual void notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) const;
|
|
|
|
|
2017-06-06 07:53:51 +03:00
|
|
|
virtual void setReply(const JsonNode & reply);
|
2013-04-20 11:34:01 +00:00
|
|
|
|
2018-01-13 11:43:26 +03:00
|
|
|
virtual ~CQuery();
|
2017-06-06 07:53:51 +03:00
|
|
|
protected:
|
2023-07-24 00:46:29 +03:00
|
|
|
QueriesProcessor * owner;
|
2017-06-06 07:53:51 +03:00
|
|
|
void addPlayer(PlayerColor color);
|
|
|
|
bool blockAllButReply(const CPack * pack) const;
|
2013-04-20 11:34:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &out, const CQuery &query);
|
|
|
|
std::ostream &operator<<(std::ostream &out, QueryPtr query);
|
|
|
|
|
2017-06-06 07:53:51 +03:00
|
|
|
class CGhQuery : public CQuery
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CGhQuery(CGameHandler * owner);
|
|
|
|
protected:
|
|
|
|
CGameHandler * gh;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CDialogQuery : public CGhQuery
|
2013-04-20 11:34:01 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-06-06 07:53:51 +03:00
|
|
|
CDialogQuery(CGameHandler * owner);
|
2013-06-26 11:18:27 +00:00
|
|
|
virtual bool endsByPlayerAnswer() const override;
|
|
|
|
virtual bool blocksPack(const CPack *pack) const override;
|
2017-06-06 07:53:51 +03:00
|
|
|
void setReply(const JsonNode & reply) override;
|
|
|
|
protected:
|
2023-04-16 20:42:56 +03:00
|
|
|
std::optional<ui32> answer;
|
2013-04-20 11:34:01 +00:00
|
|
|
};
|
|
|
|
|
2017-07-03 21:09:27 +03:00
|
|
|
class CGenericQuery : public CQuery
|
2017-06-06 07:53:51 +03:00
|
|
|
{
|
|
|
|
public:
|
2023-07-24 00:46:29 +03:00
|
|
|
CGenericQuery(QueriesProcessor * Owner, PlayerColor color, std::function<void(const JsonNode &)> Callback);
|
2017-06-06 07:53:51 +03:00
|
|
|
|
|
|
|
bool blocksPack(const CPack * pack) const override;
|
|
|
|
bool endsByPlayerAnswer() const override;
|
|
|
|
void onExposure(QueryPtr topQuery) override;
|
2017-07-03 21:09:27 +03:00
|
|
|
void setReply(const JsonNode & reply) override;
|
2023-03-20 16:08:18 +01:00
|
|
|
void onRemoval(PlayerColor color) override;
|
2017-07-03 21:09:27 +03:00
|
|
|
private:
|
|
|
|
std::function<void(const JsonNode &)> callback;
|
2023-03-20 16:08:18 +01:00
|
|
|
JsonNode reply;
|
2017-06-06 07:53:51 +03:00
|
|
|
};
|