rewritten; have not changed interface

should support messages with more than 32 params now
This commit is contained in:
Pavol Marko
2004-02-26 19:04:53 +00:00
parent ce318d366d
commit 3c2107bf1d
2 changed files with 474 additions and 334 deletions

View File

@@ -1,40 +1,43 @@
/* AMX Mod X
/*
* Copyright (c) 2002-2003 Aleksander Naszko, Pavol Marko
*
* by the AMX Mod X Development Team
* originally developed by OLO
* This file is part of AMX Mod X.
*
* AMX Mod X 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.
*
* 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.
* AMX Mod X 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.
*
* 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.
* You should have received a copy of the GNU General Public License
* along with AMX Mod Xod; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* 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
* 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.
*
* 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.
*/
#ifndef EVENTS_H
#define EVENTS_H
#ifndef __CEVENTS_H__
#define __CEVENTS_H__
#include <vector>
#include <map>
#include <string>
#define MAX_PARSE_VALUES 32
#define MAX_AMX_REG_MSG MAX_REG_MSGS+16
enum {
CS_DEATHMSG = MAX_REG_MSGS,
// CS_ROUNDEND,
@@ -46,10 +49,10 @@ enum {
// class EventsMngr
// *****************************************************
class EventsMngr {
enum MsgValueType{
class EventsMngr
{
enum MsgParamType
{
MSG_INTEGER,
MSG_FLOAT,
MSG_STRING,
@@ -57,7 +60,8 @@ class EventsMngr {
public:
enum CS_EventsIds {
enum CS_EventsIds
{
CS_Null = 0,
CS_DeathMsg = MAX_REG_MSGS, // start from last element
// CS_RoundEnd,
@@ -65,51 +69,69 @@ public:
// CS_Restart,
};
class iterator;
friend class iterator;
class ClEvent
{
friend class EventsMngr; // events manager may access our private members
class ClEvent {
friend class EventsMngr;
friend class iterator;
CPluginMngr::CPlugin* plugin;
int func;
bool player;
bool world;
bool once;
bool done;
bool dead;
bool alive;
float stamp;
struct cond_t {
String sValue;
int m_Func; // function to be executed
CPluginMngr::CPlugin *m_Plugin; // the plugin this ClEvent class is assigned to
// flags
bool m_FlagPlayer;
bool m_FlagWorld;
bool m_FlagOnce;
bool m_FlagDead;
bool m_FlagAlive;
float m_Stamp; // for 'once' flag
bool m_Done;
// conditions
struct cond_t
{
std::string sValue; // value
float fValue;
int iValue;
int type;
cond_t* next;
} *cond[MAX_PARSE_VALUES];
ClEvent* next;
ClEvent( CPluginMngr::CPlugin* p, int f, int flags );
};
typedef std::pair<int, cond_t> CondMapPair;
typedef std::map<int, cond_t> CondMap;
typedef CondMap::iterator CondMapIter;
CondMap m_Conditions;
// constructors & destructors
ClEvent(CPluginMngr::CPlugin* plugin, int func, int flags);
~ClEvent();
public:
inline CPluginMngr::CPlugin* getPlugin() { return plugin; }
inline int getFunction() { return func; }
void registerFilter( char* filter );
inline CPluginMngr::CPlugin* getPlugin();
inline int getFunction();
void registerFilter(char* filter); // add a condition
};
private:
struct MsgDataVault {
struct MsgDataVault
{
float fValue;
int iValue;
const char* sValue;
MsgValueType type;
} parseVault[MAX_PARSE_VALUES];
MsgParamType type;
};
typedef std::vector<MsgDataVault> MsgDataVaultVec;
typedef MsgDataVaultVec::iterator MsgDataVaultVecIter;
MsgDataVaultVec m_ParseVault;
typedef std::vector<ClEvent*> ClEventVec;
typedef ClEventVec::iterator ClEventVecIter;
ClEventVec m_Events[MAX_AMX_REG_MSG];
ClEventVec *m_ParseFun; // current Event vector
ClEvent* modMsgsFunCall[MAX_AMX_REG_MSG];
ClEvent* parseFun;
bool parseNotDone;
int parsePos; // is -1 less then args. num.
float* timer;
bool m_ParseNotDone;
int m_ParsePos; // is -1 less then args. num.
float* m_Timer;
ClEvent* getValidEvent(ClEvent* a );
public:
@@ -118,37 +140,18 @@ public:
// Interface
ClEvent* registerEvent( CPluginMngr::CPlugin* p, int f, int flags, int pos );
void parserInit(int msg_type, float* timer , CPlayer* target = 0, int index = 0);
ClEvent* registerEvent(CPluginMngr::CPlugin* plugin, int func, int flags, int msgid);
void parserInit(int msg_type, float* timer, CPlayer* pPlayer, int index);
void parseValue(int iValue);
void parseValue(float fValue);
void parseValue(const char *sz);
void executeEvents();
inline int getArgNum() { return (parsePos+1); }
int getArgNum(); //{ return (parsePos+1); }
const char* getArgString(int a);
int getArgInteger(int a);
float getArgFloat(int a);
void clearEvents(void);
static int getEventId( const char* msg );
class iterator {
EventsMngr* b;
ClEvent* a;
public:
inline iterator(ClEvent*aa,EventsMngr* bb) : a(aa), b(bb) {}
inline iterator& operator++() {
a = b->getValidEvent( a->next );
return *this;
}
inline bool operator==(const iterator& c) const { return a == c.a; }
inline bool operator!=(const iterator& c) const { return !operator==(c); }
ClEvent& operator*() { return *a; }
operator bool ( ) const { return a ? true : false; }
};
inline iterator begin() { return iterator(getValidEvent(parseFun),this); }
inline iterator end() { return iterator(0,this); }
};
#endif
#endif // #ifdef __CEVENTS_H__