From 86013328d6c2a429e44364ed35eb8587b70f9ba4 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sat, 21 May 2022 20:57:26 +0200 Subject: [PATCH] Factorio: fix crude-oil related crashes (#552) --- Options.py | 1 + worlds/factorio/Technologies.py | 15 ++++++++++++--- worlds/factorio/__init__.py | 4 +++- .../data/mod_template/data-final-fixes.lua | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Options.py b/Options.py index 6a3dd5bc..2fdb92da 100644 --- a/Options.py +++ b/Options.py @@ -8,6 +8,7 @@ import random from schema import Schema, And, Or, Optional from Utils import get_fuzzy_results + class AssembleOptions(abc.ABCMeta): def __new__(mcs, name, bases, attrs): options = attrs["options"] = {} diff --git a/worlds/factorio/Technologies.py b/worlds/factorio/Technologies.py index 3f6f6ea9..d7d1b88b 100644 --- a/worlds/factorio/Technologies.py +++ b/worlds/factorio/Technologies.py @@ -193,9 +193,18 @@ del (raw) recipes = {} all_product_sources: Dict[str, Set[Recipe]] = {"character": set()} # add uranium mining to logic graph. TODO: add to automatic extractor for mod support -raw_recipes["uranium-ore"] = {"ingredients": {"sulfuric-acid": 1}, "products": {"uranium-ore": 1}, "category": "mining", - "energy": 2} -raw_recipes["crude-oil"] = {"ingredients": {}, "products": {"crude-oil"}, "category": "basic-fluid"} +raw_recipes["uranium-ore"] = { + "ingredients": {"sulfuric-acid": 1}, + "products": {"uranium-ore": 1}, + "category": "mining", + "energy": 2 +} +raw_recipes["crude-oil"] = { + "ingredients": {}, + "products": {"crude-oil": 1}, + "category": "basic-fluid", + "energy": 1 +} # raw_recipes["iron-ore"] = {"ingredients": {}, "products": {"iron-ore": 1}, "category": "mining", "energy": 2} # raw_recipes["copper-ore"] = {"ingredients": {}, "products": {"copper-ore": 1}, "category": "mining", "energy": 2} diff --git a/worlds/factorio/__init__.py b/worlds/factorio/__init__.py index 9ca1156e..6cf6f357 100644 --- a/worlds/factorio/__init__.py +++ b/worlds/factorio/__init__.py @@ -245,14 +245,16 @@ class Factorio(World): ingredient = pool.pop() if liquids_used == allow_liquids and ingredient in liquids: continue # can't use this ingredient as we already have maximum liquid in our recipe. + ingredient_raw = 0 if ingredient in all_product_sources: ingredient_recipe = min(all_product_sources[ingredient], key=lambda recipe: recipe.rel_cost) ingredient_raw = sum((count for ingredient, count in ingredient_recipe.base_cost.items())) ingredient_energy = ingredient_recipe.total_energy else: # assume simple ore TODO: remove if tree when mining data is harvested from Factorio - ingredient_raw = 1 ingredient_energy = 2 + if not ingredient_raw: + ingredient_raw = 1 if remaining_num_ingredients == 1: max_raw = 1.1 * remaining_raw min_raw = 0.9 * remaining_raw diff --git a/worlds/factorio/data/mod_template/data-final-fixes.lua b/worlds/factorio/data/mod_template/data-final-fixes.lua index d9b16bf5..36d1df53 100644 --- a/worlds/factorio/data/mod_template/data-final-fixes.lua +++ b/worlds/factorio/data/mod_template/data-final-fixes.lua @@ -178,13 +178,13 @@ data:extend{new_tree_copy} {% endfor %} {% if recipe_time_scale %} {%- for recipe_name, recipe in recipes.items() %} -{%- if recipe.category != "mining" %} +{%- if recipe.category not in ("mining", "basic-fluid") %} adjust_energy("{{ recipe_name }}", {{ flop_random(*recipe_time_scale) }}) {%- endif %} {%- endfor -%} {% elif recipe_time_range %} {%- for recipe_name, recipe in recipes.items() %} -{%- if recipe.category != "mining" %} +{%- if recipe.category not in ("mining", "basic-fluid") %} set_energy("{{ recipe_name }}", {{ flop_random(*recipe_time_range) }}) {%- endif %} {%- endfor -%}