2015-12-02 21:39:53 +02:00
|
|
|
/*
|
|
|
|
* CPlayerState.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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
2015-12-02 21:39:53 +02:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
#include <vcmi/Player.h>
|
|
|
|
#include <vcmi/Team.h>
|
|
|
|
|
2023-05-01 19:29:53 +02:00
|
|
|
#include "bonuses/Bonus.h"
|
2023-04-30 16:35:15 +02:00
|
|
|
#include "bonuses/CBonusSystemNode.h"
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
#include "ResourceSet.h"
|
2023-08-14 00:16:25 +02:00
|
|
|
#include "TurnTimerInfo.h"
|
2023-08-19 23:22:31 +02:00
|
|
|
#include "ConstTransitivePtr.h"
|
2015-12-02 21:39:53 +02:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2024-08-25 00:21:26 +02:00
|
|
|
class CGObjectInstance;
|
2015-12-02 21:39:53 +02:00
|
|
|
class CGHeroInstance;
|
|
|
|
class CGTownInstance;
|
|
|
|
class CGDwelling;
|
2022-06-11 17:45:34 +02:00
|
|
|
struct QuestInfo;
|
2015-12-02 21:39:53 +02:00
|
|
|
|
2024-08-25 00:21:26 +02:00
|
|
|
class DLL_LINKAGE PlayerState : public CBonusSystemNode, public Player
|
2015-12-02 21:39:53 +02:00
|
|
|
{
|
2023-11-17 21:18:34 +02:00
|
|
|
struct VisitedObjectGlobal
|
|
|
|
{
|
|
|
|
MapObjectID id;
|
|
|
|
MapObjectSubID subID;
|
|
|
|
|
|
|
|
bool operator < (const VisitedObjectGlobal & other) const
|
|
|
|
{
|
|
|
|
if (id != other.id)
|
|
|
|
return id < other.id;
|
|
|
|
else
|
|
|
|
return subID < other.subID;
|
|
|
|
}
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-11-17 21:18:34 +02:00
|
|
|
{
|
|
|
|
h & id;
|
2024-01-20 20:34:51 +02:00
|
|
|
subID.serializeIdentifier(h, id);
|
2023-11-17 21:18:34 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-08-25 00:21:26 +02:00
|
|
|
std::vector<CGObjectInstance*> ownedObjects;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
std::vector<T> getObjectsOfType() const;
|
|
|
|
|
2015-12-02 21:39:53 +02:00
|
|
|
public:
|
|
|
|
PlayerColor color;
|
|
|
|
bool human; //true if human controlled player, false for AI
|
|
|
|
TeamID team;
|
|
|
|
TResources resources;
|
2024-01-31 01:37:33 +02:00
|
|
|
|
|
|
|
/// list of objects that were "destroyed" by player, either via simple pick-up (e.g. resources) or defeated heroes or wandering monsters
|
|
|
|
std::set<ObjectInstanceID> destroyedObjects;
|
2015-12-02 21:39:53 +02:00
|
|
|
std::set<ObjectInstanceID> visitedObjects; // as a std::set, since most accesses here will be from visited status checks
|
2023-11-17 21:18:34 +02:00
|
|
|
std::set<VisitedObjectGlobal> visitedObjectsGlobal;
|
2015-12-02 21:39:53 +02:00
|
|
|
std::vector<QuestInfo> quests; //store info about all received quests
|
2023-09-20 03:50:35 +02:00
|
|
|
std::vector<Bonus> battleBonuses; //additional bonuses to be added during battle with neutrals
|
2024-04-28 13:02:27 +02:00
|
|
|
std::map<uint32_t, std::map<ArtifactPosition, ArtifactID>> costumesArtifacts;
|
2015-12-02 21:39:53 +02:00
|
|
|
|
2023-09-23 20:41:30 +02:00
|
|
|
bool cheated;
|
2015-12-02 21:39:53 +02:00
|
|
|
bool enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
|
2023-08-19 20:43:50 +02:00
|
|
|
EPlayerStatus status;
|
2023-04-16 19:42:56 +02:00
|
|
|
std::optional<ui8> daysWithoutCastle;
|
2023-08-14 00:16:25 +02:00
|
|
|
TurnTimerInfo turnTimer;
|
2015-12-02 21:39:53 +02:00
|
|
|
|
|
|
|
PlayerState();
|
2023-06-26 16:25:29 +02:00
|
|
|
~PlayerState();
|
2016-07-29 11:27:55 +02:00
|
|
|
|
2015-12-02 21:39:53 +02:00
|
|
|
std::string nodeName() const override;
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
|
2023-04-04 16:52:33 +02:00
|
|
|
PlayerColor getId() const override;
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
TeamID getTeam() const override;
|
|
|
|
bool isHuman() const override;
|
2023-04-05 02:26:29 +02:00
|
|
|
const IBonusBearer * getBonusBearer() const override;
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
int getResourceAmount(int type) const override;
|
2015-12-02 21:39:53 +02:00
|
|
|
|
2023-04-04 16:52:33 +02:00
|
|
|
int32_t getIndex() const override;
|
|
|
|
int32_t getIconIndex() const override;
|
|
|
|
std::string getJsonKey() const override;
|
2024-08-10 16:08:04 +02:00
|
|
|
std::string getModScope() const override;
|
2023-04-04 16:52:33 +02:00
|
|
|
std::string getNameTranslated() const override;
|
|
|
|
std::string getNameTextID() const override;
|
|
|
|
void registerIcons(const IconRegistar & cb) const override;
|
|
|
|
|
2024-08-25 00:21:26 +02:00
|
|
|
std::vector<const CGHeroInstance* > getHeroes() const;
|
|
|
|
std::vector<const CGTownInstance* > getTowns() const;
|
|
|
|
std::vector<CGHeroInstance* > getHeroes();
|
|
|
|
std::vector<CGTownInstance* > getTowns();
|
|
|
|
|
|
|
|
std::vector<const CGObjectInstance* > getOwnedObjects() const;
|
|
|
|
|
|
|
|
void addOwnedObject(CGObjectInstance * object);
|
|
|
|
void removeOwnedObject(CGObjectInstance * object);
|
|
|
|
|
2022-01-25 13:19:48 +02:00
|
|
|
bool checkVanquished() const
|
|
|
|
{
|
2024-08-30 14:25:34 +02:00
|
|
|
return getHeroes().empty() && getTowns().empty();
|
2022-01-25 13:19:48 +02:00
|
|
|
}
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2015-12-02 21:39:53 +02:00
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & color;
|
|
|
|
h & human;
|
|
|
|
h & team;
|
|
|
|
h & resources;
|
|
|
|
h & status;
|
2023-08-14 00:16:25 +02:00
|
|
|
h & turnTimer;
|
2024-08-26 20:55:15 +02:00
|
|
|
|
|
|
|
if (h.version >= Handler::Version::PLAYER_STATE_OWNED_OBJECTS)
|
|
|
|
{
|
|
|
|
h & ownedObjects;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<const CGObjectInstance* > heroes;
|
|
|
|
std::vector<const CGObjectInstance* > towns;
|
|
|
|
std::vector<const CGObjectInstance* > dwellings;
|
|
|
|
|
|
|
|
h & heroes;
|
|
|
|
h & towns;
|
|
|
|
h & dwellings;
|
|
|
|
}
|
2017-07-31 15:35:42 +02:00
|
|
|
h & quests;
|
|
|
|
h & visitedObjects;
|
2023-11-17 21:18:34 +02:00
|
|
|
h & visitedObjectsGlobal;
|
2017-07-31 15:35:42 +02:00
|
|
|
h & status;
|
|
|
|
h & daysWithoutCastle;
|
2023-09-23 20:41:30 +02:00
|
|
|
h & cheated;
|
2023-09-20 03:50:35 +02:00
|
|
|
h & battleBonuses;
|
2024-08-29 20:51:53 +02:00
|
|
|
h & costumesArtifacts;
|
2017-07-31 15:35:42 +02:00
|
|
|
h & enteredLosingCheatCode;
|
|
|
|
h & enteredWinningCheatCode;
|
2015-12-02 21:39:53 +02:00
|
|
|
h & static_cast<CBonusSystemNode&>(*this);
|
2024-08-29 20:51:53 +02:00
|
|
|
h & destroyedObjects;
|
2015-12-02 21:39:53 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DLL_LINKAGE TeamState : public CBonusSystemNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TeamID id; //position in gameState::teams
|
|
|
|
std::set<PlayerColor> players; // members of this team
|
2016-12-12 22:38:12 +02:00
|
|
|
//TODO: boost::array, bool if possible
|
2024-05-07 21:17:05 +02:00
|
|
|
boost::multi_array<ui8, 3> fogOfWarMap; //[z][x][y] true - visible, false - hidden
|
2015-12-02 21:39:53 +02:00
|
|
|
|
2024-08-30 17:24:13 +02:00
|
|
|
std::set<ObjectInstanceID> scoutedObjects;
|
|
|
|
|
2015-12-02 21:39:53 +02:00
|
|
|
TeamState();
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2015-12-02 21:39:53 +02:00
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & id;
|
|
|
|
h & players;
|
2024-05-07 21:17:05 +02:00
|
|
|
if (h.version < Handler::Version::REMOVE_FOG_OF_WAR_POINTER)
|
|
|
|
{
|
|
|
|
struct Helper : public Serializeable
|
|
|
|
{
|
2024-06-01 13:48:30 +02:00
|
|
|
void serialize(Handler &h) const
|
2024-05-07 21:17:05 +02:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
Helper helper;
|
|
|
|
auto ptrHelper = &helper;
|
|
|
|
h & ptrHelper;
|
|
|
|
}
|
|
|
|
|
2017-07-31 15:35:42 +02:00
|
|
|
h & fogOfWarMap;
|
2015-12-02 21:39:53 +02:00
|
|
|
h & static_cast<CBonusSystemNode&>(*this);
|
2024-08-30 17:24:13 +02:00
|
|
|
|
2024-08-31 17:28:58 +02:00
|
|
|
if (h.version >= Handler::Version::REWARDABLE_BANKS)
|
2024-08-30 17:24:13 +02:00
|
|
|
h & scoutedObjects;
|
2015-12-02 21:39:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|