StartInfo.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. ui8 turnTime; //in minutes, 0=unlimited
  53. std::string mapname;
  54. ui8 whichMapInCampaign; //used only for mode CAMPAIGN
  55. ui8 choosenCampaignBonus; //used only for mode CAMPAIGN
  56. PlayerSettings & getIthPlayersSettings(int no)
  57. {
  58. if(playerInfos.find(no) != playerInfos.end())
  59. return playerInfos[no];
  60. tlog1 << "Cannot find info about player " << no <<". Throwing...\n";
  61. throw std::string("Cannot find info about player");
  62. }
  63. PlayerSettings *getPlayersSettings(const ui8 nameID)
  64. {
  65. for(bmap<int, PlayerSettings>::iterator it=playerInfos.begin(); it != playerInfos.end(); ++it)
  66. if(it->second.human == nameID)
  67. return &it->second;
  68. return NULL;
  69. }
  70. template <typename Handler> void serialize(Handler &h, const int version)
  71. {
  72. h & mode;
  73. h & difficulty;
  74. h & playerInfos;
  75. h & turnTime;
  76. h & mapname;
  77. h & whichMapInCampaign;
  78. h & choosenCampaignBonus;
  79. }
  80. StartInfo()
  81. {
  82. mode = INVALID;
  83. choosenCampaignBonus = -1;
  84. }
  85. };