CMapGenOptions.h 5.8 KB

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