| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | from __future__ import annotations | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 19:03:41 +02:00
										 |  |  | import collections | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | import logging | 
					
						
							| 
									
										
										
										
											2023-07-05 22:39:35 +02:00
										 |  |  | import settings | 
					
						
							| 
									
										
										
										
											2021-11-20 04:47:19 +01:00
										 |  |  | import typing | 
					
						
							| 
									
										
										
										
											2021-08-03 19:03:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 18:06:43 -06:00
										 |  |  | from BaseClasses import Region, Entrance, Location, Item, Tutorial, ItemClassification | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | from worlds.AutoWorld import World, WebWorld | 
					
						
							| 
									
										
										
										
											2023-06-25 02:31:25 +02:00
										 |  |  | from worlds.LauncherComponents import Component, components, Type, launch_subprocess | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  | from worlds.generic import Rules | 
					
						
							|  |  |  | from .Locations import location_pools, location_table | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | from .Mod import generate_mod | 
					
						
							| 
									
										
										
										
											2023-01-28 00:38:12 +01:00
										 |  |  | from .Options import factorio_options, MaxSciencePack, Silo, Satellite, TechTreeInformation, Goal, TechCostDistribution | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | from .Shapes import get_shapes | 
					
						
							| 
									
										
										
										
											2021-11-20 04:47:19 +01:00
										 |  |  | from .Technologies import base_tech_table, recipe_sources, base_technology_table, \ | 
					
						
							| 
									
										
										
										
											2022-06-19 18:06:27 +02:00
										 |  |  |     all_ingredient_names, all_product_sources, required_technologies, get_rocket_requirements, \ | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  |     progressive_technology_table, common_tech_table, tech_to_progressive_lookup, progressive_tech_table, \ | 
					
						
							| 
									
										
										
										
											2021-11-25 09:44:01 -08:00
										 |  |  |     get_science_pack_pools, Recipe, recipes, technology_table, tech_table, factorio_base_id, useless_technologies, \ | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |     fluids, stacking_items, valid_ingredients, progressive_rows | 
					
						
							| 
									
										
										
										
											2023-03-20 21:24:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-25 02:31:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | def launch_client(): | 
					
						
							|  |  |  |     from .Client import launch | 
					
						
							|  |  |  |     launch_subprocess(launch, name="FactorioClient") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | components.append(Component("Factorio Client", "FactorioClient", func=launch_client, component_type=Type.CLIENT)) | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-12 13:54:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 22:39:35 +02:00
										 |  |  | class FactorioSettings(settings.Group): | 
					
						
							|  |  |  |     class Executable(settings.UserFilePath): | 
					
						
							|  |  |  |         is_exe = True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class ServerSettings(settings.OptionalUserFilePath): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         by default, no settings are loaded if this file does not exist. \ | 
					
						
							|  |  |  | If this file does exist, then it will be used. | 
					
						
							|  |  |  |         server_settings: "factorio\\\\data\\\\server-settings.json" | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class FilterItemSends(settings.Bool): | 
					
						
							|  |  |  |         """Whether to filter item send messages displayed in-game to only those that involve you.""" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class BridgeChatOut(settings.Bool): | 
					
						
							|  |  |  |         """Whether to send chat messages from players on the Factorio server to Archipelago.""" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     executable: Executable = Executable("factorio/bin/x64/factorio") | 
					
						
							|  |  |  |     server_settings: typing.Optional[FactorioSettings.ServerSettings] = None | 
					
						
							|  |  |  |     filter_item_sends: typing.Union[FilterItemSends, bool] = False | 
					
						
							|  |  |  |     bridge_chat_out: typing.Union[BridgeChatOut, bool] = True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-11 13:05:53 -05:00
										 |  |  | class FactorioWeb(WebWorld): | 
					
						
							|  |  |  |     tutorials = [Tutorial( | 
					
						
							| 
									
										
										
										
											2024-02-20 11:22:32 -05:00
										 |  |  |         "Multiworld Setup Guide", | 
					
						
							| 
									
										
										
										
											2022-05-11 13:05:53 -05:00
										 |  |  |         "A guide to setting up the Archipelago Factorio software on your computer.", | 
					
						
							|  |  |  |         "English", | 
					
						
							|  |  |  |         "setup_en.md", | 
					
						
							|  |  |  |         "setup/en", | 
					
						
							|  |  |  |         ["Berserker, Farrak Kilhn"] | 
					
						
							|  |  |  |     )] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-12 13:54:47 +02:00
										 |  |  | class FactorioItem(Item): | 
					
						
							|  |  |  |     game = "Factorio" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 05:40:51 +02:00
										 |  |  | all_items = tech_table.copy() | 
					
						
							|  |  |  | all_items["Attack Trap"] = factorio_base_id - 1 | 
					
						
							|  |  |  | all_items["Evolution Trap"] = factorio_base_id - 2 | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  | all_items["Teleport Trap"] = factorio_base_id - 3 | 
					
						
							|  |  |  | all_items["Grenade Trap"] = factorio_base_id - 4 | 
					
						
							|  |  |  | all_items["Cluster Grenade Trap"] = factorio_base_id - 5 | 
					
						
							|  |  |  | all_items["Artillery Trap"] = factorio_base_id - 6 | 
					
						
							|  |  |  | all_items["Atomic Rocket Trap"] = factorio_base_id - 7 | 
					
						
							| 
									
										
										
										
											2021-08-04 05:40:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-13 01:34:59 +02:00
										 |  |  | class Factorio(World): | 
					
						
							| 
									
										
										
										
											2021-08-31 17:28:46 -04:00
										 |  |  |     """
 | 
					
						
							|  |  |  |     Factorio is a game about automation. You play as an engineer who has crash landed on the planet | 
					
						
							|  |  |  |     Nauvis, an inhospitable world filled with dangerous creatures called biters. Build a factory, | 
					
						
							|  |  |  |     research new technologies, and become more efficient in your quest to build a rocket and return home. | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |     game = "Factorio" | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |     special_nodes = {"automation", "logistics", "rocket-silo"} | 
					
						
							| 
									
										
										
										
											2022-03-14 19:40:35 +01:00
										 |  |  |     custom_recipes: typing.Dict[str, Recipe] | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |     location_pool: typing.List[FactorioScienceLocation] | 
					
						
							| 
									
										
										
										
											2021-11-20 04:47:19 +01:00
										 |  |  |     advancement_technologies: typing.Set[str] | 
					
						
							| 
									
										
										
										
											2021-06-11 14:22:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-11 13:05:53 -05:00
										 |  |  |     web = FactorioWeb() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 05:40:51 +02:00
										 |  |  |     item_name_to_id = all_items | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |     location_name_to_id = location_table | 
					
						
							| 
									
										
										
										
											2022-02-05 15:49:19 +01:00
										 |  |  |     item_name_groups = { | 
					
						
							| 
									
										
										
										
											2022-06-01 17:25:40 +02:00
										 |  |  |         "Progressive": set(progressive_tech_table.keys()), | 
					
						
							| 
									
										
										
										
											2022-02-05 15:49:19 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |     data_version = 8 | 
					
						
							| 
									
										
										
										
											2023-07-24 00:09:47 +02:00
										 |  |  |     required_client_version = (0, 4, 2) | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ordered_science_packs: typing.List[str] = MaxSciencePack.get_ordered_science_packs() | 
					
						
							| 
									
										
										
										
											2023-04-24 01:58:26 +02:00
										 |  |  |     tech_tree_layout_prerequisites: typing.Dict[FactorioScienceLocation, typing.Set[FactorioScienceLocation]] | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |     tech_mix: int = 0 | 
					
						
							|  |  |  |     skip_silo: bool = False | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |     science_locations: typing.List[FactorioScienceLocation] | 
					
						
							| 
									
										
										
										
											2021-08-01 06:15:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-05 22:39:35 +02:00
										 |  |  |     settings: typing.ClassVar[FactorioSettings] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-19 19:44:34 +01:00
										 |  |  |     def __init__(self, world, player: int): | 
					
						
							|  |  |  |         super(Factorio, self).__init__(world, player) | 
					
						
							| 
									
										
										
										
											2021-11-20 04:47:19 +01:00
										 |  |  |         self.advancement_technologies = set() | 
					
						
							| 
									
										
										
										
											2022-03-14 19:40:35 +01:00
										 |  |  |         self.custom_recipes = {} | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |         self.science_locations = [] | 
					
						
							| 
									
										
										
										
											2023-04-24 01:58:26 +02:00
										 |  |  |         self.tech_tree_layout_prerequisites = {} | 
					
						
							| 
									
										
										
										
											2021-10-09 20:38:53 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  |     generate_output = generate_mod | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |     def generate_early(self) -> None: | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |         # if max < min, then swap max and min | 
					
						
							|  |  |  |         if self.multiworld.max_tech_cost[self.player] < self.multiworld.min_tech_cost[self.player]: | 
					
						
							|  |  |  |             self.multiworld.min_tech_cost[self.player].value, self.multiworld.max_tech_cost[self.player].value = \ | 
					
						
							|  |  |  |                 self.multiworld.max_tech_cost[self.player].value, self.multiworld.min_tech_cost[self.player].value | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |         self.tech_mix = self.multiworld.tech_cost_mix[self.player] | 
					
						
							|  |  |  |         self.skip_silo = self.multiworld.silo[self.player].value == Silo.option_spawn | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-11 18:02:48 +02:00
										 |  |  |     def create_regions(self): | 
					
						
							|  |  |  |         player = self.player | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |         random = self.multiworld.random | 
					
						
							| 
									
										
										
										
											2023-02-13 18:06:43 -06:00
										 |  |  |         menu = Region("Menu", player, self.multiworld) | 
					
						
							| 
									
										
										
										
											2021-06-11 14:22:44 +02:00
										 |  |  |         crash = Entrance(player, "Crash Land", menu) | 
					
						
							|  |  |  |         menu.exits.append(crash) | 
					
						
							| 
									
										
										
										
											2023-02-13 18:06:43 -06:00
										 |  |  |         nauvis = Region("Nauvis", player, self.multiworld) | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |         location_count = len(base_tech_table) - len(useless_technologies) - self.skip_silo + \ | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |                          self.multiworld.evolution_traps[player] + \ | 
					
						
							|  |  |  |                          self.multiworld.attack_traps[player] + \ | 
					
						
							|  |  |  |                          self.multiworld.teleport_traps[player] + \ | 
					
						
							|  |  |  |                          self.multiworld.grenade_traps[player] + \ | 
					
						
							|  |  |  |                          self.multiworld.cluster_grenade_traps[player] + \ | 
					
						
							|  |  |  |                          self.multiworld.atomic_rocket_traps[player] + \ | 
					
						
							|  |  |  |                          self.multiworld.artillery_traps[player] | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         location_pool = [] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |         for pack in sorted(self.multiworld.max_science_pack[self.player].get_allowed_packs()): | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |             location_pool.extend(location_pools[pack]) | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |         try: | 
					
						
							|  |  |  |             location_names = self.multiworld.random.sample(location_pool, location_count) | 
					
						
							|  |  |  |         except ValueError as e: | 
					
						
							|  |  |  |             # should be "ValueError: Sample larger than population or is negative" | 
					
						
							|  |  |  |             raise Exception("Too many traps for too few locations. Either decrease the trap count, " | 
					
						
							|  |  |  |                             f"or increase the location count (higher max science pack). (Player {self.player})") from e | 
					
						
							| 
									
										
										
										
											2022-10-30 14:34:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |         self.science_locations = [FactorioScienceLocation(player, loc_name, self.location_name_to_id[loc_name], nauvis) | 
					
						
							|  |  |  |                                   for loc_name in location_names] | 
					
						
							| 
									
										
										
										
											2023-01-28 00:38:12 +01:00
										 |  |  |         distribution: TechCostDistribution = self.multiworld.tech_cost_distribution[self.player] | 
					
						
							|  |  |  |         min_cost = self.multiworld.min_tech_cost[self.player] | 
					
						
							|  |  |  |         max_cost = self.multiworld.max_tech_cost[self.player] | 
					
						
							|  |  |  |         if distribution == distribution.option_even: | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |             rand_values = (random.randint(min_cost, max_cost) for _ in self.science_locations) | 
					
						
							| 
									
										
										
										
											2023-01-28 00:38:12 +01:00
										 |  |  |         else: | 
					
						
							|  |  |  |             mode = {distribution.option_low: min_cost, | 
					
						
							|  |  |  |                     distribution.option_middle: (min_cost+max_cost)//2, | 
					
						
							|  |  |  |                     distribution.option_high: max_cost}[distribution.value] | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |             rand_values = (random.triangular(min_cost, max_cost, mode) for _ in self.science_locations) | 
					
						
							| 
									
										
										
										
											2023-01-28 00:38:12 +01:00
										 |  |  |         rand_values = sorted(rand_values) | 
					
						
							| 
									
										
										
										
											2023-01-28 00:30:05 +01:00
										 |  |  |         if self.multiworld.ramping_tech_costs[self.player]: | 
					
						
							|  |  |  |             def sorter(loc: FactorioScienceLocation): | 
					
						
							|  |  |  |                 return loc.complexity, loc.rel_cost | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             def sorter(loc: FactorioScienceLocation): | 
					
						
							|  |  |  |                 return loc.rel_cost | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |         for i, location in enumerate(sorted(self.science_locations, key=sorter)): | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |             location.count = rand_values[i] | 
					
						
							|  |  |  |         del rand_values | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |         nauvis.locations.extend(self.science_locations) | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |         location = FactorioLocation(player, "Rocket Launch", None, nauvis) | 
					
						
							| 
									
										
										
										
											2021-05-22 10:06:21 +02:00
										 |  |  |         nauvis.locations.append(location) | 
					
						
							| 
									
										
										
										
											2022-06-17 03:23:27 +02:00
										 |  |  |         event = FactorioItem("Victory", ItemClassification.progression, None, player) | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |         location.place_locked_item(event) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |         for ingredient in sorted(self.multiworld.max_science_pack[self.player].get_allowed_packs()): | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |             location = FactorioLocation(player, f"Automate {ingredient}", None, nauvis) | 
					
						
							| 
									
										
										
										
											2021-06-11 14:22:44 +02:00
										 |  |  |             nauvis.locations.append(location) | 
					
						
							| 
									
										
										
										
											2022-06-17 03:23:27 +02:00
										 |  |  |             event = FactorioItem(f"Automated {ingredient}", ItemClassification.progression, None, player) | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |             location.place_locked_item(event) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-11 14:22:44 +02:00
										 |  |  |         crash.connect(nauvis) | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |         self.multiworld.regions += [menu, nauvis] | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |     def create_items(self) -> None: | 
					
						
							|  |  |  |         player = self.player | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |         self.custom_technologies = self.set_custom_technologies() | 
					
						
							|  |  |  |         self.set_custom_recipes() | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |         traps = ("Evolution", "Attack", "Teleport", "Grenade", "Cluster Grenade", "Artillery", "Atomic Rocket") | 
					
						
							|  |  |  |         for trap_name in traps: | 
					
						
							|  |  |  |             self.multiworld.itempool.extend(self.create_item(f"{trap_name} Trap") for _ in | 
					
						
							|  |  |  |                                             range(getattr(self.multiworld, | 
					
						
							|  |  |  |                                                           f"{trap_name.lower().replace(' ', '_')}_traps")[player])) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |         want_progressives = collections.defaultdict(lambda: self.multiworld.progressive[player]. | 
					
						
							|  |  |  |                                                     want_progressives(self.multiworld.random)) | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |         cost_sorted_locations = sorted(self.science_locations, key=lambda location: location.name) | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |         special_index = {"automation": 0, | 
					
						
							|  |  |  |                          "logistics": 1, | 
					
						
							|  |  |  |                          "rocket-silo": -1} | 
					
						
							|  |  |  |         loc: FactorioScienceLocation | 
					
						
							| 
									
										
										
										
											2022-11-21 19:30:45 +01:00
										 |  |  |         if self.multiworld.tech_tree_information[player] == TechTreeInformation.option_full: | 
					
						
							|  |  |  |             # mark all locations as pre-hinted | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |             for loc in self.science_locations: | 
					
						
							| 
									
										
										
										
											2022-11-21 19:30:45 +01:00
										 |  |  |                 loc.revealed = True | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |         if self.skip_silo: | 
					
						
							|  |  |  |             removed = useless_technologies | {"rocket-silo"} | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             removed = useless_technologies | 
					
						
							|  |  |  |         for tech_name in base_tech_table: | 
					
						
							|  |  |  |             if tech_name not in removed: | 
					
						
							|  |  |  |                 progressive_item_name = tech_to_progressive_lookup.get(tech_name, tech_name) | 
					
						
							|  |  |  |                 want_progressive = want_progressives[progressive_item_name] | 
					
						
							|  |  |  |                 item_name = progressive_item_name if want_progressive else tech_name | 
					
						
							|  |  |  |                 tech_item = self.create_item(item_name) | 
					
						
							|  |  |  |                 index = special_index.get(tech_name, None) | 
					
						
							|  |  |  |                 if index is None: | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |                     self.multiworld.itempool.append(tech_item) | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |                 else: | 
					
						
							|  |  |  |                     loc = cost_sorted_locations[index] | 
					
						
							| 
									
										
										
										
											2023-01-24 03:36:50 +01:00
										 |  |  |                     if index >= 0: | 
					
						
							|  |  |  |                         # beginning techs - limit cost to 10 | 
					
						
							|  |  |  |                         # as automation is not achievable yet and hand-crafting for hours is not fun gameplay | 
					
						
							|  |  |  |                         loc.count = min(loc.count, 10) | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |                     loc.place_locked_item(tech_item) | 
					
						
							|  |  |  |                     loc.revealed = True | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |     def set_rules(self): | 
					
						
							|  |  |  |         world = self.multiworld | 
					
						
							|  |  |  |         player = self.player | 
					
						
							|  |  |  |         shapes = get_shapes(self) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for ingredient in self.multiworld.max_science_pack[self.player].get_allowed_packs(): | 
					
						
							|  |  |  |             location = world.get_location(f"Automate {ingredient}", player) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if self.multiworld.recipe_ingredients[self.player]: | 
					
						
							|  |  |  |                 custom_recipe = self.custom_recipes[ingredient] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 location.access_rule = lambda state, ingredient=ingredient, custom_recipe=custom_recipe: \ | 
					
						
							|  |  |  |                     (ingredient not in technology_table or state.has(ingredient, player)) and \ | 
					
						
							|  |  |  |                     all(state.has(technology.name, player) for sub_ingredient in custom_recipe.ingredients | 
					
						
							| 
									
										
										
										
											2023-12-22 20:02:49 -08:00
										 |  |  |                         for technology in required_technologies[sub_ingredient]) and \ | 
					
						
							|  |  |  |                     all(state.has(technology.name, player) for technology in required_technologies[custom_recipe.crafting_machine]) | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |             else: | 
					
						
							|  |  |  |                 location.access_rule = lambda state, ingredient=ingredient: \ | 
					
						
							|  |  |  |                     all(state.has(technology.name, player) for technology in required_technologies[ingredient]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for location in self.science_locations: | 
					
						
							|  |  |  |             Rules.set_rule(location, lambda state, ingredients=location.ingredients: | 
					
						
							|  |  |  |                 all(state.has(f"Automated {ingredient}", player) for ingredient in ingredients)) | 
					
						
							|  |  |  |             prerequisites = shapes.get(location) | 
					
						
							|  |  |  |             if prerequisites: | 
					
						
							|  |  |  |                 Rules.add_rule(location, lambda state, locations= | 
					
						
							|  |  |  |                     prerequisites: all(state.can_reach(loc) for loc in locations)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         silo_recipe = None | 
					
						
							|  |  |  |         if self.multiworld.silo[self.player] == Silo.option_spawn: | 
					
						
							|  |  |  |             silo_recipe = self.custom_recipes["rocket-silo"] if "rocket-silo" in self.custom_recipes \ | 
					
						
							|  |  |  |                 else next(iter(all_product_sources.get("rocket-silo"))) | 
					
						
							|  |  |  |         part_recipe = self.custom_recipes["rocket-part"] | 
					
						
							|  |  |  |         satellite_recipe = None | 
					
						
							|  |  |  |         if self.multiworld.goal[self.player] == Goal.option_satellite: | 
					
						
							|  |  |  |             satellite_recipe = self.custom_recipes["satellite"] if "satellite" in self.custom_recipes \ | 
					
						
							|  |  |  |                 else next(iter(all_product_sources.get("satellite"))) | 
					
						
							|  |  |  |         victory_tech_names = get_rocket_requirements(silo_recipe, part_recipe, satellite_recipe) | 
					
						
							|  |  |  |         if self.multiworld.silo[self.player] != Silo.option_spawn: | 
					
						
							|  |  |  |             victory_tech_names.add("rocket-silo") | 
					
						
							|  |  |  |         world.get_location("Rocket Launch", player).access_rule = lambda state: all(state.has(technology, player) | 
					
						
							|  |  |  |                                                                                     for technology in | 
					
						
							|  |  |  |                                                                                     victory_tech_names) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         world.completion_condition[player] = lambda state: state.has('Victory', player) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def generate_basic(self): | 
					
						
							|  |  |  |         map_basic_settings = self.multiworld.world_gen[self.player].value["basic"] | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |         if map_basic_settings.get("seed", None) is None:  # allow seed 0 | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |             # 32 bit uint | 
					
						
							|  |  |  |             map_basic_settings["seed"] = self.multiworld.per_slot_randoms[self.player].randint(0, 2 ** 32 - 1) | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-21 19:30:45 +01:00
										 |  |  |         start_location_hints: typing.Set[str] = self.multiworld.start_location_hints[self.player].value | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-09 20:58:24 +02:00
										 |  |  |         for loc in self.science_locations: | 
					
						
							| 
									
										
										
										
											2022-11-21 19:30:45 +01:00
										 |  |  |             # show start_location_hints ingame | 
					
						
							|  |  |  |             if loc.name in start_location_hints: | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |                 loc.revealed = True | 
					
						
							| 
									
										
										
										
											2022-11-21 19:30:45 +01:00
										 |  |  |             # make spoiler match mod info | 
					
						
							|  |  |  |             elif loc.revealed: | 
					
						
							|  |  |  |                 start_location_hints.add(loc.name) | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-21 06:55:08 +02:00
										 |  |  |     def collect_item(self, state, item, remove=False): | 
					
						
							| 
									
										
										
										
											2021-07-04 22:21:53 +02:00
										 |  |  |         if item.advancement and item.name in progressive_technology_table: | 
					
						
							|  |  |  |             prog_table = progressive_technology_table[item.name].progressive | 
					
						
							| 
									
										
										
										
											2021-08-21 06:55:08 +02:00
										 |  |  |             if remove: | 
					
						
							|  |  |  |                 for item_name in reversed(prog_table): | 
					
						
							|  |  |  |                     if state.has(item_name, item.player): | 
					
						
							|  |  |  |                         return item_name | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 for item_name in prog_table: | 
					
						
							|  |  |  |                     if not state.has(item_name, item.player): | 
					
						
							|  |  |  |                         return item_name | 
					
						
							| 
									
										
										
										
											2021-08-10 09:47:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-21 06:55:08 +02:00
										 |  |  |         return super(Factorio, self).collect_item(state, item, remove) | 
					
						
							| 
									
										
										
										
											2021-07-04 22:21:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-15 16:46:59 -05:00
										 |  |  |     option_definitions = factorio_options | 
					
						
							| 
									
										
										
										
											2021-06-25 23:32:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-02 12:29:29 +01:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def stage_write_spoiler(cls, world, spoiler_handle): | 
					
						
							|  |  |  |         factorio_players = world.get_game_players(cls.game) | 
					
						
							|  |  |  |         spoiler_handle.write('\n\nFactorio Recipes:\n') | 
					
						
							|  |  |  |         for player in factorio_players: | 
					
						
							|  |  |  |             name = world.get_player_name(player) | 
					
						
							|  |  |  |             for recipe in world.worlds[player].custom_recipes.values(): | 
					
						
							|  |  |  |                 spoiler_handle.write(f"\n{recipe.name} ({name}): {recipe.ingredients} -> {recipe.products}") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-25 18:27:16 -08:00
										 |  |  |     @staticmethod | 
					
						
							|  |  |  |     def get_category(category: str, liquids: int) -> str: | 
					
						
							|  |  |  |         categories = {1: "crafting-with-fluid", | 
					
						
							|  |  |  |                       2: "chemistry"} | 
					
						
							|  |  |  |         return categories.get(liquids, category) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |     def make_quick_recipe(self, original: Recipe, pool: list, allow_liquids: int = 2, | 
					
						
							|  |  |  |                           ingredients_offset: int = 0) -> Recipe: | 
					
						
							| 
									
										
										
										
											2021-11-25 18:27:16 -08:00
										 |  |  |         new_ingredients = {} | 
					
						
							|  |  |  |         liquids_used = 0 | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |         for _ in range(len(original.ingredients) + ingredients_offset): | 
					
						
							| 
									
										
										
										
											2021-11-25 18:27:16 -08:00
										 |  |  |             new_ingredient = pool.pop() | 
					
						
							| 
									
										
										
										
											2022-06-18 13:40:02 +02:00
										 |  |  |             if new_ingredient in fluids: | 
					
						
							|  |  |  |                 while liquids_used == allow_liquids and new_ingredient in fluids: | 
					
						
							| 
									
										
										
										
											2022-03-15 14:02:05 +01:00
										 |  |  |                     # liquids already at max for current recipe. | 
					
						
							|  |  |  |                     # Return the liquid to the pool and get a new ingredient. | 
					
						
							| 
									
										
										
										
											2021-11-25 18:27:16 -08:00
										 |  |  |                     pool.append(new_ingredient) | 
					
						
							| 
									
										
										
										
											2022-03-15 14:02:05 +01:00
										 |  |  |                     new_ingredient = pool.pop(0) | 
					
						
							| 
									
										
										
										
											2022-07-31 14:01:39 -07:00
										 |  |  |                 liquids_used += 1 if new_ingredient in fluids else 0 | 
					
						
							| 
									
										
										
										
											2021-11-25 18:27:16 -08:00
										 |  |  |             new_ingredients[new_ingredient] = 1 | 
					
						
							| 
									
										
										
										
											2022-02-02 16:29:29 +01:00
										 |  |  |         return Recipe(original.name, self.get_category(original.category, liquids_used), new_ingredients, | 
					
						
							|  |  |  |                       original.products, original.energy) | 
					
						
							| 
									
										
										
										
											2021-11-25 18:27:16 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-18 09:15:14 +02:00
										 |  |  |     def make_balanced_recipe(self, original: Recipe, pool: typing.Set[str], factor: float = 1, | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |                              allow_liquids: int = 2, ingredients_offset: int = 0) -> Recipe: | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  |         """Generate a recipe from pool with time and cost similar to original * factor""" | 
					
						
							|  |  |  |         new_ingredients = {} | 
					
						
							| 
									
										
										
										
											2022-06-18 09:15:14 +02:00
										 |  |  |         # have to first sort for determinism, while filtering out non-stacking items | 
					
						
							| 
									
										
										
										
											2022-07-08 06:35:33 -07:00
										 |  |  |         pool: typing.List[str] = sorted(pool & valid_ingredients) | 
					
						
							| 
									
										
										
										
											2022-06-18 09:15:14 +02:00
										 |  |  |         # then sort with random data to shuffle | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |         self.multiworld.random.shuffle(pool) | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  |         target_raw = int(sum((count for ingredient, count in original.base_cost.items())) * factor) | 
					
						
							|  |  |  |         target_energy = original.total_energy * factor | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |         target_num_ingredients = len(original.ingredients) + ingredients_offset | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  |         remaining_raw = target_raw | 
					
						
							|  |  |  |         remaining_energy = target_energy | 
					
						
							|  |  |  |         remaining_num_ingredients = target_num_ingredients | 
					
						
							|  |  |  |         fallback_pool = [] | 
					
						
							| 
									
										
										
										
											2021-11-25 09:44:01 -08:00
										 |  |  |         liquids_used = 0 | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # fill all but one slot with random ingredients, last with a good match | 
					
						
							| 
									
										
										
										
											2021-11-19 19:44:34 +01:00
										 |  |  |         while remaining_num_ingredients > 0 and pool: | 
					
						
							| 
									
										
										
										
											2021-11-26 02:37:15 +01:00
										 |  |  |             ingredient = pool.pop() | 
					
						
							| 
									
										
										
										
											2022-06-18 13:40:02 +02:00
										 |  |  |             if liquids_used == allow_liquids and ingredient in fluids: | 
					
						
							| 
									
										
										
										
											2022-02-02 16:29:29 +01:00
										 |  |  |                 continue  # can't use this ingredient as we already have maximum liquid in our recipe. | 
					
						
							| 
									
										
										
										
											2022-05-21 20:57:26 +02:00
										 |  |  |             ingredient_raw = 0 | 
					
						
							| 
									
										
										
										
											2021-11-26 02:37:15 +01:00
										 |  |  |             if ingredient in all_product_sources: | 
					
						
							|  |  |  |                 ingredient_recipe = min(all_product_sources[ingredient], key=lambda recipe: recipe.rel_cost) | 
					
						
							|  |  |  |                 ingredient_raw = sum((count for ingredient, count in ingredient_recipe.base_cost.items())) | 
					
						
							|  |  |  |                 ingredient_energy = ingredient_recipe.total_energy | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 # assume simple ore TODO: remove if tree when mining data is harvested from Factorio | 
					
						
							|  |  |  |                 ingredient_energy = 2 | 
					
						
							| 
									
										
										
										
											2022-05-21 20:57:26 +02:00
										 |  |  |             if not ingredient_raw: | 
					
						
							|  |  |  |                 ingredient_raw = 1 | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  |             if remaining_num_ingredients == 1: | 
					
						
							|  |  |  |                 max_raw = 1.1 * remaining_raw | 
					
						
							|  |  |  |                 min_raw = 0.9 * remaining_raw | 
					
						
							|  |  |  |                 max_energy = 1.1 * remaining_energy | 
					
						
							| 
									
										
										
										
											2021-11-21 18:24:25 -08:00
										 |  |  |                 min_energy = 0.9 * remaining_energy | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  |             else: | 
					
						
							|  |  |  |                 max_raw = remaining_raw * 0.75 | 
					
						
							|  |  |  |                 min_raw = (remaining_raw - max_raw) / remaining_num_ingredients | 
					
						
							|  |  |  |                 max_energy = remaining_energy * 0.75 | 
					
						
							|  |  |  |                 min_energy = (remaining_energy - max_energy) / remaining_num_ingredients | 
					
						
							| 
									
										
										
										
											2021-09-22 08:08:29 +02:00
										 |  |  |             min_num_raw = min_raw / ingredient_raw | 
					
						
							|  |  |  |             max_num_raw = max_raw / ingredient_raw | 
					
						
							|  |  |  |             min_num_energy = min_energy / ingredient_energy | 
					
						
							|  |  |  |             max_num_energy = max_energy / ingredient_energy | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  |             min_num = int(max(1, min_num_raw, min_num_energy)) | 
					
						
							|  |  |  |             max_num = int(min(1000, max_num_raw, max_num_energy)) | 
					
						
							|  |  |  |             if min_num > max_num: | 
					
						
							|  |  |  |                 fallback_pool.append(ingredient) | 
					
						
							| 
									
										
										
										
											2021-09-22 08:08:29 +02:00
										 |  |  |                 continue  # can't use that ingredient | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |             num = self.multiworld.random.randint(min_num, max_num) | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  |             new_ingredients[ingredient] = num | 
					
						
							|  |  |  |             remaining_raw -= num * ingredient_raw | 
					
						
							|  |  |  |             remaining_energy -= num * ingredient_energy | 
					
						
							|  |  |  |             remaining_num_ingredients -= 1 | 
					
						
							| 
									
										
										
										
											2022-06-18 13:40:02 +02:00
										 |  |  |             if ingredient in fluids: | 
					
						
							| 
									
										
										
										
											2021-11-25 09:44:01 -08:00
										 |  |  |                 liquids_used += 1 | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # fill failed slots with whatever we got | 
					
						
							|  |  |  |         pool = fallback_pool | 
					
						
							| 
									
										
										
										
											2021-11-19 19:44:34 +01:00
										 |  |  |         while remaining_num_ingredients > 0 and pool: | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  |             ingredient = pool.pop() | 
					
						
							| 
									
										
										
										
											2022-06-18 13:40:02 +02:00
										 |  |  |             if liquids_used == allow_liquids and ingredient in fluids: | 
					
						
							| 
									
										
										
										
											2021-11-26 02:37:15 +01:00
										 |  |  |                 continue  # can't use this ingredient as we already have maximum liquid in our recipe. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-25 16:38:33 -08:00
										 |  |  |             ingredient_recipe = recipes.get(ingredient, None) | 
					
						
							|  |  |  |             if not ingredient_recipe and ingredient.endswith("-barrel"): | 
					
						
							|  |  |  |                 ingredient_recipe = recipes.get(f"fill-{ingredient}", None) | 
					
						
							|  |  |  |             if not ingredient_recipe: | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  |                 logging.warning(f"missing recipe for {ingredient}") | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             ingredient_raw = sum((count for ingredient, count in ingredient_recipe.base_cost.items())) | 
					
						
							|  |  |  |             ingredient_energy = ingredient_recipe.total_energy | 
					
						
							| 
									
										
										
										
											2021-09-22 08:08:29 +02:00
										 |  |  |             num_raw = remaining_raw / ingredient_raw / remaining_num_ingredients | 
					
						
							|  |  |  |             num_energy = remaining_energy / ingredient_energy / remaining_num_ingredients | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  |             num = int(min(num_raw, num_energy)) | 
					
						
							| 
									
										
										
										
											2021-11-26 02:37:15 +01:00
										 |  |  |             if num < 1: | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  |             new_ingredients[ingredient] = num | 
					
						
							|  |  |  |             remaining_raw -= num * ingredient_raw | 
					
						
							|  |  |  |             remaining_energy -= num * ingredient_energy | 
					
						
							|  |  |  |             remaining_num_ingredients -= 1 | 
					
						
							| 
									
										
										
										
											2022-06-18 13:40:02 +02:00
										 |  |  |             if ingredient in fluids: | 
					
						
							| 
									
										
										
										
											2021-11-25 09:44:01 -08:00
										 |  |  |                 liquids_used += 1 | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if remaining_num_ingredients > 1: | 
					
						
							|  |  |  |             logging.warning("could not randomize recipe") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-02 16:29:29 +01:00
										 |  |  |         return Recipe(original.name, self.get_category(original.category, liquids_used), new_ingredients, | 
					
						
							|  |  |  |                       original.products, original.energy) | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  |     def set_custom_technologies(self): | 
					
						
							|  |  |  |         custom_technologies = {} | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |         allowed_packs = self.multiworld.max_science_pack[self.player].get_allowed_packs() | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  |         for technology_name, technology in base_technology_table.items(): | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |             custom_technologies[technology_name] = technology.get_custom(self.multiworld, allowed_packs, self.player) | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  |         return custom_technologies | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def set_custom_recipes(self): | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |         ingredients_offset = self.multiworld.recipe_ingredients_offset[self.player] | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  |         original_rocket_part = recipes["rocket-part"] | 
					
						
							| 
									
										
										
										
											2021-07-09 17:44:24 +02:00
										 |  |  |         science_pack_pools = get_science_pack_pools() | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |         valid_pool = sorted(science_pack_pools[self.multiworld.max_science_pack[self.player].get_max_pack()] & valid_ingredients) | 
					
						
							|  |  |  |         self.multiworld.random.shuffle(valid_pool) | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  |         self.custom_recipes = {"rocket-part": Recipe("rocket-part", original_rocket_part.category, | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |                                                      {valid_pool[x]: 10 for x in range(3 + ingredients_offset)}, | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  |                                                      original_rocket_part.products, | 
					
						
							|  |  |  |                                                      original_rocket_part.energy)} | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |         if self.multiworld.recipe_ingredients[self.player]: | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  |             valid_pool = [] | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |             for pack in self.multiworld.max_science_pack[self.player].get_ordered_science_packs(): | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  |                 valid_pool += sorted(science_pack_pools[pack]) | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |                 self.multiworld.random.shuffle(valid_pool) | 
					
						
							| 
									
										
										
										
											2021-09-22 08:08:29 +02:00
										 |  |  |                 if pack in recipes:  # skips over space science pack | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |                     new_recipe = self.make_quick_recipe(recipes[pack], valid_pool, ingredients_offset= | 
					
						
							|  |  |  |                                                         ingredients_offset) | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  |                     self.custom_recipes[pack] = new_recipe | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |         if self.multiworld.silo[self.player].value == Silo.option_randomize_recipe \ | 
					
						
							|  |  |  |                 or self.multiworld.satellite[self.player].value == Satellite.option_randomize_recipe: | 
					
						
							| 
									
										
										
										
											2022-06-18 09:15:14 +02:00
										 |  |  |             valid_pool = set() | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |             for pack in sorted(self.multiworld.max_science_pack[self.player].get_allowed_packs()): | 
					
						
							| 
									
										
										
										
											2022-06-18 09:15:14 +02:00
										 |  |  |                 valid_pool |= science_pack_pools[pack] | 
					
						
							| 
									
										
										
										
											2021-07-24 01:41:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |             if self.multiworld.silo[self.player].value == Silo.option_randomize_recipe: | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |                 new_recipe = self.make_balanced_recipe( | 
					
						
							|  |  |  |                     recipes["rocket-silo"], valid_pool, | 
					
						
							|  |  |  |                     factor=(self.multiworld.max_science_pack[self.player].value + 1) / 7, | 
					
						
							|  |  |  |                     ingredients_offset=ingredients_offset) | 
					
						
							| 
									
										
										
										
											2021-11-20 16:27:17 -08:00
										 |  |  |                 self.custom_recipes["rocket-silo"] = new_recipe | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |             if self.multiworld.satellite[self.player].value == Satellite.option_randomize_recipe: | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |                 new_recipe = self.make_balanced_recipe( | 
					
						
							|  |  |  |                     recipes["satellite"], valid_pool, | 
					
						
							|  |  |  |                     factor=(self.multiworld.max_science_pack[self.player].value + 1) / 7, | 
					
						
							|  |  |  |                     ingredients_offset=ingredients_offset) | 
					
						
							| 
									
										
										
										
											2021-11-20 16:27:17 -08:00
										 |  |  |                 self.custom_recipes["satellite"] = new_recipe | 
					
						
							| 
									
										
										
										
											2022-03-14 19:40:35 +01:00
										 |  |  |         bridge = "ap-energy-bridge" | 
					
						
							|  |  |  |         new_recipe = self.make_quick_recipe( | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |             Recipe(bridge, "crafting", {"replace_1": 1, "replace_2": 1, "replace_3": 1, | 
					
						
							|  |  |  |                                         "replace_4": 1, "replace_5": 1, "replace_6": 1}, | 
					
						
							| 
									
										
										
										
											2022-03-14 19:40:35 +01:00
										 |  |  |                    {bridge: 1}, 10), | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |             sorted(science_pack_pools[self.multiworld.max_science_pack[self.player].get_ordered_science_packs()[0]]), | 
					
						
							|  |  |  |             ingredients_offset=ingredients_offset) | 
					
						
							| 
									
										
										
										
											2022-03-14 19:40:35 +01:00
										 |  |  |         for ingredient_name in new_recipe.ingredients: | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |             new_recipe.ingredients[ingredient_name] = self.multiworld.random.randint(50, 500) | 
					
						
							| 
									
										
										
										
											2022-03-14 19:40:35 +01:00
										 |  |  |         self.custom_recipes[bridge] = new_recipe | 
					
						
							| 
									
										
										
										
											2021-11-20 16:27:17 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |         needed_recipes = self.multiworld.max_science_pack[self.player].get_allowed_packs() | {"rocket-part"} | 
					
						
							|  |  |  |         if self.multiworld.silo[self.player] != Silo.option_spawn: | 
					
						
							| 
									
										
										
										
											2021-11-20 16:27:17 -08:00
										 |  |  |             needed_recipes |= {"rocket-silo"} | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |         if self.multiworld.goal[self.player].value == Goal.option_satellite: | 
					
						
							| 
									
										
										
										
											2021-11-20 12:35:51 -08:00
										 |  |  |             needed_recipes |= {"satellite"} | 
					
						
							| 
									
										
										
										
											2021-11-20 04:47:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         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} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  |         # handle marking progressive techs as advancement | 
					
						
							|  |  |  |         prog_add = set() | 
					
						
							| 
									
										
										
										
											2021-11-20 04:47:19 +01:00
										 |  |  |         for tech in self.advancement_technologies: | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  |             if tech in tech_to_progressive_lookup: | 
					
						
							|  |  |  |                 prog_add.add(tech_to_progressive_lookup[tech]) | 
					
						
							| 
									
										
										
										
											2021-11-20 04:47:19 +01:00
										 |  |  |         self.advancement_technologies |= prog_add | 
					
						
							| 
									
										
										
										
											2021-07-12 13:54:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-17 03:23:27 +02:00
										 |  |  |     def create_item(self, name: str) -> FactorioItem: | 
					
						
							|  |  |  |         if name in tech_table:  # is a Technology | 
					
						
							|  |  |  |             if name in self.advancement_technologies: | 
					
						
							|  |  |  |                 classification = ItemClassification.progression | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 classification = ItemClassification.filler | 
					
						
							|  |  |  |             return FactorioItem(name, | 
					
						
							|  |  |  |                                 classification, | 
					
						
							| 
									
										
										
										
											2021-08-04 05:40:51 +02:00
										 |  |  |                                 tech_table[name], self.player) | 
					
						
							| 
									
										
										
										
											2021-09-29 05:21:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-17 03:23:27 +02:00
										 |  |  |         item = FactorioItem(name, | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |                             ItemClassification.trap if name.endswith("Trap") else ItemClassification.filler, | 
					
						
							| 
									
										
										
										
											2022-06-17 03:23:27 +02:00
										 |  |  |                             all_items[name], self.player) | 
					
						
							| 
									
										
										
										
											2021-09-29 05:21:33 +02:00
										 |  |  |         return item | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FactorioLocation(Location): | 
					
						
							|  |  |  |     game: str = Factorio.game | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FactorioScienceLocation(FactorioLocation): | 
					
						
							|  |  |  |     complexity: int | 
					
						
							|  |  |  |     revealed: bool = False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Factorio technology properties: | 
					
						
							|  |  |  |     ingredients: typing.Dict[str, int] | 
					
						
							| 
									
										
										
										
											2023-01-24 03:36:50 +01:00
										 |  |  |     count: int = 0 | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self, player: int, name: str, address: int, parent: Region): | 
					
						
							|  |  |  |         super(FactorioScienceLocation, self).__init__(player, name, address, parent) | 
					
						
							|  |  |  |         # "AP-{Complexity}-{Cost}" | 
					
						
							|  |  |  |         self.complexity = int(self.name[3]) - 1 | 
					
						
							| 
									
										
										
										
											2023-11-07 21:02:28 +01:00
										 |  |  |         self.rel_cost = int(self.name[5:]) | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         self.ingredients = {Factorio.ordered_science_packs[self.complexity]: 1} | 
					
						
							|  |  |  |         for complexity in range(self.complexity): | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |             if parent.multiworld.tech_cost_mix[self.player] > parent.multiworld.random.randint(0, 99): | 
					
						
							| 
									
										
										
										
											2022-10-28 21:00:06 +02:00
										 |  |  |                 self.ingredients[Factorio.ordered_science_packs[complexity]] = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     def factorio_ingredients(self) -> typing.List[typing.Tuple[str, int]]: | 
					
						
							|  |  |  |         return [(name, count) for name, count in self.ingredients.items()] |