GameConstants.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 "CDefObjInfoHandler.h"
  14. #include "CArtHandler.h"
  15. #include "CCreatureHandler.h"
  16. #include "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. #define ID_LIKE_OPERATORS_INTERNAL(A, B, AN, BN) \
  24. bool operator==(const A & a, const B & b) \
  25. { \
  26. return AN == BN ; \
  27. } \
  28. bool operator!=(const A & a, const B & b) \
  29. { \
  30. return AN != BN ; \
  31. } \
  32. bool operator<(const A & a, const B & b) \
  33. { \
  34. return AN < BN ; \
  35. } \
  36. bool operator<=(const A & a, const B & b) \
  37. { \
  38. return AN <= BN ; \
  39. } \
  40. bool operator>(const A & a, const B & b) \
  41. { \
  42. return AN > BN ; \
  43. } \
  44. bool operator>=(const A & a, const B & b) \
  45. { \
  46. return AN >= BN ; \
  47. }
  48. #define ID_LIKE_OPERATORS(CLASS_NAME, ENUM_NAME) \
  49. ID_LIKE_OPERATORS_INTERNAL(CLASS_NAME, CLASS_NAME, a.num, b.num) \
  50. ID_LIKE_OPERATORS_INTERNAL(CLASS_NAME, ENUM_NAME, a.num, b) \
  51. ID_LIKE_OPERATORS_INTERNAL(ENUM_NAME, CLASS_NAME, a, b.num)
  52. ID_LIKE_OPERATORS(SecondarySkill, SecondarySkill::ESecondarySkill)
  53. ID_LIKE_OPERATORS(Obj, Obj::EObj)
  54. ID_LIKE_OPERATORS(ETerrainType, ETerrainType::EETerrainType)
  55. ID_LIKE_OPERATORS(ArtifactID, ArtifactID::EArtifactID)
  56. ID_LIKE_OPERATORS(ArtifactPosition, ArtifactPosition::EArtifactPosition)
  57. ID_LIKE_OPERATORS(CreatureID, CreatureID::ECreatureID)
  58. ID_LIKE_OPERATORS(SpellID, SpellID::ESpellID)
  59. ID_LIKE_OPERATORS(BuildingID, BuildingID::EBuildingID)
  60. ID_LIKE_OPERATORS(BFieldType, BFieldType::EBFieldType)
  61. CArtifact * ArtifactID::toArtifact() const
  62. {
  63. return VLC->arth->artifacts[*this];
  64. }
  65. CCreature * CreatureID::toCreature() const
  66. {
  67. return VLC->creh->creatures[*this];
  68. }
  69. CSpell * SpellID::toSpell() const
  70. {
  71. return VLC->spellh->spells[*this];
  72. }
  73. //template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
  74. //template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);
  75. bool PlayerColor::isValidPlayer() const
  76. {
  77. return num < PLAYER_LIMIT_I;
  78. }
  79. std::ostream & operator<<(std::ostream & os, const Battle::ActionType actionType)
  80. {
  81. static const std::map<Battle::ActionType, std::string> actionTypeToString = boost::assign::map_list_of
  82. (Battle::END_TACTIC_PHASE, "End tactic phase")
  83. (Battle::INVALID, "Invalid")
  84. (Battle::NO_ACTION, "No action")
  85. (Battle::HERO_SPELL, "Hero spell")
  86. (Battle::WALK, "Walk")
  87. (Battle::DEFEND, "Defend")
  88. (Battle::RETREAT, "Retreat")
  89. (Battle::SURRENDER, "Surrender")
  90. (Battle::WALK_AND_ATTACK, "Walk and attack")
  91. (Battle::SHOOT, "Shoot")
  92. (Battle::WAIT, "Wait")
  93. (Battle::CATAPULT, "Catapult")
  94. (Battle::MONSTER_SPELL, "Monster spell")
  95. (Battle::BAD_MORALE, "Bad morale")
  96. (Battle::STACK_HEAL, "Stack heal")
  97. (Battle::DAEMON_SUMMONING, "Daemon summoning");
  98. auto it = actionTypeToString.find(actionType);
  99. if (it == actionTypeToString.end()) return os << "<Unknown type>";
  100. else return os << it->second;
  101. }