StartInfo.h 2.7 KB

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