B5: Inventory and pickups

Five slots plus the always-carried boathook (selection 0), ammunition carried
apart from the slots, and items lying in the world as pickup entities. All
changes are made by the server from commands: interact picks up the nearest
pickup in reach, drop (new BUTTON_DROP) leaves the held stack at the feet, and
both act once per press. A full inventory swaps the held item. Consumables and
thrown weapons stack; ammunition stops at its cap and leaves the rest on the
ground. An eliminated player drops everything on a ring around where they fell,
and the simulation now emits an "eliminated" event when health reaches 0.

Item definitions are ItemDef resources built by ItemCatalog from the tables in
Tuning (WEAPONS, ITEMS and the new AMMO), so a new item is a data change only.

Closes #19

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 17:19:45 -05:00
co-authored by Claude Opus 5.5
parent ced13f1f42
commit e58d6140cc
12 changed files with 800 additions and 3 deletions
+46 -1
View File
@@ -33,6 +33,9 @@ var structures: StructureSet = StructureSet.new()
## The sky barge, from start_drop() on. Null in matches and tests that start on foot.
var drop: Drop = null
## Items lying in the world, as entity IDs in ascending order. See Inventory.
var pickups: Array[int] = []
## 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] = []
@@ -76,6 +79,7 @@ func add_player() -> int:
player.on_ground = true
player.health = Tuning.PLAYER_MAX_HEALTH
Water.reset(player)
Inventory.reset(player)
if drop != null and not drop.finished:
Drop.board(player, drop.barge_position(tick))
_players.append(player.id)
@@ -120,10 +124,13 @@ func step() -> void:
var command: PlayerCommand = queued.get(tick)
queued.erase(tick)
var player: SimEntity = entities.find(player_id)
if player.eliminated:
continue
if player.drop_state == Drop.ABOARD:
_ride(player, command)
else:
_apply_command(player, command)
_check_eliminations()
if drop != null and not drop.finished and drop.is_over(tick + 1):
# The end of the route: everyone still aboard goes over the side.
for player_id: int in _players:
@@ -151,6 +158,16 @@ func _apply_command(player: SimEntity, command: PlayerCommand) -> void:
Water.update(player, sea_level, drown_dps, sprinting)
if player.action_cooldown > 0:
player.action_cooldown -= 1
var held: int = command.buttons if command != null else 0
var pressed: int = held & ~player.prev_buttons
player.prev_buttons = held
if command != null and not command.is_pressed(PlayerCommand.BUTTON_BUILD):
Inventory.select(player, command.selection)
if Harvest.can_swing(player):
if pressed & PlayerCommand.BUTTON_INTERACT:
Inventory.interact(self, player)
if pressed & PlayerCommand.BUTTON_DROP:
Inventory.drop_held(self, player)
if command == null or not command.is_pressed(PlayerCommand.BUTTON_FIRE):
return
if not Building.is_allowed(player):
@@ -158,10 +175,22 @@ func _apply_command(player: SimEntity, command: PlayerCommand) -> void:
if command.is_pressed(PlayerCommand.BUTTON_BUILD):
Building.act(self, player, command)
return
if command.selection == BOATHOOK_SLOT:
if player.selected == BOATHOOK_SLOT:
Harvest.swing(player, ground, props, events, structures)
## Marks players whose health reached 0 as eliminated, and drops what they carried.
func _check_eliminations() -> void:
for player_id: int in _players:
var player: SimEntity = entities.find(player_id)
if player.eliminated or player.health > 0:
continue
player.eliminated = true
player.velocity = Vector3.ZERO
events.append({"type": "eliminated", "player": player_id, "by": player.last_attacker})
Inventory.drop_all(self, player)
## Moves the sea surface. Takes effect on the next step.
func set_sea_level(level: float) -> void:
sea_level = level
@@ -207,6 +236,22 @@ func state_hash() -> String:
buffer.put_u8(entity.drop_state)
buffer.put_data(entity.materials.to_byte_array())
buffer.put_32(entity.action_cooldown)
buffer.put_32(entity.armor)
buffer.put_32(entity.selected)
for array: PackedInt32Array in [entity.slot_items, entity.slot_counts, entity.slot_rounds, entity.slot_tiers, entity.ammo]:
buffer.put_data(array.to_byte_array())
buffer.put_32(entity.reload_ticks)
buffer.put_64(roundi(entity.bloom * 1000.0))
buffer.put_32(entity.prev_buttons)
buffer.put_u8(1 if entity.eliminated else 0)
buffer.put_32(entity.last_attacker)
buffer.put_32(entity.item)
buffer.put_32(entity.item_count)
buffer.put_32(entity.item_rounds)
buffer.put_32(entity.item_tier)
buffer.put_32(entity.owner_id)
for value: float in [entity.origin.x, entity.origin.y, entity.origin.z]:
buffer.put_64(roundi(value * 1000.0))
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]: