TurnOrderProcessor.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 true if waiting player can act alongside with currently acting player
  20. bool canActSimultaneously(PlayerColor active, PlayerColor waiting) const;
  21. /// Returns true if left player must act before right player
  22. bool mustActBefore(PlayerColor left, PlayerColor right) const;
  23. /// Returns true if player is ready to start turn
  24. bool canStartTurn(PlayerColor which) const;
  25. /// Starts turn for all players that can start turn
  26. void tryStartTurnsForPlayers();
  27. void doStartNewDay();
  28. void doStartPlayerTurn(PlayerColor which);
  29. void doEndPlayerTurn(PlayerColor which);
  30. bool isPlayerAwaitsTurn(PlayerColor which) const;
  31. bool isPlayerMakingTurn(PlayerColor which) const;
  32. bool isPlayerAwaitsNewDay(PlayerColor which) const;
  33. public:
  34. TurnOrderProcessor(CGameHandler * owner);
  35. /// Add new player to handle (e.g. on game start)
  36. void addPlayer(PlayerColor which);
  37. /// NetPack call-in
  38. bool onPlayerEndsTurn(PlayerColor which);
  39. /// Ends player turn and removes this player from turn order
  40. void onPlayerEndsGame(PlayerColor which);
  41. /// Start game (or resume from save) and send YourTurn pack to player(s)
  42. void onGameStarted();
  43. template<typename Handler>
  44. void serialize(Handler & h, const int version)
  45. {
  46. h & awaitingPlayers;
  47. h & actingPlayers;
  48. h & actedPlayers;
  49. }
  50. };