diff --git a/de_react_auto b/de_react_auto index b66257f..1a7d755 100644 --- a/de_react_auto +++ b/de_react_auto @@ -58,6 +58,10 @@ local CONFIG = { min_saturation = 0.20, -- Below this, reactor produces less 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_interval = 0.1, -- Main loop speed (faster = more responsive) display_interval = 0.5, -- Monitor refresh rate @@ -111,6 +115,9 @@ local lastFluxUpdate = 0 local lastInputRate = -1 local lastOutputRate = -1 +-- Fuel warning throttle +local lastFuelWarning = 0 + -- ============================================================================ -- UTILITY FUNCTIONS -- ============================================================================ @@ -503,6 +510,26 @@ local function processStateMachine() 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 if shutdownRequested then if reactorStatus == "cold" or reactorStatus == "cooling" then @@ -869,11 +896,17 @@ local function updateDisplay() fieldColor = colors.red 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.setTextColor(colors.white) mon.write("Field Strength: ") mon.setTextColor(fieldColor) - mon.write(formatPercent(fieldPercent) .. " (Target: " .. formatPercent(CONFIG.target_field_strength) .. ")") + mon.write(formatPercent(fieldPercent) .. " (Target: " .. formatPercent(fieldTarget) .. ")") y = y + 1 -- Field bar