TurnOrderProcessor.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * TurnOrderProcessor.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. class CGameHandler;
  13. class TurnOrderProcessor : boost::noncopyable
  14. {
  15. CGameHandler * gameHandler;
  16. std::set<PlayerColor> awaitingPlayers;
  17. std::set<PlayerColor> actingPlayers;
  18. std::set<PlayerColor> actedPlayers;
  19. /// Returns date on which simturns must end unconditionally
  20. int simturnsTurnsMaxLimit() const;
  21. /// Returns date until which simturns must play unconditionally
  22. int simturnsTurnsMinLimit() const;
  23. /// Returns true if players are close enough to each other for their heroes to meet on this turn
  24. bool playersInContact(PlayerColor left, PlayerColor right) const;
  25. /// Returns true if waiting player can act alongside with currently acting player
  26. bool canActSimultaneously(PlayerColor active, PlayerColor waiting) const;
  27. /// Returns true if left player must act before right player
  28. bool mustActBefore(PlayerColor left, PlayerColor right) const;
  29. /// Returns true if player is ready to start turn
  30. bool canStartTurn(PlayerColor which) const;
  31. /// Starts turn for all players that can start turn
  32. void tryStartTurnsForPlayers();
  33. void doStartNewDay();
  34. void doStartPlayerTurn(PlayerColor which);
  35. void doEndPlayerTurn(PlayerColor which);
  36. bool isPlayerAwaitsTurn(PlayerColor which) const;
  37. bool isPlayerMakingTurn(PlayerColor which) const;
  38. bool isPlayerAwaitsNewDay(PlayerColor which) const;
  39. public:
  40. TurnOrderProcessor(CGameHandler * owner);
  41. /// Add new player to handle (e.g. on game start)
  42. void addPlayer(PlayerColor which);
  43. /// NetPack call-in
  44. bool onPlayerEndsTurn(PlayerColor which);
  45. /// Ends player turn and removes this player from turn order
  46. void onPlayerEndsGame(PlayerColor which);
  47. /// Start game (or resume from save) and send PlayerStartsTurn pack to player(s)
  48. void onGameStarted();
  49. template<typename Handler>
  50. void serialize(Handler & h, const int version)
  51. {
  52. h & awaitingPlayers;
  53. h & actingPlayers;
  54. h & actedPlayers;
  55. }
  56. };