CMapGenOptions.h 5.4 KB

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