BattleResultProcessor.h 2.2 KB

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