1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/extensions/sdktools/tenatives.cpp Mon Jul 02 00:25:46 2007 +0000
1.3 @@ -0,0 +1,169 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * ===============================================================
1.7 + * SourceMod SDK Tools 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
1.12 + * modify it under the terms of the GNU General Public License
1.13 + * as published by the Free Software Foundation; either version 2
1.14 + * of the License, or (at your option) any later version.
1.15 + * This program is distributed in the hope that it will be useful,
1.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.18 + * GNU General Public License for more details.
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License
1.21 + * along with this program; if not, write to the Free Software
1.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1.23 + *
1.24 + * Version: $Id$
1.25 + */
1.26 +
1.27 +#include "tempents.h"
1.28 +#include "CellRecipientFilter.h"
1.29 +
1.30 +CellRecipientFilter g_TERecFilter;
1.31 +TempEntityInfo *g_CurrentTE = NULL;
1.32 +
1.33 +static cell_t smn_TEStart(IPluginContext *pContext, const cell_t *params)
1.34 +{
1.35 + if (!g_TEManager.IsAvailable())
1.36 + {
1.37 + return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
1.38 + }
1.39 +
1.40 + char *name;
1.41 + pContext->LocalToString(params[1], &name);
1.42 +
1.43 + g_CurrentTE = g_TEManager.GetTempEntityInfo(name);
1.44 + if (!g_CurrentTE)
1.45 + {
1.46 + return pContext->ThrowNativeError("Invalid TempEntity name: \"%s\"", name);
1.47 + }
1.48 +
1.49 + return 1;
1.50 +}
1.51 +
1.52 +static cell_t smn_TEWriteNum(IPluginContext *pContext, const cell_t *params)
1.53 +{
1.54 + if (!g_TEManager.IsAvailable())
1.55 + {
1.56 + return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
1.57 + }
1.58 + if (!g_CurrentTE)
1.59 + {
1.60 + return pContext->ThrowNativeError("No TempEntity call is in progress");
1.61 + }
1.62 +
1.63 + char *prop;
1.64 + pContext->LocalToString(params[1], &prop);
1.65 +
1.66 + if (!g_CurrentTE->TE_SetEntData(prop, params[2]))
1.67 + {
1.68 + return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop);
1.69 + }
1.70 +
1.71 + return 1;
1.72 +}
1.73 +
1.74 +static cell_t smn_TE_WriteFloat(IPluginContext *pContext, const cell_t *params)
1.75 +{
1.76 + if (!g_TEManager.IsAvailable())
1.77 + {
1.78 + return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
1.79 + }
1.80 + if (!g_CurrentTE)
1.81 + {
1.82 + return pContext->ThrowNativeError("No TempEntity call is in progress");
1.83 + }
1.84 +
1.85 + char *prop;
1.86 + pContext->LocalToString(params[1], &prop);
1.87 +
1.88 + if (!g_CurrentTE->TE_SetEntDataFloat(prop, sp_ctof(params[2])))
1.89 + {
1.90 + return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop);
1.91 + }
1.92 +
1.93 + return 1;
1.94 +}
1.95 +
1.96 +static cell_t smn_TEWriteVector(IPluginContext *pContext, const cell_t *params)
1.97 +{
1.98 + if (!g_TEManager.IsAvailable())
1.99 + {
1.100 + return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
1.101 + }
1.102 + if (!g_CurrentTE)
1.103 + {
1.104 + return pContext->ThrowNativeError("No TempEntity call is in progress");
1.105 + }
1.106 +
1.107 + char *prop;
1.108 + pContext->LocalToString(params[1], &prop);
1.109 +
1.110 + cell_t *addr;
1.111 + pContext->LocalToPhysAddr(params[2], &addr);
1.112 + float vec[3] = {sp_ctof(addr[0]), sp_ctof(addr[1]), sp_ctof(addr[2])};
1.113 +
1.114 + if (!g_CurrentTE->TE_SetEntDataVector(prop, vec))
1.115 + {
1.116 + return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop);
1.117 + }
1.118 +
1.119 + return 1;
1.120 +}
1.121 +
1.122 +static cell_t smn_TESend(IPluginContext *pContext, const cell_t *params)
1.123 +{
1.124 + if (!g_TEManager.IsAvailable())
1.125 + {
1.126 + return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
1.127 + }
1.128 + if (!g_CurrentTE)
1.129 + {
1.130 + return pContext->ThrowNativeError("No TempEntity call is in progress");
1.131 + }
1.132 +
1.133 + cell_t *cl_array;
1.134 + pContext->LocalToPhysAddr(params[1], &cl_array);
1.135 +
1.136 + g_TERecFilter.Reset();
1.137 + g_TERecFilter.Initialize(cl_array, params[2]);
1.138 +
1.139 + g_CurrentTE->Send(g_TERecFilter, sp_ctof(params[3]));
1.140 + g_CurrentTE = NULL;
1.141 +
1.142 + return 1;
1.143 +}
1.144 +
1.145 +static cell_t smn_TEIsValidProp(IPluginContext *pContext, const cell_t *params)
1.146 +{
1.147 + if (!g_TEManager.IsAvailable())
1.148 + {
1.149 + return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
1.150 + }
1.151 + if (!g_CurrentTE)
1.152 + {
1.153 + return pContext->ThrowNativeError("No TempEntity call is in progress");
1.154 + }
1.155 +
1.156 + char *prop;
1.157 + pContext->LocalToString(params[1], &prop);
1.158 +
1.159 + return g_CurrentTE->IsValidProp(prop) ? 1 : 0;
1.160 +}
1.161 +
1.162 +sp_nativeinfo_t g_TENatives[] =
1.163 +{
1.164 + {"TE_Start", smn_TEStart},
1.165 + {"TE_WriteNum", smn_TEWriteNum},
1.166 + {"TE_WriteFloat", smn_TE_WriteFloat},
1.167 + {"TE_WriteVector", smn_TEWriteVector},
1.168 + {"TE_WriteAngles", smn_TEWriteVector},
1.169 + {"TE_Send", smn_TESend},
1.170 + {"TE_IsValidProp", smn_TEIsValidProp},
1.171 + {NULL, NULL}
1.172 +};