SectorMap.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * SectorMap.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 "AIUtility.h"
  12. enum
  13. {
  14. NOT_VISIBLE = 0,
  15. NOT_CHECKED = 1,
  16. NOT_AVAILABLE
  17. };
  18. struct SectorMap
  19. {
  20. //a sector is set of tiles that would be mutually reachable if all visitable objs would be passable (incl monsters)
  21. struct Sector
  22. {
  23. int id;
  24. std::vector<int3> tiles;
  25. std::vector<int3> embarkmentPoints; //tiles of other sectors onto which we can (dis)embark
  26. std::vector<const CGObjectInstance *> visitableObjs;
  27. bool water; //all tiles of sector are land or water
  28. Sector()
  29. {
  30. id = -1;
  31. water = false;
  32. }
  33. };
  34. typedef unsigned short TSectorID; //smaller than int to allow -1 value. Max number of sectors 65K should be enough for any proper map.
  35. typedef boost::multi_array<TSectorID, 3> TSectorArray;
  36. bool valid; //some kind of lazy eval
  37. std::map<int3, int3> parent;
  38. TSectorArray sector;
  39. //std::vector<std::vector<std::vector<unsigned char>>> pathfinderSector;
  40. std::map<int, Sector> infoOnSectors;
  41. std::shared_ptr<boost::multi_array<TerrainTile *, 3>> visibleTiles;
  42. SectorMap();
  43. SectorMap(HeroPtr h);
  44. void update();
  45. void clear();
  46. void exploreNewSector(crint3 pos, int num, CCallback * cbp);
  47. void write(crstring fname);
  48. bool markIfBlocked(TSectorID & sec, crint3 pos, const TerrainTile * t);
  49. bool markIfBlocked(TSectorID & sec, crint3 pos);
  50. TSectorID & retrieveTile(crint3 pos);
  51. TSectorID & retrieveTileN(TSectorArray & vectors, const int3 & pos);
  52. const TSectorID & retrieveTileN(const TSectorArray & vectors, const int3 & pos);
  53. TerrainTile * getTile(crint3 pos) const;
  54. std::vector<const CGObjectInstance *> getNearbyObjs(HeroPtr h, bool sectorsAround);
  55. void makeParentBFS(crint3 source);
  56. int3 firstTileToGet(HeroPtr h, crint3 dst); //if h wants to reach tile dst, which tile he should visit to clear the way?
  57. int3 findFirstVisitableTile(HeroPtr h, crint3 dst);
  58. };