Classes:BlockLinesIterator
Note: This feature is for ZScript only. |
BlockLinesIterator is a type of iterator used to search for lines in the Blockmap. Contrary to the name, this does not grab only blocking lines but all lines. Instead it gets any line that exists in a blockmap square within the given radius. You can use this to get nearby lines instead of having to iterate through all of them. If you wish to get only blocking lines you'll have to manually check the flags on each line found in the iterator.
While iterating, you should take care not to call any function that refers to the validcount variable, such as other iterators or actor spawning functions. Doing so would interfere with the operation of the iterator, causing lines to be skipped or counted several times. Cf. this forum link.
Variables
- Line CurLine
- The line the iterator is currently checking.
- Vector3 position
- The xy map position for the origin of the check relative to the line. The z value is the radius that was given.
- int portalflags
- Used to signify what Portal-related flags were used when getting the line.
Methods
Static
The iterator can be initalized with either Create() or CreateFromPos() methods. Both are static methods and must be called as BlockLinesIterator.Create
/BlockLinesIterator.CreateFromPos
- BlockLinesIterator Create(Actor origin, double checkradius = -1)
- Initializes the iterator upon a pointer. Either this or CreateFromPos can be used. Parameters:
- Actor origin
- A pointer to an Actor to perform the search upon. To perform it on the calling actor,
self
can be used.
- double checkradius
- The radius to search. Default is -1, interpreted as "use the pointer's radius".
- BlockLinesIterator CreateFromPos(Vector3 pos, double checkh, double checkradius, Sector sec = null)
- Initializes the iterator upon a vector. Either this or Create can be used. Parameters:
- Vector3 pos
- The map coordinates to set the origin of the search to.
- double checkh
- The height to use for the origin point. Important for getting correct portal information.
- double checkradius
- The radius to search.
- Sector sec
- The starting sector to do the search from. If
null
, this will get the sector at the provided xy position.
Non-static
- bool Next()
- Iterates through the list of found lines. Returns
false
when at the end of the list.
Examples
This function returns how many blocking lines there are within approximately rad distance.
int CountBlockingLines(double rad)
{
// Create the iterator
BlockLinesIterator it = BlockLinesIterator.Create(self, rad);
Line ln;
int blocking;
while (it.Next())
{
ln = it.CurLine; // Get the line it's currently on
if (!(ln.flags & Line.ML_BLOCKING))
{
continue;
}
++blocking;
}
return blocking;
}