Skip to content

Commit

Permalink
Add connect_entrances
Browse files Browse the repository at this point in the history
  • Loading branch information
NewSoupVi committed Jan 1, 2025
1 parent 917335e commit c46095c
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 23 deletions.
1 change: 1 addition & 0 deletions Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
multiworld.worlds[1].options.local_items.value = set()

AutoWorld.call_all(multiworld, "generate_basic")
AutoWorld.call_all(multiworld, "connect_entrances")

# remove starting inventory from pool items.
# Because some worlds don't actually create items during create_items this has to be as late as possible.
Expand Down
3 changes: 3 additions & 0 deletions docs/world api.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ In addition, the following methods can be implemented and are called in this ord
after this step. Locations cannot be moved to different regions after this step.
* `set_rules(self)`
called to set access and item rules on locations and entrances.
* `connect_entrances(self)`
by the end of this step, all entrances must exist and be connected to their source and target regions.
Entrance randomization should be done here.
* `generate_basic(self)`
player-specific randomization that does not affect logic can be done here.
* `pre_fill(self)`, `fill_hook(self)` and `post_fill(self)`
Expand Down
9 changes: 8 additions & 1 deletion test/benchmark/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ def run_locations_benchmark():

class BenchmarkRunner:
gen_steps: typing.Tuple[str, ...] = (
"generate_early", "create_regions", "create_items", "set_rules", "generate_basic", "pre_fill")
"generate_early",
"create_regions",
"create_items",
"set_rules",
"generate_basic",
"connect_entrances",
"pre_fill"
)
rule_iterations: int = 100_000

if sys.version_info >= (3, 9):
Expand Down
10 changes: 9 additions & 1 deletion test/general/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
from worlds import network_data_package
from worlds.AutoWorld import World, call_all

gen_steps = ("generate_early", "create_regions", "create_items", "set_rules", "generate_basic", "pre_fill")
gen_steps = (
"generate_early",
"create_regions",
"create_items",
"set_rules",
"connect_entrances",
"generate_basic",
"pre_fill"
)


def setup_solo_multiworld(
Expand Down
4 changes: 2 additions & 2 deletions test/general/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_items_in_datapackage(self):
def test_itempool_not_modified(self):
"""Test that worlds don't modify the itempool after `create_items`"""
gen_steps = ("generate_early", "create_regions", "create_items")
additional_steps = ("set_rules", "generate_basic", "pre_fill")
additional_steps = ("set_rules", "connect_entrances", "generate_basic", "pre_fill")
excluded_games = ("Links Awakening DX", "Ocarina of Time", "SMZ3")
worlds_to_test = {game: world
for game, world in AutoWorldRegister.world_types.items() if game not in excluded_games}
Expand All @@ -84,7 +84,7 @@ def test_itempool_not_modified(self):
def test_locality_not_modified(self):
"""Test that worlds don't modify the locality of items after duplicates are resolved"""
gen_steps = ("generate_early", "create_regions", "create_items")
additional_steps = ("set_rules", "generate_basic", "pre_fill")
additional_steps = ("set_rules", "connect_entrances", "generate_basic", "pre_fill")
worlds_to_test = {game: world for game, world in AutoWorldRegister.world_types.items()}
for game_name, world_type in worlds_to_test.items():
with self.subTest("Game", game=game_name):
Expand Down
25 changes: 8 additions & 17 deletions test/general/test_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,20 @@ def test_locations_in_datapackage(self):
def test_location_creation_steps(self):
"""Tests that Regions and Locations aren't created after `create_items`."""
gen_steps = ("generate_early", "create_regions", "create_items")
additional_steps = ("set_rules", "connect_entrances", "generate_basic", "pre_fill")
for game_name, world_type in AutoWorldRegister.world_types.items():
with self.subTest("Game", game_name=game_name):
multiworld = setup_solo_multiworld(world_type, gen_steps)
region_count = len(multiworld.get_regions())
location_count = len(multiworld.get_locations())

call_all(multiworld, "set_rules")
self.assertEqual(region_count, len(multiworld.get_regions()),
f"{game_name} modified region count during rule creation")
self.assertEqual(location_count, len(multiworld.get_locations()),
f"{game_name} modified locations count during rule creation")

call_all(multiworld, "generate_basic")
self.assertEqual(region_count, len(multiworld.get_regions()),
f"{game_name} modified region count during generate_basic")
self.assertGreaterEqual(location_count, len(multiworld.get_locations()),
f"{game_name} modified locations count during generate_basic")

call_all(multiworld, "pre_fill")
self.assertEqual(region_count, len(multiworld.get_regions()),
f"{game_name} modified region count during pre_fill")
self.assertGreaterEqual(location_count, len(multiworld.get_locations()),
f"{game_name} modified locations count during pre_fill")
for step in additional_steps:
with self.subTest("step", step=step):
call_all(multiworld, step)
self.assertEqual(region_count, len(multiworld.get_regions()),
f"{game_name} modified region count during {step}")
self.assertEqual(location_count, len(multiworld.get_locations()),
f"{game_name} modified locations count during {step}")

def test_location_group(self):
"""Test that all location name groups contain valid locations and don't share names."""
Expand Down
4 changes: 2 additions & 2 deletions test/general/test_reachability.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from BaseClasses import CollectionState
from worlds.AutoWorld import AutoWorldRegister
from . import setup_solo_multiworld
from . import setup_solo_multiworld, gen_steps


class TestBase(unittest.TestCase):
gen_steps = ["generate_early", "create_regions", "create_items", "set_rules", "generate_basic", "pre_fill"]
gen_steps = gen_steps

default_settings_unreachable_regions = {
"A Link to the Past": {
Expand Down
4 changes: 4 additions & 0 deletions worlds/AutoWorld.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ def set_rules(self) -> None:
"""Method for setting the rules on the World's regions and locations."""
pass

def connect_entrances(self) -> None:
"""Method to finalize the source and target regions of the World's entrances"""
pass

def generate_basic(self) -> None:
"""
Useful for randomizing things that don't affect logic but are better to be determined before the output stage.
Expand Down

0 comments on commit c46095c

Please sign in to comment.