B3: Structure health and structural integrity

Pieces build up health, take damage from the boathook and the tide, and
collapse when nothing connects them to the ground.

- Build-up: a piece starts at 10% of its material's health and gains
  the rest evenly over build_seconds. Damage taken while building stays.
- Damage: Simulation.damage_piece, and boathook swings now hit pieces
  nearer than any prop for HARVEST_DAMAGE, with no material back.
- Tide: once a second, pieces with their base under the sea lose
  TIDE_STRUCTURE_DPS; breakwaters wear per metre of head and fail past
  BREAKWATER_MAX_HEAD.
- Integrity: grounded means touching terrain or a fixed solid (not a
  prop). On removal, a breadth-first search from the former neighbours
  stops at the first grounded piece, so only structures that really
  lost support are walked in full; loose components collapse together.
  Simulation.ground_changed rechecks grounding after terrain changes.
- Wall skirts now reach at most one level (2 m), so upper walls aren't
  grounded through a skirt; terrain checks merge boxes sharing a bottom.
- 12 tests: build-up per material, damage during building, material
  strength, fresh pieces breaking, cascades, a second support, boathook
  bringing down a wall and its floor, tide wear and breakwater failure,
  tide-triggered collapse, terrain-triggered collapse, fixed solids as
  ground, and a 564-piece fort (one removal 57 us, worst search 416 us,
  full cascade of 479 pieces 4.7 ms).

Closes #17

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 14:30:54 -05:00
co-authored by Claude Opus 5.5
parent f35ebf7171
commit f38bb9c69a
9 changed files with 548 additions and 20 deletions
+8 -1
View File
@@ -181,7 +181,8 @@ const GRID_CELL_METRES: float = 4.0
const MATERIAL_CAP: int = 500
## Material gained per boathook hit on a prop, whatever the prop.
const HARVEST_PER_HIT: int = 15
## Damage a boathook hit does to a prop. Players take the boathook's `damage` instead.
## Damage a boathook hit does to a prop or a built piece. Players take the boathook's
## `damage` instead.
const HARVEST_DAMAGE: int = 50
## A swing reaches this far past the boathook's range, from the eye, so a prop the body
## is touching is always in reach.
@@ -221,6 +222,12 @@ const BREAKWATER_THICKNESS: float = 0.6
const FLOOR_THICKNESS: float = 0.2
## Ramps are stairs of this many steps, so each riser can be stepped up.
const RAMP_STEPS: int = 10
## A new piece starts at this fraction of its material's health and reaches full health
## after the material's `build_seconds`.
const BUILD_START_HEALTH_FRACTION: float = 0.1
## Damage per second to a piece other than a breakwater whose base is under the sea.
const TIDE_STRUCTURE_DPS: int = 4
## A breakwater holds this much water above its base. Deeper, it fails at once.
const BREAKWATER_MAX_HEAD: float = 6.0
const BREAKWATER_WEAR_PER_METRE: float = 2.0
const BREACH_FLOW_METRES_PER_SECOND: float = 1.5