The pack
settlement
function settlement(): Pack<{ settlement: SettlementApi }>
Village life on a work yard: hunger, cold and rest through the seasons, houses, newcomers and a year's goal.
Helpers
createSettlement
function createSettlement(def: SettlementDef): Settlement
Found a settlement. Throws, with every fault, on one validateSettlement or the yard refuses.
createSteward
function createSteward(town: Settlement, options: { every?: number } = {}): Steward
A steward for a settlement, setting priorities every every seconds (default 1).
defaultSeasons
const defaultSeasons: Season[]
The default year.
planVillage
function planVillage(options: VillageOptions = {}): SettlementDef
Plan a village: its map, stores, jobs, villagers and the rules of its year.
validateSettlement
function validateSettlement(def: SettlementDef): string[]
Check a settlement. Every fault, or empty when it can be run.
villagePresets
const villagePresets: Record<'hearthguard' | 'frostmere' | 'meadowend', VillageOptions>
Three villages: Hearthguard by its river, Frostmere with one bridge and a long hard winter, and Meadowend with no river and a mild year but more mouths to feed.
Types
Season
interface Season
A season.
name: string— Season name, shown to the player and carried by theseasonevent.length: number— Seconds.cold: number— How fast, a second, a villager without a warm home grows cold. 0 is a mild season: no fuel is burnt.closed?: string[]— Jobs that cannot be worked this season.
Settlement
interface Settlement
A settlement.
readonly def: SettlementDef— The definition the settlement was built from.readonly state: SettlementState— Where the settlement stands now.readonly yard: Yard— The yard its villagers work in. Change roles there; set priorities here.priority(job: string, priority: number): string | null— Ask for a job's priority. A job closed this season stays at 0 until it opens.season(): Season— The season now.left(): number— Seconds left in the year.beds(): number— Beds in standing houses.food(): number— Food in the storehouse, of every kind.step(dt: number): void— Advance bydtseconds of play in fixed yard ticks (at most 0.25 s counts per call); does nothing once the year is won or lost. Throws for a negative or non-numericdt.drain(): SettlementEvent[]— Settlement events since the last drain (the latest 512). The yard's areyard.drain().snapshot(): SettlementSave— A copy of the whole settlement, yard included, as plain data.restore(save: SettlementSave): void— Restore asnapshot; pending events are discarded.
SettlementApi
interface SettlementApi
What the pack adds to the game as game.settlement.
create(def: SettlementDef): Settlement— Found a settlement.validate(def: SettlementDef): string[]— Check a settlement: every fault, or empty.plan(options?: VillageOptions): SettlementDef— Plan a village from options.steward(town: Settlement, options?: { every?: number }): Steward— A steward who runs a settlement through its priorities.presets: typeof villagePresets— Three villages' options.seasons: typeof defaultSeasons— The default year.
SettlementDef
interface SettlementDef
A settlement: its yard and the rules of village life.
yard: YardDef— The work yard the villagers work in: its map, stores, jobs and workers (one villager per worker).storehouse: string— The store villagers eat from and houses burn fuel from.food: string[]— What can be eaten, in the order it is eaten.fuel: string— What houses burn.houses: { store: string; beds: number }[]— The houses: a house stands once its store holdsbuilt; it sleepsbeds.built?: string— The item that marks a house standing. Default'house'.seasons: Season[]— The year, in order; its length is the sum of the seasons' lengths. At least one.hunger: { rate: number; eat: number; meal: number }— Hunger risesratea second; ateata villager eats one food, which takesmealoff.warmth: { heal: number; fuel: number; every: number }— Cold fallsheala second in a warm home or a mild season; in a cold season each occupied house burnsfueleveryeveryseconds, and is cold until the next burn if there is none.fatigue: { work: number; rest: number; stop: number; resume: number }— Fatigue risesworka second on a task and fallsresta second off one; atstopa villager stops work until it falls toresume.leave: number— Seconds a villager stays at the limit (100) of hunger or cold before leaving.arrivals?: { every: number; spare: number; at: [number, number]; names?: string[]; skills?: Stock; speed?: number; carry?: number }— Newcomers: one aftereveryseconds while a bed is free and the storehouse holdssparefood a villager (counting them). They start atat, with these skills, speed and carry, named fromnames.goal: { population: number; stock?: Stock }— At the end of the last season: at least this many villagers, and this stock in the storehouse.
SettlementEvent
type SettlementEvent = | { kind: 'season'; name: string } | { kind: 'ate'; villager: string; item: string } | { kind: 'hungry'; villager: string } | { kind: 'cold-house'; house: string } | { kind: 'built'; house: string } | { kind: 'tired'; villager: string } | { kind: 'rested'; villager: string } | { kind: 'arrive'; villager: string } | { kind: 'leave'; villager: string; why: 'hunger' | 'cold' } | { kind: 'won' } | { kind: 'lost'; why: string }
Something that happened.
SettlementSave
interface SettlementSave
A settlement saved as plain JSON.
state: SettlementState— The settlement state.carry: number— Seconds of play stepped but not yet consumed by a fixed tick.yard: YardSave— The yard's own save.
SettlementState
interface SettlementState
Where the settlement stands. Plain JSON.
time: number— Seconds elapsed in the year.season: number— The season, by index.villagers: Villager[]— The villagers now in the settlement.standing: string[]— The houses that stand.warm: Record<string, boolean>— Whether each standing house is warm.heatIn: number— Seconds to the next burn.waited: number— Seconds of free bed and spare food so far, towards the next newcomer.arrived: number— Newcomers who have arrived so far.left: number— Villagers who have left so far.priorities: Record<string, number>— The priority asked for each job (a closed job runs at 0 whatever is asked).phase: 'play' | 'won' | 'lost'—playwhile the year runs,wonorlostonce it has ended.message: string— What happened at the end, or''.
Steward
interface Steward
A steward.
act(dt: number): void— Run on bydtseconds; everyeveryseconds the priorities are set again.readonly focus: string— What the steward is seeing to most, in a few words.
VillageOptions
interface VillageOptions
What a village is made of.
seed?: number— Seed for the layout and placement; the same seed and options make the same village. Default 1.width?: number— Cells. Default 28 by 16. At least 18 by 12.height?: number— Rows of cells. Default 16. At least 12.villagers?: number— Villagers at the start; the longhouse sleeps them all. Default 5.plots?: number— House plots, 1 to 9. Default 3.beds?: number— Beds a house sleeps. Default 2.river?: boolean— Whether a river divides the village from the woods and quarry. Default true.bridges?: number— Bridges over the river, 1 or more. Default 2.seasons?: Season[]— The year. Default spring, summer and autumn of 60 seconds and a 90-second winter that closes the fields.goal?: number— Villagers needed at the year's end. Default the starting villagers and 4 more.stock?: Record<string, number>— What the storehouse starts with.arrivals?: number— Newcomers every this many seconds while a bed is free and food is spare; 0 for none. Default 25.
Villager
interface Villager
A villager's needs, each from 0 (fine) to 100 (the limit).
id: string— Villager id: the id of the yard worker they are.hunger: number— Hunger, 0 (fed) to 100 (the limit); rises with time and falls when they eat.cold: number— Cold, 0 (warm) to 100 (the limit); rises in a cold season without a warm home.fatigue: number— Fatigue, 0 (fresh) to 100; rises while working and falls at rest.tired: boolean— Worn out: not working until rested.suffering: number— Seconds at the limit of hunger or cold.home: string | null— The house store they sleep in, or null.


