BattleResultProcessor.h 2.4 KB

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