From e985fc41ce9aa224c7d953b1e856c733ab514827 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Thu, 24 Feb 2022 22:40:16 +0100 Subject: [PATCH] Factorio: make EnergyLink an option --- worlds/factorio/Mod.py | 51 +++++++++++-------- worlds/factorio/Options.py | 10 +++- worlds/factorio/data/mod_template/control.lua | 13 +++-- worlds/factorio/data/mod_template/data.lua | 4 +- 4 files changed, 45 insertions(+), 33 deletions(-) diff --git a/worlds/factorio/Mod.py b/worlds/factorio/Mod.py index 0b10e8f5..204aedc2 100644 --- a/worlds/factorio/Mod.py +++ b/worlds/factorio/Mod.py @@ -53,6 +53,7 @@ recipe_time_ranges = { Options.RecipeTime.option_slow: (5, 10) } + def generate_mod(world, output_directory: str): player = world.player multiworld = world.world @@ -88,38 +89,44 @@ def generate_mod(world, output_directory: str): if base: distance = random.random() if random.randint(0, 1): - return base + (high-base) * distance + return base + (high - base) * distance else: - return base - (base-low) * distance + return base - (base - low) * distance return random.uniform(low, high) - template_data = {"locations": locations, "player_names": player_names, "tech_table": tech_table, - "base_tech_table": base_tech_table, "tech_to_progressive_lookup": tech_to_progressive_lookup, - "mod_name": mod_name, "allowed_science_packs": multiworld.max_science_pack[player].get_allowed_packs(), - "tech_cost_scale": tech_cost_scale, "custom_technologies": multiworld.worlds[player].custom_technologies, - "tech_tree_layout_prerequisites": multiworld.tech_tree_layout_prerequisites[player], - "slot_name": multiworld.player_name[player], "seed_name": multiworld.seed_name, "slot_player": player, - "starting_items": multiworld.starting_items[player], "recipes": recipes, - "random": random, "flop_random": flop_random, - "static_nodes": multiworld.worlds[player].static_nodes, - "recipe_time_scale": recipe_time_scales.get(multiworld.recipe_time[player].value, None), - "recipe_time_range": recipe_time_ranges.get(multiworld.recipe_time[player].value, None), - "free_sample_blacklist": {item : 1 for item in free_sample_blacklist}, - "progressive_technology_table": {tech.name : tech.progressive for tech in - progressive_technology_table.values()}, - "custom_recipes": world.custom_recipes, - "max_science_pack": multiworld.max_science_pack[player].value, - "liquids": liquids, - "goal": multiworld.goal[player].value} + template_data = { + "locations": locations, "player_names": player_names, "tech_table": tech_table, + "base_tech_table": base_tech_table, "tech_to_progressive_lookup": tech_to_progressive_lookup, + "mod_name": mod_name, + "allowed_science_packs": multiworld.max_science_pack[player].get_allowed_packs(), + "tech_cost_scale": tech_cost_scale, + "custom_technologies": multiworld.worlds[player].custom_technologies, + "tech_tree_layout_prerequisites": multiworld.tech_tree_layout_prerequisites[player], + "slot_name": multiworld.player_name[player], "seed_name": multiworld.seed_name, + "slot_player": player, + "starting_items": multiworld.starting_items[player], "recipes": recipes, + "random": random, "flop_random": flop_random, + "static_nodes": multiworld.worlds[player].static_nodes, + "recipe_time_scale": recipe_time_scales.get(multiworld.recipe_time[player].value, None), + "recipe_time_range": recipe_time_ranges.get(multiworld.recipe_time[player].value, None), + "free_sample_blacklist": {item: 1 for item in free_sample_blacklist}, + "progressive_technology_table": {tech.name: tech.progressive for tech in + progressive_technology_table.values()}, + "custom_recipes": world.custom_recipes, + "max_science_pack": multiworld.max_science_pack[player].value, + "liquids": liquids, + "goal": multiworld.goal[player].value, + "energy_link": multiworld.energy_link[player].value + } for factorio_option in Options.factorio_options: if factorio_option in ["free_sample_blacklist", "free_sample_whitelist"]: continue template_data[factorio_option] = getattr(multiworld, factorio_option)[player].value - + 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 diff --git a/worlds/factorio/Options.py b/worlds/factorio/Options.py index 12bb7afe..2e24fe07 100644 --- a/worlds/factorio/Options.py +++ b/worlds/factorio/Options.py @@ -1,7 +1,7 @@ from __future__ import annotations import typing -from Options import Choice, OptionDict, OptionSet, ItemDict, Option, DefaultOnToggle, Range, DeathLink +from Options import Choice, OptionDict, OptionSet, ItemDict, Option, DefaultOnToggle, Range, DeathLink, Toggle from schema import Schema, Optional, And, Or # schema helpers @@ -333,6 +333,11 @@ class ImportedBlueprint(DefaultOnToggle): display_name = "Blueprints" +class EnergyLink(Toggle): + """Allow sending energy to other worlds. 25% of the energy is lost in the transfer.""" + display_name = "EnergyLink" + + factorio_options: typing.Dict[str, type(Option)] = { "max_science_pack": MaxSciencePack, "goal": Goal, @@ -353,5 +358,6 @@ factorio_options: typing.Dict[str, type(Option)] = { "evolution_traps": EvolutionTrapCount, "attack_traps": AttackTrapCount, "evolution_trap_increase": EvolutionTrapIncrease, - "death_link": DeathLink + "death_link": DeathLink, + "energy_link": EnergyLink } diff --git a/worlds/factorio/data/mod_template/control.lua b/worlds/factorio/data/mod_template/control.lua index c95dc52a..e4249fd2 100644 --- a/worlds/factorio/data/mod_template/control.lua +++ b/worlds/factorio/data/mod_template/control.lua @@ -11,7 +11,8 @@ TRAP_EVO_FACTOR = {{ evolution_trap_increase }} / 100 MAX_SCIENCE_PACK = {{ max_science_pack }} GOAL = {{ goal }} ARCHIPELAGO_DEATH_LINK_SETTING = "archipelago-death-link-{{ slot_player }}-{{ seed_name }}" -ENERGY_INCREMENT = 0 +ENERGY_INCREMENT = {{ energy_link * 1000000 }} +ENERGY_LINK_EFFICIENCY = 0.75 if settings.global[ARCHIPELAGO_DEATH_LINK_SETTING].value then DEATH_LINK = 1 @@ -24,9 +25,6 @@ CURRENTLY_DEATH_LOCK = 0 function on_check_energy_link(event) --- assuming 1 MJ increment and 5MJ battery: --- first 2 MJ request fill, last 2 MJ push energy, middle 1 MJ does nothing - if event.tick == 0 then - ENERGY_INCREMENT = game.entity_prototypes["ap-energy-bridge"].electric_energy_source_prototype.buffer_capacity / 5 - end if event.tick % 60 == 30 then local surface = game.get_surface(1) local force = "player" @@ -39,7 +37,7 @@ function on_check_energy_link(event) if global.forcedata[force].energy < ENERGY_INCREMENT * bridgecount * 5 then for i, bridge in ipairs(bridges) do if bridge.energy > ENERGY_INCREMENT*3 then - global.forcedata[force].energy = global.forcedata[force].energy + ENERGY_INCREMENT + global.forcedata[force].energy = (global.forcedata[force].energy + ENERGY_INCREMENT) * ENERGY_LINK_EFFICIENCY bridge.energy = bridge.energy - ENERGY_INCREMENT end end @@ -55,7 +53,9 @@ function on_check_energy_link(event) end end end -script.on_event(defines.events.on_tick, on_check_energy_link) +if (ENERGY_INCREMENT) then + script.on_event(defines.events.on_tick, on_check_energy_link) +end {% if not imported_blueprints -%} function set_permissions() @@ -557,7 +557,6 @@ end) commands.add_command("ap-rcon-info", "Used by the Archipelago client to get information", function(call) - ENERGY_INCREMENT = game.entity_prototypes["ap-energy-bridge"].electric_energy_source_prototype.buffer_capacity / 5 rcon.print(game.table_to_json({ ["slot_name"] = SLOT_NAME, ["seed_name"] = SEED_NAME, diff --git a/worlds/factorio/data/mod_template/data.lua b/worlds/factorio/data/mod_template/data.lua index b8d66ad6..c5cb8988 100644 --- a/worlds/factorio/data/mod_template/data.lua +++ b/worlds/factorio/data/mod_template/data.lua @@ -3,7 +3,7 @@ local energy_bridge = table.deepcopy(data.raw["accumulator"]["accumulator"]) energy_bridge.name = "ap-energy-bridge" energy_bridge.minable.result = "ap-energy-bridge" energy_bridge.localised_name = "Archipelago EnergyLink Bridge" -energy_bridge.energy_source.buffer_capacity = "10MJ" +energy_bridge.energy_source.buffer_capacity = "5MJ" energy_bridge.energy_source.input_flow_limit = "1MW" energy_bridge.energy_source.output_flow_limit = "1MW" data.raw["accumulator"]["ap-energy-bridge"] = energy_bridge @@ -19,7 +19,7 @@ energy_bridge_recipe.name = "ap-energy-bridge" energy_bridge_recipe.result = energy_bridge_item.name energy_bridge_recipe.energy_required = 1 energy_bridge_recipe.ingredients = { {# {type="item", name="iron-plate", amount=1} TODO: randomized recipe #} } -energy_bridge_recipe.enabled = true +energy_bridge_recipe.enabled = {{ energy_link }} energy_bridge_recipe.localised_name = "Archipelago EnergyLink Bridge" data.raw["recipe"]["ap-energy-bridge"] = energy_bridge_recipe