Player beta
Class of @v12-engine/engine
export declare class PlayerA player of a world: team, colour, race, resources, supply, researched upgrades and the state of modules, kept by world.player(id)
Members
constructor
constructor(init: PlayerInit);Constructs a new instance of the Player class
color
readonly color: [number, number, number];The player's colour as RGB, each 0..1, used to tint their units
creeps
readonly creeps: boolean;Whether this is the creeps' player: hostile to everyone, and not someone who can win or lose
defeated
defeated: boolean;Out of the game
established
established: boolean;Has had a building, and with that something to lose
id
readonly id: PlayerId;The player's id, as PlayerInit.id
name
readonly name: string;The name shown for the player, as PlayerInit.name
neutral
readonly neutral: boolean;Whether this is a neutral player (owner of gold mines and the like); nobody is hostile towards it
race
race: string | undefined;The race they play (raceOf): changed by setRace only. None in a game without races
researching
readonly researching: Set<string>;Upgrades in some production queue right now
resources
readonly resources: Purse;What the player has of each resource, by resource id
setState
setState<T>(key: Component<T, unknown>, value: T): void;Sets this player's state for a component, replacing what state gives for it
setUpgrade
setUpgrade(upgrade: string, level: number): void;Records that an upgrade is researched at this level and bumps upgradesVersion
state
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
readonly states: StateStore;State of game modules and mods for this player, see state
supplies
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
supplyCap: number;The most supply the player may use, from their buildings that provide it
supplyUsed
supplyUsed: number;Supply the player's units and queued units take up now; counted against supplyCap
team
team: number;Changed by world.setTeam, which the fog and everyone's sight follow
upgrades
get upgrades(): ReadonlyMap<string, number>;Finished research: upgrade id to level. Changed through setUpgrade only, which keeps upgradesVersion honest
upgradesVersion
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