B1: Harvesting and materials

Boathook swings harvest props. The client only presses fire with the
boathook selected; the server casts the swing from its own copy of the
player's eye and look, so range and swing rate are enforced by
construction. Each hit damages the prop and gives its material
(driftwood, stone or salvage iron), capped per material.

- Materials: material codes and add/spend helpers; carried stock lives
  on SimEntity.materials and is part of the state hash.
- Harvest: swing interval from the boathook's fire rate, reach from its
  range plus slack, nearest prop along the ray, blocked by terrain or
  other solids. Emits harvest and prop_destroyed events.
- Simulation: per-tick events list, a shared action cooldown, and fire
  with selection 0 outside build mode swings.
- Tuning: HARVEST_DAMAGE, HARVEST_REACH_SLACK, HARVEST_AIM_SLACK.
- 12 tests: yields per kind, rate limit, reach, blocking, nearest prop,
  caps, destruction clearing collision, state gating and determinism on
  a real island.

Closes #15

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 14:11:15 -05:00
co-authored by Claude Opus 5.5
parent 21559a637d
commit b847ba9695
12 changed files with 376 additions and 1 deletions
+10
View File
@@ -47,6 +47,8 @@ var solid_ids: PackedInt32Array = PackedInt32Array()
var destroyed: PackedInt32Array = PackedInt32Array()
var _ground: SimGround
## SimGround solid ID -> prop ID, for props whose box is in `_ground`.
var _by_solid: Dictionary = {}
## Places props for `island`, clear of `placed` points of interest.
@@ -88,6 +90,13 @@ func add_solids_to(ground: SimGround) -> void:
solid_ids.resize(count())
for prop: int in count():
solid_ids[prop] = ground.add_solid(boxes[prop]) if is_standing(prop) else -1
if solid_ids[prop] >= 0:
_by_solid[solid_ids[prop]] = prop
## The prop whose box is ground solid `solid_id`, or -1 if that solid isn't a prop.
func prop_of_solid(solid_id: int) -> int:
return _by_solid.get(solid_id, -1)
## Takes `amount` health from a standing prop. Returns true if this destroyed it, which
@@ -101,6 +110,7 @@ func damage(prop: int, amount: int) -> bool:
destroyed.append(prop)
if _ground != null and solid_ids[prop] >= 0:
_ground.remove_solid(solid_ids[prop])
_by_solid.erase(solid_ids[prop])
solid_ids[prop] = -1
return true