1.1 --- a/extensions/sdktools/trnatives.cpp Wed Jan 23 03:18:36 2008 +0000
1.2 +++ b/extensions/sdktools/trnatives.cpp Wed Jan 23 17:05:50 2008 +0000
1.3 @@ -1,418 +1,444 @@
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 <worldsize.h>
1.37 -
1.38 -class CSMTraceFilter : public CTraceFilter
1.39 -{
1.40 -public:
1.41 - bool ShouldHitEntity(IHandleEntity *pEntity, int contentsMask)
1.42 - {
1.43 - cell_t res = 1;
1.44 - edict_t *pEdict = gameents->BaseEntityToEdict(reinterpret_cast<CBaseEntity *>(pEntity));
1.45 - m_pFunc->PushCell(engine->IndexOfEdict(pEdict));
1.46 - m_pFunc->PushCell(contentsMask);
1.47 - m_pFunc->PushCell(m_Data);
1.48 - m_pFunc->Execute(&res);
1.49 -
1.50 - return (res) ? true : false;
1.51 - }
1.52 - void SetFunctionPtr(IPluginFunction *pFunc, cell_t data)
1.53 - {
1.54 - m_pFunc = pFunc;
1.55 - m_Data = data;
1.56 - }
1.57 -private:
1.58 - IPluginFunction *m_pFunc;
1.59 - cell_t m_Data;
1.60 -};
1.61 -
1.62 -/* Used for the global trace version */
1.63 -Ray_t g_Ray;
1.64 -trace_t g_Trace;
1.65 -Vector g_StartVec;
1.66 -Vector g_EndVec;
1.67 -QAngle g_DirAngles;
1.68 -CTraceFilterHitAll g_HitAllFilter;
1.69 -CSMTraceFilter g_SMTraceFilter;
1.70 -
1.71 -enum
1.72 -{
1.73 - RayType_EndPoint,
1.74 - RayType_Infinite
1.75 -};
1.76 -
1.77 -static cell_t smn_TRTraceRay(IPluginContext *pContext, const cell_t *params)
1.78 -{
1.79 - cell_t *startaddr, *endaddr;
1.80 - pContext->LocalToPhysAddr(params[1], &startaddr);
1.81 - pContext->LocalToPhysAddr(params[2], &endaddr);
1.82 -
1.83 - g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
1.84 -
1.85 - switch (params[4])
1.86 - {
1.87 - case RayType_EndPoint:
1.88 - {
1.89 - g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.90 - break;
1.91 - }
1.92 - case RayType_Infinite:
1.93 - {
1.94 - g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.95 - AngleVectors(g_DirAngles, &g_EndVec);
1.96 -
1.97 - /* Make it unitary and get the ending point */
1.98 - g_EndVec.NormalizeInPlace();
1.99 - g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH;
1.100 - break;
1.101 - }
1.102 - }
1.103 -
1.104 - g_Ray.Init(g_StartVec, g_EndVec);
1.105 - enginetrace->TraceRay(g_Ray, params[3], &g_HitAllFilter, &g_Trace);
1.106 -
1.107 - return 1;
1.108 -}
1.109 -
1.110 -static cell_t smn_TRTraceRayFilter(IPluginContext *pContext, const cell_t *params)
1.111 -{
1.112 - cell_t *startaddr, *endaddr;
1.113 - IPluginFunction *pFunc;
1.114 - cell_t data;
1.115 -
1.116 - pFunc = pContext->GetFunctionById(params[5]);
1.117 - if (!pFunc)
1.118 - {
1.119 - return pContext->ThrowNativeError("Invalid function id (%X)", params[5]);
1.120 - }
1.121 -
1.122 - if (params[0] >= 6)
1.123 - {
1.124 - data = params[6];
1.125 - }
1.126 - else
1.127 - {
1.128 - data = 0;
1.129 - }
1.130 -
1.131 - g_SMTraceFilter.SetFunctionPtr(pFunc, data);
1.132 - pContext->LocalToPhysAddr(params[1], &startaddr);
1.133 - pContext->LocalToPhysAddr(params[2], &endaddr);
1.134 -
1.135 - g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
1.136 -
1.137 - switch (params[4])
1.138 - {
1.139 - case RayType_EndPoint:
1.140 - {
1.141 - g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.142 - break;
1.143 - }
1.144 - case RayType_Infinite:
1.145 - {
1.146 - g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.147 - AngleVectors(g_DirAngles, &g_EndVec);
1.148 -
1.149 - /* Make it unitary and get the ending point */
1.150 - g_EndVec.NormalizeInPlace();
1.151 - g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH;
1.152 - break;
1.153 - }
1.154 - }
1.155 -
1.156 - g_Ray.Init(g_StartVec, g_EndVec);
1.157 - enginetrace->TraceRay(g_Ray, params[3], &g_SMTraceFilter, &g_Trace);
1.158 -
1.159 - return 1;
1.160 -}
1.161 -
1.162 -static cell_t smn_TRTraceRayEx(IPluginContext *pContext, const cell_t *params)
1.163 -{
1.164 - cell_t *startaddr, *endaddr;
1.165 - pContext->LocalToPhysAddr(params[1], &startaddr);
1.166 - pContext->LocalToPhysAddr(params[2], &endaddr);
1.167 -
1.168 - Vector StartVec, EndVec;
1.169 - Ray_t ray;
1.170 -
1.171 - StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
1.172 -
1.173 - switch (params[4])
1.174 - {
1.175 - case RayType_EndPoint:
1.176 - {
1.177 - EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.178 - break;
1.179 - }
1.180 - case RayType_Infinite:
1.181 - {
1.182 - QAngle DirAngles;
1.183 - DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.184 - AngleVectors(DirAngles, &EndVec);
1.185 -
1.186 - /* Make it unitary and get the ending point */
1.187 - EndVec.NormalizeInPlace();
1.188 - EndVec = StartVec + EndVec * MAX_TRACE_LENGTH;
1.189 - break;
1.190 - }
1.191 - }
1.192 -
1.193 - trace_t *tr = new trace_t;
1.194 - ray.Init(StartVec, EndVec);
1.195 - enginetrace->TraceRay(ray, params[3], &g_HitAllFilter, tr);
1.196 -
1.197 - HandleError herr;
1.198 - Handle_t hndl;
1.199 - if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr)))
1.200 - {
1.201 - delete tr;
1.202 - return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr);
1.203 - }
1.204 -
1.205 - return hndl;
1.206 -}
1.207 -
1.208 -static cell_t smn_TRTraceRayFilterEx(IPluginContext *pContext, const cell_t *params)
1.209 -{
1.210 - IPluginFunction *pFunc;
1.211 - cell_t *startaddr, *endaddr;
1.212 - cell_t data;
1.213 -
1.214 - pFunc = pContext->GetFunctionById(params[5]);
1.215 - if (!pFunc)
1.216 - {
1.217 - return pContext->ThrowNativeError("Invalid function id (%X)", params[5]);
1.218 - }
1.219 - pContext->LocalToPhysAddr(params[1], &startaddr);
1.220 - pContext->LocalToPhysAddr(params[2], &endaddr);
1.221 -
1.222 - Vector StartVec, EndVec;
1.223 - CSMTraceFilter smfilter;
1.224 - Ray_t ray;
1.225 -
1.226 - if (params[0] >= 6)
1.227 - {
1.228 - data = params[6];
1.229 - }
1.230 - else
1.231 - {
1.232 - data = 0;
1.233 - }
1.234 -
1.235 - smfilter.SetFunctionPtr(pFunc, data);
1.236 - StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
1.237 -
1.238 - switch (params[4])
1.239 - {
1.240 - case RayType_EndPoint:
1.241 - {
1.242 - EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.243 - break;
1.244 - }
1.245 - case RayType_Infinite:
1.246 - {
1.247 - QAngle DirAngles;
1.248 - DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.249 - AngleVectors(DirAngles, &EndVec);
1.250 -
1.251 - /* Make it unitary and get the ending point */
1.252 - EndVec.NormalizeInPlace();
1.253 - EndVec = StartVec + EndVec * MAX_TRACE_LENGTH;
1.254 - break;
1.255 - }
1.256 - }
1.257 -
1.258 - trace_t *tr = new trace_t;
1.259 - ray.Init(StartVec, EndVec);
1.260 - enginetrace->TraceRay(ray, params[3], &smfilter, tr);
1.261 -
1.262 - HandleError herr;
1.263 - Handle_t hndl;
1.264 - if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr)))
1.265 - {
1.266 - delete tr;
1.267 - return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr);
1.268 - }
1.269 -
1.270 - return hndl;
1.271 -}
1.272 -
1.273 -static cell_t smn_TRGetFraction(IPluginContext *pContext, const cell_t *params)
1.274 -{
1.275 - trace_t *tr;
1.276 - HandleError err;
1.277 - HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
1.278 -
1.279 - if (params[1] == BAD_HANDLE)
1.280 - {
1.281 - tr = &g_Trace;
1.282 - } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
1.283 - return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
1.284 - }
1.285 -
1.286 - return sp_ftoc(tr->fraction);
1.287 -}
1.288 -
1.289 -static cell_t smn_TRGetEndPosition(IPluginContext *pContext, const cell_t *params)
1.290 -{
1.291 - trace_t *tr;
1.292 - HandleError err;
1.293 - HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
1.294 -
1.295 - if (params[2] == BAD_HANDLE)
1.296 - {
1.297 - tr = &g_Trace;
1.298 - } else if ((err = handlesys->ReadHandle(params[2], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
1.299 - return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[2], err);
1.300 - }
1.301 -
1.302 - cell_t *addr;
1.303 - pContext->LocalToPhysAddr(params[1], &addr);
1.304 -
1.305 - addr[0] = sp_ftoc(tr->endpos.x);
1.306 - addr[1] = sp_ftoc(tr->endpos.y);
1.307 - addr[2] = sp_ftoc(tr->endpos.z);
1.308 -
1.309 - return 1;
1.310 -}
1.311 -
1.312 -static cell_t smn_TRDidHit(IPluginContext *pContext, const cell_t *params)
1.313 -{
1.314 - trace_t *tr;
1.315 - HandleError err;
1.316 - HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
1.317 -
1.318 - if (params[1] == BAD_HANDLE)
1.319 - {
1.320 - tr = &g_Trace;
1.321 - } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
1.322 - return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
1.323 - }
1.324 -
1.325 - return tr->DidHit() ? 1 : 0;
1.326 -}
1.327 -
1.328 -static cell_t smn_TRGetHitGroup(IPluginContext *pContext, const cell_t *params)
1.329 -{
1.330 - trace_t *tr;
1.331 - HandleError err;
1.332 - HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
1.333 -
1.334 - if (params[1] == BAD_HANDLE)
1.335 - {
1.336 - tr = &g_Trace;
1.337 - } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
1.338 - return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
1.339 - }
1.340 -
1.341 - return tr->hitgroup;
1.342 -}
1.343 -
1.344 -static cell_t smn_TRGetEntityIndex(IPluginContext *pContext, const cell_t *params)
1.345 -{
1.346 - trace_t *tr;
1.347 - HandleError err;
1.348 - HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
1.349 -
1.350 - if (params[1] == BAD_HANDLE)
1.351 - {
1.352 - tr = &g_Trace;
1.353 - } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
1.354 - return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
1.355 - }
1.356 -
1.357 - edict_t *pEdict = gameents->BaseEntityToEdict(tr->m_pEnt);
1.358 - return engine->IndexOfEdict(pEdict);
1.359 -}
1.360 -
1.361 -static cell_t smn_TRGetPointContents(IPluginContext *pContext, const cell_t *params)
1.362 -{
1.363 - cell_t *vec, *ent;
1.364 - IHandleEntity *hentity;
1.365 - Vector pos;
1.366 - int mask;
1.367 -
1.368 - pContext->LocalToPhysAddr(params[1], &vec);
1.369 - pContext->LocalToPhysAddr(params[2], &ent);
1.370 -
1.371 - pos.x = sp_ctof(vec[0]);
1.372 - pos.y = sp_ctof(vec[1]);
1.373 - pos.z = sp_ctof(vec[2]);
1.374 -
1.375 - if (*ent == -1)
1.376 - {
1.377 - mask = enginetrace->GetPointContents(pos);
1.378 - } else {
1.379 - mask = enginetrace->GetPointContents(pos, &hentity);
1.380 - edict_t *pEdict = gameents->BaseEntityToEdict(reinterpret_cast<CBaseEntity *>(hentity));
1.381 - *ent = engine->IndexOfEdict(pEdict);
1.382 - }
1.383 -
1.384 - return mask;
1.385 -}
1.386 -
1.387 -static cell_t smn_TRGetPointContentsEnt(IPluginContext *pContext, const cell_t *params)
1.388 -{
1.389 - edict_t *pEdict = engine->PEntityOfEntIndex(params[1]);
1.390 - if (!pEdict || pEdict->IsFree())
1.391 - {
1.392 - return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
1.393 - }
1.394 -
1.395 - cell_t *addr;
1.396 - Vector pos;
1.397 -
1.398 - pContext->LocalToPhysAddr(params[2], &addr);
1.399 -
1.400 - pos.x = sp_ctof(addr[0]);
1.401 - pos.y = sp_ctof(addr[1]);
1.402 - pos.z = sp_ctof(addr[2]);
1.403 -
1.404 - return enginetrace->GetPointContents_Collideable(pEdict->GetCollideable(), pos);
1.405 -}
1.406 -
1.407 -sp_nativeinfo_t g_TRNatives[] =
1.408 -{
1.409 - {"TR_TraceRay", smn_TRTraceRay},
1.410 - {"TR_TraceRayEx", smn_TRTraceRayEx},
1.411 - {"TR_GetFraction", smn_TRGetFraction},
1.412 - {"TR_GetEndPosition", smn_TRGetEndPosition},
1.413 - {"TR_GetEntityIndex", smn_TRGetEntityIndex},
1.414 - {"TR_DidHit", smn_TRDidHit},
1.415 - {"TR_GetHitGroup", smn_TRGetHitGroup},
1.416 - {"TR_GetPointContents", smn_TRGetPointContents},
1.417 - {"TR_GetPointContentsEnt", smn_TRGetPointContentsEnt},
1.418 - {"TR_TraceRayFilter", smn_TRTraceRayFilter},
1.419 - {"TR_TraceRayFilterEx", smn_TRTraceRayFilterEx},
1.420 - {NULL, NULL}
1.421 -};
1.422 +/**
1.423 + * vim: set ts=4 :
1.424 + * =============================================================================
1.425 + * SourceMod SDKTools Extension
1.426 + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
1.427 + * =============================================================================
1.428 + *
1.429 + * This program is free software; you can redistribute it and/or modify it under
1.430 + * the terms of the GNU General Public License, version 3.0, as published by the
1.431 + * Free Software Foundation.
1.432 + *
1.433 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.434 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.435 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.436 + * details.
1.437 + *
1.438 + * You should have received a copy of the GNU General Public License along with
1.439 + * this program. If not, see <http://www.gnu.org/licenses/>.
1.440 + *
1.441 + * As a special exception, AlliedModders LLC gives you permission to link the
1.442 + * code of this program (as well as its derivative works) to "Half-Life 2," the
1.443 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.444 + * by the Valve Corporation. You must obey the GNU General Public License in
1.445 + * all respects for all other code used. Additionally, AlliedModders LLC grants
1.446 + * this exception to all derivative works. AlliedModders LLC defines further
1.447 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.448 + * or <http://www.sourcemod.net/license.php>.
1.449 + *
1.450 + * Version: $Id$
1.451 + */
1.452 +
1.453 +#include "extension.h"
1.454 +#include <worldsize.h>
1.455 +
1.456 +class CSMTraceFilter : public CTraceFilter
1.457 +{
1.458 +public:
1.459 + bool ShouldHitEntity(IHandleEntity *pEntity, int contentsMask)
1.460 + {
1.461 + cell_t res = 1;
1.462 + edict_t *pEdict = gameents->BaseEntityToEdict(reinterpret_cast<CBaseEntity *>(pEntity));
1.463 + m_pFunc->PushCell(engine->IndexOfEdict(pEdict));
1.464 + m_pFunc->PushCell(contentsMask);
1.465 + m_pFunc->PushCell(m_Data);
1.466 + m_pFunc->Execute(&res);
1.467 +
1.468 + return (res) ? true : false;
1.469 + }
1.470 + void SetFunctionPtr(IPluginFunction *pFunc, cell_t data)
1.471 + {
1.472 + m_pFunc = pFunc;
1.473 + m_Data = data;
1.474 + }
1.475 +private:
1.476 + IPluginFunction *m_pFunc;
1.477 + cell_t m_Data;
1.478 +};
1.479 +
1.480 +/* Used for the global trace version */
1.481 +Ray_t g_Ray;
1.482 +trace_t g_Trace;
1.483 +Vector g_StartVec;
1.484 +Vector g_EndVec;
1.485 +QAngle g_DirAngles;
1.486 +CTraceFilterHitAll g_HitAllFilter;
1.487 +CSMTraceFilter g_SMTraceFilter;
1.488 +
1.489 +enum
1.490 +{
1.491 + RayType_EndPoint,
1.492 + RayType_Infinite
1.493 +};
1.494 +
1.495 +static cell_t smn_TRTraceRay(IPluginContext *pContext, const cell_t *params)
1.496 +{
1.497 + cell_t *startaddr, *endaddr;
1.498 + pContext->LocalToPhysAddr(params[1], &startaddr);
1.499 + pContext->LocalToPhysAddr(params[2], &endaddr);
1.500 +
1.501 + g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
1.502 +
1.503 + switch (params[4])
1.504 + {
1.505 + case RayType_EndPoint:
1.506 + {
1.507 + g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.508 + break;
1.509 + }
1.510 + case RayType_Infinite:
1.511 + {
1.512 + g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.513 + AngleVectors(g_DirAngles, &g_EndVec);
1.514 +
1.515 + /* Make it unitary and get the ending point */
1.516 + g_EndVec.NormalizeInPlace();
1.517 + g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH;
1.518 + break;
1.519 + }
1.520 + }
1.521 +
1.522 + g_Ray.Init(g_StartVec, g_EndVec);
1.523 + enginetrace->TraceRay(g_Ray, params[3], &g_HitAllFilter, &g_Trace);
1.524 +
1.525 + return 1;
1.526 +}
1.527 +
1.528 +static cell_t smn_TRTraceRayFilter(IPluginContext *pContext, const cell_t *params)
1.529 +{
1.530 + cell_t *startaddr, *endaddr;
1.531 + IPluginFunction *pFunc;
1.532 + cell_t data;
1.533 +
1.534 + pFunc = pContext->GetFunctionById(params[5]);
1.535 + if (!pFunc)
1.536 + {
1.537 + return pContext->ThrowNativeError("Invalid function id (%X)", params[5]);
1.538 + }
1.539 +
1.540 + if (params[0] >= 6)
1.541 + {
1.542 + data = params[6];
1.543 + }
1.544 + else
1.545 + {
1.546 + data = 0;
1.547 + }
1.548 +
1.549 + g_SMTraceFilter.SetFunctionPtr(pFunc, data);
1.550 + pContext->LocalToPhysAddr(params[1], &startaddr);
1.551 + pContext->LocalToPhysAddr(params[2], &endaddr);
1.552 +
1.553 + g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
1.554 +
1.555 + switch (params[4])
1.556 + {
1.557 + case RayType_EndPoint:
1.558 + {
1.559 + g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.560 + break;
1.561 + }
1.562 + case RayType_Infinite:
1.563 + {
1.564 + g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.565 + AngleVectors(g_DirAngles, &g_EndVec);
1.566 +
1.567 + /* Make it unitary and get the ending point */
1.568 + g_EndVec.NormalizeInPlace();
1.569 + g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH;
1.570 + break;
1.571 + }
1.572 + }
1.573 +
1.574 + g_Ray.Init(g_StartVec, g_EndVec);
1.575 + enginetrace->TraceRay(g_Ray, params[3], &g_SMTraceFilter, &g_Trace);
1.576 +
1.577 + return 1;
1.578 +}
1.579 +
1.580 +static cell_t smn_TRTraceRayEx(IPluginContext *pContext, const cell_t *params)
1.581 +{
1.582 + cell_t *startaddr, *endaddr;
1.583 + pContext->LocalToPhysAddr(params[1], &startaddr);
1.584 + pContext->LocalToPhysAddr(params[2], &endaddr);
1.585 +
1.586 + Vector StartVec, EndVec;
1.587 + Ray_t ray;
1.588 +
1.589 + StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
1.590 +
1.591 + switch (params[4])
1.592 + {
1.593 + case RayType_EndPoint:
1.594 + {
1.595 + EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.596 + break;
1.597 + }
1.598 + case RayType_Infinite:
1.599 + {
1.600 + QAngle DirAngles;
1.601 + DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.602 + AngleVectors(DirAngles, &EndVec);
1.603 +
1.604 + /* Make it unitary and get the ending point */
1.605 + EndVec.NormalizeInPlace();
1.606 + EndVec = StartVec + EndVec * MAX_TRACE_LENGTH;
1.607 + break;
1.608 + }
1.609 + }
1.610 +
1.611 + trace_t *tr = new trace_t;
1.612 + ray.Init(StartVec, EndVec);
1.613 + enginetrace->TraceRay(ray, params[3], &g_HitAllFilter, tr);
1.614 +
1.615 + HandleError herr;
1.616 + Handle_t hndl;
1.617 + if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr)))
1.618 + {
1.619 + delete tr;
1.620 + return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr);
1.621 + }
1.622 +
1.623 + return hndl;
1.624 +}
1.625 +
1.626 +static cell_t smn_TRTraceRayFilterEx(IPluginContext *pContext, const cell_t *params)
1.627 +{
1.628 + IPluginFunction *pFunc;
1.629 + cell_t *startaddr, *endaddr;
1.630 + cell_t data;
1.631 +
1.632 + pFunc = pContext->GetFunctionById(params[5]);
1.633 + if (!pFunc)
1.634 + {
1.635 + return pContext->ThrowNativeError("Invalid function id (%X)", params[5]);
1.636 + }
1.637 + pContext->LocalToPhysAddr(params[1], &startaddr);
1.638 + pContext->LocalToPhysAddr(params[2], &endaddr);
1.639 +
1.640 + Vector StartVec, EndVec;
1.641 + CSMTraceFilter smfilter;
1.642 + Ray_t ray;
1.643 +
1.644 + if (params[0] >= 6)
1.645 + {
1.646 + data = params[6];
1.647 + }
1.648 + else
1.649 + {
1.650 + data = 0;
1.651 + }
1.652 +
1.653 + smfilter.SetFunctionPtr(pFunc, data);
1.654 + StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
1.655 +
1.656 + switch (params[4])
1.657 + {
1.658 + case RayType_EndPoint:
1.659 + {
1.660 + EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.661 + break;
1.662 + }
1.663 + case RayType_Infinite:
1.664 + {
1.665 + QAngle DirAngles;
1.666 + DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
1.667 + AngleVectors(DirAngles, &EndVec);
1.668 +
1.669 + /* Make it unitary and get the ending point */
1.670 + EndVec.NormalizeInPlace();
1.671 + EndVec = StartVec + EndVec * MAX_TRACE_LENGTH;
1.672 + break;
1.673 + }
1.674 + }
1.675 +
1.676 + trace_t *tr = new trace_t;
1.677 + ray.Init(StartVec, EndVec);
1.678 + enginetrace->TraceRay(ray, params[3], &smfilter, tr);
1.679 +
1.680 + HandleError herr;
1.681 + Handle_t hndl;
1.682 + if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr)))
1.683 + {
1.684 + delete tr;
1.685 + return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr);
1.686 + }
1.687 +
1.688 + return hndl;
1.689 +}
1.690 +
1.691 +static cell_t smn_TRGetFraction(IPluginContext *pContext, const cell_t *params)
1.692 +{
1.693 + trace_t *tr;
1.694 + HandleError err;
1.695 + HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
1.696 +
1.697 + if (params[1] == BAD_HANDLE)
1.698 + {
1.699 + tr = &g_Trace;
1.700 + } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
1.701 + return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
1.702 + }
1.703 +
1.704 + return sp_ftoc(tr->fraction);
1.705 +}
1.706 +
1.707 +static cell_t smn_TRGetPlaneNormal(IPluginContext *pContext, const cell_t *params)
1.708 +{
1.709 + trace_t *tr;
1.710 + HandleError err;
1.711 + HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
1.712 +
1.713 + if (params[1] == BAD_HANDLE)
1.714 + {
1.715 + tr = &g_Trace;
1.716 + } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
1.717 + return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
1.718 + }
1.719 +
1.720 + Vector *normal = &tr->plane.normal;
1.721 +
1.722 + cell_t *r;
1.723 + pContext->LocalToPhysAddr(params[2], &r);
1.724 + r[0] = sp_ftoc(normal->x);
1.725 + r[1] = sp_ftoc(normal->y);
1.726 + r[2] = sp_ftoc(normal->z);
1.727 +
1.728 + return 1;
1.729 +}
1.730 +
1.731 +
1.732 +static cell_t smn_TRGetEndPosition(IPluginContext *pContext, const cell_t *params)
1.733 +{
1.734 + trace_t *tr;
1.735 + HandleError err;
1.736 + HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
1.737 +
1.738 + if (params[2] == BAD_HANDLE)
1.739 + {
1.740 + tr = &g_Trace;
1.741 + } else if ((err = handlesys->ReadHandle(params[2], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
1.742 + return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[2], err);
1.743 + }
1.744 +
1.745 + cell_t *addr;
1.746 + pContext->LocalToPhysAddr(params[1], &addr);
1.747 +
1.748 + addr[0] = sp_ftoc(tr->endpos.x);
1.749 + addr[1] = sp_ftoc(tr->endpos.y);
1.750 + addr[2] = sp_ftoc(tr->endpos.z);
1.751 +
1.752 + return 1;
1.753 +}
1.754 +
1.755 +static cell_t smn_TRDidHit(IPluginContext *pContext, const cell_t *params)
1.756 +{
1.757 + trace_t *tr;
1.758 + HandleError err;
1.759 + HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
1.760 +
1.761 + if (params[1] == BAD_HANDLE)
1.762 + {
1.763 + tr = &g_Trace;
1.764 + } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
1.765 + return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
1.766 + }
1.767 +
1.768 + return tr->DidHit() ? 1 : 0;
1.769 +}
1.770 +
1.771 +static cell_t smn_TRGetHitGroup(IPluginContext *pContext, const cell_t *params)
1.772 +{
1.773 + trace_t *tr;
1.774 + HandleError err;
1.775 + HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
1.776 +
1.777 + if (params[1] == BAD_HANDLE)
1.778 + {
1.779 + tr = &g_Trace;
1.780 + } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
1.781 + return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
1.782 + }
1.783 +
1.784 + return tr->hitgroup;
1.785 +}
1.786 +
1.787 +static cell_t smn_TRGetEntityIndex(IPluginContext *pContext, const cell_t *params)
1.788 +{
1.789 + trace_t *tr;
1.790 + HandleError err;
1.791 + HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
1.792 +
1.793 + if (params[1] == BAD_HANDLE)
1.794 + {
1.795 + tr = &g_Trace;
1.796 + } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
1.797 + return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
1.798 + }
1.799 +
1.800 + edict_t *pEdict = gameents->BaseEntityToEdict(tr->m_pEnt);
1.801 + return engine->IndexOfEdict(pEdict);
1.802 +}
1.803 +
1.804 +static cell_t smn_TRGetPointContents(IPluginContext *pContext, const cell_t *params)
1.805 +{
1.806 + cell_t *vec, *ent;
1.807 + IHandleEntity *hentity;
1.808 + Vector pos;
1.809 + int mask;
1.810 +
1.811 + pContext->LocalToPhysAddr(params[1], &vec);
1.812 + pContext->LocalToPhysAddr(params[2], &ent);
1.813 +
1.814 + pos.x = sp_ctof(vec[0]);
1.815 + pos.y = sp_ctof(vec[1]);
1.816 + pos.z = sp_ctof(vec[2]);
1.817 +
1.818 + if (*ent == -1)
1.819 + {
1.820 + mask = enginetrace->GetPointContents(pos);
1.821 + } else {
1.822 + mask = enginetrace->GetPointContents(pos, &hentity);
1.823 + edict_t *pEdict = gameents->BaseEntityToEdict(reinterpret_cast<CBaseEntity *>(hentity));
1.824 + *ent = engine->IndexOfEdict(pEdict);
1.825 + }
1.826 +
1.827 + return mask;
1.828 +}
1.829 +
1.830 +static cell_t smn_TRGetPointContentsEnt(IPluginContext *pContext, const cell_t *params)
1.831 +{
1.832 + edict_t *pEdict = engine->PEntityOfEntIndex(params[1]);
1.833 + if (!pEdict || pEdict->IsFree())
1.834 + {
1.835 + return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
1.836 + }
1.837 +
1.838 + cell_t *addr;
1.839 + Vector pos;
1.840 +
1.841 + pContext->LocalToPhysAddr(params[2], &addr);
1.842 +
1.843 + pos.x = sp_ctof(addr[0]);
1.844 + pos.y = sp_ctof(addr[1]);
1.845 + pos.z = sp_ctof(addr[2]);
1.846 +
1.847 + return enginetrace->GetPointContents_Collideable(pEdict->GetCollideable(), pos);
1.848 +}
1.849 +
1.850 +sp_nativeinfo_t g_TRNatives[] =
1.851 +{
1.852 + {"TR_TraceRay", smn_TRTraceRay},
1.853 + {"TR_TraceRayEx", smn_TRTraceRayEx},
1.854 + {"TR_GetFraction", smn_TRGetFraction},
1.855 + {"TR_GetEndPosition", smn_TRGetEndPosition},
1.856 + {"TR_GetEntityIndex", smn_TRGetEntityIndex},
1.857 + {"TR_DidHit", smn_TRDidHit},
1.858 + {"TR_GetHitGroup", smn_TRGetHitGroup},
1.859 + {"TR_GetPointContents", smn_TRGetPointContents},
1.860 + {"TR_GetPointContentsEnt", smn_TRGetPointContentsEnt},
1.861 + {"TR_TraceRayFilter", smn_TRTraceRayFilter},
1.862 + {"TR_TraceRayFilterEx", smn_TRTraceRayFilterEx},
1.863 + {"TR_GetPlaneNormal", smn_TRGetPlaneNormal},
1.864 + {NULL, NULL}
1.865 +};
2.1 --- a/plugins/include/sdktools_trace.inc Wed Jan 23 03:18:36 2008 +0000
2.2 +++ b/plugins/include/sdktools_trace.inc Wed Jan 23 17:05:50 2008 +0000
2.3 @@ -1,261 +1,271 @@
2.4 -/**
2.5 - * vim: set ts=4 :
2.6 - * =============================================================================
2.7 - * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
2.8 - * =============================================================================
2.9 - *
2.10 - * This file is part of the SourceMod/SourcePawn SDK.
2.11 - *
2.12 - * This program is free software; you can redistribute it and/or modify it under
2.13 - * the terms of the GNU General Public License, version 3.0, as published by the
2.14 - * Free Software Foundation.
2.15 - *
2.16 - * This program is distributed in the hope that it will be useful, but WITHOUT
2.17 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
2.18 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
2.19 - * details.
2.20 - *
2.21 - * You should have received a copy of the GNU General Public License along with
2.22 - * this program. If not, see <http://www.gnu.org/licenses/>.
2.23 - *
2.24 - * As a special exception, AlliedModders LLC gives you permission to link the
2.25 - * code of this program (as well as its derivative works) to "Half-Life 2," the
2.26 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
2.27 - * by the Valve Corporation. You must obey the GNU General Public License in
2.28 - * all respects for all other code used. Additionally, AlliedModders LLC grants
2.29 - * this exception to all derivative works. AlliedModders LLC defines further
2.30 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
2.31 - * or <http://www.sourcemod.net/license.php>.
2.32 - *
2.33 - * Version: $Id$
2.34 - */
2.35 -
2.36 -#if defined _sdktools_trace_included
2.37 - #endinput
2.38 -#endif
2.39 -#define _sdktools_trace_included
2.40 -
2.41 -#define CONTENTS_EMPTY 0 /**< No contents. */
2.42 -#define CONTENTS_SOLID 0x1 /**< an eye is never valid in a solid . */
2.43 -#define CONTENTS_WINDOW 0x2 /**< translucent, but not watery (glass). */
2.44 -#define CONTENTS_AUX 0x4
2.45 -#define CONTENTS_GRATE 0x8 /**< alpha-tested "grate" textures. Bullets/sight pass through, but solids don't. */
2.46 -#define CONTENTS_SLIME 0x10
2.47 -#define CONTENTS_WATER 0x20
2.48 -#define CONTENTS_MIST 0x40
2.49 -#define CONTENTS_OPAQUE 0x80 /**< things that cannot be seen through (may be non-solid though). */
2.50 -#define LAST_VISIBLE_CONTENTS 0x80
2.51 -#define ALL_VISIBLE_CONTENTS (LAST_VISIBLE_CONTENTS | (LAST_VISIBLE_CONTENTS-1))
2.52 -#define CONTENTS_TESTFOGVOLUME 0x100
2.53 -#define CONTENTS_UNUSED5 0x200
2.54 -#define CONTENTS_UNUSED6 0x4000
2.55 -#define CONTENTS_TEAM1 0x800 /**< per team contents used to differentiate collisions. */
2.56 -#define CONTENTS_TEAM2 0x1000 /**< between players and objects on different teams. */
2.57 -#define CONTENTS_IGNORE_NODRAW_OPAQUE 0x2000 /**< ignore CONTENTS_OPAQUE on surfaces that have SURF_NODRAW. */
2.58 -#define CONTENTS_MOVEABLE 0x4000 /**< hits entities which are MOVETYPE_PUSH (doors, plats, etc) */
2.59 -#define CONTENTS_AREAPORTAL 0x8000 /**< remaining contents are non-visible, and don't eat brushes. */
2.60 -#define CONTENTS_PLAYERCLIP 0x10000
2.61 -#define CONTENTS_MONSTERCLIP 0x20000
2.62 -
2.63 -/**
2.64 - * @section currents can be added to any other contents, and may be mixed
2.65 - */
2.66 -#define CONTENTS_CURRENT_0 0x40000
2.67 -#define CONTENTS_CURRENT_90 0x80000
2.68 -#define CONTENTS_CURRENT_180 0x100000
2.69 -#define CONTENTS_CURRENT_270 0x200000
2.70 -#define CONTENTS_CURRENT_UP 0x400000
2.71 -#define CONTENTS_CURRENT_DOWN 0x800000
2.72 -
2.73 -/**
2.74 - * @endsection
2.75 - */
2.76 -
2.77 -#define CONTENTS_ORIGIN 0x1000000 /**< removed before bsping an entity. */
2.78 -#define CONTENTS_MONSTER 0x2000000 /**< should never be on a brush, only in game. */
2.79 -#define CONTENTS_DEBRIS 0x4000000
2.80 -#define CONTENTS_DETAIL 0x8000000 /**< brushes to be added after vis leafs. */
2.81 -#define CONTENTS_TRANSLUCENT 0x10000000 /**< auto set if any surface has trans. */
2.82 -#define CONTENTS_LADDER 0x20000000
2.83 -#define CONTENTS_HITBOX 0x40000000 /**< use accurate hitboxes on trace. */
2.84 -
2.85 -/**
2.86 - * @section Trace masks.
2.87 - */
2.88 -#define MASK_ALL (0xFFFFFFFF)
2.89 -#define MASK_SOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< everything that is normally solid */
2.90 -#define MASK_PLAYERSOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< everything that blocks player movement */
2.91 -#define MASK_NPCSOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< blocks npc movement */
2.92 -#define MASK_WATER (CONTENTS_WATER|CONTENTS_MOVEABLE|CONTENTS_SLIME) /**< water physics in these contents */
2.93 -#define MASK_OPAQUE (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_OPAQUE) /**< everything that blocks line of sight for AI, lighting, etc */
2.94 -#define MASK_OPAQUE_AND_NPCS (MASK_OPAQUE|CONTENTS_MONSTER) /**< everything that blocks line of sight for AI, lighting, etc, but with monsters added. */
2.95 -#define MASK_VISIBLE (MASK_OPAQUE|CONTENTS_IGNORE_NODRAW_OPAQUE) /**< everything that blocks line of sight for players */
2.96 -#define MASK_VISIBLE_AND_NPCS (MASK_OPAQUE_AND_NPCS|CONTENTS_IGNORE_NODRAW_OPAQUE) /**< everything that blocks line of sight for players, but with monsters added. */
2.97 -#define MASK_SHOT (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_HITBOX) /**< bullets see these as solid */
2.98 -#define MASK_SHOT_HULL (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_GRATE) /**< non-raycasted weapons see this as solid (includes grates) */
2.99 -#define MASK_SHOT_PORTAL (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW) /**< hits solids (not grates) and passes through everything else */
2.100 -#define MASK_SOLID_BRUSHONLY (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE) /**< everything normally solid, except monsters (world+brush only) */
2.101 -#define MASK_PLAYERSOLID_BRUSHONLY (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_PLAYERCLIP|CONTENTS_GRATE) /**< everything normally solid for player movement, except monsters (world+brush only) */
2.102 -#define MASK_NPCSOLID_BRUSHONLY (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) /**< everything normally solid for npc movement, except monsters (world+brush only) */
2.103 -#define MASK_NPCWORLDSTATIC (CONTENTS_SOLID|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) /**< just the world, used for route rebuilding */
2.104 -#define MASK_SPLITAREAPORTAL (CONTENTS_WATER|CONTENTS_SLIME) /**< These are things that can split areaportals */
2.105 -
2.106 -/**
2.107 - * @endsection
2.108 - */
2.109 -
2.110 -enum RayType
2.111 -{
2.112 - RayType_EndPoint, /**< The trace ray will go from the start position to the end position. */
2.113 - RayType_Infinite /**< The trace ray will go from the start position to infinity using a direction vector. */
2.114 -};
2.115 -
2.116 -funcenum TraceEntityFilter
2.117 -{
2.118 - /**
2.119 - * Called on entity filtering.
2.120 - *
2.121 - * @param entity Entity index.
2.122 - * @param contentsMask Contents Mask.
2.123 - * @return True to allow the current entity to be hit, otherwise false.
2.124 - */
2.125 - bool:public(entity, contentsMask),
2.126 -
2.127 - /**
2.128 - * Called on entity filtering.
2.129 - *
2.130 - * @param entity Entity index.
2.131 - * @param contentsMask Contents Mask.
2.132 - * @param data Data value, if used.
2.133 - * @return True to allow the current entity to be hit, otherwise false.
2.134 - */
2.135 - bool:public(entity, contentsMask, any:data),
2.136 -};
2.137 -
2.138 -/**
2.139 - * Get the contents mask and the entity index at the given position.
2.140 - *
2.141 - * @param pos World position to test.
2.142 - * @param entindex Entity index found at the given position (by reference).
2.143 - * @return Contents mask.
2.144 - */
2.145 -native TR_GetPointContents(const Float:pos[3], &entindex=-1);
2.146 -
2.147 -/**
2.148 - * Get the point contents testing only the given entity index.
2.149 - *
2.150 - * @param entindex Entity index to test.
2.151 - * @param pos World position.
2.152 - * @return Contents mask.
2.153 - */
2.154 -native TR_GetPointContentsEnt(entindex, const Float:pos[3]);
2.155 -
2.156 -/**
2.157 - * Starts up a new trace ray using a global trace result.
2.158 - *
2.159 - * @param pos Starting position of the ray.
2.160 - * @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
2.161 - * @param flags Trace flags.
2.162 - * @param rtype Method to calculate the ray direction.
2.163 - * @noreturn
2.164 - */
2.165 -native TR_TraceRay(const Float:pos[3], const Float:vec[3], flags, RayType:rtype);
2.166 -
2.167 -/**
2.168 - * Starts up a new trace ray using a global trace result and a customized trace ray filter.
2.169 - *
2.170 - * Calling TR_TraceRayFilter or TR_TraceRayFilterEx from inside a filter function is
2.171 - * currently not allowed and may not work.
2.172 - *
2.173 - * @param pos Starting position of the ray.
2.174 - * @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
2.175 - * @param flags Trace flags.
2.176 - * @param rtype Method to calculate the ray direction.
2.177 - * @param filter Function to use as a filter.
2.178 - * @param data Arbitrary data value to pass through to the filter function.
2.179 - * @noreturn
2.180 - */
2.181 -native TR_TraceRayFilter(const Float:pos[3],
2.182 - const Float:vec[3],
2.183 - flags,
2.184 - RayType:rtype,
2.185 - TraceEntityFilter:filter,
2.186 - any:data=0);
2.187 -
2.188 -/**
2.189 - * Starts up a new trace ray using a new trace result.
2.190 - *
2.191 - * @param pos Starting position of the ray.
2.192 - * @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
2.193 - * @param flags Trace flags.
2.194 - * @param rtype Method to calculate the ray direction.
2.195 - * @return Ray trace handle, which must be closed via CloseHandle().
2.196 - */
2.197 -native Handle:TR_TraceRayEx(const Float:pos[3], const Float:vec[3], flags, RayType:rtype);
2.198 -
2.199 -/**
2.200 - * Starts up a new trace ray using a new trace result and a customized trace ray filter.
2.201 - *
2.202 - * Calling TR_TraceRayFilter or TR_TraceRayFilterEx from inside a filter function is
2.203 - * currently not allowed and may not work.
2.204 - *
2.205 - * @param pos Starting position of the ray.
2.206 - * @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
2.207 - * @param flags Trace flags.
2.208 - * @param rtype Method to calculate the ray direction.
2.209 - * @param filter Function to use as a filter.
2.210 - * @param data Arbitrary data value to pass through to the filter function.
2.211 - * @return Ray trace handle, which must be closed via CloseHandle().
2.212 - */
2.213 -native Handle:TR_TraceRayFilterEx(const Float:pos[3],
2.214 - const Float:vec[3],
2.215 - flags,
2.216 - RayType:rtype,
2.217 - TraceEntityFilter:filter,
2.218 - any:data=0);
2.219 -
2.220 -/**
2.221 - * Returns the time fraction from a trace result (1.0 means no collision).
2.222 - *
2.223 - * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
2.224 - * @return Time fraction value of the trace.
2.225 - * @error Invalid Handle.
2.226 - */
2.227 -native Float:TR_GetFraction(Handle:hndl=INVALID_HANDLE);
2.228 -
2.229 -/**
2.230 - * Returns the collision position of a trace result.
2.231 - *
2.232 - * @param pos Vector buffer to store data in.
2.233 - * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
2.234 - * @noreturn
2.235 - * @error Invalid Handle.
2.236 - */
2.237 -native TR_GetEndPosition(Float:pos[3], Handle:hndl=INVALID_HANDLE);
2.238 -
2.239 -/**
2.240 - * Returns the entity index that collided with the trace.
2.241 - *
2.242 - * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
2.243 - * @return Entity index or -1 for no collision.
2.244 - * @error Invalid Handle.
2.245 - */
2.246 -native TR_GetEntityIndex(Handle:hndl=INVALID_HANDLE);
2.247 -
2.248 -/**
2.249 - * Returns if there was any kind of collision along the trace ray.
2.250 - *
2.251 - * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
2.252 - * @return True if any collision found, otherwise false.
2.253 - * @error Invalid Handle.
2.254 - */
2.255 -native bool:TR_DidHit(Handle:hndl=INVALID_HANDLE);
2.256 -
2.257 -/**
2.258 - * Returns in which body hit group the trace collided if any.
2.259 - *
2.260 - * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
2.261 - * @return Body hit group.
2.262 - * @error Invalid Handle.
2.263 - */
2.264 -native TR_GetHitGroup(Handle:hndl=INVALID_HANDLE);
2.265 +/**
2.266 + * vim: set ts=4 :
2.267 + * =============================================================================
2.268 + * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
2.269 + * =============================================================================
2.270 + *
2.271 + * This file is part of the SourceMod/SourcePawn SDK.
2.272 + *
2.273 + * This program is free software; you can redistribute it and/or modify it under
2.274 + * the terms of the GNU General Public License, version 3.0, as published by the
2.275 + * Free Software Foundation.
2.276 + *
2.277 + * This program is distributed in the hope that it will be useful, but WITHOUT
2.278 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
2.279 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
2.280 + * details.
2.281 + *
2.282 + * You should have received a copy of the GNU General Public License along with
2.283 + * this program. If not, see <http://www.gnu.org/licenses/>.
2.284 + *
2.285 + * As a special exception, AlliedModders LLC gives you permission to link the
2.286 + * code of this program (as well as its derivative works) to "Half-Life 2," the
2.287 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
2.288 + * by the Valve Corporation. You must obey the GNU General Public License in
2.289 + * all respects for all other code used. Additionally, AlliedModders LLC grants
2.290 + * this exception to all derivative works. AlliedModders LLC defines further
2.291 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
2.292 + * or <http://www.sourcemod.net/license.php>.
2.293 + *
2.294 + * Version: $Id$
2.295 + */
2.296 +
2.297 +#if defined _sdktools_trace_included
2.298 + #endinput
2.299 +#endif
2.300 +#define _sdktools_trace_included
2.301 +
2.302 +#define CONTENTS_EMPTY 0 /**< No contents. */
2.303 +#define CONTENTS_SOLID 0x1 /**< an eye is never valid in a solid . */
2.304 +#define CONTENTS_WINDOW 0x2 /**< translucent, but not watery (glass). */
2.305 +#define CONTENTS_AUX 0x4
2.306 +#define CONTENTS_GRATE 0x8 /**< alpha-tested "grate" textures. Bullets/sight pass through, but solids don't. */
2.307 +#define CONTENTS_SLIME 0x10
2.308 +#define CONTENTS_WATER 0x20
2.309 +#define CONTENTS_MIST 0x40
2.310 +#define CONTENTS_OPAQUE 0x80 /**< things that cannot be seen through (may be non-solid though). */
2.311 +#define LAST_VISIBLE_CONTENTS 0x80
2.312 +#define ALL_VISIBLE_CONTENTS (LAST_VISIBLE_CONTENTS | (LAST_VISIBLE_CONTENTS-1))
2.313 +#define CONTENTS_TESTFOGVOLUME 0x100
2.314 +#define CONTENTS_UNUSED5 0x200
2.315 +#define CONTENTS_UNUSED6 0x4000
2.316 +#define CONTENTS_TEAM1 0x800 /**< per team contents used to differentiate collisions. */
2.317 +#define CONTENTS_TEAM2 0x1000 /**< between players and objects on different teams. */
2.318 +#define CONTENTS_IGNORE_NODRAW_OPAQUE 0x2000 /**< ignore CONTENTS_OPAQUE on surfaces that have SURF_NODRAW. */
2.319 +#define CONTENTS_MOVEABLE 0x4000 /**< hits entities which are MOVETYPE_PUSH (doors, plats, etc) */
2.320 +#define CONTENTS_AREAPORTAL 0x8000 /**< remaining contents are non-visible, and don't eat brushes. */
2.321 +#define CONTENTS_PLAYERCLIP 0x10000
2.322 +#define CONTENTS_MONSTERCLIP 0x20000
2.323 +
2.324 +/**
2.325 + * @section currents can be added to any other contents, and may be mixed
2.326 + */
2.327 +#define CONTENTS_CURRENT_0 0x40000
2.328 +#define CONTENTS_CURRENT_90 0x80000
2.329 +#define CONTENTS_CURRENT_180 0x100000
2.330 +#define CONTENTS_CURRENT_270 0x200000
2.331 +#define CONTENTS_CURRENT_UP 0x400000
2.332 +#define CONTENTS_CURRENT_DOWN 0x800000
2.333 +
2.334 +/**
2.335 + * @endsection
2.336 + */
2.337 +
2.338 +#define CONTENTS_ORIGIN 0x1000000 /**< removed before bsping an entity. */
2.339 +#define CONTENTS_MONSTER 0x2000000 /**< should never be on a brush, only in game. */
2.340 +#define CONTENTS_DEBRIS 0x4000000
2.341 +#define CONTENTS_DETAIL 0x8000000 /**< brushes to be added after vis leafs. */
2.342 +#define CONTENTS_TRANSLUCENT 0x10000000 /**< auto set if any surface has trans. */
2.343 +#define CONTENTS_LADDER 0x20000000
2.344 +#define CONTENTS_HITBOX 0x40000000 /**< use accurate hitboxes on trace. */
2.345 +
2.346 +/**
2.347 + * @section Trace masks.
2.348 + */
2.349 +#define MASK_ALL (0xFFFFFFFF)
2.350 +#define MASK_SOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< everything that is normally solid */
2.351 +#define MASK_PLAYERSOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< everything that blocks player movement */
2.352 +#define MASK_NPCSOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< blocks npc movement */
2.353 +#define MASK_WATER (CONTENTS_WATER|CONTENTS_MOVEABLE|CONTENTS_SLIME) /**< water physics in these contents */
2.354 +#define MASK_OPAQUE (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_OPAQUE) /**< everything that blocks line of sight for AI, lighting, etc */
2.355 +#define MASK_OPAQUE_AND_NPCS (MASK_OPAQUE|CONTENTS_MONSTER) /**< everything that blocks line of sight for AI, lighting, etc, but with monsters added. */
2.356 +#define MASK_VISIBLE (MASK_OPAQUE|CONTENTS_IGNORE_NODRAW_OPAQUE) /**< everything that blocks line of sight for players */
2.357 +#define MASK_VISIBLE_AND_NPCS (MASK_OPAQUE_AND_NPCS|CONTENTS_IGNORE_NODRAW_OPAQUE) /**< everything that blocks line of sight for players, but with monsters added. */
2.358 +#define MASK_SHOT (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_HITBOX) /**< bullets see these as solid */
2.359 +#define MASK_SHOT_HULL (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_GRATE) /**< non-raycasted weapons see this as solid (includes grates) */
2.360 +#define MASK_SHOT_PORTAL (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW) /**< hits solids (not grates) and passes through everything else */
2.361 +#define MASK_SOLID_BRUSHONLY (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE) /**< everything normally solid, except monsters (world+brush only) */
2.362 +#define MASK_PLAYERSOLID_BRUSHONLY (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_PLAYERCLIP|CONTENTS_GRATE) /**< everything normally solid for player movement, except monsters (world+brush only) */
2.363 +#define MASK_NPCSOLID_BRUSHONLY (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) /**< everything normally solid for npc movement, except monsters (world+brush only) */
2.364 +#define MASK_NPCWORLDSTATIC (CONTENTS_SOLID|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) /**< just the world, used for route rebuilding */
2.365 +#define MASK_SPLITAREAPORTAL (CONTENTS_WATER|CONTENTS_SLIME) /**< These are things that can split areaportals */
2.366 +
2.367 +/**
2.368 + * @endsection
2.369 + */
2.370 +
2.371 +enum RayType
2.372 +{
2.373 + RayType_EndPoint, /**< The trace ray will go from the start position to the end position. */
2.374 + RayType_Infinite /**< The trace ray will go from the start position to infinity using a direction vector. */
2.375 +};
2.376 +
2.377 +funcenum TraceEntityFilter
2.378 +{
2.379 + /**
2.380 + * Called on entity filtering.
2.381 + *
2.382 + * @param entity Entity index.
2.383 + * @param contentsMask Contents Mask.
2.384 + * @return True to allow the current entity to be hit, otherwise false.
2.385 + */
2.386 + bool:public(entity, contentsMask),
2.387 +
2.388 + /**
2.389 + * Called on entity filtering.
2.390 + *
2.391 + * @param entity Entity index.
2.392 + * @param contentsMask Contents Mask.
2.393 + * @param data Data value, if used.
2.394 + * @return True to allow the current entity to be hit, otherwise false.
2.395 + */
2.396 + bool:public(entity, contentsMask, any:data),
2.397 +};
2.398 +
2.399 +/**
2.400 + * Get the contents mask and the entity index at the given position.
2.401 + *
2.402 + * @param pos World position to test.
2.403 + * @param entindex Entity index found at the given position (by reference).
2.404 + * @return Contents mask.
2.405 + */
2.406 +native TR_GetPointContents(const Float:pos[3], &entindex=-1);
2.407 +
2.408 +/**
2.409 + * Get the point contents testing only the given entity index.
2.410 + *
2.411 + * @param entindex Entity index to test.
2.412 + * @param pos World position.
2.413 + * @return Contents mask.
2.414 + */
2.415 +native TR_GetPointContentsEnt(entindex, const Float:pos[3]);
2.416 +
2.417 +/**
2.418 + * Starts up a new trace ray using a global trace result.
2.419 + *
2.420 + * @param pos Starting position of the ray.
2.421 + * @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
2.422 + * @param flags Trace flags.
2.423 + * @param rtype Method to calculate the ray direction.
2.424 + * @noreturn
2.425 + */
2.426 +native TR_TraceRay(const Float:pos[3], const Float:vec[3], flags, RayType:rtype);
2.427 +
2.428 +/**
2.429 + * Starts up a new trace ray using a global trace result and a customized trace ray filter.
2.430 + *
2.431 + * Calling TR_TraceRayFilter or TR_TraceRayFilterEx from inside a filter function is
2.432 + * currently not allowed and may not work.
2.433 + *
2.434 + * @param pos Starting position of the ray.
2.435 + * @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
2.436 + * @param flags Trace flags.
2.437 + * @param rtype Method to calculate the ray direction.
2.438 + * @param filter Function to use as a filter.
2.439 + * @param data Arbitrary data value to pass through to the filter function.
2.440 + * @noreturn
2.441 + */
2.442 +native TR_TraceRayFilter(const Float:pos[3],
2.443 + const Float:vec[3],
2.444 + flags,
2.445 + RayType:rtype,
2.446 + TraceEntityFilter:filter,
2.447 + any:data=0);
2.448 +
2.449 +/**
2.450 + * Starts up a new trace ray using a new trace result.
2.451 + *
2.452 + * @param pos Starting position of the ray.
2.453 + * @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
2.454 + * @param flags Trace flags.
2.455 + * @param rtype Method to calculate the ray direction.
2.456 + * @return Ray trace handle, which must be closed via CloseHandle().
2.457 + */
2.458 +native Handle:TR_TraceRayEx(const Float:pos[3], const Float:vec[3], flags, RayType:rtype);
2.459 +
2.460 +/**
2.461 + * Starts up a new trace ray using a new trace result and a customized trace ray filter.
2.462 + *
2.463 + * Calling TR_TraceRayFilter or TR_TraceRayFilterEx from inside a filter function is
2.464 + * currently not allowed and may not work.
2.465 + *
2.466 + * @param pos Starting position of the ray.
2.467 + * @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
2.468 + * @param flags Trace flags.
2.469 + * @param rtype Method to calculate the ray direction.
2.470 + * @param filter Function to use as a filter.
2.471 + * @param data Arbitrary data value to pass through to the filter function.
2.472 + * @return Ray trace handle, which must be closed via CloseHandle().
2.473 + */
2.474 +native Handle:TR_TraceRayFilterEx(const Float:pos[3],
2.475 + const Float:vec[3],
2.476 + flags,
2.477 + RayType:rtype,
2.478 + TraceEntityFilter:filter,
2.479 + any:data=0);
2.480 +
2.481 +/**
2.482 + * Returns the time fraction from a trace result (1.0 means no collision).
2.483 + *
2.484 + * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
2.485 + * @return Time fraction value of the trace.
2.486 + * @error Invalid Handle.
2.487 + */
2.488 +native Float:TR_GetFraction(Handle:hndl=INVALID_HANDLE);
2.489 +
2.490 +/**
2.491 + * Returns the collision position of a trace result.
2.492 + *
2.493 + * @param pos Vector buffer to store data in.
2.494 + * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
2.495 + * @noreturn
2.496 + * @error Invalid Handle.
2.497 + */
2.498 +native TR_GetEndPosition(Float:pos[3], Handle:hndl=INVALID_HANDLE);
2.499 +
2.500 +/**
2.501 + * Returns the entity index that collided with the trace.
2.502 + *
2.503 + * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
2.504 + * @return Entity index or -1 for no collision.
2.505 + * @error Invalid Handle.
2.506 + */
2.507 +native TR_GetEntityIndex(Handle:hndl=INVALID_HANDLE);
2.508 +
2.509 +/**
2.510 + * Returns if there was any kind of collision along the trace ray.
2.511 + *
2.512 + * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
2.513 + * @return True if any collision found, otherwise false.
2.514 + * @error Invalid Handle.
2.515 + */
2.516 +native bool:TR_DidHit(Handle:hndl=INVALID_HANDLE);
2.517 +
2.518 +/**
2.519 + * Returns in which body hit group the trace collided if any.
2.520 + *
2.521 + * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
2.522 + * @return Body hit group.
2.523 + * @error Invalid Handle.
2.524 + */
2.525 +native TR_GetHitGroup(Handle:hndl=INVALID_HANDLE);
2.526 +
2.527 +/**
2.528 + * Find the normal vector to the collison plane of a trace.
2.529 + *
2.530 + * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
2.531 + * @param normal Vector buffer to store the vector normal to the collision plane
2.532 + * @noreturn
2.533 + * @error Invalid Handle
2.534 + */
2.535 +native TR_GetPlaneNormal(Handle:hndl=INVALID_HANDLE, Float:normal[3]);