Extract CVoting::RemoveOption function

This commit is contained in:
Robert Müller 2024-01-29 23:17:12 +01:00
parent c1549635c6
commit df95ca74ec
2 changed files with 33 additions and 28 deletions

View file

@ -177,6 +177,37 @@ void CVoting::AddOption(const char *pDescription)
++m_NumVoteOptions; ++m_NumVoteOptions;
} }
void CVoting::RemoveOption(const char *pDescription)
{
for(CVoteOptionClient *pOption = m_pFirst; pOption; pOption = pOption->m_pNext)
{
if(str_comp(pOption->m_aDescription, 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;
--m_NumVoteOptions;
// 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::ClearOptions() void CVoting::ClearOptions()
{ {
m_Heap.Reset(); m_Heap.Reset();
@ -271,34 +302,7 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg)
else if(MsgType == NETMSGTYPE_SV_VOTEOPTIONREMOVE) else if(MsgType == NETMSGTYPE_SV_VOTEOPTIONREMOVE)
{ {
CNetMsg_Sv_VoteOptionRemove *pMsg = (CNetMsg_Sv_VoteOptionRemove *)pRawMsg; CNetMsg_Sv_VoteOptionRemove *pMsg = (CNetMsg_Sv_VoteOptionRemove *)pRawMsg;
RemoveOption(pMsg->m_pDescription);
for(CVoteOptionClient *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;
--m_NumVoteOptions;
// 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;
}
}
} }
else if(MsgType == NETMSGTYPE_SV_YOURVOTE) else if(MsgType == NETMSGTYPE_SV_YOURVOTE)
{ {

View file

@ -25,6 +25,7 @@ class CVoting : public CComponent
int m_Yes, m_No, m_Pass, m_Total; int m_Yes, m_No, m_Pass, m_Total;
void AddOption(const char *pDescription); void AddOption(const char *pDescription);
void RemoveOption(const char *pDescription);
void ClearOptions(); void ClearOptions();
void Callvote(const char *pType, const char *pValue, const char *pReason); void Callvote(const char *pType, const char *pValue, const char *pReason);