CMapGenOptions.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. namespace EPlayerType
  16. {
  17. enum EPlayerType
  18. {
  19. HUMAN,
  20. AI,
  21. COMP_ONLY
  22. };
  23. }
  24. /// The map gen options class holds values about general map generation settings
  25. /// e.g. the size of the map, the count of players,...
  26. class DLL_LINKAGE CMapGenOptions
  27. {
  28. public:
  29. /// The player settings class maps the player color, starting town and human player flag.
  30. class DLL_LINKAGE CPlayerSettings
  31. {
  32. public:
  33. CPlayerSettings();
  34. /// The color of the player ranging from 0 to PlayerColor::PLAYER_LIMIT - 1.
  35. /// The default value is 0.
  36. PlayerColor getColor() const;
  37. void setColor(const PlayerColor & value);
  38. /// The starting town of the player ranging from 0 to town max count or RANDOM_TOWN.
  39. /// The default value is RANDOM_TOWN.
  40. si32 getStartingTown() const;
  41. void setStartingTown(si32 value);
  42. /// The default value is EPlayerType::AI.
  43. EPlayerType::EPlayerType getPlayerType() const;
  44. void setPlayerType(EPlayerType::EPlayerType value);
  45. /// Team id for this player. TeamID::NO_TEAM by default - team will be randomly assigned
  46. TeamID getTeam() const;
  47. void setTeam(const TeamID & value);
  48. /// Constant for a random town selection.
  49. static const si32 RANDOM_TOWN = -1;
  50. private:
  51. PlayerColor color;
  52. si32 startingTown;
  53. EPlayerType::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. }
  65. };
  66. CMapGenOptions();
  67. CMapGenOptions(const CMapGenOptions&) = delete;
  68. si32 getWidth() const;
  69. void setWidth(si32 value);
  70. si32 getHeight() const;
  71. void setHeight(si32 value);
  72. bool getHasTwoLevels() const;
  73. void setHasTwoLevels(bool value);
  74. /// The count of all (human or computer) players ranging from 1 to PlayerColor::PLAYER_LIMIT or RANDOM_SIZE for random. If you call
  75. /// this method, all player settings are reset to default settings.
  76. si8 getPlayerCount() const;
  77. void setPlayerCount(si8 value);
  78. /// The count of the teams ranging from 0 to <players count - 1> or RANDOM_SIZE for random.
  79. si8 getTeamCount() const;
  80. void setTeamCount(si8 value);
  81. /// The count of the computer only players ranging from 0 to <PlayerColor::PLAYER_LIMIT - players count> or RANDOM_SIZE for random.
  82. /// If you call this method, all player settings are reset to default settings.
  83. si8 getCompOnlyPlayerCount() const;
  84. void setCompOnlyPlayerCount(si8 value);
  85. /// The count of the computer only teams ranging from 0 to <comp only players - 1> or RANDOM_SIZE for random.
  86. si8 getCompOnlyTeamCount() const;
  87. void setCompOnlyTeamCount(si8 value);
  88. EWaterContent::EWaterContent getWaterContent() const;
  89. void setWaterContent(EWaterContent::EWaterContent value);
  90. EGlobalMonsterStrength::EGlobalMonsterStrength getMonsterStrength() const;
  91. void setMonsterStrength(EGlobalMonsterStrength::EGlobalMonsterStrength value);
  92. bool isRoadEnabled(const std::string & roadName) const;
  93. void setRoadEnabled(const std::string & roadName, 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. void setStartingTownForPlayer(const PlayerColor & color, si32 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::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. static const si8 RANDOM_SIZE = -1;
  115. private:
  116. void resetPlayersMap();
  117. int countHumanPlayers() const;
  118. int countCompOnlyPlayers() const;
  119. PlayerColor getNextPlayerColor() const;
  120. void updateCompOnlyPlayers();
  121. void updatePlayers();
  122. const CRmgTemplate * getPossibleTemplate(CRandomGenerator & rand) const;
  123. si32 width, height;
  124. bool hasTwoLevels;
  125. si8 playerCount, teamCount, compOnlyPlayerCount, compOnlyTeamCount;
  126. EWaterContent::EWaterContent waterContent;
  127. EGlobalMonsterStrength::EGlobalMonsterStrength monsterStrength;
  128. std::map<PlayerColor, CPlayerSettings> players;
  129. std::set<std::string> disabledRoads;
  130. const CRmgTemplate * mapTemplate;
  131. public:
  132. template <typename Handler>
  133. void serialize(Handler & h, const int version)
  134. {
  135. h & width;
  136. h & height;
  137. h & hasTwoLevels;
  138. h & playerCount;
  139. h & teamCount;
  140. h & compOnlyPlayerCount;
  141. h & compOnlyTeamCount;
  142. h & waterContent;
  143. h & monsterStrength;
  144. h & players;
  145. std::string templateName;
  146. if(mapTemplate && h.saving)
  147. {
  148. templateName = mapTemplate->getId();
  149. }
  150. if(version >= 806)
  151. {
  152. h & templateName;
  153. if(!h.saving)
  154. {
  155. setMapTemplate(templateName);
  156. }
  157. h & disabledRoads;
  158. }
  159. }
  160. };
  161. VCMI_LIB_NAMESPACE_END