This is already possible in ZScript (and ACS via
ScriptCall) by using
Level.PointInSector and
Level.IsPointInLevel.
Level.PointInSector returns the sector that corresponds to the provided set of XY-coordinates, so if you have a sector reference, you can compare the returned value with it. However, it'd only be a partial solution because from the point of view of the Doom engine,
every point in the level corresponds to a certain sector (even those that are "outside" of it, because the engine doesn't care). That's where
Level.IsPointInLevel comes in. IIRC, it was created specifically to address the "inside vs outside" problem. You can use IsPointInLevel to make sure your point is actually inside the sector. Note that it accepts a set of XYZ-coordinates instead of just XY; you can use the sector's ceiling or floor planes to get the Z value by calling
SecPlane.ZatPoint (not sure if there's an easier way to get the Z value, but this one definitely works in my tests).
TL;DR: Here's some ZScript code that does more or less what you want:
- Code: Select all • Expand view
class SectorUtil
{
static bool IsInsideSector(Sector sec, double x, double y)
{
let result = Level.PointInSector((x, y));
if (result == sec)
{
double z = sec.floorplane.ZatPoint((x, y));
return Level.IsPointInLevel((x, y, z));
}
return false;
}
}
And if you want to find sectors by tag, you can use a
SectorTagIterator:
- Code: Select all • Expand view
class SectorUtil
{
static bool IsInsideSector(Sector sec, double x, double y)
{
let result = Level.PointInSector((x, y));
if (result == sec)
{
double z = sec.floorplane.ZatPoint((x, y));
return Level.IsPointInLevel((x, y, z));
}
return false;
}
static bool IsInsideSectorTag(int tag, double x, double y)
{
let it = Level.CreateSectorTagIterator(tag);
int index;
while ((index = it.Next()) >= 0)
{
if (IsInsideSector(Level.Sectors[index], x, y))
{
return true;
}
}
return false;
}
}
To use this from ACS, please see
ScriptCall.