From aa73dbab2daa1d316add35809a655d559c9e9940 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Thu, 26 Oct 2023 00:03:14 +0200 Subject: [PATCH] Subnautica: avoid cache recreation in create_regions call and clean up function. (#2365) --- worlds/subnautica/__init__.py | 40 ++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/worlds/subnautica/__init__.py b/worlds/subnautica/__init__.py index 7b25b61c81e5..de4f4e33dc87 100644 --- a/worlds/subnautica/__init__.py +++ b/worlds/subnautica/__init__.py @@ -65,22 +65,38 @@ def generate_early(self) -> None: creature_pool, self.options.creature_scans.value) def create_regions(self): - self.multiworld.regions += [ - self.create_region("Menu", None, ["Lifepod 5"]), - self.create_region("Planet 4546B", - locations.events + - [location["name"] for location in locations.location_table.values()] + - [creature + creatures.suffix for creature in self.creatures_to_scan]) - ] + # Create Regions + menu_region = Region("Menu", self.player, self.multiworld) + planet_region = Region("Planet 4546B", self.player, self.multiworld) + + # Link regions together + menu_region.connect(planet_region, "Lifepod 5") + + # Create regular locations + location_names = itertools.chain((location["name"] for location in locations.location_table.values()), + (creature + creatures.suffix for creature in self.creatures_to_scan)) + for location_name in location_names: + loc_id = self.location_name_to_id[location_name] + location = SubnauticaLocation(self.player, location_name, loc_id, planet_region) + planet_region.locations.append(location) - # Link regions - self.multiworld.get_entrance("Lifepod 5", self.player).connect(self.multiworld.get_region("Planet 4546B", self.player)) + # Create events + goal_event_name = self.options.goal.get_event_name() for event in locations.events: - self.multiworld.get_location(event, self.player).place_locked_item( + location = SubnauticaLocation(self.player, event, None, planet_region) + planet_region.locations.append(location) + location.place_locked_item( SubnauticaItem(event, ItemClassification.progression, None, player=self.player)) - # make the goal event the victory "item" - self.multiworld.get_location(self.options.goal.get_event_name(), self.player).item.name = "Victory" + if event == goal_event_name: + # make the goal event the victory "item" + location.item.name = "Victory" + + # Register regions to multiworld + self.multiworld.regions += [ + menu_region, + planet_region + ] # refer to Rules.py set_rules = set_rules