CMapGenOptions.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 "../CRandomGenerator.h"
  13. class CRmgTemplate;
  14. namespace EWaterContent
  15. {
  16. enum EWaterContent
  17. {
  18. RANDOM = -1,
  19. NONE,
  20. NORMAL,
  21. ISLANDS
  22. };
  23. }
  24. namespace EMonsterStrength
  25. {
  26. enum EMonsterStrength
  27. {
  28. RANDOM = -1,
  29. WEAK,
  30. NORMAL,
  31. STRONG
  32. };
  33. }
  34. namespace EPlayerType
  35. {
  36. enum EPlayerType
  37. {
  38. HUMAN,
  39. AI,
  40. COMP_ONLY
  41. };
  42. }
  43. /// The map gen options class holds values about general map generation settings
  44. /// e.g. the size of the map, the count of players,...
  45. class DLL_LINKAGE CMapGenOptions
  46. {
  47. public:
  48. /// The player settings class maps the player color, starting town and human player flag.
  49. class DLL_LINKAGE CPlayerSettings
  50. {
  51. public:
  52. CPlayerSettings();
  53. /// The color of the player ranging from 0 to PlayerColor::PLAYER_LIMIT - 1.
  54. /// The default value is 0.
  55. PlayerColor getColor() const;
  56. void setColor(PlayerColor value);
  57. /// The starting town of the player ranging from 0 to town max count or RANDOM_TOWN.
  58. /// The default value is RANDOM_TOWN.
  59. si32 getStartingTown() const;
  60. void setStartingTown(si32 value);
  61. /// The default value is EPlayerType::AI.
  62. EPlayerType::EPlayerType getPlayerType() const;
  63. void setPlayerType(EPlayerType::EPlayerType value);
  64. /// Constant for a random town selection.
  65. static const si32 RANDOM_TOWN = -1;
  66. private:
  67. PlayerColor color;
  68. si32 startingTown;
  69. EPlayerType::EPlayerType playerType;
  70. public:
  71. template <typename Handler>
  72. void serialize(Handler & h, const int version)
  73. {
  74. h & color & startingTown & playerType;
  75. }
  76. };
  77. CMapGenOptions();
  78. si32 getWidth() const;
  79. void setWidth(si32 value);
  80. si32 getHeight() const;
  81. void setHeight(si32 value);
  82. bool getHasTwoLevels() const;
  83. void setHasTwoLevels(bool value);
  84. /// The count of the players ranging from 1 to PlayerColor::PLAYER_LIMIT or RANDOM_SIZE for random. If you call
  85. /// this method, all player settings are reset to default settings.
  86. si8 getPlayerCount() const;
  87. void setPlayerCount(si8 value);
  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. /// The first player colors belong to standard players and the last player colors belong to comp only players.
  103. /// All standard players are by default of type EPlayerType::AI.
  104. const std::map<PlayerColor, CPlayerSettings> & getPlayersSettings() const;
  105. void setStartingTownForPlayer(PlayerColor color, si32 town);
  106. /// Sets a player type for a standard player. A standard player is the opposite of a computer only player. The
  107. /// values which can be chosen for the player type are EPlayerType::AI or EPlayerType::HUMAN.
  108. void setPlayerTypeForStandardPlayer(PlayerColor color, EPlayerType::EPlayerType playerType);
  109. /// The random map template to generate the map with or empty/not set if the template should be chosen randomly.
  110. /// Default: Not set/random.
  111. const CRmgTemplate * getMapTemplate() const;
  112. void setMapTemplate(const CRmgTemplate * value);
  113. const std::map<std::string, CRmgTemplate *> & getAvailableTemplates() const;
  114. /// Finalizes the options. All random sizes for various properties will be overwritten by numbers from
  115. /// a random number generator by keeping the options in a valid state. Check options should return true, otherwise
  116. /// this function fails.
  117. void finalize();
  118. void finalize(CRandomGenerator & gen);
  119. /// Returns false if there is no template available which fits to the currently selected options.
  120. bool checkOptions() const;
  121. static const si8 RANDOM_SIZE = -1;
  122. private:
  123. void resetPlayersMap();
  124. int countHumanPlayers() const;
  125. PlayerColor getNextPlayerColor() const;
  126. void updateCompOnlyPlayers();
  127. void updatePlayers();
  128. const CRmgTemplate * getPossibleTemplate(CRandomGenerator & gen) const;
  129. si32 width, height;
  130. bool hasTwoLevels;
  131. si8 playerCount, teamCount, compOnlyPlayerCount, compOnlyTeamCount;
  132. EWaterContent::EWaterContent waterContent;
  133. EMonsterStrength::EMonsterStrength monsterStrength;
  134. std::map<PlayerColor, CPlayerSettings> players;
  135. const CRmgTemplate * mapTemplate;
  136. public:
  137. template <typename Handler>
  138. void serialize(Handler & h, const int version)
  139. {
  140. h & width & height & hasTwoLevels & playerCount & teamCount & compOnlyPlayerCount;
  141. h & compOnlyTeamCount & waterContent & monsterStrength & players;
  142. //TODO add name of template to class, enables selection of a template by a user
  143. }
  144. };