2
0

StartInfo.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 which describes the name, the color, the starting bonus of a player
  16. struct PlayerSettings
  17. {
  18. enum Ebonus {brandom=-1,bartifact, bgold, bresource};
  19. si32 castle, hero, //ID, if -1 then random, if -2 then none
  20. heroPortrait; //-1 if default, else ID
  21. std::string heroName;
  22. si8 bonus; //usees enum type Ebonus
  23. ui8 color; //from 0 -
  24. ui8 handicap;//0-no, 1-mild, 2-severe
  25. std::string name;
  26. ui8 human; //0 - AI, non-0 serves as player id
  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 & handicap;
  36. h & name;
  37. h & human;
  38. }
  39. PlayerSettings()
  40. {
  41. bonus = brandom;
  42. castle = -2;
  43. heroPortrait = -1;
  44. }
  45. };
  46. /// Struct which describes the difficulty, the turn time,.. of a heroes match.
  47. struct StartInfo
  48. {
  49. enum EMode {NEW_GAME, LOAD_GAME, CAMPAIGN, DUEL, DUEL_REPLAY, INVALID = 255};
  50. ui8 mode; //uses EMode enum
  51. ui8 difficulty; //0=easy; 4=impossible
  52. bmap<int, PlayerSettings> playerInfos; //color indexed
  53. ui8 turnTime; //in minutes, 0=unlimited
  54. std::string mapname;
  55. ui8 whichMapInCampaign; //used only for mode CAMPAIGN
  56. ui8 choosenCampaignBonus; //used only for mode CAMPAIGN
  57. PlayerSettings & getIthPlayersSettings(int no)
  58. {
  59. if(playerInfos.find(no) != playerInfos.end())
  60. return playerInfos[no];
  61. tlog1 << "Cannot find info about player " << no <<". Throwing...\n";
  62. throw std::string("Cannot find info about player");
  63. }
  64. PlayerSettings *getPlayersSettings(const ui8 nameID)
  65. {
  66. for(bmap<int, PlayerSettings>::iterator it=playerInfos.begin(); it != playerInfos.end(); ++it)
  67. if(it->second.human == nameID)
  68. return &it->second;
  69. return NULL;
  70. }
  71. template <typename Handler> void serialize(Handler &h, const int version)
  72. {
  73. h & mode;
  74. h & difficulty;
  75. h & playerInfos;
  76. h & turnTime;
  77. h & mapname;
  78. h & whichMapInCampaign;
  79. h & choosenCampaignBonus;
  80. }
  81. StartInfo()
  82. {
  83. mode = INVALID;
  84. choosenCampaignBonus = -1;
  85. }
  86. };
  87. #endif // __STARTINFO_H__