5#include <entity2/entityidentity.h>
6#include <entity2/entityinstance.h>
16static constexpr uint64_t
SightMask = CONTENTS_SOLID | CONTENTS_BLOCK_LOS;
17static constexpr uint64_t
SurfacesMask = CONTENTS_SOLID | CONTENTS_WINDOW | CONTENTS_PASS_BULLETS | CONTENTS_SKY;
28 return MASK_PLAYERSOLID;
35 CTraceFilter filter(
Mask(options.
Layers), COLLISION_GROUP_DEFAULT,
false);
44 if (!entity || !entity->m_pEntity)
48 return {
static_cast<uint32_t
>(entity->GetRefEHandle().ToInt())};
53 return TraceHit{.Hit = trace.DidHit(),
54 .Fraction = trace.m_flFraction,
55 .End = trace.m_vEndPos,
56 .Normal = trace.m_vHitNormal,
57 .HitEntity =
Ref(trace.m_pEnt),
58 .HitWorld = trace.DidHit() && trace.m_pEnt && trace.m_pEnt->m_pEntity &&
59 trace.m_pEnt->GetEntityIndex().Get() == 0};
64 return trace && trace->
Hit ? std::optional(*trace) : std::nullopt;
75 if (!_bindings.NavTraceLine)
77 return std::unexpected(
Error::Unsupported(
"the Nav_TraceLine vtable slot did not bind"));
86 return std::unexpected(available.error());
90 void* table = _bindings.NavTraceLine.Table();
92 alignas(16) CGameTrace trace;
93 _bindings.NavTraceLine(
NavPhysics(table), &from, &to, &filter, &trace);
100 if (!_bindings.NavTraceShape)
102 return std::unexpected(
Error::Unsupported(
"the Nav_TraceShape vtable slot did not bind"));
105 const Ray_t ray(mins, maxs);
107 void* table = _bindings.NavTraceShape.Table();
108 alignas(16) CGameTrace trace;
109 _bindings.NavTraceShape(
NavPhysics(table), &ray, &from, &to, &filter, &trace);
116 return Line(eyes, eyes + pawn.
EyeForward() * distance, {.Layers = layers, .Ignore1 = pawn});
127 return OnlyHit(
Box(from, to, mins, maxs, options));
140 return std::unexpected(std::move(hit).error());
CEntityInstance * Raw() const noexcept
A player's body: health, armor, movement, aim, weapons. The engine replaces it on every spawn; the Co...
Vector EyePosition() const
Vector EyeForward() const
Result< TraceHit > Line(const Vector &from, const Vector &to, const TraceOptions &options={}) const
Result< TraceHit > Box(const Vector &from, const Vector &to, const Vector &mins, const Vector &maxs, const TraceOptions &options={}) const
std::optional< TraceHit > FirstHit(const Vector &from, const Vector &to, const TraceOptions &options={}) const
Result< bool > Clear(const Vector &from, const Vector &to, const TraceOptions &options={}) const
Result< TraceHit > FromEyes(const Pawn &pawn, float distance, TraceLayers layers=TraceLayers::Solid) const
static CTraceFilter MakeFilter(const TraceOptions &options)
std::expected< void, Error > Status
static uint64_t Mask(TraceLayers layers)
std::expected< T, Error > Result
static TraceHit ToHit(const CGameTrace &trace)
static EngineNavPhysics * NavPhysics(void *&table)
static std::optional< TraceHit > OnlyHit(const Result< TraceHit > &trace)
@ Sight
what hides one player from another
@ Surfaces
every drawn surface and the sky; no player clips or players
static constexpr uint64_t SightMask
static EntityRef Ref(const CEntityInstance *entity)
static constexpr uint64_t SurfacesMask
static Error Unsupported(std::string detail)
bool Hit
also true when the start is inside a solid