2004-03-06 00:03:14 +03:00
|
|
|
/* AMX Mod X
|
2004-02-21 22:36:35 +03:00
|
|
|
*
|
2004-03-06 00:03:14 +03:00
|
|
|
* by the AMX Mod X Development Team
|
|
|
|
* originally developed by OLO
|
2004-02-21 22:36:35 +03:00
|
|
|
*
|
|
|
|
*
|
2004-03-06 00:03:14 +03:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
2004-02-21 22:36:35 +03:00
|
|
|
*
|
2004-03-06 00:03:14 +03:00
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
2004-02-21 22:36:35 +03:00
|
|
|
*
|
2004-03-06 00:03:14 +03:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2004-02-21 22:36:35 +03:00
|
|
|
*
|
2004-03-06 00:03:14 +03:00
|
|
|
* In addition, as a special exception, the author gives permission to
|
|
|
|
* link the code of this program with the Half-Life Game Engine ("HL
|
|
|
|
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
|
|
|
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
|
|
|
* respects for all of the code used other than the HL Engine and MODs
|
|
|
|
* from Valve. If you modify this file, you may extend this exception
|
|
|
|
* to your version of the file, but you are not obligated to do so. If
|
|
|
|
* you do not wish to do so, delete this exception statement from your
|
|
|
|
* version.
|
2004-02-21 22:36:35 +03:00
|
|
|
*/
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2004-03-24 04:35:44 +03:00
|
|
|
#include "amxmodx.h"
|
2004-01-31 23:56:22 +03:00
|
|
|
#include "CEvent.h"
|
|
|
|
|
|
|
|
// *****************************************************
|
2004-02-26 22:04:53 +03:00
|
|
|
// class ClEvent
|
2004-01-31 23:56:22 +03:00
|
|
|
// *****************************************************
|
2004-02-26 22:04:53 +03:00
|
|
|
|
2005-09-10 07:39:23 +04:00
|
|
|
EventsMngr::ClEvent::ClEvent(CPluginMngr::CPlugin* plugin, int func, int flags)
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
|
|
|
m_Plugin = plugin;
|
|
|
|
m_Func = func;
|
|
|
|
|
|
|
|
// flags
|
2004-03-11 17:22:06 +03:00
|
|
|
m_FlagAlive = true;
|
|
|
|
m_FlagDead = true;
|
|
|
|
|
2005-09-10 07:39:23 +04:00
|
|
|
m_FlagWorld = (flags & 1) ? true : false; // flag a
|
|
|
|
m_FlagPlayer = (flags & 2) ? true : false; // flag b
|
|
|
|
m_FlagOnce = (flags & 4) ? true : false; // flag c
|
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
if (flags & 24)
|
|
|
|
{
|
2005-09-10 07:39:23 +04:00
|
|
|
m_FlagAlive = (flags & 16) ? true : false; // flag e
|
|
|
|
m_FlagDead = (flags & 8) ? true : false; // flag d
|
2004-02-26 22:04:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
m_Stamp = 0.0f;
|
|
|
|
m_Done = false;
|
2004-03-14 16:57:27 +03:00
|
|
|
|
|
|
|
m_Conditions = NULL;
|
2004-02-26 22:04:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
EventsMngr::ClEvent::~ClEvent()
|
|
|
|
{
|
2004-03-14 16:57:27 +03:00
|
|
|
cond_t *tmp1 = m_Conditions;
|
|
|
|
cond_t *tmp2 = NULL;
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
while (tmp1)
|
|
|
|
{
|
|
|
|
tmp2 = tmp1->next;
|
|
|
|
delete tmp1;
|
|
|
|
tmp1 = tmp2;
|
|
|
|
}
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
m_Conditions = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventsMngr::NextParam()
|
|
|
|
{
|
|
|
|
const int INITIAL_PARSEVAULT_SIZE = 32;
|
|
|
|
|
|
|
|
if (m_ParsePos < m_ParseVaultSize)
|
|
|
|
return;
|
2004-02-26 22:04:53 +03:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
MsgDataEntry *tmp = NULL;
|
|
|
|
int tmpSize = 0;
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
if (m_ParseVault)
|
|
|
|
{
|
|
|
|
// copy to tmp
|
|
|
|
tmp = new MsgDataEntry[m_ParseVaultSize];
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-05-28 15:24:59 +04:00
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
return; // :TODO: Error report !!
|
|
|
|
}
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
memcpy(tmp, m_ParseVault, m_ParseVaultSize * sizeof(MsgDataEntry));
|
|
|
|
tmpSize = m_ParseVaultSize;
|
|
|
|
delete [] m_ParseVault;
|
|
|
|
m_ParseVault = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_ParseVaultSize > 0)
|
|
|
|
m_ParseVaultSize *= 2;
|
|
|
|
else
|
|
|
|
m_ParseVaultSize = INITIAL_PARSEVAULT_SIZE;
|
|
|
|
|
|
|
|
m_ParseVault = new MsgDataEntry[m_ParseVaultSize];
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
if (tmp)
|
|
|
|
{
|
|
|
|
memcpy(m_ParseVault, tmp, tmpSize * sizeof(MsgDataEntry));
|
|
|
|
delete [] tmp;
|
|
|
|
tmp = NULL;
|
|
|
|
}
|
2004-02-26 22:04:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int EventsMngr::ClEvent::getFunction()
|
|
|
|
{
|
|
|
|
return m_Func;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventsMngr::EventsMngr()
|
|
|
|
{
|
2004-03-14 16:57:27 +03:00
|
|
|
m_ParseVault = NULL;
|
|
|
|
m_ParseVaultSize = 0;
|
2004-04-03 23:15:43 +04:00
|
|
|
m_CurrentMsgType = -1;
|
2004-02-26 22:04:53 +03:00
|
|
|
clearEvents();
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
2004-02-26 22:04:53 +03:00
|
|
|
|
2004-01-31 23:56:22 +03:00
|
|
|
EventsMngr::~EventsMngr()
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-01-31 23:56:22 +03:00
|
|
|
clearEvents();
|
|
|
|
}
|
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
|
|
|
|
CPluginMngr::CPlugin * EventsMngr::ClEvent::getPlugin()
|
|
|
|
{
|
|
|
|
return m_Plugin;
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
// *****************************************************
|
|
|
|
// class EventsMngr
|
|
|
|
// *****************************************************
|
|
|
|
|
|
|
|
void EventsMngr::ClEvent::registerFilter(char *filter)
|
2004-01-31 23:56:22 +03:00
|
|
|
{
|
2004-02-26 22:04:53 +03:00
|
|
|
// filters (conditions) have the form x&y
|
|
|
|
// x is the param number
|
|
|
|
// & may also be other characters
|
|
|
|
// y is a string or a number
|
|
|
|
if (!filter)
|
|
|
|
return;
|
2004-01-31 23:56:22 +03:00
|
|
|
|
|
|
|
char* value = filter;
|
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
// get the first numbr
|
|
|
|
while (isdigit(*value))
|
2004-01-31 23:56:22 +03:00
|
|
|
++value;
|
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
// end of string => ignore
|
|
|
|
if (!*value)
|
|
|
|
return;
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
cond_t *tmpCond = new cond_t;
|
|
|
|
if (!tmpCond)
|
|
|
|
return;
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
// type character
|
2004-03-14 16:57:27 +03:00
|
|
|
tmpCond->type = *value;
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
// set a null here so param id can be recognized, and save it
|
2004-01-31 23:56:22 +03:00
|
|
|
*value++ = 0;
|
2004-03-14 16:57:27 +03:00
|
|
|
tmpCond->paramId = atoi(filter);
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
// rest of line
|
2004-08-13 12:46:04 +04:00
|
|
|
tmpCond->sValue.assign(value);
|
2005-08-27 13:55:32 +04:00
|
|
|
tmpCond->fValue = static_cast<float>(atof(value));
|
2004-03-14 16:57:27 +03:00
|
|
|
tmpCond->iValue = atoi(value);
|
|
|
|
|
|
|
|
tmpCond->next = NULL;
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
if (m_Conditions)
|
|
|
|
{
|
|
|
|
cond_t *tmp = m_Conditions;
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
while (tmp->next)
|
|
|
|
tmp = tmp->next;
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
tmp->next = tmpCond;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_Conditions = tmpCond;
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
EventsMngr::ClEvent* EventsMngr::registerEvent(CPluginMngr::CPlugin* plugin, int func, int flags, int msgid)
|
2004-01-31 23:56:22 +03:00
|
|
|
{
|
2004-02-26 22:04:53 +03:00
|
|
|
// validate parameter
|
|
|
|
if (msgid < 0 || msgid >= MAX_AMX_REG_MSG)
|
|
|
|
return NULL;
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
ClEvent *event = new ClEvent(plugin, func, flags);
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
if (!event)
|
|
|
|
return NULL;
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
m_Events[msgid].put(event);
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int index)
|
2004-01-31 23:56:22 +03:00
|
|
|
{
|
2004-02-26 22:04:53 +03:00
|
|
|
if (msg_type < 0 || msg_type > MAX_AMX_REG_MSG)
|
|
|
|
return;
|
|
|
|
|
2004-04-03 23:15:43 +04:00
|
|
|
m_CurrentMsgType = msg_type;
|
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
m_ParseNotDone = false;
|
|
|
|
m_Timer = timer;
|
|
|
|
|
|
|
|
// don't parse if nothing to do
|
2004-03-14 16:57:27 +03:00
|
|
|
if (!m_Events[msg_type].size())
|
2004-02-26 22:04:53 +03:00
|
|
|
return;
|
|
|
|
|
2005-09-10 07:39:23 +04:00
|
|
|
for (ClEventVecIter iter = m_Events[msg_type].begin(); iter; ++iter)
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-14 16:57:27 +03:00
|
|
|
if ((*iter).m_Done)
|
2004-02-26 22:04:53 +03:00
|
|
|
continue;
|
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
if (!(*iter).m_Plugin->isExecutable((*iter).m_Func))
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-14 16:57:27 +03:00
|
|
|
(*iter).m_Done = true;
|
2004-02-26 22:04:53 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pPlayer)
|
|
|
|
{
|
2005-09-10 07:39:23 +04:00
|
|
|
if (!(*iter).m_FlagPlayer || (pPlayer->IsAlive() ? !(*iter).m_FlagAlive : !(*iter).m_FlagDead))
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-14 16:57:27 +03:00
|
|
|
(*iter).m_Done = true;
|
2004-02-26 22:04:53 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2004-03-14 16:57:27 +03:00
|
|
|
else if (!(*iter).m_FlagWorld)
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-14 16:57:27 +03:00
|
|
|
(*iter).m_Done = true;
|
2004-02-26 22:04:53 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
if ((*iter).m_FlagOnce && (*iter).m_Stamp == (float)(*timer))
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-14 16:57:27 +03:00
|
|
|
(*iter).m_Done = true;
|
2004-02-26 22:04:53 +03:00
|
|
|
continue;
|
|
|
|
}
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
m_ParseNotDone = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_ParseNotDone)
|
|
|
|
{
|
|
|
|
m_ParsePos = 0;
|
2004-03-14 16:57:27 +03:00
|
|
|
NextParam();
|
2004-03-17 21:57:36 +03:00
|
|
|
m_ParseVault[0].type = MSG_INTEGER;
|
|
|
|
m_ParseVault[0].iValue = index;
|
2004-03-11 16:48:57 +03:00
|
|
|
}
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
m_ParseFun = &m_Events[msg_type];
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
void EventsMngr::parseValue(int iValue)
|
2004-01-31 23:56:22 +03:00
|
|
|
{
|
2004-02-26 22:04:53 +03:00
|
|
|
// not parsing
|
|
|
|
if (!m_ParseNotDone || !m_ParseFun)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// grow if needed
|
2004-03-14 16:57:27 +03:00
|
|
|
++m_ParsePos;
|
|
|
|
NextParam();
|
2004-02-26 22:04:53 +03:00
|
|
|
|
|
|
|
m_ParseVault[m_ParsePos].type = MSG_INTEGER;
|
|
|
|
m_ParseVault[m_ParsePos].iValue = iValue;
|
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
// loop through the registered funcs, and decide whether they have to be called or not
|
|
|
|
// if they shouldnt, their m_Done is set to true
|
|
|
|
for (ClEventVecIter iter = m_ParseFun->begin(); iter; ++iter)
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-14 16:57:27 +03:00
|
|
|
if ((*iter).m_Done)
|
|
|
|
continue; // already skipped; don't bother with parsing
|
2004-02-26 22:04:53 +03:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
// loop through conditions
|
2004-03-17 21:57:36 +03:00
|
|
|
bool execute = false;
|
|
|
|
bool anyConditions = false;
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-14 16:57:27 +03:00
|
|
|
if (condIter->paramId == m_ParsePos)
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-17 21:57:36 +03:00
|
|
|
anyConditions = true;
|
2004-03-14 16:57:27 +03:00
|
|
|
switch(condIter->type)
|
|
|
|
{
|
2005-09-10 07:39:23 +04:00
|
|
|
case '=': if (condIter->iValue == iValue) execute = true; break;
|
|
|
|
case '!': if (condIter->iValue != iValue) execute = true; break;
|
|
|
|
case '&': if (iValue & condIter->iValue) execute = true; break;
|
|
|
|
case '<': if (iValue < condIter->iValue) execute = true; break;
|
|
|
|
case '>': if (iValue > condIter->iValue) execute = true; break;
|
2004-03-14 16:57:27 +03:00
|
|
|
}
|
|
|
|
if (execute)
|
2004-03-17 21:57:36 +03:00
|
|
|
break;
|
2004-03-14 16:57:27 +03:00
|
|
|
}
|
|
|
|
}
|
2004-03-17 21:57:36 +03:00
|
|
|
if (anyConditions && !execute)
|
|
|
|
(*iter).m_Done = true; // don't execute
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
void EventsMngr::parseValue(float fValue)
|
2004-01-31 23:56:22 +03:00
|
|
|
{
|
2004-02-26 22:04:53 +03:00
|
|
|
// not parsing
|
|
|
|
if (!m_ParseNotDone || !m_ParseFun)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// grow if needed
|
2004-03-14 16:57:27 +03:00
|
|
|
++m_ParsePos;
|
|
|
|
NextParam();
|
2004-02-26 22:04:53 +03:00
|
|
|
|
|
|
|
m_ParseVault[m_ParsePos].type = MSG_FLOAT;
|
|
|
|
m_ParseVault[m_ParsePos].fValue = fValue;
|
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
// loop through the registered funcs, and decide whether they have to be called or not
|
|
|
|
// if they shouldnt, their m_Done is set to true
|
|
|
|
for (ClEventVecIter iter = m_ParseFun->begin(); iter; ++iter)
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-14 16:57:27 +03:00
|
|
|
if ((*iter).m_Done)
|
|
|
|
continue; // already skipped; don't bother with parsing
|
2004-02-26 22:04:53 +03:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
// loop through conditions
|
2004-03-17 21:57:36 +03:00
|
|
|
bool execute = false;
|
|
|
|
bool anyConditions = false;
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-14 16:57:27 +03:00
|
|
|
if (condIter->paramId == m_ParsePos)
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-17 21:57:36 +03:00
|
|
|
anyConditions = true;
|
2004-03-14 16:57:27 +03:00
|
|
|
switch(condIter->type)
|
|
|
|
{
|
2005-09-10 07:39:23 +04:00
|
|
|
case '=': if (condIter->fValue == fValue) execute = true; break;
|
|
|
|
case '!': if (condIter->fValue != fValue) execute = true; break;
|
|
|
|
case '<': if (fValue < condIter->fValue) execute = true; break;
|
|
|
|
case '>': if (fValue > condIter->fValue) execute = true; break;
|
2004-03-14 16:57:27 +03:00
|
|
|
}
|
|
|
|
if (execute)
|
2004-03-17 21:57:36 +03:00
|
|
|
break;
|
2004-03-14 16:57:27 +03:00
|
|
|
}
|
|
|
|
}
|
2004-03-17 21:57:36 +03:00
|
|
|
if (anyConditions && !execute)
|
|
|
|
(*iter).m_Done = true; // don't execute
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
void EventsMngr::parseValue(const char *sz)
|
|
|
|
{
|
|
|
|
// not parsing
|
|
|
|
if (!m_ParseNotDone || !m_ParseFun)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// grow if needed
|
2004-03-14 16:57:27 +03:00
|
|
|
++m_ParsePos;
|
|
|
|
NextParam();
|
2004-02-26 22:04:53 +03:00
|
|
|
|
|
|
|
m_ParseVault[m_ParsePos].type = MSG_STRING;
|
|
|
|
m_ParseVault[m_ParsePos].sValue = sz;
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
// loop through the registered funcs, and decide whether they have to be called or not
|
|
|
|
// if they shouldnt, their m_Done is set to true
|
|
|
|
for (ClEventVecIter iter = m_ParseFun->begin(); iter; ++iter)
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-14 16:57:27 +03:00
|
|
|
if ((*iter).m_Done)
|
|
|
|
continue; // already skipped; don't bother with parsing
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
// loop through conditions
|
2004-03-17 21:57:36 +03:00
|
|
|
bool execute = false;
|
|
|
|
bool anyConditions = false;
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-03-14 16:57:27 +03:00
|
|
|
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-14 16:57:27 +03:00
|
|
|
if (condIter->paramId == m_ParsePos)
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2004-03-17 21:57:36 +03:00
|
|
|
anyConditions = true;
|
2004-03-14 16:57:27 +03:00
|
|
|
switch(condIter->type)
|
|
|
|
{
|
2005-09-10 07:39:23 +04:00
|
|
|
case '=': if (!strcmp(sz, condIter->sValue.c_str())) execute = true; break;
|
|
|
|
case '!': if (strcmp(sz, condIter->sValue.c_str())) execute = true; break;
|
|
|
|
case '&': if (strstr(sz, condIter->sValue.c_str())) execute = true; break;
|
2004-03-14 16:57:27 +03:00
|
|
|
}
|
|
|
|
if (execute)
|
2004-03-17 21:57:36 +03:00
|
|
|
break;
|
2004-03-14 16:57:27 +03:00
|
|
|
}
|
|
|
|
}
|
2004-03-17 21:57:36 +03:00
|
|
|
if (anyConditions && !execute)
|
|
|
|
(*iter).m_Done = true; // don't execute
|
2004-02-26 22:04:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventsMngr::executeEvents()
|
|
|
|
{
|
2004-03-05 21:32:29 +03:00
|
|
|
if (!m_ParseFun)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-07-25 10:03:43 +04:00
|
|
|
for (ClEventVecIter iter = m_ParseFun->begin(); iter; ++iter)
|
2004-01-31 23:56:22 +03:00
|
|
|
{
|
2005-09-10 07:39:23 +04:00
|
|
|
if ((*iter).m_Done)
|
2004-01-31 23:56:22 +03:00
|
|
|
{
|
2005-07-25 10:03:43 +04:00
|
|
|
(*iter).m_Done = false;
|
|
|
|
continue;
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2005-07-25 10:03:43 +04:00
|
|
|
(*iter).m_Stamp = (float)*m_Timer;
|
|
|
|
executeForwards((*iter).m_Func, m_ParseVault ? m_ParseVault[0].iValue : 0);
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
2004-03-11 15:35:13 +03:00
|
|
|
|
2004-04-03 23:15:43 +04:00
|
|
|
m_CurrentMsgType = -1;
|
2004-03-11 15:35:13 +03:00
|
|
|
m_ParseFun = NULL;
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
|
|
|
|
2004-03-31 22:05:07 +04:00
|
|
|
int EventsMngr::getArgNum() const
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
|
|
|
return m_ParsePos + 1;
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
|
|
|
|
2004-03-31 22:05:07 +04:00
|
|
|
const char* EventsMngr::getArgString(int a) const
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2005-09-10 07:39:23 +04:00
|
|
|
if (a < 0 || a > m_ParsePos)
|
2004-02-26 22:04:53 +03:00
|
|
|
return "";
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
static char var[32];
|
|
|
|
|
|
|
|
switch(m_ParseVault[a].type)
|
|
|
|
{
|
2005-09-10 07:39:23 +04:00
|
|
|
case MSG_INTEGER:
|
|
|
|
sprintf(var, "%d", m_ParseVault[a].iValue);
|
|
|
|
return var;
|
|
|
|
case MSG_STRING:
|
|
|
|
return m_ParseVault[a].sValue;
|
|
|
|
default:
|
|
|
|
sprintf(var, "%g", m_ParseVault[a].fValue);
|
|
|
|
return var;
|
2004-02-26 22:04:53 +03:00
|
|
|
}
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
|
|
|
|
2004-03-31 22:05:07 +04:00
|
|
|
int EventsMngr::getArgInteger(int a) const
|
2004-01-31 23:56:22 +03:00
|
|
|
{
|
2005-09-10 07:39:23 +04:00
|
|
|
if (a < 0 || a > m_ParsePos)
|
2004-02-26 22:04:53 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch(m_ParseVault[a].type)
|
|
|
|
{
|
2005-09-10 07:39:23 +04:00
|
|
|
case MSG_INTEGER:
|
|
|
|
return m_ParseVault[a].iValue;
|
|
|
|
case MSG_STRING:
|
|
|
|
return atoi(m_ParseVault[a].sValue);
|
|
|
|
default:
|
|
|
|
return (int)m_ParseVault[a].fValue;
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-31 22:05:07 +04:00
|
|
|
float EventsMngr::getArgFloat(int a) const
|
2004-02-26 22:04:53 +03:00
|
|
|
{
|
2005-09-10 07:39:23 +04:00
|
|
|
if (a < 0 || a > m_ParsePos)
|
2004-02-26 22:04:53 +03:00
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
switch(m_ParseVault[a].type)
|
|
|
|
{
|
2005-09-10 07:39:23 +04:00
|
|
|
case MSG_INTEGER:
|
|
|
|
return static_cast<float>(m_ParseVault[a].iValue);
|
|
|
|
case MSG_STRING:
|
|
|
|
return static_cast<float>(atof(m_ParseVault[a].sValue));
|
|
|
|
default:
|
|
|
|
return m_ParseVault[a].fValue;
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
void EventsMngr::clearEvents(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < MAX_AMX_REG_MSG; ++i)
|
|
|
|
{
|
|
|
|
m_Events[i].clear();
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-03-17 21:57:36 +03:00
|
|
|
// delete parsevault
|
|
|
|
if (m_ParseVault)
|
|
|
|
{
|
|
|
|
delete [] m_ParseVault;
|
|
|
|
m_ParseVault = NULL;
|
|
|
|
m_ParseVaultSize = 0;
|
|
|
|
}
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
int EventsMngr::getEventId(const char* msg)
|
|
|
|
{
|
2004-03-04 21:16:51 +03:00
|
|
|
// :TODO: Remove this somehow!!! :)
|
2004-02-26 22:04:53 +03:00
|
|
|
const struct CS_Events
|
|
|
|
{
|
2004-01-31 23:56:22 +03:00
|
|
|
const char* name;
|
|
|
|
CS_EventsIds id;
|
2004-02-26 22:04:53 +03:00
|
|
|
} table[] =
|
|
|
|
{
|
2005-09-10 07:39:23 +04:00
|
|
|
{"CS_DeathMsg", CS_DeathMsg},
|
|
|
|
// {"CS_RoundEnd", CS_RoundEnd},
|
|
|
|
// {"CS_RoundStart", CS_RoundStart},
|
|
|
|
// {"CS_Restart", CS_Restart},
|
|
|
|
{"", CS_Null}
|
2004-01-31 23:56:22 +03:00
|
|
|
};
|
2004-03-04 21:16:51 +03:00
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
// if msg is a number, return it
|
|
|
|
int pos = atoi(msg);
|
2005-09-10 07:39:23 +04:00
|
|
|
|
2004-02-26 22:04:53 +03:00
|
|
|
if (pos != 0)
|
2004-01-31 23:56:22 +03:00
|
|
|
return pos;
|
2004-02-26 22:04:53 +03:00
|
|
|
|
|
|
|
// try to find in table first
|
2005-09-10 07:39:23 +04:00
|
|
|
for (pos = 0; table[pos].id != CS_Null; ++pos)
|
|
|
|
if (!strcmp(table[pos].name, msg))
|
|
|
|
return table[pos].id;
|
2004-02-26 22:04:53 +03:00
|
|
|
|
2004-03-04 21:16:51 +03:00
|
|
|
// find the id of the message
|
2005-09-10 07:39:23 +04:00
|
|
|
return pos = GET_USER_MSG_ID(PLID, msg, 0);
|
2004-01-31 23:56:22 +03:00
|
|
|
}
|
2004-04-03 23:15:43 +04:00
|
|
|
|
|
|
|
int EventsMngr::getCurrentMsgType()
|
|
|
|
{
|
|
|
|
return m_CurrentMsgType;
|
|
|
|
}
|