CMapGenOptions.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 getPlayerCount() const;
  74. void setPlayerCount(si8 value);
  75. /// The count of the teams ranging from 0 to <players count - 1> or RANDOM_SIZE for random.
  76. si8 getTeamCount() const;
  77. void setTeamCount(si8 value);
  78. /// The count of the computer only players ranging from 0 to <PlayerColor::PLAYER_LIMIT - players count> or RANDOM_SIZE for random.
  79. /// If you call this method, all player settings are reset to default settings.
  80. si8 getCompOnlyPlayerCount() const;
  81. void setCompOnlyPlayerCount(si8 value);
  82. /// The count of the computer only teams ranging from 0 to <comp only players - 1> or RANDOM_SIZE for random.
  83. si8 getCompOnlyTeamCount() const;
  84. void setCompOnlyTeamCount(si8 value);
  85. EWaterContent::EWaterContent getWaterContent() const;
  86. void setWaterContent(EWaterContent::EWaterContent value);
  87. EMonsterStrength::EMonsterStrength getMonsterStrength() const;
  88. void setMonsterStrength(EMonsterStrength::EMonsterStrength value);
  89. bool isRoadEnabled(const std::string & roadName) const;
  90. void setRoadEnabled(const std::string & roadName, bool enable);
  91. /// The first player colors belong to standard players and the last player colors belong to comp only players.
  92. /// All standard players are by default of type EPlayerType::AI.
  93. const std::map<PlayerColor, CPlayerSettings> & getPlayersSettings() const;
  94. void setStartingTownForPlayer(const PlayerColor & color, si32 town);
  95. /// Sets a player type for a standard player. A standard player is the opposite of a computer only player. The
  96. /// values which can be chosen for the player type are EPlayerType::AI or EPlayerType::HUMAN.
  97. void setPlayerTypeForStandardPlayer(const PlayerColor & color, EPlayerType playerType);
  98. void setPlayerTeam(const PlayerColor & color, const TeamID & team = TeamID::NO_TEAM);
  99. /// The random map template to generate the map with or empty/not set if the template should be chosen randomly.
  100. /// Default: Not set/random.
  101. const CRmgTemplate * getMapTemplate() const;
  102. void setMapTemplate(const CRmgTemplate * value);
  103. void setMapTemplate(const std::string & name);
  104. std::vector<const CRmgTemplate *> getPossibleTemplates() const;
  105. /// Finalizes the options. All random sizes for various properties will be overwritten by numbers from
  106. /// a random number generator by keeping the options in a valid state. Check options should return true, otherwise
  107. /// this function fails.
  108. void finalize(CRandomGenerator & rand);
  109. /// Returns false if there is no template available which fits to the currently selected options.
  110. bool checkOptions() const;
  111. static const si8 RANDOM_SIZE = -1;
  112. private:
  113. void resetPlayersMap();
  114. int countHumanPlayers() const;
  115. int countCompOnlyPlayers() const;
  116. PlayerColor getNextPlayerColor() const;
  117. void updateCompOnlyPlayers();
  118. void updatePlayers();
  119. const CRmgTemplate * getPossibleTemplate(CRandomGenerator & rand) const;
  120. si32 width, height;
  121. bool hasTwoLevels;
  122. si8 playerCount, teamCount, compOnlyPlayerCount, compOnlyTeamCount;
  123. EWaterContent::EWaterContent waterContent;
  124. EMonsterStrength::EMonsterStrength monsterStrength;
  125. std::map<PlayerColor, CPlayerSettings> players;
  126. std::set<std::string> disabledRoads;
  127. const CRmgTemplate * mapTemplate;
  128. public:
  129. template <typename Handler>
  130. void serialize(Handler & h, const int version)
  131. {
  132. h & width;
  133. h & height;
  134. h & hasTwoLevels;
  135. h & playerCount;
  136. h & teamCount;
  137. h & compOnlyPlayerCount;
  138. h & compOnlyTeamCount;
  139. h & waterContent;
  140. h & monsterStrength;
  141. h & players;
  142. std::string templateName;
  143. if(mapTemplate && h.saving)
  144. {
  145. templateName = mapTemplate->getId();
  146. }
  147. if(version >= 806)
  148. {
  149. h & templateName;
  150. if(!h.saving)
  151. {
  152. setMapTemplate(templateName);
  153. }
  154. h & disabledRoads;
  155. }
  156. }
  157. };
  158. VCMI_LIB_NAMESPACE_END