2
0

GameConstants.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. #ifndef VCMI_NO_EXTRA_VERSION
  13. #include "../Version.h"
  14. #endif
  15. #include "VCMI_Lib.h"
  16. #include "mapObjects/CObjectClassesHandler.h"
  17. #include "CArtHandler.h"
  18. #include "CCreatureHandler.h"
  19. #include "spells/CSpellHandler.h"
  20. #include "StringConstants.h"
  21. #include "CGeneralTextHandler.h"
  22. const SlotID SlotID::COMMANDER_SLOT_PLACEHOLDER = SlotID(-2);
  23. const SlotID SlotID::SUMMONED_SLOT_PLACEHOLDER = SlotID(-3);
  24. const SlotID SlotID::WAR_MACHINES_SLOT = SlotID(-4);
  25. const SlotID SlotID::ARROW_TOWERS_SLOT = SlotID(-5);
  26. const PlayerColor PlayerColor::SPECTATOR = PlayerColor(252);
  27. const PlayerColor PlayerColor::CANNOT_DETERMINE = PlayerColor(253);
  28. const PlayerColor PlayerColor::UNFLAGGABLE = PlayerColor(254);
  29. const PlayerColor PlayerColor::NEUTRAL = PlayerColor(255);
  30. const PlayerColor PlayerColor::PLAYER_LIMIT = PlayerColor(PLAYER_LIMIT_I);
  31. const TeamID TeamID::NO_TEAM = TeamID(255);
  32. namespace GameConstants
  33. {
  34. #ifdef VCMI_NO_EXTRA_VERSION
  35. const std::string VCMI_VERSION = std::string("VCMI 0.99");
  36. #else
  37. const std::string VCMI_VERSION = std::string("VCMI 0.99 ") + GIT_SHA1;
  38. #endif
  39. }
  40. const CArtifact * ArtifactID::toArtifact() const
  41. {
  42. return VLC->arth->artifacts.at(*this);
  43. }
  44. const CCreature * CreatureID::toCreature() const
  45. {
  46. return VLC->creh->creatures.at(*this);
  47. }
  48. const CSpell * SpellID::toSpell() const
  49. {
  50. if(num < 0 || num >= VLC->spellh->objects.size())
  51. {
  52. logGlobal->errorStream() << "Unable to get spell of invalid ID " << int(num);
  53. return nullptr;
  54. }
  55. return VLC->spellh->objects[*this];
  56. }
  57. //template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
  58. //template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);
  59. bool PlayerColor::isValidPlayer() const
  60. {
  61. return num < PLAYER_LIMIT_I;
  62. }
  63. bool PlayerColor::isSpectator() const
  64. {
  65. return num == 252;
  66. }
  67. std::string PlayerColor::getStr(bool L10n) const
  68. {
  69. std::string ret = "unnamed";
  70. if(isValidPlayer())
  71. {
  72. if(L10n)
  73. ret = VLC->generaltexth->colors[num];
  74. else
  75. ret = GameConstants::PLAYER_COLOR_NAMES[num];
  76. }
  77. else if(L10n)
  78. {
  79. ret = VLC->generaltexth->allTexts[508];
  80. ret[0] = std::tolower(ret[0]);
  81. }
  82. return ret;
  83. }
  84. std::string PlayerColor::getStrCap(bool L10n) const
  85. {
  86. std::string ret = getStr(L10n);
  87. ret[0] = std::toupper(ret[0]);
  88. return ret;
  89. }
  90. std::ostream & operator<<(std::ostream & os, const Battle::ActionType actionType)
  91. {
  92. static const std::map<Battle::ActionType, std::string> actionTypeToString =
  93. {
  94. {Battle::END_TACTIC_PHASE, "End tactic phase"},
  95. {Battle::INVALID, "Invalid"},
  96. {Battle::NO_ACTION, "No action"},
  97. {Battle::HERO_SPELL, "Hero spell"},
  98. {Battle::WALK, "Walk"},
  99. {Battle::DEFEND, "Defend"},
  100. {Battle::RETREAT, "Retreat"},
  101. {Battle::SURRENDER, "Surrender"},
  102. {Battle::WALK_AND_ATTACK, "Walk and attack"},
  103. {Battle::SHOOT, "Shoot"},
  104. {Battle::WAIT, "Wait"},
  105. {Battle::CATAPULT, "Catapult"},
  106. {Battle::MONSTER_SPELL, "Monster spell"},
  107. {Battle::BAD_MORALE, "Bad morale"},
  108. {Battle::STACK_HEAL, "Stack heal"},
  109. {Battle::DAEMON_SUMMONING, "Daemon summoning"}
  110. };
  111. auto it = actionTypeToString.find(actionType);
  112. if (it == actionTypeToString.end()) return os << "<Unknown type>";
  113. else return os << it->second;
  114. }
  115. std::ostream & operator<<(std::ostream & os, const ETerrainType terrainType)
  116. {
  117. static const std::map<ETerrainType::EETerrainType, std::string> terrainTypeToString =
  118. {
  119. #define DEFINE_ELEMENT(element) {ETerrainType::element, #element}
  120. DEFINE_ELEMENT(WRONG),
  121. DEFINE_ELEMENT(BORDER),
  122. DEFINE_ELEMENT(DIRT),
  123. DEFINE_ELEMENT(SAND),
  124. DEFINE_ELEMENT(GRASS),
  125. DEFINE_ELEMENT(SNOW),
  126. DEFINE_ELEMENT(SWAMP),
  127. DEFINE_ELEMENT(ROUGH),
  128. DEFINE_ELEMENT(SUBTERRANEAN),
  129. DEFINE_ELEMENT(LAVA),
  130. DEFINE_ELEMENT(WATER),
  131. DEFINE_ELEMENT(ROCK)
  132. #undef DEFINE_ELEMENT
  133. };
  134. auto it = terrainTypeToString.find(terrainType.num);
  135. if (it == terrainTypeToString.end()) return os << "<Unknown type>";
  136. else return os << it->second;
  137. }
  138. std::string ETerrainType::toString() const
  139. {
  140. std::stringstream ss;
  141. ss << *this;
  142. return ss.str();
  143. }
  144. std::ostream & operator<<(std::ostream & os, const EPathfindingLayer pathfindingLayer)
  145. {
  146. static const std::map<EPathfindingLayer::EEPathfindingLayer, std::string> pathfinderLayerToString
  147. {
  148. #define DEFINE_ELEMENT(element) {EPathfindingLayer::element, #element}
  149. DEFINE_ELEMENT(WRONG),
  150. DEFINE_ELEMENT(AUTO),
  151. DEFINE_ELEMENT(LAND),
  152. DEFINE_ELEMENT(SAIL),
  153. DEFINE_ELEMENT(WATER),
  154. DEFINE_ELEMENT(AIR),
  155. DEFINE_ELEMENT(NUM_LAYERS)
  156. #undef DEFINE_ELEMENT
  157. };
  158. auto it = pathfinderLayerToString.find(pathfindingLayer.num);
  159. if (it == pathfinderLayerToString.end()) return os << "<Unknown type>";
  160. else return os << it->second;
  161. }