#138: structures and doctrines cost more than rocks, and more the deeper they are

Both halves of the ticket, in the shape vessels have used since gas bombers
and laser ships: a definition carries an ore figure and, when it wants more
than ore, a dictionary that IS the price. `building_costs()` and
`skill_costs()` answer it the way `product_costs()` already did, so there is
one question with one answer whatever is being bought, and every payment
path now goes through `spend_resources` rather than `spend`.

Seven of ten structures and thirteen of seventeen doctrines now want gas,
energy or dark matter alongside their rocks, and the totals climb with tree
depth - structures 16/31/58/62/96 by depth, doctrines 15/30/73/96/143/258/530.

The constraint that shaped the table is REACHABILITY, and it is the reason
some prices stayed ore-only. Energy exists only where a gas burner stands,
and a gas burner needs Power Systems - so nothing at or before that depth
may be priced in energy, or it is a wall with no way through. Dark matter is
rarer still and appears once, on the deepest node in the game. The extractor
stays rocks-only despite its depth allowing gas, because the quest chain
reaches it before it has sent the player for any.

test_progressive_costs checks those as properties rather than transcribing
the numbers, so rebalancing a price costs nothing while breaking the shape
fails: nothing unreachable at its own depth, prices rising with depth, the
ore field agreeing with the dictionary (repairs quote the field alone, since
a repair drone carries ore and nothing else), and the quest chain never
asking for a structure it has not funded.

Two things cleaned up on the way:

- The per-building cost constants in GameState are gone. Nothing but tests
  used them, and they were a second copy of a number the definitions already
  hold - exactly what would drift once a price gained a resource.
- research_for_building() returns a display NAME, and the id-keyed half of
  the tree wants an id. That mix-up is silent - skill_depth() of a name finds
  no node and answers 0, so a deep structure reads as an ungated one, which
  is how the first draft of the test let an unreachable price through.
  research_node_for_building() is the id, and the name is expressed from it.

PriceTag no longer rebuilds its labels when re-told the same price; it
refreshes the held figures instead. The craft menu re-states prices every
frame and the build menu now does too, so that was a dozen Labels being torn
down and rebuilt sixty times a second.
This commit is contained in:
Loïc Wisniewski 2026-08-28 15:30:30 +02:00
commit 1ece202731
22 changed files with 435 additions and 46 deletions

View file

@ -330,9 +330,12 @@ func transfer_gas_to_building(id: int, amount: int) -> int:
func transfer_gas_to_fleet(id: int, amount: int) -> int:
return transfer_resource_to_fleet(id, RESOURCE_GAS, amount)
const MOTHERSHIP_COST: int = 20
const SHIP_CRAFTER_COST: int = 12
const SHIP_COST: int = 6
# #138: the per-building cost constants that used to sit here are gone. A
# structure's price lives in its own BuildingDefinition and is read through
# building_costs(), which is the only thing that knows about the resources
# beyond ore that some of them now want. Two places holding the same number
# is how they end up disagreeing.
# --- Buildings -------------------------------------------------------------
@ -361,11 +364,6 @@ const BUILDING_SHIP_LAB: String = "ship_lab"
# inventory exactly like every other building (#54).
const BUILDING_GAS_BURNER: String = "gas_burner"
const COMMAND_CENTER_COST: int = 15
const EXTRACTOR_COST: int = 25
const TRANSPORT_HUB_COST: int = 30
const SHIP_LAB_COST: int = 35
const GAS_BURNER_COST: int = 30
var buildings: Array = []
@ -411,6 +409,7 @@ const SKILL_TREE: Array = [
# attacking your structures is available at about the time the waves
# start being able to hurt them.
"id": "forward_bases", "name": "Forward Bases", "cost": 30, "requires": "coordination",
"costs": {"ore": 30, "gas": 12},
"x": 0.66, "unlocks": BUILDING_OUTPOST, "research_points": 1,
"desc": "Build outposts: forward positions vessels can be stationed at, to hold ground you are not standing on.",
},
@ -419,6 +418,7 @@ const SKILL_TREE: Array = [
# applies to outposts already standing, not only to new ones, so
# researching it never means demolishing and rebuilding.
"id": "garrison_bays", "name": "Garrison Bays", "cost": 110, "requires": "forward_bases",
"costs": {"ore": 110, "gas": 35},
"x": 0.66, "outpost_bonus": 1, "research_points": 2,
"icon": 40,
"desc": "Permanent: +1 berth at every outpost, including ones already built.",
@ -429,6 +429,7 @@ const SKILL_TREE: Array = [
# hand has become work, and it has shipyards behind it because it
# manages what shipyards do.
"id": "logistics_command", "name": "Logistics Command", "cost": 140,
"costs": {"ore": 140, "gas": 40},
"requires": "vessel_science", "x": 0.94,
"unlocks": BUILDING_PLANNING_CENTER, "research_points": 3,
"desc": "Build a planning center: set how many of each vessel should always exist, and the crafters are kept working until they do.",
@ -438,6 +439,7 @@ const SKILL_TREE: Array = [
# is infrastructure that looks after infrastructure, and it should
# arrive after the player has some worth looking after.
"id": "field_engineering", "name": "Field Engineering", "cost": 95,
"costs": {"ore": 95, "gas": 35, "energy": 20},
"requires": "power_systems", "x": 0.34,
"unlocks": BUILDING_WORKSHOP, "research_points": 2,
"desc": "Build spacial workshops. Their drones fly out and repair damaged structures, spending ore delivered to the workshop.",
@ -446,28 +448,33 @@ const SKILL_TREE: Array = [
# Same shape as freight_yards and garrison_bays: a permanent bonus
# that reaches workshops already standing.
"id": "drone_bays", "name": "Drone Bays", "cost": 150,
"costs": {"ore": 150, "gas": 50, "energy": 35},
"requires": "field_engineering", "x": 0.34,
"workshop_bonus": 1, "research_points": 2, "icon": 43,
"desc": "Permanent: +1 repair drone at every spacial workshop, including ones already built.",
},
{
"id": "freight", "name": "Freight Handling", "cost": 40, "requires": "logistics",
"costs": {"ore": 40, "gas": 15},
"x": 0.18, "unlocks": BUILDING_TRANSPORT_HUB, "research_points": 1,
"desc": "Build transport hubs. Each hub includes its own automatic transporters.",
},
{
"id": "vessel_science", "name": "Vessel Science", "cost": 35, "requires": "shipyards",
"costs": {"ore": 35, "gas": 10},
"x": 0.82, "unlocks": BUILDING_SHIP_LAB, "research_points": 1,
"desc": "Build ship labs, where each vessel type is upgraded and new ones unlocked.",
},
{
"id": "freight_yards", "name": "Freight Yards", "cost": 80, "requires": "freight",
"costs": {"ore": 80, "gas": 30},
"x": 0.18, "hub_bonus": 1, "research_points": 2,
"icon": 12,
"desc": "Permanent: +1 transporter stationed at every hub, including ones already built.",
},
{
"id": "power_systems", "name": "Power Systems", "cost": 45, "requires": "freight",
"costs": {"ore": 45, "gas": 35},
"x": 0.50, "unlocks": BUILDING_GAS_BURNER, "research_points": 2,
"desc": "Build gas burners. Each converts gas into energy at its own site - hub transporters keep it stocked and collect what it makes.",
},
@ -490,12 +497,14 @@ const SKILL_TREE: Array = [
# someone else's lane.
# Also cut (70 ore / 2 points), for the same reason as wing.
"id": "squadron", "name": "Squadron Doctrine", "cost": 35, "requires": "wing",
"costs": {"ore": 35, "gas": 12},
"x": 0.82, "fleet_bonus": 1, "research_points": 1,
"icon": 2,
"desc": "Permanent: +1 vessel in the fleet.",
},
{
"id": "armada", "name": "Armada Doctrine", "cost": 90, "requires": "squadron",
"costs": {"ore": 90, "gas": 30, "energy": 15},
"x": 0.82, "fleet_bonus": 1, "research_points": 2,
"icon": 2,
"desc": "Permanent: +1 vessel in the fleet.",
@ -506,12 +515,14 @@ const SKILL_TREE: Array = [
# that only ever does one thing; two larger, costlier steps carry the
# ceiling from 6 to 10 while keeping the branch a readable length.
"id": "battlegroup", "name": "Battlegroup Doctrine", "cost": 180, "requires": "armada",
"costs": {"ore": 180, "gas": 60, "energy": 40},
"x": 0.82, "fleet_bonus": 2, "research_points": 4,
"icon": 2,
"desc": "Permanent: +2 vessels in the fleet.",
},
{
"id": "grand_fleet", "name": "Grand Fleet Doctrine", "cost": 320, "requires": "battlegroup",
"costs": {"ore": 320, "gas": 110, "energy": 80, "dark_matter": 20},
"x": 0.82, "fleet_bonus": 2, "research_points": 6,
"icon": 2,
"desc": "Permanent: +2 vessels in the fleet.",
@ -570,9 +581,26 @@ func prerequisite_met(id: String) -> bool:
return node.requires == "" or is_unlocked(node.requires)
# What one doctrine costs. Same rule as buildings and vessels (#138): the
# node's own dictionary when it has one, its ore figure otherwise.
#
# `cost` stays the ore figure either way rather than being folded into the
# dictionary and deleted, so the tree's own display - and everything that
# ever compared two nodes by price - keeps working on a plain number.
func skill_costs(id: String) -> Dictionary:
var node: Dictionary = skill_node(id)
if node.is_empty():
return {}
var costs: Dictionary = node.get("costs", {})
if not costs.is_empty():
return costs.duplicate()
return {RESOURCE_ORE: int(node.cost)} if int(node.cost) > 0 else {}
func can_unlock(id: String) -> bool:
var node: Dictionary = skill_node(id)
return not is_unlocked(id) and prerequisite_met(id) and can_afford(int(node.cost)) \
return not is_unlocked(id) and prerequisite_met(id) \
and can_afford_resources(skill_costs(id)) \
and research_points >= skill_research_point_cost(id)
@ -584,7 +612,7 @@ func unlock(id: String) -> bool:
if not can_unlock(id):
return false
var node: Dictionary = skill_node(id)
if not spend(int(node.cost)):
if not spend_resources(skill_costs(id)):
return false
var points_needed: int = skill_research_point_cost(id)
if points_needed > 0:
@ -621,13 +649,24 @@ func is_building_unlocked(type: String) -> bool:
return true
func research_for_building(type: String) -> String:
# The doctrine that unlocks a structure, BY ID - the handle everything else
# in the tree is keyed on (skill_depth, skill_costs, is_unlocked).
func research_node_for_building(type: String) -> String:
for node in SKILL_TREE:
if node.get("unlocks", "") == type:
return node.name
return String(node.id)
return ""
# The same thing by NAME, which is what a message shows the player. Kept
# apart from the id above because the two are easy to mix up and the mistake
# is silent: skill_depth() of a display name finds no node and answers 0, so
# a deep structure reads as an ungated one.
func research_for_building(type: String) -> String:
var id: String = research_node_for_building(type)
return "" if id == "" else String(skill_node(id).name)
func max_fleet_size() -> int:
if intro_fleet_size > 0:
return mini(intro_fleet_size, DEFAULT_FORMATION.size())
@ -770,6 +809,20 @@ func find_building(id: int) -> Dictionary:
# node would heal itself the moment the player landed - the same reason the
# buildings themselves live here.
# What one structure costs, in every resource it wants.
#
# #138: the same shape product_costs() already answers for vessels - the
# dictionary when a definition carries one, the ore figure otherwise - so
# there is one question with one answer whatever is being bought.
func building_costs(type: String) -> Dictionary:
var definition: Resource = building_definition(type)
if definition == null:
return {}
if not definition.build_resource_costs.is_empty():
return definition.build_resource_costs.duplicate()
return {RESOURCE_ORE: int(definition.cost)} if int(definition.cost) > 0 else {}
func building_definition(type: String) -> Resource:
return BUILDING_DEFINITIONS.get_definition(type)