Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

LandcellId.h 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #ifndef BZR_LANDCELLID_H
  19. #define BZR_LANDCELLID_H
  20. /*
  21. * A landcell id is a 32-bit value identifying a cell
  22. * Bits 24:31 are x, the 0-255, east to west position of the landblock container the landcell
  23. * Bits 16:23 are y, the 0-255, south to north position
  24. * Bits 0:15 are n, the index of the cell
  25. * 0x0001 <= n <= 0x0040 specify a cell on land, with an origin in the south-west and column-major format
  26. * 0x0100 <= n < 0xFFFE specify a structure, either above or below ground
  27. * n = 0x0000 and 0x0040 < n < 0x0100 are not used
  28. * n = 0xFFFE is reserved for the landblock info file
  29. * n = 0xFFFF is reserved for the landblock landscape file
  30. * n = 0xFFFF is also used to identify the landblock (the collection of landcells sharing an x and y)
  31. */
  32. class LandcellId
  33. {
  34. public:
  35. LandcellId();
  36. explicit LandcellId(uint32_t value);
  37. LandcellId(int x, int y);
  38. LandcellId(int x, int y, int n);
  39. int calcSquareDistance(LandcellId other) const;
  40. int x() const;
  41. int y() const;
  42. int n() const;
  43. uint32_t value() const;
  44. bool isStructure() const;
  45. bool operator==(LandcellId other) const;
  46. bool operator!=(LandcellId other) const;
  47. private:
  48. uint32_t value_;
  49. };
  50. namespace std
  51. {
  52. template<>
  53. struct hash<LandcellId>
  54. {
  55. size_t operator()(LandcellId id) const
  56. {
  57. return id.value();
  58. }
  59. };
  60. }
  61. #endif