CMapGenerator.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 "CMapGenOptions.h"
  13. #include "../CRandomGenerator.h"
  14. class CMap;
  15. class CTerrainViewPatternConfig;
  16. class CMapEditManager;
  17. /**
  18. * The map generator creates a map randomly.
  19. */
  20. class CMapGenerator
  21. {
  22. public:
  23. /**
  24. * The player settings class maps the player color, starting town and human player flag.
  25. */
  26. class CPlayerSettings
  27. {
  28. public:
  29. enum EPlayerType
  30. {
  31. HUMAN,
  32. AI,
  33. COMP_ONLY
  34. };
  35. /**
  36. * Constructor.
  37. */
  38. CPlayerSettings();
  39. /**
  40. * Gets the color of the player. The default value is 0.
  41. *
  42. * @return the color of the player ranging from 0 to PlayerColor::PLAYER_LIMIT - 1
  43. */
  44. PlayerColor getColor() const;
  45. /**
  46. * Sets the color of the player.
  47. *
  48. * @param value the color of the player ranging from 0 to PlayerColor::PLAYER_LIMIT - 1
  49. */
  50. void setColor(PlayerColor value);
  51. /**
  52. * Gets the starting town of the player. The default value is RANDOM_TOWN.
  53. *
  54. * @return the starting town of the player ranging from 0 to town max count or RANDOM_TOWN
  55. */
  56. int getStartingTown() const;
  57. /**
  58. * Sets the starting town of the player.
  59. *
  60. * @param value the starting town of the player ranging from 0 to town max count or RANDOM_TOWN
  61. */
  62. void setStartingTown(int value);
  63. /**
  64. * Gets the type of the player. The default value is EPlayerType::AI.
  65. *
  66. * @return the type of the player
  67. */
  68. EPlayerType getPlayerType() const;
  69. /**
  70. * Sets the type of the player.
  71. *
  72. * @param playerType the type of the player
  73. */
  74. void setPlayerType(EPlayerType value);
  75. /** Constant for a random town selection. */
  76. static const int RANDOM_TOWN = -1;
  77. private:
  78. /** The color of the player. */
  79. PlayerColor color;
  80. /** The starting town of the player. */
  81. int startingTown;
  82. /** The type of the player e.g. human, comp only,... */
  83. EPlayerType playerType;
  84. };
  85. /**
  86. * Constructor.
  87. *
  88. * @param mapGenOptions these options describe how to generate the map.
  89. * @param players the random gen player settings
  90. * @param randomSeed a random seed is required to get random numbers.
  91. */
  92. CMapGenerator(const CMapGenOptions & mapGenOptions, const std::map<PlayerColor, CPlayerSettings> & players, int randomSeed);
  93. /**
  94. * Destructor.
  95. */
  96. ~CMapGenerator();
  97. /**
  98. * Generates a map.
  99. *
  100. * @return the generated map object stored in a unique ptr
  101. */
  102. std::unique_ptr<CMap> generate();
  103. private:
  104. /**
  105. * Validates map gen options and players options. On errors exceptions will be thrown.
  106. */
  107. void validateOptions() const;
  108. /**
  109. * Finalizes map generation options. Random sizes for various properties are
  110. * converted to fixed values.
  111. */
  112. void finalizeMapGenOptions();
  113. /**
  114. * Gets the map description of the generated map.
  115. *
  116. * @return the map description of the generated map
  117. */
  118. std::string getMapDescription() const;
  119. /**
  120. * Adds player information.(teams, colors, etc...)
  121. */
  122. void addPlayerInfo();
  123. /**
  124. * Counts the amount of human players.
  125. *
  126. * @return the amount of human players ranging from 0 to PlayerColor::PLAYER_LIMIT
  127. */
  128. int countHumanPlayers() const;
  129. /**
  130. * Generate terrain.
  131. */
  132. void genTerrain();
  133. /**
  134. * Generate towns.
  135. */
  136. void genTowns();
  137. /**
  138. * Adds header info(size, description, etc...)
  139. */
  140. void addHeaderInfo();
  141. /**
  142. * Gets the next free player color.
  143. *
  144. * @return the next free player color
  145. */
  146. PlayerColor getNextPlayerColor() const;
  147. /** The map options which describes the size of the map and contain player info. */
  148. CMapGenOptions mapGenOptions;
  149. /** The generated map. */
  150. std::unique_ptr<CMap> map;
  151. /** The random number generator. */
  152. CRandomGenerator gen;
  153. /** The random seed, it is used for the map description. */
  154. int randomSeed;
  155. /** The terrain view pattern config. */
  156. std::unique_ptr<CTerrainViewPatternConfig> terViewPatternConfig;
  157. /** The map edit manager. */
  158. std::unique_ptr<CMapEditManager> mapMgr;
  159. /** The random gen player settings. */
  160. std::map<PlayerColor, CPlayerSettings> players;
  161. };