CGameStateFwd.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * CGameStateFwd.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "CCreatureSet.h"
  12. #include "int3.h"
  13. class CQuest;
  14. class CGObjectInstance;
  15. class CHeroClass;
  16. class CTown;
  17. //numbers of creatures are exact numbers if detailed else they are quantity ids (1 - a few, 2 - several and so on; additionally 0 - unknown)
  18. struct ArmyDescriptor : public std::map<SlotID, CStackBasicDescriptor>
  19. {
  20. bool isDetailed;
  21. DLL_LINKAGE ArmyDescriptor(const CArmedInstance *army, bool detailed); //not detailed -> quantity ids as count
  22. DLL_LINKAGE ArmyDescriptor();
  23. DLL_LINKAGE int getStrength() const;
  24. };
  25. struct DLL_LINKAGE InfoAboutArmy
  26. {
  27. PlayerColor owner;
  28. std::string name;
  29. ArmyDescriptor army;
  30. InfoAboutArmy();
  31. InfoAboutArmy(const CArmedInstance *Army, bool detailed);
  32. void initFromArmy(const CArmedInstance *Army, bool detailed);
  33. };
  34. struct DLL_LINKAGE InfoAboutHero : public InfoAboutArmy
  35. {
  36. private:
  37. void assign(const InfoAboutHero & iah);
  38. public:
  39. struct DLL_LINKAGE Details
  40. {
  41. std::vector<si32> primskills;
  42. si32 mana, manaLimit, luck, morale;
  43. } *details;
  44. const CHeroClass *hclass;
  45. int portrait;
  46. enum EInfoLevel
  47. {
  48. BASIC,
  49. DETAILED,
  50. INBATTLE
  51. };
  52. InfoAboutHero();
  53. InfoAboutHero(const InfoAboutHero & iah);
  54. InfoAboutHero(const CGHeroInstance *h, EInfoLevel infoLevel);
  55. ~InfoAboutHero();
  56. InfoAboutHero & operator=(const InfoAboutHero & iah);
  57. void initFromHero(const CGHeroInstance *h, EInfoLevel infoLevel);
  58. };
  59. /// Struct which holds a int information about a town
  60. struct DLL_LINKAGE InfoAboutTown : public InfoAboutArmy
  61. {
  62. struct DLL_LINKAGE Details
  63. {
  64. si32 hallLevel, goldIncome;
  65. bool customRes;
  66. bool garrisonedHero;
  67. } *details;
  68. const CTown *tType;
  69. si32 built;
  70. si32 fortLevel; //0 - none
  71. InfoAboutTown();
  72. InfoAboutTown(const CGTownInstance *t, bool detailed);
  73. ~InfoAboutTown();
  74. void initFromTown(const CGTownInstance *t, bool detailed);
  75. };
  76. class DLL_LINKAGE EVictoryLossCheckResult
  77. {
  78. public:
  79. static EVictoryLossCheckResult victory(std::string toSelf, std::string toOthers)
  80. {
  81. return EVictoryLossCheckResult(VICTORY, toSelf, toOthers);
  82. }
  83. static EVictoryLossCheckResult defeat(std::string toSelf, std::string toOthers)
  84. {
  85. return EVictoryLossCheckResult(DEFEAT, toSelf, toOthers);
  86. }
  87. EVictoryLossCheckResult():
  88. intValue(0)
  89. {
  90. }
  91. bool operator==(EVictoryLossCheckResult const & other) const
  92. {
  93. return intValue == other.intValue;
  94. }
  95. bool operator!=(EVictoryLossCheckResult const & other) const
  96. {
  97. return intValue != other.intValue;
  98. }
  99. bool victory() const
  100. {
  101. return intValue == VICTORY;
  102. }
  103. bool loss() const
  104. {
  105. return intValue == DEFEAT;
  106. }
  107. EVictoryLossCheckResult invert()
  108. {
  109. return EVictoryLossCheckResult(-intValue, messageToOthers, messageToSelf);
  110. }
  111. std::string messageToSelf;
  112. std::string messageToOthers;
  113. template <typename Handler> void serialize(Handler &h, const int version)
  114. {
  115. h & intValue;
  116. h & messageToSelf;
  117. h & messageToOthers;
  118. }
  119. private:
  120. enum EResult
  121. {
  122. DEFEAT = -1,
  123. INGAME = 0,
  124. VICTORY= +1
  125. };
  126. EVictoryLossCheckResult(si32 intValue, std::string toSelf, std::string toOthers):
  127. messageToSelf(toSelf),
  128. messageToOthers(toOthers),
  129. intValue(intValue)
  130. {
  131. }
  132. si32 intValue; // uses EResult
  133. };
  134. /*static std::ostream & operator<<(std::ostream & os, const EVictoryLossCheckResult & victoryLossCheckResult)
  135. {
  136. os << victoryLossCheckResult.messageToSelf;
  137. return os;
  138. }*/
  139. struct DLL_LINKAGE QuestInfo //universal interface for human and AI
  140. {
  141. const CQuest * quest;
  142. const CGObjectInstance * obj; //related object, most likely Seer Hut
  143. int3 tile;
  144. QuestInfo()
  145. : quest(nullptr), obj(nullptr), tile(-1,-1,-1)
  146. {};
  147. QuestInfo (const CQuest * Quest, const CGObjectInstance * Obj, int3 Tile) :
  148. quest (Quest), obj (Obj), tile (Tile){};
  149. QuestInfo (const QuestInfo &qi) : quest(qi.quest), obj(qi.obj), tile(qi.tile)
  150. {};
  151. const QuestInfo& operator= (const QuestInfo &qi)
  152. {
  153. quest = qi.quest;
  154. obj = qi.obj;
  155. tile = qi.tile;
  156. return *this;
  157. }
  158. bool operator== (const QuestInfo & qi) const
  159. {
  160. return (quest == qi.quest && obj == qi.obj);
  161. }
  162. //std::vector<std::string> > texts //allow additional info for quest log?
  163. template <typename Handler> void serialize(Handler &h, const int version)
  164. {
  165. h & quest;
  166. h & obj;
  167. h & tile;
  168. }
  169. };