This commit is contained in:
Navid Sassan 2025-12-09 23:24:30 +01:00
parent d6750a8dfb
commit 7c1eb85053

View File

@ -58,6 +58,10 @@ local CONFIG = {
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) target_saturation = 0.45, -- Target saturation for optimal output (lower = more power)
-- Fuel monitoring
fuel_warning_threshold = 0.85, -- Warn when fuel is 90% used
fuel_shutdown_threshold = 0.90, -- Auto-shutdown when fuel is 95% used
-- 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)
display_interval = 0.5, -- Monitor refresh rate display_interval = 0.5, -- Monitor refresh rate
@ -111,6 +115,9 @@ local lastFluxUpdate = 0
local lastInputRate = -1 local lastInputRate = -1
local lastOutputRate = -1 local lastOutputRate = -1
-- Fuel warning throttle
local lastFuelWarning = 0
-- ============================================================================ -- ============================================================================
-- UTILITY FUNCTIONS -- UTILITY FUNCTIONS
-- ============================================================================ -- ============================================================================
@ -503,6 +510,26 @@ local function processStateMachine()
end end
end end
-- Check fuel level
local maxFuel = reactorInfo.maxFuelConversion or 1
if maxFuel <= 0 then maxFuel = 1 end
local fuelUsed = (reactorInfo.fuelConversion or 0) / maxFuel
if fuelUsed >= CONFIG.fuel_shutdown_threshold then
-- Fuel nearly depleted - initiate shutdown
if state ~= STATES.SHUTDOWN and state ~= STATES.EMERGENCY then
print("[FUEL] CRITICAL: Fuel " .. formatPercent(fuelUsed) .. " depleted! Initiating shutdown...")
shutdownRequested = true
end
elseif fuelUsed >= CONFIG.fuel_warning_threshold then
-- Fuel low - warn user (throttle to every 5 seconds)
local now = os.clock()
if now - lastFuelWarning >= 5 then
lastFuelWarning = now
print("[FUEL] WARNING: Fuel " .. formatPercent(fuelUsed) .. " used - running low!")
end
end
-- Check for shutdown request -- Check for shutdown request
if shutdownRequested then if shutdownRequested then
if reactorStatus == "cold" or reactorStatus == "cooling" then if reactorStatus == "cold" or reactorStatus == "cooling" then
@ -869,11 +896,17 @@ local function updateDisplay()
fieldColor = colors.red fieldColor = colors.red
end end
-- Show correct target based on state (55% during charging, 30% when running)
local fieldTarget = CONFIG.target_field_strength
if state == STATES.CHARGING or state == STATES.WARMING_UP then
fieldTarget = CONFIG.charge_field_target
end
mon.setCursorPos(1, y) mon.setCursorPos(1, y)
mon.setTextColor(colors.white) mon.setTextColor(colors.white)
mon.write("Field Strength: ") mon.write("Field Strength: ")
mon.setTextColor(fieldColor) mon.setTextColor(fieldColor)
mon.write(formatPercent(fieldPercent) .. " (Target: " .. formatPercent(CONFIG.target_field_strength) .. ")") mon.write(formatPercent(fieldPercent) .. " (Target: " .. formatPercent(fieldTarget) .. ")")
y = y + 1 y = y + 1
-- Field bar -- Field bar