CMapGenerator.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "../CObjectHandler.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. typedef std::vector<JsonNode> JsonVector;
  24. class CMapGenerator;
  25. class rmgException : std::exception
  26. {
  27. std::string msg;
  28. public:
  29. explicit rmgException(const std::string& _Message) : msg(_Message)
  30. {
  31. }
  32. virtual ~rmgException() throw ()
  33. {
  34. };
  35. const char *what() const throw () override
  36. {
  37. return msg.c_str();
  38. }
  39. };
  40. /// The map generator creates a map randomly.
  41. class DLL_LINKAGE CMapGenerator
  42. {
  43. public:
  44. explicit CMapGenerator(shared_ptr<CMapGenOptions> mapGenOptions, int randomSeed = std::time(nullptr));
  45. ~CMapGenerator(); // required due to unique_ptr
  46. std::unique_ptr<CMap> generate();
  47. shared_ptr<CMapGenOptions> mapGenOptions;
  48. std::unique_ptr<CMap> map;
  49. CRandomGenerator rand;
  50. int randomSeed;
  51. CMapEditManager * editManager;
  52. std::map<TRmgTemplateZoneId, CRmgTemplateZone*> getZones() const;
  53. private:
  54. std::map<TRmgTemplateZoneId, CRmgTemplateZone*> zones;
  55. /// Generation methods
  56. std::string getMapDescription() const;
  57. void addPlayerInfo();
  58. void addHeaderInfo();
  59. void genZones();
  60. void fillZones();
  61. };
  62. /* ---------------------------------------------------------------------------- */
  63. /* Implementation/Detail classes, Private API */
  64. /* ---------------------------------------------------------------------------- */