TurnTimerHandler.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * TurnTimerHandler.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/TurnTimerInfo.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class CStack;
  14. class PlayerColor;
  15. class BattleID;
  16. VCMI_LIB_NAMESPACE_END
  17. class CGameHandler;
  18. class TurnTimerHandler
  19. {
  20. CGameHandler & gameHandler;
  21. static constexpr int turnTimePropagateFrequency = 1000;
  22. std::map<PlayerColor, TurnTimerInfo> timers;
  23. std::map<PlayerColor, int> lastUpdate;
  24. std::map<PlayerColor, bool> endTurnAllowed;
  25. void onPlayerMakingTurn(PlayerColor player, int waitTime);
  26. void onBattleLoop(const BattleID & battleID, int waitTime);
  27. bool timerCountDown(int & timerToApply, int initialTimer, PlayerColor player, int waitTime);
  28. bool isPvpBattle(const BattleID & battleID) const;
  29. void sendTimerUpdate(PlayerColor player);
  30. public:
  31. TurnTimerHandler(CGameHandler &);
  32. void onGameplayStart(PlayerColor player);
  33. void onPlayerGetTurn(PlayerColor player);
  34. void onBattleStart(const BattleID & battle);
  35. void onBattleNextStack(const BattleID & battle, const CStack & stack);
  36. void onBattleEnd(const BattleID & battleID);
  37. void update(int waitTimeMs);
  38. void setTimerEnabled(PlayerColor player, bool enabled);
  39. void setEndTurnAllowed(PlayerColor player, bool enabled);
  40. void prolongTimers(int durationMs);
  41. template<typename Handler>
  42. void serialize(Handler & h)
  43. {
  44. h & timers;
  45. h & endTurnAllowed;
  46. }
  47. };