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
+4 -3
View File
@@ -231,11 +231,12 @@ func get_storage_current(node_id: StringName) -> int:
return int(_nodes[node_id][&"current"])
## Upkeep demand of every registered consumer, including disabled ones.
func get_total_consumer_demand() -> int:
## Upkeep demand of every registered consumer, including disabled ones,
## except the given consumer ids (for example destroyed facilities).
func get_total_consumer_demand(excluded_ids: Array = []) -> int:
var total := 0
for node_id: StringName in _nodes:
if int(_nodes[node_id][&"kind"]) == NodeKind.CONSUMER:
if int(_nodes[node_id][&"kind"]) == NodeKind.CONSUMER and not node_id in excluded_ids:
total += int(_nodes[node_id][&"demand"])
return total
+9 -2
View File
@@ -34,10 +34,12 @@ func get_last_flow() -> Dictionary:
## Processes every boundary in (last boundary, minute]. Boundaries already
## processed are no-ops, so per-minute callers and same-minute retries are safe.
## Mana may rise between boundaries (event refunds, commands); anything above
## capacity is discarded and recorded as overflow at the next boundary.
func advance_to(minute: Variant, before: Variant, demand: Variant) -> Dictionary:
if _minute < 0:
return _failure(&"NOT_STARTED")
if typeof(minute) != TYPE_INT or not _amount(before) or before > CAPACITY \
if typeof(minute) != TYPE_INT or not _amount(before) \
or typeof(demand) != TYPE_INT or demand < 0 or demand > LIMIT or minute < _minute:
return _failure(&"INVALID_FLOW")
var boundary: int = minute - minute % INTERVAL_MINUTES
@@ -69,9 +71,14 @@ static func plan(before: int, demand: int, furnace: int, start: int, end: int) -
&"consumed": consumed, &"shortage": demand - consumed,
&"overflow": maxi(remaining - CAPACITY, 0), &"after": mini(remaining, CAPACITY)}
## Legacy saves without a reserve receipt must already fit the approved capacity.
static func amount_is_valid(value: Variant) -> bool:
return _amount(value) and value <= CAPACITY
## A current save may hold more than capacity until the next boundary settles it.
static func stored_amount_is_valid(value: Variant) -> bool:
return _amount(value)
func create_snapshot() -> Dictionary:
return {&"version": VERSION, &"policy_id": POLICY_ID, &"capacity": CAPACITY,
&"generation": WORLD_TREE_GENERATION, &"interval_minutes": INTERVAL_MINUTES,
@@ -97,7 +104,7 @@ func restore_snapshot(source: Variant) -> bool:
for key: Variant in flow:
if not _amount(flow[key]):
return false
if flow["to_minute"] != source["minute"] or flow["before"] > CAPACITY \
if flow["to_minute"] != source["minute"] \
or flow["generation"] != WORLD_TREE_GENERATION \
or flow["from_minute"] + INTERVAL_MINUTES != flow["to_minute"]:
return false