Factorio: use resources data

This commit is contained in:
Fabian Dill 2022-06-19 18:06:27 +02:00 committed by Fabian Dill
parent 47edc356ad
commit 6d4c4295b3
4 changed files with 26 additions and 40 deletions

View File

@ -13,7 +13,7 @@ import Utils
import Patch import Patch
from . import Options from . import Options
from .Technologies import tech_table, recipes, free_sample_blacklist, progressive_technology_table, \ from .Technologies import tech_table, recipes, free_sample_exclusions, progressive_technology_table, \
base_tech_table, tech_to_progressive_lookup, fluids base_tech_table, tech_to_progressive_lookup, fluids
template_env: Optional[jinja2.Environment] = None template_env: Optional[jinja2.Environment] = None
@ -126,7 +126,7 @@ def generate_mod(world, output_directory: str):
"static_nodes": multiworld.worlds[player].static_nodes, "static_nodes": multiworld.worlds[player].static_nodes,
"recipe_time_scale": recipe_time_scales.get(multiworld.recipe_time[player].value, None), "recipe_time_scale": recipe_time_scales.get(multiworld.recipe_time[player].value, None),
"recipe_time_range": recipe_time_ranges.get(multiworld.recipe_time[player].value, None), "recipe_time_range": recipe_time_ranges.get(multiworld.recipe_time[player].value, None),
"free_sample_blacklist": {item: 1 for item in free_sample_blacklist}, "free_sample_blacklist": {item: 1 for item in free_sample_exclusions},
"progressive_technology_table": {tech.name: tech.progressive for tech in "progressive_technology_table": {tech.name: tech.progressive for tech in
progressive_technology_table.values()}, progressive_technology_table.values()},
"custom_recipes": world.custom_recipes, "custom_recipes": world.custom_recipes,

View File

@ -25,6 +25,7 @@ def load_json_data(data_name: str) -> Union[List[str], Dict[str, Any]]:
techs_future = pool.submit(load_json_data, "techs") techs_future = pool.submit(load_json_data, "techs")
recipes_future = pool.submit(load_json_data, "recipes") recipes_future = pool.submit(load_json_data, "recipes")
resources_future = pool.submit(load_json_data, "resources")
machines_future = pool.submit(load_json_data, "machines") machines_future = pool.submit(load_json_data, "machines")
fluids_future = pool.submit(load_json_data, "fluids") fluids_future = pool.submit(load_json_data, "fluids")
items_future = pool.submit(load_json_data, "items") items_future = pool.submit(load_json_data, "items")
@ -154,8 +155,11 @@ class Recipe(FactorioElement):
for ingredient, cost in self.ingredients.items(): for ingredient, cost in self.ingredients.items():
if ingredient in all_product_sources: if ingredient in all_product_sources:
for recipe in all_product_sources[ingredient]: for recipe in all_product_sources[ingredient]:
if recipe.ingredients:
ingredients.update({name: amount * cost / recipe.products[ingredient] for name, amount in ingredients.update({name: amount * cost / recipe.products[ingredient] for name, amount in
recipe.base_cost.items()}) recipe.base_cost.items()})
else:
ingredients[ingredient] += recipe.energy * cost / recipe.products[ingredient]
else: else:
ingredients[ingredient] += cost ingredients[ingredient] += cost
return ingredients return ingredients
@ -203,18 +207,18 @@ all_product_sources: Dict[str, Set[Recipe]] = {"character": set()}
# add uranium mining to logic graph. TODO: add to automatic extractor for mod support # add uranium mining to logic graph. TODO: add to automatic extractor for mod support
raw_recipes = recipes_future.result() raw_recipes = recipes_future.result()
del recipes_future del recipes_future
for resource_name, resource_data in resources_future.result().items():
raw_recipes["uranium-ore"] = { raw_recipes[f"mining-{resource_name}"] = current_recipe = {
"ingredients": {"sulfuric-acid": 1}, "ingredients": {},
"products": {"uranium-ore": 1}, "products": {},
"category": "mining", "energy": resource_data["mining_time"],
"energy": 2 "category": resource_data["category"]
} }
for name, data in resource_data["products"].items():
# raw_recipes["iron-ore"] = {"ingredients": {}, "products": {"iron-ore": 1}, "category": "mining", "energy": 2} current_recipe["products"].update({data["name"]: data["amount"]})
# raw_recipes["copper-ore"] = {"ingredients": {}, "products": {"copper-ore": 1}, "category": "mining", "energy": 2} if "required_fluid" in resource_data:
# raw_recipes["coal-ore"] = {"ingredients": {}, "products": {"coal": 1}, "category": "mining", "energy": 2} current_recipe["ingredients"] = {resource_data["required_fluid"]: resource_data["fluid_amount"]}
# raw_recipes["stone"] = {"ingredients": {}, "products": {"coal": 1}, "category": "mining", "energy": 2} del resources_future
for recipe_name, recipe_data in raw_recipes.items(): for recipe_name, recipe_data in raw_recipes.items():
# example: # example:
@ -237,8 +241,8 @@ for name, categories in machines_future.result().items():
machine = Machine(name, set(categories)) machine = Machine(name, set(categories))
machines[name] = machine machines[name] = machine
# add electric mining drill as a crafting machine to resolve uranium-ore # add electric mining drill as a crafting machine to resolve basic-solid (mining)
machines["electric-mining-drill"] = Machine("electric-mining-drill", {"mining"}) machines["electric-mining-drill"] = Machine("electric-mining-drill", {"basic-solid"})
machines["pumpjack"] = Machine("pumpjack", {"basic-fluid"}) machines["pumpjack"] = Machine("pumpjack", {"basic-fluid"})
machines["assembling-machine-1"].categories.add("crafting-with-fluid") # mod enables this machines["assembling-machine-1"].categories.add("crafting-with-fluid") # mod enables this
machines["character"].categories.add("basic-crafting") # somehow this is implied and not exported machines["character"].categories.add("basic-crafting") # somehow this is implied and not exported
@ -332,24 +336,7 @@ def get_rocket_requirements(silo_recipe: Recipe, part_recipe: Recipe, satellite_
return {tech.name for tech in techs} return {tech.name for tech in techs}
free_sample_blacklist: Set[str] = all_ingredient_names | {"rocket-part"} free_sample_exclusions: Set[str] = all_ingredient_names | {"rocket-part"}
rocket_recipes = {
Options.MaxSciencePack.option_space_science_pack:
{"rocket-control-unit": 10, "low-density-structure": 10, "rocket-fuel": 10},
Options.MaxSciencePack.option_utility_science_pack:
{"speed-module": 10, "steel-plate": 10, "solid-fuel": 10},
Options.MaxSciencePack.option_production_science_pack:
{"speed-module": 10, "steel-plate": 10, "solid-fuel": 10},
Options.MaxSciencePack.option_chemical_science_pack:
{"advanced-circuit": 10, "steel-plate": 10, "solid-fuel": 10},
Options.MaxSciencePack.option_military_science_pack:
{"defender-capsule": 10, "stone-wall": 10, "coal": 10},
Options.MaxSciencePack.option_logistic_science_pack:
{"electronic-circuit": 10, "stone-brick": 10, "coal": 10},
Options.MaxSciencePack.option_automation_science_pack:
{"copper-cable": 10, "iron-plate": 10, "wood": 10}
}
# progressive technologies # progressive technologies
# auto-progressive # auto-progressive
@ -502,7 +489,6 @@ def get_science_pack_pools() -> Dict[str, Set[str]]:
current |= set(recipe.products) current |= set(recipe.products)
if science_pack == "automation-science-pack": if science_pack == "automation-science-pack":
current |= {"iron-ore", "copper-ore", "coal", "stone"}
# Can't handcraft automation science if fluids end up in its recipe, making the seed impossible. # Can't handcraft automation science if fluids end up in its recipe, making the seed impossible.
current -= fluids current -= fluids
elif science_pack == "logistic-science-pack": elif science_pack == "logistic-science-pack":

View File

@ -5,7 +5,7 @@ from ..AutoWorld import World, WebWorld
from BaseClasses import Region, Entrance, Location, Item, RegionType, Tutorial, ItemClassification from BaseClasses import Region, Entrance, Location, Item, RegionType, Tutorial, ItemClassification
from .Technologies import base_tech_table, recipe_sources, base_technology_table, \ from .Technologies import base_tech_table, recipe_sources, base_technology_table, \
all_ingredient_names, all_product_sources, required_technologies, get_rocket_requirements, rocket_recipes, \ all_ingredient_names, all_product_sources, required_technologies, get_rocket_requirements, \
progressive_technology_table, common_tech_table, tech_to_progressive_lookup, progressive_tech_table, \ progressive_technology_table, common_tech_table, tech_to_progressive_lookup, progressive_tech_table, \
get_science_pack_pools, Recipe, recipes, technology_table, tech_table, factorio_base_id, useless_technologies, \ get_science_pack_pools, Recipe, recipes, technology_table, tech_table, factorio_base_id, useless_technologies, \
fluids, stacking_items fluids, stacking_items

View File

@ -178,13 +178,13 @@ data:extend{new_tree_copy}
{% endfor %} {% endfor %}
{% if recipe_time_scale %} {% if recipe_time_scale %}
{%- for recipe_name, recipe in recipes.items() %} {%- for recipe_name, recipe in recipes.items() %}
{%- if recipe.category not in ("mining", "basic-fluid") %} {%- if recipe.category not in ("basic-solid", "basic-fluid") %}
adjust_energy("{{ recipe_name }}", {{ flop_random(*recipe_time_scale) }}) adjust_energy("{{ recipe_name }}", {{ flop_random(*recipe_time_scale) }})
{%- endif %} {%- endif %}
{%- endfor -%} {%- endfor -%}
{% elif recipe_time_range %} {% elif recipe_time_range %}
{%- for recipe_name, recipe in recipes.items() %} {%- for recipe_name, recipe in recipes.items() %}
{%- if recipe.category not in ("mining", "basic-fluid") %} {%- if recipe.category not in ("basic-solid", "basic-fluid") %}
set_energy("{{ recipe_name }}", {{ flop_random(*recipe_time_range) }}) set_energy("{{ recipe_name }}", {{ flop_random(*recipe_time_range) }})
{%- endif %} {%- endif %}
{%- endfor -%} {%- endfor -%}