extensions/sdktools/tenatives.cpp
author David Anderson <dvander@alliedmods.net>
Wed Aug 01 02:48:11 2007 +0000 (2007-08-01)
changeset 1233 e9cfc03b9bb8
parent 1039 71e55e3fd8f7
child 1255 e3db1a9eb578
permissions -rw-r--r--
updated sdktools license headers
     1 /**
     2  * vim: set ts=4 :
     3  * ================================================================
     4  * SourceMod SDKTools Extension
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * ================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or 
     9  * modify it under the terms of the GNU General Public License, 
    10  * version 3.0, as published by the Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to 
    21  * link the code of this program (as well as its derivative works) to 
    22  * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any 
    23  * Game MODs that run on software by the Valve Corporation.  You must 
    24  * obey the GNU General Public License in all respects for all other 
    25  * code used. Additionally, AlliedModders LLC grants this exception 
    26  * to all derivative works. AlliedModders LLC defines further 
    27  * exceptions, found in LICENSE.txt (as of this writing, version 
    28  * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #include "tempents.h"
    34 #include "CellRecipientFilter.h"
    35 
    36 CellRecipientFilter g_TERecFilter;
    37 TempEntityInfo *g_CurrentTE = NULL;
    38 
    39 static cell_t smn_TEStart(IPluginContext *pContext, const cell_t *params)
    40 {
    41 	if (!g_TEManager.IsAvailable())
    42 	{
    43 		return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
    44 	}
    45 
    46 	char *name;
    47 	pContext->LocalToString(params[1], &name);
    48 
    49 	g_CurrentTE = g_TEManager.GetTempEntityInfo(name);
    50 	if (!g_CurrentTE)
    51 	{
    52 		return pContext->ThrowNativeError("Invalid TempEntity name: \"%s\"", name);
    53 	}
    54 
    55 	return 1;
    56 }
    57 
    58 static cell_t smn_TEWriteNum(IPluginContext *pContext, const cell_t *params)
    59 {
    60 	if (!g_TEManager.IsAvailable())
    61 	{
    62 		return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
    63 	}
    64 	if (!g_CurrentTE)
    65 	{
    66 		return pContext->ThrowNativeError("No TempEntity call is in progress");
    67 	}
    68 
    69 	char *prop;
    70 	pContext->LocalToString(params[1], &prop);
    71 
    72 	if (!g_CurrentTE->TE_SetEntData(prop, params[2]))
    73 	{
    74 		return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop);
    75 	}
    76 
    77 	return 1;
    78 }
    79 
    80 static cell_t smn_TE_WriteFloat(IPluginContext *pContext, const cell_t *params)
    81 {
    82 	if (!g_TEManager.IsAvailable())
    83 	{
    84 		return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
    85 	}
    86 	if (!g_CurrentTE)
    87 	{
    88 		return pContext->ThrowNativeError("No TempEntity call is in progress");
    89 	}
    90 
    91 	char *prop;
    92 	pContext->LocalToString(params[1], &prop);
    93 
    94 	if (!g_CurrentTE->TE_SetEntDataFloat(prop, sp_ctof(params[2])))
    95 	{
    96 		return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop);
    97 	}
    98 
    99 	return 1;
   100 }
   101 
   102 static cell_t smn_TEWriteVector(IPluginContext *pContext, const cell_t *params)
   103 {
   104 	if (!g_TEManager.IsAvailable())
   105 	{
   106 		return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
   107 	}
   108 	if (!g_CurrentTE)
   109 	{
   110 		return pContext->ThrowNativeError("No TempEntity call is in progress");
   111 	}
   112 
   113 	char *prop;
   114 	pContext->LocalToString(params[1], &prop);
   115 
   116 	cell_t *addr;
   117 	pContext->LocalToPhysAddr(params[2], &addr);
   118 	float vec[3] = {sp_ctof(addr[0]), sp_ctof(addr[1]), sp_ctof(addr[2])};
   119 
   120 	if (!g_CurrentTE->TE_SetEntDataVector(prop, vec))
   121 	{
   122 		return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop);
   123 	}
   124 
   125 	return 1;
   126 }
   127 
   128 static cell_t smn_TEWriteFloatArray(IPluginContext *pContext, const cell_t *params)
   129 {
   130 	if (!g_TEManager.IsAvailable())
   131 	{
   132 		return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
   133 	}
   134 	if (!g_CurrentTE)
   135 	{
   136 		return pContext->ThrowNativeError("No TempEntity call is in progress");
   137 	}
   138 
   139 	char *prop;
   140 	pContext->LocalToString(params[1], &prop);
   141 
   142 	cell_t *addr;
   143 	pContext->LocalToPhysAddr(params[2], &addr);
   144 
   145 	if (!g_CurrentTE->TE_SetEntDataFloatArray(prop, addr, params[3]))
   146 	{
   147 		return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop);
   148 	}
   149 
   150 	return 1;
   151 }
   152 
   153 static cell_t smn_TESend(IPluginContext *pContext, const cell_t *params)
   154 {
   155 	if (!g_TEManager.IsAvailable())
   156 	{
   157 		return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
   158 	}
   159 	if (!g_CurrentTE)
   160 	{
   161 		return pContext->ThrowNativeError("No TempEntity call is in progress");
   162 	}
   163 
   164 	cell_t *cl_array;
   165 	pContext->LocalToPhysAddr(params[1], &cl_array);
   166 
   167 	g_TERecFilter.Reset();
   168 	g_TERecFilter.Initialize(cl_array, params[2]);
   169 
   170 	g_CurrentTE->Send(g_TERecFilter, sp_ctof(params[3]));
   171 	g_CurrentTE = NULL;
   172 
   173 	return 1;
   174 }
   175 
   176 static cell_t smn_TEIsValidProp(IPluginContext *pContext, const cell_t *params)
   177 {
   178 	if (!g_TEManager.IsAvailable())
   179 	{
   180 		return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
   181 	}
   182 	if (!g_CurrentTE)
   183 	{
   184 		return pContext->ThrowNativeError("No TempEntity call is in progress");
   185 	}
   186 
   187 	char *prop;
   188 	pContext->LocalToString(params[1], &prop);
   189 
   190 	return g_CurrentTE->IsValidProp(prop) ? 1 : 0;
   191 }
   192 
   193 sp_nativeinfo_t g_TENatives[] = 
   194 {
   195 	{"TE_Start",				smn_TEStart},
   196 	{"TE_WriteNum",				smn_TEWriteNum},
   197 	{"TE_WriteFloat",			smn_TE_WriteFloat},
   198 	{"TE_WriteVector",			smn_TEWriteVector},
   199 	{"TE_WriteAngles",			smn_TEWriteVector},
   200 	{"TE_Send",					smn_TESend},
   201 	{"TE_IsValidProp",			smn_TEIsValidProp},
   202 	{"TE_WriteFloatArray",		smn_TEWriteFloatArray},
   203 	{NULL,						NULL}
   204 };