Skip to content

Computers beta ​

Class of @v12-engine/engine

ts
export declare class Computers

The computer players of a world: who is seated, kept in the world and in a save (core.computers), so that a game loaded from a save has them back without the game's doing, and how the game reaches a seated brain while it plays (tell, pause, get)

Members ​

constructor ​

ts
constructor(world: World);

Constructs a new instance of the Computers class

brain ​

ts
brain(id: string): BrainDef | undefined;

A brain by id: one the game lists (Rules.brains)

defaults ​

ts
get defaults(): Readonly<Pick<AiOptions, 'difficulty' | 'personality'>>;

set defaults(defaults: Pick<AiOptions, 'difficulty' | 'personality'>);

What every computer seated from now on is given where its request says nothing (AiOptions, data only: a difficulty, a personality), over what the map says of the player (MapPlayer.data.ai): a campaign's difficulty, set before a mission seats its computers. Kept in the world, so a save has it. Those seated already keep what they were seated with

get ​

ts
get(player: PlayerId): ComputerSystem | undefined;

The seat the computer plays a player from, while it does

list ​

ts
list(): PlayerId[];

The players the computer plays, in the order they were seated

pause ​

ts
pause(player: PlayerId): boolean;

Has a computer player sit still until resume: kept in a save. False where none is seated, or it cannot be paused

restore ​

ts
restore(): void;

Seats again the computers a save remembers, in a world loaded from it: what loadWorld does before the game's afterLoad. One the game seated already is left as it is; one whose brain is not to be found (seated by an object the game does not list) is left empty, and the log says so

resume ​

ts
resume(player: PlayerId): boolean;

Has a paused computer player think again

seat ​

ts
seat<C extends ComputerPlayer = Brain>(player: PlayerId, request?: SeatRequest): ComputerSystem<C>;

Seats the computer at a player, and remembers it: a game loaded from a save of this one has it back, with its memory (restore). request.brain is one of the game's (defineBrain; one listed in Rules.brains is found again by its id for a load, one that is not is kept by id only, and a load without it warns and leaves the seat empty), or its id, or left out for the first brain the game lists. Of the rest of the request (AiOptions), the data is kept (numbers, lists, names); a function given in it is dropped from the save, said in the log, and a load has what the brain's definition gives: a game that wants its function back after a load puts it in the brain it lists in Rules.brains. A player seated already is unseated first. What thinks in it is a Brain unless the brain was made otherwise (defineComputer: say which)

tell ​

ts
tell(player: PlayerId, word: string, data?: unknown): boolean;

Tells a computer player a word, with data to go with it: what a mission's script says to its brain (world.computers.tell(ENEMY, 'raid', { at })), taken by a rule of the brain's (when.told). False where nobody is seated there, or what is seated takes no words

unseat ​

ts
unseat(player: PlayerId): boolean;

Takes the computer out of a player's seat, and out of what a save remembers. False where none was seated