BattleResultProcessor.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * BattleProcessor.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 "../../lib/GameConstants.h"
  12. #include "../../lib/networkPacks/StackLocation.h"
  13. #include "../../lib/networkPacks/ArtifactLocation.h"
  14. #include "../../lib/battle/BattleSide.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. struct SideInBattle;
  17. struct BattleResult;
  18. class CBattleInfoCallback;
  19. class CGHeroInstance;
  20. VCMI_LIB_NAMESPACE_END
  21. class CBattleQuery;
  22. class BattleProcessor;
  23. class CGameHandler;
  24. struct CasualtiesAfterBattle
  25. {
  26. using TStackAndItsNewCount = std::pair<StackLocation, int>;
  27. using TSummoned = std::map<CreatureID, TQuantity>;
  28. const CArmedInstance * army;
  29. std::vector<TStackAndItsNewCount> newStackCounts;
  30. std::vector<ArtifactLocation> removedWarMachines;
  31. TSummoned summoned;
  32. ObjectInstanceID heroWithDeadCommander; //TODO: unify stack locations
  33. CasualtiesAfterBattle(const CBattleInfoCallback & battle, BattleSide sideInBattle);
  34. void updateArmy(CGameHandler * gh);
  35. };
  36. struct FinishingBattleHelper
  37. {
  38. FinishingBattleHelper(const CBattleInfoCallback & battle, const BattleResult & result, int RemainingBattleQueriesCount);
  39. inline bool isDraw() const {return winnerSide == BattleSide::NONE;}
  40. const CGHeroInstance *winnerHero, *loserHero;
  41. PlayerColor victor, loser;
  42. BattleSide winnerSide;
  43. int remainingBattleQueriesCount;
  44. template <typename Handler> void serialize(Handler &h)
  45. {
  46. h & winnerHero;
  47. h & loserHero;
  48. h & victor;
  49. h & loser;
  50. h & winnerSide;
  51. h & remainingBattleQueriesCount;
  52. }
  53. };
  54. class BattleResultProcessor : boost::noncopyable
  55. {
  56. // BattleProcessor * owner;
  57. CGameHandler * gameHandler;
  58. std::map<BattleID, std::unique_ptr<BattleResult>> battleResults;
  59. std::map<BattleID, std::unique_ptr<FinishingBattleHelper>> finishingBattles;
  60. public:
  61. explicit BattleResultProcessor(BattleProcessor * owner, CGameHandler * newGameHandler);
  62. bool battleIsEnding(const CBattleInfoCallback & battle) const;
  63. void setBattleResult(const CBattleInfoCallback & battle, EBattleResult resultType, BattleSide victoriusSide);
  64. void endBattle(const CBattleInfoCallback & battle); //ends battle
  65. void endBattleConfirm(const CBattleInfoCallback & battle);
  66. void battleAfterLevelUp(const BattleID & battleID, const BattleResult & result);
  67. };