CPlayerState.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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() = default;
  23. std::string PlayerState::nodeName() const
  24. {
  25. return "Player " + color.toString();
  26. }
  27. PlayerColor PlayerState::getId() const
  28. {
  29. return color;
  30. }
  31. int32_t PlayerState::getIndex() const
  32. {
  33. return color.getNum();
  34. }
  35. int32_t PlayerState::getIconIndex() const
  36. {
  37. return color.getNum();
  38. }
  39. std::string PlayerState::getJsonKey() const
  40. {
  41. return color.toString();
  42. }
  43. std::string PlayerState::getNameTranslated() const
  44. {
  45. return VLC->generaltexth->translate(getNameTextID());
  46. }
  47. std::string PlayerState::getNameTextID() const
  48. {
  49. return TextIdentifier("core.plcolors", color.getNum()).get();
  50. }
  51. void PlayerState::registerIcons(const IconRegistar & cb) const
  52. {
  53. //We cannot register new icons for players
  54. }
  55. TeamID PlayerState::getTeam() const
  56. {
  57. return team;
  58. }
  59. bool PlayerState::isHuman() const
  60. {
  61. return human;
  62. }
  63. const IBonusBearer * PlayerState::getBonusBearer() const
  64. {
  65. return this;
  66. }
  67. int PlayerState::getResourceAmount(int type) const
  68. {
  69. return vstd::atOrDefault(resources, static_cast<size_t>(type), 0);
  70. }
  71. VCMI_LIB_NAMESPACE_END