CGameStateFwd.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #pragma once
  2. /*
  3. * CGameStateFwd.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. class CQuest;
  12. class CGObjectInstance;
  13. class DLL_LINKAGE EVictoryLossCheckResult
  14. {
  15. public:
  16. static EVictoryLossCheckResult victory(std::string toSelf, std::string toOthers)
  17. {
  18. return EVictoryLossCheckResult(VICTORY, toSelf, toOthers);
  19. }
  20. static EVictoryLossCheckResult defeat(std::string toSelf, std::string toOthers)
  21. {
  22. return EVictoryLossCheckResult(DEFEAT, toSelf, toOthers);
  23. }
  24. EVictoryLossCheckResult():
  25. intValue(0)
  26. {
  27. }
  28. bool operator==(EVictoryLossCheckResult const & other) const
  29. {
  30. return intValue == other.intValue;
  31. }
  32. bool operator!=(EVictoryLossCheckResult const & other) const
  33. {
  34. return intValue != other.intValue;
  35. }
  36. bool victory() const
  37. {
  38. return intValue == VICTORY;
  39. }
  40. bool loss() const
  41. {
  42. return intValue == DEFEAT;
  43. }
  44. EVictoryLossCheckResult invert()
  45. {
  46. return EVictoryLossCheckResult(-intValue, messageToOthers, messageToSelf);
  47. }
  48. std::string messageToSelf;
  49. std::string messageToOthers;
  50. template <typename Handler> void serialize(Handler &h, const int version)
  51. {
  52. h & intValue & messageToSelf & messageToOthers;
  53. }
  54. private:
  55. enum EResult
  56. {
  57. DEFEAT = -1,
  58. INGAME = 0,
  59. VICTORY= +1
  60. };
  61. EVictoryLossCheckResult(si32 intValue, std::string toSelf, std::string toOthers):
  62. messageToSelf(toSelf),
  63. messageToOthers(toOthers),
  64. intValue(intValue)
  65. {
  66. }
  67. si32 intValue; // uses EResult
  68. };
  69. /*static std::ostream & operator<<(std::ostream & os, const EVictoryLossCheckResult & victoryLossCheckResult)
  70. {
  71. os << victoryLossCheckResult.messageToSelf;
  72. return os;
  73. }*/
  74. struct DLL_LINKAGE QuestInfo //universal interface for human and AI
  75. {
  76. const CQuest * quest;
  77. const CGObjectInstance * obj; //related object, most likely Seer Hut
  78. int3 tile;
  79. QuestInfo(){};
  80. QuestInfo (const CQuest * Quest, const CGObjectInstance * Obj, int3 Tile) :
  81. quest (Quest), obj (Obj), tile (Tile){};
  82. //FIXME: assignment operator should return QuestInfo &
  83. bool operator= (const QuestInfo &qi)
  84. {
  85. quest = qi.quest;
  86. obj = qi.obj;
  87. tile = qi.tile;
  88. return true;
  89. }
  90. bool operator== (const QuestInfo & qi) const
  91. {
  92. return (quest == qi.quest && obj == qi.obj);
  93. }
  94. //std::vector<std::string> > texts //allow additional info for quest log?
  95. template <typename Handler> void serialize(Handler &h, const int version)
  96. {
  97. h & quest & obj & tile;
  98. }
  99. };
  100. struct DLL_LINKAGE CGPathNode
  101. {
  102. enum EAccessibility
  103. {
  104. NOT_SET = 0,
  105. ACCESSIBLE = 1, //tile can be entered and passed
  106. VISITABLE, //tile can be entered as the last tile in path
  107. BLOCKVIS, //visitable from neighbouring tile but not passable
  108. BLOCKED //tile can't be entered nor visited
  109. };
  110. EAccessibility accessible;
  111. ui8 land;
  112. ui8 turns; //how many turns we have to wait before reachng the tile - 0 means current turn
  113. ui32 moveRemains; //remaining tiles after hero reaches the tile
  114. CGPathNode * theNodeBefore;
  115. int3 coord; //coordinates
  116. CGPathNode();
  117. bool reachable() const;
  118. };
  119. struct DLL_LINKAGE CGPath
  120. {
  121. std::vector<CGPathNode> nodes; //just get node by node
  122. int3 startPos() const; // start point
  123. int3 endPos() const; //destination point
  124. void convert(ui8 mode); //mode=0 -> from 'manifest' to 'object'
  125. };
  126. struct DLL_LINKAGE CPathsInfo
  127. {
  128. mutable boost::mutex pathMx;
  129. const CGHeroInstance *hero;
  130. int3 hpos;
  131. int3 sizes;
  132. CGPathNode ***nodes; //[w][h][level]
  133. const CGPathNode * getPathInfo( int3 tile ) const;
  134. bool getPath(const int3 &dst, CGPath &out) const;
  135. int getDistance( int3 tile ) const;
  136. CPathsInfo(const int3 &Sizes);
  137. ~CPathsInfo();
  138. };