improved sudden death in ctf. Closes #617

This commit is contained in:
oy 2011-06-19 17:32:00 +02:00
parent 957b81af07
commit c10c7d9ac3
7 changed files with 67 additions and 48 deletions

View file

@ -520,6 +520,8 @@ void IGameController::Tick()
}
}
}
DoWincheck();
}
@ -658,51 +660,50 @@ bool IGameController::CanChangeTeam(CPlayer *pPlayer, int JoinTeam)
return true;
}
void IGameController::DoPlayerScoreWincheck()
void IGameController::DoWincheck()
{
if(m_GameOverTick == -1 && !m_Warmup)
{
// gather some stats
int Topscore = 0;
int TopscoreCount = 0;
for(int i = 0; i < MAX_CLIENTS; i++)
if(IsTeamplay())
{
if(GameServer()->m_apPlayers[i])
// check score win condition
if((g_Config.m_SvScorelimit > 0 && (m_aTeamscore[TEAM_RED] >= g_Config.m_SvScorelimit || m_aTeamscore[TEAM_BLUE] >= g_Config.m_SvScorelimit)) ||
(g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60))
{
if(GameServer()->m_apPlayers[i]->m_Score > Topscore)
{
Topscore = GameServer()->m_apPlayers[i]->m_Score;
TopscoreCount = 1;
}
else if(GameServer()->m_apPlayers[i]->m_Score == Topscore)
TopscoreCount++;
if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE])
EndRound();
else
m_SuddenDeath = 1;
}
}
// check score win condition
if((g_Config.m_SvScorelimit > 0 && Topscore >= g_Config.m_SvScorelimit) ||
(g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60))
else
{
if(TopscoreCount == 1)
EndRound();
else
m_SuddenDeath = 1;
}
}
}
// gather some stats
int Topscore = 0;
int TopscoreCount = 0;
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(GameServer()->m_apPlayers[i])
{
if(GameServer()->m_apPlayers[i]->m_Score > Topscore)
{
Topscore = GameServer()->m_apPlayers[i]->m_Score;
TopscoreCount = 1;
}
else if(GameServer()->m_apPlayers[i]->m_Score == Topscore)
TopscoreCount++;
}
}
void IGameController::DoTeamScoreWincheck()
{
if(m_GameOverTick == -1 && !m_Warmup)
{
// check score win condition
if((g_Config.m_SvScorelimit > 0 && (m_aTeamscore[TEAM_RED] >= g_Config.m_SvScorelimit || m_aTeamscore[TEAM_BLUE] >= g_Config.m_SvScorelimit)) ||
(g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60))
{
if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE])
EndRound();
else
m_SuddenDeath = 1;
// check score win condition
if((g_Config.m_SvScorelimit > 0 && Topscore >= g_Config.m_SvScorelimit) ||
(g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60))
{
if(TopscoreCount == 1)
EndRound();
else
m_SuddenDeath = 1;
}
}
}
}

View file

@ -68,8 +68,7 @@ public:
IGameController(class CGameContext *pGameServer);
virtual ~IGameController();
void DoTeamScoreWincheck();
void DoPlayerScoreWincheck();
virtual void DoWincheck();
void DoWarmup(int Seconds);

View file

@ -1,6 +1,9 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <engine/shared/config.h>
#include <game/mapitems.h>
#include <game/server/entities/character.h>
#include <game/server/entities/flag.h>
#include <game/server/player.h>
@ -63,6 +66,30 @@ int CGameControllerCTF::OnCharacterDeath(class CCharacter *pVictim, class CPlaye
return HadFlag;
}
void CGameControllerCTF::DoWincheck()
{
if(m_GameOverTick == -1 && !m_Warmup)
{
// check score win condition
if((g_Config.m_SvScorelimit > 0 && (m_aTeamscore[TEAM_RED] >= g_Config.m_SvScorelimit || m_aTeamscore[TEAM_BLUE] >= g_Config.m_SvScorelimit)) ||
(g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60))
{
if(m_SuddenDeath)
{
if(m_aTeamscore[TEAM_RED]/100 != m_aTeamscore[TEAM_BLUE]/100)
EndRound();
}
else
{
if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE])
EndRound();
else
m_SuddenDeath = 1;
}
}
}
}
bool CGameControllerCTF::CanBeMovedOnBalance(int ClientID)
{
CCharacter* Character = GameServer()->m_apPlayers[ClientID]->GetCharacter();
@ -117,12 +144,7 @@ void CGameControllerCTF::Tick()
{
IGameController::Tick();
if(GameServer()->m_World.m_ResetRequested)
return;
DoTeamScoreWincheck();
if(GameServer()->m_World.m_Paused)
if(GameServer()->m_World.m_ResetRequested || GameServer()->m_World.m_Paused)
return;
for(int fi = 0; fi < 2; fi++)

View file

@ -11,6 +11,7 @@ public:
class CFlag *m_apFlags[2];
CGameControllerCTF(class CGameContext *pGameServer);
virtual void DoWincheck();
virtual bool CanBeMovedOnBalance(int ClientID);
virtual void Snap(int SnappingClient);
virtual void Tick();

View file

@ -11,6 +11,5 @@ CGameControllerDM::CGameControllerDM(class CGameContext *pGameServer)
void CGameControllerDM::Tick()
{
DoPlayerScoreWincheck();
IGameController::Tick();
}

View file

@ -15,8 +15,6 @@ CGameControllerMOD::CGameControllerMOD(class CGameContext *pGameServer)
void CGameControllerMOD::Tick()
{
// this is the main part of the gamemode, this function is run every tick
DoPlayerScoreWincheck(); // checks for winners, no teams version
//DoTeamScoreWincheck(); // checks for winners, two teams version
IGameController::Tick();
}

View file

@ -48,6 +48,5 @@ void CGameControllerTDM::Snap(int SnappingClient)
void CGameControllerTDM::Tick()
{
DoTeamScoreWincheck();
IGameController::Tick();
}