GameConstants.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * GameConstants.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. #define INSTANTIATE_BASE_FOR_ID_HERE
  11. #include "StdInc.h"
  12. #include "VCMI_Lib.h"
  13. #include "mapObjects/CObjectClassesHandler.h"
  14. #include "CArtHandler.h"
  15. #include "CCreatureHandler.h"
  16. #include "spells/CSpellHandler.h"
  17. const SlotID SlotID::COMMANDER_SLOT_PLACEHOLDER = SlotID(-2);
  18. const PlayerColor PlayerColor::CANNOT_DETERMINE = PlayerColor(253);
  19. const PlayerColor PlayerColor::UNFLAGGABLE = PlayerColor(254);
  20. const PlayerColor PlayerColor::NEUTRAL = PlayerColor(255);
  21. const PlayerColor PlayerColor::PLAYER_LIMIT = PlayerColor(PLAYER_LIMIT_I);
  22. const TeamID TeamID::NO_TEAM = TeamID(255);
  23. CArtifact * ArtifactID::toArtifact() const
  24. {
  25. return VLC->arth->artifacts[*this];
  26. }
  27. CCreature * CreatureID::toCreature() const
  28. {
  29. return VLC->creh->creatures[*this];
  30. }
  31. CSpell * SpellID::toSpell() const
  32. {
  33. if(num < 0 || num >= VLC->spellh->objects.size())
  34. {
  35. logGlobal->errorStream() << "Unable to get spell of invalid ID " << int(num);
  36. return nullptr;
  37. }
  38. return VLC->spellh->objects[*this];
  39. }
  40. //template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
  41. //template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);
  42. bool PlayerColor::isValidPlayer() const
  43. {
  44. return num < PLAYER_LIMIT_I;
  45. }
  46. std::ostream & operator<<(std::ostream & os, const Battle::ActionType actionType)
  47. {
  48. static const std::map<Battle::ActionType, std::string> actionTypeToString =
  49. {
  50. {Battle::END_TACTIC_PHASE, "End tactic phase"},
  51. {Battle::INVALID, "Invalid"},
  52. {Battle::NO_ACTION, "No action"},
  53. {Battle::HERO_SPELL, "Hero spell"},
  54. {Battle::WALK, "Walk"},
  55. {Battle::DEFEND, "Defend"},
  56. {Battle::RETREAT, "Retreat"},
  57. {Battle::SURRENDER, "Surrender"},
  58. {Battle::WALK_AND_ATTACK, "Walk and attack"},
  59. {Battle::SHOOT, "Shoot"},
  60. {Battle::WAIT, "Wait"},
  61. {Battle::CATAPULT, "Catapult"},
  62. {Battle::MONSTER_SPELL, "Monster spell"},
  63. {Battle::BAD_MORALE, "Bad morale"},
  64. {Battle::STACK_HEAL, "Stack heal"},
  65. {Battle::DAEMON_SUMMONING, "Daemon summoning"}
  66. };
  67. auto it = actionTypeToString.find(actionType);
  68. if (it == actionTypeToString.end()) return os << "<Unknown type>";
  69. else return os << it->second;
  70. }
  71. std::ostream & operator<<(std::ostream & os, const ETerrainType terrainType)
  72. {
  73. static const std::map<ETerrainType::EETerrainType, std::string> terrainTypeToString =
  74. {
  75. #define DEFINE_ELEMENT(element) {ETerrainType::element, #element}
  76. DEFINE_ELEMENT(WRONG),
  77. DEFINE_ELEMENT(BORDER),
  78. DEFINE_ELEMENT(DIRT),
  79. DEFINE_ELEMENT(SAND),
  80. DEFINE_ELEMENT(GRASS),
  81. DEFINE_ELEMENT(SNOW),
  82. DEFINE_ELEMENT(SWAMP),
  83. DEFINE_ELEMENT(ROUGH),
  84. DEFINE_ELEMENT(SUBTERRANEAN),
  85. DEFINE_ELEMENT(LAVA),
  86. DEFINE_ELEMENT(WATER),
  87. DEFINE_ELEMENT(ROCK)
  88. #undef DEFINE_ELEMENT
  89. };
  90. auto it = terrainTypeToString.find(terrainType.num);
  91. if (it == terrainTypeToString.end()) return os << "<Unknown type>";
  92. else return os << it->second;
  93. }
  94. std::string ETerrainType::toString() const
  95. {
  96. std::stringstream ss;
  97. ss << *this;
  98. return ss.str();
  99. }
  100. std::ostream & operator<<(std::ostream & os, const EPathfindingLayer pathfindingLayer)
  101. {
  102. static const std::map<EPathfindingLayer::EEPathfindingLayer, std::string> pathfinderLayerToString
  103. {
  104. #define DEFINE_ELEMENT(element) {EPathfindingLayer::element, #element}
  105. DEFINE_ELEMENT(WRONG),
  106. DEFINE_ELEMENT(AUTO),
  107. DEFINE_ELEMENT(LAND),
  108. DEFINE_ELEMENT(SAIL),
  109. DEFINE_ELEMENT(WATER),
  110. DEFINE_ELEMENT(AIR),
  111. DEFINE_ELEMENT(NUM_LAYERS)
  112. #undef DEFINE_ELEMENT
  113. };
  114. auto it = pathfinderLayerToString.find(pathfindingLayer.num);
  115. if (it == pathfinderLayerToString.end()) return os << "<Unknown type>";
  116. else return os << it->second;
  117. }