added amb1403 - CBaseTrace.plane from pRED

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401865
This commit is contained in:
David Anderson 2008-01-23 17:05:50 +00:00
parent e553996281
commit 4ade0dbdc2
2 changed files with 715 additions and 679 deletions

View File

@ -1,418 +1,444 @@
/** /**
* vim: set ts=4 : * vim: set ts=4 :
* ============================================================================= * =============================================================================
* SourceMod SDKTools Extension * SourceMod SDKTools Extension
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
* ============================================================================= * =============================================================================
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
* *
* As a special exception, AlliedModders LLC gives you permission to link the * As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the * code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in * by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants * all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further * this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>. * or <http://www.sourcemod.net/license.php>.
* *
* Version: $Id$ * Version: $Id$
*/ */
#include "extension.h" #include "extension.h"
#include <worldsize.h> #include <worldsize.h>
class CSMTraceFilter : public CTraceFilter class CSMTraceFilter : public CTraceFilter
{ {
public: public:
bool ShouldHitEntity(IHandleEntity *pEntity, int contentsMask) bool ShouldHitEntity(IHandleEntity *pEntity, int contentsMask)
{ {
cell_t res = 1; cell_t res = 1;
edict_t *pEdict = gameents->BaseEntityToEdict(reinterpret_cast<CBaseEntity *>(pEntity)); edict_t *pEdict = gameents->BaseEntityToEdict(reinterpret_cast<CBaseEntity *>(pEntity));
m_pFunc->PushCell(engine->IndexOfEdict(pEdict)); m_pFunc->PushCell(engine->IndexOfEdict(pEdict));
m_pFunc->PushCell(contentsMask); m_pFunc->PushCell(contentsMask);
m_pFunc->PushCell(m_Data); m_pFunc->PushCell(m_Data);
m_pFunc->Execute(&res); m_pFunc->Execute(&res);
return (res) ? true : false; return (res) ? true : false;
} }
void SetFunctionPtr(IPluginFunction *pFunc, cell_t data) void SetFunctionPtr(IPluginFunction *pFunc, cell_t data)
{ {
m_pFunc = pFunc; m_pFunc = pFunc;
m_Data = data; m_Data = data;
} }
private: private:
IPluginFunction *m_pFunc; IPluginFunction *m_pFunc;
cell_t m_Data; cell_t m_Data;
}; };
/* Used for the global trace version */ /* Used for the global trace version */
Ray_t g_Ray; Ray_t g_Ray;
trace_t g_Trace; trace_t g_Trace;
Vector g_StartVec; Vector g_StartVec;
Vector g_EndVec; Vector g_EndVec;
QAngle g_DirAngles; QAngle g_DirAngles;
CTraceFilterHitAll g_HitAllFilter; CTraceFilterHitAll g_HitAllFilter;
CSMTraceFilter g_SMTraceFilter; CSMTraceFilter g_SMTraceFilter;
enum enum
{ {
RayType_EndPoint, RayType_EndPoint,
RayType_Infinite RayType_Infinite
}; };
static cell_t smn_TRTraceRay(IPluginContext *pContext, const cell_t *params) static cell_t smn_TRTraceRay(IPluginContext *pContext, const cell_t *params)
{ {
cell_t *startaddr, *endaddr; cell_t *startaddr, *endaddr;
pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[1], &startaddr);
pContext->LocalToPhysAddr(params[2], &endaddr); pContext->LocalToPhysAddr(params[2], &endaddr);
g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
switch (params[4]) switch (params[4])
{ {
case RayType_EndPoint: case RayType_EndPoint:
{ {
g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
break; break;
} }
case RayType_Infinite: case RayType_Infinite:
{ {
g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
AngleVectors(g_DirAngles, &g_EndVec); AngleVectors(g_DirAngles, &g_EndVec);
/* Make it unitary and get the ending point */ /* Make it unitary and get the ending point */
g_EndVec.NormalizeInPlace(); g_EndVec.NormalizeInPlace();
g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH; g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH;
break; break;
} }
} }
g_Ray.Init(g_StartVec, g_EndVec); g_Ray.Init(g_StartVec, g_EndVec);
enginetrace->TraceRay(g_Ray, params[3], &g_HitAllFilter, &g_Trace); enginetrace->TraceRay(g_Ray, params[3], &g_HitAllFilter, &g_Trace);
return 1; return 1;
} }
static cell_t smn_TRTraceRayFilter(IPluginContext *pContext, const cell_t *params) static cell_t smn_TRTraceRayFilter(IPluginContext *pContext, const cell_t *params)
{ {
cell_t *startaddr, *endaddr; cell_t *startaddr, *endaddr;
IPluginFunction *pFunc; IPluginFunction *pFunc;
cell_t data; cell_t data;
pFunc = pContext->GetFunctionById(params[5]); pFunc = pContext->GetFunctionById(params[5]);
if (!pFunc) if (!pFunc)
{ {
return pContext->ThrowNativeError("Invalid function id (%X)", params[5]); return pContext->ThrowNativeError("Invalid function id (%X)", params[5]);
} }
if (params[0] >= 6) if (params[0] >= 6)
{ {
data = params[6]; data = params[6];
} }
else else
{ {
data = 0; data = 0;
} }
g_SMTraceFilter.SetFunctionPtr(pFunc, data); g_SMTraceFilter.SetFunctionPtr(pFunc, data);
pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[1], &startaddr);
pContext->LocalToPhysAddr(params[2], &endaddr); pContext->LocalToPhysAddr(params[2], &endaddr);
g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
switch (params[4]) switch (params[4])
{ {
case RayType_EndPoint: case RayType_EndPoint:
{ {
g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
break; break;
} }
case RayType_Infinite: case RayType_Infinite:
{ {
g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
AngleVectors(g_DirAngles, &g_EndVec); AngleVectors(g_DirAngles, &g_EndVec);
/* Make it unitary and get the ending point */ /* Make it unitary and get the ending point */
g_EndVec.NormalizeInPlace(); g_EndVec.NormalizeInPlace();
g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH; g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH;
break; break;
} }
} }
g_Ray.Init(g_StartVec, g_EndVec); g_Ray.Init(g_StartVec, g_EndVec);
enginetrace->TraceRay(g_Ray, params[3], &g_SMTraceFilter, &g_Trace); enginetrace->TraceRay(g_Ray, params[3], &g_SMTraceFilter, &g_Trace);
return 1; return 1;
} }
static cell_t smn_TRTraceRayEx(IPluginContext *pContext, const cell_t *params) static cell_t smn_TRTraceRayEx(IPluginContext *pContext, const cell_t *params)
{ {
cell_t *startaddr, *endaddr; cell_t *startaddr, *endaddr;
pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[1], &startaddr);
pContext->LocalToPhysAddr(params[2], &endaddr); pContext->LocalToPhysAddr(params[2], &endaddr);
Vector StartVec, EndVec; Vector StartVec, EndVec;
Ray_t ray; Ray_t ray;
StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
switch (params[4]) switch (params[4])
{ {
case RayType_EndPoint: case RayType_EndPoint:
{ {
EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
break; break;
} }
case RayType_Infinite: case RayType_Infinite:
{ {
QAngle DirAngles; QAngle DirAngles;
DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
AngleVectors(DirAngles, &EndVec); AngleVectors(DirAngles, &EndVec);
/* Make it unitary and get the ending point */ /* Make it unitary and get the ending point */
EndVec.NormalizeInPlace(); EndVec.NormalizeInPlace();
EndVec = StartVec + EndVec * MAX_TRACE_LENGTH; EndVec = StartVec + EndVec * MAX_TRACE_LENGTH;
break; break;
} }
} }
trace_t *tr = new trace_t; trace_t *tr = new trace_t;
ray.Init(StartVec, EndVec); ray.Init(StartVec, EndVec);
enginetrace->TraceRay(ray, params[3], &g_HitAllFilter, tr); enginetrace->TraceRay(ray, params[3], &g_HitAllFilter, tr);
HandleError herr; HandleError herr;
Handle_t hndl; Handle_t hndl;
if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr))) if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr)))
{ {
delete tr; delete tr;
return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr); return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr);
} }
return hndl; return hndl;
} }
static cell_t smn_TRTraceRayFilterEx(IPluginContext *pContext, const cell_t *params) static cell_t smn_TRTraceRayFilterEx(IPluginContext *pContext, const cell_t *params)
{ {
IPluginFunction *pFunc; IPluginFunction *pFunc;
cell_t *startaddr, *endaddr; cell_t *startaddr, *endaddr;
cell_t data; cell_t data;
pFunc = pContext->GetFunctionById(params[5]); pFunc = pContext->GetFunctionById(params[5]);
if (!pFunc) if (!pFunc)
{ {
return pContext->ThrowNativeError("Invalid function id (%X)", params[5]); return pContext->ThrowNativeError("Invalid function id (%X)", params[5]);
} }
pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[1], &startaddr);
pContext->LocalToPhysAddr(params[2], &endaddr); pContext->LocalToPhysAddr(params[2], &endaddr);
Vector StartVec, EndVec; Vector StartVec, EndVec;
CSMTraceFilter smfilter; CSMTraceFilter smfilter;
Ray_t ray; Ray_t ray;
if (params[0] >= 6) if (params[0] >= 6)
{ {
data = params[6]; data = params[6];
} }
else else
{ {
data = 0; data = 0;
} }
smfilter.SetFunctionPtr(pFunc, data); smfilter.SetFunctionPtr(pFunc, data);
StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
switch (params[4]) switch (params[4])
{ {
case RayType_EndPoint: case RayType_EndPoint:
{ {
EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
break; break;
} }
case RayType_Infinite: case RayType_Infinite:
{ {
QAngle DirAngles; QAngle DirAngles;
DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
AngleVectors(DirAngles, &EndVec); AngleVectors(DirAngles, &EndVec);
/* Make it unitary and get the ending point */ /* Make it unitary and get the ending point */
EndVec.NormalizeInPlace(); EndVec.NormalizeInPlace();
EndVec = StartVec + EndVec * MAX_TRACE_LENGTH; EndVec = StartVec + EndVec * MAX_TRACE_LENGTH;
break; break;
} }
} }
trace_t *tr = new trace_t; trace_t *tr = new trace_t;
ray.Init(StartVec, EndVec); ray.Init(StartVec, EndVec);
enginetrace->TraceRay(ray, params[3], &smfilter, tr); enginetrace->TraceRay(ray, params[3], &smfilter, tr);
HandleError herr; HandleError herr;
Handle_t hndl; Handle_t hndl;
if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr))) if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr)))
{ {
delete tr; delete tr;
return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr); return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr);
} }
return hndl; return hndl;
} }
static cell_t smn_TRGetFraction(IPluginContext *pContext, const cell_t *params) static cell_t smn_TRGetFraction(IPluginContext *pContext, const cell_t *params)
{ {
trace_t *tr; trace_t *tr;
HandleError err; HandleError err;
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity()); HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
if (params[1] == BAD_HANDLE) if (params[1] == BAD_HANDLE)
{ {
tr = &g_Trace; tr = &g_Trace;
} else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) { } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
} }
return sp_ftoc(tr->fraction); return sp_ftoc(tr->fraction);
} }
static cell_t smn_TRGetEndPosition(IPluginContext *pContext, const cell_t *params) static cell_t smn_TRGetPlaneNormal(IPluginContext *pContext, const cell_t *params)
{ {
trace_t *tr; trace_t *tr;
HandleError err; HandleError err;
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity()); HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
if (params[2] == BAD_HANDLE) if (params[1] == BAD_HANDLE)
{ {
tr = &g_Trace; tr = &g_Trace;
} else if ((err = handlesys->ReadHandle(params[2], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) { } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[2], err); return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
} }
cell_t *addr; Vector *normal = &tr->plane.normal;
pContext->LocalToPhysAddr(params[1], &addr);
cell_t *r;
addr[0] = sp_ftoc(tr->endpos.x); pContext->LocalToPhysAddr(params[2], &r);
addr[1] = sp_ftoc(tr->endpos.y); r[0] = sp_ftoc(normal->x);
addr[2] = sp_ftoc(tr->endpos.z); r[1] = sp_ftoc(normal->y);
r[2] = sp_ftoc(normal->z);
return 1;
} return 1;
}
static cell_t smn_TRDidHit(IPluginContext *pContext, const cell_t *params)
{
trace_t *tr; static cell_t smn_TRGetEndPosition(IPluginContext *pContext, const cell_t *params)
HandleError err; {
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity()); trace_t *tr;
HandleError err;
if (params[1] == BAD_HANDLE) HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
{
tr = &g_Trace; if (params[2] == BAD_HANDLE)
} else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) { {
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); tr = &g_Trace;
} } else if ((err = handlesys->ReadHandle(params[2], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[2], err);
return tr->DidHit() ? 1 : 0; }
}
cell_t *addr;
static cell_t smn_TRGetHitGroup(IPluginContext *pContext, const cell_t *params) pContext->LocalToPhysAddr(params[1], &addr);
{
trace_t *tr; addr[0] = sp_ftoc(tr->endpos.x);
HandleError err; addr[1] = sp_ftoc(tr->endpos.y);
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity()); addr[2] = sp_ftoc(tr->endpos.z);
if (params[1] == BAD_HANDLE) return 1;
{ }
tr = &g_Trace;
} else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) { static cell_t smn_TRDidHit(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); {
} trace_t *tr;
HandleError err;
return tr->hitgroup; HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
}
if (params[1] == BAD_HANDLE)
static cell_t smn_TRGetEntityIndex(IPluginContext *pContext, const cell_t *params) {
{ tr = &g_Trace;
trace_t *tr; } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
HandleError err; return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity()); }
if (params[1] == BAD_HANDLE) return tr->DidHit() ? 1 : 0;
{ }
tr = &g_Trace;
} else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) { static cell_t smn_TRGetHitGroup(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); {
} trace_t *tr;
HandleError err;
edict_t *pEdict = gameents->BaseEntityToEdict(tr->m_pEnt); HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
return engine->IndexOfEdict(pEdict);
} if (params[1] == BAD_HANDLE)
{
static cell_t smn_TRGetPointContents(IPluginContext *pContext, const cell_t *params) tr = &g_Trace;
{ } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
cell_t *vec, *ent; return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
IHandleEntity *hentity; }
Vector pos;
int mask; return tr->hitgroup;
}
pContext->LocalToPhysAddr(params[1], &vec);
pContext->LocalToPhysAddr(params[2], &ent); static cell_t smn_TRGetEntityIndex(IPluginContext *pContext, const cell_t *params)
{
pos.x = sp_ctof(vec[0]); trace_t *tr;
pos.y = sp_ctof(vec[1]); HandleError err;
pos.z = sp_ctof(vec[2]); HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
if (*ent == -1) if (params[1] == BAD_HANDLE)
{ {
mask = enginetrace->GetPointContents(pos); tr = &g_Trace;
} else { } else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
mask = enginetrace->GetPointContents(pos, &hentity); return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
edict_t *pEdict = gameents->BaseEntityToEdict(reinterpret_cast<CBaseEntity *>(hentity)); }
*ent = engine->IndexOfEdict(pEdict);
} edict_t *pEdict = gameents->BaseEntityToEdict(tr->m_pEnt);
return engine->IndexOfEdict(pEdict);
return mask; }
}
static cell_t smn_TRGetPointContents(IPluginContext *pContext, const cell_t *params)
static cell_t smn_TRGetPointContentsEnt(IPluginContext *pContext, const cell_t *params) {
{ cell_t *vec, *ent;
edict_t *pEdict = engine->PEntityOfEntIndex(params[1]); IHandleEntity *hentity;
if (!pEdict || pEdict->IsFree()) Vector pos;
{ int mask;
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
} pContext->LocalToPhysAddr(params[1], &vec);
pContext->LocalToPhysAddr(params[2], &ent);
cell_t *addr;
Vector pos; pos.x = sp_ctof(vec[0]);
pos.y = sp_ctof(vec[1]);
pContext->LocalToPhysAddr(params[2], &addr); pos.z = sp_ctof(vec[2]);
pos.x = sp_ctof(addr[0]); if (*ent == -1)
pos.y = sp_ctof(addr[1]); {
pos.z = sp_ctof(addr[2]); mask = enginetrace->GetPointContents(pos);
} else {
return enginetrace->GetPointContents_Collideable(pEdict->GetCollideable(), pos); mask = enginetrace->GetPointContents(pos, &hentity);
} edict_t *pEdict = gameents->BaseEntityToEdict(reinterpret_cast<CBaseEntity *>(hentity));
*ent = engine->IndexOfEdict(pEdict);
sp_nativeinfo_t g_TRNatives[] = }
{
{"TR_TraceRay", smn_TRTraceRay}, return mask;
{"TR_TraceRayEx", smn_TRTraceRayEx}, }
{"TR_GetFraction", smn_TRGetFraction},
{"TR_GetEndPosition", smn_TRGetEndPosition}, static cell_t smn_TRGetPointContentsEnt(IPluginContext *pContext, const cell_t *params)
{"TR_GetEntityIndex", smn_TRGetEntityIndex}, {
{"TR_DidHit", smn_TRDidHit}, edict_t *pEdict = engine->PEntityOfEntIndex(params[1]);
{"TR_GetHitGroup", smn_TRGetHitGroup}, if (!pEdict || pEdict->IsFree())
{"TR_GetPointContents", smn_TRGetPointContents}, {
{"TR_GetPointContentsEnt", smn_TRGetPointContentsEnt}, return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
{"TR_TraceRayFilter", smn_TRTraceRayFilter}, }
{"TR_TraceRayFilterEx", smn_TRTraceRayFilterEx},
{NULL, NULL} cell_t *addr;
}; Vector pos;
pContext->LocalToPhysAddr(params[2], &addr);
pos.x = sp_ctof(addr[0]);
pos.y = sp_ctof(addr[1]);
pos.z = sp_ctof(addr[2]);
return enginetrace->GetPointContents_Collideable(pEdict->GetCollideable(), pos);
}
sp_nativeinfo_t g_TRNatives[] =
{
{"TR_TraceRay", smn_TRTraceRay},
{"TR_TraceRayEx", smn_TRTraceRayEx},
{"TR_GetFraction", smn_TRGetFraction},
{"TR_GetEndPosition", smn_TRGetEndPosition},
{"TR_GetEntityIndex", smn_TRGetEntityIndex},
{"TR_DidHit", smn_TRDidHit},
{"TR_GetHitGroup", smn_TRGetHitGroup},
{"TR_GetPointContents", smn_TRGetPointContents},
{"TR_GetPointContentsEnt", smn_TRGetPointContentsEnt},
{"TR_TraceRayFilter", smn_TRTraceRayFilter},
{"TR_TraceRayFilterEx", smn_TRTraceRayFilterEx},
{"TR_GetPlaneNormal", smn_TRGetPlaneNormal},
{NULL, NULL}
};

View File

@ -1,261 +1,271 @@
/** /**
* vim: set ts=4 : * vim: set ts=4 :
* ============================================================================= * =============================================================================
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
* ============================================================================= * =============================================================================
* *
* This file is part of the SourceMod/SourcePawn SDK. * This file is part of the SourceMod/SourcePawn SDK.
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
* *
* As a special exception, AlliedModders LLC gives you permission to link the * As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the * code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in * by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants * all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further * this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>. * or <http://www.sourcemod.net/license.php>.
* *
* Version: $Id$ * Version: $Id$
*/ */
#if defined _sdktools_trace_included #if defined _sdktools_trace_included
#endinput #endinput
#endif #endif
#define _sdktools_trace_included #define _sdktools_trace_included
#define CONTENTS_EMPTY 0 /**< No contents. */ #define CONTENTS_EMPTY 0 /**< No contents. */
#define CONTENTS_SOLID 0x1 /**< an eye is never valid in a solid . */ #define CONTENTS_SOLID 0x1 /**< an eye is never valid in a solid . */
#define CONTENTS_WINDOW 0x2 /**< translucent, but not watery (glass). */ #define CONTENTS_WINDOW 0x2 /**< translucent, but not watery (glass). */
#define CONTENTS_AUX 0x4 #define CONTENTS_AUX 0x4
#define CONTENTS_GRATE 0x8 /**< alpha-tested "grate" textures. Bullets/sight pass through, but solids don't. */ #define CONTENTS_GRATE 0x8 /**< alpha-tested "grate" textures. Bullets/sight pass through, but solids don't. */
#define CONTENTS_SLIME 0x10 #define CONTENTS_SLIME 0x10
#define CONTENTS_WATER 0x20 #define CONTENTS_WATER 0x20
#define CONTENTS_MIST 0x40 #define CONTENTS_MIST 0x40
#define CONTENTS_OPAQUE 0x80 /**< things that cannot be seen through (may be non-solid though). */ #define CONTENTS_OPAQUE 0x80 /**< things that cannot be seen through (may be non-solid though). */
#define LAST_VISIBLE_CONTENTS 0x80 #define LAST_VISIBLE_CONTENTS 0x80
#define ALL_VISIBLE_CONTENTS (LAST_VISIBLE_CONTENTS | (LAST_VISIBLE_CONTENTS-1)) #define ALL_VISIBLE_CONTENTS (LAST_VISIBLE_CONTENTS | (LAST_VISIBLE_CONTENTS-1))
#define CONTENTS_TESTFOGVOLUME 0x100 #define CONTENTS_TESTFOGVOLUME 0x100
#define CONTENTS_UNUSED5 0x200 #define CONTENTS_UNUSED5 0x200
#define CONTENTS_UNUSED6 0x4000 #define CONTENTS_UNUSED6 0x4000
#define CONTENTS_TEAM1 0x800 /**< per team contents used to differentiate collisions. */ #define CONTENTS_TEAM1 0x800 /**< per team contents used to differentiate collisions. */
#define CONTENTS_TEAM2 0x1000 /**< between players and objects on different teams. */ #define CONTENTS_TEAM2 0x1000 /**< between players and objects on different teams. */
#define CONTENTS_IGNORE_NODRAW_OPAQUE 0x2000 /**< ignore CONTENTS_OPAQUE on surfaces that have SURF_NODRAW. */ #define CONTENTS_IGNORE_NODRAW_OPAQUE 0x2000 /**< ignore CONTENTS_OPAQUE on surfaces that have SURF_NODRAW. */
#define CONTENTS_MOVEABLE 0x4000 /**< hits entities which are MOVETYPE_PUSH (doors, plats, etc) */ #define CONTENTS_MOVEABLE 0x4000 /**< hits entities which are MOVETYPE_PUSH (doors, plats, etc) */
#define CONTENTS_AREAPORTAL 0x8000 /**< remaining contents are non-visible, and don't eat brushes. */ #define CONTENTS_AREAPORTAL 0x8000 /**< remaining contents are non-visible, and don't eat brushes. */
#define CONTENTS_PLAYERCLIP 0x10000 #define CONTENTS_PLAYERCLIP 0x10000
#define CONTENTS_MONSTERCLIP 0x20000 #define CONTENTS_MONSTERCLIP 0x20000
/** /**
* @section currents can be added to any other contents, and may be mixed * @section currents can be added to any other contents, and may be mixed
*/ */
#define CONTENTS_CURRENT_0 0x40000 #define CONTENTS_CURRENT_0 0x40000
#define CONTENTS_CURRENT_90 0x80000 #define CONTENTS_CURRENT_90 0x80000
#define CONTENTS_CURRENT_180 0x100000 #define CONTENTS_CURRENT_180 0x100000
#define CONTENTS_CURRENT_270 0x200000 #define CONTENTS_CURRENT_270 0x200000
#define CONTENTS_CURRENT_UP 0x400000 #define CONTENTS_CURRENT_UP 0x400000
#define CONTENTS_CURRENT_DOWN 0x800000 #define CONTENTS_CURRENT_DOWN 0x800000
/** /**
* @endsection * @endsection
*/ */
#define CONTENTS_ORIGIN 0x1000000 /**< removed before bsping an entity. */ #define CONTENTS_ORIGIN 0x1000000 /**< removed before bsping an entity. */
#define CONTENTS_MONSTER 0x2000000 /**< should never be on a brush, only in game. */ #define CONTENTS_MONSTER 0x2000000 /**< should never be on a brush, only in game. */
#define CONTENTS_DEBRIS 0x4000000 #define CONTENTS_DEBRIS 0x4000000
#define CONTENTS_DETAIL 0x8000000 /**< brushes to be added after vis leafs. */ #define CONTENTS_DETAIL 0x8000000 /**< brushes to be added after vis leafs. */
#define CONTENTS_TRANSLUCENT 0x10000000 /**< auto set if any surface has trans. */ #define CONTENTS_TRANSLUCENT 0x10000000 /**< auto set if any surface has trans. */
#define CONTENTS_LADDER 0x20000000 #define CONTENTS_LADDER 0x20000000
#define CONTENTS_HITBOX 0x40000000 /**< use accurate hitboxes on trace. */ #define CONTENTS_HITBOX 0x40000000 /**< use accurate hitboxes on trace. */
/** /**
* @section Trace masks. * @section Trace masks.
*/ */
#define MASK_ALL (0xFFFFFFFF) #define MASK_ALL (0xFFFFFFFF)
#define MASK_SOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< everything that is normally solid */ #define MASK_SOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< everything that is normally solid */
#define MASK_PLAYERSOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< everything that blocks player movement */ #define MASK_PLAYERSOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< everything that blocks player movement */
#define MASK_NPCSOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< blocks npc movement */ #define MASK_NPCSOLID (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< blocks npc movement */
#define MASK_WATER (CONTENTS_WATER|CONTENTS_MOVEABLE|CONTENTS_SLIME) /**< water physics in these contents */ #define MASK_WATER (CONTENTS_WATER|CONTENTS_MOVEABLE|CONTENTS_SLIME) /**< water physics in these contents */
#define MASK_OPAQUE (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_OPAQUE) /**< everything that blocks line of sight for AI, lighting, etc */ #define MASK_OPAQUE (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_OPAQUE) /**< everything that blocks line of sight for AI, lighting, etc */
#define MASK_OPAQUE_AND_NPCS (MASK_OPAQUE|CONTENTS_MONSTER) /**< everything that blocks line of sight for AI, lighting, etc, but with monsters added. */ #define MASK_OPAQUE_AND_NPCS (MASK_OPAQUE|CONTENTS_MONSTER) /**< everything that blocks line of sight for AI, lighting, etc, but with monsters added. */
#define MASK_VISIBLE (MASK_OPAQUE|CONTENTS_IGNORE_NODRAW_OPAQUE) /**< everything that blocks line of sight for players */ #define MASK_VISIBLE (MASK_OPAQUE|CONTENTS_IGNORE_NODRAW_OPAQUE) /**< everything that blocks line of sight for players */
#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. */ #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. */
#define MASK_SHOT (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_HITBOX) /**< bullets see these as solid */ #define MASK_SHOT (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_HITBOX) /**< bullets see these as solid */
#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) */ #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) */
#define MASK_SHOT_PORTAL (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW) /**< hits solids (not grates) and passes through everything else */ #define MASK_SHOT_PORTAL (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW) /**< hits solids (not grates) and passes through everything else */
#define MASK_SOLID_BRUSHONLY (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE) /**< everything normally solid, except monsters (world+brush only) */ #define MASK_SOLID_BRUSHONLY (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE) /**< everything normally solid, except monsters (world+brush only) */
#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) */ #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) */
#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) */ #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) */
#define MASK_NPCWORLDSTATIC (CONTENTS_SOLID|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) /**< just the world, used for route rebuilding */ #define MASK_NPCWORLDSTATIC (CONTENTS_SOLID|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) /**< just the world, used for route rebuilding */
#define MASK_SPLITAREAPORTAL (CONTENTS_WATER|CONTENTS_SLIME) /**< These are things that can split areaportals */ #define MASK_SPLITAREAPORTAL (CONTENTS_WATER|CONTENTS_SLIME) /**< These are things that can split areaportals */
/** /**
* @endsection * @endsection
*/ */
enum RayType enum RayType
{ {
RayType_EndPoint, /**< The trace ray will go from the start position to the end position. */ RayType_EndPoint, /**< The trace ray will go from the start position to the end position. */
RayType_Infinite /**< The trace ray will go from the start position to infinity using a direction vector. */ RayType_Infinite /**< The trace ray will go from the start position to infinity using a direction vector. */
}; };
funcenum TraceEntityFilter funcenum TraceEntityFilter
{ {
/** /**
* Called on entity filtering. * Called on entity filtering.
* *
* @param entity Entity index. * @param entity Entity index.
* @param contentsMask Contents Mask. * @param contentsMask Contents Mask.
* @return True to allow the current entity to be hit, otherwise false. * @return True to allow the current entity to be hit, otherwise false.
*/ */
bool:public(entity, contentsMask), bool:public(entity, contentsMask),
/** /**
* Called on entity filtering. * Called on entity filtering.
* *
* @param entity Entity index. * @param entity Entity index.
* @param contentsMask Contents Mask. * @param contentsMask Contents Mask.
* @param data Data value, if used. * @param data Data value, if used.
* @return True to allow the current entity to be hit, otherwise false. * @return True to allow the current entity to be hit, otherwise false.
*/ */
bool:public(entity, contentsMask, any:data), bool:public(entity, contentsMask, any:data),
}; };
/** /**
* Get the contents mask and the entity index at the given position. * Get the contents mask and the entity index at the given position.
* *
* @param pos World position to test. * @param pos World position to test.
* @param entindex Entity index found at the given position (by reference). * @param entindex Entity index found at the given position (by reference).
* @return Contents mask. * @return Contents mask.
*/ */
native TR_GetPointContents(const Float:pos[3], &entindex=-1); native TR_GetPointContents(const Float:pos[3], &entindex=-1);
/** /**
* Get the point contents testing only the given entity index. * Get the point contents testing only the given entity index.
* *
* @param entindex Entity index to test. * @param entindex Entity index to test.
* @param pos World position. * @param pos World position.
* @return Contents mask. * @return Contents mask.
*/ */
native TR_GetPointContentsEnt(entindex, const Float:pos[3]); native TR_GetPointContentsEnt(entindex, const Float:pos[3]);
/** /**
* Starts up a new trace ray using a global trace result. * Starts up a new trace ray using a global trace result.
* *
* @param pos Starting position of the ray. * @param pos Starting position of the ray.
* @param vec Depending on RayType, it will be used as the ending point, or the direction angle. * @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
* @param flags Trace flags. * @param flags Trace flags.
* @param rtype Method to calculate the ray direction. * @param rtype Method to calculate the ray direction.
* @noreturn * @noreturn
*/ */
native TR_TraceRay(const Float:pos[3], const Float:vec[3], flags, RayType:rtype); native TR_TraceRay(const Float:pos[3], const Float:vec[3], flags, RayType:rtype);
/** /**
* Starts up a new trace ray using a global trace result and a customized trace ray filter. * Starts up a new trace ray using a global trace result and a customized trace ray filter.
* *
* Calling TR_TraceRayFilter or TR_TraceRayFilterEx from inside a filter function is * Calling TR_TraceRayFilter or TR_TraceRayFilterEx from inside a filter function is
* currently not allowed and may not work. * currently not allowed and may not work.
* *
* @param pos Starting position of the ray. * @param pos Starting position of the ray.
* @param vec Depending on RayType, it will be used as the ending point, or the direction angle. * @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
* @param flags Trace flags. * @param flags Trace flags.
* @param rtype Method to calculate the ray direction. * @param rtype Method to calculate the ray direction.
* @param filter Function to use as a filter. * @param filter Function to use as a filter.
* @param data Arbitrary data value to pass through to the filter function. * @param data Arbitrary data value to pass through to the filter function.
* @noreturn * @noreturn
*/ */
native TR_TraceRayFilter(const Float:pos[3], native TR_TraceRayFilter(const Float:pos[3],
const Float:vec[3], const Float:vec[3],
flags, flags,
RayType:rtype, RayType:rtype,
TraceEntityFilter:filter, TraceEntityFilter:filter,
any:data=0); any:data=0);
/** /**
* Starts up a new trace ray using a new trace result. * Starts up a new trace ray using a new trace result.
* *
* @param pos Starting position of the ray. * @param pos Starting position of the ray.
* @param vec Depending on RayType, it will be used as the ending point, or the direction angle. * @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
* @param flags Trace flags. * @param flags Trace flags.
* @param rtype Method to calculate the ray direction. * @param rtype Method to calculate the ray direction.
* @return Ray trace handle, which must be closed via CloseHandle(). * @return Ray trace handle, which must be closed via CloseHandle().
*/ */
native Handle:TR_TraceRayEx(const Float:pos[3], const Float:vec[3], flags, RayType:rtype); native Handle:TR_TraceRayEx(const Float:pos[3], const Float:vec[3], flags, RayType:rtype);
/** /**
* Starts up a new trace ray using a new trace result and a customized trace ray filter. * Starts up a new trace ray using a new trace result and a customized trace ray filter.
* *
* Calling TR_TraceRayFilter or TR_TraceRayFilterEx from inside a filter function is * Calling TR_TraceRayFilter or TR_TraceRayFilterEx from inside a filter function is
* currently not allowed and may not work. * currently not allowed and may not work.
* *
* @param pos Starting position of the ray. * @param pos Starting position of the ray.
* @param vec Depending on RayType, it will be used as the ending point, or the direction angle. * @param vec Depending on RayType, it will be used as the ending point, or the direction angle.
* @param flags Trace flags. * @param flags Trace flags.
* @param rtype Method to calculate the ray direction. * @param rtype Method to calculate the ray direction.
* @param filter Function to use as a filter. * @param filter Function to use as a filter.
* @param data Arbitrary data value to pass through to the filter function. * @param data Arbitrary data value to pass through to the filter function.
* @return Ray trace handle, which must be closed via CloseHandle(). * @return Ray trace handle, which must be closed via CloseHandle().
*/ */
native Handle:TR_TraceRayFilterEx(const Float:pos[3], native Handle:TR_TraceRayFilterEx(const Float:pos[3],
const Float:vec[3], const Float:vec[3],
flags, flags,
RayType:rtype, RayType:rtype,
TraceEntityFilter:filter, TraceEntityFilter:filter,
any:data=0); any:data=0);
/** /**
* Returns the time fraction from a trace result (1.0 means no collision). * Returns the time fraction from a trace result (1.0 means no collision).
* *
* @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result. * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
* @return Time fraction value of the trace. * @return Time fraction value of the trace.
* @error Invalid Handle. * @error Invalid Handle.
*/ */
native Float:TR_GetFraction(Handle:hndl=INVALID_HANDLE); native Float:TR_GetFraction(Handle:hndl=INVALID_HANDLE);
/** /**
* Returns the collision position of a trace result. * Returns the collision position of a trace result.
* *
* @param pos Vector buffer to store data in. * @param pos Vector buffer to store data in.
* @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result. * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
* @noreturn * @noreturn
* @error Invalid Handle. * @error Invalid Handle.
*/ */
native TR_GetEndPosition(Float:pos[3], Handle:hndl=INVALID_HANDLE); native TR_GetEndPosition(Float:pos[3], Handle:hndl=INVALID_HANDLE);
/** /**
* Returns the entity index that collided with the trace. * Returns the entity index that collided with the trace.
* *
* @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result. * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
* @return Entity index or -1 for no collision. * @return Entity index or -1 for no collision.
* @error Invalid Handle. * @error Invalid Handle.
*/ */
native TR_GetEntityIndex(Handle:hndl=INVALID_HANDLE); native TR_GetEntityIndex(Handle:hndl=INVALID_HANDLE);
/** /**
* Returns if there was any kind of collision along the trace ray. * Returns if there was any kind of collision along the trace ray.
* *
* @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result. * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
* @return True if any collision found, otherwise false. * @return True if any collision found, otherwise false.
* @error Invalid Handle. * @error Invalid Handle.
*/ */
native bool:TR_DidHit(Handle:hndl=INVALID_HANDLE); native bool:TR_DidHit(Handle:hndl=INVALID_HANDLE);
/** /**
* Returns in which body hit group the trace collided if any. * Returns in which body hit group the trace collided if any.
* *
* @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result. * @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
* @return Body hit group. * @return Body hit group.
* @error Invalid Handle. * @error Invalid Handle.
*/ */
native TR_GetHitGroup(Handle:hndl=INVALID_HANDLE); native TR_GetHitGroup(Handle:hndl=INVALID_HANDLE);
/**
* Find the normal vector to the collison plane of a trace.
*
* @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
* @param normal Vector buffer to store the vector normal to the collision plane
* @noreturn
* @error Invalid Handle
*/
native TR_GetPlaneNormal(Handle:hndl=INVALID_HANDLE, Float:normal[3]);