1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-26 08:41:13 +02:00
vcmi/lib/CPlayerState.cpp

109 lines
2.2 KiB
C++
Raw Normal View History

/*
* 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"
#include "gameState/QuestInfo.h"
#include "CGeneralTextHandler.h"
#include "VCMI_Lib.h"
VCMI_LIB_NAMESPACE_BEGIN
PlayerState::PlayerState()
2023-09-23 20:41:30 +02:00
: color(-1), human(false), cheated(false), enteredWinningCheatCode(false),
enteredLosingCheatCode(false), status(EPlayerStatus::INGAME)
{
setNodeType(PLAYER);
}
2023-03-13 23:26:44 +02:00
PlayerState::PlayerState(PlayerState && other) noexcept:
CBonusSystemNode(std::move(other)),
color(other.color),
human(other.human),
team(other.team),
resources(other.resources),
2023-09-23 20:41:30 +02:00
cheated(other.cheated),
enteredWinningCheatCode(other.enteredWinningCheatCode),
enteredLosingCheatCode(other.enteredLosingCheatCode),
status(other.status),
daysWithoutCastle(other.daysWithoutCastle)
{
std::swap(visitedObjects, other.visitedObjects);
std::swap(heroes, other.heroes);
std::swap(towns, other.towns);
std::swap(dwellings, other.dwellings);
std::swap(quests, other.quests);
2023-09-22 13:34:00 +02:00
std::swap(battleBonuses, other.battleBonuses);
}
2023-06-26 16:25:29 +02:00
PlayerState::~PlayerState() = default;
std::string PlayerState::nodeName() const
{
return "Player " + color.toString();
}
PlayerColor PlayerState::getId() const
{
return color;
}
int32_t PlayerState::getIndex() const
{
return color.getNum();
}
int32_t PlayerState::getIconIndex() const
{
return color.getNum();
}
std::string PlayerState::getJsonKey() const
{
return color.toString();
}
std::string PlayerState::getNameTranslated() const
{
return VLC->generaltexth->translate(getNameTextID());
}
std::string PlayerState::getNameTextID() const
{
return TextIdentifier("core.plcolors", color.getNum()).get();
}
void PlayerState::registerIcons(const IconRegistar & cb) const
{
//We cannot register new icons for players
}
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
{
return this;
}
int PlayerState::getResourceAmount(int type) const
{
return vstd::atOrDefault(resources, static_cast<size_t>(type), 0);
}
VCMI_LIB_NAMESPACE_END