CMapGenerator.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. //static const int3 dirs[] = { int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0),
  26. // int3(1,1,0),int3(-1,1,0),int3(1,-1,0),int3(-1,-1,0) };
  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(const int3& pos)> foo);
  56. private:
  57. std::map<TRmgTemplateZoneId, CRmgTemplateZone*> zones;
  58. /// Generation methods
  59. std::string getMapDescription() const;
  60. void addPlayerInfo();
  61. void addHeaderInfo();
  62. void genZones();
  63. void fillZones();
  64. };
  65. /* ---------------------------------------------------------------------------- */
  66. /* Implementation/Detail classes, Private API */
  67. /* ---------------------------------------------------------------------------- */