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; return true;
} }
void IGameController::DoPlayerScoreWincheck() void IGameController::DoWincheck()
{ {
if(m_GameOverTick == -1 && !m_Warmup) if(m_GameOverTick == -1 && !m_Warmup)
{ {
// gather some stats if(IsTeamplay())
int Topscore = 0;
int TopscoreCount = 0;
for(int i = 0; i < MAX_CLIENTS; i++)
{ {
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) if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE])
{ EndRound();
Topscore = GameServer()->m_apPlayers[i]->m_Score; else
TopscoreCount = 1; m_SuddenDeath = 1;
}
else if(GameServer()->m_apPlayers[i]->m_Score == Topscore)
TopscoreCount++;
} }
} }
else
// 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) // gather some stats
EndRound(); int Topscore = 0;
else int TopscoreCount = 0;
m_SuddenDeath = 1; 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() // check score win condition
{ if((g_Config.m_SvScorelimit > 0 && Topscore >= g_Config.m_SvScorelimit) ||
if(m_GameOverTick == -1 && !m_Warmup) (g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60))
{ {
// check score win condition if(TopscoreCount == 1)
if((g_Config.m_SvScorelimit > 0 && (m_aTeamscore[TEAM_RED] >= g_Config.m_SvScorelimit || m_aTeamscore[TEAM_BLUE] >= g_Config.m_SvScorelimit)) || EndRound();
(g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60)) else
{ m_SuddenDeath = 1;
if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE]) }
EndRound();
else
m_SuddenDeath = 1;
} }
} }
} }

View file

@ -68,8 +68,7 @@ public:
IGameController(class CGameContext *pGameServer); IGameController(class CGameContext *pGameServer);
virtual ~IGameController(); virtual ~IGameController();
void DoTeamScoreWincheck(); virtual void DoWincheck();
void DoPlayerScoreWincheck();
void DoWarmup(int Seconds); 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. */ /* (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. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <engine/shared/config.h>
#include <game/mapitems.h> #include <game/mapitems.h>
#include <game/server/entities/character.h> #include <game/server/entities/character.h>
#include <game/server/entities/flag.h> #include <game/server/entities/flag.h>
#include <game/server/player.h> #include <game/server/player.h>
@ -63,6 +66,30 @@ int CGameControllerCTF::OnCharacterDeath(class CCharacter *pVictim, class CPlaye
return HadFlag; 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) bool CGameControllerCTF::CanBeMovedOnBalance(int ClientID)
{ {
CCharacter* Character = GameServer()->m_apPlayers[ClientID]->GetCharacter(); CCharacter* Character = GameServer()->m_apPlayers[ClientID]->GetCharacter();
@ -117,12 +144,7 @@ void CGameControllerCTF::Tick()
{ {
IGameController::Tick(); IGameController::Tick();
if(GameServer()->m_World.m_ResetRequested) if(GameServer()->m_World.m_ResetRequested || GameServer()->m_World.m_Paused)
return;
DoTeamScoreWincheck();
if(GameServer()->m_World.m_Paused)
return; return;
for(int fi = 0; fi < 2; fi++) for(int fi = 0; fi < 2; fi++)

View file

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

View file

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

View file

@ -15,8 +15,6 @@ CGameControllerMOD::CGameControllerMOD(class CGameContext *pGameServer)
void CGameControllerMOD::Tick() void CGameControllerMOD::Tick()
{ {
// this is the main part of the gamemode, this function is run every 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(); IGameController::Tick();
} }

View file

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