Skip to content

TUNIC: ER Refactor for better plando connections, fewer shops improvement #3075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a6e1765
Fixed shop changes
ScipioWright Mar 31, 2024
75887f2
Merge branch 'ArchipelagoMW:main' into tunc-fewer-shops-change
ScipioWright Apr 1, 2024
32c99cd
Update option description
ScipioWright Apr 1, 2024
c32328e
Apply suggestions from Vi's review (thank you)
ScipioWright Apr 3, 2024
ef8c93d
Fix for plando connections on a full scene
ScipioWright Apr 11, 2024
655f9b3
Plando connections should work better now for complicated paths
ScipioWright Apr 12, 2024
0727ff6
Merge branch 'ArchipelagoMW:main' into tunc-fewer-shops-change
ScipioWright Apr 12, 2024
ecbd143
Even more good plando connections yes
ScipioWright Apr 12, 2024
ff40c6c
Starting to move the info over
ScipioWright Apr 12, 2024
1d56af7
Fixing up formatting a bit
ScipioWright Apr 12, 2024
0dd557a
Remove unneeded item info
ScipioWright Apr 12, 2024
ed14cab
Put in updated_reachable_regions, to replace add_dependent_regions
ScipioWright Apr 12, 2024
f8c3dea
Updated to match ladder shuffle
ScipioWright Apr 13, 2024
872d234
More stuff I guess
ScipioWright Apr 13, 2024
0b659e5
It functions!
ScipioWright Apr 13, 2024
4c0468a
It mostly works with plando now, some slight issues still
ScipioWright Apr 13, 2024
c2b2bae
Fixed minor logic bug
ScipioWright Apr 13, 2024
024c0b1
Fixed world leakage
ScipioWright Apr 13, 2024
06548cd
Change exception message
ScipioWright Apr 13, 2024
174260b
Make exception message better for troubleshooting failed connections
ScipioWright Apr 13, 2024
b5c68a4
Merge branch 'main' into tunc-fewer-shops-change
ScipioWright Apr 14, 2024
2fe100f
Merge branch 'main' into tunc-fewer-shops-change
ScipioWright Apr 14, 2024
ad144b1
Merge branch 'main' into tunc-fewer-shops-change
ScipioWright Apr 21, 2024
02aabb5
Merge branch 'main' into tunc-fewer-shops-change
ScipioWright May 2, 2024
236f67f
Merge remote-tracking branch 'origin/main' into tunc-fewer-shops-change
ScipioWright May 3, 2024
344f879
Merged with main
ScipioWright May 3, 2024
24b31d1
technically a logic fix but it would never matter cause no start shuffle
ScipioWright May 4, 2024
0a38b80
Add a couple more alias item groups cause yeah
ScipioWright May 4, 2024
ff0611a
Rename beneath the vault front -> beneath the vault main
ScipioWright May 4, 2024
be2f136
Flip lantern access rule to the region
ScipioWright May 4, 2024
ef5d47b
Add missing connection to traversal reqs
ScipioWright May 4, 2024
2e5e40c
Move start_inventory_from_pool to the top so that it's next to start_…
ScipioWright May 10, 2024
6e87a18
Reword the fixed shop description slightly
ScipioWright May 10, 2024
65f7d9e
Refactor per ixrec's comments
ScipioWright May 14, 2024
b691bae
Merge branch 'main' into tunc-fewer-shops-change
ScipioWright May 15, 2024
ce9eadb
Greatly reduced an overcomplicated block because Vi is cool and smart…
ScipioWright May 18, 2024
d0d13ab
Rewrite traversal reqs thing per Vi's comments
ScipioWright May 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions worlds/tunic/er_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ def destination_scene(self) -> str: # the vanilla connection
destination="ziggurat2020_2", tag="_"),
Portal(name="Ziggurat Portal Room Entrance", region="Rooted Ziggurat Portal Room Entrance",
destination="ziggurat2020_FTRoom", tag="_"),
# only if fixed shop is on, removed otherwise
Portal(name="Ziggurat Lower Falling Entrance", region="Zig Skip Exit",
destination="ziggurat2020_1", tag="_zig2_skip"),

Portal(name="Ziggurat Portal Room Exit", region="Rooted Ziggurat Portal Room Exit",
destination="ziggurat2020_3", tag="_"),
Expand Down Expand Up @@ -687,6 +690,7 @@ class DeadEnd(IntEnum):
"Rooted Ziggurat Middle Bottom": RegionInfo("ziggurat2020_2"),
"Rooted Ziggurat Lower Front": RegionInfo("ziggurat2020_3"), # the vanilla entry point side
"Rooted Ziggurat Lower Back": RegionInfo("ziggurat2020_3"), # the boss side
"Zig Skip Exit": RegionInfo("ziggurat2020_3"), # the exit from zig skip, for use with fixed shop on
"Rooted Ziggurat Portal Room Entrance": RegionInfo("ziggurat2020_3"), # the door itself on the zig 3 side
"Rooted Ziggurat Portal": RegionInfo("ziggurat2020_FTRoom"),
"Rooted Ziggurat Portal Room Exit": RegionInfo("ziggurat2020_FTRoom"),
Expand Down
3 changes: 3 additions & 0 deletions worlds/tunic/er_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,9 @@ def set_er_region_rules(world: "TunicWorld", ability_unlocks: Dict[str, int], re
regions["Rooted Ziggurat Portal Room Entrance"].connect(
connecting_region=regions["Rooted Ziggurat Lower Back"])

regions["Zig Skip Exit"].connect(
connecting_region=regions["Rooted Ziggurat Lower Front"])

regions["Rooted Ziggurat Portal"].connect(
connecting_region=regions["Rooted Ziggurat Portal Room Exit"],
rule=lambda state: state.has("Activate Ziggurat Fuse", player))
Expand Down
56 changes: 32 additions & 24 deletions worlds/tunic/er_scripts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, List, Set, TYPE_CHECKING
from typing import Dict, List, Set, TYPE_CHECKING, Tuple
from BaseClasses import Region, ItemClassification, Item, Location
from .locations import location_table
from .er_data import Portal, tunic_er_regions, portal_mapping, \
Expand Down Expand Up @@ -88,7 +88,8 @@ def place_event_items(world: "TunicWorld", regions: Dict[str, Region]) -> None:

def vanilla_portals() -> Dict[Portal, Portal]:
portal_pairs: Dict[Portal, Portal] = {}
portal_map = portal_mapping.copy()
# we don't want the zig skip exit for vanilla portals, since it shouldn't be considered for logic here
portal_map = [portal for portal in portal_mapping if portal.name != "Ziggurat Lower Falling Entrance"]

while portal_map:
portal1 = portal_map[0]
Expand Down Expand Up @@ -124,29 +125,36 @@ def pair_portals(world: "TunicWorld") -> Dict[Portal, Portal]:
two_plus: List[Portal] = []
logic_rules = world.options.logic_rules.value
player_name = world.multiworld.get_player_name(world.player)
portal_map = portal_mapping.copy()

shop_scenes: Set[str] = set()
shop_count = 6
if world.options.fixed_shop.value:
shop_count = 1
if world.options.fixed_shop:
shop_count = 0
shop_scenes.add("Overworld Redux")
else:
# if fixed shop is off, remove this portal
for portal in portal_map:
if portal.name == "Ziggurat Lower Falling Entrance":
portal_map.remove(portal)
break

if not logic_rules:
dependent_regions = dependent_regions_restricted
dependent_regions = dependent_regions_restricted.copy()
elif logic_rules == 1:
dependent_regions = dependent_regions_nmg
dependent_regions = dependent_regions_nmg.copy()
else:
dependent_regions = dependent_regions_ur
dependent_regions = dependent_regions_ur.copy()

# create separate lists for dead ends and non-dead ends
if logic_rules:
for portal in portal_mapping:
for portal in portal_map:
if tunic_er_regions[portal.region].dead_end == 1:
dead_ends.append(portal)
else:
two_plus.append(portal)
else:
for portal in portal_mapping:
for portal in portal_map:
if tunic_er_regions[portal.region].dead_end:
dead_ends.append(portal)
else:
Expand All @@ -155,7 +163,7 @@ def pair_portals(world: "TunicWorld") -> Dict[Portal, Portal]:
connected_regions: Set[str] = set()
# make better start region stuff when/if implementing random start
start_region = "Overworld"
connected_regions.update(add_dependent_regions(start_region, logic_rules))
connected_regions.update(add_dependent_regions(start_region, dependent_regions))

plando_connections = world.multiworld.plando_connections[world.player]

Expand All @@ -182,6 +190,8 @@ def pair_portals(world: "TunicWorld") -> Dict[Portal, Portal]:

non_dead_end_regions = set()
for region_name, region_info in tunic_er_regions.items():
if region_name == "Zig Skip Exit" and not world.options.fixed_shop:
continue
if not region_info.dead_end:
non_dead_end_regions.add(region_name)
elif region_info.dead_end == 2 and logic_rules:
Expand Down Expand Up @@ -244,7 +254,7 @@ def pair_portals(world: "TunicWorld") -> Dict[Portal, Portal]:

portal_pairs[portal1] = portal2

# update dependent regions based on the plando'd connections, to ensure the portals connect well, logically
# update dependent regions based on the plando'd connections, to ensure the portals connect logically
for origins, destinations in dependent_regions.items():
if portal1.region in origins:
if portal2.region in non_dead_end_regions:
Expand All @@ -257,7 +267,7 @@ def pair_portals(world: "TunicWorld") -> Dict[Portal, Portal]:
while True:
test1 = len(connected_regions)
for region in connected_regions.copy():
connected_regions.update(add_dependent_regions(region, logic_rules))
connected_regions.update(add_dependent_regions(region, dependent_regions))
test2 = len(connected_regions)
if test1 == test2:
break
Expand Down Expand Up @@ -300,6 +310,10 @@ def pair_portals(world: "TunicWorld") -> Dict[Portal, Portal]:
portal_pairs[portal1] = portal2
two_plus.remove(portal1)

# add zig skip exit to the dependent regions
dependent_regions[("Zig Skip Exit",)] = ["Zig Skip Exit", "Rooted Ziggurat Lower Front",
"Rooted Ziggurat Lower Back", "Rooted Ziggurat Portal Room Entrance"]

random_object: Random = world.random
if world.options.entrance_rando.value != 1:
random_object = Random(world.options.entrance_rando.value)
Expand All @@ -311,10 +325,11 @@ def pair_portals(world: "TunicWorld") -> Dict[Portal, Portal]:
previous_conn_num = 0
fail_count = 0
while len(connected_regions) < len(non_dead_end_regions):
# if the connected regions length stays unchanged for too long, it's stuck in a loop
# should, hopefully, only ever occur if someone plandos connections poorly
# if this is universal tracker, just break immediately and move on
if hasattr(world.multiworld, "re_gen_passthrough"):
break
# if the connected regions length stays unchanged for too long, it's stuck in a loop
# should, hopefully, only ever occur if someone plandos connections poorly
if previous_conn_num == len(connected_regions):
fail_count += 1
if fail_count >= 500:
Expand Down Expand Up @@ -351,7 +366,7 @@ def pair_portals(world: "TunicWorld") -> Dict[Portal, Portal]:

# once we have both portals, connect them and add the new region(s) to connected_regions
if check_success == 2:
connected_regions.update(add_dependent_regions(portal2.region, logic_rules))
connected_regions.update(add_dependent_regions(portal2.region, dependent_regions))
portal_pairs[portal1] = portal2
check_success = 0
random_object.shuffle(two_plus)
Expand Down Expand Up @@ -411,16 +426,9 @@ def create_randomized_entrances(portal_pairs: Dict[Portal, Portal], regions: Dic


# loop through the static connections, return regions you can reach from this region
# todo: refactor to take region_name and dependent_regions
def add_dependent_regions(region_name: str, logic_rules: int) -> Set[str]:
def add_dependent_regions(region_name: str, dependent_regions: Dict[Tuple[str, ...], List[str]]) -> Set[str]:
region_set = set()
if not logic_rules:
regions_to_add = dependent_regions_restricted
elif logic_rules == 1:
regions_to_add = dependent_regions_nmg
else:
regions_to_add = dependent_regions_ur
for origin_regions, destination_regions in regions_to_add.items():
for origin_regions, destination_regions in dependent_regions.items():
if region_name in origin_regions:
# if you matched something in the first set, you get the regions in its paired set
region_set.update(destination_regions)
Expand Down
3 changes: 2 additions & 1 deletion worlds/tunic/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class EntranceRando(TextChoice):


class FixedShop(Toggle):
"""Forces the Windmill entrance to lead to a shop, and places only one other shop in the pool.
"""Forces the Windmill entrance to lead to a shop, and excludes all other shops from the entrance pool.
Adds another entrance in Rooted Ziggurat Lower to keep an even number of entrances.
Has no effect if Entrance Rando is not enabled."""
internal_name = "fixed_shop"
display_name = "Fewer Shops in Entrance Rando"
Expand Down
Loading