StartInfo.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. 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; //usees enum type Ebonus
  22. ui8 color; //from 0 -
  23. ui8 handicap;//0-no, 1-mild, 2-severe
  24. std::string name;
  25. ui8 human;
  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. }
  38. PlayerSettings()
  39. {
  40. bonus = brandom;
  41. castle = -2;
  42. heroPortrait = -1;
  43. }
  44. };
  45. struct StartInfo
  46. {
  47. enum EMode {NEW_GAME, LOAD_GAME, CAMPAIGN};
  48. ui8 mode; //0 - new game; 1 - load game; 2 - campaign
  49. ui8 difficulty; //0=easy; 4=impossible
  50. std::map<int, PlayerSettings> playerInfos; //color indexed
  51. ui8 turnTime; //in minutes, 0=unlimited
  52. std::string mapname;
  53. ui8 whichMapInCampaign; //used only for mode 2
  54. ui8 choosenCampaignBonus; //used only for mode 2
  55. PlayerSettings & getIthPlayersSettings(int no)
  56. {
  57. if(playerInfos.find(no) != playerInfos.end())
  58. return playerInfos[no];
  59. tlog1 << "Cannot find info about player " << no <<". Throwing...\n";
  60. throw std::string("Cannot find info about player");
  61. }
  62. PlayerSettings *getPlayersSettings(const std::string &name)
  63. {
  64. for(std::map<int, PlayerSettings>::iterator it=playerInfos.begin(); it != playerInfos.end(); ++it)
  65. if(it->second.name == name)
  66. return &it->second;
  67. return NULL;
  68. }
  69. template <typename Handler> void serialize(Handler &h, const int version)
  70. {
  71. h & mode;
  72. h & difficulty;
  73. h & playerInfos;
  74. h & turnTime;
  75. h & mapname;
  76. h & whichMapInCampaign;
  77. h & choosenCampaignBonus;
  78. }
  79. };
  80. #endif // __STARTINFO_H__