GameConstants.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "StdInc.h"
  2. #include "VCMI_Lib.h"
  3. #include "CDefObjInfoHandler.h"
  4. #include "CArtHandler.h"
  5. #include "CCreatureHandler.h"
  6. #include "CSpellHandler.h"
  7. #define ID_LIKE_OPERATORS_INTERNAL(A, B, AN, BN) \
  8. bool operator==(const A & a, const B & b) \
  9. { \
  10. return AN == BN ; \
  11. } \
  12. bool operator!=(const A & a, const B & b) \
  13. { \
  14. return AN != BN ; \
  15. } \
  16. bool operator<(const A & a, const B & b) \
  17. { \
  18. return AN < BN ; \
  19. } \
  20. bool operator<=(const A & a, const B & b) \
  21. { \
  22. return AN <= BN ; \
  23. } \
  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. #define ID_LIKE_OPERATORS(CLASS_NAME, ENUM_NAME) \
  33. ID_LIKE_OPERATORS_INTERNAL(CLASS_NAME, CLASS_NAME, a.num, b.num) \
  34. ID_LIKE_OPERATORS_INTERNAL(CLASS_NAME, ENUM_NAME, a.num, b) \
  35. ID_LIKE_OPERATORS_INTERNAL(ENUM_NAME, CLASS_NAME, a, b.num)
  36. ID_LIKE_OPERATORS(Obj, Obj::EObj)
  37. ID_LIKE_OPERATORS(ArtifactID, ArtifactID::EArtifactID)
  38. ID_LIKE_OPERATORS(CreatureID, CreatureID::ECreatureID)
  39. ID_LIKE_OPERATORS(SpellID, SpellID::ESpellID)
  40. ID_LIKE_OPERATORS(BuildingID, BuildingID::EBuildingID)
  41. bmap<int, ConstTransitivePtr<CGDefInfo> > & Obj::toDefObjInfo() const
  42. {
  43. return VLC->dobjinfo->gobjs[*this];
  44. }
  45. CArtifact * ArtifactID::toArtifact() const
  46. {
  47. return VLC->arth->artifacts[*this];
  48. }
  49. CCreature * CreatureID::toCreature() const
  50. {
  51. return VLC->creh->creatures[*this];
  52. }
  53. CSpell * SpellID::toSpell() const
  54. {
  55. return VLC->spellh->spells[*this];
  56. }