From 1b4659276ce36ea43582b77fdd50bc69630ccbb6 Mon Sep 17 00:00:00 2001 From: CaitSith2 Date: Sat, 20 Nov 2021 16:27:17 -0800 Subject: [PATCH] Add randomized recipe for Satellite. --- worlds/factorio/Mod.py | 3 +++ worlds/factorio/Options.py | 9 +++++++++ worlds/factorio/Technologies.py | 1 + worlds/factorio/__init__.py | 23 +++++++++++++++++------ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/worlds/factorio/Mod.py b/worlds/factorio/Mod.py index 484ed626..ef9893cb 100644 --- a/worlds/factorio/Mod.py +++ b/worlds/factorio/Mod.py @@ -107,6 +107,9 @@ def generate_mod(world, output_directory: str): if getattr(multiworld, "silo")[player].value == Options.Silo.option_randomize_recipe: template_data["free_sample_blacklist"]["rocket-silo"] = 1 + + if getattr(multiworld, "satellite")[player].value == Options.Satellite.option_randomize_recipe: + template_data["free_sample_blacklist"]["satellite"] = 1 control_code = control_template.render(**template_data) data_template_code = data_template.render(**template_data) diff --git a/worlds/factorio/Options.py b/worlds/factorio/Options.py index 0c9e3cd8..68858498 100644 --- a/worlds/factorio/Options.py +++ b/worlds/factorio/Options.py @@ -55,6 +55,14 @@ class Silo(Choice): default = 0 +class Satellite(Choice): + """Ingredients to craft satellite.""" + displayname = "Satellite" + options_vanilla = 0 + option_randomize_recipe = 1 + default = 0 + + class FreeSamples(Choice): """Get free items with your technologies.""" displayname = "Free Samples" @@ -289,6 +297,7 @@ factorio_options: typing.Dict[str, type(Option)] = { "tech_tree_layout": TechTreeLayout, "tech_cost": TechCost, "silo": Silo, + "satellite": Satellite, "free_samples": FreeSamples, "tech_tree_information": TechTreeInformation, "starting_items": FactorioStartItems, diff --git a/worlds/factorio/Technologies.py b/worlds/factorio/Technologies.py index 31b7ea12..89f50b84 100644 --- a/worlds/factorio/Technologies.py +++ b/worlds/factorio/Technologies.py @@ -308,6 +308,7 @@ def get_rocket_requirements(silo_recipe: Recipe, part_recipe: Recipe, satellite_ for ingredient in part_recipe.ingredients: techs |= recursively_get_unlocking_technologies(ingredient) if satellite_recipe: + techs |= satellite_recipe.unlocking_technologies for ingredient in satellite_recipe.ingredients: techs |= recursively_get_unlocking_technologies(ingredient) return {tech.name for tech in techs} diff --git a/worlds/factorio/__init__.py b/worlds/factorio/__init__.py index 7574396d..0c957180 100644 --- a/worlds/factorio/__init__.py +++ b/worlds/factorio/__init__.py @@ -10,7 +10,7 @@ from .Technologies import base_tech_table, recipe_sources, base_technology_table get_science_pack_pools, Recipe, recipes, technology_table, tech_table, factorio_base_id, useless_technologies from .Shapes import get_shapes from .Mod import generate_mod -from .Options import factorio_options, MaxSciencePack, Silo, TechTreeInformation +from .Options import factorio_options, MaxSciencePack, Silo, Satellite, TechTreeInformation import logging @@ -285,20 +285,31 @@ class Factorio(World): new_recipe = Recipe(pack, original.category, new_ingredients, original.products, original.energy) 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 \ + or self.world.satellite[self.player].value == Satellite.option_randomize_recipe: valid_pool = [] for pack in sorted(self.world.max_science_pack[self.player].get_allowed_packs()): valid_pool += sorted(science_pack_pools[pack]) - new_recipe = self.make_balanced_recipe(recipes["rocket-silo"], valid_pool, - factor=(self.world.max_science_pack[self.player].value + 1) / 7) - self.custom_recipes["rocket-silo"] = new_recipe - needed_recipes = self.world.max_science_pack[self.player].get_allowed_packs() | {"rocket-silo", "rocket-part"} + if self.world.silo[self.player].value == Silo.option_randomize_recipe: + new_recipe = self.make_balanced_recipe(recipes["rocket-silo"], valid_pool, + factor=(self.world.max_science_pack[self.player].value + 1) / 7) + self.custom_recipes["rocket-silo"] = new_recipe + + if self.world.satellite[self.player].value == Satellite.option_randomize_recipe: + new_recipe = self.make_balanced_recipe(recipes["satellite"], valid_pool, + factor=(self.world.max_science_pack[self.player].value + 1) / 7) + self.custom_recipes["satellite"] = new_recipe + + needed_recipes = self.world.max_science_pack[self.player].get_allowed_packs() | {"rocket-part"} + if self.world.silo[self.player] != Silo.option_spawn: + needed_recipes |= {"rocket-silo"} if self.world.max_science_pack[self.player].value == MaxSciencePack.option_space_science_pack: needed_recipes |= {"satellite"} for recipe in needed_recipes: recipe = self.custom_recipes.get(recipe, recipes[recipe]) + self.advancement_technologies |= {tech.name for tech in recipe.unlocking_technologies} self.advancement_technologies |= {tech.name for tech in recipe.recursive_unlocking_technologies} # handle marking progressive techs as advancement