Factorio: load fluids from exported data
This commit is contained in:
parent
51341f6255
commit
c4769eeebb
|
@ -14,7 +14,7 @@ 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_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
|
template_env: Optional[jinja2.Environment] = None
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ def generate_mod(world, output_directory: str):
|
||||||
progressive_technology_table.values()},
|
progressive_technology_table.values()},
|
||||||
"custom_recipes": world.custom_recipes,
|
"custom_recipes": world.custom_recipes,
|
||||||
"max_science_pack": multiworld.max_science_pack[player].value,
|
"max_science_pack": multiworld.max_science_pack[player].value,
|
||||||
"liquids": liquids,
|
"liquids": fluids,
|
||||||
"goal": multiworld.goal[player].value,
|
"goal": multiworld.goal[player].value,
|
||||||
"energy_link": multiworld.energy_link[player].value
|
"energy_link": multiworld.energy_link[player].value
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import os
|
||||||
import string
|
import string
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
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
|
import Utils
|
||||||
from . import Options
|
from . import Options
|
||||||
|
@ -18,7 +18,7 @@ source_folder = os.path.join(os.path.dirname(__file__), "data")
|
||||||
pool = ThreadPoolExecutor(1)
|
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:
|
with open(os.path.join(source_folder, f"{data_name}.json")) as f:
|
||||||
return json.load(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")
|
techs_future = pool.submit(load_json_data, "techs")
|
||||||
recipes_future = pool.submit(load_json_data, "recipes")
|
recipes_future = pool.submit(load_json_data, "recipes")
|
||||||
machines_future = pool.submit(load_json_data, "machines")
|
machines_future = pool.submit(load_json_data, "machines")
|
||||||
|
fluids_future = pool.submit(load_json_data, "fluids")
|
||||||
items_future = pool.submit(load_json_data, "items")
|
items_future = pool.submit(load_json_data, "items")
|
||||||
|
|
||||||
tech_table: Dict[str, int] = {}
|
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():
|
for category, (cost, machine_name) in machine_tech_cost.items():
|
||||||
machine_per_category[category] = machine_name
|
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 technologies to be able to craft recipes from a certain category
|
||||||
required_category_technologies: Dict[str, FrozenSet[FrozenSet[Technology]]] = {}
|
required_category_technologies: Dict[str, FrozenSet[FrozenSet[Technology]]] = {}
|
||||||
|
@ -481,8 +482,9 @@ rel_cost = {
|
||||||
"used-up-uranium-fuel-cell": 1000
|
"used-up-uranium-fuel-cell": 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
blacklist: Set[str] = all_ingredient_names | {"rocket-part"}
|
exclusion_list: Set[str] = all_ingredient_names | {"rocket-part", "used-up-uranium-fuel-cell"}
|
||||||
liquids: Set[str] = {"crude-oil", "water", "sulfuric-acid", "petroleum-gas", "light-oil", "heavy-oil", "lubricant", "steam"}
|
fluids: Set[str] = set(fluids_future.result())
|
||||||
|
del fluids_future
|
||||||
|
|
||||||
|
|
||||||
@Utils.cache_argsless
|
@Utils.cache_argsless
|
||||||
|
@ -496,7 +498,7 @@ def get_science_pack_pools() -> Dict[str, Set[str]]:
|
||||||
return cost
|
return cost
|
||||||
|
|
||||||
science_pack_pools: Dict[str, Set[str]] = {}
|
science_pack_pools: Dict[str, Set[str]] = {}
|
||||||
already_taken = blacklist.copy()
|
already_taken = exclusion_list.copy()
|
||||||
current_difficulty = 5
|
current_difficulty = 5
|
||||||
for science_pack in Options.MaxSciencePack.get_ordered_science_packs():
|
for science_pack in Options.MaxSciencePack.get_ordered_science_packs():
|
||||||
current = science_pack_pools[science_pack] = set()
|
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) \
|
if (science_pack != "automation-science-pack" or not recipe.recursive_unlocking_technologies) \
|
||||||
and get_estimated_difficulty(recipe) < current_difficulty:
|
and get_estimated_difficulty(recipe) < current_difficulty:
|
||||||
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"}
|
current |= {"iron-ore", "copper-ore", "coal", "stone"}
|
||||||
# Can't hand craft automation science if liquids 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 -= liquids
|
current -= fluids
|
||||||
elif science_pack == "logistic-science-pack":
|
elif science_pack == "logistic-science-pack":
|
||||||
current |= {"steam"}
|
current |= {"steam"}
|
||||||
|
|
||||||
current -= already_taken
|
current -= already_taken
|
||||||
already_taken |= current
|
already_taken |= current
|
||||||
current_difficulty *= 2
|
current_difficulty *= 2
|
||||||
|
|
||||||
return science_pack_pools
|
return science_pack_pools
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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, \
|
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, \
|
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, \
|
||||||
liquids, stacking_items
|
fluids, stacking_items
|
||||||
from .Shapes import get_shapes
|
from .Shapes import get_shapes
|
||||||
from .Mod import generate_mod
|
from .Mod import generate_mod
|
||||||
from .Options import factorio_options, MaxSciencePack, Silo, Satellite, TechTreeInformation, Goal
|
from .Options import factorio_options, MaxSciencePack, Silo, Satellite, TechTreeInformation, Goal
|
||||||
|
@ -215,8 +215,8 @@ class Factorio(World):
|
||||||
liquids_used = 0
|
liquids_used = 0
|
||||||
for _ in original.ingredients:
|
for _ in original.ingredients:
|
||||||
new_ingredient = pool.pop()
|
new_ingredient = pool.pop()
|
||||||
if new_ingredient in liquids:
|
if new_ingredient in fluids:
|
||||||
while liquids_used == allow_liquids and new_ingredient in liquids:
|
while liquids_used == allow_liquids and new_ingredient in fluids:
|
||||||
# liquids already at max for current recipe.
|
# liquids already at max for current recipe.
|
||||||
# Return the liquid to the pool and get a new ingredient.
|
# Return the liquid to the pool and get a new ingredient.
|
||||||
pool.append(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
|
# fill all but one slot with random ingredients, last with a good match
|
||||||
while remaining_num_ingredients > 0 and pool:
|
while remaining_num_ingredients > 0 and pool:
|
||||||
ingredient = pool.pop()
|
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.
|
continue # can't use this ingredient as we already have maximum liquid in our recipe.
|
||||||
ingredient_raw = 0
|
ingredient_raw = 0
|
||||||
if ingredient in all_product_sources:
|
if ingredient in all_product_sources:
|
||||||
|
@ -282,14 +282,14 @@ class Factorio(World):
|
||||||
remaining_raw -= num * ingredient_raw
|
remaining_raw -= num * ingredient_raw
|
||||||
remaining_energy -= num * ingredient_energy
|
remaining_energy -= num * ingredient_energy
|
||||||
remaining_num_ingredients -= 1
|
remaining_num_ingredients -= 1
|
||||||
if ingredient in liquids:
|
if ingredient in fluids:
|
||||||
liquids_used += 1
|
liquids_used += 1
|
||||||
|
|
||||||
# fill failed slots with whatever we got
|
# fill failed slots with whatever we got
|
||||||
pool = fallback_pool
|
pool = fallback_pool
|
||||||
while remaining_num_ingredients > 0 and pool:
|
while remaining_num_ingredients > 0 and pool:
|
||||||
ingredient = pool.pop()
|
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.
|
continue # can't use this ingredient as we already have maximum liquid in our recipe.
|
||||||
|
|
||||||
ingredient_recipe = recipes.get(ingredient, None)
|
ingredient_recipe = recipes.get(ingredient, None)
|
||||||
|
@ -310,7 +310,7 @@ class Factorio(World):
|
||||||
remaining_raw -= num * ingredient_raw
|
remaining_raw -= num * ingredient_raw
|
||||||
remaining_energy -= num * ingredient_energy
|
remaining_energy -= num * ingredient_energy
|
||||||
remaining_num_ingredients -= 1
|
remaining_num_ingredients -= 1
|
||||||
if ingredient in liquids:
|
if ingredient in fluids:
|
||||||
liquids_used += 1
|
liquids_used += 1
|
||||||
|
|
||||||
if remaining_num_ingredients > 1:
|
if remaining_num_ingredients > 1:
|
||||||
|
@ -331,7 +331,7 @@ class Factorio(World):
|
||||||
science_pack_pools = get_science_pack_pools()
|
science_pack_pools = get_science_pack_pools()
|
||||||
valid_pool = sorted(science_pack_pools[self.world.max_science_pack[self.player].get_max_pack()])
|
valid_pool = sorted(science_pack_pools[self.world.max_science_pack[self.player].get_max_pack()])
|
||||||
self.world.random.shuffle(valid_pool)
|
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.world.random.shuffle(valid_pool)
|
||||||
self.custom_recipes = {"rocket-part": Recipe("rocket-part", original_rocket_part.category,
|
self.custom_recipes = {"rocket-part": Recipe("rocket-part", original_rocket_part.category,
|
||||||
{valid_pool[x]: 10 for x in range(3)},
|
{valid_pool[x]: 10 for x in range(3)},
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
["fluid-unknown","water","crude-oil","steam","heavy-oil","light-oil","petroleum-gas","sulfuric-acid","lubricant"]
|
Loading…
Reference in New Issue