#99 (#97a): buildings have health, and can be destroyed

Nothing can attack a structure that cannot be hurt, so this is the floor the
rest of #97 stands on.

max_hp is per definition - an extractor bolted to a rock is not the
mothership - and the current value lives on the RECORD in GameState, not on
the Building node. Main.tscn is torn down and rebuilt on every trip to a
planet surface, so damage kept on a node would heal itself the moment the
player landed.

A record written before this carries no hp field at all. That reads as
undamaged rather than as zero, or an existing save would open on a field of
wrecks.

The mothership cannot be destroyed - it floors at 1hp. The bank, the hangar
and research all live there and a wiped fleet rebuilds there, so losing it
would be a soft-lock with no route back. Keyed on the "bank" capability
rather than on the type: whatever building holds the bank is the one that
cannot be lost.

Destroying a hub retires its transporters. Everything else keyed on a
building id already copes with the building being gone - a transporter
mid-delivery puts its cargo back rather than destroying it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Loïc Wisniewski 2026-08-23 13:37:40 +02:00
commit c221584848
12 changed files with 293 additions and 0 deletions

View file

@ -22,9 +22,27 @@ var spawned: Array = []
func _ready() -> void:
# #99: the record is the truth, so the node follows it out. Connected
# here rather than in Building.gd because the field owns `spawned` and
# would otherwise be left holding a freed node.
if not GameState.building_destroyed.is_connected(_on_building_destroyed):
GameState.building_destroyed.connect(_on_building_destroyed)
rebuild_all()
func _on_building_destroyed(building_id: int, _type: String) -> void:
var kept: Array = []
for b in spawned:
if not is_instance_valid(b):
continue
if int(b.building_id) == building_id:
BuildingExplosionVFX.spawn(get_tree().root, b.global_position)
b.queue_free()
continue
kept.append(b)
spawned = kept
func rebuild_all() -> void:
for b in spawned:
if is_instance_valid(b):