Skip to content

Commit 66e358e

Browse files
committed
Fix grid tree flow, it was using old capacity equation instead of proper flow, fix 5731
1 parent f748924 commit 66e358e

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

LuaRules/Gadgets/gfx_overdrive_cables.lua

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,17 +1528,15 @@ local function ComputeMaxPotentials(flowMode)
15281528

15291529
local flow, flowSrcSubtree
15301530
if flowMode then
1531-
local totalPcur, totalDcur = subPcur[r], subDcur[r]
1532-
local sPc, sDc = subPcur[cid], subDcur[cid]
1533-
local oPc, oDc = totalPcur - sPc, totalDcur - sDc
1534-
local flowAB = (sPc < oDc) and sPc or oDc
1535-
local flowBA = (oPc < sDc) and oPc or sDc
1536-
if flowAB >= flowBA then
1537-
flow, flowSrcSubtree = flowAB, true
1531+
-- Realized flow across a tree edge is defined by conservation.
1532+
-- The grids are MSTs, so each edge is the only path between its subtree S (cid side) and the rest
1533+
-- Power that physically crosses it equals S's net export flow = | subPcur[S] - subDcur[S] |
1534+
local net = subPcur[cid] - subDcur[cid]
1535+
if net >= 0 then
1536+
flow, flowSrcSubtree = net, true -- subtree exports → cid is source
15381537
else
1539-
flow, flowSrcSubtree = flowBA, false
1538+
flow, flowSrcSubtree = -net, false -- subtree imports → parent is source
15401539
end
1541-
if flow < 0 then flow = 0 end
15421540
if flow <= 0 then flowSrcSubtree = potentialSrcSubtree end
15431541
else
15441542
flow, flowSrcSubtree = 0, potentialSrcSubtree
@@ -2319,7 +2317,7 @@ local function GenerateOrganicTree()
23192317
local k = 0
23202318
for i = 1, n do
23212319
local e = renderEdges[i]
2322-
local cap = max(1, e.capacity or 1)
2320+
local cap = max(1, e.capacity or 1)
23232321
local appearTime = (e.appearFrame or 0) / GAME_SPEED
23242322
local witherTime = e.witherFrame and (e.witherFrame / GAME_SPEED) or 0
23252323
local eff = (e.eff or 0) * (e.maxxed and -1 or 1)

0 commit comments

Comments
 (0)