CPlayerState.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "CGameStateFwd.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):
  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. std::string PlayerState::nodeName() const
  39. {
  40. return "Player " + color.getStrCap(false);
  41. }
  42. PlayerColor PlayerState::getColor() const
  43. {
  44. return color;
  45. }
  46. TeamID PlayerState::getTeam() const
  47. {
  48. return team;
  49. }
  50. bool PlayerState::isHuman() const
  51. {
  52. return human;
  53. }
  54. const IBonusBearer * PlayerState::accessBonuses() const
  55. {
  56. return this;
  57. }
  58. int PlayerState::getResourceAmount(int type) const
  59. {
  60. return vstd::atOrDefault(resources, static_cast<size_t>(type), 0);
  61. }
  62. VCMI_LIB_NAMESPACE_END