about summary refs log tree commit diff
path: root/src/game/client/components
diff options
context:
space:
mode:
authorJohannes Loher <ghost91@gmx.net>2011-04-04 01:27:23 +0200
committeroy <Tom_Adams@web.de>2011-04-04 17:29:08 +0200
commit1364631211a42b6fc5ed7eb5a7ecb6ab6e7a7422 (patch)
treed64fcc6fa0c2eab22c8bf8faca9e2a435508435a /src/game/client/components
parent0046825953ce635e2044a16ad046ee01660c1ec7 (diff)
downloadzcatch-1364631211a42b6fc5ed7eb5a7ecb6ab6e7a7422.tar.gz
zcatch-1364631211a42b6fc5ed7eb5a7ecb6ab6e7a7422.zip
Added functionality to switch to the next and the previous player while spectating.
Diffstat (limited to 'src/game/client/components')
-rw-r--r--src/game/client/components/spectator.cpp96
-rw-r--r--src/game/client/components/spectator.h2
2 files changed, 98 insertions, 0 deletions
diff --git a/src/game/client/components/spectator.cpp b/src/game/client/components/spectator.cpp
index 050e0608..b3bdff7c 100644
--- a/src/game/client/components/spectator.cpp
+++ b/src/game/client/components/spectator.cpp
@@ -27,6 +27,100 @@ void CSpectator::ConSpectate(IConsole::IResult *pResult, void *pUserData)
 	((CSpectator *)pUserData)->Spectate(pResult->GetInteger(0));
 }
 
+void CSpectator::ConSpectateNext(IConsole::IResult *pResult, void *pUserData)
+{
+	CSpectator *pSelf = (CSpectator *)pUserData;
+	int SelectedSpectator;
+	bool GotNewPlayer = false;
+	
+	if(pSelf->m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW)
+	{
+		for(int i = 0; i < MAX_CLIENTS; i++)
+		{
+			if(!pSelf->m_pClient->m_Snap.m_paPlayerInfos[i] || pSelf->m_pClient->m_Snap.m_paPlayerInfos[i]->m_Team == TEAM_SPECTATORS)
+				continue;
+
+			SelectedSpectator = i;
+			GotNewPlayer = true;
+			break;
+		}
+	}
+	else
+	{
+		for(int i = pSelf->m_pClient->m_Snap.m_SpecInfo.m_SpectatorID + 1; i < MAX_CLIENTS; i++)
+		{
+			if(!pSelf->m_pClient->m_Snap.m_paPlayerInfos[i] || pSelf->m_pClient->m_Snap.m_paPlayerInfos[i]->m_Team == TEAM_SPECTATORS)
+				continue;
+
+			SelectedSpectator = i;
+			GotNewPlayer = true;
+			break;
+		}
+	
+		if(!GotNewPlayer)
+		{
+			for(int i = 0; i < pSelf->m_pClient->m_Snap.m_SpecInfo.m_SpectatorID; i++)
+			{
+				if(!pSelf->m_pClient->m_Snap.m_paPlayerInfos[i] || pSelf->m_pClient->m_Snap.m_paPlayerInfos[i]->m_Team == TEAM_SPECTATORS)
+					continue;
+
+				SelectedSpectator = i;
+				GotNewPlayer = true;
+				break;
+			}
+		}
+	}
+	if(GotNewPlayer)
+		pSelf->Spectate(SelectedSpectator);
+}
+
+void CSpectator::ConSpectatePrevious(IConsole::IResult *pResult, void *pUserData)
+{
+	CSpectator *pSelf = (CSpectator *)pUserData;
+	int SelectedSpectator;
+	bool GotNewPlayer = false;
+	
+	if(pSelf->m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW)
+	{
+		for(int i = MAX_CLIENTS -1; i > -1; i--)
+		{
+			if(!pSelf->m_pClient->m_Snap.m_paPlayerInfos[i] || pSelf->m_pClient->m_Snap.m_paPlayerInfos[i]->m_Team == TEAM_SPECTATORS)
+				continue;
+
+			SelectedSpectator = i;
+			GotNewPlayer = true;
+			break;
+		}
+	}
+	else
+	{
+		for(int i = pSelf->m_pClient->m_Snap.m_SpecInfo.m_SpectatorID - 1; i > -1; i--)
+		{
+			if(!pSelf->m_pClient->m_Snap.m_paPlayerInfos[i] || pSelf->m_pClient->m_Snap.m_paPlayerInfos[i]->m_Team == TEAM_SPECTATORS)
+				continue;
+
+			SelectedSpectator = i;
+			GotNewPlayer = true;
+			break;
+		}
+	
+		if(!GotNewPlayer)
+		{
+			for(int i = MAX_CLIENTS - 1; i > pSelf->m_pClient->m_Snap.m_SpecInfo.m_SpectatorID; i--)
+			{
+				if(!pSelf->m_pClient->m_Snap.m_paPlayerInfos[i] || pSelf->m_pClient->m_Snap.m_paPlayerInfos[i]->m_Team == TEAM_SPECTATORS)
+					continue;
+
+				SelectedSpectator = i;
+				GotNewPlayer = true;
+				break;
+			}
+		}
+	}
+	if(GotNewPlayer)
+		pSelf->Spectate(SelectedSpectator);
+}
+
 CSpectator::CSpectator()
 {
 	OnReset();
@@ -36,6 +130,8 @@ void CSpectator::OnConsoleInit()
 {
 	Console()->Register("+spectate", "", CFGFLAG_CLIENT, ConKeySpectator, this, "Open spectator mode selector");
 	Console()->Register("spectate", "i", CFGFLAG_CLIENT, ConSpectate, this, "Switch spectator mode");
+	Console()->Register("spectate_next", "", CFGFLAG_CLIENT, ConSpectateNext, this, "Spectate the next player");
+	Console()->Register("spectate_previous", "", CFGFLAG_CLIENT, ConSpectatePrevious, this, "Spectate the previous player");
 }
 
 bool CSpectator::OnMouseMove(float x, float y)
diff --git a/src/game/client/components/spectator.h b/src/game/client/components/spectator.h
index 607780f5..7dfbf856 100644
--- a/src/game/client/components/spectator.h
+++ b/src/game/client/components/spectator.h
@@ -21,6 +21,8 @@ class CSpectator : public CComponent
 
 	static void ConKeySpectator(IConsole::IResult *pResult, void *pUserData);
 	static void ConSpectate(IConsole::IResult *pResult, void *pUserData);
+	static void ConSpectateNext(IConsole::IResult *pResult, void *pUserData);
+	static void ConSpectatePrevious(IConsole::IResult *pResult, void *pUserData);
 	
 public:
 	CSpectator();