CMapGenOptions.h 6.2 KB

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