Skip to content

Player beta ​

Class of @v12-engine/engine

ts
export declare class Player

A player of a world: team, colour, race, resources, supply, researched upgrades and the state of modules, kept by world.player(id)

Members ​

constructor ​

ts
constructor(init: PlayerInit);

Constructs a new instance of the Player class

color ​

ts
readonly color: [number, number, number];

The player's colour as RGB, each 0..1, used to tint their units

creeps ​

ts
readonly creeps: boolean;

Whether this is the creeps' player: hostile to everyone, and not someone who can win or lose

defeated ​

ts
defeated: boolean;

Out of the game

established ​

ts
established: boolean;

Has had a building, and with that something to lose

id ​

ts
readonly id: PlayerId;

The player's id, as PlayerInit.id

name ​

ts
readonly name: string;

The name shown for the player, as PlayerInit.name

neutral ​

ts
readonly neutral: boolean;

Whether this is a neutral player (owner of gold mines and the like); nobody is hostile towards it

race ​

ts
race: string | undefined;

The race they play (raceOf): changed by setRace only. None in a game without races

researching ​

ts
readonly researching: Set<string>;

Upgrades in some production queue right now

resources ​

ts
readonly resources: Purse;

What the player has of each resource, by resource id

setState ​

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

Sets this player's state for a component, replacing what state gives for it

setUpgrade ​

ts
setUpgrade(upgrade: string, level: number): void;

Records that an upgrade is researched at this level and bumps upgradesVersion

state ​

ts
state<T>(key: Component<T, unknown>): T;

State of a game module or a mod for this player: made from the component's default when first asked for

states ​

ts
readonly states: StateStore;

State of game modules and mods for this player, see state

supplies ​

ts
supplies: Record<string, {
        used: number;
        cap: number;
    }>;

The game's other pools of supply, by name (RuleSettings.supply.pools): what is used and the cap of each

supplyCap ​

ts
supplyCap: number;

The most supply the player may use, from their buildings that provide it

supplyUsed ​

ts
supplyUsed: number;

Supply the player's units and queued units take up now; counted against supplyCap

team ​

ts
team: number;

Changed by world.setTeam, which the fog and everyone's sight follow

upgrades ​

ts
get upgrades(): ReadonlyMap<string, number>;

Finished research: upgrade id to level. Changed through setUpgrade only, which keeps upgradesVersion honest

upgradesVersion ​

ts
upgradesVersion: number;

Bumped whenever a research finishes. Whatever is worked out from upgrades (like the stats of units) can check this to tell whether it still holds