Table of Contents

Class SiteSearch

Namespace
Valheim.Testing.Game
Assembly
Valheim.Testing.Game.dll

Finds test sites on a world the game has just created, from the world generator's heights read through ValheimCLI (valheim.world/terrain-grid, TerrainCapture), never from the mod under test. Grids are read in the given order, each sample kept, until the mod's own rule (choose) finds what it needs; the rule decides what a site is, the search only decides where to look and in what order.

public static class SiteSearch
Inheritance
object
SiteSearch

Fields

WorldLimit

Samples farther than this from the world's centre are never chosen (Valheim's world radius is 10 km).

public const float WorldLimit = 10000

Field Value

float

Methods

Around(float, float, float, int)

A square generator grid of side by side samples spacing metres apart, centred on (centreX, centreZ).

public static TerrainGridRequest Around(float centreX, float centreZ, float spacing, int side)

Parameters

centreX float
centreZ float
spacing float
side int

Returns

TerrainGridRequest

Find(GameActor, string, IReadOnlyList<TerrainGridRequest>, Func<IReadOnlyList<TerrainSample>, bool>)

Reads each of grids (generator layer only, all checked before anything is read) in order through Read(GameActor, TerrainGridRequest, string), which refuses an incomplete or misplaced grid or a world that changed during it, and requires every grid to come from worldUid, the world the caller pinned. After each grid it asks enough with every sample read so far (with the generator's biome and river readings) and returns them once it says yes; grids after that are not read. Fails with SiteNotFoundException, naming how many samples were searched, when no grid is enough.

public static IReadOnlyList<TerrainSample> Find(GameActor server, string worldUid, IReadOnlyList<TerrainGridRequest> grids, Func<IReadOnlyList<TerrainSample>, bool> enough)

Parameters

server GameActor
worldUid string
grids IReadOnlyList<TerrainGridRequest>
enough Func<IReadOnlyList<TerrainSample>, bool>

Returns

IReadOnlyList<TerrainSample>

Nearest(IEnumerable<TerrainSample>, Func<TerrainSample, bool>)

The sample closest to the world's centre that where accepts, among finite samples within WorldLimit of the centre; null when none does. Ties go to the smaller x, then the smaller z, so the choice never depends on the order the samples were read in.

public static TerrainSample? Nearest(IEnumerable<TerrainSample> samples, Func<TerrainSample, bool> where)

Parameters

samples IEnumerable<TerrainSample>
where Func<TerrainSample, bool>

Returns

TerrainSample