added rounds, wincheck and start equipment for survival

This commit is contained in:
oy 2012-02-15 01:39:54 +01:00
parent 98c18ebade
commit 340ac89967
6 changed files with 92 additions and 12 deletions

View file

@ -231,12 +231,27 @@ int IGameController::OnCharacterDeath(class CCharacter *pVictim, class CPlayer *
void IGameController::OnCharacterSpawn(class CCharacter *pChr) void IGameController::OnCharacterSpawn(class CCharacter *pChr)
{ {
// default health if(m_GameFlags&GAMEFLAG_SURVIVAL)
pChr->IncreaseHealth(10); {
// give start equipment
pChr->IncreaseHealth(10);
pChr->IncreaseArmor(5);
// give default weapons pChr->GiveWeapon(WEAPON_HAMMER, -1);
pChr->GiveWeapon(WEAPON_HAMMER, -1); pChr->GiveWeapon(WEAPON_GUN, 10);
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) bool IGameController::OnEntity(int Index, vec2 Pos)
@ -347,7 +362,7 @@ void IGameController::OnReset()
} }
// game // game
void IGameController::DoWincheck() void IGameController::DoWincheckMatch()
{ {
if(IsTeamplay()) if(IsTeamplay())
{ {
@ -397,6 +412,11 @@ void IGameController::EndMatch()
SetGameState(GS_GAMEOVER, 10); SetGameState(GS_GAMEOVER, 10);
} }
void IGameController::EndRound()
{
SetGameState(GS_ROUNDOVER, 10);
}
void IGameController::ResetGame() void IGameController::ResetGame()
{ {
GameServer()->m_World.m_ResetRequested = true; GameServer()->m_World.m_ResetRequested = true;
@ -479,6 +499,17 @@ void IGameController::SetGameState(int GameState, int Seconds)
} }
} }
break; 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: case GS_GAMEOVER:
{ {
if(GetGameState() != GS_WARMUP && GetGameState() != GS_PAUSED) if(GetGameState() != GS_WARMUP && GetGameState() != GS_PAUSED)
@ -587,6 +618,15 @@ void IGameController::Tick()
else else
++m_GameStartTick; ++m_GameStartTick;
break; break;
case GS_ROUNDOVER:
if(m_GameStateTimer == 0)
{
ResetGame();
DoWincheckMatch();
SetGameState(GS_STARTCOUNTDOWN, TIMER_STARTCOUNTDOWN);
m_StartCountdownReset = false;
}
break;
case GS_GAMEOVER: case GS_GAMEOVER:
if(m_GameStateTimer == 0) if(m_GameStateTimer == 0)
{ {
@ -615,7 +655,12 @@ void IGameController::Tick()
// win check // win check
if(GetGameState() == GS_GAME && !GameServer()->m_World.m_ResetRequested) if(GetGameState() == GS_GAME && !GameServer()->m_World.m_ResetRequested)
DoWincheck(); {
if(m_GameFlags&GAMEFLAG_SURVIVAL)
DoWincheckRound();
else
DoWincheckMatch();
}
} }
// info // info

View file

@ -39,8 +39,11 @@ class IGameController
int m_GameStateTimer; int m_GameStateTimer;
bool m_StartCountdownReset; bool m_StartCountdownReset;
virtual void DoWincheck(); virtual void DoWincheckMatch();
virtual void DoWincheckRound() {};
void ResetGame();
void SetGameState(int GameState, int Seconds=0); void SetGameState(int GameState, int Seconds=0);
void StartMatch();
// map // map
char m_aMapWish[128]; char m_aMapWish[128];
@ -82,8 +85,7 @@ protected:
int m_aTeamscore[NUM_TEAMS]; int m_aTeamscore[NUM_TEAMS];
void EndMatch(); void EndMatch();
void ResetGame(); void EndRound();
void StartMatch();
// info // info
int m_GameFlags; int m_GameFlags;
@ -140,6 +142,7 @@ public:
GS_STARTCOUNTDOWN, GS_STARTCOUNTDOWN,
GS_GAME, GS_GAME,
GS_PAUSED, GS_PAUSED,
GS_ROUNDOVER,
GS_GAMEOVER, GS_GAMEOVER,
TIMER_INFINITE = -1, TIMER_INFINITE = -1,

View file

@ -85,7 +85,7 @@ bool CGameControllerCTF::OnEntity(int Index, vec2 Pos)
} }
// game // game
void CGameControllerCTF::DoWincheck() void CGameControllerCTF::DoWincheckMatch()
{ {
// check score win condition // 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)) || if((g_Config.m_SvScorelimit > 0 && (m_aTeamscore[TEAM_RED] >= g_Config.m_SvScorelimit || m_aTeamscore[TEAM_BLUE] >= g_Config.m_SvScorelimit)) ||

View file

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

View file

@ -13,6 +13,35 @@ CGameControllerSUR::CGameControllerSUR(class CGameContext *pGameServer) : IGameC
m_GameFlags = GAMEFLAG_TEAMS|GAMEFLAG_SURVIVAL; 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 // general
void CGameControllerSUR::Snap(int SnappingClient) void CGameControllerSUR::Snap(int SnappingClient)
{ {

View file

@ -9,6 +9,9 @@ class CGameControllerSUR : public IGameController
public: public:
CGameControllerSUR(class CGameContext *pGameServer); CGameControllerSUR(class CGameContext *pGameServer);
// game
virtual void DoWincheckRound();
// general // general
virtual void Snap(int SnappingClient); virtual void Snap(int SnappingClient);
}; };