amxmodx/amxmodx/CMisc.h

290 lines
6.0 KiB
C
Raw Normal View History

2004-02-21 19:36:35 +00:00
/* AMX Mod X
*
* by the AMX Mod X Development Team
* originally developed by OLO
*
*
* 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.
*
* 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 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.
*/
2004-01-31 20:56:22 +00:00
#ifndef CMISC_H
#define CMISC_H
#include "CList.h"
#include "sh_list.h"
2004-01-31 20:56:22 +00:00
// *****************************************************
// class CCVar
// *****************************************************
2005-09-10 00:38:42 +00:00
2004-01-31 20:56:22 +00:00
class CCVar
{
2005-09-16 23:48:51 +00:00
cvar_t cvar;
String name;
String plugin;
2005-09-10 00:38:42 +00:00
2004-01-31 20:56:22 +00:00
public:
2005-09-10 00:38:42 +00:00
CCVar(const char* pname, const char* pplugin, int pflags, float pvalue) : name(pname), plugin(pplugin)
{
2004-08-13 08:46:04 +00:00
cvar.name = (char*)name.c_str();
2004-01-31 20:56:22 +00:00
cvar.flags = pflags;
cvar.string = "";
cvar.value = pvalue;
2005-09-16 23:48:51 +00:00
}
2005-09-10 00:38:42 +00:00
2004-01-31 20:56:22 +00:00
inline cvar_t* getCvar() { return &cvar; }
2004-08-13 08:46:04 +00:00
inline const char* getPluginName() { return plugin.c_str(); }
inline const char* getName() { return name.c_str(); }
2005-09-16 23:48:51 +00:00
inline bool operator == (const char* string) { return (strcmp(name.c_str(), string) == 0); }
2004-01-31 20:56:22 +00:00
};
// *****************************************************
// class CPlayer
// *****************************************************
2005-08-27 23:00:44 +00:00
struct ClientCvarQuery_Info
{
int resultFwd;
int requestId;
int paramLen;
cell *params;
2005-08-27 23:00:44 +00:00
};
2004-01-31 20:56:22 +00:00
class CPlayer
{
public:
edict_t* pEdict;
String name;
String ip;
String team;
2004-01-31 20:56:22 +00:00
bool initialized;
bool ingame;
2004-12-22 18:19:51 +00:00
bool bot;
2004-01-31 20:56:22 +00:00
bool authorized;
2005-11-17 23:04:43 +00:00
bool vgui;
2004-01-31 20:56:22 +00:00
float time;
float playtime;
2005-11-13 20:33:30 +00:00
float menuexpire;
2004-01-31 20:56:22 +00:00
2005-09-10 00:38:42 +00:00
struct
{
2004-01-31 20:56:22 +00:00
int ammo;
int clip;
} weapons[MAX_WEAPONS];
int current;
int teamId;
int deaths;
int aiming;
int menu;
int keys;
int index;
int flags[32];
int death_headshot;
int death_killer;
int death_victim;
bool death_tk;
String death_weapon;
int newmenu;
int page;
float channels[5];
cell hudmap[5];
2004-01-31 20:56:22 +00:00
Vector lastTrace;
Vector thisTrace;
Vector lastHit;
List<ClientCvarQuery_Info *> queries;
2005-08-27 23:00:44 +00:00
2005-09-10 00:38:42 +00:00
void Init(edict_t* e, int i);
2004-01-31 20:56:22 +00:00
void Disconnect();
void PutInServer();
2005-09-10 00:38:42 +00:00
bool Connect(const char* connectname, const char* ipaddress);
2004-01-31 20:56:22 +00:00
2005-09-10 00:38:42 +00:00
inline bool IsBot()
{
return ((pEdict->v.flags & FL_FAKECLIENT) ? true : false);
2004-01-31 20:56:22 +00:00
}
2005-09-10 00:38:42 +00:00
inline bool IsAlive()
{
return ((pEdict->v.deadflag == DEAD_NO) && (pEdict->v.health > 0));
2004-01-31 20:56:22 +00:00
}
inline void Authorize() { authorized = true; }
int NextHUDChannel();
2004-01-31 20:56:22 +00:00
};
// *****************************************************
// class Grenades
// *****************************************************
class Grenades
{
2005-09-10 00:38:42 +00:00
struct Obj
{
CPlayer* player;
edict_t* grenade;
float time;
int type;
Obj* next;
} *head;
2004-01-31 20:56:22 +00:00
public:
2005-09-10 00:38:42 +00:00
Grenades() { head = 0; }
~Grenades() { clear(); }
2005-09-16 23:48:51 +00:00
2005-09-10 00:38:42 +00:00
void put(edict_t* grenade, float time, int type, CPlayer* player);
bool find(edict_t* enemy, CPlayer** p, int& type);
void clear();
2004-01-31 20:56:22 +00:00
};
// *****************************************************
// class ForceObject
// *****************************************************
2005-09-10 00:38:42 +00:00
class ForceObject
{
2005-09-16 23:48:51 +00:00
String filename;
FORCE_TYPE type;
Vector mins;
Vector maxs;
AMX* amx;
2004-01-31 20:56:22 +00:00
public:
2005-09-16 23:48:51 +00:00
ForceObject(const char* n, FORCE_TYPE c, Vector& mi, Vector& ma, AMX* a) : filename(n), type(c), mins(mi), maxs(ma), amx(a) {}
2005-09-10 00:38:42 +00:00
2004-08-13 08:46:04 +00:00
inline const char* getFilename() { return filename.c_str(); }
2004-01-31 20:56:22 +00:00
inline AMX* getAMX() { return amx; }
2005-09-16 23:48:51 +00:00
2004-01-31 20:56:22 +00:00
Vector& getMin() { return mins; }
Vector& getMax() { return maxs; }
2005-09-16 23:48:51 +00:00
2004-01-31 20:56:22 +00:00
inline FORCE_TYPE getForceType() { return type; }
};
// *****************************************************
// class XVars
// *****************************************************
class XVars
{
2005-09-10 00:38:42 +00:00
struct XVarEle
{
AMX* amx;
cell* value;
};
2005-09-16 23:48:51 +00:00
2005-09-10 00:38:42 +00:00
XVarEle* head;
2005-09-16 23:48:51 +00:00
2005-09-10 00:38:42 +00:00
int size;
int num;
int realloc_array(int nsize);
2004-01-31 20:56:22 +00:00
public:
2005-09-16 23:48:51 +00:00
XVars() { num = 0; size = 0; head = 0; }
2005-09-10 00:38:42 +00:00
~XVars() { clear(); }
2005-09-16 23:48:51 +00:00
2005-09-10 00:38:42 +00:00
void clear();
int put(AMX* a, cell* v);
inline cell getValue(int a)
{
return (a >= 0 && a < num) ? *(head[a].value) : 0;
}
2005-09-16 23:48:51 +00:00
2005-09-10 00:38:42 +00:00
inline int setValue(int a, cell v)
{
if (a >= 0 && a < num)
{
*(head[a].value) = v;
return 0;
}
2005-09-16 23:48:51 +00:00
2005-09-10 00:38:42 +00:00
return 1;
}
2004-01-31 20:56:22 +00:00
};
// *****************************************************
// class CScript
// *****************************************************
2005-09-10 00:38:42 +00:00
2004-01-31 20:56:22 +00:00
class CScript
{
String filename;
2004-01-31 20:56:22 +00:00
AMX* amx;
void* code;
public:
2005-09-16 23:48:51 +00:00
CScript(AMX* aa, void* cc, const char* ff) : filename(ff), amx(aa), code(cc) {}
2005-09-10 00:38:42 +00:00
2004-01-31 20:56:22 +00:00
inline AMX* getAMX() { return amx; }
2004-08-13 08:46:04 +00:00
inline const char* getName() { return filename.c_str(); }
2005-09-10 00:38:42 +00:00
inline bool operator==(void* a) { return (amx == (AMX*)a); }
2004-01-31 20:56:22 +00:00
inline void* getCode() { return code; }
};
// *****************************************************
// class TeamIds
// *****************************************************
2005-09-10 00:38:42 +00:00
2004-01-31 20:56:22 +00:00
class TeamIds
{
2005-09-10 00:38:42 +00:00
struct TeamEle
{
String name;
int id;
char tid;
static char uid;
TeamEle* next;
TeamEle(const char* n, int& i) : name(n), id(i), next(0)
{
tid = uid++;
}
~TeamEle() { --uid; }
} *head;
int newTeam;
2004-01-31 20:56:22 +00:00
public:
2005-09-10 00:38:42 +00:00
TeamIds();
~TeamIds();
2005-09-16 23:48:51 +00:00
2005-09-10 00:38:42 +00:00
void registerTeam(const char* n, int s);
int findTeamId(const char* n);
int findTeamIdCase(const char* n);
inline bool isNewTeam() { return newTeam ? true : false; }
2004-01-31 20:56:22 +00:00
};
2005-09-10 00:38:42 +00:00
#endif //CMISC_H