CMapGenOptions.h 6.7 KB

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