StartInfo.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * StartInfo.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. class CMapGenOptions;
  13. class CCampaignState;
  14. /// Struct which describes the name, the color, the starting bonus of a player
  15. struct PlayerSettings
  16. {
  17. enum { PLAYER_AI = 0 }; // for use in playerID
  18. enum Ebonus {
  19. NONE = -2,
  20. RANDOM = -1,
  21. ARTIFACT = 0,
  22. GOLD = 1,
  23. RESOURCE = 2
  24. };
  25. Ebonus bonus;
  26. si16 castle;
  27. si32 hero,
  28. heroPortrait; //-1 if default, else ID
  29. std::string heroName;
  30. PlayerColor color; //from 0 -
  31. enum EHandicap {NO_HANDICAP, MILD, SEVERE};
  32. EHandicap handicap;//0-no, 1-mild, 2-severe
  33. TeamID team;
  34. std::string name;
  35. ui8 playerID; //0 - AI, non-0 serves as player id
  36. bool compOnly; //true if this player is a computer only player; required for RMG
  37. template <typename Handler>
  38. void serialize(Handler &h, const int version)
  39. {
  40. h & castle;
  41. h & hero;
  42. h & heroPortrait;
  43. h & heroName;
  44. h & bonus;
  45. h & color;
  46. h & handicap;
  47. h & name;
  48. h & playerID;
  49. h & team;
  50. h & compOnly;
  51. }
  52. PlayerSettings() : bonus(RANDOM), castle(NONE), hero(RANDOM), heroPortrait(RANDOM),
  53. color(0), handicap(NO_HANDICAP), team(0), playerID(PLAYER_AI), compOnly(false)
  54. {
  55. }
  56. };
  57. /// Struct which describes the difficulty, the turn time,.. of a heroes match.
  58. struct StartInfo
  59. {
  60. enum EMode {NEW_GAME, LOAD_GAME, CAMPAIGN, INVALID = 255};
  61. EMode mode;
  62. ui8 difficulty; //0=easy; 4=impossible
  63. typedef std::map<PlayerColor, PlayerSettings> TPlayerInfos;
  64. TPlayerInfos playerInfos; //color indexed
  65. ui32 seedToBeUsed; //0 if not sure (client requests server to decide, will be send in reply pack)
  66. ui32 seedPostInit; //so we know that game is correctly synced at the start; 0 if not known yet
  67. ui32 mapfileChecksum; //0 if not relevant
  68. ui8 turnTime; //in minutes, 0=unlimited
  69. std::string mapname; // empty for random map, otherwise name of the map or savegame
  70. bool createRandomMap() const { return mapGenOptions.get() != nullptr; }
  71. std::shared_ptr<CMapGenOptions> mapGenOptions;
  72. std::shared_ptr<CCampaignState> campState;
  73. PlayerSettings & getIthPlayersSettings(PlayerColor no)
  74. {
  75. if(playerInfos.find(no) != playerInfos.end())
  76. return playerInfos[no];
  77. logGlobal->error("Cannot find info about player %s. Throwing...", no.getStr());
  78. throw std::runtime_error("Cannot find info about player");
  79. }
  80. const PlayerSettings & getIthPlayersSettings(PlayerColor no) const
  81. {
  82. return const_cast<StartInfo&>(*this).getIthPlayersSettings(no);
  83. }
  84. PlayerSettings *getPlayersSettings(const ui8 nameID)
  85. {
  86. for(auto it=playerInfos.begin(); it != playerInfos.end(); ++it)
  87. if(it->second.playerID == nameID)
  88. return &it->second;
  89. return nullptr;
  90. }
  91. template <typename Handler>
  92. void serialize(Handler &h, const int version)
  93. {
  94. h & mode;
  95. h & difficulty;
  96. h & playerInfos;
  97. h & seedToBeUsed;
  98. h & seedPostInit;
  99. h & mapfileChecksum;
  100. h & turnTime;
  101. h & mapname;
  102. h & mapGenOptions;
  103. h & campState;
  104. }
  105. StartInfo() : mode(INVALID), difficulty(0), seedToBeUsed(0), seedPostInit(0),
  106. mapfileChecksum(0), turnTime(0)
  107. {
  108. }
  109. };