P06-01: Fix review r01 findings for A06 reserve

Settle Mana raised above capacity between boundaries as recorded overflow
instead of rejecting saves or latching a fault, exclude destroyed facilities
from upkeep demand, and keep the depletion drill's outage sustained.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Takeshi
2026-10-19 20:56:57 +09:00
co-authored by Claude Opus 5.5
parent 65534cfd15
commit f247d19325
10 changed files with 104 additions and 21 deletions
+19 -9
View File
@@ -866,18 +866,18 @@ func _restore_snapshot_internal(snapshot: Dictionary, recovery_mode: bool) -> bo
# (0 stays stopped) only within capacity; nothing is silently truncated.
var restored_mana_reserve := ManaReserveCycle.new()
var saved_game_resources: Variant = snapshot[&"game_state"].get(&"resources", null)
if not saved_game_resources is Dictionary \
or not ManaReserveCycle.amount_is_valid(saved_game_resources.get(&"mana", saved_game_resources.get("mana", null))):
if not saved_game_resources is Dictionary:
return false
var saved_mana: Variant = saved_game_resources.get(&"mana", saved_game_resources.get("mana", null))
if runtime_data.has(&"mana_reserve"):
if not restored_mana_reserve.restore_snapshot(runtime_data[&"mana_reserve"]) \
# Between boundaries Mana may exceed capacity; the next boundary records
# and discards the excess, so only a valid integer amount is required.
if not ManaReserveCycle.stored_amount_is_valid(saved_mana) \
or not restored_mana_reserve.restore_snapshot(runtime_data[&"mana_reserve"]) \
or restored_mana_reserve.get_minute() > restored_minute:
return false
var last_reserve_flow := restored_mana_reserve.get_last_flow()
if not last_reserve_flow.is_empty() \
and int(saved_game_resources.get(&"mana", saved_game_resources.get("mana", 0))) > int(last_reserve_flow[&"after"]):
return false
elif not restored_mana_reserve.start_at(restored_minute):
elif not ManaReserveCycle.amount_is_valid(saved_mana) \
or not restored_mana_reserve.start_at(restored_minute):
return false
var restored_economy := EconomyService.new()
if not restored_economy.restore_snapshot(runtime_data[&"economy"]):
@@ -10741,6 +10741,16 @@ func _reservation_references_are_valid(
return false
return true
## A06 upkeep demand: every owned consumer, open or not, except destroyed
## facilities. Removed facilities are already unregistered from the network.
func _mana_reserve_demand() -> int:
var destroyed: Array[StringName] = []
for facility: FacilityInstance in facility_service.get_instances():
if facility.suspension_reason == &"DESTROYED":
destroyed.append(facility.instance_id)
return mana_network_service.get_total_consumer_demand(destroyed)
func _advance_mana(absolute_minute: int) -> void:
if _operations_tick_blocked:
return
@@ -10760,7 +10770,7 @@ func _advance_mana(absolute_minute: int) -> void:
# A06: generation and upkeep demand settle before local distribution and the
# whole-tower gate, so the network and projection see the committed reserve.
var reserve_flow := mana_reserve.advance_to(
absolute_minute, int(_state.get_resource(&"mana")), mana_network_service.get_total_consumer_demand()
absolute_minute, int(_state.get_resource(&"mana")), _mana_reserve_demand()
)
if not bool(reserve_flow.get(&"ok", false)):
_latch_infrastructure_failure(