CMapGenOptions.h 6.3 KB

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