.
This commit is contained in:
parent
e38fe600f7
commit
f4ce6980aa
@ -54,8 +54,9 @@ local CONFIG = {
|
|||||||
max_temperature = 8000, -- Emergency shutdown above this (Kelvin)
|
max_temperature = 8000, -- Emergency shutdown above this (Kelvin)
|
||||||
critical_temperature = 7500, -- Start reducing output at this temp
|
critical_temperature = 7500, -- Start reducing output at this temp
|
||||||
|
|
||||||
-- Saturation threshold for fuel conversion
|
-- Saturation control for optimal fuel conversion
|
||||||
min_saturation = 0.20, -- Below this, reactor produces less power
|
min_saturation = 0.20, -- Below this, reactor produces less power
|
||||||
|
target_saturation = 0.45, -- Target saturation for optimal output (lower = more power)
|
||||||
|
|
||||||
-- Update intervals (in seconds)
|
-- Update intervals (in seconds)
|
||||||
update_interval = 0.1, -- Main loop speed (faster = more responsive)
|
update_interval = 0.1, -- Main loop speed (faster = more responsive)
|
||||||
@ -402,22 +403,47 @@ local function calculateOutputRate()
|
|||||||
result = math.floor(generationRate * 0.8)
|
result = math.floor(generationRate * 0.8)
|
||||||
reason = state .. " - 80% of generation"
|
reason = state .. " - 80% of generation"
|
||||||
else
|
else
|
||||||
-- Normal operation
|
-- Normal operation with saturation targeting
|
||||||
local tempFactor = 1.0
|
local tempFactor = 1.0
|
||||||
|
local tempCritical = false
|
||||||
if temp > CONFIG.critical_temperature then
|
if temp > CONFIG.critical_temperature then
|
||||||
local overTemp = temp - CONFIG.critical_temperature
|
local overTemp = temp - CONFIG.critical_temperature
|
||||||
local tempRange = CONFIG.max_temperature - CONFIG.critical_temperature
|
local tempRange = CONFIG.max_temperature - CONFIG.critical_temperature
|
||||||
tempFactor = 1.0 - (overTemp / tempRange) * 0.5
|
tempFactor = 1.0 - (overTemp / tempRange) * 0.5
|
||||||
reason = "temp " .. formatTemp(temp) .. " > critical, factor=" .. string.format("%.2f", tempFactor)
|
tempCritical = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local outputRate = generationRate * tempFactor
|
-- Saturation-based output adjustment
|
||||||
|
-- Target saturation for optimal fuel conversion (lower sat = more power)
|
||||||
|
local targetSat = CONFIG.target_saturation
|
||||||
|
local satError = saturation - targetSat -- positive = too high, negative = too low
|
||||||
|
|
||||||
if saturation > 0.8 then
|
-- Scale factor: adjust output by up to 50% based on saturation error
|
||||||
outputRate = generationRate * 1.1 * tempFactor
|
local satFactor = 1.0 + satError
|
||||||
if reason == "" then reason = "high saturation (110%)" end
|
satFactor = math.max(0.5, math.min(1.5, satFactor)) -- Clamp to 50%-150%
|
||||||
elseif reason == "" then
|
|
||||||
reason = "normal operation"
|
-- IMPORTANT: If temperature is critical, don't increase output to drain saturation
|
||||||
|
-- Temperature safety takes priority over saturation optimization
|
||||||
|
if tempCritical and satFactor > 1.0 then
|
||||||
|
satFactor = 1.0 -- Cap at 100%, don't try to drain saturation when hot
|
||||||
|
end
|
||||||
|
|
||||||
|
local outputRate = generationRate * tempFactor * satFactor
|
||||||
|
|
||||||
|
-- Build reason string
|
||||||
|
local satPct = string.format("%.0f%%", saturation * 100)
|
||||||
|
local targetPct = string.format("%.0f%%", targetSat * 100)
|
||||||
|
if tempCritical then
|
||||||
|
reason = "TEMP CRITICAL " .. formatTemp(temp) .. ", factor=" .. string.format("%.2f", tempFactor)
|
||||||
|
if satFactor < 1.0 then
|
||||||
|
reason = reason .. ", sat " .. satPct .. " low"
|
||||||
|
end
|
||||||
|
elseif satError > 0.05 then
|
||||||
|
reason = "sat " .. satPct .. " > " .. targetPct .. " target, +" .. string.format("%.0f%%", (satFactor - 1) * 100) .. " output"
|
||||||
|
elseif satError < -0.05 then
|
||||||
|
reason = "sat " .. satPct .. " < " .. targetPct .. " target, " .. string.format("%.0f%%", (satFactor - 1) * 100) .. " output"
|
||||||
|
else
|
||||||
|
reason = "sat " .. satPct .. " at target"
|
||||||
end
|
end
|
||||||
|
|
||||||
result = math.max(0, math.floor(outputRate))
|
result = math.max(0, math.floor(outputRate))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user