2023-08-22 18:45:13 +03:00
|
|
|
/*
|
|
|
|
* TurnOrderProcessor.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../../lib/GameConstants.h"
|
|
|
|
|
|
|
|
class CGameHandler;
|
|
|
|
|
|
|
|
class TurnOrderProcessor : boost::noncopyable
|
|
|
|
{
|
|
|
|
CGameHandler * gameHandler;
|
|
|
|
|
2023-09-20 13:53:06 +03:00
|
|
|
struct PlayerPair
|
|
|
|
{
|
|
|
|
PlayerColor a;
|
|
|
|
PlayerColor b;
|
|
|
|
|
|
|
|
bool operator == (const PlayerPair & other) const
|
|
|
|
{
|
|
|
|
return (a == other.a && b == other.b) || (a == other.b && b == other.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Handler>
|
2024-01-20 20:34:51 +02:00
|
|
|
void serialize(Handler & h)
|
2023-09-20 13:53:06 +03:00
|
|
|
{
|
|
|
|
h & a;
|
|
|
|
h & b;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<PlayerPair> blockedContacts;
|
|
|
|
|
2023-08-22 18:45:13 +03:00
|
|
|
std::set<PlayerColor> awaitingPlayers;
|
|
|
|
std::set<PlayerColor> actingPlayers;
|
|
|
|
std::set<PlayerColor> actedPlayers;
|
|
|
|
|
2024-05-19 17:12:29 +00:00
|
|
|
std::optional<int> simturnsMinDurationDays;
|
|
|
|
std::optional<int> simturnsMaxDurationDays;
|
|
|
|
|
2023-09-18 22:09:16 +03:00
|
|
|
/// Returns date on which simturns must end unconditionally
|
2023-09-19 19:46:27 +03:00
|
|
|
int simturnsTurnsMaxLimit() const;
|
|
|
|
|
|
|
|
/// Returns date until which simturns must play unconditionally
|
|
|
|
int simturnsTurnsMinLimit() const;
|
2023-09-18 22:09:16 +03:00
|
|
|
|
|
|
|
/// Returns true if players are close enough to each other for their heroes to meet on this turn
|
|
|
|
bool playersInContact(PlayerColor left, PlayerColor right) const;
|
|
|
|
|
2023-08-22 18:45:13 +03:00
|
|
|
/// Returns true if waiting player can act alongside with currently acting player
|
2023-09-20 13:53:06 +03:00
|
|
|
bool computeCanActSimultaneously(PlayerColor active, PlayerColor waiting) const;
|
2023-08-22 18:45:13 +03:00
|
|
|
|
|
|
|
/// Returns true if left player must act before right player
|
|
|
|
bool mustActBefore(PlayerColor left, PlayerColor right) const;
|
|
|
|
|
|
|
|
/// Returns true if player is ready to start turn
|
|
|
|
bool canStartTurn(PlayerColor which) const;
|
|
|
|
|
|
|
|
/// Starts turn for all players that can start turn
|
|
|
|
void tryStartTurnsForPlayers();
|
|
|
|
|
2023-12-23 18:11:25 +02:00
|
|
|
void updateAndNotifyContactStatus();
|
|
|
|
|
|
|
|
std::vector<PlayerPair> computeContactStatus() const;
|
2023-09-20 13:53:06 +03:00
|
|
|
|
2023-08-22 18:45:13 +03:00
|
|
|
void doStartNewDay();
|
|
|
|
void doStartPlayerTurn(PlayerColor which);
|
2023-08-24 13:36:35 +03:00
|
|
|
void doEndPlayerTurn(PlayerColor which);
|
2023-08-22 18:45:13 +03:00
|
|
|
|
2023-08-24 23:34:28 +03:00
|
|
|
bool isPlayerAwaitsTurn(PlayerColor which) const;
|
|
|
|
bool isPlayerAwaitsNewDay(PlayerColor which) const;
|
2023-08-24 21:35:01 +03:00
|
|
|
|
2023-08-22 18:45:13 +03:00
|
|
|
public:
|
|
|
|
TurnOrderProcessor(CGameHandler * owner);
|
|
|
|
|
2023-09-20 00:05:11 +03:00
|
|
|
bool isContactAllowed(PlayerColor left, PlayerColor right) const;
|
2024-04-27 12:36:24 +03:00
|
|
|
bool isPlayerMakingTurn(PlayerColor which) const;
|
2023-09-20 00:05:11 +03:00
|
|
|
|
2023-08-22 18:45:13 +03:00
|
|
|
/// Add new player to handle (e.g. on game start)
|
|
|
|
void addPlayer(PlayerColor which);
|
|
|
|
|
|
|
|
/// NetPack call-in
|
2023-08-24 13:36:35 +03:00
|
|
|
bool onPlayerEndsTurn(PlayerColor which);
|
|
|
|
|
2023-08-24 21:35:01 +03:00
|
|
|
/// Ends player turn and removes this player from turn order
|
2023-08-24 13:36:35 +03:00
|
|
|
void onPlayerEndsGame(PlayerColor which);
|
2023-08-22 18:45:13 +03:00
|
|
|
|
2023-09-17 01:13:58 +03:00
|
|
|
/// Start game (or resume from save) and send PlayerStartsTurn pack to player(s)
|
2023-08-22 18:45:13 +03:00
|
|
|
void onGameStarted();
|
|
|
|
|
2024-05-19 17:12:29 +00:00
|
|
|
/// Permanently override duration of contactless simultaneous turns
|
|
|
|
void setMinSimturnsDuration(int days);
|
|
|
|
|
|
|
|
/// Permanently override duration of simultaneous turns with contact detection
|
|
|
|
void setMaxSimturnsDuration(int days);
|
|
|
|
|
2023-08-24 21:35:01 +03:00
|
|
|
template<typename Handler>
|
2024-01-20 20:34:51 +02:00
|
|
|
void serialize(Handler & h)
|
2023-08-22 18:45:13 +03:00
|
|
|
{
|
2023-09-20 13:53:06 +03:00
|
|
|
h & blockedContacts;
|
2023-08-22 18:45:13 +03:00
|
|
|
h & awaitingPlayers;
|
|
|
|
h & actingPlayers;
|
|
|
|
h & actedPlayers;
|
2024-05-19 17:12:29 +00:00
|
|
|
|
|
|
|
if (h.version >= Handler::Version::VOTING_SIMTURNS)
|
|
|
|
{
|
|
|
|
h & simturnsMinDurationDays;
|
|
|
|
h & simturnsMaxDurationDays;
|
|
|
|
}
|
2024-05-29 20:08:32 +00:00
|
|
|
else if (!h.saving)
|
|
|
|
{
|
|
|
|
simturnsMinDurationDays.reset();
|
|
|
|
simturnsMaxDurationDays.reset();
|
|
|
|
}
|
2023-08-22 18:45:13 +03:00
|
|
|
}
|
|
|
|
};
|