CPlayerState.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 "texts/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::getModScope() const
  44. {
  45. return "core";
  46. }
  47. std::string PlayerState::getNameTranslated() const
  48. {
  49. return VLC->generaltexth->translate(getNameTextID());
  50. }
  51. std::string PlayerState::getNameTextID() const
  52. {
  53. return TextIdentifier("core.plcolors", color.getNum()).get();
  54. }
  55. void PlayerState::registerIcons(const IconRegistar & cb) const
  56. {
  57. //We cannot register new icons for players
  58. }
  59. TeamID PlayerState::getTeam() const
  60. {
  61. return team;
  62. }
  63. bool PlayerState::isHuman() const
  64. {
  65. return human;
  66. }
  67. const IBonusBearer * PlayerState::getBonusBearer() const
  68. {
  69. return this;
  70. }
  71. int PlayerState::getResourceAmount(int type) const
  72. {
  73. return vstd::atOrDefault(resources, static_cast<size_t>(type), 0);
  74. }
  75. VCMI_LIB_NAMESPACE_END