StartInfo.h 2.6 KB

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