Status: done (2026-10-30)
Priority: 2
Size: L
Design ref: World and scale (Rivers: Decided; River courses: Proposed); Settlements and look (Generated villages: fitted to the land, villages follow rivers); Long work and processing (water mills need rivers). Questions answered 30 Oct 2026 when this task was set (QUESTION_ARCHIVE.md, “VB-111: rivers”).
Goal: The world has no rivers, so nothing in the design that needs them (water mills, villages that follow rivers, wet banks) can be built. Generate rivers with the world, draw them on the map, and let villages prefer river land, whose fields are watered from the river.
Acceptance criteria:
src/gen/rivers.js (@sys gen/rivers, listed before gen.js, which calls it) traces rivers from the elevation w.he: every tile drains to a neighbour on a path to the sea (priority flood from the sea, Barnes, Lehman and Mulla 2014); a lake fills to its lowest shore and drains on from there, so a river that enters a lake leaves it and runs on to the sea.round(land tiles / 700) sources (none on islands under 350 tiles); sources lie at least 10 steps apart, and a new river runs at least 3 land tiles before it meets water or another river. Long courses go first (a course of 15 land tiles or more counts as long), with a random term of up to 10 so sources spread over the island instead of crowding its longest drainage. Rivers merge where they meet.w.river (Uint16Array per tile): the catchment of a land tile a river runs through, in tiles weighted by moisture (0.5 + hm), 0 elsewhere; w.riverTo (Int32Array per tile): the next tile down the course (a river tile, a lake on the course or the sea), -1 off every course. Both have @state tags. The rivers use their own random stream, so every other field of w is unchanged.farmable is false there; new fields and plots avoid them).RIVER.irrigation in src/sim/rules.js), wherever fertility is used: placing and choosing fields and the field’s fert.siteScore adds RIVER.site by steps to the nearest river tile (10 at 1 or 2 steps, 5 at 3), so village centres and lone farms move to river land. Report the share of village centres within 3 steps of a river before and after (populous, medium, seeds 7 and 42).tests/rivers.js, in npm test): rivers are deterministic; every course ends in the sea; catchment never falls downstream; sources are hills, mountains or marsh; no house or field on a river tile; fields next to a river carry the bonus.gen.js stays at its lint baseline of 672 lines: the trace is one line, the thinning call replaces the sort of the decoration items, and items joined the declaration above it. The river drawing is called from the page’s chunkJob, between the bake and the decorations.tests/populous.js checked the mean household size of each map against fixed bounds of 5.5 to 6.6. On a Tiny map of about 20 households that is only 1.3 standard errors above the drawn mean of 6.17 (sd 1.48), so about one run in ten failed by chance; with rivers, Tiny seed 7 drew 19 households of mean 6.84 and failed. Over 28 maps (7 seeds, 4 sizes) the mean is 6.18 before and 6.22 after. The check now asks for the mean within 3 standard errors of the drawn mean: about ±1.0 on Tiny maps, ±0.4 on Medium ones (5.79 to 6.57), close to the old bounds there.world/7 and world/42 gain river and riverTo (no other world key changes); every founders and heirs entry at seeds 7 and 42; apiKeys/Sim (RIVER, byRiver). calibrate is unchanged.