void IGameController::Tick() { // handle game states if(m_GameState != IGS_GAME_RUNNING) { if(m_GameStateTimer > 0) --m_GameStateTimer; if(m_GameStateTimer == 0) { // timer fires switch(m_GameState) { case IGS_WARMUP_USER: // end warmup SetGameState(IGS_WARMUP_USER, 0); break; case IGS_START_COUNTDOWN: // unpause the game SetGameState(IGS_GAME_RUNNING); break; case IGS_GAME_PAUSED: // end pause SetGameState(IGS_GAME_PAUSED, 0); break; case IGS_END_ROUND: // check if the match is over otherwise start next round DoWincheckMatch(); if(m_GameState != IGS_END_MATCH) StartRound(); break; case IGS_END_MATCH: // start next match CycleMap(); m_MatchCount++; StartMatch(); break; case IGS_WARMUP_GAME: case IGS_GAME_RUNNING: // not effected break; } } else { // timer still running switch(m_GameState) { case IGS_WARMUP_USER: // check if player ready mode was disabled and it waits that all players are ready -> end warmup if(!g_Config.m_SvPlayerReadyMode && m_GameStateTimer == TIMER_INFINITE) SetGameState(IGS_WARMUP_USER, 0); break; case IGS_START_COUNTDOWN: case IGS_GAME_PAUSED: // freeze the game ++m_GameStartTick; break; case IGS_WARMUP_GAME: case IGS_GAME_RUNNING: case IGS_END_MATCH: case IGS_END_ROUND: // not effected break; } } } // do team-balancing (skip this in survival, done there when a round starts) if(IsTeamplay() && !(m_GameFlags&GAMEFLAG_SURVIVAL)) { switch(m_UnbalancedTick) { case TBALANCE_CHECK: CheckTeamBalance(); break; case TBALANCE_OK: break; default: if(Server()->Tick() > m_UnbalancedTick+g_Config.m_SvTeambalanceTime*Server()->TickSpeed()*60) DoTeamBalance(); } } // check for inactive players DoActivityCheck(); // win check if((m_GameState == IGS_GAME_RUNNING || m_GameState == IGS_GAME_PAUSED) && !GameServer()->m_World.m_ResetRequested) { if(m_GameFlags&GAMEFLAG_SURVIVAL) DoWincheckRound(); else DoWincheckMatch(); } }
void IGameController::Tick() { // do warmup if(!GameServer()->m_World.m_Paused && m_Warmup) { m_Warmup--; if(!m_Warmup) StartRound(); } if(m_GameOverTick != -1) { // game over.. wait for restart if(Server()->Tick() > m_GameOverTick+Server()->TickSpeed()*10) { CycleMap(); StartRound(); m_RoundCount++; } } else if(GameServer()->m_World.m_Paused && m_UnpauseTimer) { --m_UnpauseTimer; if(!m_UnpauseTimer) GameServer()->m_World.m_Paused = false; } // game is Paused if(GameServer()->m_World.m_Paused) ++m_RoundStartTick; // do team-balancing if(IsTeamplay() && m_UnbalancedTick != -1 && Server()->Tick() > m_UnbalancedTick+g_Config.m_SvTeambalanceTime*Server()->TickSpeed()*60) { GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", "Balancing teams"); int aT[2] = {0,0}; float aTScore[2] = {0,0}; float aPScore[MAX_CLIENTS] = {0.0f}; for(int i = 0; i < MAX_CLIENTS; i++) { if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS) { aT[GameServer()->m_apPlayers[i]->GetTeam()]++; aPScore[i] = GameServer()->m_apPlayers[i]->m_Score*Server()->TickSpeed()*60.0f/ (Server()->Tick()-GameServer()->m_apPlayers[i]->m_ScoreStartTick); aTScore[GameServer()->m_apPlayers[i]->GetTeam()] += aPScore[i]; } } // are teams unbalanced? if(absolute(aT[0]-aT[1]) >= 2) { int M = (aT[0] > aT[1]) ? 0 : 1; int NumBalance = absolute(aT[0]-aT[1]) / 2; do { CPlayer *pP = 0; float PD = aTScore[M]; for(int i = 0; i < MAX_CLIENTS; i++) { if(!GameServer()->m_apPlayers[i] || !CanBeMovedOnBalance(i)) continue; // remember the player who would cause lowest score-difference if(GameServer()->m_apPlayers[i]->GetTeam() == M && (!pP || absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i])) < PD)) { pP = GameServer()->m_apPlayers[i]; PD = absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i])); } } // move the player to the other team int Temp = pP->m_LastActionTick; pP->SetTeam(M^1); pP->m_LastActionTick = Temp; pP->Respawn(); pP->m_ForceBalanced = true; } while (--NumBalance); m_ForceBalanced = true; } m_UnbalancedTick = -1; } // check for inactive players if(g_Config.m_SvInactiveKickTime > 0) { for(int i = 0; i < MAX_CLIENTS; ++i) { #ifdef CONF_DEBUG if(g_Config.m_DbgDummies) { if(i >= MAX_CLIENTS-g_Config.m_DbgDummies) break; } #endif if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && !Server()->IsAuthed(i)) { if(Server()->Tick() > GameServer()->m_apPlayers[i]->m_LastActionTick+g_Config.m_SvInactiveKickTime*Server()->TickSpeed()*60) { switch(g_Config.m_SvInactiveKick) { case 0: { // move player to spectator GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS); } break; case 1: { // move player to spectator if the reserved slots aren't filled yet, kick him otherwise int Spectators = 0; for(int j = 0; j < MAX_CLIENTS; ++j) if(GameServer()->m_apPlayers[j] && GameServer()->m_apPlayers[j]->GetTeam() == TEAM_SPECTATORS) ++Spectators; if(Spectators >= g_Config.m_SvSpectatorSlots) Server()->Kick(i, "Kicked for inactivity"); else GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS); } break; case 2: { // kick the player Server()->Kick(i, "Kicked for inactivity"); } } } } } } DoWincheck(); }
void IGameController::Tick() { // do warmup if(m_Warmup) { m_Warmup--; if(!m_Warmup) StartRound(); } if(m_GameOverTick != -1) { // game over.. wait for restart if(Server()->Tick() > m_GameOverTick+Server()->TickSpeed()*10) { CycleMap(); StartRound(); m_RoundCount++; } } // do team-balancing if (IsTeamplay() && m_UnbalancedTick != -1 && Server()->Tick() > m_UnbalancedTick+g_Config.m_SvTeambalanceTime*Server()->TickSpeed()*60) { dbg_msg("game", "Balancing teams"); int aT[2] = {0,0}; float aTScore[2] = {0,0}; float aPScore[MAX_CLIENTS] = {0.0f}; for(int i = 0; i < MAX_CLIENTS; i++) { if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != -1) { aT[GameServer()->m_apPlayers[i]->GetTeam()]++; aPScore[i] = GameServer()->m_apPlayers[i]->m_Score*Server()->TickSpeed()*60.0f/ (Server()->Tick()-GameServer()->m_apPlayers[i]->m_ScoreStartTick); aTScore[GameServer()->m_apPlayers[i]->GetTeam()] += aPScore[i]; } } // are teams unbalanced? if(absolute(aT[0]-aT[1]) >= 2) { int M = (aT[0] > aT[1]) ? 0 : 1; int NumBalance = absolute(aT[0]-aT[1]) / 2; do { CPlayer *pP = 0; int PD = aTScore[M]; for(int i = 0; i < MAX_CLIENTS; i++) { if(!GameServer()->m_apPlayers[i] || !CanBeMovedOnBalance(i)) continue; // remember the player who would cause lowest score-difference if(GameServer()->m_apPlayers[i]->GetTeam() == M && (!pP || absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i])) < PD)) { pP = GameServer()->m_apPlayers[i]; PD = absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i])); } } // move the player to the other team pP->SetTeam(M^1); pP->Respawn(); pP->m_ForceBalanced = true; } while (--NumBalance); m_ForceBalanced = true; } m_UnbalancedTick = -1; } // update browse info int Prog = -1; if(g_Config.m_SvTimelimit > 0) Prog = max(Prog, (Server()->Tick()-m_RoundStartTick) * 100 / (g_Config.m_SvTimelimit*Server()->TickSpeed()*60)); if(g_Config.m_SvScorelimit) { if(IsTeamplay()) { Prog = max(Prog, (m_aTeamscore[0]*100)/g_Config.m_SvScorelimit); Prog = max(Prog, (m_aTeamscore[1]*100)/g_Config.m_SvScorelimit); } else { for(int i = 0; i < MAX_CLIENTS; i++) { if(GameServer()->m_apPlayers[i]) Prog = max(Prog, (GameServer()->m_apPlayers[i]->m_Score*100)/g_Config.m_SvScorelimit); } } } if(m_Warmup) Prog = -1; Server()->SetBrowseInfo(m_pGameType, Prog); }