From 340ac89967e2fb1ca3eef3a3f5a73b7ba7f67f8f Mon Sep 17 00:00:00 2001 From: oy Date: Wed, 15 Feb 2012 01:39:54 +0100 Subject: [PATCH] added rounds, wincheck and start equipment for survival --- src/game/server/gamecontroller.cpp | 59 ++++++++++++++++++++++++++---- src/game/server/gamecontroller.h | 9 +++-- src/game/server/gamemodes/ctf.cpp | 2 +- src/game/server/gamemodes/ctf.h | 2 +- src/game/server/gamemodes/sur.cpp | 29 +++++++++++++++ src/game/server/gamemodes/sur.h | 3 ++ 6 files changed, 92 insertions(+), 12 deletions(-) diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 1978ec747..09e15fcd9 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -231,12 +231,27 @@ int IGameController::OnCharacterDeath(class CCharacter *pVictim, class CPlayer * void IGameController::OnCharacterSpawn(class CCharacter *pChr) { - // default health - pChr->IncreaseHealth(10); + if(m_GameFlags&GAMEFLAG_SURVIVAL) + { + // give start equipment + pChr->IncreaseHealth(10); + pChr->IncreaseArmor(5); - // give default weapons - pChr->GiveWeapon(WEAPON_HAMMER, -1); - pChr->GiveWeapon(WEAPON_GUN, 10); + pChr->GiveWeapon(WEAPON_HAMMER, -1); + pChr->GiveWeapon(WEAPON_GUN, 10); + pChr->GiveWeapon(WEAPON_SHOTGUN, 10); + pChr->GiveWeapon(WEAPON_GRENADE, 10); + pChr->GiveWeapon(WEAPON_RIFLE, 5); + } + else + { + // default health + pChr->IncreaseHealth(10); + + // give default weapons + pChr->GiveWeapon(WEAPON_HAMMER, -1); + pChr->GiveWeapon(WEAPON_GUN, 10); + } } bool IGameController::OnEntity(int Index, vec2 Pos) @@ -347,7 +362,7 @@ void IGameController::OnReset() } // game -void IGameController::DoWincheck() +void IGameController::DoWincheckMatch() { if(IsTeamplay()) { @@ -397,6 +412,11 @@ void IGameController::EndMatch() SetGameState(GS_GAMEOVER, 10); } +void IGameController::EndRound() +{ + SetGameState(GS_ROUNDOVER, 10); +} + void IGameController::ResetGame() { GameServer()->m_World.m_ResetRequested = true; @@ -479,6 +499,17 @@ void IGameController::SetGameState(int GameState, int Seconds) } } break; + case GS_ROUNDOVER: + { + if(GetGameState() != GS_WARMUP && GetGameState() != GS_PAUSED) + { + m_GameState = GS_ROUNDOVER; + m_GameStateTimer = Seconds*Server()->TickSpeed(); + m_SuddenDeath = 0; + GameServer()->m_World.m_Paused = true; + } + } + break; case GS_GAMEOVER: { if(GetGameState() != GS_WARMUP && GetGameState() != GS_PAUSED) @@ -587,6 +618,15 @@ void IGameController::Tick() else ++m_GameStartTick; break; + case GS_ROUNDOVER: + if(m_GameStateTimer == 0) + { + ResetGame(); + DoWincheckMatch(); + SetGameState(GS_STARTCOUNTDOWN, TIMER_STARTCOUNTDOWN); + m_StartCountdownReset = false; + } + break; case GS_GAMEOVER: if(m_GameStateTimer == 0) { @@ -615,7 +655,12 @@ void IGameController::Tick() // win check if(GetGameState() == GS_GAME && !GameServer()->m_World.m_ResetRequested) - DoWincheck(); + { + if(m_GameFlags&GAMEFLAG_SURVIVAL) + DoWincheckRound(); + else + DoWincheckMatch(); + } } // info diff --git a/src/game/server/gamecontroller.h b/src/game/server/gamecontroller.h index 3b284a0cb..89d2709a8 100644 --- a/src/game/server/gamecontroller.h +++ b/src/game/server/gamecontroller.h @@ -39,8 +39,11 @@ class IGameController int m_GameStateTimer; bool m_StartCountdownReset; - virtual void DoWincheck(); + virtual void DoWincheckMatch(); + virtual void DoWincheckRound() {}; + void ResetGame(); void SetGameState(int GameState, int Seconds=0); + void StartMatch(); // map char m_aMapWish[128]; @@ -82,8 +85,7 @@ protected: int m_aTeamscore[NUM_TEAMS]; void EndMatch(); - void ResetGame(); - void StartMatch(); + void EndRound(); // info int m_GameFlags; @@ -140,6 +142,7 @@ public: GS_STARTCOUNTDOWN, GS_GAME, GS_PAUSED, + GS_ROUNDOVER, GS_GAMEOVER, TIMER_INFINITE = -1, diff --git a/src/game/server/gamemodes/ctf.cpp b/src/game/server/gamemodes/ctf.cpp index e9ddc68ee..b0cc69e0f 100644 --- a/src/game/server/gamemodes/ctf.cpp +++ b/src/game/server/gamemodes/ctf.cpp @@ -85,7 +85,7 @@ bool CGameControllerCTF::OnEntity(int Index, vec2 Pos) } // game -void CGameControllerCTF::DoWincheck() +void CGameControllerCTF::DoWincheckMatch() { // 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)) || diff --git a/src/game/server/gamemodes/ctf.h b/src/game/server/gamemodes/ctf.h index f61f6df7e..45ca184c6 100644 --- a/src/game/server/gamemodes/ctf.h +++ b/src/game/server/gamemodes/ctf.h @@ -13,7 +13,7 @@ class CGameControllerCTF : public IGameController // game class CFlag *m_apFlags[2]; - virtual void DoWincheck(); + virtual void DoWincheckMatch(); public: CGameControllerCTF(class CGameContext *pGameServer); diff --git a/src/game/server/gamemodes/sur.cpp b/src/game/server/gamemodes/sur.cpp index 2452a6a7e..46f19fbc9 100644 --- a/src/game/server/gamemodes/sur.cpp +++ b/src/game/server/gamemodes/sur.cpp @@ -13,6 +13,35 @@ CGameControllerSUR::CGameControllerSUR(class CGameContext *pGameServer) : IGameC m_GameFlags = GAMEFLAG_TEAMS|GAMEFLAG_SURVIVAL; } +// game +void CGameControllerSUR::DoWincheckRound() +{ + int Count[2] = {0}; + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && + GameServer()->m_apPlayers[i]->GetCharacter() && GameServer()->m_apPlayers[i]->GetCharacter()->IsAlive()) + ++Count[GameServer()->m_apPlayers[i]->GetTeam()]; + } + + if(Count[TEAM_RED]+Count[TEAM_BLUE] == 0 || (g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_GameStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60)) + { + ++m_aTeamscore[TEAM_BLUE]; + ++m_aTeamscore[TEAM_RED]; + EndRound(); + } + else if(Count[TEAM_RED] == 0) + { + ++m_aTeamscore[TEAM_BLUE]; + EndRound(); + } + else if(Count[TEAM_BLUE] == 0) + { + ++m_aTeamscore[TEAM_RED]; + EndRound(); + } +} + // general void CGameControllerSUR::Snap(int SnappingClient) { diff --git a/src/game/server/gamemodes/sur.h b/src/game/server/gamemodes/sur.h index efe30f4aa..69be296bb 100644 --- a/src/game/server/gamemodes/sur.h +++ b/src/game/server/gamemodes/sur.h @@ -9,6 +9,9 @@ class CGameControllerSUR : public IGameController public: CGameControllerSUR(class CGameContext *pGameServer); + // game + virtual void DoWincheckRound(); + // general virtual void Snap(int SnappingClient); };