mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
TurnTimerInfo
This commit is contained in:
parent
f01973a4f0
commit
3c9c302fd2
@ -474,7 +474,7 @@ void CServerHandler::setTurnLength(int npos) const
|
||||
{
|
||||
vstd::amin(npos, GameConstants::POSSIBLE_TURNTIME.size() - 1);
|
||||
LobbySetTurnTime lstt;
|
||||
lstt.turnTime = GameConstants::POSSIBLE_TURNTIME[npos];
|
||||
lstt.turnTimerInfo.turnTimer = GameConstants::POSSIBLE_TURNTIME[npos] * 60 * 1000;
|
||||
sendLobbyPack(lstt);
|
||||
}
|
||||
|
||||
|
@ -866,7 +866,7 @@ void ApplyClientNetPackVisitor::visitYourTurn(YourTurn & pack)
|
||||
|
||||
void ApplyClientNetPackVisitor::visitTurnTimeUpdate(TurnTimeUpdate & pack)
|
||||
{
|
||||
logNetwork->debug("Server sets %d turn time for %s", pack.turnTime, pack.player.getStr());
|
||||
logNetwork->debug("Server sets turn timer {turn: %d, base: %d, battle: %d, creature: %d} for %s", pack.turnTimer.turnTimer, pack.turnTimer.baseTimer, pack.turnTimer.battleTimer, pack.turnTimer.creatureTimer, pack.player.getStr());
|
||||
}
|
||||
|
||||
void ApplyClientNetPackVisitor::visitPlayerMessageClient(PlayerMessageClient & pack)
|
||||
|
@ -63,7 +63,7 @@ AdventureMapInterface::AdventureMapInterface():
|
||||
shortcuts->setState(EAdventureState::MAKING_TURN);
|
||||
widget->getMapView()->onViewMapActivated();
|
||||
|
||||
if(LOCPLINT->cb->getStartInfo()->turnTime > 0)
|
||||
if(LOCPLINT->cb->getStartInfo()->turnTimerInfo.isEnabled())
|
||||
watches = std::make_shared<TurnTimerWidget>();
|
||||
|
||||
addUsedEvents(KEYBOARD | TIME);
|
||||
|
@ -77,11 +77,11 @@ void TurnTimerWidget::tick(uint32_t msPassed)
|
||||
auto player = LOCPLINT->cb->getCurrentPlayer();
|
||||
auto time = LOCPLINT->cb->getPlayerTurnTime(player);
|
||||
cachedTurnTime -= msPassed;
|
||||
if(time / 1000 != lastTurnTime / 1000)
|
||||
if(time.turnTimer / 1000 != lastTurnTime / 1000)
|
||||
{
|
||||
//do not update timer on this tick
|
||||
lastTurnTime = time;
|
||||
cachedTurnTime = time;
|
||||
lastTurnTime = time.turnTimer;
|
||||
cachedTurnTime = time.turnTimer;
|
||||
}
|
||||
else setTime(cachedTurnTime);
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ void OptionsTab::recreate()
|
||||
|
||||
if(sliderTurnDuration)
|
||||
{
|
||||
sliderTurnDuration->scrollTo(vstd::find_pos(GameConstants::POSSIBLE_TURNTIME, SEL->getStartInfo()->turnTime));
|
||||
sliderTurnDuration->scrollTo(vstd::find_pos(GameConstants::POSSIBLE_TURNTIME, SEL->getStartInfo()->turnTimerInfo.turnTimer / (60 * 1000)));
|
||||
labelTurnDurationValue->setText(CGI->generaltexth->turnDurations[sliderTurnDuration->getValue()]);
|
||||
}
|
||||
}
|
||||
|
@ -264,6 +264,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
|
||||
${MAIN_LIB_DIR}/ScriptHandler.cpp
|
||||
${MAIN_LIB_DIR}/TerrainHandler.cpp
|
||||
${MAIN_LIB_DIR}/TextOperations.cpp
|
||||
${MAIN_LIB_DIR}/TurnTimerInfo.cpp
|
||||
${MAIN_LIB_DIR}/VCMIDirs.cpp
|
||||
${MAIN_LIB_DIR}/VCMI_Lib.cpp
|
||||
)
|
||||
@ -621,6 +622,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
|
||||
${MAIN_LIB_DIR}/StringConstants.h
|
||||
${MAIN_LIB_DIR}/TerrainHandler.h
|
||||
${MAIN_LIB_DIR}/TextOperations.h
|
||||
${MAIN_LIB_DIR}/TurnTimerInfo.h
|
||||
${MAIN_LIB_DIR}/UnlockGuard.h
|
||||
${MAIN_LIB_DIR}/VCMIDirs.h
|
||||
${MAIN_LIB_DIR}/vcmi_endian.h
|
||||
|
@ -99,20 +99,20 @@ const PlayerState * CGameInfoCallback::getPlayerState(PlayerColor color, bool ve
|
||||
}
|
||||
}
|
||||
|
||||
int CGameInfoCallback::getPlayerTurnTime(PlayerColor color) const
|
||||
TurnTimerInfo CGameInfoCallback::getPlayerTurnTime(PlayerColor color) const
|
||||
{
|
||||
if(!color.isValidPlayer())
|
||||
{
|
||||
return 0;
|
||||
return TurnTimerInfo{};
|
||||
}
|
||||
|
||||
auto player = gs->players.find(color);
|
||||
if(player != gs->players.end())
|
||||
{
|
||||
return player->second.turnTime;
|
||||
return player->second.turnTimer;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return TurnTimerInfo{};
|
||||
}
|
||||
|
||||
const CGObjectInstance * CGameInfoCallback::getObjByQuestIdentifier(int identifier) const
|
||||
|
@ -37,6 +37,7 @@ struct TeamState;
|
||||
struct QuestInfo;
|
||||
class CGameState;
|
||||
class PathfinderConfig;
|
||||
struct TurnTimerInfo;
|
||||
|
||||
class CArmedInstance;
|
||||
class CGObjectInstance;
|
||||
@ -153,7 +154,7 @@ public:
|
||||
virtual PlayerColor getCurrentPlayer() const; //player that currently makes move // TODO synchronous turns
|
||||
PlayerColor getLocalPlayer() const override; //player that is currently owning given client (if not a client, then returns current player)
|
||||
virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const;
|
||||
virtual int getPlayerTurnTime(PlayerColor color) const;
|
||||
virtual TurnTimerInfo getPlayerTurnTime(PlayerColor color) const;
|
||||
|
||||
//map
|
||||
virtual bool isVisible(int3 pos, const std::optional<PlayerColor> & Player) const;
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "bonuses/Bonus.h"
|
||||
#include "bonuses/CBonusSystemNode.h"
|
||||
#include "ResourceSet.h"
|
||||
#include "TurnTimerInfo.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
@ -39,7 +40,7 @@ public:
|
||||
bool enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
|
||||
EPlayerStatus::EStatus status;
|
||||
std::optional<ui8> daysWithoutCastle;
|
||||
int turnTime = 0;
|
||||
TurnTimerInfo turnTimer;
|
||||
|
||||
PlayerState();
|
||||
PlayerState(PlayerState && other) noexcept;
|
||||
@ -72,7 +73,7 @@ public:
|
||||
h & team;
|
||||
h & resources;
|
||||
h & status;
|
||||
h & turnTime;
|
||||
h & turnTimer;
|
||||
h & heroes;
|
||||
h & towns;
|
||||
h & dwellings;
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "ConstTransitivePtr.h"
|
||||
#include "MetaString.h"
|
||||
#include "ResourceSet.h"
|
||||
#include "TurnTimerInfo.h"
|
||||
#include "int3.h"
|
||||
|
||||
#include "battle/BattleAction.h"
|
||||
@ -152,12 +153,12 @@ struct DLL_LINKAGE TurnTimeUpdate : public CPackForClient
|
||||
void applyGs(CGameState * gs) const;
|
||||
|
||||
PlayerColor player;
|
||||
int turnTime = 0;
|
||||
TurnTimerInfo turnTimer;
|
||||
|
||||
template <typename Handler> void serialize(Handler & h, const int version)
|
||||
{
|
||||
h & player;
|
||||
h & turnTime;
|
||||
h & turnTimer;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2516,7 +2516,7 @@ void YourTurn::applyGs(CGameState * gs) const
|
||||
void TurnTimeUpdate::applyGs(CGameState *gs) const
|
||||
{
|
||||
auto & playerState = gs->players[player];
|
||||
playerState.turnTime = turnTime;
|
||||
playerState.turnTimer = turnTimer;
|
||||
}
|
||||
|
||||
Component::Component(const CStackBasicDescriptor & stack)
|
||||
|
@ -240,13 +240,13 @@ struct DLL_LINKAGE LobbySetPlayer : public CLobbyPackToServer
|
||||
|
||||
struct DLL_LINKAGE LobbySetTurnTime : public CLobbyPackToServer
|
||||
{
|
||||
ui8 turnTime = 0;
|
||||
TurnTimerInfo turnTimerInfo;
|
||||
|
||||
virtual void visitTyped(ICPackVisitor & visitor) override;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & turnTime;
|
||||
h & turnTimerInfo;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "GameConstants.h"
|
||||
#include "TurnTimerInfo.h"
|
||||
#include "campaign/CampaignConstants.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
@ -80,7 +81,7 @@ struct DLL_LINKAGE StartInfo
|
||||
ui32 seedToBeUsed; //0 if not sure (client requests server to decide, will be send in reply pack)
|
||||
ui32 seedPostInit; //so we know that game is correctly synced at the start; 0 if not known yet
|
||||
ui32 mapfileChecksum; //0 if not relevant
|
||||
ui8 turnTime; //in minutes, 0=unlimited
|
||||
TurnTimerInfo turnTimerInfo;
|
||||
std::string mapname; // empty for random map, otherwise name of the map or savegame
|
||||
bool createRandomMap() const { return mapGenOptions != nullptr; }
|
||||
std::shared_ptr<CMapGenOptions> mapGenOptions;
|
||||
@ -103,14 +104,14 @@ struct DLL_LINKAGE StartInfo
|
||||
h & seedToBeUsed;
|
||||
h & seedPostInit;
|
||||
h & mapfileChecksum;
|
||||
h & turnTime;
|
||||
h & turnTimerInfo;
|
||||
h & mapname;
|
||||
h & mapGenOptions;
|
||||
h & campState;
|
||||
}
|
||||
|
||||
StartInfo() : mode(INVALID), difficulty(1), seedToBeUsed(0), seedPostInit(0),
|
||||
mapfileChecksum(0), turnTime(0)
|
||||
mapfileChecksum(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
21
lib/TurnTimerInfo.cpp
Normal file
21
lib/TurnTimerInfo.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* TurnTimerInfo.cpp, 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
|
||||
*
|
||||
*/
|
||||
#include "StdInc.h"
|
||||
#include "TurnTimerInfo.h"
|
||||
|
||||
bool TurnTimerInfo::isEnabled() const
|
||||
{
|
||||
return turnTimer > 0;
|
||||
}
|
||||
|
||||
bool TurnTimerInfo::isBattleEnabled() const
|
||||
{
|
||||
return battleTimer > 0;
|
||||
}
|
35
lib/TurnTimerInfo.h
Normal file
35
lib/TurnTimerInfo.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* TurnTimerInfo.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
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
struct DLL_LINKAGE TurnTimerInfo
|
||||
{
|
||||
int turnTimer = 0; //in ms, counts down when player is making his turn on adventure map
|
||||
int baseTimer = 0; //in ms, counts down only when turn timer runs out
|
||||
int battleTimer = 0; //in ms, counts down during battles when creature timer runs out
|
||||
int creatureTimer = 0; //in ms, counts down when player is choosing action in battle
|
||||
|
||||
bool isEnabled() const;
|
||||
bool isBattleEnabled() const;
|
||||
|
||||
template <typename Handler>
|
||||
void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & turnTimer;
|
||||
h & baseTimer;
|
||||
h & battleTimer;
|
||||
h & creatureTimer;
|
||||
}
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
@ -2068,11 +2068,11 @@ void CGameHandler::run(bool resume)
|
||||
yt.daysWithoutCastle = playerState->daysWithoutCastle;
|
||||
applyAndSend(&yt);
|
||||
|
||||
if(gs->getStartInfo()->turnTime > 0) //turn timer check
|
||||
if(gs->getStartInfo()->turnTimerInfo.turnTimer > 0) //turn timer check
|
||||
{
|
||||
TurnTimeUpdate ttu;
|
||||
ttu.player = player;
|
||||
ttu.turnTime = gs->getStartInfo()->turnTime * 60 * 1000; //ms
|
||||
ttu.turnTimer = gs->getStartInfo()->turnTimerInfo;
|
||||
applyAndSend(&ttu);
|
||||
}
|
||||
}
|
||||
@ -2088,18 +2088,18 @@ void CGameHandler::run(bool resume)
|
||||
boost::unique_lock<boost::mutex> lock(states.mx);
|
||||
while(states.players.at(playerColor).makingTurn && lobby->state == EServerState::GAMEPLAY)
|
||||
{
|
||||
if(gs->getStartInfo()->turnTime > 0 && !gs->curB) //turn timer check
|
||||
if(gs->getStartInfo()->turnTimerInfo.isEnabled() && !gs->curB) //turn timer check
|
||||
{
|
||||
if(gs->players[playerColor].turnTime > 0)
|
||||
if(gs->players[playerColor].turnTimer.turnTimer > 0)
|
||||
{
|
||||
gs->players[playerColor].turnTime -= waitTime;
|
||||
gs->players[playerColor].turnTimer.turnTimer -= waitTime;
|
||||
|
||||
if(gs->players[playerColor].status == EPlayerStatus::INGAME //do not send message if player is not active already
|
||||
&& gs->players[playerColor].turnTime % turnTimePropagateFrequency == 0)
|
||||
&& gs->players[playerColor].turnTimer.turnTimer % turnTimePropagateFrequency == 0)
|
||||
{
|
||||
TurnTimeUpdate ttu;
|
||||
ttu.player = playerColor;
|
||||
ttu.turnTime = gs->players[playerColor].turnTime;
|
||||
ttu.turnTimer = gs->players[playerColor].turnTimer;
|
||||
applyAndSend(&ttu);
|
||||
}
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ void ApplyOnServerNetPackVisitor::visitLobbySetCampaign(LobbySetCampaign & pack)
|
||||
srv.si->mapname = pack.ourCampaign->getFilename();
|
||||
srv.si->mode = StartInfo::CAMPAIGN;
|
||||
srv.si->campState = pack.ourCampaign;
|
||||
srv.si->turnTime = 0;
|
||||
srv.si->turnTimerInfo = TurnTimerInfo{};
|
||||
|
||||
bool isCurrentMapConquerable = pack.ourCampaign->currentScenario() && pack.ourCampaign->isAvailable(*pack.ourCampaign->currentScenario());
|
||||
|
||||
@ -382,7 +382,7 @@ void ApplyOnServerNetPackVisitor::visitLobbySetPlayer(LobbySetPlayer & pack)
|
||||
|
||||
void ApplyOnServerNetPackVisitor::visitLobbySetTurnTime(LobbySetTurnTime & pack)
|
||||
{
|
||||
srv.si->turnTime = pack.turnTime;
|
||||
srv.si->turnTimerInfo = pack.turnTimerInfo;
|
||||
result = true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user