BattleHex.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * BattleHex.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. //TODO: change to enum class
  12. namespace BattleSide
  13. {
  14. enum
  15. {
  16. ATTACKER = 0,
  17. DEFENDER = 1
  18. };
  19. }
  20. typedef boost::optional<ui8> BattleSideOpt;
  21. // for battle stacks' positions
  22. struct DLL_LINKAGE BattleHex //TODO: decide if this should be changed to class for better code design
  23. {
  24. si16 hex;
  25. static const si16 INVALID = -1;
  26. enum EDir
  27. {
  28. TOP_LEFT,
  29. TOP_RIGHT,
  30. RIGHT,
  31. BOTTOM_RIGHT,
  32. BOTTOM_LEFT,
  33. LEFT,
  34. NONE
  35. };
  36. BattleHex();
  37. BattleHex(si16 _hex);
  38. BattleHex(si16 x, si16 y);
  39. BattleHex(std::pair<si16, si16> xy);
  40. operator si16() const;
  41. bool isValid() const;
  42. bool isAvailable() const; //valid position not in first or last column
  43. void setX(si16 x);
  44. void setY(si16 y);
  45. void setXY(si16 x, si16 y, bool hasToBeValid = true);
  46. void setXY(std::pair<si16, si16> xy);
  47. si16 getX() const;
  48. si16 getY() const;
  49. std::pair<si16, si16> getXY() const;
  50. BattleHex& moveInDirection(EDir dir, bool hasToBeValid = true);
  51. BattleHex& operator+=(EDir dir);
  52. BattleHex cloneInDirection(EDir dir, bool hasToBeValid = true) const;
  53. BattleHex operator+(EDir dir) const;
  54. std::vector<BattleHex> neighbouringTiles() const;
  55. static signed char mutualPosition(BattleHex hex1, BattleHex hex2);
  56. static char getDistance(BattleHex hex1, BattleHex hex2);
  57. static void checkAndPush(BattleHex tile, std::vector<BattleHex> & ret);
  58. static BattleHex getClosestTile(ui8 side, BattleHex initialPos, std::set<BattleHex> & possibilities); //TODO: vector or set? copying one to another is bad
  59. template <typename Handler>
  60. void serialize(Handler &h, const int version)
  61. {
  62. h & hex;
  63. }
  64. };
  65. DLL_EXPORT std::ostream & operator<<(std::ostream & os, const BattleHex & hex);