From 17ed957c6b9ff1500c68d8cd049a3d6534fc1c61 Mon Sep 17 00:00:00 2001 From: CaitSith2 Date: Thu, 14 Oct 2021 10:20:56 -0700 Subject: [PATCH] Include military science pack in all techs military or higher. This does mean you have to get military science online to research your silo. --- worlds/factorio/Technologies.py | 6 ++++++ worlds/factorio/data/mod/lib.lua | 18 ++++++++++++++++++ .../data/mod_template/data-final-fixes.lua | 1 + 3 files changed, 25 insertions(+) diff --git a/worlds/factorio/Technologies.py b/worlds/factorio/Technologies.py index ac3dcad9..74f5bbbd 100644 --- a/worlds/factorio/Technologies.py +++ b/worlds/factorio/Technologies.py @@ -84,11 +84,17 @@ class CustomTechnology(Technology): def __init__(self, origin: Technology, world, allowed_packs: Set[str], player: int): ingredients = origin.ingredients & allowed_packs + military_allowed = "military-science-pack" in allowed_packs \ + and (ingredients & {"chemical-science-pack", "production-science-pack", "utility-science-pack"}) self.player = player if origin.name not in world.worlds[player].static_nodes: + if military_allowed: + ingredients.add("military-science-pack") ingredients = list(ingredients) ingredients.sort() # deterministic sample ingredients = world.random.sample(ingredients, world.random.randint(1, len(ingredients))) + elif origin.name == "rocket-silo" and military_allowed: + ingredients.add("military-science-pack") super(CustomTechnology, self).__init__(origin.name, ingredients, origin.factorio_id) diff --git a/worlds/factorio/data/mod/lib.lua b/worlds/factorio/data/mod/lib.lua index a341effe..8bcd7325 100644 --- a/worlds/factorio/data/mod/lib.lua +++ b/worlds/factorio/data/mod/lib.lua @@ -9,6 +9,24 @@ function filter_ingredients(ingredients, ingredient_filter) return new_ingredient_list end +function add_ingredients(ingredients, added_ingredients) + local new_ingredient_list = table.deepcopy(ingredients) + for new_ingredient, count in pairs(added_ingredients) do + local found = false + for _, old_ingredient in pairs(ingredients) do + if old_ingredient[1] == new_ingredient then + found = true + break + end + end + if not found then + table.insert(new_ingredient_list, {new_ingredient, count}) + end + end + + return new_ingredient_list +end + function get_any_stack_size(name) local item = game.item_prototypes[name] if item ~= nil then diff --git a/worlds/factorio/data/mod_template/data-final-fixes.lua b/worlds/factorio/data/mod_template/data-final-fixes.lua index 2422cbaf..df911a18 100644 --- a/worlds/factorio/data/mod_template/data-final-fixes.lua +++ b/worlds/factorio/data/mod_template/data-final-fixes.lua @@ -30,6 +30,7 @@ function prep_copy(new_copy, old_tech) local ingredient_filter = allowed_ingredients[old_tech.name] if ingredient_filter ~= nil then new_copy.unit.ingredients = filter_ingredients(new_copy.unit.ingredients, ingredient_filter) + new_copy.unit.ingredients = add_ingredients(new_copy.unit.ingredients, ingredient_filter) end end