2023-08-14 01:20:27 +02:00
|
|
|
/*
|
|
|
|
* TurnTimerHandler.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
|
|
|
|
|
2023-08-30 00:17:29 +02:00
|
|
|
#include "../lib/TurnTimerInfo.h"
|
|
|
|
|
2023-08-14 01:20:27 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2023-08-14 21:31:44 +02:00
|
|
|
class CStack;
|
2023-08-14 01:20:27 +02:00
|
|
|
class PlayerColor;
|
2023-08-25 17:23:15 +02:00
|
|
|
class BattleID;
|
2023-08-14 01:20:27 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
|
|
|
class CGameHandler;
|
|
|
|
|
|
|
|
class TurnTimerHandler
|
2023-08-30 01:11:46 +02:00
|
|
|
{
|
2023-08-14 01:20:27 +02:00
|
|
|
CGameHandler & gameHandler;
|
2024-04-26 12:16:02 +02:00
|
|
|
static constexpr int turnTimePropagateFrequency = 1000;
|
2023-08-30 01:11:46 +02:00
|
|
|
std::map<PlayerColor, TurnTimerInfo> timers;
|
|
|
|
std::map<PlayerColor, int> lastUpdate;
|
2023-09-02 01:17:32 +02:00
|
|
|
std::map<PlayerColor, bool> endTurnAllowed;
|
2023-08-14 01:20:27 +02:00
|
|
|
|
2023-08-29 13:48:42 +02:00
|
|
|
void onPlayerMakingTurn(PlayerColor player, int waitTime);
|
2023-08-25 17:23:15 +02:00
|
|
|
void onBattleLoop(const BattleID & battleID, int waitTime);
|
2023-08-29 13:48:42 +02:00
|
|
|
|
2023-08-30 00:17:29 +02:00
|
|
|
bool timerCountDown(int & timerToApply, int initialTimer, PlayerColor player, int waitTime);
|
2023-08-25 17:23:15 +02:00
|
|
|
bool isPvpBattle(const BattleID & battleID) const;
|
2023-08-30 00:17:29 +02:00
|
|
|
void sendTimerUpdate(PlayerColor player);
|
|
|
|
|
2023-08-14 01:20:27 +02:00
|
|
|
public:
|
|
|
|
TurnTimerHandler(CGameHandler &);
|
|
|
|
|
2023-08-26 03:39:29 +02:00
|
|
|
void onGameplayStart(PlayerColor player);
|
|
|
|
void onPlayerGetTurn(PlayerColor player);
|
2023-08-25 17:23:15 +02:00
|
|
|
void onBattleStart(const BattleID & battle);
|
|
|
|
void onBattleNextStack(const BattleID & battle, const CStack & stack);
|
|
|
|
void onBattleEnd(const BattleID & battleID);
|
2024-05-19 19:12:29 +02:00
|
|
|
void update(int waitTimeMs);
|
2023-08-28 02:40:35 +02:00
|
|
|
void setTimerEnabled(PlayerColor player, bool enabled);
|
2023-09-02 01:17:32 +02:00
|
|
|
void setEndTurnAllowed(PlayerColor player, bool enabled);
|
2024-04-26 12:16:02 +02:00
|
|
|
|
2024-05-19 19:12:29 +02:00
|
|
|
void prolongTimers(int durationMs);
|
|
|
|
|
2024-04-26 12:16:02 +02:00
|
|
|
template<typename Handler>
|
|
|
|
void serialize(Handler & h)
|
|
|
|
{
|
|
|
|
h & timers;
|
|
|
|
h & endTurnAllowed;
|
|
|
|
}
|
2023-08-14 01:20:27 +02:00
|
|
|
};
|