Constructor
new Entity(sharedAI, entity)
Represents a single object (entity) in the game.
Parameters:
| Name | Type | Description |
|---|---|---|
sharedAI |
API3.SharedScript | The common data container which holds the raw engine data. |
entity |
Object | The raw entity description as provided by the pyrogenesis engine. |
Extends
Methods
attack(unitId) → {API3.Entity}
Have the entity attack another entity.
Parameters:
| Name | Type | Description |
|---|---|---|
unitId |
Number | The numeric id of the entity to attack. |
Returns:
- Type
- API3.Entity
canGarrisonInside() → {Boolean}
Checks whether any (more) entities may be garrisoned in this entity.
Returns:
true iff the entity's garrison
capacity allows for at least one more entity.
- Type
- Boolean
construct(template, x, z, angle) → {API3.Entity}
Build a structure at a specific position.
Parameters:
| Name | Type | Description |
|---|---|---|
template |
String | The civilization-qualified template name
of the desired structure, e.g.
"structures/brit_dock" |
x |
Number | Location of the new structure's center point along the x-direction. |
z |
Number | Location of the new structure's center point along the z-direction. |
angle |
Number | Rotation angle of the structure. To comply
with the general 45 degree orientation of
buildings in normal game plays, this value
should usually be set to
0.75*Math.PI. |
Returns:
- Type
- API3.Entity
currentGatherRate() → {Number}
Retrieves the rate of the entity's current gathering activity.
Returns:
undefined.
- Type
- Number
decaying() → {Boolean}
Checks whether the entity is auto-loosing hit points.
Returns:
true iff the entity is currently
loosing hit points due to being out of the
player's territory.
- Type
- Boolean
deleteAllMetadata(player)
Discards all user-defined properties.
Parameters:
| Name | Type | Description |
|---|---|---|
player |
Number | Numeric id of the player whose extra properties will be removed from the entity. |
Returns:
deleteMetadata(player, key)
Removes a user-defined property from this entity.
Parameters:
| Name | Type | Description |
|---|---|---|
player |
Number | Numeric id of the player whose extra properties will be modified. |
key |
String | Identifier of the user property to be removed. |
Returns:
destroy() → {API3.Entity}
Kills or pulls down this entity.
Returns:
- Type
- API3.Entity
flee(unitToFleeFrom) → {API3.Entity}
Move the entity away from another entity.
Parameters:
| Name | Type | Description |
|---|---|---|
unitToFleeFrom |
API3.Entity | The unit to evade. |
Returns:
- Type
- API3.Entity
footprintRadius() → {Number}
- Inherited From:
- Overrides:
- Source:
Returns:
- Type
- Number
garrison(target, queued) → {API3.Entity}
Have the entity hide itself in another entity.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
API3.Entity | The entity to hide inside. |
queued |
Boolean | States whether the command shall be put
into the order queue of the entity.
Iff not true, the garrison
command is executed immediately. |
Returns:
- Type
- API3.Entity
gather(target, queued) → {API3.Entity}
Gather resources from another entity.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
API3.Entity | The entity to gather from. |
queued |
Boolean | States whether the command shall be put
into the order queue of the entity.
Iff not true, the entity will
start gathering immediately. |
Returns:
- Type
- API3.Entity
getMetadata(player, key) → {Object}
Reads a user-defined property from the entity.
Parameters:
| Name | Type | Description |
|---|---|---|
player |
Number | Numeric id of the player whose user properties are queried. |
key |
String | Identifier of the user property to fetch. |
Returns:
undefined if property with the
given key and player-id
was defined before.
- Type
- Object
getResourceType() → {String}
Provides the type of resource to be gathered from this entity type.
- Inherited From:
- Overrides:
- Source:
Returns:
"food", "metal",
"stone", "wood"
- Type
- String
healthLevel() → {Number}
Retrieves the entity's relative health.
Returns:
- Type
- Number
hitpoints() → {Number}
Retrieves the entity's current hit points (absolute health).
- Source:
- To Do:
-
- understand why we have sometimes rounding problems with maxHitpoints ? making wrongly isHurt=true problem seems to be with hele civs (i.e. spart)
Returns:
- Type
- Number
id() → {Number}
Retrieves the id of the entity.
Returns:
- Type
- Number
isEnemy(player) → {Boolean}
Checks whether this entity is inimicious to entities of a certain player.
Parameters:
| Name | Type | Description |
|---|---|---|
player |
Number | Numeric id of the player to check. |
Returns:
true if this entity is likely to
attack entities of the specified player.
- Type
- Boolean
isFriendly(player) → {Boolean}
Checks whether this entity is friendly (non-attacking) to the entities of a certain player.
Parameters:
| Name | Type | Description |
|---|---|---|
player |
Number | Numeric id of the player to check. |
Returns:
true if this entity will not attack
entities of the specified player.
- Type
- Boolean
isHurt() → {Boolean}
Checks whether the entity has already lost some hit points.
- Source:
- See:
-
- API3.Entity.prototype.healthLevel
- API3.Entity.prototype.hitpoints
- API3.Entity.prototype.needsHeal
- API3.Entity.prototype.needsRepair
Returns:
true iff the entity does not have
all of its hitpoints.
- Type
- Boolean
isIdle() → {Boolean}
Checks whether this entity is without task.
Returns:
undefined.
- Type
- Boolean
isOwn(player) → {Boolean}
Checks whether the entity belongs to a certain player.
Parameters:
| Name | Type | Description |
|---|---|---|
player |
Number | Numeric id of the player to check. |
Returns:
true if this entity belongs to the
player with the given id, so he can control it.
- Type
- Boolean
isUnhuntable() → {Boolean}
- Inherited From:
- Overrides:
- Source:
Returns:
true iff the entity will flee or
counter-attack when hunted.
- Type
- Boolean
moveApart(point, dist)
Move the entity away from a given position.
dist game meters off the target point.
When the entity is on the target
point, it is moved off in x-direction.
Parameters:
| Name | Type | Description |
|---|---|---|
point |
Array.<Number> | A two-dimensionl array whose elements give the x- and z-position of the repellent point. |
dist |
Number | The desired distance of the entity from the repellent point. |
needsHeal() → {Boolean}
Checks whether the entity should be tasked to heal.
Returns:
true iff it is possible to heal
the entity to full hit points (false
if the entity is at full health or unhealable).
- Type
- Boolean
needsRepair() → {Boolean}
Checks whether a builder should be tasked to repair the entity.
Returns:
true iff it is possible to restore
the entity to full hit points by repairing
(false if the entity is at full
health or unrepairable).
- Type
- Boolean
obstructionRadius() → {Number}
Computes the size of a circular "bounding cylinder" around the entity.
- Inherited From:
- Overrides:
- Source:
Returns:
- Type
- Number
owner() → {Number}
Retrieves the player who owns the entity.
Returns:
- Type
- Number
position() → {Array.<Number>}
Retrieves the current location of the entity on the map.
Returns:
undefined.
- Type
- Array.<Number>
repair(target, queued) → {API3.Entity}
Repair a structure or siege device.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
API3.Entity | The entity to repair. |
queued |
Boolean | States whether the command shall be put
into the order queue of the entity.
Iff not true, the entity will
start repairing immediately. |
Returns:
- Type
- API3.Entity
research(template) → {API3.Entity}
Research a technology.
Parameters:
| Name | Type | Description |
|---|---|---|
template |
String | The name of the technology to research. |
Returns:
- Type
- API3.Entity
resourceCarrying() → {Boolean}
Checks whether the entity has been loaded with some resource.
Returns:
true iff the entity has gathered
some resource which has not yet been disposed at
a dropsite.
- Type
- Boolean
resourceSupplyAmount() → {Number}
Retrieves the resources available of this entity.
Returns:
undefined. For
entities with unlimited supply, such as farms,
it may return infinite.
- Type
- Number
setMetadata(player, key, value)
Creates a new player-dependant property at the entity object.
Parameters:
| Name | Type | Description |
|---|---|---|
player |
Number | Numeric id of the player whose user properties are to be defined. |
key |
String | Identifier of the new user property. |
value |
Object | The object to attach to the entity for later reference. |
Returns:
setStance(stance) → {API3.Entity}
Changes the default reaction of the entity towards enemy entities.
Parameters:
| Name | Type | Description |
|---|---|---|
stance |
String | The identifier of the new entity stance,
allowing "violent",
"aggressive",
"defensive",
"passive"
"standground". |
- Source:
- To Do:
-
- Link to the 0AD game description of the entity behavior at the various stances.
Returns:
- Type
- API3.Entity
stopMoving()
Commands the entity to stop at its momentary position.
Returns:
templateName() → {String}
Retrieves the name of the entitie's template.
Returns:
"structures/celt_barracks".
- Type
- String
toString() → {String}
Provides a quick overview of the entity for listing it up.
Returns:
- Type
- String
train(type, count) → {API3.Entity}
Train some entities from this one.
Parameters:
| Name | Type | Description |
|---|---|---|
type |
String | The civilization-qualified template name
of the desired entity, e.g.
"units/athen_infantry_archer". |
count |
Number | Number of entities to train in one batch. For fairness against the human player(s), this should always be 1 or a multiple of 5 (the 0AD GUI does not support arbitrary values). |
Returns:
- Type
- API3.Entity
trainingQueue() → {Array.<Object>}
Retrieves the raw training queue state of the entity.
Returns:
[ { "id": 0, "template": "...", "count": 1, "progress": 0.5, "metadata": ... }, ... ]
- Type
- Array.<Object>
unload(id) → {API3.Entity}
Ungarrisons a particular entity from this entity.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
Number | The id of the entity to be ungarrisoned. |
Returns:
- Type
- API3.Entity
unloadAll() → {API3.Entity}
Ungarrisons all entities currently garrisoned.
Returns:
- Type
- API3.Entity