TurnOrderProcessor.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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)
  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. std::optional<int> simturnsMinDurationDays;
  36. std::optional<int> simturnsMaxDurationDays;
  37. /// Returns date on which simturns must end unconditionally
  38. int simturnsTurnsMaxLimit() const;
  39. /// Returns date until which simturns must play unconditionally
  40. int simturnsTurnsMinLimit() const;
  41. /// Returns true if players are close enough to each other for their heroes to meet on this turn
  42. bool playersInContact(PlayerColor left, PlayerColor right) const;
  43. /// Returns true if waiting player can act alongside with currently acting player
  44. bool computeCanActSimultaneously(PlayerColor active, PlayerColor waiting) const;
  45. /// Returns true if left player must act before right player
  46. bool mustActBefore(PlayerColor left, PlayerColor right) const;
  47. /// Returns true if player is ready to start turn
  48. bool canStartTurn(PlayerColor which) const;
  49. /// Starts turn for all players that can start turn
  50. void tryStartTurnsForPlayers();
  51. void updateAndNotifyContactStatus();
  52. std::vector<PlayerPair> computeContactStatus() const;
  53. void doStartNewDay();
  54. void doStartPlayerTurn(PlayerColor which);
  55. void doEndPlayerTurn(PlayerColor which);
  56. bool isPlayerAwaitsTurn(PlayerColor which) const;
  57. bool isPlayerAwaitsNewDay(PlayerColor which) const;
  58. public:
  59. TurnOrderProcessor(CGameHandler * owner);
  60. bool isContactAllowed(PlayerColor left, PlayerColor right) const;
  61. bool isPlayerMakingTurn(PlayerColor which) const;
  62. /// Add new player to handle (e.g. on game start)
  63. void addPlayer(PlayerColor which);
  64. /// NetPack call-in
  65. bool onPlayerEndsTurn(PlayerColor which);
  66. /// Ends player turn and removes this player from turn order
  67. void onPlayerEndsGame(PlayerColor which);
  68. /// Start game (or resume from save) and send PlayerStartsTurn pack to player(s)
  69. void onGameStarted();
  70. /// Permanently override duration of contactless simultaneous turns
  71. void setMinSimturnsDuration(int days);
  72. /// Permanently override duration of simultaneous turns with contact detection
  73. void setMaxSimturnsDuration(int days);
  74. template<typename Handler>
  75. void serialize(Handler & h)
  76. {
  77. h & blockedContacts;
  78. h & awaitingPlayers;
  79. h & actingPlayers;
  80. h & actedPlayers;
  81. if (h.version >= Handler::Version::VOTING_SIMTURNS)
  82. {
  83. h & simturnsMinDurationDays;
  84. h & simturnsMaxDurationDays;
  85. }
  86. }
  87. };