BattleSide.h 949 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * BattleSide.h, 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. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. enum class BattleSide : int8_t
  13. {
  14. NONE = -1,
  15. INVALID = -2,
  16. ALL_KNOWING = -3,
  17. ATTACKER = 0,
  18. DEFENDER = 1,
  19. // Aliases for convenience
  20. LEFT_SIDE = ATTACKER,
  21. RIGHT_SIDE = DEFENDER,
  22. };
  23. template<typename T>
  24. class BattleSideArray : public std::array<T, 2>
  25. {
  26. public:
  27. const T & at(BattleSide side) const
  28. {
  29. return std::array<T, 2>::at(static_cast<int>(side));
  30. }
  31. T & at(BattleSide side)
  32. {
  33. return std::array<T, 2>::at(static_cast<int>(side));
  34. }
  35. const T & operator[](BattleSide side) const
  36. {
  37. return std::array<T, 2>::at(static_cast<int>(side));
  38. }
  39. T & operator[](BattleSide side)
  40. {
  41. return std::array<T, 2>::at(static_cast<int>(side));
  42. }
  43. };
  44. VCMI_LIB_NAMESPACE_END