Send the race time using warmup timer

This commit is contained in:
necropotame 2017-01-04 14:14:10 +01:00
parent 16f04d8989
commit 4cfe96801b
8 changed files with 66 additions and 24 deletions

View file

@ -176,6 +176,7 @@ if gen_network_source:
lines += ['']
lines += ['static const int max_int = 0x7fffffff;']
lines += ['static const int min_int = 0x80000000;']
lines += ['int CNetObjHandler::ClampInt(const char *pErrorMsg, int Value, int Min, int Max)']
lines += ['{']

View file

@ -3,7 +3,7 @@ from datatypes import *
Emotes = ["NORMAL", "PAIN", "HAPPY", "SURPRISE", "ANGRY", "BLINK"]
PlayerFlags = ["PLAYING", "IN_MENU", "CHATTING", "SCOREBOARD", "AIM"]
GameFlags = ["TEAMS", "FLAGS"]
GameStateFlags = ["GAMEOVER", "SUDDENDEATH", "PAUSED"]
GameStateFlags = ["GAMEOVER", "SUDDENDEATH", "PAUSED", "RACETIME"]
Emoticons = ["OOP", "EXCLAMATION", "HEARTS", "DROP", "DOTDOT", "MUSIC", "SORRY", "GHOST", "SUSHI", "SPLATTEE", "DEVILTEE", "ZOMG", "ZZZ", "WTF", "EYES", "QUESTION"]
@ -106,7 +106,7 @@ Objects = [
NetIntRange("m_GameFlags", 0, 256),
NetIntRange("m_GameStateFlags", 0, 256),
NetTick("m_RoundStartTick"),
NetIntRange("m_WarmupTimer", 0, 'max_int'),
NetIntRange("m_WarmupTimer", 'min_int', 'max_int'),
NetIntRange("m_ScoreLimit", 0, 'max_int'),
NetIntRange("m_TimeLimit", 0, 'max_int'),

View file

@ -108,6 +108,7 @@ enum
VERSION_DDNET_HOOKDURATION_TUNE = 607,
VERSION_DDNET_FIREDELAY_TUNE = 701,
VERSION_DDNET_UPDATER_FIXED = 707,
VERSION_DDNET_GAMETICK = 10036,
};
#endif

View file

@ -47,13 +47,18 @@ void CHud::RenderGameTimer()
{
char Buf[32];
int Time = 0;
if(m_pClient->m_Snap.m_pGameInfoObj->m_TimeLimit && !m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer)
if(m_pClient->m_Snap.m_pGameInfoObj->m_TimeLimit && (m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer <= 0))
{
Time = m_pClient->m_Snap.m_pGameInfoObj->m_TimeLimit*60 - ((Client()->GameTick()-m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick)/Client()->GameTickSpeed());
if(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER)
Time = 0;
}
else if(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_RACETIME)
{
//The Warmup timer is negative in this case to make sure that incompatible clients will not see a warmup timer
Time = (Client()->GameTick()+m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer)/Client()->GameTickSpeed();
}
else
Time = (Client()->GameTick()-m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick)/Client()->GameTickSpeed();
@ -77,7 +82,7 @@ void CHud::RenderGameTimer()
else
w = TextRender()->TextWidth(0, 12,"00:00",-1);
// last 60 sec red, last 10 sec blink
if(m_pClient->m_Snap.m_pGameInfoObj->m_TimeLimit && Time <= 60 && !m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer)
if(m_pClient->m_Snap.m_pGameInfoObj->m_TimeLimit && Time <= 60 && (m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer <= 0))
{
float Alpha = Time <= 10 && (2*time_get()/time_freq()) % 2 ? 0.5f : 1.0f;
TextRender()->TextColor(1.0f, 0.25f, 0.25f, Alpha);
@ -283,7 +288,7 @@ void CHud::RenderScoreHud()
void CHud::RenderWarmupTimer()
{
// render warmup timer
if(m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer)
if(m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer > 0 && !(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_RACETIME))
{
char Buf[256];
float FontSize = 20.0f;

View file

@ -1182,30 +1182,58 @@ void CGameContext::ConSetTimerType(IConsole::IResult *pResult, void *pUserData)
const char msg[3][128] = {"game/round timer.", "broadcast.", "both game/round timer and broadcast."};
char aBuf[128];
if(pPlayer->m_TimerType <= 2 && pPlayer->m_TimerType >= 0)
str_format(aBuf, sizeof(aBuf), "Timer is displayed in", msg[pPlayer->m_TimerType]);
str_format(aBuf, sizeof(aBuf), "Timer is displayed in %s", msg[pPlayer->m_TimerType]);
else if(pPlayer->m_TimerType == 3)
str_format(aBuf, sizeof(aBuf), "Timer isn't displayed.");
int OldType = pPlayer->m_TimerType;
if(pResult->NumArguments() == 0) {
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD,"timer",aBuf);
return;
}
else if(str_comp_nocase(pResult->GetString(0), "gametimer") == 0) {
pSelf->SendBroadcast("", pResult->m_ClientID);
pPlayer->m_TimerType = 0;
else if(str_comp_nocase(pResult->GetString(0), "gametimer") == 0)
{
if(pPlayer->m_ClientVersion >= VERSION_DDNET_GAMETICK)
pPlayer->m_TimerType = 0;
else
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD,"timer","gametimer is not supported by your client.");
}
else if(str_comp_nocase(pResult->GetString(0), "broadcast") == 0)
pPlayer->m_TimerType = 1;
pPlayer->m_TimerType = 1;
else if(str_comp_nocase(pResult->GetString(0), "both") == 0)
{
if(pPlayer->m_ClientVersion >= VERSION_DDNET_GAMETICK)
pPlayer->m_TimerType = 2;
else if(str_comp_nocase(pResult->GetString(0), "none") == 0)
pPlayer->m_TimerType = 3;
else if(str_comp_nocase(pResult->GetString(0), "cycle") == 0) {
if(pPlayer->m_TimerType < 3)
pPlayer->m_TimerType++;
else if(pPlayer->m_TimerType == 3)
pPlayer->m_TimerType = 0;
else
{
pPlayer->m_TimerType = 1;
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD,"timer","gametimer is not supported by your client.");
}
}
else if(str_comp_nocase(pResult->GetString(0), "none") == 0)
pPlayer->m_TimerType = 3;
else if(str_comp_nocase(pResult->GetString(0), "cycle") == 0)
{
if(pPlayer->m_ClientVersion >= VERSION_DDNET_GAMETICK)
{
if(pPlayer->m_TimerType < 3)
pPlayer->m_TimerType++;
else if(pPlayer->m_TimerType == 3)
pPlayer->m_TimerType = 0;
}
else
{
if(pPlayer->m_TimerType < 3)
pPlayer->m_TimerType = 3;
else if(pPlayer->m_TimerType == 3)
pPlayer->m_TimerType = 1;
}
}
if((OldType == 1 || OldType == 2) && (pPlayer->m_TimerType == 0 || pPlayer->m_TimerType == 3))
pSelf->SendBroadcast("", pResult->m_ClientID);
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD,"timer",aBuf);
}

View file

@ -1561,7 +1561,10 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
}
else if(pPlayer->m_ClientVersion < Version)
pPlayer->m_ClientVersion = Version;
if(pPlayer->m_ClientVersion >= VERSION_DDNET_GAMETICK)
pPlayer->m_TimerType = g_Config.m_SvDefaultTimerType;
dbg_msg("ddnet", "%d using Custom Client %d", ClientID, pPlayer->m_ClientVersion);
//first update his teams state

View file

@ -770,18 +770,22 @@ void IGameController::Snap(int SnappingClient)
CPlayer *pPlayer = SnappingClient > -1 ? GameServer()->m_apPlayers[SnappingClient] : 0;
CPlayer *pPlayer2;
if(pPlayer && (pPlayer->m_TimerType == 0 || pPlayer->m_TimerType == 2))
if(pPlayer && (pPlayer->m_TimerType == 0 || pPlayer->m_TimerType == 2) && pPlayer->m_ClientVersion >= VERSION_DDNET_GAMETICK)
{
if((pPlayer->GetTeam() == -1 || pPlayer->m_Paused)
&& pPlayer->m_SpectatorID != SPEC_FREEVIEW
&& (pPlayer2 = GameServer()->m_apPlayers[pPlayer->m_SpectatorID]))
{
if((pChr = pPlayer2->GetCharacter()))
pGameInfoObj->m_RoundStartTick = (pChr->m_DDRaceState == DDRACE_STARTED)?pChr->m_StartTime:m_RoundStartTick;
if((pChr = pPlayer2->GetCharacter()) && pChr->m_DDRaceState == DDRACE_STARTED)
{
pGameInfoObj->m_WarmupTimer = -pChr->m_StartTime;
pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_RACETIME;
}
}
else if((pChr = pPlayer->GetCharacter()))
else if((pChr = pPlayer->GetCharacter()) && pChr->m_DDRaceState == DDRACE_STARTED)
{
pGameInfoObj->m_RoundStartTick = (pChr->m_DDRaceState == DDRACE_STARTED)?pChr->m_StartTime:m_RoundStartTick;
pGameInfoObj->m_WarmupTimer = -pChr->m_StartTime;
pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_RACETIME;
}
}
}

View file

@ -64,7 +64,7 @@ void CPlayer::Reset()
m_Sent2ndAfkWarning = 0;
m_ChatScore = 0;
m_EyeEmote = true;
m_TimerType = g_Config.m_SvDefaultTimerType;
m_TimerType = (g_Config.m_SvDefaultTimerType == 0 || g_Config.m_SvDefaultTimerType == 2) ? 1 : g_Config.m_SvDefaultTimerType;
m_DefEmote = EMOTE_NORMAL;
m_Afk = false;
m_LastWhisperTo = -1;