CPlayerState.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. std::swap(battleBonuses, other.battleBonuses);
  40. }
  41. PlayerState::~PlayerState() = default;
  42. std::string PlayerState::nodeName() const
  43. {
  44. return "Player " + color.toString();
  45. }
  46. PlayerColor PlayerState::getId() const
  47. {
  48. return color;
  49. }
  50. int32_t PlayerState::getIndex() const
  51. {
  52. return color.getNum();
  53. }
  54. int32_t PlayerState::getIconIndex() const
  55. {
  56. return color.getNum();
  57. }
  58. std::string PlayerState::getJsonKey() const
  59. {
  60. return color.toString();
  61. }
  62. std::string PlayerState::getNameTranslated() const
  63. {
  64. return VLC->generaltexth->translate(getNameTextID());
  65. }
  66. std::string PlayerState::getNameTextID() const
  67. {
  68. return TextIdentifier("core.plcolors", color.getNum()).get();
  69. }
  70. void PlayerState::registerIcons(const IconRegistar & cb) const
  71. {
  72. //We cannot register new icons for players
  73. }
  74. TeamID PlayerState::getTeam() const
  75. {
  76. return team;
  77. }
  78. bool PlayerState::isHuman() const
  79. {
  80. return human;
  81. }
  82. const IBonusBearer * PlayerState::getBonusBearer() const
  83. {
  84. return this;
  85. }
  86. int PlayerState::getResourceAmount(int type) const
  87. {
  88. return vstd::atOrDefault(resources, static_cast<size_t>(type), 0);
  89. }
  90. VCMI_LIB_NAMESPACE_END