Factorio: load fluids from exported data

This commit is contained in:
Fabian Dill 2022-06-18 13:40:02 +02:00
parent 51341f6255
commit c4769eeebb
4 changed files with 24 additions and 18 deletions

View File

@ -14,7 +14,7 @@ import Patch
from . import Options
from .Technologies import tech_table, recipes, free_sample_blacklist, progressive_technology_table, \
base_tech_table, tech_to_progressive_lookup, liquids
base_tech_table, tech_to_progressive_lookup, fluids
template_env: Optional[jinja2.Environment] = None
@ -131,7 +131,7 @@ def generate_mod(world, output_directory: str):
progressive_technology_table.values()},
"custom_recipes": world.custom_recipes,
"max_science_pack": multiworld.max_science_pack[player].value,
"liquids": liquids,
"liquids": fluids,
"goal": multiworld.goal[player].value,
"energy_link": multiworld.energy_link[player].value
}

View File

@ -6,7 +6,7 @@ import os
import string
from collections import Counter
from concurrent.futures import ThreadPoolExecutor
from typing import Dict, Set, FrozenSet, Tuple, Union, List
from typing import Dict, Set, FrozenSet, Tuple, Union, List, Any
import Utils
from . import Options
@ -18,7 +18,7 @@ source_folder = os.path.join(os.path.dirname(__file__), "data")
pool = ThreadPoolExecutor(1)
def load_json_data(data_name: str) -> dict:
def load_json_data(data_name: str) -> Union[List[str], Dict[str, Any]]:
with open(os.path.join(source_folder, f"{data_name}.json")) as f:
return json.load(f)
@ -26,6 +26,7 @@ def load_json_data(data_name: str) -> dict:
techs_future = pool.submit(load_json_data, "techs")
recipes_future = pool.submit(load_json_data, "recipes")
machines_future = pool.submit(load_json_data, "machines")
fluids_future = pool.submit(load_json_data, "fluids")
items_future = pool.submit(load_json_data, "items")
tech_table: Dict[str, int] = {}
@ -310,7 +311,7 @@ machine_per_category: Dict[str: str] = {}
for category, (cost, machine_name) in machine_tech_cost.items():
machine_per_category[category] = machine_name
del (machine_tech_cost)
del machine_tech_cost
# required technologies to be able to craft recipes from a certain category
required_category_technologies: Dict[str, FrozenSet[FrozenSet[Technology]]] = {}
@ -481,8 +482,9 @@ rel_cost = {
"used-up-uranium-fuel-cell": 1000
}
blacklist: Set[str] = all_ingredient_names | {"rocket-part"}
liquids: Set[str] = {"crude-oil", "water", "sulfuric-acid", "petroleum-gas", "light-oil", "heavy-oil", "lubricant", "steam"}
exclusion_list: Set[str] = all_ingredient_names | {"rocket-part", "used-up-uranium-fuel-cell"}
fluids: Set[str] = set(fluids_future.result())
del fluids_future
@Utils.cache_argsless
@ -496,7 +498,7 @@ def get_science_pack_pools() -> Dict[str, Set[str]]:
return cost
science_pack_pools: Dict[str, Set[str]] = {}
already_taken = blacklist.copy()
already_taken = exclusion_list.copy()
current_difficulty = 5
for science_pack in Options.MaxSciencePack.get_ordered_science_packs():
current = science_pack_pools[science_pack] = set()
@ -504,15 +506,18 @@ def get_science_pack_pools() -> Dict[str, Set[str]]:
if (science_pack != "automation-science-pack" or not recipe.recursive_unlocking_technologies) \
and get_estimated_difficulty(recipe) < current_difficulty:
current |= set(recipe.products)
if science_pack == "automation-science-pack":
current |= {"iron-ore", "copper-ore", "coal", "stone"}
# Can't hand craft automation science if liquids end up in its recipe, making the seed impossible.
current -= liquids
# Can't handcraft automation science if fluids end up in its recipe, making the seed impossible.
current -= fluids
elif science_pack == "logistic-science-pack":
current |= {"steam"}
current -= already_taken
already_taken |= current
current_difficulty *= 2
return science_pack_pools

View File

@ -8,7 +8,7 @@ from .Technologies import base_tech_table, recipe_sources, base_technology_table
all_ingredient_names, all_product_sources, required_technologies, get_rocket_requirements, rocket_recipes, \
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, \
liquids, stacking_items
fluids, stacking_items
from .Shapes import get_shapes
from .Mod import generate_mod
from .Options import factorio_options, MaxSciencePack, Silo, Satellite, TechTreeInformation, Goal
@ -215,8 +215,8 @@ class Factorio(World):
liquids_used = 0
for _ in original.ingredients:
new_ingredient = pool.pop()
if new_ingredient in liquids:
while liquids_used == allow_liquids and new_ingredient in liquids:
if new_ingredient in fluids:
while liquids_used == allow_liquids and new_ingredient in fluids:
# liquids already at max for current recipe.
# Return the liquid to the pool and get a new ingredient.
pool.append(new_ingredient)
@ -246,7 +246,7 @@ class Factorio(World):
# fill all but one slot with random ingredients, last with a good match
while remaining_num_ingredients > 0 and pool:
ingredient = pool.pop()
if liquids_used == allow_liquids and ingredient in liquids:
if liquids_used == allow_liquids and ingredient in fluids:
continue # can't use this ingredient as we already have maximum liquid in our recipe.
ingredient_raw = 0
if ingredient in all_product_sources:
@ -282,14 +282,14 @@ class Factorio(World):
remaining_raw -= num * ingredient_raw
remaining_energy -= num * ingredient_energy
remaining_num_ingredients -= 1
if ingredient in liquids:
if ingredient in fluids:
liquids_used += 1
# fill failed slots with whatever we got
pool = fallback_pool
while remaining_num_ingredients > 0 and pool:
ingredient = pool.pop()
if liquids_used == allow_liquids and ingredient in liquids:
if liquids_used == allow_liquids and ingredient in fluids:
continue # can't use this ingredient as we already have maximum liquid in our recipe.
ingredient_recipe = recipes.get(ingredient, None)
@ -310,7 +310,7 @@ class Factorio(World):
remaining_raw -= num * ingredient_raw
remaining_energy -= num * ingredient_energy
remaining_num_ingredients -= 1
if ingredient in liquids:
if ingredient in fluids:
liquids_used += 1
if remaining_num_ingredients > 1:
@ -331,7 +331,7 @@ class Factorio(World):
science_pack_pools = get_science_pack_pools()
valid_pool = sorted(science_pack_pools[self.world.max_science_pack[self.player].get_max_pack()])
self.world.random.shuffle(valid_pool)
while any([valid_pool[x] in liquids for x in range(3)]):
while any([valid_pool[x] in fluids for x in range(3)]):
self.world.random.shuffle(valid_pool)
self.custom_recipes = {"rocket-part": Recipe("rocket-part", original_rocket_part.category,
{valid_pool[x]: 10 for x in range(3)},

View File

@ -0,0 +1 @@
["fluid-unknown","water","crude-oil","steam","heavy-oil","light-oil","petroleum-gas","sulfuric-acid","lubricant"]