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
+11 -4
View File
@@ -84,7 +84,8 @@ func test_placing_spends_material_and_adds_collision() -> void:
assert_eq(_player(sim).materials[Materials.STONE], 200 - Tuning.BUILD_PIECES["wall"]["cost"])
var piece: StructureSet.Piece = sim.structures.find(1)
assert_eq(piece.material, Materials.STONE)
assert_eq(piece.health, Tuning.MATERIALS["stone"]["health"])
assert_eq(piece.max_health, Tuning.MATERIALS["stone"]["health"])
assert_eq(piece.health, ceili(piece.max_health * Tuning.BUILD_START_HEALTH_FRACTION), "pieces start weak (B3)")
assert_true(piece.grounded)
# The wall stands at z = 12 across x 8..12 and blocks walking.
for _i: int in 60:
@@ -212,12 +213,12 @@ func test_walls_meet_at_corners_without_gaps() -> void:
func test_walls_on_low_ground_get_a_skirt() -> void:
# A slope: terrain height rises 1 m per 4 m along x.
# A slope: terrain height rises 0.375 m per metre along x.
var values: PackedFloat32Array = PackedFloat32Array()
var side: int = 65
for z: int in side:
for x: int in side:
values.append(x * 4.0)
values.append(x * 6.0)
var ground: SimGround = SimGround.from_heights(values, side, 16.0)
var sim: Simulation = Simulation.new(3, ground)
var id: int = sim.add_player()
@@ -230,7 +231,13 @@ func test_walls_on_low_ground_get_a_skirt() -> void:
var piece: StructureSet.Piece = sim.structures.find(1)
assert_eq(piece.boxes.size(), 2, "the wall should get a skirt")
var skirt: AABB = piece.boxes[1]
assert_true(skirt.position.y <= ground.terrain_height(8.0, 12.0), "the skirt reaches the ground")
assert_true(skirt.position.y <= ground.terrain_height(7.85, 12.0), "the skirt reaches the ground")
assert_true(piece.boxes[0].position.y - skirt.position.y > 0.9, "a real gap was filled")
# A wall a whole cell higher gets no skirt: it must be held up by something.
var high: Building.Target = Building.Target.new()
high.kind = W
high.slot = at.slot + Vector4i(0, 2, 0, 0)
assert_eq(Building.boxes_for_target(high, ground).size(), 1)
func test_rapid_placement_stays_within_the_tick_budget() -> void: