GameConstants.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #include "StdInc.h"
  11. #include "VCMI_Lib.h"
  12. #include "CDefObjInfoHandler.h"
  13. #include "CArtHandler.h"
  14. #include "CCreatureHandler.h"
  15. #include "CSpellHandler.h"
  16. #define ID_LIKE_OPERATORS_INTERNAL(A, B, AN, BN) \
  17. bool operator==(const A & a, const B & b) \
  18. { \
  19. return AN == BN ; \
  20. } \
  21. bool operator!=(const A & a, const B & b) \
  22. { \
  23. return AN != BN ; \
  24. } \
  25. bool operator<(const A & a, const B & b) \
  26. { \
  27. return AN < BN ; \
  28. } \
  29. bool operator<=(const A & a, const B & b) \
  30. { \
  31. return AN <= BN ; \
  32. } \
  33. bool operator>(const A & a, const B & b) \
  34. { \
  35. return AN > BN ; \
  36. } \
  37. bool operator>=(const A & a, const B & b) \
  38. { \
  39. return AN >= BN ; \
  40. }
  41. #define ID_LIKE_OPERATORS(CLASS_NAME, ENUM_NAME) \
  42. ID_LIKE_OPERATORS_INTERNAL(CLASS_NAME, CLASS_NAME, a.num, b.num) \
  43. ID_LIKE_OPERATORS_INTERNAL(CLASS_NAME, ENUM_NAME, a.num, b) \
  44. ID_LIKE_OPERATORS_INTERNAL(ENUM_NAME, CLASS_NAME, a, b.num)
  45. ID_LIKE_OPERATORS(SecondarySkill, SecondarySkill::ESecondarySkill)
  46. ID_LIKE_OPERATORS(Obj, Obj::EObj)
  47. ID_LIKE_OPERATORS(ArtifactID, ArtifactID::EArtifactID)
  48. ID_LIKE_OPERATORS(ArtifactPosition, ArtifactPosition::EArtifactPosition)
  49. ID_LIKE_OPERATORS(CreatureID, CreatureID::ECreatureID)
  50. ID_LIKE_OPERATORS(SpellID, SpellID::ESpellID)
  51. ID_LIKE_OPERATORS(BuildingID, BuildingID::EBuildingID)
  52. bmap<int, ConstTransitivePtr<CGDefInfo> > & Obj::toDefObjInfo() const
  53. {
  54. return VLC->dobjinfo->gobjs[*this];
  55. }
  56. CArtifact * ArtifactID::toArtifact() const
  57. {
  58. return VLC->arth->artifacts[*this];
  59. }
  60. CCreature * CreatureID::toCreature() const
  61. {
  62. return VLC->creh->creatures[*this];
  63. }
  64. CSpell * SpellID::toSpell() const
  65. {
  66. return VLC->spellh->spells[*this];
  67. }