Skip to content

PWA4: Show farmhouse and forester ranges while the planting tool is open - #9

Merged
kramsey458 merged 3 commits into
mainfrom
claude/planting-tool-ranges
Sep 22, 2026
Merged

kramsey458 merged 3 commits into
mainfrom
claude/planting-tool-ranges

Conversation

@kramsey458

Copy link
Copy Markdown
Collaborator

Stacked on #6 (claude/pin-refresh-planner, PWA1). This PR's base is that branch, so the diff shows only PWA4. Merge #6 first, then retarget this PR to main.

Summary

While a crop or tree planting tool is open, the mod now outlines the working area of every building that can plant the selected plant. The outlines are drawn alongside the player's pins:

  • Crops: every farmhouse.
  • Aquatic crops (Folktails): every aquatic farmhouse.
  • Trees and bushes: every forester.

Buildings still under construction are included. The outlines disappear when you leave the planting tool, and pins are unaffected.

This is display only. All work stays in UpdateSingleton, the event handlers only set fields, and nothing adds a tick, save or persistence interface or a Harmony patch.

Items

PWA4: show farmhouse and forester ranges while the planting tool is open

What changed

  • Tool events. ToolEnteredEvent and ToolExitedEvent with Tool is PlantingTool record only the selected plant's ResourceGroup. The game's own PlantingModeService uses the same hook.
  • Scan. The next UpdateSingleton scans EntityComponentRegistry.GetAll<Workplace>(). It keeps each building whose PlanterBuildingSpec.PlantableResourceGroup matches the plant, using PlantingRanges.Shows, a Unity-free rule. This is the same pairing PlanterBuilding.GetAllowedPlantables and PlantingToolButtonFactory use (ordinal ==).
  • Why the scan waits for the update. ToolService.SwitchToolInternal posts the old tool's exit and the new tool's entry in one call. Waiting means that switching between two crops planted by the same farmhouses keeps their cached ranges and costs 0 queries.
  • Planner. PinRefreshPlanner entries are now pinned, shown by the tool, or both, with one cache per building. Show(set) replaces the shown set. A building that leaves the set keeps its range only while it is pinned. Navigation, selection and construction-mode handling apply to shown buildings exactly as they do to pins.
  • Buildings added or removed. A planter created or deleted while the tool is open triggers a rescan. EntityComponent.Initialize registers the entity before it posts EntityInitializedEvent, and InternalDelete unregisters it before it posts EntityDeletedEvent, so the scan sees the current set.
  • Clearing. Clear pinned areas (the button or the key) clears only the player's pins. The tool's outlines stay until the tool closes, and the renderer is released once nothing is drawn.
  • Docs. The README's Use section and VALIDATION.md's playtest checklist are updated: steps 1, 2 and 4 are reworded and step 8 is new.

Tests (tests/Program.cs, +30 checks)

  • Game-free (16).
    • 4 checks of the PlantingRanges.Shows rule.
    • 12 planner work counts. Opening a crop's tool costs 2 queries and 1 rebuild. Another crop for the same farmhouses costs 0/0. A navigation change near one shown farmhouse costs 1/0. A selected shown building is left to the game's outline. A construction toggle re-queries every building. Switching to a tree queries only the forester. Closing the tool costs 0 queries and 1 rebuild back to the pins, and closing it again costs 0/0. A building that is both pinned and shown keeps one cache. Pinning or unpinning a shown building keeps its range drawn.
  • Game-dependent (14).
    • 4 tool-switch checks. They drive OnToolEntered/OnToolExited through reflection with the game's own PlantingTool, CancelPlantingTool and ToolEntered/ExitedEvent.
    • 1 check that Workplace is still an IRegisteredComponent, as a guard against game updates.
    • 4 checks of the rule against the game's Blueprints.zip. Every plantable shows at least one planter. Crops show only farmhouses, and trees and bushes only foresters. Carrot, Cattail, Pine and BlueberryBush map exactly. Every planter has WorkplaceSpec and BuildingAccessibleSpec.
    • 3 [OnEvent] subscription checks.
    • 2 checks on the service instance, added after review. ClearAll keeps the tool's building and drops only the pin. The scan after leaving the tool, with no pins, empties the planner.

Fail before, pass after

  • Before: on the unfixed base, the new checks do not compile:
    • Program.cs(109,7): error CS0103: The name 'PlantingRanges' does not exist in the current context
    • Program.cs(118,9): error CS1061: 'PinRefreshPlanner<FakePin, ...>' does not contain a definition for 'Show'
    • With the PlantingRanges.cs link left in Checks.csproj, the build instead fails with CS2001, file not found.
  • Beyond the compile errors, source mutations were applied one at a time; each fails a named check:
    • The owner's nine planner and handler mutations.
    • The reviewer's three planner mutations.
    • Removing _planner.Show(_planters) from ShowPlanters.
    • Reverting ClearAll to wipe everything.
  • After: 97/97.

Tests

Suite Before (base bb694dd, #6 head) After (7ec9ee2)
build.ps1 -GameDir <Timberborn> (builds, runs Checks, packages) 67/67, 0 warnings 97/97, 0 warnings
dotnet run --project tests/Checks.csproj -c Release -- <Timberborn> <dll> <package> 67/67 97/97 (48 game-free, 49 need the game)

Co-op impact

None. The change is display only and does not affect simulation or the wire format, so co-op players do not need to update together.

  • No simulation hooks. It adds no tick, save, persistence or replay interfaces, no Harmony patches and no random calls. The existing "No simulation tick or persistence interfaces" check still passes.
  • Range queries. It adds range queries of the same kind as the game's selected-building outline and PWA1: re-query only the pins a navigation change can reach #6's pins, so PWA1: re-query only the pins a navigation change can reach #6's co-op analysis still holds. The shared flow-field cache is keyed by position and graph. Refills are deterministic because the heap is cleared before each fill. The instant graph changes only inside NavMeshUpdater.ProcessInstantChanges, which clears the cache in the same call.
  • Registry scan. GetAll<T> only reads the registry and never inserts into it.
  • Event handlers. OnInitialized, OnDeleted and the tool handlers only read _planting and call GetComponent on a live entity, so they cannot throw inside a simulation event post.

Proposed CHANGELOG lines

  • Added: while a crop or tree planting tool is open, the working areas of every farmhouse (crops), aquatic farmhouse (aquatic crops) or forester (trees and bushes) that can plant it are outlined automatically, including buildings under construction. They disappear when you leave the tool; pins are unaffected. Clear pinned areas clears only your pins.

Needs in-game / two-player testing

  • Core. Place a few farmhouses (one still under construction) and foresters, and leave them unpinned.
    • Pick a crop in the Fields tools: every farmhouse's outline appears and no forester's.
    • Pick a tree or a bush: only the foresters' outlines appear.
    • As Folktails, pick Cattail or Spadderdock: only the aquatic farmhouses' outlines appear.
    • Leave the planting tool: nothing remains.
  • With pins.
    • Pin one forester and open a crop tool: the farmhouses and the pinned forester show.
    • Leave the tool: only the pinned forester remains.
    • Press Clear pinned areas (button or key) while a crop tool is open: the pin goes, and the farmhouses' outlines stay until the tool closes.
  • Selection. Select a farmhouse, then open a crop tool. The selected farmhouse keeps the game's own outline and is not drawn twice. It joins the combined outline after you deselect it.
  • Performance. In a large colony (20 or more farmhouses and foresters), open and switch planting tools and watch for a hitch when the tool opens. Opening costs one range query per building in one frame. Switching between two crops should cost nothing.
  • Two-player (BeaverBuddies Stability Fork). While one player has a crop tool open, the other places and deletes a farmhouse. The first player's outlines update, and the session stays in sync.
  • Re-run VALIDATION.md's release playtest checklist, including the new step 8.

Decisions for the maintainer

  • Always on. The feature is always on while a crop or tree tool is selected, with no toggle. A key-binding toggle would need a new key-binding blueprint, UI text and a default state. Decide whether players should be able to turn it off.
  • Construction sites are shown, using the preview navigation graph as pins already do. The game itself plants only for finished buildings. They are included so fields can be marked around a farmhouse that was just placed.
  • When outlines appear. They appear once a specific crop or tree is picked, not when the Fields or Forestry group opens. PlantingToolGroupSpec is internal, and the chosen plant decides farmhouses versus foresters.
  • No per-frame query budget. If the performance check shows a hitch in big colonies, spread the first queries over a few frames and rebuild the outline once.
  • Known limitation, BeaverBuddies MultiColony. In MultiColony sessions, other colonies' planters are outlined too, although they never plant this player's marks. PWA has no generic way to read MultiColony's colony ownership, and PWA only claims compatibility with the Stability Fork, so this was not addressed.

Merge coordination

Release-time doc updates (not done here: they are release text or the live site)

  • README.md: "passes 38 automated lifecycle/API checks" (97 at this head). The "tested in game on 1.1.2.4" sentence should cover PWA4 only after the checklist above passes.
  • VALIDATION.md "Automated checks":
    • "38 checks passed".
    • The refresh bullet should mention PWA1: re-query only the pins a navigation change can reach #6's per-pin caching and this PR's planting-tool refresh.
    • "Empty pin sets do no range queries" should become "with no pins and no planting tool open…".
    • "Clearing releases the renderer's owned meshes…" should add "…once nothing is drawn".
  • Website (docs/, built from main):
    • docs/index.html ("does no work while nothing is pinned, and releases its meshes when you clear").
    • docs/troubleshooting.html ("does no work while nothing is pinned").
    • docs/faq.html ("nothing runs while there are no pins, and the mesh is released when you clear").
    • Add a short feature and FAQ entry: outlines appear by themselves in the planting tools, Clear does not remove them, and they cost range queries while the tool is open.

Review

Three adversarial reviewers checked 79e1790. All three approved.

  • (a) Determinism and lockstep: approve, no findings.
    • Every game claim was re-checked against the decompiled 1.1.2.4 code.
    • A model-based fuzz of the planner and the service's pin, Clear, Show, rescan, delete, create, select, radius and Touch handling ran 20,000 seeds × 60 operations with 0 failures. A planted bug failed 4,326 seeds.
  • (b) Save compatibility and cross-mod interaction: approve.
    • The website says the mod does no work without pins. Accepted. It is listed under release-time doc updates rather than edited, because docs/ is the live site from main.
    • MultiColony outlines every colony's planters. Accepted as a known limitation and listed under decisions.
    • VALIDATION.md's 1.0.0 record carried unreleased behaviour. Fixed in 7ec9ee2: the Automated checks bullet is back to its 1.0.0 wording and is listed for release time.
  • (c) Is the test real: approve.
    • No check covered the service wiring. Fixed in 7ec9ee2 with two offline checks on the service instance. They fail when _planner.Show(_planters) is removed from ShowPlanters and when ClearAll wipes the tool's buildings. UpdateSingleton cannot run offline (Time.unscaledTime is an ECall), so the registry scan, the create and delete rescans (the two-player item) and the release on the last unpin stay in game only.
    • CI: run the pin-logic checks without the game on GitHub Actions #7 merge coordination. Recorded above with the verified numbers.
    • Playtest step 2 no longer tests a pin, since a tree tool outlines every forester. Fixed: the step now leaves the planting tool first.
    • Stale README and VALIDATION counts. Listed under release-time doc updates.
    • The Workplace/IRegisteredComponent check cannot fail against the DLLs the mod was built with. Kept, not counted as scan coverage. It loads the type from the game folder passed at run time, so it catches a game update that drops the interface when the checks are re-run against a new install, which VALIDATION.md asks for after each update.

🤖 Generated with Claude Code

kramsey458 and others added 2 commits September 22, 2026 07:49
The game's planting tools draw no working areas, so a player marking
crops or trees has to pin or re-select each farmhouse or forester to see
where it reaches.

While a crop or tree planting tool is open, the service now outlines
every building that plants it, alongside the player's pins:
- ToolEnteredEvent/ToolExitedEvent with `Tool is PlantingTool` (what the
  game's PlantingModeService uses) record the plant's resource group.
  PlantingToolGroupSpec is internal, so the tool group is not used.
- The next UpdateSingleton scans EntityComponentRegistry.GetAll<Workplace>
  for buildings whose PlanterBuildingSpec.PlantableResourceGroup matches
  PlantableSpec.ResourceGroup, the pairing PlanterBuilding and
  PlantingToolButtonFactory use: farmhouses for crops, aquatic farmhouses
  for aquatic crops, foresters for trees and bushes. Construction sites
  are included, as pins already allow. The scan waits for the update
  because ToolService.SwitchTool posts the old tool's exit and the new
  tool's entry in one call, so switching between two crops of the same
  planters keeps their cached ranges and does no work.
- A planter created or deleted while the tool is open triggers a rescan.
- PinRefreshPlanner entries are now pinned, shown, or both, with one
  cache. Show(set) replaces the shown set: a building leaving it keeps
  its range only while pinned, and one joining it reuses a pin's cache.
  Navigation, selection and construction-mode handling apply to shown
  buildings exactly as to pins.
- Clear pinned areas clears only pins; the tool's buildings stay until
  it closes. The renderer is released once nothing is drawn.

Display only: all work stays in UpdateSingleton and event handlers that
set fields; no tick, save or persistence interface, no patches.

Tests (tests/Program.cs, 67 -> 95 checks):
- PlantingRanges.Shows, a Unity-free rule linked into Checks.csproj.
- Planner counts: opening a crop's tool queries each farmhouse once and
  rebuilds once; another crop for the same farmhouses is 0/0; switching
  to a tree queries only the forester; closing is 0 queries and 1
  rebuild back to the pins; pinned-and-shown buildings keep one cache.
- The rule on the game's Blueprints.zip: every plantable shows at least
  one planter, crops only farmhouses, trees and bushes only foresters;
  every planter is a workplace with an access point.
- The service's tool handlers, driven with the game's own PlantingTool,
  CancelPlantingTool and tool events through reflection.
Before the fix the checks do not compile (CS0103 PlantingRanges, CS1061
no Show on PinRefreshPlanner). Nine mutations (Show dropping pinned
buildings, Add refusing a shown one, Remove dropping a shown one, Show
forgetting caches, a case-insensitive rule, a rule accepting buildings
without a group, exit not hiding, any tool showing planters, entry not
scheduling a scan) each fail a check. The registry scan itself runs only
in game.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Review found that no check exercised the service's own wiring of the
planting tool: deleting `_planner.Show(_planters)` from ShowPlanters, or
reverting ClearAll to wipe everything, still passed all 95 checks.

Two offline checks on the service instance the checks already build:
- ClearAll with one pinned entity and one the tool shows leaves only the
  shown one drawn and no pins.
- ShowPlanters (the scan UpdateSingleton starts with) after leaving the
  tool, with no pins, empties the planner and clears the scan flag.
UpdateSingleton itself reads Time.unscaledTime and cannot run outside the
game; the registry scan, the create/delete rescans and the release on the
last unpin remain in-game checks.

Both checks fail on those two mutations and pass on the fix (97 checks).

VALIDATION.md:
- Playtest step 2 now leaves the planting tool before checking the pinned
  forester, since a tree tool outlines every forester by itself.
- The Automated checks bullet goes back to its 1.0.0 wording. That section
  records the 1.0.0 release (it still says 38 checks) and is refreshed at
  release time together with the check count.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@kramsey458
kramsey458 changed the base branch from claude/pin-refresh-planner to main September 22, 2026 16:41
- WorkAreaService constructor: keep PWA4's EntityComponentRegistry and
  PWA2's ILoc.
- tests/Program.cs: move the planting-rule and planner Show checks above
  the game-free split so CI runs them, and raise GameChecks to 56.
  Full run: 104/104; no-argument run: 48 passed, 56 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kramsey458
kramsey458 marked this pull request as ready for review September 22, 2026 16:41
@kramsey458
kramsey458 merged commit 936c61d into main Sep 22, 2026
1 check passed
kramsey458 added a commit that referenced this pull request Sep 22, 2026
- WorkAreaService constructor: keep PWA2's ILoc alongside PWA3's
  EntityRegistry and SettlementReferenceService, and keep the localized
  clear button next to the pin-file restore in PostLoad.
- tests/Program.cs: keep the PinStore checks above the game-free split,
  raise GameChecks to 65, and allow the pin file's format, file names
  and argument-check text in the hard-coded UI text check. Full run:
  142/142; no-argument run: 77 passed, 65 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kramsey458 kramsey458 mentioned this pull request Sep 22, 2026
@kramsey458
kramsey458 deleted the claude/planting-tool-ranges branch September 22, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant