Factorio: always build dynamic advancement flag

This commit is contained in:
Fabian Dill 2021-11-20 04:47:19 +01:00
parent 824b932961
commit 80c3b8bbca
2 changed files with 15 additions and 25 deletions

View File

@ -59,7 +59,7 @@ class Technology(FactorioElement): # maybe make subclass of Location?
def build_rule(self, player: int): def build_rule(self, player: int):
logging.debug(f"Building rules for {self.name}") logging.debug(f"Building rules for {self.name}")
return lambda state, technologies=technologies: all(state.has(f"Automated {ingredient}", player) return lambda state: all(state.has(f"Automated {ingredient}", player)
for ingredient in self.ingredients) for ingredient in self.ingredients)
def get_prior_technologies(self) -> Set[Technology]: def get_prior_technologies(self) -> Set[Technology]:
@ -300,12 +300,6 @@ for category_name, machine_name in machine_per_category.items():
required_technologies: Dict[str, FrozenSet[Technology]] = Utils.KeyedDefaultDict(lambda ingredient_name: frozenset( required_technologies: Dict[str, FrozenSet[Technology]] = Utils.KeyedDefaultDict(lambda ingredient_name: frozenset(
recursively_get_unlocking_technologies(ingredient_name, unlock_func=unlock))) recursively_get_unlocking_technologies(ingredient_name, unlock_func=unlock)))
advancement_technologies: Set[str] = set()
for ingredient_name in all_ingredient_names:
technologies = required_technologies[ingredient_name]
advancement_technologies |= {technology.name for technology in technologies}
def get_rocket_requirements(silo_recipe: Recipe, part_recipe: Recipe) -> Set[str]: def get_rocket_requirements(silo_recipe: Recipe, part_recipe: Recipe) -> Set[str]:
techs = set() techs = set()
if silo_recipe: if silo_recipe:
@ -335,8 +329,6 @@ rocket_recipes = {
{"copper-cable": 10, "iron-plate": 10, "wood": 10} {"copper-cable": 10, "iron-plate": 10, "wood": 10}
} }
advancement_technologies |= {tech.name for tech in required_technologies["rocket-silo"]}
# progressive technologies # progressive technologies
# auto-progressive # auto-progressive
progressive_rows: Dict[str, Union[List[str], Tuple[str, ...]]] = {} progressive_rows: Dict[str, Union[List[str], Tuple[str, ...]]] = {}
@ -430,8 +422,6 @@ for root in sorted_rows:
unlocks=any(technology_table[tech].unlocks for tech in progressive)) unlocks=any(technology_table[tech].unlocks for tech in progressive))
progressive_tech_table[root] = progressive_technology.factorio_id progressive_tech_table[root] = progressive_technology.factorio_id
progressive_technology_table[root] = progressive_technology progressive_technology_table[root] = progressive_technology
if any(tech in advancement_technologies for tech in progressive):
advancement_technologies.add(root)
tech_to_progressive_lookup: Dict[str, str] = {} tech_to_progressive_lookup: Dict[str, str] = {}
for technology in progressive_technology_table.values(): for technology in progressive_technology_table.values():

View File

@ -1,9 +1,10 @@
import collections import collections
import typing
from ..AutoWorld import World from ..AutoWorld import World
from BaseClasses import Region, Entrance, Location, Item from BaseClasses import Region, Entrance, Location, Item
from .Technologies import base_tech_table, recipe_sources, base_technology_table, advancement_technologies, \ 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
@ -32,7 +33,7 @@ class Factorio(World):
game: str = "Factorio" game: str = "Factorio"
static_nodes = {"automation", "logistics", "rocket-silo"} static_nodes = {"automation", "logistics", "rocket-silo"}
custom_recipes = {} custom_recipes = {}
additional_advancement_technologies: set advancement_technologies: typing.Set[str]
item_name_to_id = all_items item_name_to_id = all_items
location_name_to_id = base_tech_table location_name_to_id = base_tech_table
@ -41,7 +42,7 @@ class Factorio(World):
def __init__(self, world, player: int): def __init__(self, world, player: int):
super(Factorio, self).__init__(world, player) super(Factorio, self).__init__(world, player)
self.additional_advancement_technologies = set() self.advancement_technologies = set()
def generate_basic(self): def generate_basic(self):
player = self.player player = self.player
@ -268,8 +269,6 @@ class Factorio(World):
{valid_pool[x]: 10 for x in range(3)}, {valid_pool[x]: 10 for x in range(3)},
original_rocket_part.products, original_rocket_part.products,
original_rocket_part.energy)} original_rocket_part.energy)}
self.additional_advancement_technologies = {tech.name for tech in
self.custom_recipes["rocket-part"].recursive_unlocking_technologies}
if self.world.recipe_ingredients[self.player]: if self.world.recipe_ingredients[self.player]:
valid_pool = [] valid_pool = []
@ -282,8 +281,6 @@ class Factorio(World):
for _ in original.ingredients: for _ in original.ingredients:
new_ingredients[valid_pool.pop()] = 1 new_ingredients[valid_pool.pop()] = 1
new_recipe = Recipe(pack, original.category, new_ingredients, original.products, original.energy) new_recipe = Recipe(pack, original.category, new_ingredients, original.products, original.energy)
self.additional_advancement_technologies |= {tech.name for tech in
new_recipe.recursive_unlocking_technologies}
self.custom_recipes[pack] = new_recipe self.custom_recipes[pack] = new_recipe
if self.world.silo[self.player].value == Silo.option_randomize_recipe: if self.world.silo[self.player].value == Silo.option_randomize_recipe:
@ -292,21 +289,24 @@ class Factorio(World):
valid_pool += sorted(science_pack_pools[pack]) valid_pool += sorted(science_pack_pools[pack])
new_recipe = self.make_balanced_recipe(recipes["rocket-silo"], valid_pool, new_recipe = self.make_balanced_recipe(recipes["rocket-silo"], valid_pool,
factor=(self.world.max_science_pack[self.player].value + 1) / 7) factor=(self.world.max_science_pack[self.player].value + 1) / 7)
self.additional_advancement_technologies |= {tech.name for tech in
new_recipe.recursive_unlocking_technologies}
self.custom_recipes["rocket-silo"] = new_recipe self.custom_recipes["rocket-silo"] = new_recipe
needed_recipes = self.world.max_science_pack[self.player].get_allowed_packs() | {"rocket-silo", "rocket-part"}
for recipe in needed_recipes:
recipe = self.custom_recipes.get(recipe, recipes[recipe])
self.advancement_technologies |= {tech.name for tech in recipe.recursive_unlocking_technologies}
# handle marking progressive techs as advancement # handle marking progressive techs as advancement
prog_add = set() prog_add = set()
for tech in self.additional_advancement_technologies: for tech in self.advancement_technologies:
if tech in tech_to_progressive_lookup: if tech in tech_to_progressive_lookup:
prog_add.add(tech_to_progressive_lookup[tech]) prog_add.add(tech_to_progressive_lookup[tech])
self.additional_advancement_technologies |= prog_add self.advancement_technologies |= prog_add
def create_item(self, name: str) -> Item: def create_item(self, name: str) -> Item:
if name in tech_table: if name in tech_table:
return FactorioItem(name, name in advancement_technologies or return FactorioItem(name, name in self.advancement_technologies,
name in self.additional_advancement_technologies,
tech_table[name], self.player) tech_table[name], self.player)
item = FactorioItem(name, False, all_items[name], self.player) item = FactorioItem(name, False, all_items[name], self.player)