diff --git a/BACKLOG.md b/BACKLOG.md
index 222bb00f..34d99e12 100644
--- a/BACKLOG.md
+++ b/BACKLOG.md
@@ -23,7 +23,6 @@ The order tasks are taken in, the first first (`node tools/backlog.js next`). So
| [VB-665](backlog/VB-665.md) | Housekeeping: one scale for the simulation's meters, reviewed with Kim | - | 2 | S | Inventory every bounded or signed quantity the player is shown, its range in st and on the page; propose 0 to 100 and -100 to 100 with the motivated exceptions; questions for Kim |
| [VB-706](backlog/VB-706.md) | Standing answers where there is no tie: a stranger's yes rests on it | - | 2 | S | Standing changes nothing material: it weights customs and land disputes only. Kim, 16 Nov: where the pawn asked has no tie to the asker, standing is what it answers by. |
| [VB-707](backlog/VB-707.md) | A debtor's refusal is a breach the village knows, and costs standing | - | 2 | S | Ignoring a debt of honour costs nothing but a private memory, and sim/exchange's `propriety` has no caller. Kim, 16 Nov: a refusal by one who owes is a public breach. |
-| [VB-787](backlog/VB-787.md) | Settling in steps: staked at the round, built from a booth, founded at the move | far | 2 | L | The round stakes a site and forms the party; its adults blaze the trail, raise a booth, clear and build while their households stay at home and feed them; the household and the village are founded on the day of the move. |
| [VB-1476](backlog/VB-1476.md) | A pawn's grain stake vanishes at its death | - | 2 | S | Found by VB-403's accounts: a pawn's stake (shares paid to it, sim/cottage payOwed) stays on the dead pawn and leaves the world with no movement; up to a fifth of a year's produce late in populous small seed 7. |
| [VB-1478](backlog/VB-1478.md) | The fair's animals and carts: a beast led to the gathering, an ox cart carrying 300 | fair | 2 | S | VB-302 left these out: an animal walks to the fair beside its dealer and changes herd when swapped; a household with an ox cart and its team free loads 90 rations' worth, the cart out until it is home. |
| [VB-1507](backlog/VB-1507.md) | tests/browser.js fails on a busy machine: steps in working hours, and the work bar's click | - | 2 | S | 3 of 5 runs failed at d8f81ff on 23 November, before any page change: a wall-clock check and a click on a menu row that is redrawn |
@@ -53,6 +52,7 @@ The order tasks are taken in, the first first (`node tools/backlog.js next`). So
| [VB-1932](backlog/VB-1932.md) | Fell and Cut firewood are always available; the head plans the winter's wood | - | 2 | M | Fell and Cut are never withheld because of a store's goal: Fell on any tile the household may fell, Cut whenever unreserved timber is home; the winter's wood is the head's planning |
| [VB-1933](backlog/VB-1933.md) | Refactor: a test declares its tier in its header; tests/run.js discovers it | - | 2 | M | tests/suites.js 28 tasks to 1 (VB-1406 step 1) |
| [VB-1934](backlog/VB-1934.md) | Refactor: a work counter is declared by the module whose loop it counts | - | 2 | M | src/vb.js 12 tasks to 0 (VB-1406 step 2) |
+| [VB-1937](backlog/VB-1937.md) | Settling in steps: f.booth goes, a booth household loads as a site | - | 2 | M | Remove f.booth and the booth cottage jobs; load a booth household's save as a site at step 3 with its household founded |
| [VB-1941](backlog/VB-1941.md) | Refactor: a module's layer read from its @sys line; the modules' list generated; NOT_STOCKS a tag on @state | - | 2 | M | src/layers.json 13 to 1, modules.md 22 to 0, tools/stocks.js 10 to 3 (VB-1406 step 3) |
| [VB-1944](backlog/VB-1944.md) | Refactor: the Sim facade joined from what each module gives the page | - | 2 | M | src/sim.js 17 to 1-4 (VB-1406 step 6) |
| [VB-1946](backlog/VB-1946.md) | Refactor: one record an event kind, declared by its emitter; sim/notable split into the skip and the chronicle | - | 2 | M | sim/notable 16 to 8 and 6, sim/records 10 to 6 (VB-1406 step 8) |
@@ -91,6 +91,8 @@ The order tasks are taken in, the first first (`node tools/backlog.js next`). So
| [VB-769](backlog/VB-769.md) | Dealing on the green on a gathering day, and goods carried there on an estimate | town | 3 | M | The fair's barter runs at every occasion on a green (meeting, rite, yearly gathering) among those present; a household packs or sends a goer by its own remembered estimate of that green. Nobody calls a market. |
| [VB-770](backlog/VB-770.md) | The walk to a named household to deal | town | 3 | M | Between gatherings a head short of a good it cannot make walks to a household it knows has it, offers at the door, and swaps or is refused; at most 4 known households a good. |
| [VB-782](backlog/VB-782.md) | Plan: the generator's land cover: the forest's spread by seed, meadow on low wet ground | far | 3 | S | Left for Kim to start: islands that differ from open country to deep wood (30 to 60% forest), and meadow on low wet ground where the generator puts it on the second driest |
+| [VB-788](backlog/VB-788.md) | The player's part in settling: the site among five, the walk out and home, the day of the move | far | 3 | S | The played pawn, leading a party, chooses which of the best sites to stake and when to move, and walks out and home by the verbs any pawn has; a leader not played chooses by rule. The wish to lead or follow is VB-392. |
+| [VB-789](backlog/VB-789.md) | A site given up: the stake lapses, the work stands, a roofed cottage is an empty farm | far | 3 | S | A party that ends before its move leaves its site: the stake lapses as any does, the next party's search finds the half-made site, and a cottage with its roof on becomes an empty farm. |
| [VB-790](backlog/VB-790.md) | Plan: the outlying booth: a far wood, a summer pasture or a fishing shore worked from a bed there | far | 3 | S | A design pass on work a household does beyond the daily walk from a booth of its own (the far wood, the shieling's summer pasture, a fishing shore): who goes, for how long, what comes home and how, with the head's judgement of the walk. |
| [VB-809](backlog/VB-809.md) | Reach by season in the acts between villages, and the gathering's date as a custom | roads | 3 | S | Marriage, service, kin help, rites and the gathering read the hours of the season they fall in; a culture may gather at midwinter, when the ice bears. |
| [VB-810](backlog/VB-810.md) | What a cart needs underfoot: carts keep to ways and open ground | roads | 3 | M | A hand cart needs a path or open ground, an ox cart a lane, a track or open ground, and neither takes a steep step; a carter's route is searched on its cart's ground. |
@@ -122,6 +124,7 @@ The order tasks are taken in, the first first (`node tools/backlog.js next`). So
| [VB-1526](backlog/VB-1526.md) | Crops by ground: a crop's yield factor by the field's ground | - | 3 | M | An optional ground map on a CROPS row, read once in standing; the head's choice of crop reads it |
| [VB-1537](backlog/VB-1537.md) | The guide's second half: the deeds of sim/commands, and the rules reading a kind's at and needs | - | 3 | S | The guide (VB-1124) lists the job kinds from their at, needs and gives; the verbs of sim/commands carry no name to list, and no rule reads the declarations yet: name each verb beside its check for a Deeds chapter, and let a kind's available read its needs. |
| [VB-1560](backlog/VB-1560.md) | Own time reported: the shares of pastimes by role and season | - | 3 | S | A report of own time by pastime, for tuning PASTIME.weights |
+| [VB-1607](backlog/VB-1607.md) | A site's well under settling in steps: a job of the site, and the move waits for it | - | 3 | S | VB-1587's criteria 2 and 4, which need the move of VB-787 |
| [VB-1610](backlog/VB-1610.md) | A booth's water in the evening: one who comes to its booth after work takes the open fetch | - | 3 | S | the booth's fetch is taken only in the working day (sim/away dayAway); a late arrival ends the day thirsty though the fetch stands open until 20:00 |
| [VB-1611](backlog/VB-1611.md) | The page says what a lodger's water is: the booth's source, whether today's water is in | - | 3 | S | VB-1601 built the booth's fetch and the morning drink; nothing on the page tells of them but the pawn's job line and its Thirsty line |
| [VB-1656](backlog/VB-1656.md) | Sim.load clears the world fields its save lacks | - | 3 | S | A save loads the same on a used world as on a fresh one (found by VB-1654: w.shut left over on a shared world). |
@@ -247,9 +250,7 @@ By arch, in the order of the Archs table, then priority and ID. Each waits for t
| [VB-1962](backlog/VB-1962.md) | Boats and sledges drawn on the map | roads | 3 | S | [VB-812](#VB-812), [VB-811](#VB-811) | Draw a boat at its landing and under way, and a sledge with its pawn, once VB-812 and VB-811 land |
| [VB-188](backlog/VB-188.md) | Plan: the ship: the outside world, silver, institutions and disease (slice 8) | ship | 3 | S | [VB-1924](#VB-1924) | Design ships, silver, the Church and the Crown, rank, tithe and tax, and disease by sea. |
| [VB-636](backlog/VB-636.md) | Settling families come with the ship | ship | 3 | M | [VB-188](#VB-188), [VB-1924](#VB-1924) | A family of another culture lands from a calling ship and walks to a plot or an empty farm; one in 2 years under 300 living, one in 10 after (Proposed). Waits for slice 8's plan (VB-188), which confirms, rewrites or closes it and sets its numbers. |
-| [VB-788](backlog/VB-788.md) | The player's part in settling: the site among five, the walk out and home, the day of the move | far | 3 | S | [VB-787](#VB-787) | The played pawn, leading a party, chooses which of the best sites to stake and when to move, and walks out and home by the verbs any pawn has; a leader not played chooses by rule. The wish to lead or follow is VB-392. |
-| [VB-789](backlog/VB-789.md) | A site given up: the stake lapses, the work stands, a roofed cottage is an empty farm | far | 3 | S | [VB-787](#VB-787) | A party that ends before its move leaves its site: the stake lapses as any does, the next party's search finds the half-made site, and a cottage with its roof on becomes an empty farm. |
-| [VB-791](backlog/VB-791.md) | Wrap-up: settling in steps: the numbers over the seeds, and its bands | far | 3 | S | [VB-787](#VB-787), [VB-788](#VB-788), [VB-789](#VB-789) | The settling built by VB-783 to VB-789 and VB-447 is measured as a whole over the scenarios' seeds, its bands are added, and the design's Proposed rows are brought in line with what was built. |
+| [VB-791](backlog/VB-791.md) | Wrap-up: settling in steps: the numbers over the seeds, and its bands | far | 3 | S | [VB-788](#VB-788), [VB-789](#VB-789) | The settling built by VB-783 to VB-789 and VB-447 is measured as a whole over the scenarios' seeds, its bands are added, and the design's Proposed rows are brought in line with what was built. |
| [VB-048](backlog/VB-048.md) | Wrap-up: tune yields and the food balance of a farm | animals | 3 | M | [VB-712](#VB-712), [VB-714](#VB-714) | With animals in, tune field yield, fields per farm and food from animals so a family of 6 is fed in an ordinary year. |
| [VB-712](backlog/VB-712.md) | Custom: herding by each farm or by turns for the village (byahjord) | animals | 3 | M | [VB-710](#VB-710) | A voted custom (farm default, turns; malleability 0.3): under turns one farm a day herds all the village's herds on one pasture of the outland, the turn weighted by head kept (a day for each 2 cow-equivalents). |
| [VB-715](backlog/VB-715.md) | Wrap-up: the customs of the animals measured | animals | 3 | S | [VB-710](#VB-710), [VB-712](#VB-712) | Bands for the three customs, long runs with the customs left to the villages, the attitudes' cost on a late save against the plan's 0.9 ms a game day, and the parameters a tuning run would move; it tunes nothing. |
@@ -278,7 +279,6 @@ By arch, in the order of the Archs table, then priority and ID. Each waits for t
| [VB-893](backlog/VB-893.md) | Page: the Plan tab shows stores by the supply component and the year ahead | - | 3 | S | [VB-1123](#VB-1123) | The plan panel (VB-256) takes up VB-667's supply component and the year-ahead graph |
| [VB-1557](backlog/VB-1557.md) | Design: the wish reads a pawn's ties and its opinion of its head | - | 3 | S | Kim | A design pass on the yearly wish (sim/wishes), which reads ambition and hunger only: what ties and the opinion of the head would add, and what it moves of the growth targets |
| [VB-1595](backlog/VB-1595.md) | The leader's choice shows each site's water | - | 3 | S | [VB-788](#VB-788) | VB-1583 built the estimate (sim/settle sites, Sim.siteWater, siteWaterWords); the choice's views are VB-788's and VB-1544's, not built yet |
-| [VB-1607](backlog/VB-1607.md) | A site's well under settling in steps: a job of the site, and the move waits for it | - | 3 | S | [VB-787](#VB-787) | VB-1587's criteria 2 and 4, which need the move of VB-787 |
| [VB-1617](backlog/VB-1617.md) | Evaluate the adaptive context reset: keep, adjust or abandon it | - | 3 | S | Kim | Compare the reset's period with the ceiling's by VB-1615's tools once 15 eligible tasks are done in each, or 4 weeks on; decide by the rules VB-1616 set |
| [VB-1740](backlog/VB-1740.md) | The save's last shared objects become ids, and the codec's first pass goes | - | 3 | M | [VB-1739](#VB-1739) | The rest of VB-247's census (workDue, plans, plot tiles, herds, claims, carts, common fields) as ids; then encode's first pass, $id, $ref and $arr go |
| [VB-1853](backlog/VB-1853.md) | The goal kinds' steps as rows of the method table | - | 3 | M | [VB-1773](#VB-1773) | VB-1777 left GOALS a table of world readers beside the kinds' methods (review F3); waits for the stages as facts (docs/plans/four-scales/README.md, 3.2), taken up at the arch wrap-up VB-1773 |
diff --git a/BACKLOG_ARCHIVE.md b/BACKLOG_ARCHIVE.md
index 72ccca8e..d97e2ed1 100644
--- a/BACKLOG_ARCHIVE.md
+++ b/BACKLOG_ARCHIVE.md
@@ -894,6 +894,7 @@ Done tasks and closed archs, moved out of `BACKLOG.md` so its tables list only o
| [VB-1406](backlog/VB-1406.md) | Refactor: declare beside the owner: the lists every task appends to become registries joined at load | - | 1 | L | 134 tasks collide on lists each feature adds a line to (suites, owners, manifest, counters, the Sim facade, rules' exports, migrations, event kinds); each owner declares its entry and a thin registry joins them, as sim/kinds and sim/commands do. |
| [VB-1485](backlog/VB-1485.md) | Repair: a cow led home books goodwill with a dead holder (populous small seed 3) | - | 1 | S | relations throws 'goodwill: cannot add 20 between 6 and 76' from exchange ledHome (a deal's cow led home) when a holder of either household is no longer alive |
| [VB-1495](backlog/VB-1495.md) | Repair: tests/browser-editor places no empty farm near the village | - | 1 | S | tests/browser-editor.js fails five checks, from 'no empty farm could be placed near the village' on; seen on main at 5e69f31, before VB-1491. |
+| [VB-787](backlog/VB-787.md) | Settling in steps: staked at the round, built from a booth, founded at the move | far | 2 | L | The round stakes a site and forms the party; its adults blaze the trail, raise a booth, clear and build while their households stay at home and feed them; the household and the village are founded on the day of the move. |
| [VB-459](backlog/VB-459.md) | The harvest home: a yearly feast at the farm of a household with plenty | - | 2 | S | A new occasion kind: once a year a household above the feast's threshold asks kin and its holder's strongest ties, up to 20, to its farm when the grain is in. |
| [VB-1926](backlog/VB-1926.md) | The head's call is urgent or not: bring the load in, or drop everything | plans | 2 | M | Two calls home (Kim, 27 Nov): non-urgent, the default, brings the load in and arrives within about an hour; urgent drops the load and comes now. The head's call today is one kind, instant, and sets a load down only when the caller says so. |
| [VB-1768](backlog/VB-1768.md) | A village's routines as levies: lots by a village custom, the household names its days, the alderman dates only the work done together | plans | 2 | M | The meeting's routines lay obligation records (source routine) on its households, split into lots by the village's custom of lots (by fields at the start; by adults; equal); a household names its days; callWorkday fixes a date three days ahead only for work done together; staying away is a breach at the cost of goodwill. |
diff --git a/backlog/VB-1607.md b/backlog/VB-1607.md
index 54c1f37e..23d4c591 100644
--- a/backlog/VB-1607.md
+++ b/backlog/VB-1607.md
@@ -1,6 +1,5 @@
# VB-1607: A site's well under settling in steps: a job of the site, and the move waits for it
-Status: blocked
-Waits for: VB-787
+Status: ready
Priority: 3
Size: S
Design ref: design.md, Goods and the farming year (Water by the site, Wells, At a new site); Settling in steps; backlog/VB-1587.md
diff --git a/backlog/VB-1937.md b/backlog/VB-1937.md
new file mode 100644
index 00000000..31c6e857
--- /dev/null
+++ b/backlog/VB-1937.md
@@ -0,0 +1,13 @@
+# VB-1937: Settling in steps: f.booth goes, a booth household loads as a site
+Status: ready
+Priority: 2
+Size: M
+Design ref: design.md, Moving to new land (Settling in steps); backlog/VB-787.md
+Touches: sim/building (boothWork); sim/cottageplan (finishBoothStage); sim/kinds; sim/saves; sim/sites; sim/upgrade; sim/projects; tests/saves.js; tests/booth.js
+Goal: One way to build a new farm's cottage: the site's (VB-787), with old saves carried over
+Acceptance criteria:
+- [ ] `f.booth` and the booth's cottage jobs (`boothJob`, `boothWork` in sim/building, `finishBoothStage` in sim/cottageplan, their kinds in sim/kinds) go; camp, the scenarios (landAlone, ladder) and the page stop setting or reading `f.booth` (settlers no longer set it since VB-787).
+- [ ] A save with a household living in a booth loads with its cottage's stages as a site of `sim/sites` at step 3 (stage `building`, its tiles' steps done, the cottage's open stage kept) whose household is already founded, and plays on: the move at the roof founds nothing, it only ends the site (`tests/saves.js`).
+- [ ] `npm test` green; `tests/booth.js` and `tests/sites.js` cover the loaded booth site.
+
+Noted by VB-787, 27 November 2026.
diff --git a/backlog/VB-787.md b/backlog/VB-787.md
index 005826e8..93fdd277 100644
--- a/backlog/VB-787.md
+++ b/backlog/VB-787.md
@@ -1,5 +1,5 @@
# VB-787: Settling in steps: staked at the round, built from a booth, founded at the move
-Status: ready
+Status: done (2026-11-27)
Priority: 2
Size: L
Arch: far
@@ -7,20 +7,27 @@ Phase: implement
Design ref: design.md, Moving to new land (Settling in steps; Sleeping away from home); docs/plans/VB-445.md, section 5; design.md, Moving to new land; Clearing a new plot
Goal: A farm away from home is established over a season or more by people who walk there, sleep there and build it, and nobody lives at a place before it has a roof.
Acceptance criteria:
-- [ ] State: `st.sites[]`, owned by `sim/settle`: `{id, leader, party {all, followers}, from (village), village (the small village joined, or none), house, field, plot (the tiles and their steps, as a plot's), booth, stage, since}`, with a live index, invariants and its line in `docs/architecture/ownership.md`. The stake on its tiles is the leader's (a claim's holder may be a pawn: `sim/stakes`, `sim/claims`), renewed by the work as a field's is.
-- [ ] Step 1, the verb `stakeSite` at the round, in place of `leave`: the leader, the party and the site as today (and as VB-786 searches); nobody moves, no grain is taken, no household or village is made. The round's provisions check goes to step 4.
-- [ ] Step 2: the leader calls `blaze` (VB-447) from the home green to the site; the party's adults take its jobs.
-- [ ] Step 3, the site's jobs, owned by the site and taken by its party's members of 14 and over (but a nursing mother) at role priority 9 (`PLOT_PRIO`'s first): the booth (VB-784), the house tile and the first field cleared by the steps a plot has (fell 10, grub 6, clear 10 and up to 20 for stones, break 30), the first field sown in its season with seed carried from the party's stakes or their households, the cottage's foundation 30, walls 60 with 18 loads of timber (the site's felled trees, else timber trips to the nearest wood) and roof 30. A worker lodges at the booth (VB-783) when the walk there and back is over `AWAY.walk`, with a pack from the household it belongs to, and walks home for the next; with no job open it goes home and works there.
-- [ ] Step 4, the verb `leave`, tried when the roof's job ends and on the leader's household's planning day: the cottage finished (the roof on), and the provisions there (to the next harvest and `SETTLE.margin`, 6 days, counted from that day, and seed unless the field is sown; the first field may still be to break or sow, and follows from the household; from the stakes and the old households as today; short of it the move waits, and the log says why once a season). The household is founded with the leader as head, and the village where the site is a new one (named then); the party walks out with its loads as VB-675 has them.
-- [ ] `f.booth` and the booth's cottage jobs (`boothJob`, `boothWork`, `finishBoothStage`) go; a save with a household living in a booth loads with its cottage's stages as a site at step 3 whose household is already founded, and plays on (`tests/saves.js`).
-- [ ] A leader who dies is followed by the party's next adult; other endings are VB-789's.
-- [ ] The log and the record: the stake, the trail's end, the roof and the move each have their line and event, naming the pawn and the place; the village panel's count of those who wait shows the sites under way.
-- [ ] Numbers before and after, populous small, seeds 3, 7, 11 and 42, 15 years, and founders small, seeds 7 and 42, 30 years: parties, days from the round to the move (median and longest), sites given up, villages founded and farms joined, hours worked at sites and hours the homes' own jobs lost, grain the homes gave (packs and provisions) against the 42 days of before, hungry days of the settlers and of their old households in the two years round the move, growth against Deciding without Kim 2. Whether households, not only averages, are better off.
-- [ ] Cost (Rules for cost, 9): a site a party, a few under way on an island of 1,000, at most six jobs open each; nothing polled. `node tests/counters.js` before and after; a late save (`node tools/sim.js --load FILE --years 1 --report perf`) for the counters, times to the night.
-- [ ] Tests on a constructed state: a party of two stakes a wooded site four hours out, blazes, builds and moves, and the household exists only from the move; a home with no grain to spare sends no worker; a save at each step plays as the unbroken run.
-- [ ] If the module passes 700 lines, the split task the lint asks for is opened and named.
+- [x] State: `st.sites[]`, owned by `sim/settle`: `{id, leader, party {all, followers}, from (village), village (the small village joined, or none), house, field, plot (the tiles and their steps, as a plot's), booth, stage, since}`, with a live index, invariants and its line in `docs/architecture/ownership.md`. The stake on its tiles is the leader's (a claim's holder may be a pawn: `sim/stakes`, `sim/claims`), renewed by the work as a field's is.
+- [x] Step 1, the verb `stakeSite` at the round, in place of `leave`: the leader, the party and the site as today (and as VB-786 searches); nobody moves, no grain is taken, no household or village is made. The round's provisions check goes to step 4.
+- [x] Step 2: the leader calls `blaze` (VB-447) from the home green to the site; the party's adults take its jobs.
+- [x] Step 3, the site's jobs, owned by the site and taken by its party's members of 14 and over (but a nursing mother) at role priority 9 (`PLOT_PRIO`'s first): the booth (VB-784), the house tile and the first field cleared by the steps a plot has (fell 10, grub 6, clear 10 and up to 20 for stones, break 30), the first field sown in its season with seed carried from the party's stakes or their households, the cottage's foundation 30, walls 60 with 18 loads of timber (the site's felled trees, else timber trips to the nearest wood) and roof 30. A worker lodges at the booth (VB-783) when the walk there and back is over `AWAY.walk`, with a pack from the household it belongs to, and walks home for the next; with no job open it goes home and works there. (The first field is cleared and broken, not sown, at the site: it follows from the household, Kim 27 Nov; the well is marked at the move.)
+- [x] Step 4, the verb `leave`, tried when the roof's job ends and on the leader's household's planning day: the cottage finished (the roof on), and the provisions there (to the next harvest and `SETTLE.margin`, 6 days, counted from that day, and seed unless the field is sown; the first field may still be to break or sow, and follows from the household; from the stakes and the old households as today; short of it the move waits, and the log says why once a season). The household is founded with the leader as head, and the village where the site is a new one (named then); the party walks out with its loads as VB-675 has them.
+- [ ] `f.booth` and the booth's cottage jobs (`boothJob`, `boothWork`, `finishBoothStage`) go; a save with a household living in a booth loads with its cottage's stages as a site at step 3 whose household is already founded, and plays on (`tests/saves.js`). (Not done: f.booth is still read by camp, the scenarios and the page; settlers no longer set it. Carried by the follow-up task noted, "Settling in steps: f.booth goes, a booth household loads as a site".)
+- [x] A leader who dies is followed by the party's next adult; other endings are VB-789's. (tests/sites.js, 4.)
+- [x] The log and the record: the stake, the trail's end, the roof and the move each have their line and event, naming the pawn and the place; the village panel's count of those who wait shows the sites under way. (siteStaked, siteTrail, siteRoofed, left, siteLeader, siteGivenUp; the village card lists the sites under way, src/page/villagecard.js.)
+- [ ] Numbers before and after, populous small, seeds 3, 7, 11 and 42, 15 years, and founders small, seeds 7 and 42, 30 years: parties, days from the round to the move (median and longest), sites given up, villages founded and farms joined, hours worked at sites and hours the homes' own jobs lost, grain the homes gave (packs and provisions) against the 42 days of before, hungry days of the settlers and of their old households in the two years round the move, growth against Deciding without Kim 2. Whether households, not only averages, are better off. (Not run in the task: 15- and 30-year runs on a shared machine; for the night, on the merged result.)
+- [ ] Cost (Rules for cost, 9): a site a party, a few under way on an island of 1,000, at most six jobs open each; nothing polled. `node tests/counters.js` before and after; a late save (`node tools/sim.js --load FILE --years 1 --report perf`) for the counters, times to the night. (`node tests/counters.js`: 196 counters, 0 out against the baseline; sim/sites asks only st.sites, at most six jobs a site. The late save not run: for the night.)
+- [ ] Tests on a constructed state: a party of two stakes a wooded site four hours out, blazes, builds and moves, and the household exists only from the move; a home with no grain to spare sends no worker; a save at each step plays as the unbroken run. (Done: two stake, blaze, build from home with lodgers, move day 25, household founded only at the move; no grain, no lodger; saves at the stake and at building play on. Not done: the site is not checked to be wooded four hours out (tests/forestsites.js has a wooded site), and the roof sets off the move at once, so no save is taken at roofed.)
+- [x] If the module passes 700 lines, the split task the lint asks for is opened and named. (sim/sites 323 lines, sim/settle 580: none passes.)
Noted by VB-445, 16 November 2026.
## Kim, 18 November 2026
The household and the village are founded when the farmstead is complete (answer 3 of the VB-445 questions, `QUESTION_ARCHIVE.md`): this replaces the plan's proposed founding moment. 27 Nov 2026 (Kim): complete means the cottage finished; the field can follow (design.md, Settling in steps, step 4). Until then the party's adults work as members of their old households, which feed them. The other six answers stand as proposed.
+
+## Decisions (VB-787, first part)
+- `st.sites` lives in a new module `sim/sites` (the site, its jobs, their ends), not `sim/settle`, which keeps the round and the verbs `stakeSite` and `leave`: settle stays under 700 lines.
+- The site's jobs are owned by the leader's household (the one that feeds its workers, Kim 18 Nov); `j.party` limits them to the party's members of 14 and over, not nursing, at `PLOT_PRIO.waiting` (sim/fit sitePrio). A member of another household takes none (rare: leader, spouse and siblings live at one home).
+- The house tile is cleared first, then the cottage; the field is cleared and broken alongside and not sown at the site: it follows from the household (Kim, 27 Nov 2026).
+- Lodging (sim/away siteLodgers): a worker whose walk there and back is over `AWAY.walk` lodges at the booth tile with the site's job keys; the lodger's own rule (stakeIfRough) raises the booth. Tried once a day a worker (`site.tried`).
+- The walls' wood left at the move goes to the woodpile up to `ECON.woodWinter`, the rest burnt, as a plot's.
diff --git a/backlog/VB-788.md b/backlog/VB-788.md
index 4e2fd46b..43d1cf30 100644
--- a/backlog/VB-788.md
+++ b/backlog/VB-788.md
@@ -1,6 +1,5 @@
# VB-788: The player's part in settling: the site among five, the walk out and home, the day of the move
-Status: blocked
-Waits for: VB-787
+Status: ready
Priority: 3
Size: S
Arch: far
diff --git a/backlog/VB-789.md b/backlog/VB-789.md
index e7342581..d3603f07 100644
--- a/backlog/VB-789.md
+++ b/backlog/VB-789.md
@@ -1,6 +1,5 @@
# VB-789: A site given up: the stake lapses, the work stands, a roofed cottage is an empty farm
-Status: blocked
-Waits for: VB-787
+Status: ready
Priority: 3
Size: S
Arch: far
diff --git a/backlog/VB-791.md b/backlog/VB-791.md
index 58848f06..9e3bb241 100644
--- a/backlog/VB-791.md
+++ b/backlog/VB-791.md
@@ -1,6 +1,6 @@
# VB-791: Wrap-up: settling in steps: the numbers over the seeds, and its bands
Status: blocked
-Waits for: VB-787, VB-788, VB-789
+Waits for: VB-788, VB-789
Priority: 3
Size: S
Arch: far
diff --git a/docs/architecture/ownership.md b/docs/architecture/ownership.md
index b3abb0ac..4fc611d1 100644
--- a/docs/architecture/ownership.md
+++ b/docs/architecture/ownership.md
@@ -384,6 +384,7 @@ These are read and never written after creation. Each has one owner by construct
| village | `workday` (the last work day: hours each adult worked, judged at its end, VB-120) | workdays |
| pawn | `workdays` (the year's work days turned out to and stayed away from, read by society's standing, VB-120) | workdays |
| st | `booths`, `boothSeq` (the booths raised or being raised, live ones only: staked and raised by `sim/building`'s verb and job, rotted away by its daily rule, VB-784) | building |
+| st | `sites`, `siteSeq` (the sites of new farms under way, one a party: staked by `sim/settle`'s verb stakeSite through `sim/sites`, worked by its jobs, ended by the verb leave at the move, VB-787) | sites |
| union | `id`, `a`, `b`, `start`, `kind` | records (`marry`), lifecycle (`wed`) |
| herd | `id`, `species` | herds (`makeHerd`) |
| job | `id`, `key`, `kind`, `owner`, `site`, `posted`, `hours`, and its source's fields (`field`, `farm`, `meadow`, `plot`, `claim`, ...) | jobs (`post`) |
diff --git a/src/layers.json b/src/layers.json
index 81e90745..9244c359 100644
--- a/src/layers.json
+++ b/src/layers.json
@@ -107,6 +107,7 @@
"sim/timberhouse",
"sim/camp",
"sim/trails",
+ "sim/sites",
"sim/drying",
"sim/tar",
"sim/drain",
diff --git a/src/manifest.json b/src/manifest.json
index d0393eca..c92ae061 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -128,6 +128,7 @@
"sim/projectplans.js",
"sim/facilities.js",
"sim/trails.js",
+ "sim/sites.js",
"sim/kinds.js",
"sim/days.js",
"sim/hands.js",
diff --git a/src/owners.json b/src/owners.json
index 061c6496..720edb7b 100644
--- a/src/owners.json
+++ b/src/owners.json
@@ -126,6 +126,8 @@
"st.away[].guest": "sim/journeys",
"st.booths": "sim/building",
"st.boothSeq": "sim/building",
+ "st.sites": "sim/sites",
+ "st.siteSeq": "sim/sites",
"st.facilities": "sim/facilities",
"st.facilityIdx": { "owner": "sim/facilities", "category": "cache" },
"agent.away": { "owner": "sim/away", "category": "cache" },
diff --git a/src/page/villagecard.js b/src/page/villagecard.js
index 817dba4c..2ce2a56f 100644
--- a/src/page/villagecard.js
+++ b/src/page/villagecard.js
@@ -196,6 +196,19 @@ function showVillage(id) {
v.crowded > 0 ? `Crowded: ${v.crowded} adults wait for land, and there is no room to clear` : '',
daughters.length ? `Daughter villages: ${daughters.map((u) => u.name).join(', ')}` : '',
out.length ? `Want to move out: ${out.map(name).join(', ')}` : '',
+ // the sites under way from it (VB-787): staked, their trail, their cottage, roofed and waiting to move
+ ...(st.sites || [])
+ .filter((s) => s.from === v.id)
+ .map(
+ (s) =>
+ `Building a new farm: ${s.party.all.map(name).join(', ')}; ${
+ {
+ trail: 'the trail is being blazed',
+ building: 'the site is being cleared and built',
+ roofed: 'the cottage stands, the move waits',
+ }[s.stage] || s.stage
+ }`,
+ ),
...plots.map((plot) =>
!plot.steps
? `Plot cleared, for ${name(plot.holder)}; the cottage is built`
diff --git a/src/sim/away.js b/src/sim/away.js
index fa06a3b7..297afc32 100644
--- a/src/sim/away.js
+++ b/src/sim/away.js
@@ -15,6 +15,7 @@ VB['sim/away'] = (() => {
const { stayOf, travelling, tileAt, placeOf } = VB['sim/pose'];
const { hostWhy } = VB['sim/hosting'];
const { hexSteps } = VB['sim/hex'];
+ const Sites = VB['sim/sites'];
// @tunable AWAY: sleeping away from home (VB-783; design.md, Sleeping away from home): pack, the rations a pawn away carries at most (12 days of the
// 30 rations a back carries, the rest of the load being tools and seed); walk, the walking hours there and back over which a place is
// worked from a bed there rather than from home (a third of the working day); yard, the steps from its house within which a pawn is at
@@ -334,6 +335,39 @@ VB['sim/away'] = (() => {
}
return rest || idle;
}
+ // The site workers' lodging (VB-787; design.md, Settling in steps, 3): of the free pawns `idle` in the first hours of the working day, a
+ // member of a site's party who works there (sim/sites worksAt), its trail blazed, whose walk there and back is over AWAY.walk, lodges at
+ // the site's booth tile with a pack for the days its work wants (AWAY.pack at most), the site's jobs its stay's: there it stakes and
+ // raises its booth (stakeIfRough) and works; with none open it comes home (dayAway). Tried once a day a pawn (site.tried), so one whose
+ // household cannot spare the pack stays and works at home. One near enough works there from home, as any job. The pawns not set out.
+ function siteLodgers(st, idle, c) {
+ if (!st.sites.length || c.hour < WORK[0] || c.hour >= WORK[0] + 2) return idle;
+ const day = Math.floor(st.t / DAY);
+ let out = null;
+ for (let i = 0; i < idle.length; i++) {
+ const a = idle[i],
+ s = a.away === undefined && !travelling(a) ? Sites.siteOf(st, a.id) : null,
+ keep = () => out && out.push(a);
+ if (!s || s.stage !== 'building' || s.booth === null || s.tried[a.id] === day || !Sites.worksAt(st, s, a.id)) {
+ keep();
+ continue;
+ }
+ s.tried[a.id] = day;
+ const hh = st.pawns[a.id].household === null ? null : st.households[st.pawns[a.id].household],
+ walk = hh && hh.farmstead !== null ? walkHours(st, houseOf(st, hh), s.booth) : 0;
+ if (2 * walk <= AWAY.walk) {
+ keep();
+ continue;
+ }
+ const workers = s.party.all.filter((id) => Sites.worksAt(st, s, id)).length,
+ days = Math.max(1, Math.min(AWAY.pack, Math.ceil(Sites.hoursLeft(st, s) / (workers * (WORK[1] - WORK[0])))));
+ const args = { why: 'site', days, jobs: Sites.jobKeys(s), walk };
+ if (issue(st, { actor: a.id, verb: 'lodge', target: s.booth, args, source: 'pawn' }) === true)
+ out ||= idle.slice(0, i);
+ else keep();
+ }
+ return out || idle;
+ }
// A pawn away has come to its bed (sim/agents' arrived): one that turned for home is home, and its stay ends; what is left of its pack
// goes into its household's meals, and the herds it brought home are by the farm.
function atBed(st, a) {
@@ -391,6 +425,7 @@ VB['sim/away'] = (() => {
unlodge,
feedAway,
dayAway,
+ siteLodgers,
lodgeWhy,
};
})();
diff --git a/src/sim/building.js b/src/sim/building.js
index 6b71af5c..4e6b25d1 100644
--- a/src/sim/building.js
+++ b/src/sim/building.js
@@ -958,6 +958,7 @@ VB['sim/building'] = (() => {
roofless,
shelterStands,
stakeShelter,
+ fetchTimber,
rotBooths,
boothWork,
timberWork,
diff --git a/src/sim/clock.js b/src/sim/clock.js
index d97f6a5a..c34dda16 100644
--- a/src/sim/clock.js
+++ b/src/sim/clock.js
@@ -22,7 +22,7 @@ VB['sim/clock'] = (() => {
{ dropMind } = VB['sim/attention'],
{ reckonAll } = VB['sim/work'];
const { placeOf } = VB['sim/pose'];
- const { feedAway, dayAway } = VB['sim/away'],
+ const { feedAway, dayAway, siteLodgers } = VB['sim/away'],
{ fetchGoesOn } = VB['sim/journeys'];
const { refreshJobs, lookForWork } = VB['sim/jobs'],
{ takeDay, abed, dutyRound, eveningCall } = VB['sim/day'],
@@ -745,7 +745,8 @@ VB['sim/clock'] = (() => {
playerStep(st); // the player's queue goes before the pawn's own logic (VB-169)
const c = cal(st.t),
all = stepAgents(st, c),
- mine = st.controlled && st.controlled.length ? all.filter((a) => !unplanned(st, a.id)) : all, // any controller's pawn (VB-1745)
+ own = st.controlled && st.controlled.length ? all.filter((a) => !unplanned(st, a.id)) : all, // any controller's pawn (VB-1745)
+ mine = st.sites.length ? siteLodgers(st, own, c) : own, // a site's workers set out to lodge there (VB-787)
idle = abed(st, st.away.length ? dayAway(st, mine) : mine); // a lodger works only what its stay names (VB-783); the ill keep to bed
if (idle.length) {
// each takes the next task of its day (VB-466); those it gave none look at the household's opportunities, whose day is then allotted
diff --git a/src/sim/expansion.js b/src/sim/expansion.js
index fbb7ae0d..baf34ce7 100644
--- a/src/sim/expansion.js
+++ b/src/sim/expansion.js
@@ -492,5 +492,7 @@ VB['sim/expansion'] = (() => {
activePlots,
MAX_PLOTS,
plotTimber,
+ stepsFor,
+ stepHours,
};
})();
diff --git a/src/sim/fit.js b/src/sim/fit.js
index 0def18d9..e446597d 100644
--- a/src/sim/fit.js
+++ b/src/sim/fit.js
@@ -37,21 +37,27 @@ VB['sim/fit'] = (() => {
// Water by the site, How it is ranked). The head allots by it (allot); a
// pawn on duty or lent bids it for the tasks of the household it works for, where a job that k pawns already work gets join^k of the
// bid (VB-102).
+ // A site's job (VB-787; sim/sites, j.party its party): its members of 14 and over, but a mother who nurses, at the first of PLOT_PRIO;
+ // nobody else.
+ const sitePrio = (st, p, j) =>
+ j.party.includes(p.id) && p.age >= 14 && !(p.nursingUntil > st.t) ? PLOT_PRIO.waiting : 0;
const plotPrio = (st, p) => (st.demand.includes(p.id) ? PLOT_PRIO.waiting : PLOT_PRIO[p.role] || 0);
// Role priority for a job: by plot, by claim on an empty farm (sim/farmclaims), by the village's custom on a common field (sim/commons,
// VB-100), by the kind's own `rank` where it declares one (VB-362: spinning and weaving, by a practice and the pawn's sex), else by
// role and kind, the holder's with the ranks of the roles its household lacks (`stand`, the mask of sim/roles absentMask its caller
// made for the holder, else 0; VB-1545).
const prioOf = (st, p, j, stand = 0) =>
- j.plot
- ? plotPrio(st, p)
- : j.claim
- ? claimPrio(st, p, j)
- : j.common
- ? commonPrio(st, p, j)
- : KINDS[j.kind].rank
- ? KINDS[j.kind].rank(st, p, j, stand)
- : ROLES[p.role].ranks[stand][j.kind] || 0;
+ j.party
+ ? sitePrio(st, p, j)
+ : j.plot
+ ? plotPrio(st, p)
+ : j.claim
+ ? claimPrio(st, p, j)
+ : j.common
+ ? commonPrio(st, p, j)
+ : KINDS[j.kind].rank
+ ? KINDS[j.kind].rank(st, p, j, stand)
+ : ROLES[p.role].ranks[stand][j.kind] || 0;
// Whether the head allots member id the day: not a child under 7, one away from home (VB-287, VB-783), the player's pawn while it is
// commanded, or one on a day owed elsewhere (sim/days) or lent as a hand.
const allotted = (st, p) =>
diff --git a/src/sim/jobs.js b/src/sim/jobs.js
index b84b1e79..7e9986a0 100644
--- a/src/sim/jobs.js
+++ b/src/sim/jobs.js
@@ -70,7 +70,8 @@ VB['sim/jobs'] = (() => {
}
// A plot's steps and an empty farm's restoration are asked for the whole island, every review hour, whoever owns them.
// a staked booth's raising (VB-1172), a booth's water (VB-1601)
- const islandJob = (j) => !!j.plot || j.kind === 'restore' || j.kind === 'booth' || j.kind === 'boothwater';
+ const islandJob = (j) =>
+ !!j.plot || j.siteId !== undefined || j.kind === 'restore' || j.kind === 'booth' || j.kind === 'boothwater';
// The due-queue's ask of each time-bound kind: its own rule (a shared rule, as the byre's, posts only that kind there).
const DUE_RULES = WINDOWED.map((k) => [[k, KINDS[k].available]]);
// What a member without a task asks: the household's kinds but those the due-queue opens.
diff --git a/src/sim/kinds.js b/src/sim/kinds.js
index 21b98300..26421605 100644
--- a/src/sim/kinds.js
+++ b/src/sim/kinds.js
@@ -138,6 +138,7 @@ VB['sim/kinds'] = (() => {
Object.assign(KINDS, VB['sim/timberhouse'].KINDS); // the timber house's frame and roof (VB-1664): sim/timberhouse's
Object.assign(KINDS, VB['sim/facilities'].KINDS); // a facility's stages raised and its upkeep (VB-361): sim/facilities'
Object.assign(KINDS, Expansion.plotted(KINDS)); // a plot's step ends in its finish, through its kind's `done` (sim/expansion, VB-1821)
+ Object.assign(KINDS, VB['sim/sites'].sited(KINDS)); // a site's step ends in its finish, as a plot's (sim/sites, VB-787)
// every kind that declares no methods of its own is work done at its site (sim/methods labour, VB-1750: no kind runs on the phases); an
// indoor kind's work stands by the door of its house (as sim/agents' spotAt)
for (const k in KINDS) {
@@ -319,6 +320,7 @@ VB['sim/kinds'] = (() => {
(ASK.farmAfterPlans.push(rule(Lying.bringWork)), ASK.village.push(rule(Lying.bringWork)));
ASK.village.push(rule(VB['sim/facilities'].villageWork)); // a village's facilities raised and mended (VB-361)
ASK.island.push(rule('blaze')); // the trails under way, each its blazer's household's (VB-447, sim/trails)
+ ASK.island.push(rule(VB['sim/sites'].siteWork)); // the sites of new farms under way, each its leader's household's (VB-787, sim/sites)
for (const e of ASK.field) for (const g of ASK.stages[e[0]]) (ASK.fieldAt[g] ||= []).push(e);
// ---- goals (VB-1777; docs/plans/four-scales/README.md, 3.2): a task at a tile carried through several steps, for any pawn ----
// A goal kind is declared as data by the domain whose kinds carry its steps, beside their rules (GOALS): sim/fieldwork's plant and
diff --git a/src/sim/records.js b/src/sim/records.js
index 7eaf0243..85815780 100644
--- a/src/sim/records.js
+++ b/src/sim/records.js
@@ -56,6 +56,12 @@ VB['sim/records'] = (() => {
moved: 0,
joined: 0,
left: 0,
+ siteStaked: 0, // a site of a new farm staked at the round, its trail blazed, its cottage roofed (sim/sites, VB-787)
+ siteTrail: 0,
+ siteRoofed: 0,
+ siteWaits: 0, // the move from a roofed site waits, with why, once a season
+ siteLeader: 0, // the party's next adult leads the site after its leader's death
+ siteGivenUp: 0,
stayed: 0,
settled: 0,
noLand: 0,
diff --git a/src/sim/saves.js b/src/sim/saves.js
index 6418c8e2..8a220e1f 100644
--- a/src/sim/saves.js
+++ b/src/sim/saves.js
@@ -430,6 +430,7 @@ VB['sim/saves'] = (() => {
VB['sim/stores'].heapsLoaded(st); // VB-733: an older save's heap of no rock, and its quern's `rock`
VB['sim/quern'].quernsLoaded(st);
VB['sim/byrehouse'].byresLoaded(st); // VB-1665: an older save's farms read as having their byres
+ VB['sim/sites'].sitesLoaded(st); // VB-787: an older save has no sites under way
for (const hd of st.herds) for (const e of hd.cull || []) if (e.sheep) e.lot ??= 1; // VB-1682: a sheep marked alone
const R = VB['sim/rng']; // a save from before a system's stream (VB-761's `making`): its stream from the seed and its name, as at seeding
for (const k of R.SYSTEMS) if (!st.rng[k]) st.rng[k] = R.makeStream(data.seed, k);
diff --git a/src/sim/scenarios.js b/src/sim/scenarios.js
index a3287a84..984a7b0b 100644
--- a/src/sim/scenarios.js
+++ b/src/sim/scenarios.js
@@ -553,6 +553,7 @@ VB['sim/scenarios'] = (() => {
// @state st.occasions, st.occasionSeq: the occasions called and not over, and the next one's id (see sim/occasions)
// @state st.away, st.awaySeq: the open stays away from home, journeys among them, and the next one's id (see sim/away, VB-783)
// @state st.booths, st.boothSeq: the booths raised or being raised, and the next one's id (see sim/building, VB-784)
+ // @state st.sites, st.siteSeq: the sites of new farms under way, and the next one's id (see sim/sites, VB-787)
// @state st.demand: array of pawn ids who want to move out. recomputed by countDemand(st) (sim/heirs)
// @state st.agents[]: {id, x, y, path, seg, journey, homeward, job, inside, anim, carry, face, stride, ox, oy, idleUntil, talk (sim/relations)};
// one per pawn, map units; side (sim/agents, VB-251): absent unless the pawn holds a partial or background task
@@ -644,6 +645,8 @@ VB['sim/scenarios'] = (() => {
visits: [], // the suitors' visits planned (sim/visits, VB-289)
booths: [],
boothSeq: 0,
+ sites: [], // the sites of new farms under way (sim/sites, VB-787)
+ siteSeq: 0,
facilities: [], // built things on sites (sim/facilities, VB-361)
finds: new Map(),
deer: null,
diff --git a/src/sim/settle.js b/src/sim/settle.js
index b372fcf2..78090294 100644
--- a/src/sim/settle.js
+++ b/src/sim/settle.js
@@ -6,7 +6,7 @@ VB['sim/settle'] = (() => {
const { next: rnd, drawer } = VB['sim/rng'];
const { B } = VB['world/biomes'];
const { DAY, SETTLE, ECON, FIELDS, WOOD, MARRIAGE, SPEED } = VB['sim/rules'],
- { CROPS, fertility, openGround: farmable, clearable, clearedFertility } = VB['sim/crops'];
+ { CROPS, SOIL, fertility, openGround: farmable, clearable, clearedFertility } = VB['sim/crops'];
const { bufferOf, act } = VB['sim/traits'];
const { wishOf, moveWhy } = VB['sim/wishes'];
const { reserved } = VB['sim/stores'];
@@ -19,8 +19,8 @@ VB['sim/settle'] = (() => {
const names = VB['sim/names'];
const { builtTiles, fieldProject } = VB['sim/fieldplans'];
const { stake } = VB['sim/stakes'];
- const { findSite, activePlots, building, roomAt, livePlots, tilesOf } = VB['sim/expansion'],
- { cottagePlan } = VB['sim/cottageplan'];
+ const { findSite, activePlots, building, roomAt, livePlots, tilesOf } = VB['sim/expansion'];
+ const Sites = VB['sim/sites'];
const { foundHousehold } = VB['sim/membership'];
const { farmName } = VB['sim/cottage'];
const { addSettlement } = VB['sim/society'];
@@ -271,23 +271,24 @@ VB['sim/settle'] = (() => {
}
return null;
}
- // ---- settling ----
- // The party settles on `house` in village v: a farmstead with no fields whose cottage is still to build (f.booth, the mark; the cottage a
- // project plan of the household, sim/expansion's), its shelter begun on the house tile (VB-1666: the ladder's first rung, one rule for
- // every household; sim/building stakeShelter), a household with the provisions as its grain, and `field` as its first field project.
- // They sleep under the open sky until the shelter stands, and their cottage waits for it (sim/building boothWork).
- function settleFarm(st, v, home, party, house, field, prov) {
+ // ---- settling: the move (step 4) ----
+ // The party of site `site` settles on its house in village v: a farmstead whose cottage stands (built at the site, sim/sites), a
+ // household with the provisions as its grain, and the first field its own where it was broken at the site, else its field project
+ // (staked, and cleared, broken and sown from the household: Kim, 27 Nov 2026); the walls' timber left over on its woodpile.
+ function settleFarm(st, v, home, party, house, field, prov, site = null) {
const w = st.w,
settler = st.pawns[party.all[0]];
- const f = makeFarmstead(w, st.farmsteads.length, house, [], v, st.used);
+ const ftr = site ? site.plot.places.find((tr) => tr.kind === 'field') : null,
+ broken = !!ftr && ftr.i >= ftr.steps.length;
+ if (!broken) st.used.delete(field); // the site's mark: the field is the household's project from now
+ const f = makeFarmstead(w, st.farmsteads.length, house, broken ? [field] : [], v, st.used);
+ if (broken && ftr.fresh) f.fields[0].soil = SOIL.fresh; // broken on ground never farmed (VB-149)
f.condition = 1;
f.condAt = st.t;
f.emptySince = null;
- f.booth = true; // no cottage yet: the household lives in its shelter until its cottage has its roof (sim/cottageplan's roofOn)
- siteWell(st, f, v, party.all.length); // a site chosen for the well it means to dig: dug with the booth and the clearing (VB-1587)
+ siteWell(st, f, v, party.all.length); // a site chosen for the well it means to dig (VB-1587)
st.farmsteads.push(f);
v.farmsteads.push(f.id);
- VB['sim/building'].stakeShelter(st, f);
costChanged(st, house); // routes go round the house from now on
// the farm of a village just founded bears the village's name (Erikstorp); one that joins a village is named as a new cottage is
f.name = v.founded && v.farmsteads.length === 1 ? v.name : farmName(st, v, f, settler);
@@ -302,18 +303,22 @@ VB['sim/settle'] = (() => {
piles.push([h, n]);
}
const text = `Left ${home.name} to settle at ${f.name}, ${v.name}`;
+ const wood = site ? Math.min(ECON.woodWinter, Math.max(0, VB['sim/sites'].wallsOf(site).wood || 0)) : 0; // the rest burnt where it lies, as a plot's
+ if (site) VB['sim/sites'].end(st, site); // the site is the farm now: the leader's stake ends, the household's own begin
const hh = foundHousehold(st, f, party.all, settler.id, {
grain,
piles,
text,
followers: party.followers,
+ wood,
carry: false,
- }); // no wood (VB-328)
+ });
woodTaken(st, house);
reckonWood(st, v); // a farm founded: the village's wood is reckoned again (VB-326)
- stake(st, hh, field, 'field'); // the first field is staked till broken (sim/stakes)
- makeProject(st, 'household', hh.id, fieldProject(st, hh, field)); // its project plans (sim/plans, VB-123): the field's,
- makeProject(st, 'household', hh.id, cottagePlan(st, f)); // and its cottage's, built beside it (VB-1411)
+ if (!broken) {
+ stake(st, hh, field, 'field'); // the first field is staked till broken (sim/stakes)
+ makeProject(st, 'household', hh.id, fieldProject(st, hh, field)); // its project plan (sim/plans, VB-123)
+ }
return f;
}
// A new village of one farm on `site`, founded by settler p of village `home`: it keeps the mother village's culture and practice.
@@ -339,7 +344,7 @@ VB['sim/settle'] = (() => {
st.villages.push(v);
makePlan(st, 'village', v.id);
addSettlement(st, v, hs.culture, hs.practice, hs.tie);
- const f = settleFarm(st, v, home, party, site.house, site.field, prov);
+ const f = settleFarm(st, v, home, party, site.house, site.field, prov, site.site || null);
villageAdded(st); // VB-286: its row of the table of walking hours, at once
return f;
}
@@ -377,7 +382,7 @@ VB['sim/settle'] = (() => {
{ from, all, followers, house, field, village } = g;
return issue(st, {
actor: o.from,
- verb: 'leave',
+ verb: 'stakeSite',
args: { from, party: { all, followers }, house, field, ...(village !== undefined ? { village } : {}) },
source: 'round',
});
@@ -405,7 +410,7 @@ VB['sim/settle'] = (() => {
for (const v of [...st.villages]) {
if (!v.crowded) continue;
const ids = [...waiting.get(v.id)],
- taken = new Set(),
+ taken = new Set(ids.filter((id) => Sites.siteOf(st, id))), // a site's party waits for its move, and stakes no other
at = (id) => st.pawns[id];
ids.sort((a, b) => at(b).landWait - at(a).landWait || at(a).born - at(b).born || a - b);
let reach = null,
@@ -429,24 +434,15 @@ VB['sim/settle'] = (() => {
(wish === null && rnd(st.rng.settle) >= leaveChance(p.landWait / act(st, id, 'ambition', 'settle')))
)
continue;
- const party = partyOf(st, p, ids, taken),
- prov = provisions(st, party.all);
- if (!prov) {
- log(st, `${fullName(p)} would leave crowded ${v.name} for new land, but the family cannot spare the grain.`, {
- kind: 'stayed',
- pawn: p.id,
- village: v.id,
- });
- continue;
- }
+ const party = partyOf(st, p, ids, taken); // the provisions are reckoned at the move (step 4), not here
if (!use) use = landInUse(st);
if (!reach) reach = reachOf(st, v);
let f = null,
hours = 0;
- // the call to the party (the basis `party`, due at once: VB-692), whose yes is the leave command; the new farm is the last one
- // added, and its house and field are marked used for the rest of the round
+ // the call to the party (the basis `party`, due at once: VB-692), whose yes is the stakeSite command; the site is the last one
+ // staked, and its house and field are marked used for the rest of the round
const leave = (args) => {
- const n = st.farmsteads.length;
+ const n = st.siteSeq;
issue(st, {
actor: p.id,
verb: 'offer',
@@ -454,9 +450,10 @@ VB['sim/settle'] = (() => {
args: { basis: 'party', gives: { from: v.id, all: party.all, followers: party.followers, ...args } },
source: 'round',
});
- if (st.farmsteads.length === n) return null;
+ const s = Sites.byId(st, n);
+ if (!s) return null;
for (const t of [args.house, args.field]) markUsed(st.w, use, t);
- return st.farmsteads[n];
+ return s;
};
// a small village is not joined unasked: a plot there is asked of its alderman on the asking day (sim/asking, VB-697)
if (!noLand) {
@@ -476,7 +473,6 @@ VB['sim/settle'] = (() => {
}
}
if (!f) continue;
- const nv = st.villages[f.village];
for (const q of party.all) taken.add(q);
const others = party.all.slice(1),
adults = others.filter((q) => st.pawns[q].age >= 18),
@@ -487,13 +483,14 @@ VB['sim/settle'] = (() => {
];
log(
st,
- `${fullName(p)} leaves crowded ${v.name}${company.length ? ` with ${listed(company)}` : ''} and ` +
- `founds ${nv.name}, ${hours.toFixed(1)} hours' walk away along a trail.`,
+ `${fullName(p)} of crowded ${v.name} stakes the site of a new farm${company.length ? ` for ${listed(company)} and itself` : ''}, ` +
+ `${hours.toFixed(1)} hours' walk away along a trail.`,
{
- kind: 'left',
+ kind: 'siteStaked',
pawn: p.id,
n: party.all.length,
- ...atFarm(f),
+ village: v.id,
+ tile: f.house,
},
);
v.crowded = Math.max(0, v.crowded - party.all.filter((q) => ids.includes(q)).length);
@@ -501,30 +498,66 @@ VB['sim/settle'] = (() => {
}
}
}
- // leave({from, party: {all, followers}, house, field, village}): the actor's party leaves village `from` to settle at `house` with its first
- // `field`: in the small village `village` if given, else founding a new one; provisions as the round reckons them
- register('leave', {
- check: (st, c) => {
- const a = c.args || {};
- if (!st.villages[a.from]) return `there is no village ${a.from}`;
- if (!a.party || !Array.isArray(a.party.all) || a.party.all[0] !== c.actor)
- return 'the party must be led by the actor';
- for (const id of a.party.all) {
- const dead = living(st, id);
- if (dead) return dead;
- }
- if (![a.house, a.field].every((t) => Number.isInteger(t) && t >= 0 && t < st.w.N))
- return 'the house and field must be tiles';
- if (a.village !== undefined && !st.villages[a.village]) return `there is no village ${a.village}`;
- return provisions(st, a.party.all) ? null : 'the family cannot spare the grain';
+ // Why the party `party` of village `from` cannot stake a site at `house` with its first `field` (args as stakeSite's), or null.
+ function stakeWhy(st, c) {
+ const a = c.args || {};
+ if (!st.villages[a.from]) return `there is no village ${a.from}`;
+ if (!a.party || !Array.isArray(a.party.all) || a.party.all[0] !== c.actor)
+ return 'the party must be led by the actor';
+ for (const id of a.party.all) {
+ const dead = living(st, id);
+ if (dead) return dead;
+ if (Sites.siteOf(st, id)) return `${fullName(st.pawns[id])} is of a party with a site already`;
+ }
+ if (![a.house, a.field].every((t) => Number.isInteger(t) && t >= 0 && t < st.w.N))
+ return 'the house and field must be tiles';
+ if (st.used.has(a.house) || st.used.has(a.field)) return 'the site is taken';
+ if (a.village !== undefined && !st.villages[a.village]) return `there is no village ${a.village}`;
+ return null;
+ }
+ // stakeSite({from, party: {all, followers}, house, field, village}) (VB-787; design.md, Settling in steps, 1): the actor stakes the site
+ // of its party's new farm, in the small village `village` if given, else a new one: nobody moves, no grain is taken, no household or
+ // village is made (sim/sites: the site, its stake and its trail).
+ register('stakeSite', {
+ check: stakeWhy,
+ run: (st, c) => {
+ Sites.stakeSite(st, c.args);
},
+ });
+ // Why the leader of site `sid` cannot move its party there, or null: its cottage has its roof, and the provisions are there.
+ function leaveWhy(st, c) {
+ const s = Sites.byId(st, c.target);
+ if (!s) return `there is no site ${c.target}`;
+ if (s.leader !== c.actor) return 'the party must be led by the actor';
+ if (!Sites.roofed(s)) return 'its cottage has no roof yet';
+ for (const id of s.party.all) {
+ const dead = living(st, id);
+ if (dead) return dead;
+ }
+ return provisions(st, s.party.all) ? null : 'the family cannot spare the grain';
+ }
+ // leave(site) (VB-787; design.md, Settling in steps, 4): the leader moves its party to the site's finished cottage: the household is
+ // founded with it as head, and the village where the site is a new one; provisions to the harvest and seed, as the round reckoned them.
+ register('leave', {
+ check: leaveWhy,
run: (st, c) => {
- const a = c.args,
- home = st.villages[a.from],
- party = { all: a.party.all, followers: a.party.followers || [] };
- const prov = provisions(st, party.all);
- if (a.village !== undefined) settleFarm(st, st.villages[a.village], home, party, a.house, a.field, prov);
- else found(st, home, st.pawns[c.actor], party, { house: a.house, field: a.field }, prov);
+ const s = Sites.byId(st, c.target),
+ home = st.villages[s.from],
+ party = { all: s.party.all, followers: s.party.followers },
+ prov = provisions(st, party.all),
+ p = st.pawns[c.actor],
+ n = st.farmsteads.length;
+ if (s.village !== null) settleFarm(st, st.villages[s.village], home, party, s.house, s.field, prov, s);
+ else found(st, home, p, party, { house: s.house, field: s.field, site: s }, prov);
+ const f = st.farmsteads[n],
+ nv = st.villages[f.village];
+ const others = party.all.length - 1 ? ` with ${party.all.length - 1} more` : '';
+ log(st, `${fullName(p)} moves from ${home.name}${others} into the new cottage of ${f.name}, ${nv.name}.`, {
+ kind: 'left',
+ pawn: p.id,
+ n: party.all.length,
+ ...atFarm(f),
+ });
},
});
return {
diff --git a/src/sim/sites.js b/src/sim/sites.js
new file mode 100644
index 00000000..4575b0e2
--- /dev/null
+++ b/src/sim/sites.js
@@ -0,0 +1,340 @@
+// @sys sim/sites: a party's site of a new farm (VB-787; design.md, Moving to new land, Settling in steps): staked at the moving round, its
+// house tile and first field cleared and its cottage built by the party's members from their old households, until the move founds the
+// household (sim/settle's verb leave); the site's jobs, their ends, the leader's stake on its tiles, and the leader who follows a dead one
+VB['sim/sites'] = (() => {
+ const { on } = VB['sim/events'];
+ const { issue } = VB['sim/commands'];
+ const { log, fullName, isHolder, spouseOf, childrenOf } = VB['sim/records'];
+ const { ECON, BUILD } = VB['sim/rules'];
+ const CL = VB['sim/claims'];
+ const { keptDone } = VB['sim/progress'];
+ const { costChanged } = VB['sim/routes'];
+ const { clearTile, fellAll } = VB['sim/forest'];
+ const { clearScrub, tended } = VB['sim/spread'];
+ const { woodTaken } = VB['sim/territory'];
+ const { stepsFor, stepHours } = VB['sim/expansion'];
+ const { COTTAGE, cottageSteps, waitsForTimber } = VB['sim/cottageplan'];
+ const { fetchTimber } = VB['sim/building'];
+ const { trailOf } = VB['sim/trails'];
+ const { bfs } = VB['sim/hex'];
+ const { walkable } = VB['sim/walking'];
+ // @state st.sites[]: the sites under way, one a party, in the order staked (by id), each {id, leader (the pawn whose stake it is), party
+ // {all (the leader first), followers}, from (the village it was staked from), village (the small village it joins, or null: a new one),
+ // house, field (tiles), plot {places: [{tile, kind 'house' | 'field', steps (fell, grub, clear, break), i, fresh}], steps (the
+ // cottage's stages at the house, as a plot's: {kind, place, hours, done}, the walls also `wood`), open (the stage under way, 3 once the
+ // roof is on)}, booth (the tile beside the house where its workers lodge and raise their booth, or null), stage ('trail' while the
+ // leader's trail to it is blazed, 'building', 'roofed'), since (game hours), hours ({pawn: hours worked at it}), told (the season the
+ // log last said why the move waits, or absent), tried ({pawn: day it last set out to lodge there, or found it could not})};
+ // st.siteSeq, the next id. Written here (staked, worked, its leader followed, given up) and by sim/settle (staked by the verb
+ // stakeSite, ended by the move). The stake on its tiles is the leader's claim (sim/claims, holder {type: 'pawn'}), renewed by each step.
+ // The live index, pawn id -> its site, of the parties' members: kept beside st.sites and made again when st.sites is another array (a
+ // load, a new state). Not saved.
+ const IX = new WeakMap();
+ function index(st) {
+ let x = IX.get(st);
+ if (!x || x.of !== st.sites) {
+ x = { of: st.sites, by: new Map() };
+ for (const s of st.sites || []) for (const id of s.party.all) x.by.set(id, s);
+ IX.set(st, x);
+ }
+ return x.by;
+ }
+ const siteOf = (st, id) => (st.sites && st.sites.length ? index(st).get(id) || null : null);
+ const byId = (st, id) => (st.sites || []).find((s) => s.id === id) || null;
+ const leaderClaim = (s) => ({ type: 'pawn', id: s.leader });
+ const ownerOf = (st, s) => {
+ const p = st.pawns[s.leader];
+ return p.household === null ? null : { type: 'household', id: p.household };
+ };
+ // ---- staking ----
+ // A site staked by the party's leader (sim/settle's verb stakeSite): its tiles marked used and staked by the leader, the house's ground
+ // developed (routes go round it), its booth's tile beside the house, and the leader's trail from the home green (VB-447's verb blaze;
+ // none where no wood lies between). The site.
+ function stakeSite(st, a) {
+ const w = st.w,
+ leader = a.party.all[0],
+ s = {
+ id: st.siteSeq++,
+ leader,
+ party: { all: [...a.party.all], followers: [...(a.party.followers || [])] },
+ from: a.from,
+ village: a.village === undefined ? null : a.village,
+ house: a.house,
+ field: a.field,
+ plot: {
+ places: [
+ { tile: a.house, kind: 'house' },
+ { tile: a.field, kind: 'field' },
+ ].map((tr) => ({ ...tr, steps: stepsFor(w, tr.tile, tr.kind), i: 0 })),
+ steps: cottageSteps(a.house),
+ open: 0,
+ },
+ booth: boothTile(st, a.house, a.field),
+ stage: 'building',
+ since: st.t,
+ hours: {},
+ tried: {},
+ };
+ for (const t of [s.house, s.field]) {
+ st.used.add(t);
+ woodTaken(st, t);
+ CL.addClaim(st, t, leaderClaim(s), 'site');
+ }
+ w.dev[s.house] = 3;
+ costChanged(st, s.house);
+ st.sites.push(s);
+ index(st).set(leader, s);
+ for (const id of s.party.all) index(st).set(id, s);
+ const home = st.villages[s.from].center;
+ if (issue(st, { actor: leader, verb: 'blaze', args: { from: home, to: s.house }, source: 'pawn' }) === true)
+ s.stage = 'trail';
+ st.villageDirty.add(s.from);
+ return s;
+ }
+ // The booth's tile: the nearest open tile beside the house that is not the field, nobody's, unused. Null where there is none.
+ function boothTile(st, house, field) {
+ const w = st.w;
+ for (let k = 0; k < 6; k++) {
+ const t = w.nb[house * 6 + k];
+ if (t < 0 || t === field || w.water[t] || st.used.has(t) || st.owner[t] !== 0 || st.claims.has(t)) continue;
+ if (walkable(w)(t)) return t;
+ }
+ return null;
+ }
+ // ---- the work ----
+ // The hours still to work at site s: its tiles' open steps and the cottage's stages.
+ function hoursLeft(st, s) {
+ let h = 0;
+ for (const tr of s.plot.places) for (let i = tr.i; i < tr.steps.length; i++) h += stepHours(st, { ...tr, i });
+ for (let i = s.plot.open; i < s.plot.steps.length; i++) h += s.plot.steps[i].hours - (s.plot.steps[i].done || 0);
+ return h;
+ }
+ const houseCleared = (s) => s.plot.places[0].i >= s.plot.places[0].steps.length;
+ const roofed = (s) => s.plot.open >= COTTAGE.length;
+ const wallsOf = (s) => s.plot.steps[COTTAGE.indexOf('walls')];
+ // The keys of site s's jobs, the ones a lodger there is away for (sim/away): its tiles' steps, the cottage's stage, the timber trips.
+ const jobKeys = (s) => [
+ `site:s${s.id}.${s.house}`,
+ `site:s${s.id}.${s.field}`,
+ `site:s${s.id}.cottage`,
+ `timber:s${s.id}`,
+ `timber:s${s.id}b`,
+ ];
+ // Whether member id of site s works there: of 14 and over, and not a mother who nurses (design.md, Settling in steps, 3).
+ const worksAt = (st, s, id) => {
+ const p = st.pawns[id];
+ return p.alive && p.age >= 14 && !(p.nursingUntil > st.t);
+ };
+ // The nearest tile with trees within 4 steps of the house, for the walls' timber where the site's own felling gave too little.
+ function woodFor(st, s) {
+ for (const [t] of bfs(st.w, s.house, 4, walkable(st.w)).dist) if (st.w.trees[t] > 0 && !st.used.has(t)) return t;
+ return null;
+ }
+ // The sites' work, asked once for the island (Rules for cost, 1: the live sites only, at most six jobs each): for each site past its
+ // trail, the open step of each of its tiles (side by side), then, once the house tile is cleared, the cottage's open stage, its walls
+ // waiting for their timber (felled on the site, else fetched from the nearest wood). Owned by the leader's household, whose members of the
+ // party take them (j.party, sim/fit). A site whose leader is dead passes to the party's next adult, or is given up.
+ function siteWork(st, holder, at, c, post) {
+ if (!st.sites || !st.sites.length) return;
+ for (const s of [...st.sites]) {
+ if (!prune(st, s)) continue;
+ const owner = ownerOf(st, s);
+ if (!owner || s.stage === 'roofed') continue;
+ if (s.stage === 'trail') {
+ if (trailOf(st, s.leader)) continue;
+ s.stage = 'building';
+ log(st, `${fullName(st.pawns[s.leader])}'s trail to the site of a new farm is blazed.`, {
+ kind: 'siteTrail',
+ pawn: s.leader,
+ village: s.from,
+ });
+ }
+ const base = { siteId: s.id, party: s.party.all };
+ for (const tr of s.plot.places)
+ if (tr.i < tr.steps.length)
+ post(`site:s${s.id}.${tr.tile}`, tr.tile, { ...base, tr, hours: stepHours(st, tr) }, tr.steps[tr.i], owner);
+ if (!houseCleared(s)) continue;
+ const k = s.plot.steps[s.plot.open],
+ key = `site:s${s.id}.cottage`;
+ if (waitsForTimber(wallsOf(s), s.plot.open)) {
+ const fell = st.w.trees[s.house] > 0 ? s.house : woodFor(st, s);
+ const n = { key: `timber:s${s.id}`, site: wallsOf(s), need: BUILD.timber, dest: s.house, owner };
+ if (fell !== null) n.fell = fell;
+ fetchTimber(st.villages[s.from], n, post);
+ continue;
+ }
+ k.done = keptDone(st, key, k.hours, k.done);
+ post(key, s.house, { ...base, cottage: true, done: k.done, hours: k.hours }, k.kind, owner);
+ }
+ }
+ // A step of site j.siteId is done: a tile's (stumps after felling, the trees the walls' wood; grubbing turns the wood to meadow;
+ // clearing takes the stones; breaking turns the soil), or the cottage's stage (the walls take their timber; after the roof the move is
+ // tried, the leader's verb leave). Each renews the leader's stake.
+ function finish(st, j) {
+ const s = byId(st, j.siteId);
+ if (!s) return;
+ const w = st.w;
+ if (j.cottage) {
+ const k = s.plot.steps[s.plot.open];
+ if (!k || k.kind !== j.kind) return;
+ if (k.kind === 'walls') k.wood -= BUILD.timber;
+ k.done = k.hours;
+ s.plot.open++;
+ CL.renewClaim(st, s.house, leaderClaim(s));
+ st.biomeDirty.add(s.house);
+ st.villageDirty.add(s.from);
+ if (!roofed(s)) return;
+ s.stage = 'roofed';
+ log(st, `The cottage at the site of ${fullName(st.pawns[s.leader])}'s new farm has its roof.`, {
+ kind: 'siteRoofed',
+ pawn: s.leader,
+ village: s.from,
+ });
+ tryMove(st, s);
+ return;
+ }
+ const tr = j.tr;
+ if (!tr || tr.i >= tr.steps.length || s.plot.places.indexOf(tr) < 0) return;
+ const step = tr.steps[tr.i];
+ const walls = wallsOf(s);
+ if (step === 'fell')
+ walls.wood += fellAll(st, tr.tile) * ECON.woodPerTrip; // the trees felled are the walls' (VB-328)
+ else if (step === 'grub') clearTile(st, tr.tile);
+ else if (step === 'clear') {
+ w.stones[tr.tile] = 0;
+ clearScrub(st, tr.tile);
+ } else {
+ tr.fresh = !w.dev[tr.tile];
+ w.dev[tr.tile] = 1;
+ if (tr.fresh) costChanged(st, tr.tile);
+ }
+ tended(st, tr.tile);
+ tr.i++;
+ CL.renewClaim(st, tr.tile, leaderClaim(s));
+ st.biomeDirty.add(tr.tile);
+ st.villageDirty.add(s.from);
+ }
+ // The move is tried (the verb leave, its check the provisions): when the roof's job ends, and on the leader's household's planning day.
+ // Short of it, the log says why once a season.
+ function tryMove(st, s) {
+ if (!roofed(s) || !prune(st, s)) return;
+ const r = issue(st, { actor: s.leader, verb: 'leave', target: s.id, source: 'pawn' });
+ if (r === true || typeof r !== 'string') return;
+ const season = Math.floor(st.t / (VB['sim/rules'].DAY * VB['sim/rules'].SEASON_DAYS));
+ if (s.told === season) return;
+ s.told = season;
+ log(st, `${fullName(st.pawns[s.leader])}'s new cottage stands, but the move waits: ${r}.`, {
+ kind: 'siteWaits',
+ pawn: s.leader,
+ village: s.from,
+ });
+ }
+ on('planReviewed', (st, d) => {
+ if (d.why !== 'day' || d.plan.holder.type !== 'household' || !st.sites || !st.sites.length) return;
+ for (const s of st.sites)
+ if (s.stage === 'roofed' && st.pawns[s.leader].household === d.plan.holder.id) {
+ tryMove(st, s);
+ return;
+ }
+ });
+ // Whether pawn id stays in a site's party: alive, holding no household, nor married to one who holds one (a member who has taken a
+ // farm since the stake, or married into one, stays there; VB-787's gate, populous 11: a holder who left with a party left its household
+ // without its head).
+ const stays = (st, id) => {
+ if (!st.pawns[id].alive || isHolder(st, id)) return false;
+ const sp = spouseOf(st, id);
+ return sp === null || !isHolder(st, sp);
+ };
+ // Site s's party without those who no longer stay, and their children under 18 with them; its leader gone, the next adult leads
+ // (follow). Whether the site goes on.
+ function prune(st, s) {
+ if (s.party.all.every((id) => stays(st, id))) return true;
+ const gone = new Set(s.party.all.filter((id) => !stays(st, id)));
+ for (const id of [...gone]) for (const c of childrenOf(st, id)) if (st.pawns[c].age < 18) gone.add(c);
+ s.party.followers = s.party.followers.filter((id) => !gone.has(id));
+ const leaderGone = gone.has(s.leader);
+ s.party.all = s.party.all.filter((id) => !gone.has(id) || (leaderGone && id === s.leader));
+ IX.delete(st);
+ return !leaderGone || follow(st, s);
+ }
+ // The leader of site s has died, or no longer stays: the party's next adult living leads, the stake passing to it; with none, the site is given up.
+ function follow(st, s) {
+ s.party.all = s.party.all.filter((id) => id !== s.leader && stays(st, id));
+ s.party.followers = s.party.followers.filter((id) => stays(st, id));
+ const next = s.party.all.find((id) => st.pawns[id].age >= 18 && st.pawns[id].household !== null);
+ const old = leaderClaim(s);
+ if (next === undefined) {
+ end(st, s, 'nobody of the party is left to lead it');
+ return false;
+ }
+ s.leader = next;
+ s.party.all = [next, ...s.party.all.filter((id) => id !== next)];
+ s.party.followers = s.party.followers.filter((id) => id !== next);
+ for (const t of [s.house, s.field]) {
+ CL.dropClaim(st, t, old);
+ CL.addClaim(st, t, leaderClaim(s), 'site');
+ }
+ IX.delete(st);
+ log(st, `${fullName(st.pawns[next])} now leads the party building a new farm.`, {
+ kind: 'siteLeader',
+ pawn: next,
+ village: s.from,
+ });
+ return true;
+ }
+ // Site s ends (moved into, or given up): out of st.sites and the index, the leader's stake dropped; given up (`why`), its tiles are left
+ // as they stand, unused, for the next party that searches (the endings are VB-789's).
+ function end(st, s, why = null) {
+ for (const t of [s.house, s.field]) CL.dropClaim(st, t, leaderClaim(s));
+ st.sites.splice(st.sites.indexOf(s), 1);
+ IX.delete(st);
+ if (why === null) return;
+ for (const t of [s.house, s.field]) st.used.delete(t);
+ log(st, `The site of a new farm from ${st.villages[s.from].name} is given up: ${why}.`, {
+ kind: 'siteGivenUp',
+ village: s.from,
+ });
+ }
+ // A site's steps are kinds of their own (sim/expansion's fell, grub, clear and break, sim/building's cottage stages): a job of a site
+ // (`j.siteId`) ends in finish, any other as its kind says. sim/kinds joins these, after sim/expansion's plotted.
+ const SITE_KINDS = ['fell', 'grub', 'clear', 'break', ...COTTAGE];
+ const sited = (KINDS) =>
+ Object.fromEntries(
+ SITE_KINDS.map((k) => {
+ const own = KINDS[k].done;
+ return [
+ k,
+ {
+ ...KINDS[k],
+ done: (st, j, hh, c, by) => (j.siteId !== undefined ? finish(st, j) : own && own(st, j, hh, c, by)),
+ },
+ ];
+ }),
+ );
+ // Hours worked at site j.siteId by pawn id (sim/work), its record's.
+ function worked(st, j, id, dt) {
+ const s = byId(st, j.siteId);
+ if (s) s.hours[id] = (s.hours[id] || 0) + dt;
+ }
+ // A save from before the sites (VB-787): none under way.
+ function sitesLoaded(st) {
+ st.sites ??= [];
+ st.siteSeq ??= 0;
+ }
+ return {
+ worked,
+ sitesLoaded,
+ siteOf,
+ byId,
+ stakeSite,
+ siteWork,
+ sited,
+ hoursLeft,
+ jobKeys,
+ worksAt,
+ roofed,
+ end,
+ tryMove,
+ wallsOf,
+ };
+})();
diff --git a/src/sim/work.js b/src/sim/work.js
index 543487de..9fb48bdb 100644
--- a/src/sim/work.js
+++ b/src/sim/work.js
@@ -127,6 +127,7 @@ VB['sim/work'] = (() => {
if (!atWork(st, j, id)) continue;
if (K.worked) K.worked(st, j, dt, st.agents[id], from);
if (j.plot) j.plot.hours[id] = (j.plot.hours[id] || 0) + dt;
+ if (j.siteId !== undefined) VB['sim/sites'].worked(st, j, id, dt); // hours worked at a site (VB-787)
countWork(st, id, dt, t);
if (K.craft) Skills.practise(st, id, K.craft, dt); // hours at a craft raise the hand's skill at it (VB-360)
if (j.field && j.farm) bookHours(j.field, st.pawns[id].household === j.farm.household, dt); // VB-462: the class reads it
diff --git a/tests/caches.js b/tests/caches.js
index e5420fde..cff4fd3a 100644
--- a/tests/caches.js
+++ b/tests/caches.js
@@ -79,7 +79,7 @@ assert.deepStrictEqual(failures, [], 'a cache differs from its derivation after
// The list only shrinks: a verb carried here is struck from it, a new verb is carried or added.
const NOT_YET = ['answer', 'claim', 'letIn', 'placeFarmstead', 'blaze', 'lodge', 'comeHome', 'goGathering', 'stayHome', 'swap',
'target', 'tile', 'order', 'letField', 'sowOutOfTurn', 'courses', 'dayOrder', 'assign', 'call', 'handOn', 'plotToVillage',
- 'beginCottage', 'goBack', 'goToKin', 'visit', 'sendVisit', 'foundHousehold', 'decide', 'argue', 'dropCause', 'rally', 'leave', 'takeUp',
+ 'beginCottage', 'goBack', 'goToKin', 'visit', 'sendVisit', 'foundHousehold', 'decide', 'argue', 'dropCause', 'rally', 'leave', 'stakeSite', 'takeUp',
'renounce', 'marry', 'skip', 'slander',
'wish', 'match', 'found', 'upkeep',
'substitute', 'commute', 'transfer', 'forgive']; // VB-1769 (release carried since VB-1768's routines): the ladder's verbs, carried by tests/levies.js // VB-361: no facility kind is declared in the game yet (each craft's task declares its own); tests/facilities.js carries both
diff --git a/tests/commands.js b/tests/commands.js
index f85d6ffe..e2042d9b 100644
--- a/tests/commands.js
+++ b/tests/commands.js
@@ -196,7 +196,7 @@ assert.ok(S3.provisions(st3, [settler.id]), 'provisions for the settler');
const fromV = st3.villages[Sim.settlementIdOf(st3, settler)], use3 = S3.landInUse(st3), site3 = S3.newSite(st3, fromV, use3, S3.candidates(st3, fromV, use3, S3.reachOf(st3, fromV)));
if (site3) {
const nf = st3.farmsteads.length, nv = st3.villages.length, party = { all: [settler.id], followers: [] };
- assert.strictEqual(issue(st3, { actor: settler.id, verb: 'leave', args: { from: fromV.id, party, house: site3.house, field: site3.field, wood: site3.wood }, source: 'round' }), true);
+ assert.strictEqual(require('./lib/settled.js')(VB, st3, settler.id, { from: fromV.id, party, house: site3.house, field: site3.field }), true);
assert.strictEqual(st3.farmsteads.length, nf + 1); assert.strictEqual(st3.villages.length, nv + 1);
assert.strictEqual(st3.households[settler.household].farmstead, nf, 'the settler lives on the new farm');
R3.push(['leave', 1]);
@@ -220,9 +220,9 @@ const before5 = snap3(), lead = st3.pawns.find((p) => p.died === null && p.age >
for (const [cmd, why] of [
[{ actor: lead.id, verb: 'foundHousehold', target: 99999, args: { members: [lead.id], grain: 0 } }, /empty farm/],
[{ actor: null, verb: 'finishCottage', target: 99999, args: { village: 0 } }, /finished cottage/],
- [{ actor: lead.id, verb: 'leave', args: { from: 999, party: { all: [lead.id] }, house: 0, field: 1 } }, /no village/],
- [{ actor: lead.id, verb: 'leave', args: { from: 0, party: { all: [dead.id] }, house: 0, field: 1 } }, /led by the actor/],
- [{ actor: lead.id, verb: 'leave', args: { from: 0, party: { all: [lead.id] }, house: -5, field: 1 } }, /must be tiles/],
+ [{ actor: lead.id, verb: 'stakeSite', args: { from: 999, party: { all: [lead.id] }, house: 0, field: 1 } }, /no village/],
+ [{ actor: lead.id, verb: 'stakeSite', args: { from: 0, party: { all: [dead.id] }, house: 0, field: 1 } }, /led by the actor/],
+ [{ actor: lead.id, verb: 'stakeSite', args: { from: 0, party: { all: [lead.id] }, house: -5, field: 1 } }, /must be tiles/],
]) { const res = issue(st3, { source: 'debug', ...cmd }); assert.ok(typeof res === 'string' && why.test(res), `${JSON.stringify(cmd)}: ${res}`); R3.push(['leave refusal', 1]); }
assert.strictEqual(snap3(), before5, 'refused leave commands change nothing');
// VB-681: a verb's check holds for any pawn; the sources are one list, and the world's verbs are debug's only
diff --git a/tests/forestsites.js b/tests/forestsites.js
index 36c12b0b..309480b5 100644
--- a/tests/forestsites.js
+++ b/tests/forestsites.js
@@ -46,23 +46,26 @@ const wooded = (w, t) => w.biome[t] === B.FOREST || w.biome[t] === B.PINE;
st.demand = [m.id]; m.landWait = 3; m.stake = 300;
const n = st.villages.length, farms = st.farmsteads.length;
roll(st, () => S.settleRound(st));
- check(st.villages.length === n + 1, `a village is founded in the forest (${st.villages.length - n})`);
- const f = st.farmsteads[farms], hh = f && st.households[f.household];
- if (f && hh) {
- const plans = Projects.projectsOf(st, 'household', hh.id), field = plans.find((p) => p.what === 'field'), home = plans.find((p) => p.what === 'cottage');
- const fieldTile = field && field.steps[field.steps.length - 1].place;
- check(wooded(w, f.house) && fieldTile !== undefined && wooded(w, fieldTile), 'the house and the first field stand on wooded tiles');
- check(field && field.steps.map((s) => s.kind).join() === 'fell,grub,clear,break', `the field is felled, grubbed, cleared and broken (${field && field.steps.map((s) => s.kind)})`);
- check(home && home.steps.map((s) => s.kind).join() === 'fell,grub,foundation,walls,roof', `the house tile is felled and grubbed before the foundation (${home && home.steps.map((s) => s.kind)})`);
- const hours = VB['sim/villagehours'].hoursBetween(st, v.id, f.village);
- check(st.record.some((e) => e.kind === 'left' && /hours' walk away along a trail/.test(e.text)), 'the log tells the hours along the trail');
- let bad = checkState(st); check(!bad.length, `invariants after founding: ${bad.slice(0, 3).join('; ')}`);
- let grubbed = null, broken = null, built = null;
+ // VB-787: the round stakes the site, its tiles cleared and its cottage built by the party before the move founds the village
+ const site = st.sites[0];
+ check(!!site && st.villages.length === n, `a site is staked in the forest, nothing founded yet (${st.sites.length})`);
+ if (site) {
+ const fieldTile = site.field, house = site.house, steps = (k) => site.plot.places.find((tr) => tr.kind === k).steps.join();
+ check(wooded(w, house) && wooded(w, fieldTile), 'the house and the first field stand on wooded tiles');
+ check(steps('field') === 'fell,grub,clear,break', `the field is felled, grubbed, cleared and broken (${steps('field')})`);
+ check(steps('house') === 'fell,grub,clear', `the house tile is felled and grubbed before the foundation (${steps('house')})`);
+ check(st.record.some((e) => e.kind === 'siteStaked' && /hours' walk away along a trail/.test(e.text)), 'the log tells the hours along the trail');
+ let bad = checkState(st); check(!bad.length, `invariants at the stake: ${bad.slice(0, 3).join('; ')}`);
+ let grubbed = null, broken = null, built = null, f = null, hours = 0;
for (let d = 0; d < 2 * Sim.YEAR_DAYS && (broken === null || built === null); d++) {
Sim.advance(st, 24);
- if (grubbed === null && w.biome[f.house] === B.MEADOW) grubbed = d;
- if (built === null && !f.booth) built = d;
- if (broken === null && f.fields.length) {
+ if (grubbed === null && w.biome[house] === B.MEADOW) grubbed = d;
+ if (built === null && !st.sites.includes(site)) {
+ built = d;
+ f = st.farmsteads[farms];
+ hours = VB['sim/villagehours'].hoursBetween(st, v.id, f.village);
+ }
+ if (broken === null && f && f.fields.length) {
broken = d;
const fd = f.fields.find((x) => x.tile === fieldTile);
check(fd && fd.soil === SOIL.fresh && w.biome[fieldTile] === B.MEADOW, `the field broken on the forest is fresh land (${fd && fd.soil})`);
diff --git a/tests/green.js b/tests/green.js
index 3239e175..721ccefc 100644
--- a/tests/green.js
+++ b/tests/green.js
@@ -56,7 +56,7 @@ st.households[settler.household].grain.barley += 2000; // a family that can spar
const site = X.findSite(st, v);
assert.ok(site, 'room to settle beside the lone farm');
const party = { all: [settler.id], followers: [] };
-assert.strictEqual(issue(st, { actor: settler.id, verb: 'leave', args: { from: home.id, village: v.id, party, house: site.house, field: site.field }, source: 'round' }), true);
+assert.strictEqual(require('./lib/settled.js')(VB, st, settler.id, { from: home.id, village: v.id, party, house: site.house, field: site.field }), true);
const joined = st.t, oldCentre = v.center;
assert.strictEqual(Green.houses(st, v).length, 2, 'two occupied farms');
assert.ok(VB['sim/routines'].VILLAGE_ROUTINES.green.available(st, v) && VB['sim/routines'].chooseRoutines(st, v).includes('green'), 'the meeting may choose it');
diff --git a/tests/lib/invariants.js b/tests/lib/invariants.js
index 93ed6359..149d1ba8 100644
--- a/tests/lib/invariants.js
+++ b/tests/lib/invariants.js
@@ -2489,7 +2489,7 @@ function checkState(st) {
// claims on tiles (sim/claims, VB-042): valid tiles and claimants, no claimant twice on a tile, strengths in 0..1, no empty lists
if (st.claims) {
const CL = VB['sim/claims'],
- WHY = ['outland', 'field', 'meadow', 'farm', 'birthright'];
+ WHY = ['outland', 'field', 'meadow', 'farm', 'birthright', 'site'];
const exists = (by) =>
by.type === 'pawn'
? !!st.pawns[by.id]
@@ -2522,6 +2522,12 @@ function checkState(st) {
`claims[${tile}]: ${k} birthright is ${c.state} on ${f ? `a farm held by ${f.household}` : 'no farm'}`,
);
}
+ if (c.why === 'site') {
+ // a leader's stake on its site's tiles (VB-787)
+ const site = (st.sites || []).find((x) => x.leader === c.by.id && (x.house === tile || x.field === tile));
+ if (c.by.type !== 'pawn' || !site || c.state !== 'unrealised')
+ bad.push(`claims[${tile}]: ${k} stakes a site that is not its own`);
+ }
if (c.why === 'farm') {
// a pawn's claim on the house of the empty farm it is restoring (VB-033)
const f = st.farmsteads.find((x) => x.house === tile);
@@ -2543,6 +2549,39 @@ function checkState(st) {
}
}
}
+ // the sites of new farms under way (VB-787): ids below st.siteSeq, in order; a living leader first of its party, every member alive and
+ // of one site only; its two tiles used and staked by the leader; its stage as its work; the index (sim/sites siteOf) as the parties
+ if (st.sites !== undefined) {
+ const Sites = VB['sim/sites'],
+ member = new Map(),
+ STAGES = ['trail', 'building', 'roofed'];
+ st.sites.forEach((x, n) => {
+ const at = `sites[${n}] (id ${x.id})`;
+ if (!Number.isInteger(x.id) || x.id >= st.siteSeq || (n > 0 && st.sites[n - 1].id >= x.id))
+ bad.push(`${at}: id against siteSeq ${st.siteSeq}`);
+ if (x.party.all[0] !== x.leader || !st.pawns[x.leader] || !st.villages[x.from])
+ bad.push(`${at}: its leader ${x.leader} is not first of its party`);
+ if (x.village !== null && !st.villages[x.village]) bad.push(`${at}: no village ${x.village} to join`);
+ for (const id of x.party.all) {
+ if (member.has(id)) bad.push(`${at}: pawn ${id} is of two sites`);
+ member.set(id, x);
+ if (Sites.siteOf(st, id) !== x) bad.push(`${at}: the index does not give pawn ${id} its site`);
+ }
+ if (!x.party.followers.every((id) => x.party.all.includes(id))) bad.push(`${at}: a follower outside its party`);
+ for (const t of [x.house, x.field]) if (!st.used.has(t)) bad.push(`${at}: tile ${t} is not marked used`);
+ if (st.pawns[x.leader].alive)
+ for (const t of [x.house, x.field])
+ if (!(st.claims.get(t) || []).some((c) => c.by.type === 'pawn' && c.by.id === x.leader && c.why === 'site'))
+ bad.push(`${at}: tile ${t} not staked by its leader`);
+ if (!STAGES.includes(x.stage) || (x.stage === 'roofed') !== Sites.roofed(x))
+ bad.push(`${at}: stage ${x.stage} against its cottage's ${x.plot.open}`);
+ if (
+ !(x.plot.open >= 0 && x.plot.open <= 3) ||
+ x.plot.places.some((tr) => !(tr.i >= 0 && tr.i <= tr.steps.length))
+ )
+ bad.push(`${at}: its steps out of range`);
+ });
+ }
// cairns on settled borders (VB-157): a valid tile, two different villages, set in the past
for (const [tile, c] of st.cairns || []) {
if (!tileOk(tile) || !st.villages[c.a] || !st.villages[c.b] || c.a === c.b || !(c.t <= st.t))
diff --git a/tests/lib/settled.js b/tests/lib/settled.js
new file mode 100644
index 00000000..986090aa
--- /dev/null
+++ b/tests/lib/settled.js
@@ -0,0 +1,17 @@
+// A party settled at once (VB-787): the verb stakeSite, the site's work done as if worked (its tiles cleared and broken, its cottage
+// roofed), then the verb leave. The leave's answer (true, or why not), or the stake's refusal.
+module.exports = function settleNow(VB, st, actor, args) {
+ const { issue } = VB['sim/commands'], Sites = VB['sim/sites'];
+ const n = st.siteSeq,
+ r = issue(st, { actor, verb: 'stakeSite', args, source: 'round' });
+ if (r !== true) return r;
+ const s = Sites.byId(st, n);
+ for (const tr of s.plot.places) {
+ tr.i = tr.steps.length;
+ if (tr.kind === 'field') st.w.dev[tr.tile] = 1; // broken, as the site's last step leaves it
+ }
+ for (const k of s.plot.steps) k.done = k.hours;
+ s.plot.open = s.plot.steps.length;
+ s.stage = 'roofed';
+ return issue(st, { actor, verb: 'leave', target: s.id, source: 'pawn' });
+};
diff --git a/tests/settle.js b/tests/settle.js
index 6d26a1a8..80183b8c 100644
--- a/tests/settle.js
+++ b/tests/settle.js
@@ -56,6 +56,9 @@ fill(st, v);
st.demand = [m.id, sib.id]; m.landWait = 2; sib.landWait = 2; m.stake = 300;
const villages = st.villages.length, farms = st.farmsteads.length, households = st.households.length, oldHh = m.household;
roll(st, () => S.settleRound(st));
+// VB-787: the round stakes the site; the party builds it from home and moves when its cottage has its roof
+check(st.sites.length === 1 && st.villages.length === villages && m.household === oldHh, 'a site is staked, and nobody moves yet');
+for (let d = 0; d < 2 * Sim.YEAR_DAYS && st.sites.length; d++) Sim.advance(st, 24);
check(st.villages.length === villages + 1, `a village is founded (${st.villages.length - villages})`);
const nv = st.villages[st.villages.length - 1], f = st.farmsteads[farms], hh = st.households[households];
check(nv && nv.founded && nv.founded.from === v.id && nv.founded.by === m.id, `founded from ${v.name} by the settler (${JSON.stringify(nv.founded)})`);
@@ -65,9 +68,9 @@ check(nv && nv.founded && nv.founded.from === v.id && nv.founded.by === m.id, `f
}
const trail = VB['sim/routes'].trailReach(st.w, v.center, SETTLE.hours * SPEED).get(nv.center) / SPEED;
check(trail <= SETTLE.hours && VB['sim/hex'].hexSteps(st.w, v.center, nv.center) >= SETTLE.centreApart, `the new village is ${trail.toFixed(1)} hours away along a trail`);
-check(f && f.village === nv.id && nv.farmsteads.length === 1 && nv.farmsteads[0] === f.id && f.booth === true && VB['sim/projects'].projectsOf(st, 'household', f.household).some((p) => p.what === 'cottage'), 'one farm, in a booth');
+check(f && f.village === nv.id && nv.farmsteads.length === 1 && nv.farmsteads[0] === f.id && !f.booth, 'one farm, its cottage built');
check(f.name === nv.name, `the farm bears the new village's name (${f.name}, ${nv.name})`);
-check(f.fields.length === 0 && ['clear', 'fell'].includes(VB['sim/projects'].openOf(st, hh.id)?.kind), 'the first field is the household\'s project plan');
+check(f.fields.length === 1 || !!VB['sim/projects'].openOf(st, hh.id), 'the first field is broken, or the household\'s project plan');
check(hh && hh.holder === m.id && m.household === hh.id && sib.household === hh.id && hh.members.length === 2, 'settler and sibling live there');
check(sib.servant && ['farmhand', 'maid'].includes(sib.role) && m.role === 'farmer', `the sibling serves (${sib.role})`);
// the stake less a day's ration a head, eaten uncooked on the journey (VB-287, sim/agents setOut)
@@ -76,9 +79,7 @@ const journeyFood = hh.members.reduce((n, id) => n + (st.pawns[id].age >= 14 ? s
const oldHouse = st.farmsteads[st.households[oldHh].farmstead].house;
const bearing = () => st.away.filter((j) => j.why === 'fetch' && j.gift && j.gift.to === hh.id);
const lies = () => bearing().reduce((n, j) => n + j.gift.held + j.gift.stops.reduce((k, x) => k + x.left, 0), 0);
-check(Sim.grainOf(hh) === 0 && !m.stake && bearing().length === 2 && bearing().every((j) => j.gift.stops.every((x) => x.at === oldHouse && x.start)),
- `the stake lies at the old home for both to bear (${Sim.grainOf(hh)} in store, ${bearing().length} bearers)`);
-check(Math.abs(lies() - (300 - journeyFood)) < 1e-6, `the stake less the journey's food (${lies()})`);
+check(!m.stake, 'the stake is taken as provisions at the move');
check(!st.households[oldHh].members.includes(m.id), 'the settler left the old household');
check(st.demand.includes(sib.id) && !st.demand.includes(m.id), 'the sibling still wants land, the settler does not');
const s = st.cenv.settlements[nv.id];
@@ -109,7 +110,7 @@ bad = checkState(st); check(!bad.length, `invariants after two years: ${bad.slic
for (const h of t.st.households) h.grain = { barley: 0 };
const n = t.st.villages.length;
roll(t.st, () => S.settleRound(t.st));
- check(t.st.villages.length === n && Sim.villageLog(t.st, Infinity).some((e) => /cannot spare the grain/.test(e.text)), 'a party without provisions stays');
+ check(t.st.villages.length === n && t.st.sites.length === 1 && !VB['sim/settle'].provisions(t.st, t.st.sites[0].party.all), 'a party without provisions stakes its site, and its move waits for them (VB-787)');
}
// 3b. A home that took in a spouse at this round gives no provisions (VB-330); the next round it gives, and one that did not marry gives as before.
{
@@ -144,7 +145,7 @@ const founders = () => {
const small = S.smallVillage(t.st, t.v, t.m, S.waitingByVillage(t.st));
check(d <= SETTLE.join && small && small.village === t.lone, `the lone farm lies within ${SETTLE.join} hours (${d.toFixed(1)}) and is the small village offered`);
roll(t.st, () => S.settleRound(t.st));
- check(t.st.villages.length === n + 1 && t.st.villages[n].founded.by === t.m.id && t.lone.farmsteads.length === 1, 'the round founds, and joins nobody unasked');
+ check(t.st.sites.length === 1 && t.st.sites[0].leader === t.m.id && t.st.sites[0].village === null && t.lone.farmsteads.length === 1, 'the round stakes a new village\'s site, and joins nobody unasked');
bad = checkState(t.st); check(!bad.length, `invariants after founding: ${bad.slice(0, 3).join('; ')}`);
joined = `; the lone village ${t.lone.name} ${d.toFixed(1)} hours away is offered, not joined`;
}
@@ -154,13 +155,13 @@ const founders = () => {
VB['sim/heirs'].moveTo(t.st, other.id, t.st.farmsteads[t.lone.farmsteads[0]].household); t.st.demand.push(other.id);
check(S.smallVillage(t.st, t.v, t.m, S.waitingByVillage(t.st)) === null, 'with its own adult waiting, the lone farm is passed over');
roll(t.st, () => S.settleRound(t.st));
- check(t.st.villages.length === n + 1 && t.st.villages[n].founded.by === t.m.id, 'and the settler founds');
+ check(t.st.sites.length === 1 && t.st.sites[0].leader === t.m.id && t.st.sites[0].village === null, 'and the settler stakes a new village\'s site');
}
{ // no room at the lone farm either: the settler founds
const t = founders(), n = t.st.villages.length; fill(t.st, t.lone);
check(S.smallVillage(t.st, t.v, t.m, S.waitingByVillage(t.st)) === null, 'with no room at the lone farm, it is passed over');
roll(t.st, () => S.settleRound(t.st));
- check(t.st.villages.length === n + 1 && t.st.villages[n].founded.by === t.m.id, 'and the settler founds');
+ check(t.st.sites.length === 1 && t.st.sites[0].leader === t.m.id && t.st.sites[0].village === null, 'and the settler stakes a new village\'s site');
}
// 5. The wish to settle (VB-392, on VB-680's wishes): true passes the draws to lead and to follow, false never leads or follows, null
// draws as before; the round's other rules decide as for anyone. Every pawn holds it; the played pawn's is set by the wish verb.
@@ -174,8 +175,8 @@ const founders = () => {
if (ws !== null) Wi.setWish(t.st, t.sib.id, 'settle', ws);
const n = t.st.villages.length;
how(t.st, () => S.settleRound(t.st));
- const nv = t.st.villages[n], hh = nv && t.st.households[t.st.farmsteads[nv.farmsteads[0]].household];
- return { led: !!nv && nv.founded.by === t.m.id, followed: !!hh && hh.members.includes(t.sib.id), st: t.st };
+ const s = t.st.sites[0];
+ return { led: !!s && s.leader === t.m.id && t.st.villages.length === n, followed: !!s && s.party.all.includes(t.sib.id), st: t.st };
};
let r = scene(null, null, never);
check(!r.led, 'with no wish and the draws against it, nobody leaves');
diff --git a/tests/shelter.js b/tests/shelter.js
index 87a82d1c..fece52a4 100644
--- a/tests/shelter.js
+++ b/tests/shelter.js
@@ -1,4 +1,5 @@
-// VB-1666: the shelter, the ladder's first rung, on the house tile for every household (Kim: one rule for every household). A settler
+// VB-1666: the shelter, the ladder's first rung, on the house tile for every household (Kim: one rule for every household). (A settler
+// household moves into a finished cottage since VB-787: tests/sites.js.) Before that, a settler
// household (sim/settle settleFarm; heirs at seed 13 on the probe island, as tests/settle.js) begins its shelter on its own house tile, no
// booth of st.booths beside it; it sleeps under the open sky and its cottage waits until the shelter stands, then the cottage's stages are
// worked on that same tile. A save from before VB-1666, a farm's booth staked beside its house, loads and goes on: the booth is kept as
@@ -25,56 +26,6 @@ const roll = (st, f) => {
}
};
-// ---- 1. a settler household: its shelter on its house tile, then its cottage there ----
-{
- const st = scenario('heirs', 13);
- st.naturalDeaths = false;
- const v = st.villages[0];
- const inA = (p) =>
- p.alive && p.age >= 18 && p.age <= 45 && Sim.settlementIdOf(st, p) === 0 && !Sim.isHolder(st, p.id) && Sim.spouseOf(st, p.id) === null;
- const m = st.pawns.find((p) => inA(p) && Sim.siblingsOf(st, p.id).some((q) => inA(st.pawns[q])));
- const sib = Sim.siblingsOf(st, m.id).map((q) => st.pawns[q]).find(inA);
- for (const [t] of bfs(st.w, v.center, 6, () => true).dist) st.used.add(t);
- for (const u of st.villages) VB['sim/territory'].reckonWood(st, u);
- st.demand = [m.id, sib.id];
- m.landWait = 2;
- sib.landWait = 2;
- m.stake = 300;
- const farms = st.farmsteads.length,
- booths = st.booths.length;
- roll(st, () => S.settleRound(st));
- const f = st.farmsteads[farms];
- assert(f, 'a farm settled');
- const hh = st.households[f.household];
- assert.strictEqual(f.booth, true, 'no cottage yet');
- assert.deepStrictEqual(f.shelter, { wood: 0, done: 0, built: null, cond: 1, condAt: st.t }, 'its shelter begun');
- assert.strictEqual(st.booths.length, booths, 'no booth of st.booths for it');
- assert(Sim.stakedBooths(st).includes(f.house), 'the page reads it being raised on the house tile');
- assert(B.roofless(st, hh), 'under the open sky until it stands');
- assert.strictEqual(rungOf(st, f), 'camp');
- assert.strictEqual(Sim.farmView(st, f.id, st.player && st.player.pawn).building.what, 'shelter');
- sound(st, 'settled');
- let stood = null,
- staged = false;
- for (let d = 0; d < Sim.SEASON_DAYS * 2 && !staged; d++) {
- for (let h = 0; h < 24; h++) {
- Sim.advance(st, 1);
- const stage = st.jobs.get(`booth:f${f.id}`);
- if (stage) {
- assert(stood !== null, `a cottage stage (${stage.kind}) posted before the shelter stands`);
- assert.strictEqual(stage.site, f.house, 'the cottage worked on the shelter\'s tile');
- staged = true;
- }
- if (stood === null && B.shelterStands(st, f)) stood = st.t;
- }
- }
- assert(stood !== null, 'the shelter stands');
- assert(!B.roofless(st, hh) && rungOf(st, f) === 'shelter', 'under the shelter: the rung a shelter');
- assert(staged, 'the cottage begun on the same tile');
- assert.strictEqual(st.booths.length, booths, 'still no booth of st.booths for it');
- sound(st, 'the shelter up, the cottage under way');
-}
-
// ---- 2. a save from before VB-1666: a farm's booth staked beside the house, no shelter; kept as a booth until the cottage is roofed ----
{
const rows = Array.from({ length: 12 }, (_, i) => (i < 2 ? 'FFFFFFFFFFFFFFFF' : '................'));
@@ -106,5 +57,5 @@ const roll = (st, f) => {
}
assert(BOOTH.hours > 0);
console.log(
- 'shelter: a settler household raises its shelter on its house tile, no booth, and its cottage there after; an older save\'s booth kept',
+ 'shelter: an older save\'s booth kept',
);
diff --git a/tests/sites.js b/tests/sites.js
new file mode 100644
index 00000000..6bc67392
--- /dev/null
+++ b/tests/sites.js
@@ -0,0 +1,111 @@
+// VB-787: settling in steps (design.md, Moving to new land, Settling in steps). On the heirs island of tests/lib/probe.js at seed 13,
+// village A crowded: at the round its waiting adult stakes a site for itself and its sibling (nobody moves, no household or village is
+// made), blazes the trail, the two clear its tiles and build its cottage from their old household, and they move when its roof is on,
+// founding the household and the village then; a party whose home has no grain to spare sends no worker to lodge there; and a save taken
+// at each step plays on as the unbroken run.
+const VB = require('../src/load.js'), Sim = VB.sim, S = VB['sim/settle'], Sites = VB['sim/sites'];
+const { bfs } = VB['sim/hex'], { checkState } = require('./lib/invariants.js');
+const probe = require('./lib/probe.js'), { scenario } = probe;
+let failed = 0; const check = (ok, m) => { if (!ok) { failed++; console.error('SITES FAIL:', m); } };
+const roll = (st, f) => { const rs = new Set(Object.values(st.rng)); rs.forEach((r) => { r.fix = 0; }); try { f(); } finally { rs.forEach((r) => { delete r.fix; }); } };
+function setUp() {
+ const st = scenario('heirs', 13); st.naturalDeaths = false;
+ const inA = (p) => p.alive && p.age >= 18 && p.age <= 45 && Sim.settlementIdOf(st, p) === 0 && !Sim.isHolder(st, p.id) && Sim.spouseOf(st, p.id) === null;
+ const m = st.pawns.find((p) => inA(p) && Sim.siblingsOf(st, p.id).some((q) => inA(st.pawns[q])));
+ const sib = Sim.siblingsOf(st, m.id).map((q) => st.pawns[q]).find(inA);
+ const v = st.villages[0];
+ for (const [t] of bfs(st.w, v.center, 6, () => true).dist) st.used.add(t);
+ for (const u of st.villages) VB['sim/territory'].reckonWood(st, u);
+ st.demand = [m.id, sib.id]; m.landWait = 2; sib.landWait = 2; m.stake = 300;
+ roll(st, () => S.settleRound(st));
+ return { st, v, m, sib, s: st.sites[0] };
+}
+const told = (st, kind) => st.record.some((e) => e.kind === kind);
+// 1. the stake: a site, nobody moved, no household nor village made
+const { st, m, sib, s } = setUp();
+const villages = st.villages.length, households = st.households.length, home = m.household;
+check(s && s.leader === m.id && s.party.all.includes(sib.id) && s.village === null, `a site is staked by the leader for the party (${JSON.stringify(s && s.party)})`);
+check(st.villages.length === villages && m.household === home && sib.household === home, 'nobody moves, and no village is made');
+check(told(st, 'siteStaked'), 'the stake is told');
+check(st.claims.get(s.house).some((c) => c.by.type === 'pawn' && c.by.id === m.id), "the stake is the leader's");
+let bad = checkState(st); check(!bad.length, `invariants at the stake: ${bad.slice(0, 3).join('; ')}`);
+// 2. to the move, a save taken at each stage (staked, built, roofed) played on beside the unbroken run
+const { canon } = require('./lib/canon.js');
+const saves = {};
+// a save at a stage, loaded into the island made again from its seed, plays three days as the unbroken run does
+const playsOn = (stage) => {
+ const text = JSON.stringify(Sim.save(st)), data = JSON.parse(text), back = Sim.load(probe.island(data.seed, data), data);
+ const ahead = JSON.parse(text), run = Sim.load(probe.island(ahead.seed, ahead), ahead);
+ Sim.advance(back, 72); Sim.advance(run, 72);
+ for (const k of ['sites', 'households', 'away', 'booths', 'villages']) check(canon(back[k]) === canon(run[k]), `a save at ${stage}: ${k} as the unbroken run`);
+};
+let moved = null, lodged = 0;
+saves[s.stage] = -1; // the save at the stake, before its trail is blazed
+playsOn(s.stage);
+for (let d = 0; d < 2 * Sim.YEAR_DAYS && moved === null; d++) {
+ Sim.advance(st, 24);
+ lodged = Math.max(lodged, st.away.filter((a) => a.why === 'site').length);
+ if (st.sites.length && !saves[s.stage]) {
+ saves[s.stage] = d;
+ playsOn(s.stage);
+ }
+ if (!st.sites.length) moved = d;
+ else check(m.household === home, 'the party lives at home until the move');
+}
+check(moved !== null, `the party moves (site at ${s.stage}, steps ${s.plot.places.map((t) => t.i)}, stage ${s.plot.open})`);
+check(st.households.length === households + 1 && m.household !== home && st.households[m.household].holder === m.id, 'the household is founded at the move, the leader its head');
+check(st.villages.length === villages + 1, 'the village is founded at the move');
+const f = st.farmsteads[st.households[m.household].farmstead];
+check(f && !f.booth && !f.shelter, 'its cottage stands: no booth, no shelter');
+for (const k of ['siteRoofed', 'left']) check(told(st, k), `the ${k} is told`);
+check(Object.values(s.hours).reduce((a, b) => a + b, 0) > 100, `the party worked at the site (${JSON.stringify(s.hours)})`);
+bad = checkState(st); check(!bad.length, `invariants after the move: ${bad.slice(0, 3).join('; ')}`);
+console.log(` moved on day ${moved}; at most ${lodged} lodged; saves at ${Object.keys(saves).join(', ')}`);
+// 3. a home with no grain to spare sends no worker to lodge
+{
+ const t = setUp();
+ for (const id of t.s.party.all) t.st.pawns[id].stake = 0;
+ for (const h of t.st.households) h.grain = { barley: 0 };
+ let away = 0;
+ for (let d = 0; d < 20; d++) {
+ Sim.advance(t.st, 24);
+ away += t.st.away.filter((a) => a.why === 'site').length;
+ }
+ check(away === 0, `nobody lodges from a home with nothing to spare (${away})`);
+}
+// 4. a leader who dies is followed by the party's next adult, the stake passing to it; with nobody left, the site is given up
+{
+ const t = setUp(), { killPawn } = VB['sim/lifecycle'];
+ killPawn(t.st, t.m.id, 'killed');
+ Sim.advance(t.st, 24);
+ const s4 = t.st.sites[0];
+ check(s4 && s4.leader === t.sib.id && !s4.party.all.includes(t.m.id), `the sibling leads the site (${s4 && s4.leader})`);
+ check(told(t.st, 'siteLeader'), 'the new leader is told');
+ check(s4 && t.st.claims.get(s4.house).some((c) => c.by.type === 'pawn' && c.by.id === t.sib.id), "the stake is the new leader's");
+ let bad4 = checkState(t.st);
+ check(!bad4.length, `invariants after the leader's death: ${bad4.slice(0, 3).join('; ')}`);
+ killPawn(t.st, t.sib.id, 'killed');
+ Sim.advance(t.st, 24);
+ check(!t.st.sites.length && told(t.st, 'siteGivenUp'), 'with nobody left to lead, the site is given up');
+ const left = t.st.claims.get(s4.house) || [];
+ check(!left.some((c) => c.by.type === 'pawn'), 'its stake is dropped');
+ bad4 = checkState(t.st);
+ check(!bad4.length, `invariants after the site is given up: ${bad4.slice(0, 3).join('; ')}`);
+}
+// 5. a member who comes to hold a household (here the leader, heir to its parents) leaves the party and stays at its holding: the next
+// adult leads, and the move takes no holder from its household (the gate's crash, populous 11: a head who moved left its house headless)
+{
+ const t = setUp(), { killPawn } = VB['sim/lifecycle'], home5 = t.st.households[t.m.household];
+ for (const id of [home5.holder, Sim.spouseOf(t.st, home5.holder)]) if (id !== null) killPawn(t.st, id, 'killed');
+ const heir = home5.holder;
+ check(t.s.party.all.includes(heir) && Sim.isHolder(t.st, heir), `a member of the party is heir to the home (${heir})`);
+ Sim.advance(t.st, 24);
+ const s5 = t.st.sites[0];
+ check(s5 && !s5.party.all.includes(heir) && s5.leader !== heir, `the heir leaves the party (${s5 && s5.party.all})`);
+ for (let d = 0; d < 2 * Sim.YEAR_DAYS && t.st.sites.length; d++) Sim.advance(t.st, 24);
+ check(home5.holder === heir && t.st.pawns[heir].household === home5.id, 'the heir stays the head of its household, living there');
+ const bad5 = checkState(t.st);
+ check(!bad5.length, `invariants after the heir stays: ${bad5.slice(0, 3).join('; ')}`);
+}
+if (failed) process.exit(1);
+console.log('sites ok: staked at the round, built from home, founded at the move');
diff --git a/tests/sitewell.js b/tests/sitewell.js
index e4416c5c..5ca878fb 100644
--- a/tests/sitewell.js
+++ b/tests/sitewell.js
@@ -41,12 +41,7 @@ function settle(at, brook, depth) {
grown = home.members.filter((id) => st.pawns[id].age >= 18 && id !== home.holder).slice(0, 2);
home.grain.barley += 3000; // a family that can spare the provisions
const n = st.farmsteads.length,
- res = issue(st, {
- actor: grown[0],
- verb: 'leave',
- args: { from: 0, party: { all: grown, followers: [] }, house, field },
- source: 'round',
- });
+ res = require('./lib/settled.js')(VB, st, grown[0], { from: 0, party: { all: grown, followers: [] }, house, field });
const f = st.farmsteads[n] || null;
return { st, w, res, grown, f, hh: f ? st.households[f.household] : null, house };
}
@@ -54,10 +49,10 @@ const wellPlan = (st, hh) => Projects.projectsOf(st, 'household', hh.id).find((p
// ---- 1. an inland site, no water within reach: the well is the site's water, and the party digs it from its booth ----
{
const { st, w, res, grown, f, hh, house } = settle([30, 7], 0, 6);
- check(res === true && grown.length >= 1 && f && f.booth === true, `a party settles in a booth (${res}, ${grown})`);
+ check(res === true && grown.length >= 1 && f && !f.booth, `a party settles in its finished cottage (${res}, ${grown})`);
const est = Water.siteWater(st, house, 2);
check(est.by === 'well' && f.wellMeant === true, `the site's water is the well it means to dig (${est.by}, ${f.wellMeant})`);
- check(Projects.ownOf(st, hh.id) && Projects.ownOf(st, hh.id).what === 'field', 'its first field is under way beside it');
+ check(f.fields.length === 1, 'its first field, broken at the site, is its own (VB-787)');
let begun = null,
days = 0,
drawn = 0;
@@ -72,7 +67,7 @@ const wellPlan = (st, hh) => Projects.projectsOf(st, 'household', hh.id).find((p
}
}
check(
- begun && begun.hours === wellHours(6) && begun.stone === 6 && begun.booth === true,
+ begun && begun.hours === wellHours(6) && begun.stone === 6,
`from its booth, 6 loads gathered and a well of ${wellHours(6)} hours begun (${JSON.stringify(begun)})`,
);
check(w.fresh[house] === FRESH.WELL && f.wellMeant === undefined, `water is struck within 90 days (${days}), and the mark goes`);
diff --git a/tools/writes.js b/tools/writes.js
index 06d20a06..aca97877 100644
--- a/tools/writes.js
+++ b/tools/writes.js
@@ -63,6 +63,7 @@ const HINTS = {
'sim/claims': { c: 'claim', r: 'local' }, 'sim/trust': { t: 'st.trusts' }, 'sim/offers': { o: 'st.offers' }, 'sim/clock': { s: 'fence' }, 'sim/meadows': { m: 'farmstead.meadows[]' }, 'sim/births': { m: 'pawn' },
'sim/commands': { q: 'pawn' }, 'sim/notable': { from: 'local' }, 'sim/timetable': { from: 'local' }, 'sim/agents': { g: 'agent', stay: 'st.away[]' }, 'sim/away': { g: 'local', rest: 'local', stay: 'st.away[]' }, 'sim/journeys': { g: 'local' }, 'sim/expansion': { walls: 'plan.steps[]' }, 'sim/allotment': { live: 'local', worked: 'local' }, 'sim/building': { walls: 'plan.steps[]' }, 'sim/upgrade': { walls: 'plan.steps[]' }, // a plot's walls step (VB-1407)
'sim/facilities': { fac: 'st.facilities[]', I: 'st.facilityIdx' }, 'sim/pot': { units: 'local' }, 'sim/hands': { d: 'st.handsToday' },
+ 'sim/sites': { s: 'st.sites[]', k: 'st.sites[]', walls: 'st.sites[]', tr: 'st.sites[]', x: 'local' }, // a site and its plot's steps (VB-787)
'sim/fit': { memo: 'local' }, 'sim/occasions': { memo: 'local' }, // scratch maps of one pass (VB-1848)
'sim/day': { asking: 'local', pairs: 'local', cap: 'local', due: 'local', lists: 'plan.day', fits: 'plan.day', ctx: 'plan.day' }, // VB-470: today's lent hands; the morning's asks
'sim/voice': { G: 'plan.grants', g: 'plan.grants' }, 'sim/levies': { F: 'plan.fit', r: 'agent.book', T: 'plan.tally', U: 'local', sum: 'plan.tally', e: 'plan.tally', old: 'agent.book' }, 'sim/legs': { l: 'agent.leg' }, // VB-1761: a pawn's booked hours, a plan's tally