checkpoint

This commit is contained in:
2025-11-09 17:40:11 +00:00
parent f9e1ad0768
commit 9096d38f78
4 changed files with 198 additions and 11 deletions

25
main.py
View File

@@ -50,6 +50,7 @@ class ProductionChain:
self.excess: Dict[Items, float] = defaultdict(float)
self.byproduct: Dict[Items, float] = defaultdict(float)
self.preferred_recipes = preferred_recipes or {}
self.preferred_recipes[Items.Steam] = Recipes.SteamMk1.value
def get_recipe(self, item: Items) -> Optional[Recipe]:
if item in self.preferred_recipes:
@@ -98,6 +99,7 @@ class ProductionChain:
continue
levels = []
for out, quantity in recipe.outputs.items():
if out in demand:
target_quantity = demand[out] - production[out]
@@ -365,6 +367,27 @@ def index():
"building": "",
"rate": target_rates_by_item[item_name],
})
# If there is excess of this item, show it as a destination
if item_name in excess and excess[item_name] > 0:
dests.append({
"recipe": f"Excess: {item_name}",
"building": "",
"rate": excess[item_name],
})
# Also list byproducts produced by this step's recipe at the computed level
# Find this step's recipe and level to compute byproduct rates
rec_obj = prod_chain.recipe_name_to_obj.get(s["recipe"]) if hasattr(prod_chain, "recipe_name_to_obj") else None
if rec_obj is not None:
# Find buildings_float for this step (already stored on s)
lvl = s.get("buildings_float", 0.0)
for byp_item, per_building in rec_obj.byproducts.items():
rate = lvl * per_building
if rate > 0:
dests.append({
"recipe": f"Byproduct: {byp_item.value.name}",
"building": "",
"rate": rate,
})
# Sort destinations by descending rate for display
dests.sort(key=lambda x: x["rate"], reverse=True)
s["destinations"] = dests
@@ -457,4 +480,4 @@ if __name__ == "__main__":
# For local dev: python main.py
app.run(host="0.0.0.0", port=5000, debug=True)
# prod_chain = ProductionChain()
# prod_chain.compute_chain({Items.CateriumHeatsink: 10.0})
# prod_chain.compute_chain({Items.SteelBeam: 3.0})