CGameStateFwd.h 4.3 KB

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