CPlayerState.cpp 2.1 KB

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