CMapGenOptions.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * CMapGenOptions.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. VCMI_LIB_NAMESPACE_BEGIN
  13. class CRmgTemplate;
  14. class CRandomGenerator;
  15. namespace EWaterContent
  16. {
  17. enum EWaterContent
  18. {
  19. RANDOM = -1,
  20. NONE,
  21. NORMAL,
  22. ISLANDS
  23. };
  24. }
  25. namespace EMonsterStrength
  26. {
  27. enum EMonsterStrength
  28. {
  29. RANDOM = -2,
  30. ZONE_WEAK = -1,
  31. ZONE_NORMAL = 0,
  32. ZONE_STRONG = 1,
  33. GLOBAL_WEAK = 2,
  34. GLOBAL_NORMAL = 3,
  35. GLOBAL_STRONG = 4
  36. };
  37. }
  38. namespace EPlayerType
  39. {
  40. enum EPlayerType
  41. {
  42. HUMAN,
  43. AI,
  44. COMP_ONLY
  45. };
  46. }
  47. /// The map gen options class holds values about general map generation settings
  48. /// e.g. the size of the map, the count of players,...
  49. class DLL_LINKAGE CMapGenOptions
  50. {
  51. public:
  52. /// The player settings class maps the player color, starting town and human player flag.
  53. class DLL_LINKAGE CPlayerSettings
  54. {
  55. public:
  56. CPlayerSettings();
  57. /// The color of the player ranging from 0 to PlayerColor::PLAYER_LIMIT - 1.
  58. /// The default value is 0.
  59. PlayerColor getColor() const;
  60. void setColor(PlayerColor value);
  61. /// The starting town of the player ranging from 0 to town max count or RANDOM_TOWN.
  62. /// The default value is RANDOM_TOWN.
  63. si32 getStartingTown() const;
  64. void setStartingTown(si32 value);
  65. /// The default value is EPlayerType::AI.
  66. EPlayerType::EPlayerType getPlayerType() const;
  67. void setPlayerType(EPlayerType::EPlayerType value);
  68. /// Constant for a random town selection.
  69. static const si32 RANDOM_TOWN = -1;
  70. private:
  71. PlayerColor color;
  72. si32 startingTown;
  73. EPlayerType::EPlayerType playerType;
  74. public:
  75. template <typename Handler>
  76. void serialize(Handler & h, const int version)
  77. {
  78. h & color;
  79. h & startingTown;
  80. h & playerType;
  81. }
  82. };
  83. CMapGenOptions();
  84. CMapGenOptions(const CMapGenOptions&) = delete;
  85. si32 getWidth() const;
  86. void setWidth(si32 value);
  87. si32 getHeight() const;
  88. void setHeight(si32 value);
  89. bool getHasTwoLevels() const;
  90. void setHasTwoLevels(bool value);
  91. /// The count of all (human or computer) players ranging from 1 to PlayerColor::PLAYER_LIMIT or RANDOM_SIZE for random. If you call
  92. /// this method, all player settings are reset to default settings.
  93. si8 getPlayerCount() const;
  94. void setPlayerCount(si8 value);
  95. /// The count of the teams ranging from 0 to <players count - 1> or RANDOM_SIZE for random.
  96. si8 getTeamCount() const;
  97. void setTeamCount(si8 value);
  98. /// The count of the computer only players ranging from 0 to <PlayerColor::PLAYER_LIMIT - players count> or RANDOM_SIZE for random.
  99. /// If you call this method, all player settings are reset to default settings.
  100. si8 getCompOnlyPlayerCount() const;
  101. void setCompOnlyPlayerCount(si8 value);
  102. /// The count of the computer only teams ranging from 0 to <comp only players - 1> or RANDOM_SIZE for random.
  103. si8 getCompOnlyTeamCount() const;
  104. void setCompOnlyTeamCount(si8 value);
  105. EWaterContent::EWaterContent getWaterContent() const;
  106. void setWaterContent(EWaterContent::EWaterContent value);
  107. EMonsterStrength::EMonsterStrength getMonsterStrength() const;
  108. void setMonsterStrength(EMonsterStrength::EMonsterStrength value);
  109. /// The first player colors belong to standard players and the last player colors belong to comp only players.
  110. /// All standard players are by default of type EPlayerType::AI.
  111. const std::map<PlayerColor, CPlayerSettings> & getPlayersSettings() const;
  112. void setStartingTownForPlayer(PlayerColor color, si32 town);
  113. /// Sets a player type for a standard player. A standard player is the opposite of a computer only player. The
  114. /// values which can be chosen for the player type are EPlayerType::AI or EPlayerType::HUMAN.
  115. void setPlayerTypeForStandardPlayer(PlayerColor color, EPlayerType::EPlayerType playerType);
  116. /// The random map template to generate the map with or empty/not set if the template should be chosen randomly.
  117. /// Default: Not set/random.
  118. const CRmgTemplate * getMapTemplate() const;
  119. void setMapTemplate(const CRmgTemplate * value);
  120. std::vector<const CRmgTemplate *> getPossibleTemplates() const;
  121. /// Finalizes the options. All random sizes for various properties will be overwritten by numbers from
  122. /// a random number generator by keeping the options in a valid state. Check options should return true, otherwise
  123. /// this function fails.
  124. void finalize(CRandomGenerator & rand);
  125. /// Returns false if there is no template available which fits to the currently selected options.
  126. bool checkOptions() const;
  127. static const si8 RANDOM_SIZE = -1;
  128. private:
  129. void resetPlayersMap();
  130. int countHumanPlayers() const;
  131. int countCompOnlyPlayers() const;
  132. PlayerColor getNextPlayerColor() const;
  133. void updateCompOnlyPlayers();
  134. void updatePlayers();
  135. const CRmgTemplate * getPossibleTemplate(CRandomGenerator & rand) const;
  136. si32 width, height;
  137. bool hasTwoLevels;
  138. si8 playerCount, teamCount, compOnlyPlayerCount, compOnlyTeamCount;
  139. EWaterContent::EWaterContent waterContent;
  140. EMonsterStrength::EMonsterStrength monsterStrength;
  141. std::map<PlayerColor, CPlayerSettings> players;
  142. const CRmgTemplate * mapTemplate;
  143. public:
  144. template <typename Handler>
  145. void serialize(Handler & h, const int version)
  146. {
  147. h & width;
  148. h & height;
  149. h & hasTwoLevels;
  150. h & playerCount;
  151. h & teamCount;
  152. h & compOnlyPlayerCount;
  153. h & compOnlyTeamCount;
  154. h & waterContent;
  155. h & monsterStrength;
  156. h & players;
  157. //TODO add name of template to class, enables selection of a template by a user
  158. }
  159. };
  160. VCMI_LIB_NAMESPACE_END