2
0

CPlayerState.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * CPlayerState.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CPlayerState.h"
  12. #include "gameState/QuestInfo.h"
  13. #include "CGeneralTextHandler.h"
  14. #include "VCMI_Lib.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. PlayerState::PlayerState()
  17. : color(-1), human(false), cheated(false), enteredWinningCheatCode(false),
  18. enteredLosingCheatCode(false), status(EPlayerStatus::INGAME)
  19. {
  20. setNodeType(PLAYER);
  21. }
  22. PlayerState::PlayerState(PlayerState && other) noexcept = default;
  23. PlayerState::~PlayerState() = default;
  24. std::string PlayerState::nodeName() const
  25. {
  26. return "Player " + color.toString();
  27. }
  28. PlayerColor PlayerState::getId() const
  29. {
  30. return color;
  31. }
  32. int32_t PlayerState::getIndex() const
  33. {
  34. return color.getNum();
  35. }
  36. int32_t PlayerState::getIconIndex() const
  37. {
  38. return color.getNum();
  39. }
  40. std::string PlayerState::getJsonKey() const
  41. {
  42. return color.toString();
  43. }
  44. std::string PlayerState::getNameTranslated() const
  45. {
  46. return VLC->generaltexth->translate(getNameTextID());
  47. }
  48. std::string PlayerState::getNameTextID() const
  49. {
  50. return TextIdentifier("core.plcolors", color.getNum()).get();
  51. }
  52. void PlayerState::registerIcons(const IconRegistar & cb) const
  53. {
  54. //We cannot register new icons for players
  55. }
  56. TeamID PlayerState::getTeam() const
  57. {
  58. return team;
  59. }
  60. bool PlayerState::isHuman() const
  61. {
  62. return human;
  63. }
  64. const IBonusBearer * PlayerState::getBonusBearer() const
  65. {
  66. return this;
  67. }
  68. int PlayerState::getResourceAmount(int type) const
  69. {
  70. return vstd::atOrDefault(resources, static_cast<size_t>(type), 0);
  71. }
  72. VCMI_LIB_NAMESPACE_END