Skip to content

BuildGrid beta ​

Class of @v12-engine/engine

ts
export declare class BuildGrid

Placement grid. One cell per world unit, tracking where structures stand and where the ground is flat enough to build.

Members ​

constructor ​

ts
constructor(terrain: Terrain, options?: GridOptions);

Constructs a new instance of the BuildGrid class

canPlace ​

ts
canPlace(cellX: number, cellZ: number, w: number, d: number): boolean;

Whether a footprint of w by d cells with its first cell at (cellX, cellZ) is free and on ground level enough to build on

cellFor ​

ts
cellFor(x: number, z: number, w: number, d: number): {
        x: number;
        z: number;
    };

Min cell of a footprint centered as close as possible to the given point

depth ​

ts
readonly depth: number;

The grid's depth in cells, the map's depth

groundChanged ​

ts
groundChanged(rect: {
        x: number;
        z: number;
        width: number;
        depth: number;
    }): void;

Works out again where can be built, in a rectangle of cells and the ring about it (a slope is of the vertices about a cell): after the ground was reshaped there (World.reshapeGround). What stands there stays where it is

inBounds ​

ts
inBounds(x: number, z: number): boolean;

Whether the cell (x, z) is on the grid

isBuildable ​

ts
isBuildable(x: number, z: number): boolean;

Whether a structure may be put on the cell by the ground alone: on the grid, flat enough, dry, not at the edge or blocked

isFree ​

ts
isFree(x: number, z: number): boolean;

Whether the cell is buildable and has no structure on it

occupantAt ​

ts
occupantAt(x: number, z: number): number;

The id of the structure standing on the cell, 0 when none does and -1 when the cell is off the grid

occupy ​

ts
occupy(cellX: number, cellZ: number, w: number, d: number, id: number): void;

Marks the footprint's cells as taken by the structure id; cells off the grid are skipped

release ​

ts
release(cellX: number, cellZ: number, w: number, d: number, id: number): void;

Frees the footprint's cells that the structure id holds; cells held by another id are left

width ​

ts
readonly width: number;

The grid's width in cells, the map's width