extensions/sdktools/teamnatives.cpp
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/extensions/sdktools/teamnatives.cpp	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,176 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod SDKTools Extension
     1.8 - * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     1.9 - * =============================================================================
    1.10 - *
    1.11 - * This program is free software; you can redistribute it and/or modify it under
    1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
    1.13 - * Free Software Foundation.
    1.14 - *
    1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
    1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.18 - * details.
    1.19 - *
    1.20 - * You should have received a copy of the GNU General Public License along with
    1.21 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 - *
    1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
    1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.26 - * by the Valve Corporation.  You must obey the GNU General Public License in
    1.27 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.28 - * this exception to all derivative works.  AlliedModders LLC defines further
    1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.30 - * or <http://www.sourcemod.net/license.php>.
    1.31 - *
    1.32 - * Version: $Id$
    1.33 - */
    1.34 -
    1.35 -#include "extension.h"
    1.36 -#include <sh_vector.h>
    1.37 -
    1.38 -struct TeamInfo
    1.39 -{
    1.40 -	const char *ClassName;
    1.41 -	CBaseEntity *pEnt;
    1.42 -};
    1.43 -
    1.44 -SourceHook::CVector<TeamInfo> g_Teams;
    1.45 -
    1.46 -bool FindTeamEntities(SendTable *pTable, const char *name)
    1.47 -{
    1.48 -	int props = pTable->GetNumProps();
    1.49 -	SendProp *prop;
    1.50 -
    1.51 -	for (int i=0; i<props; i++)
    1.52 -	{
    1.53 -		prop = pTable->GetProp(i);
    1.54 -		if (prop->GetDataTable())
    1.55 -		{
    1.56 -			if (strcmp(prop->GetDataTable()->GetName(), name) == 0)
    1.57 -			{
    1.58 -				return true;
    1.59 -			}
    1.60 -			if (FindTeamEntities(prop->GetDataTable(), name))
    1.61 -			{
    1.62 -				return true;
    1.63 -			}
    1.64 -		}
    1.65 -	}
    1.66 -
    1.67 -	return false;
    1.68 -}
    1.69 -
    1.70 -void SDKTools::OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
    1.71 -{
    1.72 -	g_Teams.clear();
    1.73 -	g_Teams.resize(1);
    1.74 -
    1.75 -	for (int i=0; i<edictCount; i++)
    1.76 -	{
    1.77 -		edict_t *pEdict = engine->PEntityOfEntIndex(i);
    1.78 -		if (!pEdict || pEdict->IsFree())
    1.79 -		{
    1.80 -			continue;
    1.81 -		}
    1.82 -		if (!pEdict->GetNetworkable())
    1.83 -		{
    1.84 -			continue;
    1.85 -		}
    1.86 -
    1.87 -		ServerClass *pClass = pEdict->GetNetworkable()->GetServerClass();
    1.88 -		if (FindTeamEntities(pClass->m_pTable, "DT_Team"))
    1.89 -		{
    1.90 -			SendProp *pTeamNumProp = g_pGameHelpers->FindInSendTable(pClass->GetName(), "m_iTeamNum");
    1.91 -
    1.92 -			if (pTeamNumProp != NULL)
    1.93 -			{
    1.94 -				int offset = pTeamNumProp->GetOffset();
    1.95 -				CBaseEntity *pEnt = pEdict->GetUnknown()->GetBaseEntity();
    1.96 -				int TeamIndex = *(int *)((unsigned char *)pEnt + offset);
    1.97 -
    1.98 -				if (TeamIndex >= (int)g_Teams.size())
    1.99 -				{
   1.100 -					g_Teams.resize(TeamIndex+1);
   1.101 -				}
   1.102 -				g_Teams[TeamIndex].ClassName = pClass->GetName();
   1.103 -				g_Teams[TeamIndex].pEnt = pEnt;
   1.104 -			}
   1.105 -		}
   1.106 -	}
   1.107 -}
   1.108 -
   1.109 -static cell_t GetTeamCount(IPluginContext *pContext, const cell_t *params)
   1.110 -{
   1.111 -	return g_Teams.size();
   1.112 -}
   1.113 -
   1.114 -static cell_t GetTeamName(IPluginContext *pContext, const cell_t *params)
   1.115 -{
   1.116 -	int teamindex = params[1];
   1.117 -	if (teamindex > (int)g_Teams.size())
   1.118 -	{
   1.119 -		pContext->ThrowNativeError("Team index %d is invalid", teamindex);
   1.120 -	}
   1.121 -
   1.122 -	static int offset = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "m_szTeamname")->GetOffset();
   1.123 -	char *name = (char *)((unsigned char *)g_Teams[teamindex].pEnt + offset);
   1.124 -
   1.125 -	pContext->StringToLocalUTF8(params[2], params[3], name, NULL);
   1.126 -
   1.127 -	return 1;
   1.128 -}
   1.129 -
   1.130 -static cell_t GetTeamScore(IPluginContext *pContext, const cell_t *params)
   1.131 -{
   1.132 -	int teamindex = params[1];
   1.133 -	if (teamindex > (int)g_Teams.size())
   1.134 -	{
   1.135 -		pContext->ThrowNativeError("Team index %d is invalid", teamindex);
   1.136 -	}
   1.137 -
   1.138 -	static int offset = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "m_iScore")->GetOffset();
   1.139 -
   1.140 -	return *(int *)((unsigned char *)g_Teams[teamindex].pEnt + offset);
   1.141 -}
   1.142 -
   1.143 -static cell_t SetTeamScore(IPluginContext *pContext, const cell_t *params)
   1.144 -{
   1.145 -	int teamindex = params[1];
   1.146 -	if (teamindex > (int)g_Teams.size())
   1.147 -	{
   1.148 -		pContext->ThrowNativeError("Team index %d is invalid", teamindex);
   1.149 -	}
   1.150 -
   1.151 -	static int offset = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "m_iScore")->GetOffset();
   1.152 -	*(int *)((unsigned char *)g_Teams[teamindex].pEnt + offset) = params[2];
   1.153 -
   1.154 -	return 1;
   1.155 -}
   1.156 -
   1.157 -static cell_t GetTeamClientCount(IPluginContext *pContext, const cell_t *params)
   1.158 -{
   1.159 -	int teamindex = params[1];
   1.160 -	if (teamindex > (int)g_Teams.size())
   1.161 -	{
   1.162 -		pContext->ThrowNativeError("Team index %d is invalid", teamindex);
   1.163 -	}
   1.164 -
   1.165 -	SendProp *pProp = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "\"player_array\"");
   1.166 -	ArrayLengthSendProxyFn fn = pProp->GetArrayLengthProxy();
   1.167 -
   1.168 -	return fn(g_Teams[teamindex].pEnt, 0);
   1.169 -}
   1.170 -
   1.171 -sp_nativeinfo_t g_TeamNatives[] = 
   1.172 -{
   1.173 -	{"GetTeamCount",			GetTeamCount},
   1.174 -	{"GetTeamName",				GetTeamName},
   1.175 -	{"GetTeamScore",			GetTeamScore},
   1.176 -	{"SetTeamScore",			SetTeamScore},
   1.177 -	{"GetTeamClientCount",		GetTeamClientCount},
   1.178 -	{NULL,						NULL}
   1.179 -};