amxmodx/amxmodx/CMisc.cpp

244 lines
5.1 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-03-24 01:35:44 +00:00
#include "amxmodx.h"
2004-01-31 20:56:22 +00:00
// *****************************************************
// class CPlayer
// *****************************************************
2004-08-13 08:46:04 +00:00
2004-01-31 20:56:22 +00:00
void CPlayer::Init( edict_t* e , int i )
{
index = i;
pEdict = e;
initialized = false;
ingame = false;
2004-12-22 18:19:51 +00:00
bot = false;
2004-01-31 20:56:22 +00:00
authorized = false;
current = 0;
teamId = -1;
deaths = 0;
aiming = 0;
menu = 0;
keys = 0;
2004-01-31 20:56:22 +00:00
death_weapon.clear();
name.clear();
ip.clear();
team.clear();
}
void CPlayer::Disconnect() {
ingame = false;
initialized = false;
authorized = false;
while (!cvarQueryQueue.empty())
{
ClientCvarQuery_Info *pQuery = cvarQueryQueue.front();
unregisterSPForward(pQuery->resultFwd);
if (pQuery->params)
delete [] pQuery->params;
delete pQuery;
cvarQueryQueue.pop();
}
bot = 0;
2004-01-31 20:56:22 +00:00
}
2004-08-13 08:46:04 +00:00
2004-01-31 20:56:22 +00:00
void CPlayer::PutInServer() {
playtime = gpGlobals->time;
ingame = true;
2004-01-31 20:56:22 +00:00
}
bool CPlayer::Connect(const char* connectname,const char* ipaddress) {
name.assign(connectname);
ip.assign(ipaddress);
time = gpGlobals->time;
bot = IsBot();
death_killer = 0;
memset(flags,0,sizeof(flags));
memset(weapons,0,sizeof(weapons));
initialized = true;
authorized = false;
const char* authid = GETPLAYERAUTHID( pEdict );
if ( (authid == 0) || (*authid == 0)
|| (strcmp( authid , "STEAM_ID_PENDING") == 0) )
return true;
return false;
2004-01-31 20:56:22 +00:00
}
// *****************************************************
// class Grenades
// *****************************************************
void Grenades::put( edict_t* grenade, float time, int type, CPlayer* player )
{
Obj* a = new Obj;
if ( a == 0 ) return;
a->player = player;
a->grenade = grenade;
a->time = gpGlobals->time + time;
a->type = type;
a->next = head;
head = a;
2004-01-31 20:56:22 +00:00
}
bool Grenades::find( edict_t* enemy, CPlayer** p, int& type )
{
bool found = false;
Obj** a = &head;
while ( *a ){
if ( (*a)->time > gpGlobals->time ) {
if ( (*a)->grenade == enemy ) {
found = true;
(*p) = (*a)->player;
type = (*a)->type;
}
}
else {
Obj* b = (*a)->next;
delete *a;
*a = b;
continue;
}
a = &(*a)->next;
}
return found;
2004-01-31 20:56:22 +00:00
}
void Grenades::clear()
{
while(head){
Obj* a = head->next;
delete head;
head = a;
}
2004-01-31 20:56:22 +00:00
}
// *****************************************************
// class XVars
// *****************************************************
void XVars::clear() {
delete[] head;
head = 0;
num = 0;
size = 0;
}
int XVars::put( AMX* p, cell* v )
{
for(int a = 0; a < num; ++a) {
if ( (head[a].amx == p) && (head[a].value == v) )
return a;
}
2004-01-31 20:56:22 +00:00
if ( (num >= size) && realloc_array( size ? (size * 2) : 8 ) )
return -1;
2004-01-31 20:56:22 +00:00
head[num].value = v;
head[num].amx = p;
return num++;
2004-01-31 20:56:22 +00:00
}
int XVars::realloc_array( int nsize )
{
XVarEle* me = new XVarEle[nsize];
if ( me ){
for(int a = 0 ; a < num; ++a)
me[a] = head[a];
delete[] head;
head = me;
size = nsize;
return 0;
}
return 1;
}
// *****************************************************
// class TeamIds
// *****************************************************
TeamIds::TeamIds() { head = 0; newTeam = 0; }
TeamIds::~TeamIds() {
while( head ) {
2004-01-31 20:56:22 +00:00
TeamEle* a = head->next;
delete head;
head = a;
}
2004-01-31 20:56:22 +00:00
}
void TeamIds::registerTeam( const char* n ,int s )
{
TeamEle** a = &head;
while( *a ){
2004-08-13 08:46:04 +00:00
if ( strcmp((*a)->name.c_str(),n) == 0 ){
2004-01-31 20:56:22 +00:00
if (s != -1){
(*a)->id = s;
newTeam &= ~(1<<(*a)->tid);
}
return;
}
a = &(*a)->next;
}
*a = new TeamEle( n , s );
2004-01-31 20:56:22 +00:00
if ( *a == 0 ) return;
newTeam |= (1<<(*a)->tid);
2004-01-31 20:56:22 +00:00
}
int TeamIds::findTeamId( const char* n )
{
TeamEle* a = head;
while( a ){
2005-07-27 16:24:14 +00:00
if ( !stricmp(a->name.c_str(),n) )
2004-01-31 20:56:22 +00:00
return a->id;
a = a->next;
}
2004-01-31 20:56:22 +00:00
return -1;
}
int TeamIds::findTeamIdCase( const char* n)
{
TeamEle* a = head;
while( a ){
2004-08-13 08:46:04 +00:00
if ( !strcmp(a->name.c_str(), n) )
2004-01-31 20:56:22 +00:00
return a->id;
a = a->next;
}
2004-01-31 20:56:22 +00:00
return -1;
}
char TeamIds::TeamEle::uid = 0;