2023-08-22 17:45:13 +02: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 12:53:06 +02: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 12:53:06 +02:00
|
|
|
{
|
|
|
|
h & a;
|
|
|
|
h & b;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<PlayerPair> blockedContacts;
|
|
|
|
|
2023-08-22 17:45:13 +02:00
|
|
|
std::set<PlayerColor> awaitingPlayers;
|
|
|
|
std::set<PlayerColor> actingPlayers;
|
|
|
|
std::set<PlayerColor> actedPlayers;
|
|
|
|
|
2023-09-18 21:09:16 +02:00
|
|
|
/// Returns date on which simturns must end unconditionally
|
2023-09-19 18:46:27 +02:00
|
|
|
int simturnsTurnsMaxLimit() const;
|
|
|
|
|
|
|
|
/// Returns date until which simturns must play unconditionally
|
|
|
|
int simturnsTurnsMinLimit() const;
|
2023-09-18 21:09:16 +02: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 17:45:13 +02:00
|
|
|
/// Returns true if waiting player can act alongside with currently acting player
|
2023-09-20 12:53:06 +02:00
|
|
|
bool computeCanActSimultaneously(PlayerColor active, PlayerColor waiting) const;
|
2023-08-22 17:45:13 +02: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 12:53:06 +02:00
|
|
|
|
2023-08-22 17:45:13 +02:00
|
|
|
void doStartNewDay();
|
|
|
|
void doStartPlayerTurn(PlayerColor which);
|
2023-08-24 12:36:35 +02:00
|
|
|
void doEndPlayerTurn(PlayerColor which);
|
2023-08-22 17:45:13 +02:00
|
|
|
|
2023-08-24 22:34:28 +02:00
|
|
|
bool isPlayerAwaitsTurn(PlayerColor which) const;
|
|
|
|
bool isPlayerAwaitsNewDay(PlayerColor which) const;
|
2023-08-24 20:35:01 +02:00
|
|
|
|
2023-08-22 17:45:13 +02:00
|
|
|
public:
|
|
|
|
TurnOrderProcessor(CGameHandler * owner);
|
|
|
|
|
2023-09-19 23:05:11 +02:00
|
|
|
bool isContactAllowed(PlayerColor left, PlayerColor right) const;
|
2024-04-27 11:36:24 +02:00
|
|
|
bool isPlayerMakingTurn(PlayerColor which) const;
|
2023-09-19 23:05:11 +02:00
|
|
|
|
2023-08-22 17:45:13 +02:00
|
|
|
/// Add new player to handle (e.g. on game start)
|
|
|
|
void addPlayer(PlayerColor which);
|
|
|
|
|
|
|
|
/// NetPack call-in
|
2023-08-24 12:36:35 +02:00
|
|
|
bool onPlayerEndsTurn(PlayerColor which);
|
|
|
|
|
2023-08-24 20:35:01 +02:00
|
|
|
/// Ends player turn and removes this player from turn order
|
2023-08-24 12:36:35 +02:00
|
|
|
void onPlayerEndsGame(PlayerColor which);
|
2023-08-22 17:45:13 +02:00
|
|
|
|
2023-09-17 00:13:58 +02:00
|
|
|
/// Start game (or resume from save) and send PlayerStartsTurn pack to player(s)
|
2023-08-22 17:45:13 +02:00
|
|
|
void onGameStarted();
|
|
|
|
|
2023-08-24 20:35:01 +02:00
|
|
|
template<typename Handler>
|
2024-01-20 20:34:51 +02:00
|
|
|
void serialize(Handler & h)
|
2023-08-22 17:45:13 +02:00
|
|
|
{
|
2023-09-20 12:53:06 +02:00
|
|
|
h & blockedContacts;
|
2023-08-22 17:45:13 +02:00
|
|
|
h & awaitingPlayers;
|
|
|
|
h & actingPlayers;
|
|
|
|
h & actedPlayers;
|
|
|
|
}
|
|
|
|
};
|