CPlayerState.cpp 2.0 KB

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