diff --git a/src/g_level.cpp b/src/g_level.cpp index 05c41614ab..e62b560b6d 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -85,6 +85,7 @@ #include "g_levellocals.h" #include "actorinlines.h" #include "i_time.h" +#include "nodebuild.h" void STAT_StartNewGame(const char *lev); void STAT_ChangeLevel(const char *newl); @@ -2004,10 +2005,51 @@ void FLevelLocals::SetMusicVolume(float f) } //========================================================================== +// IsPointInMap // -// +// Checks to see if a point is inside the void or not. +// Made by dpJudas, modified and implemented by Major Cooke //========================================================================== + +bool IsPointInMap(DVector3 p) +{ + subsector_t *subsector = R_PointInSubsector(FLOAT2FIXED(p.X), FLOAT2FIXED(p.Y)); + if (!subsector) return false; + + for (uint32_t i = 0; i < subsector->numlines; i++) + { + // Skip single sided lines. + seg_t *seg = subsector->firstline + i; + if (seg->backsector != nullptr) continue; + + int sx = (int)seg->v1->fX(); + int sy = (int)seg->v1->fY(); + int dx = (int)seg->v2->fX() - sx; + int dy = (int)seg->v2->fY() - sy; + int res = FNodeBuilder::PointOnSide(sx, sy, (int)p.X, (int)p.Y, dx, dy); + bool pointOnSide = (res > 0); + if (!pointOnSide) return false; + } + + double ceilingZ = subsector->sector->ceilingplane.ZatPoint(p.X, p.Y); + if (p.Z > ceilingZ) return false; + + double floorZ = subsector->sector->floorplane.ZatPoint(p.X, p.Y); + if (p.Z < floorZ) return false; + + return true; +} + +DEFINE_ACTION_FUNCTION(FLevelLocals, IsPointInMap) +{ + PARAM_PROLOGUE; + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_FLOAT(z); + ACTION_RETURN_BOOL(IsPointInMap(DVector3(x,y,z))); +} + template inline T VecDiff(const T& v1, const T& v2) { diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index fa7a8182d5..2576ea9b20 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -670,6 +670,8 @@ struct LevelLocals native native bool IsCrouchingAllowed() const; native bool IsFreelookAllowed() const; + native static clearscope bool IsPointInMap(vector3 p); + native static clearscope vector2 Vec2Diff(vector2 v1, vector2 v2); native static clearscope vector3 Vec3Diff(vector3 v1, vector3 v2); native static clearscope vector3 SphericalCoords(vector3 viewpoint, vector3 targetPos, vector2 viewAngles = (0, 0), bool absolute = false);