Cap fleet cargo capacity by composition (#56)
The fleet hold was unbounded - GameState.fleet_inventory had no total_capacity, so a lone ship could carry unlimited resources. Capacity is now data-driven: only vessels declaring the "cargo" capability contribute their cargo_capacity stat (interceptor: 20; shield vessel and gas bomber: 0, unarmed transporters are never in the fleet at all). Fleet.gd recomputes it in the one place composition can change (spawn_ships/add_ship/store_ship/_on_ship_destroyed), which also covers the space<->surface scene-swap restore since that goes through spawn_ships(). Rock.gd and GasVentField.gd (the two "fly over it to collect" pickup paths) now check what collect_cargo()/collect_gas_cargo() actually accepted before consuming their source, instead of assuming an unlimited hold. The HUD's FLEET HOLD caption shows the live total/cap. Also fixes test_resource_transfer.gd, which pushed more ore through a 2-ship fleet than the new cap allows - it now spawns the largest fleet every unlocked doctrine permits, since that test is about the transfer UI rather than the cap itself (test_fleet_cargo_limit.gd owns that).
This commit is contained in:
parent
cbe07bbb55
commit
f040327523
11 changed files with 250 additions and 12 deletions
40
GameState.gd
40
GameState.gd
|
|
@ -57,11 +57,14 @@ var fleet_gas_cargo: int:
|
|||
get: return fleet_inventory.amount(RESOURCE_GAS)
|
||||
set(value): fleet_inventory.set_amount(RESOURCE_GAS, value)
|
||||
|
||||
func collect_cargo(amount: int = 1) -> void:
|
||||
fleet_inventory.deposit(RESOURCE_ORE, amount)
|
||||
# Both return the amount actually accepted (#56: the fleet hold now has a
|
||||
# finite total_capacity), so a collector can tell a full hold apart from a
|
||||
# successful pickup instead of assuming everything offered was taken.
|
||||
func collect_cargo(amount: int = 1) -> int:
|
||||
return fleet_inventory.deposit(RESOURCE_ORE, amount)
|
||||
|
||||
func collect_gas_cargo(amount: int = 1) -> void:
|
||||
fleet_inventory.deposit(RESOURCE_GAS, amount)
|
||||
func collect_gas_cargo(amount: int = 1) -> int:
|
||||
return fleet_inventory.deposit(RESOURCE_GAS, amount)
|
||||
|
||||
|
||||
func resource_types() -> PackedStringArray:
|
||||
|
|
@ -90,6 +93,16 @@ func fleet_resource(resource_type: String) -> int:
|
|||
return fleet_inventory.amount(resource_type)
|
||||
|
||||
|
||||
# #56: total across every resource type in the hold, and the combined cap
|
||||
# that limits it - a HUD readout wants both, not any one resource's amount.
|
||||
func fleet_cargo_used() -> int:
|
||||
return fleet_inventory.total()
|
||||
|
||||
|
||||
func fleet_cargo_total_capacity() -> int:
|
||||
return fleet_inventory.total_capacity
|
||||
|
||||
|
||||
func _inventory_for_record(record: Dictionary) -> RefCounted:
|
||||
var inventory: RefCounted = record.get("inventory") as RefCounted
|
||||
if inventory == null:
|
||||
|
|
@ -633,6 +646,25 @@ func shield_recharge_time() -> float:
|
|||
var definition: Resource = VESSEL_DEFINITIONS.with_capability("shield")
|
||||
return vessel_stat(definition.definition_id, "shield_recharge")
|
||||
|
||||
# #56: sums cargo_capacity over ships that actually declare the "cargo"
|
||||
# capability, so combat specialists (no capability, whatever their stat
|
||||
# dict says) contribute nothing - data-driven rather than a vessel-id list.
|
||||
# Takes the composition as an argument rather than reading it off a live
|
||||
# Fleet node: GameState has no fixed reference to "the" Fleet (space and a
|
||||
# planet surface each own a separate one), so the caller passes its own
|
||||
# Fleet.vessel_types().
|
||||
func fleet_cargo_capacity(vessel_types: PackedStringArray) -> int:
|
||||
var total: int = 0
|
||||
for vessel_type in vessel_types:
|
||||
if vessel_has_capability(vessel_type, "cargo"):
|
||||
total += int(vessel_stat(vessel_type, "cargo_capacity"))
|
||||
return total
|
||||
|
||||
|
||||
func sync_fleet_cargo_capacity(vessel_types: PackedStringArray) -> void:
|
||||
fleet_inventory.total_capacity = fleet_cargo_capacity(vessel_types)
|
||||
|
||||
|
||||
func transporter_load_limit() -> int:
|
||||
var definition: Resource = VESSEL_DEFINITIONS.with_capability("transport")
|
||||
return int(vessel_stat(definition.definition_id, "cargo_capacity"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue