about summary refs log tree commit diff
path: root/src/game/client
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2011-03-25 11:49:35 +0100
committeroy <Tom_Adams@web.de>2011-03-25 11:49:35 +0100
commit359b806e959fbdced610c2d84d1e12dfe7b58a7e (patch)
treef21443f47c73b40f6c64b6055354a4e36e171244 /src/game/client
parenta4580d451f8e4584f9aaa7b6ebe3380488ee4455 (diff)
downloadzcatch-359b806e959fbdced610c2d84d1e12dfe7b58a7e.tar.gz
zcatch-359b806e959fbdced610c2d84d1e12dfe7b58a7e.zip
added remove_vote command. Closes #47
Diffstat (limited to 'src/game/client')
-rw-r--r--src/game/client/components/voting.cpp52
-rw-r--r--src/game/client/components/voting.h3
-rw-r--r--src/game/client/gameclient.cpp1
3 files changed, 53 insertions, 3 deletions
diff --git a/src/game/client/components/voting.cpp b/src/game/client/components/voting.cpp
index 1f99f4b3..808b6669 100644
--- a/src/game/client/components/voting.cpp
+++ b/src/game/client/components/voting.cpp
@@ -100,6 +100,9 @@ void CVoting::ClearOptions()
 	
 	m_pFirst = 0;
 	m_pLast = 0;
+
+	m_pRecycleFirst = 0;
+	m_pRecycleLast = 0;
 }
 
 void CVoting::OnReset()
@@ -144,11 +147,23 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg)
 	{
 		ClearOptions();
 	}
-	else if(MsgType == NETMSGTYPE_SV_VOTEOPTION)
+	else if(MsgType == NETMSGTYPE_SV_VOTEOPTIONADD)
 	{
-		CNetMsg_Sv_VoteOption *pMsg = (CNetMsg_Sv_VoteOption *)pRawMsg;
+		CNetMsg_Sv_VoteOptionAdd *pMsg = (CNetMsg_Sv_VoteOptionAdd *)pRawMsg;
 	
-		CVoteOption *pOption = (CVoteOption *)m_Heap.Allocate(sizeof(CVoteOption));
+		CVoteOption *pOption;
+		if(m_pRecycleFirst)
+		{
+			pOption = m_pRecycleFirst;
+			m_pRecycleFirst = m_pRecycleFirst->m_pNext;
+			if(m_pRecycleFirst)
+				m_pRecycleFirst->m_pPrev = 0;
+			else
+				m_pRecycleLast = 0;
+		}
+		else
+			pOption = (CVoteOption *)m_Heap.Allocate(sizeof(CVoteOption));
+
 		pOption->m_pNext = 0;
 		pOption->m_pPrev = m_pLast;
 		if(pOption->m_pPrev)
@@ -159,6 +174,37 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg)
 		
 		str_copy(pOption->m_aDescription, pMsg->m_pDescription, sizeof(pOption->m_aDescription));
 	}
+	else if(MsgType == NETMSGTYPE_SV_VOTEOPTIONREMOVE)
+	{
+		CNetMsg_Sv_VoteOptionRemove *pMsg = (CNetMsg_Sv_VoteOptionRemove *)pRawMsg;
+	
+		for(CVoteOption *pOption = m_pFirst; pOption; pOption = pOption->m_pNext)
+		{
+			if(str_comp(pOption->m_aDescription, pMsg->m_pDescription) == 0)
+			{
+				// remove it from the list
+				if(m_pFirst == pOption)
+					m_pFirst = m_pFirst->m_pNext;
+				if(m_pLast == pOption)
+					m_pLast = m_pLast->m_pPrev;
+				if(pOption->m_pPrev)
+					pOption->m_pPrev->m_pNext = pOption->m_pNext;
+				if(pOption->m_pNext)
+					pOption->m_pNext->m_pPrev = pOption->m_pPrev;
+
+				// add it to recycle list
+				pOption->m_pNext = 0;
+				pOption->m_pPrev = m_pRecycleLast;
+				if(pOption->m_pPrev)
+					pOption->m_pPrev->m_pNext = pOption;
+				m_pRecycleLast = pOption;
+				if(!m_pRecycleFirst)
+					m_pRecycleLast = pOption;
+
+				break;
+			}
+		}
+	}
 }
 
 void CVoting::OnRender()
diff --git a/src/game/client/components/voting.h b/src/game/client/components/voting.h
index 10e0512c..9687d895 100644
--- a/src/game/client/components/voting.h
+++ b/src/game/client/components/voting.h
@@ -34,6 +34,9 @@ public:
 	CVoteOption *m_pFirst;
 	CVoteOption *m_pLast;
 
+	CVoteOption *m_pRecycleFirst;
+	CVoteOption *m_pRecycleLast;
+
 	CVoting();
 	virtual void OnReset();
 	virtual void OnConsoleInit();
diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp
index c6419b34..4d80e0f1 100644
--- a/src/game/client/gameclient.cpp
+++ b/src/game/client/gameclient.cpp
@@ -198,6 +198,7 @@ void CGameClient::OnConsoleInit()
 	Console()->Register("set_team", "ii", CFGFLAG_SERVER, 0, 0, "Set team of player to team");
 	Console()->Register("set_team_all", "i", CFGFLAG_SERVER, 0, 0, "Set team of all players to team");
 	Console()->Register("add_vote", "sr", CFGFLAG_SERVER, 0, 0, "Add a voting option");
+	Console()->Register("remove_vote", "s", CFGFLAG_SERVER, 0, 0, "remove a voting option");
 	Console()->Register("clear_votes", "", CFGFLAG_SERVER, 0, 0, "Clears the voting options");
 	Console()->Register("vote", "r", CFGFLAG_SERVER, 0, 0, "Force a vote to yes/no");