new EntityCollection(sharedAI)
A sequence of entities with filtering and tasking capabilities.
Parameters:
sharedAI
:
API3.SharedScript
|
The shared data container which holds all of the entities. |
- Source:
- entitycollection.js, line 8
| filter(filter) → {API3.EntityCollection} | Derives a new collection which contains only selected entities. |
| filterNearest(targetPos, n) → {API3.EntityCollection} | Returns the (at most) n entities nearest to targetPos. |
Methods
-
filter(filter) → {API3.EntityCollection}
Derives a new collection which contains only selected entities.
-
The current collection is not affected by the filtering.
Parameters:
filter: API3.FilterA filter object which chooses the entities to go into the derived collection. Only entities found in the current collection will be filtered into the derived one. It is possible to supply a "naked" decision function as well (see API3.Filter.func). - Source:
- entitycollection.js, line 135
- To Do:
-
- Describe the thisp parameter.
Returns:
A new collection which contains only those entities of the current collection which match the filter criterion. The new collection is updated as the current collection changes.Example
var wonders = gameState.getEnemyStructures().filter( API3.Filters.byClass("Wonder")); -
filterNearest(targetPos, n) → {API3.EntityCollection}
Returns the (at most) n entities nearest to targetPos.
-
Entities are selected by their euclidian distance to the target pos.
Warning: As the function considers the euclidian distance only, it is dangerous to use it for selection of unit around a target spot, as it toes not take into account obstructions on the path between unit and target.Parameters:
targetPos: Array.<Number>Describes the position to start searching for entities, where targetPos[0]gives the x-position andtargetPos[1]gives the z-position.n: NumberMaximum number of entities to return. - Source:
- entitycollection.js, line 173
Returns:
A new collection which holds only the nearest entities to the target spot. The collection will not auto-update when entities change position.