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:
@@ -7,6 +7,8 @@ extends RefCounted
|
||||
|
||||
const SECONDS_PER_TICK: float = 1.0 / Tuning.TICK_RATE_HZ
|
||||
const SPAWN_ATTEMPTS: int = 64
|
||||
## The command selection that holds the boathook, which every player always carries.
|
||||
const BOATHOOK_SLOT: int = 0
|
||||
|
||||
var tick: int = 0
|
||||
var entities: EntityRegistry = EntityRegistry.new()
|
||||
@@ -29,6 +31,10 @@ var drown_dps: int = Tuning.TIDE_PHASES[0]["drown_dps"]
|
||||
## The sky barge, from start_drop() on. Null in matches and tests that start on foot.
|
||||
var drop: Drop = null
|
||||
|
||||
## What happened during the last step(): harvests, destroyed props, placed pieces.
|
||||
## Each is a Dictionary with a "type". Cleared at the start of every step.
|
||||
var events: Array[Dictionary] = []
|
||||
|
||||
## Player entity ID -> { command tick -> PlayerCommand }
|
||||
var _pending: Dictionary = {}
|
||||
## Player entity IDs, ascending.
|
||||
@@ -102,6 +108,7 @@ func start_drop() -> void:
|
||||
|
||||
## Advances the simulation by one tick.
|
||||
func step() -> void:
|
||||
events.clear()
|
||||
for player_id: int in _players:
|
||||
var queued: Dictionary = _pending[player_id]
|
||||
var command: PlayerCommand = queued.get(tick)
|
||||
@@ -136,6 +143,14 @@ func _apply_command(player: SimEntity, command: PlayerCommand) -> void:
|
||||
Movement.step(player, command, ground, sea_level)
|
||||
var sprinting: bool = command != null and command.is_pressed(PlayerCommand.BUTTON_SPRINT)
|
||||
Water.update(player, sea_level, drown_dps, sprinting)
|
||||
if player.action_cooldown > 0:
|
||||
player.action_cooldown -= 1
|
||||
if command == null or not command.is_pressed(PlayerCommand.BUTTON_FIRE):
|
||||
return
|
||||
if command.is_pressed(PlayerCommand.BUTTON_BUILD):
|
||||
return
|
||||
if command.selection == BOATHOOK_SLOT:
|
||||
Harvest.swing(player, ground, props, events)
|
||||
|
||||
|
||||
## Moves the sea surface. Takes effect on the next step.
|
||||
@@ -170,6 +185,8 @@ func state_hash() -> String:
|
||||
buffer.put_32(entity.stamina_ticks)
|
||||
buffer.put_32(entity.drown_ticks)
|
||||
buffer.put_u8(entity.drop_state)
|
||||
buffer.put_data(entity.materials.to_byte_array())
|
||||
buffer.put_32(entity.action_cooldown)
|
||||
for value: float in [entity.position.x, entity.position.y, entity.position.z]:
|
||||
buffer.put_64(roundi(value * 1000.0))
|
||||
for value: float in [entity.velocity.x, entity.velocity.y, entity.velocity.z]:
|
||||
|
||||
Reference in New Issue
Block a user