TurnOrderProcessor.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. struct PlayerPair
  17. {
  18. PlayerColor a;
  19. PlayerColor b;
  20. bool operator == (const PlayerPair & other) const
  21. {
  22. return (a == other.a && b == other.b) || (a == other.b && b == other.a);
  23. }
  24. template<typename Handler>
  25. void serialize(Handler & h, const int version)
  26. {
  27. h & a;
  28. h & b;
  29. }
  30. };
  31. std::vector<PlayerPair> blockedContacts;
  32. std::set<PlayerColor> awaitingPlayers;
  33. std::set<PlayerColor> actingPlayers;
  34. std::set<PlayerColor> actedPlayers;
  35. /// Returns date on which simturns must end unconditionally
  36. int simturnsTurnsMaxLimit() const;
  37. /// Returns date until which simturns must play unconditionally
  38. int simturnsTurnsMinLimit() const;
  39. /// Returns true if players are close enough to each other for their heroes to meet on this turn
  40. bool playersInContact(PlayerColor left, PlayerColor right) const;
  41. /// Returns true if waiting player can act alongside with currently acting player
  42. bool computeCanActSimultaneously(PlayerColor active, PlayerColor waiting) const;
  43. /// Returns true if left player must act before right player
  44. bool mustActBefore(PlayerColor left, PlayerColor right) const;
  45. /// Returns true if player is ready to start turn
  46. bool canStartTurn(PlayerColor which) const;
  47. /// Starts turn for all players that can start turn
  48. void tryStartTurnsForPlayers();
  49. void updateAndNotifyContactStatus();
  50. std::vector<PlayerPair> computeContactStatus() const;
  51. void doStartNewDay();
  52. void doStartPlayerTurn(PlayerColor which);
  53. void doEndPlayerTurn(PlayerColor which);
  54. bool isPlayerAwaitsTurn(PlayerColor which) const;
  55. bool isPlayerMakingTurn(PlayerColor which) const;
  56. bool isPlayerAwaitsNewDay(PlayerColor which) const;
  57. public:
  58. TurnOrderProcessor(CGameHandler * owner);
  59. bool isContactAllowed(PlayerColor left, PlayerColor right) const;
  60. /// Add new player to handle (e.g. on game start)
  61. void addPlayer(PlayerColor which);
  62. /// NetPack call-in
  63. bool onPlayerEndsTurn(PlayerColor which);
  64. /// Ends player turn and removes this player from turn order
  65. void onPlayerEndsGame(PlayerColor which);
  66. /// Start game (or resume from save) and send PlayerStartsTurn pack to player(s)
  67. void onGameStarted();
  68. template<typename Handler>
  69. void serialize(Handler & h, const int version)
  70. {
  71. h & blockedContacts;
  72. h & awaitingPlayers;
  73. h & actingPlayers;
  74. h & actedPlayers;
  75. }
  76. };