BattleResultProcessor.h 2.5 KB

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