StartInfo.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. std::string name;
  22. ui8 human; //0 - AI, non-0 serves as player id
  23. template <typename Handler> void serialize(Handler &h, const int version)
  24. {
  25. h & castle;
  26. h & hero;
  27. h & heroPortrait;
  28. h & heroName;
  29. h & bonus;
  30. h & color;
  31. h & handicap;
  32. h & name;
  33. h & human;
  34. }
  35. PlayerSettings()
  36. {
  37. bonus = brandom;
  38. castle = -2;
  39. heroPortrait = -1;
  40. }
  41. };
  42. /// Struct which describes the difficulty, the turn time,.. of a heroes match.
  43. struct StartInfo
  44. {
  45. enum EMode {NEW_GAME, LOAD_GAME, CAMPAIGN, DUEL, INVALID = 255};
  46. ui8 mode; //uses EMode enum
  47. ui8 difficulty; //0=easy; 4=impossible
  48. bmap<int, PlayerSettings> playerInfos; //color indexed
  49. ui8 turnTime; //in minutes, 0=unlimited
  50. std::string mapname;
  51. ui8 whichMapInCampaign; //used only for mode CAMPAIGN
  52. ui8 choosenCampaignBonus; //used only for mode CAMPAIGN
  53. PlayerSettings & getIthPlayersSettings(int no)
  54. {
  55. if(playerInfos.find(no) != playerInfos.end())
  56. return playerInfos[no];
  57. tlog1 << "Cannot find info about player " << no <<". Throwing...\n";
  58. throw std::string("Cannot find info about player");
  59. }
  60. PlayerSettings *getPlayersSettings(const ui8 nameID)
  61. {
  62. for(bmap<int, PlayerSettings>::iterator it=playerInfos.begin(); it != playerInfos.end(); ++it)
  63. if(it->second.human == nameID)
  64. return &it->second;
  65. return NULL;
  66. }
  67. template <typename Handler> void serialize(Handler &h, const int version)
  68. {
  69. h & mode;
  70. h & difficulty;
  71. h & playerInfos;
  72. h & turnTime;
  73. h & mapname;
  74. h & whichMapInCampaign;
  75. h & choosenCampaignBonus;
  76. }
  77. StartInfo()
  78. {
  79. mode = INVALID;
  80. choosenCampaignBonus = -1;
  81. }
  82. };