CMapGenerator.h 2.2 KB

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