Buildings hold their own resource stock, and orders queue until supplied #16

Closed
opened 2026-08-11 13:36:42 +00:00 by metaheavens · 1 comment
Owner

Part 3 of #12. Depends on the fleet-cargo ticket.

#12: "anything produced needs resources to be transported" and "if no resources are available, the ship crafting is queued". So a building cannot simply deduct from the global pool at the moment of purchase - it needs a local stock that something has to deliver into.

Today BuildController refuses outright: GameState.spend(...) fails and it prints "Not enough rocks".

Scope

  • Per-building resource stock.
  • Production (ship crafting at the ship crafter) consumes from that building's stock.
  • An order placed without enough stock is QUEUED rather than rejected, and completes on its own once the stock arrives.
  • Show the queue state at the building.

Deliberately not here: how resources get to the building. Until the following tickets land, the queue can be fed by the manual fleet route.

Acceptance

  • Ordering with a full stock produces immediately.
  • Ordering with an empty stock queues rather than failing, and completes once supplied.
  • The queue survives the scene swap to a planet and back.
Part 3 of #12. Depends on the fleet-cargo ticket. #12: "anything produced needs resources to be transported" and "if no resources are available, the ship crafting is queued". So a building cannot simply deduct from the global pool at the moment of purchase - it needs a local stock that something has to deliver into. Today `BuildController` refuses outright: `GameState.spend(...)` fails and it prints "Not enough rocks". **Scope** - Per-building resource stock. - Production (ship crafting at the ship crafter) consumes from that building's stock. - An order placed without enough stock is QUEUED rather than rejected, and completes on its own once the stock arrives. - Show the queue state at the building. **Deliberately not here:** how resources get to the building. Until the following tickets land, the queue can be fed by the manual fleet route. **Acceptance** - Ordering with a full stock produces immediately. - Ordering with an empty stock queues rather than failing, and completes once supplied. - The queue survives the scene swap to a planet and back.
Author
Owner

Done in 3573ccf.

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.

Building records gained 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 had to remember which crafter it was opened for: _process() clears current_building while any menu is open, so by the next frame the menu no longer knew. It shows the ore delivered HERE rather than the bank - showing the bank would promise something the crafter cannot actually build.

Test

tests/test_building_stock_queue.gd. Four mutations caught: queueing deducting from the bank (the old behaviour), producing on a part-delivery, dropping the completed vessel instead of owing it, and stalling once the space scene is gone.

A fifth mutation initially slipped through and is worth recording. The test claimed "one delivery clears all the orders it covers", but changing the while to an if - producing one order per frame - still passed, because a 0.4s wall-clock wait gives it plenty of frames to dribble them out. A timed check cannot tell "cleared at once" from "cleared eventually". It now queues three orders and allows two TICKS, so only clearing them together passes, and the mutation fails as it should.

Full suite: 44/44.

Done in 3573ccf. `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. Building records gained 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 had to remember which crafter it was opened for: `_process()` clears `current_building` while any menu is open, so by the next frame the menu no longer knew. It shows the ore delivered HERE rather than the bank - showing the bank would promise something the crafter cannot actually build. ## Test `tests/test_building_stock_queue.gd`. Four mutations caught: queueing deducting from the bank (the old behaviour), producing on a part-delivery, dropping the completed vessel instead of owing it, and stalling once the space scene is gone. A fifth mutation initially slipped through and is worth recording. The test claimed "one delivery clears all the orders it covers", but changing the `while` to an `if` - producing one order per frame - still passed, because a 0.4s wall-clock wait gives it plenty of frames to dribble them out. A timed check cannot tell "cleared at once" from "cleared eventually". It now queues three orders and allows two TICKS, so only clearing them together passes, and the mutation fails as it should. Full suite: **44/44**.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
metaheavens/spaceship#16
No description provided.