[bot] Implement/match CScriptTimers::Process(...)

This commit is contained in:
RD42 2024-08-29 23:25:43 +08:00
parent 4c3bfe503f
commit 2d911feb2a
2 changed files with 57 additions and 0 deletions

View File

@ -1,6 +1,8 @@
#include "main.h" #include "main.h"
extern CNetGame* pNetGame;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
CScriptTimers::CScriptTimers() CScriptTimers::CScriptTimers()
@ -106,3 +108,57 @@ void CScriptTimers::Kill(DWORD dwTimerId)
//----------------------------------------------------------- //-----------------------------------------------------------
void CScriptTimers::Process(int iElapsedTime)
{
DwordTimerMap::iterator itor;
CGameMode *pGameMode;
for (itor = m_Timers.begin(); itor != m_Timers.end(); itor++)
{
itor->second->iRemainingTime -= iElapsedTime;
if (itor->second->iRemainingTime <= 0)
{
DwordTimerMap::iterator itor_tmp = ++itor; itor--;
if (!itor->second->bKilled)
{
pGameMode = pNetGame->GetBotMode();
if (pGameMode)
{
int idx;
AMX* amx = itor->second->pAMX;
if (amx && !amx_FindPublic(amx, itor->second->szScriptFunc, &idx))
{
cell ret;
int count = itor->second->iParamCount;
int i = 0;
if (count > 0)
{
cell* pars = (cell*)itor->second->cellParams;
while (i < count)
{
amx_Push(amx, pars[i]);
i++; // Go forwards to maintain push order
}
}
amx_Exec(amx, &ret, idx);
}
}
}
if (itor->second->bRepeating)
{
itor->second->iRemainingTime = itor->second->iTotalTime;
}
else
{
// Release parameter memory
FreeMem(itor->second);
Delete(itor->first);
}
itor = itor_tmp;
}
if (itor == m_Timers.end()) break;
}
}
//----------------------------------------------------------------------------------
// EOF

View File

@ -31,6 +31,7 @@ public:
DWORD New(char* szScriptFunc, int iInterval, BOOL bRepeating, AMX* pAMX); DWORD New(char* szScriptFunc, int iInterval, BOOL bRepeating, AMX* pAMX);
void Delete(DWORD dwTimerId); void Delete(DWORD dwTimerId);
void Kill(DWORD dwTimerId); void Kill(DWORD dwTimerId);
void Process(int iElapsedTime);
void FreeMem(ScriptTimer_s* Timer); void FreeMem(ScriptTimer_s* Timer);
}; };