From 149e98c543ad8b844bc72670681c264dc3ed653f Mon Sep 17 00:00:00 2001
From: anima
Date: Fri, 13 Nov 2026 02:11:38 +0100
Subject: [PATCH] massiv bugfixes around getter methods and ThermalCap outpost
handling
---
libs/wrapper/power.py | 74 ++++++++++++++++++++++++++++---------------
1 file changed, 48 insertions(+), 26 deletions(-)
diff --git a/libs/wrapper/power.py b/libs/wrapper/power.py
index ebdb04b..75cda78 100644
--- a/libs/wrapper/power.py
+++ b/libs/wrapper/power.py
@@ -41,7 +41,7 @@ class ThermalCapWrapper:
clock = get_component("clock")
default_threshold = 0.98
- def __init__(self, cap: ThermalCap | str, threshold: float = 0.99, outpost: OutpostComponent | OutpostRef | str | None = None):
+ def __init__(self, cap: ThermalCap | str, threshold: float = 0.99, outposts: list[OutpostComponent] | OutpostComponent | OutpostRef | str | None = None):
"""init wrapper for `ThermalCap`
Args:
@@ -51,7 +51,7 @@ class ThermalCapWrapper:
"""
self.cap = cap
self.threshold = threshold
- self.outpost = outpost
+ self.outposts = outposts
self.steam_out = cap.steam_out
def run(self):
@@ -83,20 +83,24 @@ class ThermalCapWrapper:
"""fills the given `GasTank` until full"""
if not isinstance(storage, GasTank): return
if storage.is_full():
+ debug(f"{storage.id=} if full, disconnect.")
self.cap.set_throttle(0)
self.steam_out.disconnect()
else:
+ debug(f"start filling {storage.id=}")
self.steam_out.connect(storage.id)
self.cap.set_throttle(1.0)
self.cap.set_relief(0)
while not storage.is_full() and self.cap.phase() == "active":
+ debug(f"wait until {storage.id=} is full")
sleep(1)
+ debug(f"{storage.id=} is full, disconnect.")
self.steam_out.disconnect()
def check_storage(self) -> None:
"""search a `GasTank` to fill"""
- if self.cap.pressure() < 10: return
+ if self.cap.pressure() < 0.1: return
gas_tanks = list()
for outpost in self.outposts:
gas_tanks.extend([ get_component(gt.id) for gt in outpost.buildings('gas_tank') ])
@@ -108,6 +112,15 @@ class ThermalCapWrapper:
if tank.fill_pct() < 0.8:
self.fill_storage(tank)
break
+
+ def get_nearest_outpost(self):
+ """get nearest outpost to `ThermalCap` vent"""
+ vent = self.cap.vent()
+ outpost = get_component(get_component("outpost_network").nearest(vent.x, vent.y).id)
+ if isinstance(outpost, OutpostComponent):
+ debug(f"nearest {outpost=}")
+ return outpost
+ else: return None
@property
def cap(self) -> ThermalCap:
@@ -122,10 +135,13 @@ class ThermalCapWrapper:
@property
def threshold(self) -> float:
- if "__threshold" not in self.__dict__: return self.default_threshold
- if not isinstance(self.__threshold, (float, int)): return self.default_threshold
- if not 0 < self.__threshold < 1: return self.default_threshold
- return self.__threshold
+ try: raw = self.__threshold
+ except AttributeError: return self.default_threshold
+
+ if not isinstance(raw, (float, int)) or isinstance(raw, bool):
+ return self.default_threshold
+ if not 0 < raw < 1: return self.default_threshold
+ return raw
@threshold.setter
def threshold(self, value: float):
@@ -137,10 +153,11 @@ class ThermalCapWrapper:
@property
def outposts(self) -> list[OutpostComponent]:
- if "__outpost" not in self.__dict__: return None
- if isinstance(self.__outposts, list): return [ o for o in self.__outposts if isinstance(o, OutpostComponent) ]
- # TODO: default
- return None
+ try: raw = self.__outposts
+ except AttributeError: return [self.get_nearest_outpost()]
+
+ if not isinstance(raw, list): return [self.get_nearest_outpost()]
+ return [o for o in raw if isinstance(o, OutpostComponent)]
@outposts.setter
def outposts(self, value: list[OutpostComponent] | OutpostComponent | OutpostRef | str):
@@ -151,9 +168,9 @@ class ThermalCapWrapper:
if isinstance(value, str): value = get_component(value)
if isinstance(value, OutpostRef): value = get_component(value.id)
if not isinstance(value, OutpostComponent):
- # TODO: find deafult. powernet ? or nearest ?
- warn(f"no outpost for steam out found ({value=}")
- self.__outposts = list()
+ warn(f"no outpost for steam out found ({value=}, use default nearest")
+ self.__outposts = [ self.get_nearest_outpost() ]
+ return
else: self.__outposts = [ value ]
class SteamTurbineWrapper:
@@ -185,10 +202,10 @@ class SteamTurbineWrapper:
def check_health(self):
"""check own function and notify if not in expected parameters"""
if self.steam_in.level() < self.notify_threshold:
- notify(f"{self.turbine.id}: steam level under {self.notify_threshold=}", "warn", 30)
- if self.turbine.is_stalled():
- notify(f"{self.turbine.id}: stopped working or has low efficency ({self.turbine.efficiency()*100}%)", "error", 10)
- sleep(10)
+ notify(f"{self.turbine.id}: steam level under {self.notify_threshold}", "warn", 30)
+ if self.turbine.is_stalled() or self.steam_in.level() == 0:
+ notify(f"{self.turbine.id}: stopped working or has low efficency ({self.turbine.efficiency()*100}%)", "error", 30)
+ sleep(30)
def fill_steam(self):
"""fills steam if own steam under threshold"""
@@ -236,7 +253,7 @@ class SteamTurbineWrapper:
else: return gastanks
@property
- def turbine(self) -> SteamTurbine:
+ def turbine(self) -> SteamTurbine:
if isinstance(self.__turbine, SteamTurbine): return self.__turbine
raise TypeError(f"{self.__turbine=} ({type(self.__turbine)=} is not a SteamTurbine)")
@@ -248,10 +265,13 @@ class SteamTurbineWrapper:
@property
def threshold(self) -> int:
- if not "__threshold" in self.__dict__: return self.default_threshold
- if not isinstance(self.__threshold, int): return self.default_threshold
- if not 0 < self.__threshold < 100: return self.default_threshold
- return self.threshold
+ try: raw = self.__threshold
+ except AttributeError: return self.default_threshold
+
+ if not isinstance(raw, int) or isinstance(raw, bool):
+ return self.default_threshold
+ if not 0 < raw < 100: return self.default_threshold
+ return raw
@threshold.setter
def threshold(self, value: int):
@@ -263,9 +283,11 @@ class SteamTurbineWrapper:
@property
def storages(self) -> list[GasTank]:
- if not "__storages" in self.__dict__: return self.get_local_storages()
- if isinstance(self.__storages, list): return [ s for s in self.__storages if isinstance(s, GasTank) ]
- return self.get_local_storages()
+ try: raw = self.__storages
+ except AttributeError: return self.get_local_storages()
+
+ if not isinstance(raw, list): return self.get_local_storages()
+ return [s for s in raw if isinstance(s, GasTank)]
@storages.setter
def storages(self, value: list[GasTank] | GasTank | str | None):