Buildings produce from their own stock, and queue orders until supplied

Forgejo #16, part 3 of #12. BuildController deducted the cost from the
bank at the moment of purchase and refused outright with "Not enough
rocks", so nothing ever had to be delivered anywhere. Each building now
carries its own stock, and an order it cannot pay for yet is QUEUED and
completes by itself once ore arrives.

Records get an `id` because a building has to be referable across the
space <-> planet-surface scene swap, when every Building NODE has been
destroyed and rebuilt. Position would nearly work and then fail on two
buildings placed on the same spot.

Production advances in the GameState autoload, the same way extractor
haulers already do, so an order can complete while the player is down a
gravity well. A finished vessel becomes `ships_owed` rather than being
handed straight to a Fleet that may not exist, and the fleet claims what
it is owed when it next has room.

The craft menu remembers which crafter it was opened for: _process()
clears current_building while any menu is open, so by the next frame the
menu would no longer know. It shows the ore delivered HERE rather than
the bank, since showing the bank would promise something the crafter
cannot actually build.

Ship crafting cannot be supplied until #17 lands - nothing yet moves ore
into a building.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Loïc Wisniewski 2026-08-11 16:18:44 +02:00
commit 3573ccf44f
6 changed files with 371 additions and 11 deletions

View file

@ -83,6 +83,8 @@ const BUILDING_INFO: Dictionary = {
# Which structure the popup is currently offering to build, or "" when it is
# only explaining something that cannot be built right now.
var pending_build_type: String = ""
# Which crafter the craft menu is showing (see _on_action_pressed).
var craft_building_id: int = 0
var current_building: Node2D = null
var pending_building: Node2D = null
@ -153,6 +155,11 @@ func _process(delta: float) -> void:
build_extractor_button.enabled = _planet_under_fleet() != null \
and GameState.is_building_unlocked(GameState.BUILDING_EXTRACTOR)
if craft_menu.visible:
# Live, so a delivery arriving while the menu is open visibly works
# the queue down instead of looking stuck.
_refresh_craft_status()
if world_map.visible or build_menu.visible or craft_menu.visible \
or formation_menu.visible or skill_menu.visible:
current_building = null
@ -420,19 +427,30 @@ func _on_unlock_pressed() -> void:
func _refresh_craft_status() -> void:
craft_status.text = "Interceptor %d rocks You have %d Fleet %d/%d" % [
GameState.SHIP_COST, GameState.rocks, fleet.ships.size(), GameState.max_fleet_size()
# "Here" is the ore delivered to THIS crafter, not the bank: since #16 a
# building builds out of its own stock, and showing the bank would say
# you can afford something the crafter cannot actually make.
var queued: int = GameState.pending_orders(craft_building_id)
var stock: int = GameState.building_stock(craft_building_id)
var queue_text: String = "" if queued == 0 else " Queued %d" % queued
craft_status.text = "Interceptor %d ore Here %d%s Fleet %d/%d" % [
GameState.SHIP_COST, stock, queue_text,
fleet.ships.size(), GameState.max_fleet_size()
]
func _on_craft_interceptor() -> void:
if fleet.ships.size() >= GameState.max_fleet_size():
if craft_building_id == 0:
return
# Still refused when there is nowhere to put the vessel - queueing an
# order that can never be delivered would just bank ships_owed forever.
if fleet.ships.size() + GameState.ships_owed + GameState.pending_orders(craft_building_id) \
>= GameState.max_fleet_size():
craft_status.text = "Fleet is full (%d slots)" % GameState.max_fleet_size()
return
if not GameState.spend(GameState.SHIP_COST):
craft_status.text = "Not enough rocks (need %d, have %d)" % [GameState.SHIP_COST, GameState.rocks]
return
fleet.add_ship()
# No affordability check: an order the crafter cannot pay for yet is
# QUEUED, and completes by itself once ore is delivered here (#16).
GameState.queue_order(craft_building_id)
_refresh_craft_status()