Enumerators.h
From OPU Wiki
Enumerators can be used to search or traverse a list of units one unit at a time. Choose an Enumerator for the type of search you need.
Enumerator types
These enumeraters are for 1 player only:
| GroupEnumerator | enumerate all the members of a group |
| PlayerVehicleEnum | enumerate all vehicles |
| PlayerBuildingEnum | enumerate all buildings |
| PlayerUnitEnum | enumerate all units |
These enumeraters are for all units (friendly and hostile):
| ClosestEnumerator | *enumerate all units, starting with the closest one to the target unit |
| InRangeEnumerator | *enumerate all units within a given range |
| InRectEnumerator | enumerate all units within a given rect |
| LocationEnumerator | enumerate all units that occupy a given location |
* See also: Distance_Table (contains equation to get the right 'distance number')
Enumerator usage
Every enumerator class should be initialized using its constructor; for example:
PlayerUnitEnum(0);
The above example will initialize an enumerator for all units of player 0 (which is player #1 in the game).
Once initialized, the class can be accessed until all its units are returned. To get the units use GetNext(class Unit ¤tUnit). After calling GetNext, check the return value. If it is non-zero currentUnit holds the next unit. If the return value is 0 all the units have been returned already.
Turn off all player 0 unit's lights:
Unit u;
PlayerUnitEnum allunits(0);
while (allunits.GetNext(u)>0)
{
u.DoSetLights(0);
}
Categories: SDK | Coding
