[PR] RimWorld-style map generation: mountains, rivers, lakes, forests #53

Open
agent-claude wants to merge 0 commits from claude/52-rimworld-mapgen into main
Collaborator

Fixes #52

Why

The old generator rolled each tile independently against biome percentages. The result was salt-and-pepper static: lone single-tile rocks everywhere, with no mountains, rivers, lakes or forests. It also ignored the world tile's hilliness and rainfall.

What changed

  • sim-core/src/noise.ts (new): deterministic fBm value noise (integer hashing) with domain warping.
  • sim-core/src/terrain-gen.ts (new), driven by the world tile:
    • Mountains: a hilliness-scaled elevation field; median rock cover is 7% (Flat), 19% (Small Hills), 31% (Large Hills) and 44% (Mountainous), measured over 30 seeds. On hilly tiles the range rolls in from one side. Stone types form bands, gravel foothills ring the rock, and salvage alloy veins sit inside it.
    • Water: rainfall-driven lakes with deep centers and shallow, sandy or marshy shores, plus meandering rivers. Rivers have a deep channel, shallow fords every ~20 tiles and fertile banks, and cut canyons through mountains.
    • Biomes, forests, ruins: biome-specific soils, clustered forests and berry thickets, and ruins with crumbling, mineable walls.
    • Guarantees: the landing site is always dry and open, and every map edge is reachable (passes are carved if needed).
  • Gameplay:
    • Alloy veins are mineable (4–6 alloy, 25% chance of a component).
    • Raids and wanderers spawn only on edge tiles connected to the colony.
    • No sowing on infertile ground.
    • Air over water counts as outdoors for room detection, so lake islands don't become "rooms".
  • Content: new terrains shallow_water, deep_water, gravel, alloy_vein. Client: procedural pixel textures for them.
  • Fix: caravan encounters granted a non-existent silver_coin item, which crashed unpacking. Exposed by the new map RNG.

Testing

  • npm test: 91 sim-core (12 new in terrain-gen.test.ts) and 5 server, all passing.
    • The new tests cover noise coherence and determinism, hilliness scaling, contiguity (<2% isolated rocks), veins, rivers, landing-site and edge reachability across biomes, vein mining, rooms over water, infertile sowing and reachable raid spawns.
  • npm run typecheck: clean.
  • Re-ran the 60-day scripted-player balance probe on temperate, boreal and arid maps. All colonies survive and every raid resolves.
  • Rendered maps across 6 biome/hilliness combinations, and checked two fresh colonies in the local client. One shows lakes and forests; the hilly one shows mountains, water and snow.

Reviewer notes

  • Existing colonies keep their saved terrain. New maps apply to new colonies and to relocations.
  • Blender fertile_loam.png sprite: its tilled-furrow look reads as plowed fields when it appears as wild rich soil. A more natural sprite would suit the new layout; that's left for the art pipeline.

🤖 Generated with Claude Code

Fixes #52 ## Why The old generator rolled each tile independently against biome percentages. The result was salt-and-pepper static: lone single-tile rocks everywhere, with no mountains, rivers, lakes or forests. It also ignored the world tile's hilliness and rainfall. ## What changed - **`sim-core/src/noise.ts`** (new): deterministic fBm value noise (integer hashing) with domain warping. - **`sim-core/src/terrain-gen.ts`** (new), driven by the world tile: - **Mountains:** a hilliness-scaled elevation field; median rock cover is 7% (Flat), 19% (Small Hills), 31% (Large Hills) and 44% (Mountainous), measured over 30 seeds. On hilly tiles the range rolls in from one side. Stone types form bands, gravel foothills ring the rock, and **salvage alloy veins** sit inside it. - **Water:** rainfall-driven lakes with deep centers and shallow, sandy or marshy shores, plus **meandering rivers**. Rivers have a deep channel, shallow fords every ~20 tiles and fertile banks, and cut canyons through mountains. - **Biomes, forests, ruins:** biome-specific soils, clustered forests and berry thickets, and ruins with crumbling, mineable walls. - **Guarantees:** the landing site is always dry and open, and **every map edge is reachable** (passes are carved if needed). - **Gameplay:** - Alloy veins are mineable (4–6 alloy, 25% chance of a component). - Raids and wanderers spawn only on edge tiles connected to the colony. - No sowing on infertile ground. - Air over water counts as outdoors for room detection, so lake islands don't become "rooms". - **Content:** new terrains `shallow_water`, `deep_water`, `gravel`, `alloy_vein`. **Client:** procedural pixel textures for them. - **Fix:** caravan encounters granted a non-existent `silver_coin` item, which crashed unpacking. Exposed by the new map RNG. ## Testing - `npm test`: 91 sim-core (12 new in `terrain-gen.test.ts`) and 5 server, all passing. - The new tests cover noise coherence and determinism, hilliness scaling, contiguity (<2% isolated rocks), veins, rivers, landing-site and edge reachability across biomes, vein mining, rooms over water, infertile sowing and reachable raid spawns. - `npm run typecheck`: clean. - Re-ran the 60-day scripted-player balance probe on temperate, boreal and arid maps. All colonies survive and every raid resolves. - Rendered maps across 6 biome/hilliness combinations, and checked two fresh colonies in the local client. One shows lakes and forests; the hilly one shows mountains, water and snow. ## Reviewer notes - **Existing colonies keep their saved terrain.** New maps apply to new colonies and to relocations. - **Blender `fertile_loam.png` sprite:** its tilled-furrow look reads as plowed fields when it appears as wild rich soil. A more natural sprite would suit the new layout; that's left for the art pipeline. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Replaces per-tile random terrain (salt-and-pepper static) with coherent,
world-tile-driven generation in a new terrain-gen module.

- Deterministic fBm value noise with domain warping (noise.ts).
- Mountains scaled by hilliness (~7% Flat to ~44% Mountainous rock),
  ranges rolling in from one side, stone bands, gravel foothills and
  mineable salvage alloy veins (4-6 alloy each).
- Rainfall-driven lakes with deep centres and shallow shores; meandering
  rivers with deep channels, fords, fertile banks and canyons.
- Biome-specific soils, clustered forests/berry thickets, mineable ruins.
- Landing site always dry and open; every map edge guaranteed reachable
  (passes carved); raids and wanderers spawn only on reachable edge tiles.
- No sowing on infertile ground; air over water counts as outdoors.
- New terrains: shallow_water, deep_water, gravel, alloy_vein, with
  client procedural textures.
- Fix: caravan encounters granted a non-existent 'silver_coin' item.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Collaborator

Merge approved by @johnw via Claude Code chat on 2026-10-20: "merge approve and pish t prd"

Merge approved by @johnw via Claude Code chat on 2026-10-20: "merge approve and pish t prd"
This branch is already included in the target branch. There is nothing to merge.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin claude/52-rimworld-mapgen:claude/52-rimworld-mapgen
git switch claude/52-rimworld-mapgen

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff claude/52-rimworld-mapgen
git switch claude/52-rimworld-mapgen
git rebase main
git switch main
git merge --ff-only claude/52-rimworld-mapgen
git switch claude/52-rimworld-mapgen
git rebase main
git switch main
git merge --no-ff claude/52-rimworld-mapgen
git switch main
git merge --squash claude/52-rimworld-mapgen
git switch main
git merge --ff-only claude/52-rimworld-mapgen
git switch main
git merge claude/52-rimworld-mapgen
git push origin main
Sign in to join this conversation.
No description provided.