amxmodx/amxmodx/CMisc.cpp

292 lines
4.8 KiB
C++
Raw Normal View History

2014-08-04 08:36:20 +00:00
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
2004-03-24 01:35:44 +00:00
#include "amxmodx.h"
#include "newmenus.h"
2004-01-31 20:56:22 +00:00
// *****************************************************
// class CPlayer
// *****************************************************
2004-08-13 08:46:04 +00:00
2005-09-10 20:09:14 +00:00
void CPlayer::Init(edict_t* e, int i)
2004-01-31 20:56:22 +00:00
{
index = i;
pEdict = e;
initialized = false;
ingame = false;
authorized = false;
teamIdsInitialized = false;
2004-01-31 20:56:22 +00:00
current = 0;
teamId = -1;
deaths = 0;
aiming = 0;
menu = 0;
keys = 0;
2005-11-13 20:33:30 +00:00
menuexpire = 0.0;
newmenu = -1;
2004-01-31 20:56:22 +00:00
death_weapon.clear();
name.clear();
ip.clear();
team.clear();
}
2005-09-10 20:09:14 +00:00
void CPlayer::Disconnect()
{
ingame = false;
initialized = false;
authorized = false;
teamIdsInitialized = false;
if (Menu *pMenu = get_menu_by_id(newmenu))
2014-05-21 16:58:51 +00:00
pMenu->Close(index);
List<ClientCvarQuery_Info *>::iterator iter, end=queries.end();
for (iter=queries.begin(); iter!=end; iter++)
{
unregisterSPForward((*iter)->resultFwd);
delete [] (*iter)->params;
delete (*iter);
}
queries.clear();
menu = 0;
newmenu = -1;
2004-01-31 20:56:22 +00:00
}
2004-08-13 08:46:04 +00:00
2005-09-10 20:09:14 +00:00
void CPlayer::PutInServer()
{
playtime = gpGlobals->time;
ingame = true;
2004-01-31 20:56:22 +00:00
}
2005-09-10 20:09:14 +00:00
int CPlayer::NextHUDChannel()
{
int ilow = 1;
for (int i=ilow+1; i<=4; i++)
{
if (channels[i] < channels[ilow])
ilow = i;
}
return ilow;
}
2005-09-10 20:09:14 +00:00
bool CPlayer::Connect(const char* connectname, const char* ipaddress)
{
name.assign(connectname);
ip.assign(ipaddress);
time = gpGlobals->time;
death_killer = 0;
2005-11-17 23:04:43 +00:00
menu = 0;
newmenu = -1;
2005-09-16 23:48:51 +00:00
2005-09-10 20:09:14 +00:00
memset(flags, 0, sizeof(flags));
memset(weapons, 0, sizeof(weapons));
2005-09-16 23:48:51 +00:00
initialized = true;
authorized = false;
for (int i=0; i<=4; i++)
{
channels[i] = 0.0f;
hudmap[i] = 0;
}
List<ClientCvarQuery_Info *>::iterator iter, end=queries.end();
for (iter=queries.begin(); iter!=end; iter++)
{
unregisterSPForward((*iter)->resultFwd);
delete [] (*iter)->params;
delete (*iter);
}
queries.clear();
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
// *****************************************************
2005-09-10 20:09:14 +00:00
void Grenades::put(edict_t* grenade, float time, int type, CPlayer* player)
2004-01-31 20:56:22 +00:00
{
Obj* a = new Obj;
2005-09-10 20:09:14 +00:00
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
}
2005-09-10 20:09:14 +00:00
bool Grenades::find(edict_t* enemy, CPlayer** p, int& type)
2004-01-31 20:56:22 +00:00
{
bool found = false;
Obj** a = &head;
2005-09-10 20:09:14 +00:00
while (*a)
{
if ((*a)->time > gpGlobals->time)
{
if ((*a)->grenade == enemy)
{
found = true;
(*p) = (*a)->player;
type = (*a)->type;
}
2005-09-10 20:09:14 +00:00
} else {
Obj* b = (*a)->next;
delete *a;
*a = b;
continue;
}
a = &(*a)->next;
}
2005-09-10 20:09:14 +00:00
return found;
2004-01-31 20:56:22 +00:00
}
void Grenades::clear()
{
2005-09-10 20:09:14 +00:00
while (head)
{
Obj* a = head->next;
delete head;
head = a;
}
2004-01-31 20:56:22 +00:00
}
// *****************************************************
// class XVars
// *****************************************************
2005-09-10 20:09:14 +00:00
void XVars::clear()
{
2004-01-31 20:56:22 +00:00
delete[] head;
head = 0;
num = 0;
size = 0;
}
2005-09-10 20:09:14 +00:00
int XVars::put(AMX* p, cell* v)
2004-01-31 20:56:22 +00:00
{
2005-09-10 20:09:14 +00:00
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
2005-09-10 20:09:14 +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;
2005-09-16 23:48:51 +00:00
return num++;
2004-01-31 20:56:22 +00:00
}
2005-09-10 20:09:14 +00:00
int XVars::realloc_array(int nsize)
2004-01-31 20:56:22 +00:00
{
XVarEle* me = new XVarEle[nsize];
2005-09-10 20:09:14 +00:00
if (me)
{
for (int a = 0 ; a < num; ++a)
2004-01-31 20:56:22 +00:00
me[a] = head[a];
2005-09-10 20:09:14 +00:00
2004-01-31 20:56:22 +00:00
delete[] head;
head = me;
size = nsize;
return 0;
}
2005-09-10 20:09:14 +00:00
2004-01-31 20:56:22 +00:00
return 1;
}
// *****************************************************
// class TeamIds
// *****************************************************
2005-09-10 20:09:14 +00:00
2004-01-31 20:56:22 +00:00
TeamIds::TeamIds() { head = 0; newTeam = 0; }
2005-09-10 20:09:14 +00:00
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
}
2005-09-10 20:09:14 +00:00
void TeamIds::registerTeam(const char* n, int s)
2004-01-31 20:56:22 +00:00
{
TeamEle** a = &head;
2005-09-10 20:09:14 +00:00
while (*a)
{
if (strcmp((*a)->name.c_str(),n) == 0)
{
if (s != -1)
{
2004-01-31 20:56:22 +00:00
(*a)->id = s;
newTeam &= ~(1<<(*a)->tid);
}
2005-09-10 20:09:14 +00:00
2004-01-31 20:56:22 +00:00
return;
}
a = &(*a)->next;
}
2005-09-10 20:09:14 +00:00
*a = new TeamEle(n, s);
2005-09-16 23:48:51 +00:00
if (*a == 0)
return;
newTeam |= (1<<(*a)->tid);
2004-01-31 20:56:22 +00:00
}
2005-09-10 20:09:14 +00:00
int TeamIds::findTeamId(const char* n)
2004-01-31 20:56:22 +00:00
{
TeamEle* a = head;
2005-09-10 20:09:14 +00:00
while (a)
{
if (!stricmp(a->name.c_str(), n))
2004-01-31 20:56:22 +00:00
return a->id;
a = a->next;
}
2005-09-10 20:09:14 +00:00
2004-01-31 20:56:22 +00:00
return -1;
}
2005-09-10 20:09:14 +00:00
int TeamIds::findTeamIdCase(const char* n)
2004-01-31 20:56:22 +00:00
{
TeamEle* a = head;
2005-09-10 20:09:14 +00:00
while (a)
{
if (!strcmp(a->name.c_str(), n))
2004-01-31 20:56:22 +00:00
return a->id;
a = a->next;
}
2005-09-10 20:09:14 +00:00
2004-01-31 20:56:22 +00:00
return -1;
}
char TeamIds::TeamEle::uid = 0;