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:
+16
-1
@@ -55,6 +55,7 @@ func _init(match_seed: int, world: SimGround = null) -> void:
|
||||
props = PropSet.generate(island, pois)
|
||||
props.add_solids_to(world)
|
||||
ground = world
|
||||
structures.props = props
|
||||
|
||||
|
||||
## Adds a player at a seeded spawn position and returns its entity ID.
|
||||
@@ -111,6 +112,9 @@ func start_drop() -> void:
|
||||
## Advances the simulation by one tick.
|
||||
func step() -> void:
|
||||
events.clear()
|
||||
structures.advance_building()
|
||||
if tick % Tuning.TICK_RATE_HZ == Tuning.TICK_RATE_HZ - 1:
|
||||
structures.tide_damage(sea_level, ground, events)
|
||||
for player_id: int in _players:
|
||||
var queued: Dictionary = _pending[player_id]
|
||||
var command: PlayerCommand = queued.get(tick)
|
||||
@@ -155,7 +159,7 @@ func _apply_command(player: SimEntity, command: PlayerCommand) -> void:
|
||||
Building.act(self, player, command)
|
||||
return
|
||||
if command.selection == BOATHOOK_SLOT:
|
||||
Harvest.swing(player, ground, props, events)
|
||||
Harvest.swing(player, ground, props, events, structures)
|
||||
|
||||
|
||||
## Moves the sea surface. Takes effect on the next step.
|
||||
@@ -163,6 +167,17 @@ func set_sea_level(level: float) -> void:
|
||||
sea_level = level
|
||||
|
||||
|
||||
## Damages a piece. Returns true if this destroyed it; anything it held up collapses.
|
||||
func damage_piece(piece_id: int, amount: int, cause: String = "damage") -> bool:
|
||||
return structures.damage(piece_id, amount, cause, ground, events)
|
||||
|
||||
|
||||
## Tells structures the terrain or fixed solids in `area` changed, so pieces that lost
|
||||
## their footing can collapse. Returns how many collapsed.
|
||||
func ground_changed(area: AABB) -> int:
|
||||
return structures.ground_changed(area, ground, events)
|
||||
|
||||
|
||||
## Damages a prop. Returns true if this destroyed it; its collision goes at once.
|
||||
func damage_prop(prop: int, amount: int) -> bool:
|
||||
return props.damage(prop, amount)
|
||||
|
||||
Reference in New Issue
Block a user