BattleResultProcessor.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. ObjectInstanceID winnerId;
  42. ObjectInstanceID loserId;
  43. PlayerColor victor;
  44. PlayerColor loser;
  45. BattleSide winnerSide;
  46. int remainingBattleQueriesCount;
  47. template <typename Handler> void serialize(Handler &h)
  48. {
  49. h & winnerId;
  50. h & loserId;
  51. h & victor;
  52. h & loser;
  53. h & winnerSide;
  54. h & remainingBattleQueriesCount;
  55. }
  56. };
  57. class BattleResultProcessor : boost::noncopyable
  58. {
  59. CGameHandler * gameHandler;
  60. std::map<BattleID, std::unique_ptr<BattleResult>> battleResults;
  61. std::map<BattleID, std::unique_ptr<FinishingBattleHelper>> finishingBattles;
  62. public:
  63. explicit BattleResultProcessor(CGameHandler * gameHandler);
  64. bool battleIsEnding(const CBattleInfoCallback & battle) const;
  65. void setBattleResult(const CBattleInfoCallback & battle, EBattleResult resultType, BattleSide victoriusSide);
  66. void endBattle(const CBattleInfoCallback & battle); //ends battle
  67. void endBattleConfirm(const CBattleInfoCallback & battle);
  68. void battleFinalize(const BattleID & battleID, const BattleResult & result);
  69. };