CMapGenOptions.h 6.7 KB

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