CPlayerState.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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:
  23. CBonusSystemNode(std::move(other)),
  24. color(other.color),
  25. human(other.human),
  26. team(other.team),
  27. resources(other.resources),
  28. cheated(other.cheated),
  29. enteredWinningCheatCode(other.enteredWinningCheatCode),
  30. enteredLosingCheatCode(other.enteredLosingCheatCode),
  31. status(other.status),
  32. daysWithoutCastle(other.daysWithoutCastle)
  33. {
  34. std::swap(visitedObjects, other.visitedObjects);
  35. std::swap(heroes, other.heroes);
  36. std::swap(towns, other.towns);
  37. std::swap(dwellings, other.dwellings);
  38. std::swap(quests, other.quests);
  39. }
  40. PlayerState::~PlayerState() = default;
  41. std::string PlayerState::nodeName() const
  42. {
  43. return "Player " + color.toString();
  44. }
  45. PlayerColor PlayerState::getId() const
  46. {
  47. return color;
  48. }
  49. int32_t PlayerState::getIndex() const
  50. {
  51. return color.getNum();
  52. }
  53. int32_t PlayerState::getIconIndex() const
  54. {
  55. return color.getNum();
  56. }
  57. std::string PlayerState::getJsonKey() const
  58. {
  59. return color.toString();
  60. }
  61. std::string PlayerState::getNameTranslated() const
  62. {
  63. return VLC->generaltexth->translate(getNameTextID());
  64. }
  65. std::string PlayerState::getNameTextID() const
  66. {
  67. return TextIdentifier("core.plcolors", color.getNum()).get();
  68. }
  69. void PlayerState::registerIcons(const IconRegistar & cb) const
  70. {
  71. //We cannot register new icons for players
  72. }
  73. TeamID PlayerState::getTeam() const
  74. {
  75. return team;
  76. }
  77. bool PlayerState::isHuman() const
  78. {
  79. return human;
  80. }
  81. const IBonusBearer * PlayerState::getBonusBearer() const
  82. {
  83. return this;
  84. }
  85. int PlayerState::getResourceAmount(int type) const
  86. {
  87. return vstd::atOrDefault(resources, static_cast<size_t>(type), 0);
  88. }
  89. VCMI_LIB_NAMESPACE_END