Skip to content

Commit

Permalink
Merge pull request #408 from gymnast86/goal-location-choosing
Browse files Browse the repository at this point in the history
Rework Goal Location Choosing
  • Loading branch information
CovenEsme authored Jul 27, 2024
2 parents bbebc3e + 9f9241e commit cf9b090
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gui/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,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())
Expand Down
10 changes: 0 additions & 10 deletions logic/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +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}"
)

# 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
26 changes: 24 additions & 2 deletions logic/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,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
Expand All @@ -413,6 +413,28 @@ 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
Expand Down

0 comments on commit cf9b090

Please sign in to comment.