CGameStateFwd.h 4.4 KB

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