GameConstants.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #define ID_LIKE_OPERATORS_INTERNAL(A, B, AN, BN) \
  18. bool operator==(const A & a, const B & b) \
  19. { \
  20. return AN == BN ; \
  21. } \
  22. bool operator!=(const A & a, const B & b) \
  23. { \
  24. return AN != BN ; \
  25. } \
  26. bool operator<(const A & a, const B & b) \
  27. { \
  28. return AN < BN ; \
  29. } \
  30. bool operator<=(const A & a, const B & b) \
  31. { \
  32. return AN <= BN ; \
  33. } \
  34. bool operator>(const A & a, const B & b) \
  35. { \
  36. return AN > BN ; \
  37. } \
  38. bool operator>=(const A & a, const B & b) \
  39. { \
  40. return AN >= BN ; \
  41. }
  42. #define ID_LIKE_OPERATORS(CLASS_NAME, ENUM_NAME) \
  43. ID_LIKE_OPERATORS_INTERNAL(CLASS_NAME, CLASS_NAME, a.num, b.num) \
  44. ID_LIKE_OPERATORS_INTERNAL(CLASS_NAME, ENUM_NAME, a.num, b) \
  45. ID_LIKE_OPERATORS_INTERNAL(ENUM_NAME, CLASS_NAME, a, b.num)
  46. ID_LIKE_OPERATORS(SecondarySkill, SecondarySkill::ESecondarySkill)
  47. ID_LIKE_OPERATORS(Obj, Obj::EObj)
  48. ID_LIKE_OPERATORS(ETerrainType, ETerrainType::EETerrainType)
  49. ID_LIKE_OPERATORS(ArtifactID, ArtifactID::EArtifactID)
  50. ID_LIKE_OPERATORS(ArtifactPosition, ArtifactPosition::EArtifactPosition)
  51. ID_LIKE_OPERATORS(CreatureID, CreatureID::ECreatureID)
  52. ID_LIKE_OPERATORS(SpellID, SpellID::ESpellID)
  53. ID_LIKE_OPERATORS(BuildingID, BuildingID::EBuildingID)
  54. ID_LIKE_OPERATORS(BFieldType, BFieldType::EBFieldType)
  55. bmap<int, ConstTransitivePtr<CGDefInfo> > & Obj::toDefObjInfo() const
  56. {
  57. return VLC->dobjinfo->gobjs[*this];
  58. }
  59. CArtifact * ArtifactID::toArtifact() const
  60. {
  61. return VLC->arth->artifacts[*this];
  62. }
  63. CCreature * CreatureID::toCreature() const
  64. {
  65. return VLC->creh->creatures[*this];
  66. }
  67. CSpell * SpellID::toSpell() const
  68. {
  69. return VLC->spellh->spells[*this];
  70. }
  71. //template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
  72. //template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);