BattleHex.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "GameConstants.h"
  12. // for battle stacks' positions
  13. struct DLL_LINKAGE BattleHex //TODO: decide if this should be changed to class for better code design
  14. {
  15. si16 hex;
  16. static const si16 INVALID = -1;
  17. enum EDir { TOP_LEFT, TOP_RIGHT, RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT, LEFT};
  18. BattleHex();
  19. BattleHex(si16 _hex);
  20. BattleHex(si16 x, si16 y);
  21. BattleHex(std::pair<si16, si16> xy);
  22. operator si16() const;
  23. bool isValid() const;
  24. bool isAvailable() const; //valid position not in first or last column
  25. void setX(si16 x);
  26. void setY(si16 y);
  27. void setXY(si16 x, si16 y, bool hasToBeValid = true);
  28. void setXY(std::pair<si16, si16> xy);
  29. si16 getX() const;
  30. si16 getY() const;
  31. std::pair<si16, si16> getXY() const;
  32. BattleHex& moveInDirection(EDir dir, bool hasToBeValid = true);
  33. BattleHex& operator+=(EDir dir);
  34. BattleHex cloneInDirection(EDir dir, bool hasToBeValid = true) const;
  35. BattleHex operator+(EDir dir) const;
  36. std::vector<BattleHex> neighbouringTiles() const;
  37. static signed char mutualPosition(BattleHex hex1, BattleHex hex2);
  38. static char getDistance(BattleHex hex1, BattleHex hex2);
  39. static void checkAndPush(BattleHex tile, std::vector<BattleHex> & ret);
  40. static BattleHex getClosestTile(bool attackerOwned, BattleHex initialPos, std::set<BattleHex> & possibilities); //TODO: vector or set? copying one to another is bad
  41. template <typename Handler>
  42. void serialize(Handler &h, const int version)
  43. {
  44. h & hex;
  45. }
  46. };
  47. DLL_EXPORT std::ostream & operator<<(std::ostream & os, const BattleHex & hex);