From acf41870d9c9abf1506169c5636634860046186d Mon Sep 17 00:00:00 2001 From: gymnast86 Date: Fri, 26 Jul 2024 01:07:25 -0700 Subject: [PATCH 1/2] rework choosing goal locations --- gui/tracker.py | 2 +- logic/area.py | 9 --------- logic/world.py | 24 ++++++++++++++++++++++-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/gui/tracker.py b/gui/tracker.py index dacee797..b1dcb587 100644 --- a/gui/tracker.py +++ b/gui/tracker.py @@ -1577,7 +1577,7 @@ def update_areas_locations(self) -> None: for area_button in self.ui.tracker_tab.findChildren(TrackerArea): area_button.locations.clear() - self.world.assign_all_areas_hint_regions() + self.world.assign_hint_regions_and_goal_locations() all_locations = self.world.get_all_item_locations() if self.world.setting("gossip_stone_hints") == "on": all_locations.extend(self.world.get_gossip_stones()) diff --git a/logic/area.py b/logic/area.py index b13732c6..ad076d37 100644 --- a/logic/area.py +++ b/logic/area.py @@ -251,12 +251,3 @@ def assign_hint_regions_and_dungeon_locations(starting_area: Area): f"{[l.name for l in locations]} have been assigned to dungeon {region}" ) - # Also assign goal locations - goal_locations = [loc for loc in locations if loc.is_goal_location] - random.shuffle(goal_locations) - for goal_location in goal_locations: - if not dungeon.goal_location: - dungeon.goal_location = goal_location - else: - if random.randint(0, 1): - dungeon.goal_location = goal_location diff --git a/logic/world.py b/logic/world.py index 5493f47c..308cc41b 100644 --- a/logic/world.py +++ b/logic/world.py @@ -387,10 +387,10 @@ def place_vanilla_items(self) -> None: location.has_known_vanilla_item = True def perform_post_entrance_shuffle_tasks(self) -> None: - self.assign_all_areas_hint_regions() + self.assign_hint_regions_and_goal_locations() self.choose_required_dungeons() - def assign_all_areas_hint_regions(self): + def assign_hint_regions(self) -> None: for area in self.areas.values(): # Assign hint regions to all areas which don't # have them at this point. This will also finalize @@ -409,6 +409,26 @@ def assign_all_areas_hint_regions(self): ): dungeon.starting_entrance = exit_ + def assign_goal_locations(self) -> None: + # Collect all the possible goal locations for each dungeon + dungeon_goal_locations = {d: [] for d in self.dungeons} + for area in self.areas.values(): + for loc_access in area.locations: + loc = loc_access.location + if loc.is_goal_location: + for region in area.hint_regions: + if region in dungeon_goal_locations: + dungeon_goal_locations[region].append(loc) + + # Set a single goal location for each dungeon + for dungeon in self.dungeons.values(): + dungeon.goal_location = random.choice(dungeon_goal_locations[dungeon.name]) + logging.getLogger("").debug(f"{dungeon.goal_location} chosen as goal location for {dungeon}") + + def assign_hint_regions_and_goal_locations(self): + self.assign_hint_regions() + self.assign_goal_locations() + def choose_required_dungeons(self) -> None: num_required_dungeons = self.setting("required_dungeons").value_as_number() num_chosen_dungeons = 0 From 9f9241e8ff8a418f76f18986a15b12bfcc5d7c6f Mon Sep 17 00:00:00 2001 From: gymnast86 Date: Fri, 26 Jul 2024 01:29:22 -0700 Subject: [PATCH 2/2] formatting --- logic/area.py | 1 - logic/world.py | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/logic/area.py b/logic/area.py index ad076d37..fe60781a 100644 --- a/logic/area.py +++ b/logic/area.py @@ -250,4 +250,3 @@ def assign_hint_regions_and_dungeon_locations(starting_area: Area): logging.getLogger("").debug( f"{[l.name for l in locations]} have been assigned to dungeon {region}" ) - diff --git a/logic/world.py b/logic/world.py index 1d4cdb37..8f3211e5 100644 --- a/logic/world.py +++ b/logic/world.py @@ -427,7 +427,9 @@ def assign_goal_locations(self) -> None: # Set a single goal location for each dungeon for dungeon in self.dungeons.values(): dungeon.goal_location = random.choice(dungeon_goal_locations[dungeon.name]) - logging.getLogger("").debug(f"{dungeon.goal_location} chosen as goal location for {dungeon}") + logging.getLogger("").debug( + f"{dungeon.goal_location} chosen as goal location for {dungeon}" + ) def assign_hint_regions_and_goal_locations(self): self.assign_hint_regions()