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
|
|
|
/*
|
|
|
|
* CPlayerState.cpp, 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
|
|
|
|
#include "CPlayerState.h"
|
2024-10-08 21:55:51 +02:00
|
|
|
#include "json/JsonNode.h"
|
2024-08-25 00:21:26 +02:00
|
|
|
#include "mapObjects/CGDwelling.h"
|
|
|
|
#include "mapObjects/CGTownInstance.h"
|
|
|
|
#include "mapObjects/CGHeroInstance.h"
|
2023-06-23 17:02:48 +02:00
|
|
|
#include "gameState/QuestInfo.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "texts/CGeneralTextHandler.h"
|
2023-09-04 21:21:02 +02:00
|
|
|
#include "VCMI_Lib.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
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
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
|
|
|
PlayerState::PlayerState()
|
2024-10-08 21:55:51 +02:00
|
|
|
: color(-1)
|
|
|
|
, playerLocalSettings(std::make_unique<JsonNode>())
|
|
|
|
, human(false)
|
|
|
|
, cheated(false)
|
|
|
|
, enteredWinningCheatCode(false)
|
|
|
|
, enteredLosingCheatCode(false)
|
|
|
|
, status(EPlayerStatus::INGAME)
|
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
|
|
|
{
|
|
|
|
setNodeType(PLAYER);
|
|
|
|
}
|
|
|
|
|
2023-06-26 16:25:29 +02:00
|
|
|
PlayerState::~PlayerState() = default;
|
|
|
|
|
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
|
|
|
std::string PlayerState::nodeName() const
|
|
|
|
{
|
2023-09-04 21:21:02 +02:00
|
|
|
return "Player " + color.toString();
|
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 PlayerState::getId() const
|
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
|
|
|
{
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2023-04-04 16:52:33 +02:00
|
|
|
int32_t PlayerState::getIndex() const
|
|
|
|
{
|
|
|
|
return color.getNum();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t PlayerState::getIconIndex() const
|
|
|
|
{
|
|
|
|
return color.getNum();
|
|
|
|
}
|
2023-09-04 21:21:02 +02:00
|
|
|
|
2023-04-04 16:52:33 +02:00
|
|
|
std::string PlayerState::getJsonKey() const
|
|
|
|
{
|
2023-09-04 21:21:02 +02:00
|
|
|
return color.toString();
|
2023-04-04 16:52:33 +02:00
|
|
|
}
|
2023-09-04 21:21:02 +02:00
|
|
|
|
2024-08-10 16:08:04 +02:00
|
|
|
std::string PlayerState::getModScope() const
|
|
|
|
{
|
|
|
|
return "core";
|
|
|
|
}
|
|
|
|
|
2023-04-04 16:52:33 +02:00
|
|
|
std::string PlayerState::getNameTranslated() const
|
|
|
|
{
|
2023-09-04 21:21:02 +02:00
|
|
|
return VLC->generaltexth->translate(getNameTextID());
|
2023-04-04 16:52:33 +02:00
|
|
|
}
|
2023-09-04 21:21:02 +02:00
|
|
|
|
2023-04-04 16:52:33 +02:00
|
|
|
std::string PlayerState::getNameTextID() const
|
|
|
|
{
|
2023-09-04 21:21:02 +02:00
|
|
|
return TextIdentifier("core.plcolors", color.getNum()).get();
|
2023-04-04 16:52:33 +02:00
|
|
|
}
|
2023-09-04 21:21:02 +02:00
|
|
|
|
2023-04-04 16:52:33 +02:00
|
|
|
void PlayerState::registerIcons(const IconRegistar & cb) const
|
|
|
|
{
|
|
|
|
//We cannot register new icons for players
|
|
|
|
}
|
|
|
|
|
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 PlayerState::getTeam() const
|
|
|
|
{
|
|
|
|
return team;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PlayerState::isHuman() const
|
|
|
|
{
|
|
|
|
return human;
|
|
|
|
}
|
|
|
|
|
2023-04-05 02:26:29 +02:00
|
|
|
const IBonusBearer * PlayerState::getBonusBearer() const
|
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
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PlayerState::getResourceAmount(int type) const
|
|
|
|
{
|
|
|
|
return vstd::atOrDefault(resources, static_cast<size_t>(type), 0);
|
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
2024-08-25 00:21:26 +02:00
|
|
|
template<typename T>
|
|
|
|
std::vector<T> PlayerState::getObjectsOfType() const
|
|
|
|
{
|
|
|
|
std::vector<T> result;
|
|
|
|
for (auto const & object : ownedObjects)
|
|
|
|
{
|
|
|
|
auto casted = dynamic_cast<T>(object);
|
|
|
|
if (casted)
|
|
|
|
result.push_back(casted);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<const CGHeroInstance *> PlayerState::getHeroes() const
|
|
|
|
{
|
|
|
|
return getObjectsOfType<const CGHeroInstance *>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<const CGTownInstance *> PlayerState::getTowns() const
|
|
|
|
{
|
|
|
|
return getObjectsOfType<const CGTownInstance *>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<CGHeroInstance *> PlayerState::getHeroes()
|
|
|
|
{
|
|
|
|
return getObjectsOfType<CGHeroInstance *>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<CGTownInstance *> PlayerState::getTowns()
|
|
|
|
{
|
|
|
|
return getObjectsOfType<CGTownInstance *>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<const CGObjectInstance *> PlayerState::getOwnedObjects() const
|
|
|
|
{
|
|
|
|
return {ownedObjects.begin(), ownedObjects.end()};
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerState::addOwnedObject(CGObjectInstance * object)
|
|
|
|
{
|
2024-08-25 17:04:44 +02:00
|
|
|
assert(object->asOwnable() != nullptr);
|
2024-08-25 00:21:26 +02:00
|
|
|
ownedObjects.push_back(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerState::removeOwnedObject(CGObjectInstance * object)
|
|
|
|
{
|
|
|
|
vstd::erase(ownedObjects, object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|