CMapGenerator.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * CMapGenerator.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. #include "../CRandomGenerator.h"
  13. #include "CMapGenOptions.h"
  14. #include "CRmgTemplateZone.h"
  15. #include "../CObjectHandler.h"
  16. #include "../int3.h"
  17. class CMap;
  18. class CRmgTemplate;
  19. class CRmgTemplateZone;
  20. class CMapGenOptions;
  21. class CTerrainViewPatternConfig;
  22. class CMapEditManager;
  23. class JsonNode;
  24. class CMapGenerator;
  25. class CTileInfo;
  26. typedef std::vector<JsonNode> JsonVector;
  27. class rmgException : std::exception
  28. {
  29. std::string msg;
  30. public:
  31. explicit rmgException(const std::string& _Message) : msg(_Message)
  32. {
  33. }
  34. virtual ~rmgException() throw ()
  35. {
  36. };
  37. const char *what() const throw () override
  38. {
  39. return msg.c_str();
  40. }
  41. };
  42. /// The map generator creates a map randomly.
  43. class DLL_LINKAGE CMapGenerator
  44. {
  45. public:
  46. explicit CMapGenerator(shared_ptr<CMapGenOptions> mapGenOptions, int randomSeed = std::time(nullptr));
  47. ~CMapGenerator(); // required due to unique_ptr
  48. std::unique_ptr<CMap> generate();
  49. shared_ptr<CMapGenOptions> mapGenOptions;
  50. std::unique_ptr<CMap> map;
  51. CRandomGenerator rand;
  52. int randomSeed;
  53. CMapEditManager * editManager;
  54. std::map<TRmgTemplateZoneId, CRmgTemplateZone*> getZones() const;
  55. void foreach_neighbour(const int3 &pos, std::function<void(int3& pos)> foo);
  56. bool isBlocked(const int3 &tile) const;
  57. bool shouldBeBlocked(const int3 &tile) const;
  58. bool isPossible(const int3 &tile) const;
  59. bool isFree(const int3 &tile) const;
  60. void setOccupied(int3 &tile, ETileType::ETileType state);
  61. CTileInfo getTile(int3 tile) const;
  62. int getNearestObjectDistance(const int3 &tile) const;
  63. void setNearestObjectDistance(int3 &tile, int value);
  64. int getNextMonlithIndex();
  65. private:
  66. std::map<TRmgTemplateZoneId, CRmgTemplateZone*> zones;
  67. CTileInfo*** tiles;
  68. int monolithIndex;
  69. /// Generation methods
  70. std::string getMapDescription() const;
  71. void addPlayerInfo();
  72. void addHeaderInfo();
  73. void initTiles();
  74. void genZones();
  75. void fillZones();
  76. };