mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Implemented accumulating timers, rename creature timer to unit timer
This commit is contained in:
parent
cb8e9e633a
commit
653304b004
@ -901,7 +901,7 @@ void ApplyClientNetPackVisitor::visitPlayerEndsTurn(PlayerEndsTurn & pack)
|
||||
|
||||
void ApplyClientNetPackVisitor::visitTurnTimeUpdate(TurnTimeUpdate & pack)
|
||||
{
|
||||
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.toString());
|
||||
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.unitTimer, pack.player.toString());
|
||||
}
|
||||
|
||||
void ApplyClientNetPackVisitor::visitPlayerMessageClient(PlayerMessageClient & pack)
|
||||
|
@ -128,9 +128,9 @@ void TurnTimerWidget::updateTimer(PlayerColor player, uint32_t msPassed)
|
||||
if(player.isValidPlayer() || (playerInfo && playerInfo->isHuman()))
|
||||
{
|
||||
if(time.isBattle)
|
||||
timeCheckAndUpdate(time.creatureTimer);
|
||||
timeCheckAndUpdate(time.baseTimer + time.turnTimer + time.battleTimer + time.unitTimer);
|
||||
else
|
||||
timeCheckAndUpdate(time.turnTimer);
|
||||
timeCheckAndUpdate(time.baseTimer + time.turnTimer);
|
||||
}
|
||||
else
|
||||
timeCheckAndUpdate(0);
|
||||
|
@ -42,8 +42,16 @@
|
||||
#include "../../lib/mapping/CMapInfo.h"
|
||||
#include "../../lib/mapping/CMapHeader.h"
|
||||
|
||||
static JsonPath optionsTabConfigLocation()
|
||||
{
|
||||
if(settings["general"]["enableUiEnhancements"].Bool())
|
||||
return JsonPath::builtin("config/widgets/playerOptionsTab.json");
|
||||
else
|
||||
return JsonPath::builtin("config/widgets/advancedOptionsTab.json");
|
||||
}
|
||||
|
||||
OptionsTab::OptionsTab()
|
||||
: OptionsTabBase(JsonPath::builtin("config/widgets/playerOptionsTab.json"))
|
||||
: OptionsTabBase(optionsTabConfigLocation())
|
||||
, humanPlayers(0)
|
||||
{
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ OptionsTabBase::OptionsTabBase(const JsonPath & configPath)
|
||||
tinfo.baseTimer = tpreset.at(0).Integer() * 1000;
|
||||
tinfo.turnTimer = tpreset.at(1).Integer() * 1000;
|
||||
tinfo.battleTimer = tpreset.at(2).Integer() * 1000;
|
||||
tinfo.creatureTimer = tpreset.at(3).Integer() * 1000;
|
||||
tinfo.unitTimer = tpreset.at(3).Integer() * 1000;
|
||||
CSH->setTurnTimerInfo(tinfo);
|
||||
}
|
||||
});
|
||||
@ -133,7 +133,7 @@ OptionsTabBase::OptionsTabBase(const JsonPath & configPath)
|
||||
if(time >= 0)
|
||||
{
|
||||
TurnTimerInfo tinfo = SEL->getStartInfo()->turnTimerInfo;
|
||||
tinfo.creatureTimer = time;
|
||||
tinfo.unitTimer = time;
|
||||
CSH->setTurnTimerInfo(tinfo);
|
||||
}
|
||||
});
|
||||
@ -175,7 +175,7 @@ OptionsTabBase::OptionsTabBase(const JsonPath & configPath)
|
||||
tinfo.baseTimer = (*tObj)["default"].Vector().at(0).Integer() * 1000;
|
||||
tinfo.turnTimer = (*tObj)["default"].Vector().at(1).Integer() * 1000;
|
||||
tinfo.battleTimer = (*tObj)["default"].Vector().at(2).Integer() * 1000;
|
||||
tinfo.creatureTimer = (*tObj)["default"].Vector().at(3).Integer() * 1000;
|
||||
tinfo.unitTimer = (*tObj)["default"].Vector().at(3).Integer() * 1000;
|
||||
CSH->setTurnTimerInfo(tinfo);
|
||||
}
|
||||
}
|
||||
@ -251,7 +251,7 @@ void OptionsTabBase::recreate()
|
||||
//classic timer
|
||||
if(auto turnSlider = widget<CSlider>("sliderTurnDuration"))
|
||||
{
|
||||
if(!variables["timerPresets"].isNull() && !turnTimerRemote.battleTimer && !turnTimerRemote.creatureTimer && !turnTimerRemote.baseTimer)
|
||||
if(!variables["timerPresets"].isNull() && !turnTimerRemote.battleTimer && !turnTimerRemote.unitTimer && !turnTimerRemote.baseTimer)
|
||||
{
|
||||
for(int idx = 0; idx < variables["timerPresets"].Vector().size(); ++idx)
|
||||
{
|
||||
@ -281,11 +281,11 @@ void OptionsTabBase::recreate()
|
||||
if(auto ww = widget<CTextInput>("chessFieldBattle"))
|
||||
ww->setText(timeToString(turnTimerRemote.battleTimer), false);
|
||||
if(auto ww = widget<CTextInput>("chessFieldCreature"))
|
||||
ww->setText(timeToString(turnTimerRemote.creatureTimer), false);
|
||||
ww->setText(timeToString(turnTimerRemote.unitTimer), false);
|
||||
|
||||
if(auto w = widget<ComboBox>("timerModeSwitch"))
|
||||
{
|
||||
if(turnTimerRemote.battleTimer || turnTimerRemote.creatureTimer || turnTimerRemote.baseTimer)
|
||||
if(turnTimerRemote.battleTimer || turnTimerRemote.unitTimer || turnTimerRemote.baseTimer)
|
||||
{
|
||||
if(auto turnSlider = widget<CSlider>("sliderTurnDuration"))
|
||||
if(turnSlider->isActive())
|
||||
|
@ -19,7 +19,7 @@ bool TurnTimerInfo::isEnabled() const
|
||||
|
||||
bool TurnTimerInfo::isBattleEnabled() const
|
||||
{
|
||||
return creatureTimer > 0 || battleTimer > 0;
|
||||
return unitTimer > 0 || battleTimer > 0;
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@ -17,7 +17,10 @@ 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
|
||||
int unitTimer = 0; //in ms, counts down when player is choosing action in battle
|
||||
|
||||
bool accumulatingTurnTimer = false;
|
||||
bool accumulatingUnitTimer = false;
|
||||
|
||||
bool isActive = false; //is being counting down
|
||||
bool isBattle = false; //indicator for current timer mode
|
||||
@ -31,7 +34,9 @@ struct DLL_LINKAGE TurnTimerInfo
|
||||
h & turnTimer;
|
||||
h & baseTimer;
|
||||
h & battleTimer;
|
||||
h & creatureTimer;
|
||||
h & unitTimer;
|
||||
h & accumulatingTurnTimer;
|
||||
h & accumulatingUnitTimer;
|
||||
h & isActive;
|
||||
h & isBattle;
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ void TurnTimerHandler::onPlayerGetTurn(PlayerColor player)
|
||||
{
|
||||
endTurnAllowed[player] = true;
|
||||
auto & timer = timers[player];
|
||||
if(si->turnTimerInfo.baseTimer > 0)
|
||||
if(si->turnTimerInfo.accumulatingTurnTimer > 0)
|
||||
timer.baseTimer += timer.turnTimer;
|
||||
timer.turnTimer = si->turnTimerInfo.turnTimer;
|
||||
|
||||
@ -127,18 +127,15 @@ void TurnTimerHandler::onPlayerMakingTurn(PlayerColor player, int waitTime)
|
||||
const auto * state = gameHandler.getPlayerState(player);
|
||||
if(state && state->human && timer.isActive && !timer.isBattle && state->status == EPlayerStatus::INGAME)
|
||||
{
|
||||
if(!timerCountDown(timer.turnTimer, si->turnTimerInfo.turnTimer, player, waitTime))
|
||||
{
|
||||
if(timer.baseTimer > 0)
|
||||
{
|
||||
timer.turnTimer = timer.baseTimer;
|
||||
timer.baseTimer = 0;
|
||||
onPlayerMakingTurn(player, 0);
|
||||
}
|
||||
else if(endTurnAllowed[state->color] && !gameHandler.queries->topQuery(state->color)) //wait for replies to avoid pending queries
|
||||
if(timerCountDown(timer.turnTimer, si->turnTimerInfo.turnTimer, player, waitTime))
|
||||
return;
|
||||
|
||||
if(timerCountDown(timer.baseTimer, si->turnTimerInfo.baseTimer, player, waitTime))
|
||||
return;
|
||||
|
||||
if(endTurnAllowed[state->color] && !gameHandler.queries->topQuery(state->color)) //wait for replies to avoid pending queries
|
||||
gameHandler.turnOrder->onPlayerEndsTurn(state->color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TurnTimerHandler::isPvpBattle(const BattleID & battleID) const
|
||||
@ -176,8 +173,8 @@ void TurnTimerHandler::onBattleStart(const BattleID & battleID)
|
||||
auto & timer = timers[i];
|
||||
timer.isBattle = true;
|
||||
timer.isActive = si->turnTimerInfo.isBattleEnabled();
|
||||
timer.battleTimer = (pvpBattle ? si->turnTimerInfo.battleTimer : 0);
|
||||
timer.creatureTimer = (pvpBattle ? si->turnTimerInfo.creatureTimer : si->turnTimerInfo.battleTimer);
|
||||
timer.battleTimer = si->turnTimerInfo.battleTimer;
|
||||
timer.unitTimer = (pvpBattle ? si->turnTimerInfo.unitTimer : 0);
|
||||
|
||||
sendTimerUpdate(i);
|
||||
}
|
||||
@ -201,8 +198,6 @@ void TurnTimerHandler::onBattleEnd(const BattleID & battleID)
|
||||
auto attacker = gs->getBattle(battleID)->getSidePlayer(BattleSide::ATTACKER);
|
||||
auto defender = gs->getBattle(battleID)->getSidePlayer(BattleSide::DEFENDER);
|
||||
|
||||
bool pvpBattle = isPvpBattle(battleID);
|
||||
|
||||
for(auto i : {attacker, defender})
|
||||
{
|
||||
if(i.isValidPlayer())
|
||||
@ -210,14 +205,6 @@ void TurnTimerHandler::onBattleEnd(const BattleID & battleID)
|
||||
auto & timer = timers[i];
|
||||
timer.isBattle = false;
|
||||
timer.isActive = true;
|
||||
if(!pvpBattle)
|
||||
{
|
||||
if(si->turnTimerInfo.baseTimer && timer.baseTimer == 0)
|
||||
timer.baseTimer = timer.creatureTimer;
|
||||
else if(si->turnTimerInfo.turnTimer && timer.turnTimer == 0)
|
||||
timer.turnTimer = timer.creatureTimer;
|
||||
}
|
||||
|
||||
sendTimerUpdate(i);
|
||||
}
|
||||
}
|
||||
@ -242,9 +229,9 @@ void TurnTimerHandler::onBattleNextStack(const BattleID & battleID, const CStack
|
||||
auto player = stack.getOwner();
|
||||
|
||||
auto & timer = timers[player];
|
||||
if(timer.battleTimer == 0)
|
||||
timer.battleTimer = timer.creatureTimer;
|
||||
timer.creatureTimer = si->turnTimerInfo.creatureTimer;
|
||||
if(timer.accumulatingUnitTimer)
|
||||
timer.battleTimer += timer.unitTimer;
|
||||
timer.unitTimer = si->turnTimerInfo.unitTimer;
|
||||
|
||||
sendTimerUpdate(player);
|
||||
}
|
||||
@ -283,22 +270,26 @@ void TurnTimerHandler::onBattleLoop(const BattleID & battleID, int waitTime)
|
||||
return;
|
||||
|
||||
const auto * state = gameHandler.getPlayerState(player);
|
||||
assert(state && state->status != EPlayerStatus::INGAME);
|
||||
assert(state && state->status == EPlayerStatus::INGAME);
|
||||
if(!state || state->status != EPlayerStatus::INGAME || !state->human)
|
||||
return;
|
||||
|
||||
auto & timer = timers[player];
|
||||
if(timer.isActive && timer.isBattle && !timerCountDown(timer.creatureTimer, si->turnTimerInfo.creatureTimer, player, waitTime))
|
||||
if(timer.isActive && timer.isBattle)
|
||||
{
|
||||
if (timerCountDown(timer.unitTimer, si->turnTimerInfo.unitTimer, player, waitTime))
|
||||
return;
|
||||
|
||||
if (timerCountDown(timer.battleTimer, si->turnTimerInfo.battleTimer, player, waitTime))
|
||||
return;
|
||||
|
||||
if (timerCountDown(timer.turnTimer, si->turnTimerInfo.turnTimer, player, waitTime))
|
||||
return;
|
||||
|
||||
if (timerCountDown(timer.baseTimer, si->turnTimerInfo.baseTimer, player, waitTime))
|
||||
return;
|
||||
|
||||
if(isPvpBattle(battleID))
|
||||
{
|
||||
if(timer.battleTimer > 0)
|
||||
{
|
||||
timer.creatureTimer = timer.battleTimer;
|
||||
timerCountDown(timer.creatureTimer, timer.battleTimer, player, 0);
|
||||
timer.battleTimer = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
BattleAction doNothing;
|
||||
doNothing.side = side;
|
||||
@ -311,21 +302,6 @@ void TurnTimerHandler::onBattleLoop(const BattleID & battleID, int waitTime)
|
||||
}
|
||||
gameHandler.battles->makePlayerBattleAction(battleID, player, doNothing);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(timer.turnTimer > 0)
|
||||
{
|
||||
timer.creatureTimer = timer.turnTimer;
|
||||
timerCountDown(timer.creatureTimer, timer.turnTimer, player, 0);
|
||||
timer.turnTimer = 0;
|
||||
}
|
||||
else if(timer.baseTimer > 0)
|
||||
{
|
||||
timer.creatureTimer = timer.baseTimer;
|
||||
timerCountDown(timer.creatureTimer, timer.baseTimer, player, 0);
|
||||
timer.baseTimer = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
BattleAction retreat;
|
||||
@ -334,5 +310,4 @@ void TurnTimerHandler::onBattleLoop(const BattleID & battleID, int waitTime)
|
||||
gameHandler.battles->makePlayerBattleAction(battleID, player, retreat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user