StartInfo.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef __STARTINFO_H__
  2. #define __STARTINFO_H__
  3. #include "global.h"
  4. #include <vector>
  5. #include <string>
  6. /*
  7. * StartInfo.h, part of VCMI engine
  8. *
  9. * Authors: listed in file AUTHORS in main folder
  10. *
  11. * License: GNU General Public License v2.0 or later
  12. * Full text of license available in license.txt file, in main folder
  13. *
  14. */
  15. enum Ebonus {brandom=-1,bartifact, bgold, bresource};
  16. struct PlayerSettings
  17. {
  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; //usees enum type Ebonus
  22. ui8 color; //from 0 -
  23. ui8 serial;
  24. ui8 handicap;//0-no, 1-mild, 2-severe
  25. std::string name;
  26. ui8 human;
  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 & serial;
  36. h & handicap;
  37. h & name;
  38. h & human;
  39. }
  40. PlayerSettings()
  41. {
  42. bonus = brandom;
  43. castle = -2;
  44. heroPortrait = -1;
  45. }
  46. };
  47. struct StartInfo
  48. {
  49. ui8 mode; //0 - new game; 1 - load game; 2 - campaign
  50. ui8 difficulty; //0=easy; 4=impossible
  51. std::vector<PlayerSettings> playerInfos; //serial indexed
  52. ui8 turnTime; //in minutes, 0=unlimited
  53. std::string mapname;
  54. ui8 whichMapInCampaign; //used only for mode 2
  55. PlayerSettings & getIthPlayersSettings(int no)
  56. {
  57. for(unsigned int i=0; i<playerInfos.size(); ++i)
  58. if(playerInfos[i].color == no)
  59. return playerInfos[i];
  60. tlog1 << "Cannot find info about player " << no <<". Throwing...\n";
  61. throw std::string("Cannot find info about player");
  62. }
  63. PlayerSettings *getPlayersSettings(const std::string &name)
  64. {
  65. for(unsigned int i=0; i<playerInfos.size(); ++i)
  66. if(playerInfos[i].name == name)
  67. return &playerInfos[i];
  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. }
  79. };
  80. #endif // __STARTINFO_H__