From b374a24c06ca3a4d97eb5329860e4b672aba4597 Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 15 Feb 2012 01:39:35 +0100 Subject: [PATCH] added start countdown when game starts without a timer --- datasrc/network.py | 2 +- src/game/client/components/hud.cpp | 24 ++++++++++++++- src/game/client/components/hud.h | 1 + src/game/server/gamecontroller.cpp | 48 ++++++++++++++++++++++++++++-- src/game/server/gamecontroller.h | 5 +++- src/game/server/gameworld.cpp | 3 +- src/game/server/player.cpp | 2 +- 7 files changed, 77 insertions(+), 8 deletions(-) diff --git a/datasrc/network.py b/datasrc/network.py index 313ce692f..2a574c494 100644 --- a/datasrc/network.py +++ b/datasrc/network.py @@ -3,7 +3,7 @@ from datatypes import * Emotes = ["NORMAL", "PAIN", "HAPPY", "SURPRISE", "ANGRY", "BLINK"] PlayerFlags = ["PLAYING", "IN_MENU", "CHATTING", "SCOREBOARD", "READY"] GameFlags = ["TEAMS", "FLAGS"] -GameStateFlags = ["WARMUP", "SUDDENDEATH", "GAMEOVER", "PAUSED"] +GameStateFlags = ["WARMUP", "SUDDENDEATH", "GAMEOVER", "PAUSED", "STARTCOUNTDOWN"] Emoticons = ["OOP", "EXCLAMATION", "HEARTS", "DROP", "DOTDOT", "MUSIC", "SORRY", "GHOST", "SUSHI", "SPLATTEE", "DEVILTEE", "ZOMG", "ZZZ", "WTF", "EYES", "QUESTION"] diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp index eb2ecbf87..6d9d4067a 100644 --- a/src/game/client/components/hud.cpp +++ b/src/game/client/components/hud.cpp @@ -63,7 +63,7 @@ void CHud::RenderGameTimer() void CHud::RenderPauseTimer() { - if(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED) + if((m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&(GAMESTATEFLAG_STARTCOUNTDOWN|GAMESTATEFLAG_PAUSED)) == GAMESTATEFLAG_PAUSED) { char aBuf[256]; const char *pText = Localize("Game paused"); @@ -101,6 +101,27 @@ void CHud::RenderPauseTimer() } } +void CHud::RenderStartCountdown() +{ + if(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_STARTCOUNTDOWN) + { + char aBuf[256]; + const char *pText = Localize("Game starts in"); + float FontSize = 20.0f; + float w = TextRender()->TextWidth(0, FontSize, pText, -1); + TextRender()->Text(0, 150*Graphics()->ScreenAspect()+-w/2, 50, FontSize, pText, -1); + + if(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateTimer == -1) + return; + + FontSize = 16.0f; + int Seconds = (m_pClient->m_Snap.m_pGameInfoObj->m_GameStateTimer+SERVER_TICK_SPEED-1)/SERVER_TICK_SPEED; + str_format(aBuf, sizeof(aBuf), "%d", Seconds); + w = TextRender()->TextWidth(0, FontSize, aBuf, -1); + TextRender()->Text(0, 150*Graphics()->ScreenAspect()+-w/2, 75, FontSize, aBuf, -1); + } +} + void CHud::RenderSuddenDeath() { if(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_SUDDENDEATH) @@ -513,6 +534,7 @@ void CHud::OnRender() RenderGameTimer(); RenderPauseTimer(); + RenderStartCountdown(); RenderSuddenDeath(); RenderScoreHud(); RenderWarmupTimer(); diff --git a/src/game/client/components/hud.h b/src/game/client/components/hud.h index 16a518012..cafc56478 100644 --- a/src/game/client/components/hud.h +++ b/src/game/client/components/hud.h @@ -18,6 +18,7 @@ class CHud : public CComponent void RenderHealthAndAmmo(const CNetObj_Character *pCharacter); void RenderGameTimer(); void RenderPauseTimer(); + void RenderStartCountdown(); void RenderSuddenDeath(); void RenderScoreHud(); void RenderSpectatorHud(); diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 13bfad800..f5f935b6c 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -24,7 +24,10 @@ IGameController::IGameController(CGameContext *pGameServer) m_GameStateTimer = TIMER_INFINITE; m_RoundStartTick = Server()->Tick(); m_SuddenDeath = 0; - SetGameState(GS_WARMUP, g_Config.m_SvWarmup); + if(g_Config.m_SvWarmup) + SetGameState(GS_WARMUP, g_Config.m_SvWarmup); + else + SetGameState(GS_STARTCOUNTDOWN, TIMER_STARTCOUNTDOWN); // info m_GameFlags = 0; @@ -421,12 +424,23 @@ void IGameController::SetGameState(int GameState, int Seconds) else SetGameState(GS_GAME); } - break; } + break; + case GS_STARTCOUNTDOWN: + { + if(m_GameState == GS_GAME || m_GameState == GS_STARTCOUNTDOWN) + { + m_GameState = GS_STARTCOUNTDOWN; + m_GameStateTimer = Seconds*Server()->TickSpeed(); + GameServer()->m_World.m_Paused = true; + } + } + break; case GS_GAME: { m_GameState = GS_GAME; m_GameStateTimer = TIMER_INFINITE; + m_StartCountdownReset = true; SetPlayersReadyState(true); GameServer()->m_World.m_Paused = false; } @@ -449,7 +463,15 @@ void IGameController::SetGameState(int GameState, int Seconds) GameServer()->m_World.m_Paused = true; } else + { + bool NeedStartCountdown = m_GameStateTimer != 0; SetGameState(GS_GAME); + if(NeedStartCountdown) + { + SetGameState(GS_STARTCOUNTDOWN, TIMER_STARTCOUNTDOWN); + m_StartCountdownReset = false; + } + } } } break; @@ -501,6 +523,10 @@ void IGameController::Snap(int SnappingClient) pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_WARMUP; pGameInfoObj->m_GameStateTimer = m_GameStateTimer; break; + case GS_STARTCOUNTDOWN: + pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_STARTCOUNTDOWN|GAMESTATEFLAG_PAUSED; + pGameInfoObj->m_GameStateTimer = m_GameStateTimer; + break; case GS_PAUSED: pGameInfoObj->m_GameStateFlags |= GAMESTATEFLAG_PAUSED; pGameInfoObj->m_GameStateTimer = m_GameStateTimer; @@ -533,7 +559,23 @@ void IGameController::Tick() { case GS_WARMUP: if(m_GameStateTimer == 0 || (m_GameStateTimer == TIMER_INFINITE && (!g_Config.m_SvPlayerReadyMode || GetPlayersReadyState()))) - StartRound(); + { + if(m_GameStateTimer == 0) + StartRound(); + else + SetGameState(GS_STARTCOUNTDOWN, TIMER_STARTCOUNTDOWN); + } + break; + case GS_STARTCOUNTDOWN: + if(m_GameStateTimer == 0) + { + if(m_StartCountdownReset) + StartRound(); + else + SetGameState(GS_GAME); + } + else + ++m_RoundStartTick; break; case GS_PAUSED: if(m_GameStateTimer == 0 || (m_GameStateTimer == TIMER_INFINITE && g_Config.m_SvPlayerReadyMode && GetPlayersReadyState())) diff --git a/src/game/server/gamecontroller.h b/src/game/server/gamecontroller.h index 615f6b266..8b39489e1 100644 --- a/src/game/server/gamecontroller.h +++ b/src/game/server/gamecontroller.h @@ -37,6 +37,7 @@ class IGameController // game int m_GameState; int m_GameStateTimer; + bool m_StartCountdownReset; virtual void DoWincheck(); void SetGameState(int GameState, int Seconds=0); @@ -136,15 +137,17 @@ public: enum { GS_WARMUP, + GS_STARTCOUNTDOWN, GS_GAME, GS_PAUSED, GS_GAMEOVER, TIMER_INFINITE = -1, + TIMER_STARTCOUNTDOWN = 3, }; void DoPause(int Seconds) { SetGameState(GS_PAUSED, Seconds); } - void DoRestart() { StartRound(); } + void DoRestart() { SetGameState(GS_STARTCOUNTDOWN, TIMER_STARTCOUNTDOWN); } void DoWarmup(int Seconds) { SetGameState(GS_WARMUP, Seconds); } // general diff --git a/src/game/server/gameworld.cpp b/src/game/server/gameworld.cpp index 7fea4db08..f959b9c75 100644 --- a/src/game/server/gameworld.cpp +++ b/src/game/server/gameworld.cpp @@ -174,7 +174,8 @@ void CGameWorld::Tick() pEnt = m_pNextTraverseEntity; } } - else if(GameServer()->m_pController->GetGameState() == IGameController::GS_PAUSED) + else if(GameServer()->m_pController->GetGameState() == IGameController::GS_PAUSED || + GameServer()->m_pController->GetGameState() == IGameController::GS_STARTCOUNTDOWN) { // update all objects for(int i = 0; i < NUM_ENTTYPES; i++) diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 3405fc38b..e95be4c4a 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -68,7 +68,7 @@ void CPlayer::Tick() m_pCharacter = 0; } - if(GameServer()->m_pController->GetGameState() != IGameController::GS_PAUSED) + if(GameServer()->m_pController->GetGameState() != IGameController::GS_PAUSED && GameServer()->m_pController->GetGameState() != IGameController::GS_STARTCOUNTDOWN) { if(!m_pCharacter && m_Team == TEAM_SPECTATORS && m_SpectatorID == SPEC_FREEVIEW) m_ViewPos -= vec2(clamp(m_ViewPos.x-m_LatestActivity.m_TargetX, -500.0f, 500.0f), clamp(m_ViewPos.y-m_LatestActivity.m_TargetY, -400.0f, 400.0f));