From 63fb88819103751855f81c668732805ee0e51a14 Mon Sep 17 00:00:00 2001 From: CaitSith2 Date: Sun, 25 Sep 2022 07:38:05 -0700 Subject: [PATCH] Now possible to run generated modded seeds even without the json files. --- FactorioClient.py | 10 ++++++++-- worlds/factorio/Mod.py | 10 ++++++++-- worlds/factorio/__init__.py | 6 +++--- worlds/factorio/data/mod_template/control.lua | 9 ++++++++- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/FactorioClient.py b/FactorioClient.py index 6797578a3a..41bc5ca99c 100644 --- a/FactorioClient.py +++ b/FactorioClient.py @@ -65,6 +65,7 @@ class FactorioContext(CommonContext): self.factorio_json_text_parser = FactorioJSONtoTextParser(self) self.energy_link_increment = 0 self.last_deplete = 0 + self.custom_data_package = 0 async def server_auth(self, password_requested: bool = False): if password_requested and not self.password: @@ -170,7 +171,7 @@ async def game_watcher(ctx: FactorioContext): if ctx.locations_checked != research_data: bridge_logger.debug( f"New researches done: " - f"{[lookup_id_to_name[rid] for rid in research_data - ctx.locations_checked]}") + f"{[lookup_id_to_name.get(rid, f'Unknown Research (ID: {rid})') for rid in research_data - ctx.locations_checked]}") ctx.locations_checked = research_data await ctx.send_msgs([{"cmd": 'LocationChecks', "locations": tuple(research_data)}]) death_link_tick = data.get("death_link_tick", 0) @@ -268,7 +269,11 @@ async def factorio_server_watcher(ctx: FactorioContext): transfer_item: NetworkItem = ctx.items_received[ctx.send_index] item_id = transfer_item.item player_name = ctx.player_names[transfer_item.player] - if item_id not in Factorio.item_id_to_name: + if ctx.custom_data_package: + item_name = Factorio.item_id_to_name.get(item_id, f"Unknown Item (ID: {item_id})") + factorio_server_logger.info(f"Sending {item_name} to Nauvis from {player_name}.{(' (Item name might not match the seed.)' if Factorio.data_version else '')}") + commands[ctx.send_index] = f'/ap-get-technology {item_id}\t{ctx.send_index}\t{player_name}' + elif item_id not in Factorio.item_id_to_name: factorio_server_logger.error(f"Cannot send unknown item ID: {item_id}") else: item_name = Factorio.item_id_to_name[item_id] @@ -297,6 +302,7 @@ async def get_info(ctx: FactorioContext, rcon_client: factorio_rcon.RCONClient): # 0.2.0 addition, not present earlier death_link = bool(info.get("death_link", False)) ctx.energy_link_increment = info.get("energy_link", 0) + ctx.custom_data_package = info.get("custom_data_package", 0) logger.debug(f"Energy Link Increment: {ctx.energy_link_increment}") if ctx.energy_link_increment and ctx.ui: ctx.ui.enable_energy_link() diff --git a/worlds/factorio/Mod.py b/worlds/factorio/Mod.py index 65f246f404..93cc16fa19 100644 --- a/worlds/factorio/Mod.py +++ b/worlds/factorio/Mod.py @@ -14,7 +14,7 @@ import Patch from . import Options from .Technologies import tech_table, recipes, free_sample_exclusions, progressive_technology_table, \ - base_tech_table, tech_to_progressive_lookup, fluids, mods + base_tech_table, tech_to_progressive_lookup, fluids, mods, tech_table, factorio_base_id template_env: Optional[jinja2.Environment] = None @@ -118,6 +118,10 @@ def generate_mod(world, output_directory: str): return base - (base - low) * distance return random.uniform(low, high) + all_items = tech_table.copy() + all_items["Attack Trap"] = factorio_base_id - 1 + all_items["Evolution Trap"] = factorio_base_id - 2 + template_data = { "locations": locations, "player_names": multiworld.player_name, "tech_table": tech_table, "base_tech_table": base_tech_table, "tech_to_progressive_lookup": tech_to_progressive_lookup, @@ -136,11 +140,13 @@ def generate_mod(world, output_directory: str): "free_sample_blacklist": {item: 1 for item in free_sample_exclusions}, "progressive_technology_table": {tech.name: tech.progressive for tech in progressive_technology_table.values()}, + "item_id_to_name": {f"{item_id}": item_name for item_name, item_id in all_items.items()}, "custom_recipes": world.custom_recipes, "max_science_pack": multiworld.max_science_pack[player].value, "liquids": fluids, "goal": multiworld.goal[player].value, - "energy_link": multiworld.energy_link[player].value + "energy_link": multiworld.energy_link[player].value, + "custom_data_package": 1 if mods else 0 } for factorio_option in Options.factorio_options: diff --git a/worlds/factorio/__init__.py b/worlds/factorio/__init__.py index 4c0b21246c..0e969bfc21 100644 --- a/worlds/factorio/__init__.py +++ b/worlds/factorio/__init__.py @@ -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, \ 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, \ - fluids, stacking_items, valid_ingredients + fluids, stacking_items, valid_ingredients, mods from .Shapes import get_shapes from .Mod import generate_mod from .Options import factorio_options, MaxSciencePack, Silo, Satellite, TechTreeInformation, Goal @@ -54,8 +54,8 @@ class Factorio(World): item_name_groups = { "Progressive": set(progressive_tech_table.keys()), } - data_version = 5 - required_client_version = (0, 3, 0) + data_version = 0 if mods else 5 + required_client_version = (0, 3, 5) if mods else (0, 3, 0) # TODO: Update required_client_version to (0, 3, 6) when that version releases. def __init__(self, world, player: int): super(Factorio, self).__init__(world, player) diff --git a/worlds/factorio/data/mod_template/control.lua b/worlds/factorio/data/mod_template/control.lua index 51cd21e4da..9d33cf605e 100644 --- a/worlds/factorio/data/mod_template/control.lua +++ b/worlds/factorio/data/mod_template/control.lua @@ -13,6 +13,7 @@ GOAL = {{ goal }} ARCHIPELAGO_DEATH_LINK_SETTING = "archipelago-death-link-{{ slot_player }}-{{ seed_name }}" ENERGY_INCREMENT = {{ energy_link * 1000000 }} ENERGY_LINK_EFFICIENCY = 0.75 +CUSTOM_DATA_PACKAGE = {{ custom_data_package }} if settings.global[ARCHIPELAGO_DEATH_LINK_SETTING].value then DEATH_LINK = 1 @@ -515,6 +516,10 @@ commands.add_command("ap-get-technology", "Grant a technology, used by the Archi local item_name = chunks[1] local index = chunks[2] local source = chunks[3] or "Archipelago" + + if CUSTOM_DATA_PACKAGE == 1 then + item_name = item_id_to_name[item_name] or item_name + end if index == -1 then -- for coop sync and restoring from an older savegame tech = force.technologies[item_name] if tech.researched ~= true then @@ -571,7 +576,8 @@ commands.add_command("ap-rcon-info", "Used by the Archipelago client to get info ["slot_name"] = SLOT_NAME, ["seed_name"] = SEED_NAME, ["death_link"] = DEATH_LINK, - ["energy_link"] = ENERGY_INCREMENT + ["energy_link"] = ENERGY_INCREMENT, + ["custom_data_package"] = CUSTOM_DATA_PACKAGE })) end) @@ -598,3 +604,4 @@ end) -- data progressive_technologies = {{ dict_to_lua(progressive_technology_table) }} +item_id_to_name = {{ dict_to_lua(item_id_to_name) }}