Skip to content

Entity ​

Class of @v12-engine/engine

ts
export declare class Entity

Anything in the world: a unit, a building, a tree.

Fields marked readonly are kept in step with things elsewhere (the navigation, the spatial index, the lookups of the world), so they are changed through the world's functions only: World.setOwner, World.setHidden, World.setLifetime, World.place, startDash, morph (each through the entity's own internal writes: moveTo, retype, changeOwner…). The rest, like health, mana or cooldowns, a game module may change as it likes: nothing is worked out from them that would not notice.

Members ​

constructor ​

ts
constructor(
    id: EntityId, 
    def: UnitTypeDef, 
    owner: PlayerId, position: Vec2);

Constructs a new instance of the Entity class

abilities ​

ts
readonly abilities: readonly AbilityState[];

What it can cast, with their levels and cooldowns: each state is the game's to change (cooldown, autocast), the list the engine's (a type's own, what a hero learns), written with the entity's own internal methods

alive ​

ts
readonly alive: boolean;

Whether the entity is in the world; false once it died

asleep ​

ts
asleep: boolean;

Does nothing by itself until something wakes it, and is drawn sleeping: creeps at night

buffs ​

ts
readonly buffs: readonly BuffInstance[];

What is on it: each instance the game's to change, the list put on and taken off by applyBuff, removeBuff

cell ​

ts
cell?: {
        x: number;
        z: number;
    };

Min corner of the footprint in grid cells, for buildings and resources

components ​

ts
get components(): Readonly<Record<string, unknown>>;

Its components' values by id, in the order it was given them: made each time it is asked, for what reads them by id now and then (a save, the inspector). What does it often goes through heldComponents

currentOrder ​

ts
get currentOrder(): Order | undefined;

The order it carries out now, the first of its orders; nothing when it has none

def ​

ts
readonly def: UnitTypeDef;

Changes when a building is upgraded into another type

expires ​

ts
readonly expires: number | null;

Seconds until it is gone by itself, for what does not last

facing ​

ts
facing: number;

The way it faces in radians

flying ​

ts
get flying(): boolean;

Up in the air, where the ground and what stands on it are not in the way

get ​

ts
get<T>(key: Component<T, unknown>): T | undefined;

A component of a game module or a mod, see defineComponent

halfDepth ​

ts
get halfDepth(): number;

Half of what it covers from front to back (rect.hd), as halfWidth

halfWidth ​

ts
get halfWidth(): number;

Half of what it covers across (rect.hw), with no rect made: what is asked all the time (is a structure in sight)

has ​

ts
has(key: Component<unknown>): boolean;

Whether it holds the component

health ​

ts
health: number;

Hit points it has now; it dies at 0

heldComponents ​

ts
heldComponents(): readonly Component<unknown, unknown>[];

Its components, in the order it was given them: each one's value is get(component)

hidden ​

ts
readonly hidden: boolean;

Hidden entities are inside something (a gold mine) and do not take part in the world

hurtAt ​

ts
hurtAt: number;

When it was last hurt, in seconds of the game. Long ago for what never was

id ​

ts
readonly id: EntityId;

The entity's number, unique in its world

index ​

ts
index: {
        componentChanged(entity: Entity, id: string, has: boolean): void;
    } | null;

The index of the world it is in (EntityIndex), told when it gets or loses a component, and the way to its world (order). Not game state

isBuilding ​

ts
get isBuilding(): boolean;

Whether its type is a building

isResource ​

ts
get isResource(): boolean;

Whether its type is a resource

isStructure ​

ts
get isStructure(): boolean;

Whether its type is a building or a resource: anything but a unit

isUnit ​

ts
get isUnit(): boolean;

Whether its type is a unit

lifetime ​

ts
lifetime: number;

Seconds it was given to last, for what does not

likeness ​

ts
likeness?: Likeness;

Drawn as another's type and owner: a soul in the fallen's shape (SpawnOptions.looksLike). Its own type and owner decide everything but the picture

look ​

ts
look?: string;

Which of the models of its type it is drawn with, for the look of a map. Nothing in the rules goes by it either

mana ​

ts
mana: number;

Mana it has now

maxHealth ​

ts
maxHealth: number;

The most hit points it can have

maxMana ​

ts
maxMana: number;

The most mana it can have

on ​

ts
on?: EntityId;

The resource it stands on (UnitTypeDef.builtOn), by id: none for what stands on the ground

operational ​

ts
get operational(): boolean;

Completed and able to do its job

order ​

ts
order<Type extends string>(type: Type, aim?: Vec2 | Entity | Omit<OrderInit<Type>, 'type'>, options?: OrderOptions): void;

Gives it an order, as its owner would: unit.order('move', point), unit.order('attack', enemy), unit.order('cast', { ability: 'blink', point }). What it is aimed at is a point (point), an entity (target) or the order's fields (OrderInits). It is the order command of its owner through its world (World.issue): taken up at the next tick, turned away as a player's would be (an order its type does not take, a target its owner does not know), and kept by a replay. queue puts it after what it was told before. Throws for an entity that is in no world (taken out of it)

orders ​

ts
readonly orders: readonly Order[];

What it was told to do, the first what it does now and the rest in turn: read here, given and ended through the orders' functions (giveOrder, clearOrders, completeOrder), which write it with the entity's own addOrder, keepOrders and removeOrder

owner ​

ts
readonly owner: PlayerId;

The player it belongs to, changed through World.setOwner only

pos ​

ts
readonly pos: Readonly<Vec2>;

Where it stands in cells (x, z), changed through the world's functions only

prevFacing ​

ts
prevFacing: number;

The way it faced at the last tick, in radians, for the screen to draw between

prevPos ​

ts
readonly prevPos: Vec2;

Where it stood at the last tick, for the screen to draw between

rect ​

ts
get rect(): Rect;

Ground area covered by a structure: a new rect each time, for who keeps it (an obstacle, a wall's reshape)

remove ​

ts
remove(key: Component<unknown>): void;

Takes the component away; nothing happens when it has none

reviving ​

ts
reviving: boolean;

A fallen hero that is on its way back

scale ​

ts
scale: number;

How big it is drawn, for the look of a map. Nothing in the rules goes by it

scenery ​

ts
readonly scenery: boolean;

Only stands there, like a tree: left out of the systems that run every tick, see isScenery. Becomes false for good once something gives it anything to do (World.wake)

seenBy ​

ts
seenBy: number;

Teams that have seen this entity at least once, one bit per team as FogOfWar.teamBit hands them out. Ask World.hasSeen

set ​

ts
set<T>(key: Component<T, unknown>, value: T): void;

Gives it the component, or a new value of it. undefined takes it away (remove)

spatialStamp ​

ts
spatialStamp: number;

Bookkeeping of the spatial index: the last query that found it. Not game state

statsCache ​

ts
statsCache: StatsCache | null;

Stats as last worked out, see statsOf. Derived from the rest, never saved or sent

unseen ​

ts
get unseen(): boolean;

Invisible to enemies right now, unless they have found it

unseenIn ​

ts
unseenIn: number | null;

Seconds until enemies cannot see it any more, for what is invisible. 0 once they cannot

velocity ​

ts
readonly velocity: Vec2;

Velocity of the last tick