StartInfo.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #include "GameConstants.h"
  3. /*
  4. * StartInfo.h, part of VCMI engine
  5. *
  6. * Authors: listed in file AUTHORS in main folder
  7. *
  8. * License: GNU General Public License v2.0 or later
  9. * Full text of license available in license.txt file, in main folder
  10. *
  11. */
  12. #include "RMG/CMapGenOptions.h"
  13. class CCampaignState;
  14. /// Struct which describes the name, the color, the starting bonus of a player
  15. struct PlayerSettings
  16. {
  17. enum Ebonus {brandom=-1,bartifact, bgold, bresource};
  18. si32 castle, hero, //ID, if -1 then random, if -2 then none
  19. heroPortrait; //-1 if default, else ID
  20. std::string heroName;
  21. si8 bonus; //uses enum type Ebonus
  22. TPlayerColor color; //from 0 -
  23. ui8 handicap;//0-no, 1-mild, 2-severe
  24. ui8 team;
  25. std::string name;
  26. ui8 human; //0 - AI, non-0 serves as player id
  27. template <typename Handler> void serialize(Handler &h, const int version)
  28. {
  29. h & castle;
  30. h & hero;
  31. h & heroPortrait;
  32. h & heroName;
  33. h & bonus;
  34. h & color;
  35. h & handicap;
  36. h & name;
  37. h & human;
  38. h & team;
  39. }
  40. PlayerSettings()
  41. {
  42. bonus = brandom;
  43. castle = -2;
  44. heroPortrait = -1;
  45. }
  46. };
  47. /// Struct which describes the difficulty, the turn time,.. of a heroes match.
  48. struct StartInfo
  49. {
  50. enum EMode {NEW_GAME, LOAD_GAME, CAMPAIGN, DUEL, INVALID = 255};
  51. ui8 mode; //uses EMode enum
  52. ui8 difficulty; //0=easy; 4=impossible
  53. typedef bmap<TPlayerColor, PlayerSettings> TPlayerInfos;
  54. TPlayerInfos playerInfos; //color indexed
  55. ui32 seedToBeUsed; //0 if not sure (client requests server to decide, will be send in reply pack)
  56. ui32 seedPostInit; //so we know that game is correctly synced at the start; 0 if not known yet
  57. ui32 mapfileChecksum; //0 if not relevant
  58. ui8 turnTime; //in minutes, 0=unlimited
  59. std::string mapname; // empty for random map, otherwise name of the map or savegame
  60. bool createRandomMap; // true if a random map should be created
  61. shared_ptr<CMapGenOptions> mapGenOptions; // needs to be not nullptr if createRandomMap=true
  62. shared_ptr<CCampaignState> campState;
  63. PlayerSettings & getIthPlayersSettings(TPlayerColor no)
  64. {
  65. if(playerInfos.find(no) != playerInfos.end())
  66. return playerInfos[no];
  67. tlog1 << "Cannot find info about player " << no <<". Throwing...\n";
  68. throw std::runtime_error("Cannot find info about player");
  69. }
  70. PlayerSettings *getPlayersSettings(const ui8 nameID)
  71. {
  72. for(auto it=playerInfos.begin(); it != playerInfos.end(); ++it)
  73. if(it->second.human == nameID)
  74. return &it->second;
  75. return NULL;
  76. }
  77. template <typename Handler> void serialize(Handler &h, const int version)
  78. {
  79. h & mode;
  80. h & difficulty;
  81. h & playerInfos;
  82. h & seedToBeUsed & seedPostInit;
  83. h & mapfileChecksum;
  84. h & turnTime;
  85. h & mapname;
  86. h & createRandomMap;
  87. h & mapGenOptions;
  88. h & campState;
  89. }
  90. StartInfo() : mode(INVALID), difficulty(0), seedToBeUsed(0), seedPostInit(0),
  91. mapfileChecksum(0), turnTime(0), createRandomMap(false)
  92. {
  93. }
  94. };