From b63ed86955d2cb7aafad0417db3c19fd6881d2e4 Mon Sep 17 00:00:00 2001 From: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> Date: Fri, 30 Aug 2024 17:02:21 -0400 Subject: [PATCH] Updated friendly limits to be more strict, optimized recalculate logic. --- worlds/jakanddaxter/JakAndDaxterOptions.py | 6 +++--- worlds/jakanddaxter/Locations.py | 9 ++++++++- worlds/jakanddaxter/Rules.py | 14 ++++++++------ worlds/jakanddaxter/__init__.py | 4 ++-- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/worlds/jakanddaxter/JakAndDaxterOptions.py b/worlds/jakanddaxter/JakAndDaxterOptions.py index cc4178723e..21fb2725b0 100644 --- a/worlds/jakanddaxter/JakAndDaxterOptions.py +++ b/worlds/jakanddaxter/JakAndDaxterOptions.py @@ -51,8 +51,8 @@ class GlobalOrbsanityBundleSize(Choice): option_500_orbs = 500 option_1000_orbs = 1000 option_2000_orbs = 2000 - multiplayer_minimum = 5 - multiplayer_maximum = 400 + multiplayer_minimum = 10 + multiplayer_maximum = 200 default = 20 @@ -66,7 +66,7 @@ class PerLevelOrbsanityBundleSize(Choice): option_10_orbs = 10 option_25_orbs = 25 option_50_orbs = 50 - multiplayer_minimum = 5 + multiplayer_minimum = 10 default = 25 diff --git a/worlds/jakanddaxter/Locations.py b/worlds/jakanddaxter/Locations.py index d358ed4213..98517aa449 100644 --- a/worlds/jakanddaxter/Locations.py +++ b/worlds/jakanddaxter/Locations.py @@ -1,4 +1,4 @@ -from BaseClasses import Location +from BaseClasses import Location, CollectionState from .GameID import jak1_name from .locs import (OrbLocations as Orbs, CellLocations as Cells, @@ -10,6 +10,13 @@ from .locs import (OrbLocations as Orbs, class JakAndDaxterLocation(Location): game: str = jak1_name + # In AP 0.5.0, the base Location.can_reach function had its two boolean conditions swapped for a faster + # short-circuit for better performance. However, Jak seeds actually generate faster using the older method, + # which has been re-implemented below. + def can_reach(self, state: CollectionState) -> bool: + assert self.parent_region, "Can't reach location without region" + return self.parent_region.can_reach(state) and self.access_rule(state) + # Different tables for location groups. # Each Item ID == its corresponding Location ID. While we're here, do all the ID conversions needed. diff --git a/worlds/jakanddaxter/Rules.py b/worlds/jakanddaxter/Rules.py index 0e3e4b8412..6403c60c3b 100644 --- a/worlds/jakanddaxter/Rules.py +++ b/worlds/jakanddaxter/Rules.py @@ -49,10 +49,11 @@ def count_reachable_orbs_global(state: CollectionState, multiworld: MultiWorld) -> int: accessible_orbs = 0 - for region in multiworld.get_regions(player): - if region.can_reach(state): - # Only cast the region when we need to. - accessible_orbs += typing.cast(JakAndDaxterRegion, region).orb_count + # Cast all regions upfront to access their unique attributes. + for region in typing.cast(typing.List[JakAndDaxterRegion], multiworld.get_regions(player)): + # Rely on short-circuiting to skip region.can_reach whenever possible. + if region.orb_count > 0 and region.can_reach(state): + accessible_orbs += region.orb_count return accessible_orbs @@ -62,9 +63,10 @@ def count_reachable_orbs_level(state: CollectionState, level_name: str = "") -> int: accessible_orbs = 0 - # Need to cast all regions upfront. + # Cast all regions upfront to access their unique attributes. for region in typing.cast(typing.List[JakAndDaxterRegion], multiworld.get_regions(player)): - if region.level_name == level_name and region.can_reach(state): + # Rely on short-circuiting to skip region.can_reach whenever possible. + if region.level_name == level_name and region.orb_count > 0 and region.can_reach(state): accessible_orbs += region.orb_count return accessible_orbs diff --git a/worlds/jakanddaxter/__init__.py b/worlds/jakanddaxter/__init__.py index 483484b15c..f58fc8a376 100644 --- a/worlds/jakanddaxter/__init__.py +++ b/worlds/jakanddaxter/__init__.py @@ -54,8 +54,8 @@ class JakAndDaxterSettings(settings.Group): description = "ArchipelaGOAL Root Directory" class EnforceFriendlyOptions(settings.Bool): - """Enforce friendly player options to be used in a multiplayer seed. - Disabling this allows for more disruptive and challenging options, but may impact seed generation.""" + """Enforce friendly player options in both single and multiplayer seeds. Disabling this allows for + more disruptive and challenging options, but may impact seed generation. Use at your own risk!""" description = "ArchipelaGOAL Enforce Friendly Options" root_directory: RootDirectory = RootDirectory("%appdata%/OpenGOAL-Mods/archipelagoal")