added additional win checks for ctf. closes #1515

This commit is contained in:
oy 2019-01-18 20:24:09 +01:00
parent c4d46668dc
commit 40b6e75552
4 changed files with 24 additions and 6 deletions

View file

@ -426,7 +426,7 @@ void IGameController::OnReset()
} }
// game // game
void IGameController::DoWincheckMatch() bool IGameController::DoWincheckMatch()
{ {
if(IsTeamplay()) if(IsTeamplay())
{ {
@ -435,7 +435,10 @@ void IGameController::DoWincheckMatch()
(m_GameInfo.m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_GameInfo.m_TimeLimit*Server()->TickSpeed()*60)) (m_GameInfo.m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_GameInfo.m_TimeLimit*Server()->TickSpeed()*60))
{ {
if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE] || m_GameFlags&GAMEFLAG_SURVIVAL) if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE] || m_GameFlags&GAMEFLAG_SURVIVAL)
{
EndMatch(); EndMatch();
return true;
}
else else
m_SuddenDeath = 1; m_SuddenDeath = 1;
} }
@ -464,11 +467,15 @@ void IGameController::DoWincheckMatch()
(m_GameInfo.m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_GameInfo.m_TimeLimit*Server()->TickSpeed()*60)) (m_GameInfo.m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_GameInfo.m_TimeLimit*Server()->TickSpeed()*60))
{ {
if(TopscoreCount == 1) if(TopscoreCount == 1)
{
EndMatch(); EndMatch();
return true;
}
else else
m_SuddenDeath = 1; m_SuddenDeath = 1;
} }
} }
return false;
} }
void IGameController::ResetGame() void IGameController::ResetGame()
@ -603,8 +610,7 @@ void IGameController::SetGameState(EGameState GameState, int Timer)
} }
break; break;
case IGS_END_ROUND: case IGS_END_ROUND:
DoWincheckMatch(); if(DoWincheckMatch())
if(m_GameState == IGS_END_MATCH)
break; break;
case IGS_END_MATCH: case IGS_END_MATCH:
// only possible when game is running or over // only possible when game is running or over

View file

@ -54,7 +54,7 @@ class IGameController
EGameState m_GameState; EGameState m_GameState;
int m_GameStateTimer; int m_GameStateTimer;
virtual void DoWincheckMatch(); virtual bool DoWincheckMatch(); // returns true when the match is over
virtual void DoWincheckRound() {}; virtual void DoWincheckRound() {};
bool HasEnoughPlayers() const { return (IsTeamplay() && m_aTeamSize[TEAM_RED] > 0 && m_aTeamSize[TEAM_BLUE] > 0) || (!IsTeamplay() && m_aTeamSize[TEAM_RED] > 1); } bool HasEnoughPlayers() const { return (IsTeamplay() && m_aTeamSize[TEAM_RED] > 0 && m_aTeamSize[TEAM_BLUE] > 0) || (!IsTeamplay() && m_aTeamSize[TEAM_RED] > 1); }
void ResetGame(); void ResetGame();

View file

@ -86,7 +86,7 @@ bool CGameControllerCTF::OnEntity(int Index, vec2 Pos)
} }
// game // game
void CGameControllerCTF::DoWincheckMatch() bool CGameControllerCTF::DoWincheckMatch()
{ {
// check score win condition // check score win condition
if((m_GameInfo.m_ScoreLimit > 0 && (m_aTeamscore[TEAM_RED] >= m_GameInfo.m_ScoreLimit || m_aTeamscore[TEAM_BLUE] >= m_GameInfo.m_ScoreLimit)) || if((m_GameInfo.m_ScoreLimit > 0 && (m_aTeamscore[TEAM_RED] >= m_GameInfo.m_ScoreLimit || m_aTeamscore[TEAM_BLUE] >= m_GameInfo.m_ScoreLimit)) ||
@ -95,16 +95,23 @@ void CGameControllerCTF::DoWincheckMatch()
if(m_SuddenDeath) if(m_SuddenDeath)
{ {
if(m_aTeamscore[TEAM_RED]/100 != m_aTeamscore[TEAM_BLUE]/100) if(m_aTeamscore[TEAM_RED]/100 != m_aTeamscore[TEAM_BLUE]/100)
{
EndMatch(); EndMatch();
return true;
}
} }
else else
{ {
if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE]) if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE])
{
EndMatch(); EndMatch();
return true;
}
else else
m_SuddenDeath = 1; m_SuddenDeath = 1;
} }
} }
return false;
} }
// general // general
@ -182,6 +189,9 @@ void CGameControllerCTF::Tick()
GameServer()->SendGameMsg(GAMEMSG_CTF_CAPTURE, fi, F->GetCarrier()->GetPlayer()->GetCID(), Server()->Tick()-F->GetGrabTick(), -1); GameServer()->SendGameMsg(GAMEMSG_CTF_CAPTURE, fi, F->GetCarrier()->GetPlayer()->GetCID(), Server()->Tick()-F->GetGrabTick(), -1);
for(int i = 0; i < 2; i++) for(int i = 0; i < 2; i++)
m_apFlags[i]->Reset(); m_apFlags[i]->Reset();
// do a win check(capture could trigger win condition)
if(DoWincheckMatch())
return;
} }
} }
} }
@ -232,4 +242,6 @@ void CGameControllerCTF::Tick()
} }
} }
} }
// do a win check(grabbing flags could trigger win condition)
DoWincheckMatch();
} }

View file

@ -13,7 +13,7 @@ class CGameControllerCTF : public IGameController
// game // game
class CFlag *m_apFlags[2]; class CFlag *m_apFlags[2];
virtual void DoWincheckMatch(); virtual bool DoWincheckMatch();
public: public:
CGameControllerCTF(class CGameContext *pGameServer); CGameControllerCTF(class CGameContext *pGameServer);