Skip to content
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

LTTP: Rip Lttp specific entrance code out of core and use Region helpers #1960

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
7 changes: 1 addition & 6 deletions BaseClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,9 +938,6 @@ class Entrance:
name: str
parent_region: Optional[Region]
connected_region: Optional[Region] = None
# LttP specific, TODO: should make a LttPEntrance
addresses = None
target = None

def __init__(self, player: int, name: str = "", parent: Optional[Region] = None) -> None:
self.name = name
Expand All @@ -956,10 +953,8 @@ def can_reach(self, state: CollectionState) -> bool:

return False

def connect(self, region: Region, addresses: Any = None, target: Any = None) -> None:
def connect(self, region: Region) -> None:
alwaysintreble marked this conversation as resolved.
Show resolved Hide resolved
self.connected_region = region
self.target = target
self.addresses = addresses
region.entrances.append(self)

def __repr__(self):
Expand Down
10 changes: 2 additions & 8 deletions worlds/alttp/OverworldGlitchRules.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Helper functions to deliver entrance/exit/region sets to OWG rules.
"""

from BaseClasses import Entrance

from .StateHelpers import can_lift_heavy_rocks, can_boots_clip_lw, can_boots_clip_dw, can_get_glitched_speed_dw


Expand Down Expand Up @@ -279,18 +277,14 @@ def create_no_logic_connections(player, world, connections):
for entrance, parent_region, target_region, *rule_override in connections:
parent = world.get_region(parent_region, player)
target = world.get_region(target_region, player)
connection = Entrance(player, entrance, parent)
parent.exits.append(connection)
connection.connect(target)
parent.connect(target, entrance)


def create_owg_connections(player, world, connections):
for entrance, parent_region, target_region, *rule_override in connections:
parent = world.get_region(parent_region, player)
target = world.get_region(target_region, player)
connection = Entrance(player, entrance, parent)
parent.exits.append(connection)
connection.connect(target)
parent.connect(target, entrance)


def set_owg_connection_rules(player, world, connections, default_rule):
Expand Down
8 changes: 4 additions & 4 deletions worlds/alttp/Regions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import collections
import typing

from BaseClasses import Entrance, MultiWorld
from .SubClasses import LTTPRegion, LTTPRegionType
from BaseClasses import MultiWorld
from .SubClasses import LTTPEntrance, LTTPRegion, LTTPRegionType


def is_main_entrance(entrance: Entrance) -> bool:
def is_main_entrance(entrance: LTTPEntrance) -> bool:
return entrance.parent_region.type in {LTTPRegionType.DarkWorld, LTTPRegionType.LightWorld} if entrance.parent_region.type else True


Expand Down Expand Up @@ -410,7 +410,7 @@ def _create_region(world: MultiWorld, player: int, name: str, type: LTTPRegionTy
ret = LTTPRegion(name, type, hint, player, world)
if exits:
for exit in exits:
ret.exits.append(Entrance(player, exit, ret))
ret.create_exit(exit)
if locations:
for location in locations:
if location in key_drop_data:
Expand Down
8 changes: 4 additions & 4 deletions worlds/alttp/Rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Iterator, Set

from Options import ItemsAccessibility
from BaseClasses import Entrance, MultiWorld
from BaseClasses import MultiWorld
from worlds.generic.Rules import (add_item_rule, add_rule, forbid_item,
item_name_in_location_names, location_item_name, set_rule, allow_self_locking_items)

Expand Down Expand Up @@ -1071,9 +1071,8 @@ def swordless_rules(world, player):
def add_connection(parent_name, target_name, entrance_name, world, player):
parent = world.get_region(parent_name, player)
target = world.get_region(target_name, player)
connection = Entrance(player, entrance_name, parent)
parent.exits.append(connection)
connection.connect(target)
parent.connect(target, entrance_name)



def standard_rules(world, player):
Expand Down Expand Up @@ -1108,6 +1107,7 @@ def standard_rules(world, player):
set_rule(world.get_location('Hyrule Castle - Zelda\'s Chest', player),
lambda state: state.has('Big Key (Hyrule Castle)', player))


def toss_junk_item(world, player):
items = ['Rupees (20)', 'Bombs (3)', 'Arrows (10)', 'Rupees (5)', 'Rupee (1)', 'Bombs (10)',
'Single Arrow', 'Rupees (50)', 'Rupees (100)', 'Single Bomb', 'Bee', 'Bee Trap',
Expand Down
19 changes: 16 additions & 3 deletions worlds/alttp/SubClasses.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Module extending BaseClasses.py for aLttP"""
from typing import Optional, TYPE_CHECKING
from typing import Any, List, Optional, TYPE_CHECKING, Tuple, Union
from enum import IntEnum

from BaseClasses import Location, Item, ItemClassification, Region, MultiWorld
from BaseClasses import Entrance, Location, Item, ItemClassification, Region, MultiWorld

if TYPE_CHECKING:
from .Dungeons import Dungeon
from .Regions import LTTPRegion


class ALttPLocation(Location):
Expand Down Expand Up @@ -77,6 +76,19 @@ def dungeon_item(self) -> Optional[str]:
return self.type


Addresses = Union[int, List[int], Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int]]


class LTTPEntrance(Entrance):
addresses: Optional[Addresses] = None
target: Optional[int] = None

def connect(self, region: Region, addresses: Optional[Addresses] = None, target: Optional[int] = None) -> None:
super().connect(region)
self.addresses = addresses
self.target = target


class LTTPRegionType(IntEnum):
LightWorld = 1
DarkWorld = 2
Expand All @@ -90,6 +102,7 @@ def is_indoors(self) -> bool:


class LTTPRegion(Region):
entrance_type = LTTPEntrance
type: LTTPRegionType

# will be set after making connections.
Expand Down
14 changes: 6 additions & 8 deletions worlds/alttp/UnderworldGlitchRules.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from BaseClasses import Entrance
from worlds.generic.Rules import set_rule, add_rule
from .StateHelpers import can_bomb_clip, has_sword, has_beam_sword, has_fire_source, can_melt_things, has_misery_mire_medallion
from .SubClasses import LTTPEntrance


# We actually need the logic to properly "mark" these regions as Light or Dark world.
Expand All @@ -9,17 +9,15 @@ def underworld_glitch_connections(world, player):
specrock = world.get_region('Spectacle Rock Cave (Bottom)', player)
mire = world.get_region('Misery Mire (West)', player)

kikiskip = Entrance(player, 'Kiki Skip', specrock)
mire_to_hera = Entrance(player, 'Mire to Hera Clip', mire)
mire_to_swamp = Entrance(player, 'Hera to Swamp Clip', mire)
specrock.exits.append(kikiskip)
mire.exits.extend([mire_to_hera, mire_to_swamp])
kikiskip = specrock.create_exit('Kiki Skip')
mire_to_hera = mire.create_exit('Mire to Hera Clip')
mire_to_swamp = mire.create_exit('Hera to Swamp Clip')

if world.worlds[player].fix_fake_world:
kikiskip.connect(world.get_entrance('Palace of Darkness Exit', player).connected_region)
mire_to_hera.connect(world.get_entrance('Tower of Hera Exit', player).connected_region)
mire_to_swamp.connect(world.get_entrance('Swamp Palace Exit', player).connected_region)
else:
else:
kikiskip.connect(world.get_region('Palace of Darkness (Entrance)', player))
mire_to_hera.connect(world.get_region('Tower of Hera (Bottom)', player))
mire_to_swamp.connect(world.get_region('Swamp Palace (Entrance)', player))
Expand All @@ -37,7 +35,7 @@ def fake_pearl_state(state, player):

# Sets the rules on where we can actually go using this clip.
# Behavior differs based on what type of ER shuffle we're playing.
def dungeon_reentry_rules(world, player, clip: Entrance, dungeon_region: str, dungeon_exit: str):
def dungeon_reentry_rules(world, player, clip: LTTPEntrance, dungeon_region: str, dungeon_exit: str):
fix_dungeon_exits = world.worlds[player].fix_palaceofdarkness_exit
fix_fake_worlds = world.worlds[player].fix_fake_world

Expand Down
6 changes: 5 additions & 1 deletion worlds/pokemon_rb/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2621,9 +2621,13 @@ def __init__(self, player, name, parent, warp_id, address, flags):
self.warp_id = warp_id
self.address = address
self.flags = flags
self.addresses = None
self.target = None

def connect(self, entrance):
super().connect(entrance.parent_region, None, target=entrance.warp_id)
super().connect(entrance.parent_region)
self.addresses = None
self.target = entrance.warp_id

def access_rule(self, state):
if self.connected_region is None:
Expand Down
Loading