BlockThingsIterator

From ZDoom Wiki
Jump to navigation Jump to search
Note: This feature is for ZScript only.


BlockThingsIterator is a type of iterator used to search for entities that are within the Blockmap. This excludes all actors with the NOBLOCKMAP flag. Any Actor in a blockmap square within the provided radius is taken, so this does not guarantee they are at radius distance or lower (manual checking will have to be done if a strict distance is necessary). Generally they are best used for getting surrounding Actors within a small area as opposed to every Actor.

Members

Type Variables Use
Actor thing The Actor the iterator is currently checking.
Vector3 position The xy map position for the origin of the check relative to the Actor. The z value is the radius that was given
int portalflags Used to signify what Portal-related flags were used when getting the Actor.

Functions

Return Type Function Arguments (first to last) Use/Arguments
BlockThingsIterator Create
  1. Actor origin,
  2. double checkradius = -1,
  3. bool ignorerestricted = false

Initializes the iterator upon a pointer. Either this or CreateFromPos can be used.

  • origin - A pointer to an Actor to perform the search upon. To perform it on the calling actor, self can be used.
  • checkradius - The radius to search. Default is -1, interpreted as "use the pointer's radius".
  • ignorerestricted - Does nothing.

Note: this function is static and should be called off the class name, i.e. BlockThingsIterator.Create(...).

BlockThingsIterator CreateFromPos
  1. double checkx,
  2. double checky,
  3. double checkz,
  4. double checkh,
  5. double checkradius,
  6. bool ignorerestricted

Initializes the iterator upon a vector. Either this or Create can be used.

  • check-x/y/z - The map coordinates to set the origin of the search to.
  • checkh - The height to use for the origin point. Important for getting correct portal information.
  • checkradius - The radius to search from the origin.
  • ignorerestricted - Does nothing.

Note: this function is static and should be called off the class name, i.e. BlockThingsIterator.CreateFromPos(...).

bool Next None Iterates through the list of found Actors. Returns false when at the end of the list.

Examples

This function returns how many solid Actors there are within rad distance.

int CountPotentialBlockers(double rad)
{
   // Create the iterator
   BlockThingsIterator it = BlockThingsIterator.Create(self, rad);
   Actor mo;
   int blockers;

   while (it.Next())
   {
       mo = it.thing; // Get the Actor it's currently on
       if (!mo || !mo.bSolid || Distance2D(mo) > rad)
           continue;

       ++blockers;
   }

   return blockers;
}

See Also