| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | from BaseClasses import Region, Entrance, Location, MultiWorld, Item | 
					
						
							| 
									
										
										
										
											2021-04-09 22:10:04 +02:00
										 |  |  | from .Technologies import tech_table, recipe_sources, technology_table, advancement_technologies, required_technologies | 
					
						
							| 
									
										
										
										
											2021-04-11 18:19:47 +02:00
										 |  |  | from .Shapes import get_shapes | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def gen_factorio(world: MultiWorld, player: int): | 
					
						
							| 
									
										
										
										
											2021-04-11 18:19:47 +02:00
										 |  |  |     static_nodes = world._static_nodes = {"automation", "logistics"}  # turn dynamic/option? | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  |     for tech_name, tech_id in tech_table.items(): | 
					
						
							| 
									
										
										
										
											2021-04-10 00:17:55 +02:00
										 |  |  |         tech_item = Item(tech_name, tech_name in advancement_technologies, tech_id, player) | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  |         tech_item.game = "Factorio" | 
					
						
							|  |  |  |         if tech_name in static_nodes: | 
					
						
							|  |  |  |             loc = world.get_location(tech_name, player) | 
					
						
							|  |  |  |             loc.item = tech_item | 
					
						
							| 
									
										
										
										
											2021-04-09 22:10:04 +02:00
										 |  |  |             loc.locked = True | 
					
						
							|  |  |  |             loc.event = tech_item.advancement | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  |         else: | 
					
						
							|  |  |  |             world.itempool.append(tech_item) | 
					
						
							| 
									
										
										
										
											2021-04-24 01:16:49 +02:00
										 |  |  |     world.custom_data[player]["custom_technologies"] = custom_technologies = set_custom_technologies(world, player) | 
					
						
							|  |  |  |     set_rules(world, player, custom_technologies) | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def factorio_create_regions(world: MultiWorld, player: int): | 
					
						
							|  |  |  |     menu = Region("Menu", None, "Menu", player) | 
					
						
							|  |  |  |     crash = Entrance(player, "Crash Land", menu) | 
					
						
							|  |  |  |     menu.exits.append(crash) | 
					
						
							|  |  |  |     nauvis = Region("Nauvis", None, "Nauvis", player) | 
					
						
							|  |  |  |     nauvis.world = menu.world = world | 
					
						
							|  |  |  |     for tech_name, tech_id in tech_table.items(): | 
					
						
							|  |  |  |         tech = Location(player, tech_name, tech_id, nauvis) | 
					
						
							|  |  |  |         nauvis.locations.append(tech) | 
					
						
							|  |  |  |         tech.game = "Factorio" | 
					
						
							|  |  |  |     crash.connect(nauvis) | 
					
						
							|  |  |  |     world.regions += [menu, nauvis] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-24 01:16:49 +02:00
										 |  |  | def set_custom_technologies(world: MultiWorld, player: int): | 
					
						
							|  |  |  |     custom_technologies = {} | 
					
						
							|  |  |  |     world_custom = getattr(world, "_custom_technologies", {}) | 
					
						
							|  |  |  |     world_custom[player] = custom_technologies | 
					
						
							|  |  |  |     world._custom_technologies = world_custom | 
					
						
							|  |  |  |     allowed_packs = world.max_science_pack[player].get_allowed_packs() | 
					
						
							|  |  |  |     for technology_name, technology in technology_table.items(): | 
					
						
							|  |  |  |         custom_technologies[technology_name] = technology.get_custom(world, allowed_packs, player) | 
					
						
							|  |  |  |     return custom_technologies | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-24 01:16:49 +02:00
										 |  |  | def set_rules(world: MultiWorld, player: int, custom_technologies): | 
					
						
							| 
									
										
										
										
											2021-04-10 03:03:46 +02:00
										 |  |  |     shapes = get_shapes(world, player) | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  |     if world.logic[player] != 'nologic': | 
					
						
							|  |  |  |         from worlds.generic import Rules | 
					
						
							| 
									
										
										
										
											2021-04-24 01:16:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for tech_name, technology in custom_technologies.items(): | 
					
						
							| 
									
										
										
										
											2021-04-09 22:10:04 +02:00
										 |  |  |             location = world.get_location(tech_name, player) | 
					
						
							| 
									
										
										
										
											2021-04-24 01:16:49 +02:00
										 |  |  |             Rules.set_rule(location, technology.build_rule(player)) | 
					
						
							| 
									
										
										
										
											2021-04-10 03:03:46 +02:00
										 |  |  |             prequisites = shapes.get(tech_name) | 
					
						
							|  |  |  |             if prequisites: | 
					
						
							| 
									
										
										
										
											2021-04-10 19:34:30 +02:00
										 |  |  |                 locations = {world.get_location(requisite, player) for requisite in prequisites} | 
					
						
							| 
									
										
										
										
											2021-04-10 03:03:46 +02:00
										 |  |  |                 Rules.add_rule(location, lambda state, | 
					
						
							|  |  |  |                                                 locations=locations: all(state.can_reach(loc) for loc in locations)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-24 01:16:49 +02:00
										 |  |  |         # get all science pack technologies (but not the ability to craft them) | 
					
						
							| 
									
										
										
										
											2021-04-05 15:37:15 +02:00
										 |  |  |         world.completion_condition[player] = lambda state: all(state.has(technology, player) | 
					
						
							| 
									
										
										
										
											2021-04-09 22:10:04 +02:00
										 |  |  |                                                                for technology in advancement_technologies) |