Skip to main content

Generator

Struct Generator 

Source
pub struct Generator {
    pub size: i32,
    pub grid: Vec<f32>,
    pub paths: Vec<Vec<PathPoint>>,
    pub vec28: Vec<[f32; 3]>,
    pub points: Vec<[f32; 3]>,
    pub lakes: Vec<[f32; 3]>,
    pub rng: Random,
    pub record: SizeRecord,
}
Expand description

The map generator: it makes a terrain from a size record and a seed, in five stages.

use banished_terrain::Generator;

let mut generator = Generator::new(record(), 290);
generator.run(|_stage, _g| {});
let heights = generator.heights(); // as a save stores them

Original: FUN_1400d4860.

Fields§

§size: i32

The terrain’s size in cells, 2n. The grid has (size + 1)² samples.

§grid: Vec<f32>

The float heights, row by row.

§paths: Vec<Vec<PathPoint>>

The river paths. The map draws each one with the River material.

§vec28: Vec<[f32; 3]>

The hill circles of stage 3 (x, y, radius), including the bridges that join them.

§points: Vec<[f32; 3]>

The lake points: circles (x, y, radius) around each lake, and its centre.

§lakes: Vec<[f32; 3]>

The lakes (x, y, depth). The map draws them with the Lake material.

§rng: Random

The random number generator, seeded with the map seed. The stages draw from it in order.

§record: SizeRecord

The size record.

Implementations§

Source§

impl Generator

Source

pub fn stage1_noise(&mut self)

Stage 1: fill the grid from two noise fields, blended by a logistic falloff from the centre.

Original: FUN_1400d3aa0.

Source

pub fn stage2_records(&mut self)

Stage 2: make the first river path, the lake points, then the branch paths.

Original: FUN_1400d2560, FUN_1400d2620, FUN_1400d2430.

Source

pub fn stage3_shape(&mut self)

Stage 3: place the hill circles, then draw the paths, lakes and hills into the grid.

Original: FUN_1400d2930, then FUN_1400d3de0.

Source

pub fn stage4_downhill(&mut self)

Stage 4: walks from random cells inside the map. Each step moves to the lowest of the 3 × 3 neighbours and moves a part of the height difference.

Original: FUN_1400d1550.

Source

pub fn stage5_smooth(&mut self)

Stage 5: carve the rivers and lakes again (without the hill mask), then smooth the grid twice.

Original: FUN_1400d4120, then FUN_1400d1820 twice.

Source§

impl Generator

Source

pub fn surface_map(&mut self) -> Vec<u32>

Build the packed surface image (dirt | rock << 8 | light << 16). Consumes two random values, so it must run after run exactly as the game does.

Original: FUN_1400d4910.

Source§

impl Generator

Source

pub fn new(record: SizeRecord, seed: u32) -> Generator

A generator for a size record and a seed, ready to run.

Original: FUN_1400b5700.

Source

pub fn width(&self) -> usize

The number of samples on each side of the grid, size + 1.

Source

pub fn heights(&self) -> Vec<i16>

The heights as a save stores them: each float height × 256, as a 16-bit integer.

Original: FUN_1400b1980.

Source

pub fn run(&mut self, after_stage: impl FnMut(u32, &Generator))

Run the five stages. after_stage is called after each one, with its number (1 to 5).

Original: FUN_1400d4860.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.