Skip to content

Commit

Permalink
sm64ex: New Options API and WebHost fix (ArchipelagoMW#2979)
Browse files Browse the repository at this point in the history
  • Loading branch information
N00byKing authored Mar 26, 2024
1 parent ea47b90 commit 98ce8f8
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 89 deletions.
69 changes: 36 additions & 33 deletions worlds/sm64ex/Options.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typing
from Options import Option, DefaultOnToggle, Range, Toggle, DeathLink, Choice
from dataclasses import dataclass
from Options import DefaultOnToggle, Range, Toggle, DeathLink, Choice, PerGameCommonOptions, OptionSet
from .Items import action_item_table

class EnableCoinStars(DefaultOnToggle):
Expand Down Expand Up @@ -114,35 +115,37 @@ class StrictMoveRequirements(DefaultOnToggle):
if Move Randomization is enabled"""
display_name = "Strict Move Requirements"

def getMoveRandomizerOption(action: str):
class MoveRandomizerOption(Toggle):
"""Mario is unable to perform this action until a corresponding item is picked up.
This option is incompatible with builds using a 'nomoverando' branch."""
display_name = f"Randomize {action}"
return MoveRandomizerOption


sm64_options: typing.Dict[str, type(Option)] = {
"AreaRandomizer": AreaRandomizer,
"BuddyChecks": BuddyChecks,
"ExclamationBoxes": ExclamationBoxes,
"ProgressiveKeys": ProgressiveKeys,
"EnableCoinStars": EnableCoinStars,
"StrictCapRequirements": StrictCapRequirements,
"StrictCannonRequirements": StrictCannonRequirements,
"StrictMoveRequirements": StrictMoveRequirements,
"AmountOfStars": AmountOfStars,
"FirstBowserStarDoorCost": FirstBowserStarDoorCost,
"BasementStarDoorCost": BasementStarDoorCost,
"SecondFloorStarDoorCost": SecondFloorStarDoorCost,
"MIPS1Cost": MIPS1Cost,
"MIPS2Cost": MIPS2Cost,
"StarsToFinish": StarsToFinish,
"death_link": DeathLink,
"CompletionType": CompletionType,
}

for action in action_item_table:
# HACK: Disable randomization of double jump
if action == 'Double Jump': continue
sm64_options[f"MoveRandomizer{action.replace(' ','')}"] = getMoveRandomizerOption(action)
class EnableMoveRandomizer(Toggle):
"""Mario is unable to perform some actions until a corresponding item is picked up.
This option is incompatible with builds using a 'nomoverando' branch.
Specific actions to randomize can be specified in the YAML."""
display_name = "Enable Move Randomizer"

class MoveRandomizerActions(OptionSet):
"""Which actions to randomize when Move Randomizer is enabled"""
display_name = "Randomized Moves"
# HACK: Disable randomization for double jump
valid_keys = [action for action in action_item_table if action != 'Double Jump']
default = valid_keys

@dataclass
class SM64Options(PerGameCommonOptions):
area_rando: AreaRandomizer
buddy_checks: BuddyChecks
exclamation_boxes: ExclamationBoxes
progressive_keys: ProgressiveKeys
enable_coin_stars: EnableCoinStars
enable_move_rando: EnableMoveRandomizer
move_rando_actions: MoveRandomizerActions
strict_cap_requirements: StrictCapRequirements
strict_cannon_requirements: StrictCannonRequirements
strict_move_requirements: StrictMoveRequirements
amount_of_stars: AmountOfStars
first_bowser_star_door_cost: FirstBowserStarDoorCost
basement_star_door_cost: BasementStarDoorCost
second_floor_star_door_cost: SecondFloorStarDoorCost
mips1_cost: MIPS1Cost
mips2_cost: MIPS2Cost
stars_to_finish: StarsToFinish
death_link: DeathLink
completion_type: CompletionType
33 changes: 17 additions & 16 deletions worlds/sm64ex/Regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from enum import Enum

from BaseClasses import MultiWorld, Region, Entrance, Location
from .Options import SM64Options
from .Locations import SM64Location, location_table, locBoB_table, locWhomp_table, locJRB_table, locCCM_table, \
locBBH_table, \
locHMC_table, locLLL_table, locSSL_table, locDDD_table, locSL_table, \
Expand Down Expand Up @@ -78,7 +79,7 @@ class SM64Region(Region):
sm64_entrances_to_level = {**sm64_paintings_to_level, **sm64_secrets_to_level }
sm64_level_to_entrances = {**sm64_level_to_paintings, **sm64_level_to_secrets }

def create_regions(world: MultiWorld, player: int):
def create_regions(world: MultiWorld, options: SM64Options, player: int):
regSS = Region("Menu", player, world, "Castle Area")
create_default_locs(regSS, locSS_table)
world.regions.append(regSS)
Expand All @@ -88,28 +89,28 @@ def create_regions(world: MultiWorld, player: int):
"BoB: Mario Wings to the Sky", "BoB: Behind Chain Chomp's Gate", "BoB: Bob-omb Buddy")
bob_island = create_subregion(regBoB, "BoB: Island", "BoB: Shoot to the Island in the Sky", "BoB: Find the 8 Red Coins")
regBoB.subregions = [bob_island]
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(regBoB, "BoB: 100 Coins")

regWhomp = create_region("Whomp's Fortress", player, world)
create_locs(regWhomp, "WF: Chip Off Whomp's Block", "WF: Shoot into the Wild Blue", "WF: Red Coins on the Floating Isle",
"WF: Fall onto the Caged Island", "WF: Blast Away the Wall")
wf_tower = create_subregion(regWhomp, "WF: Tower", "WF: To the Top of the Fortress", "WF: Bob-omb Buddy")
regWhomp.subregions = [wf_tower]
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(regWhomp, "WF: 100 Coins")

regJRB = create_region("Jolly Roger Bay", player, world)
create_locs(regJRB, "JRB: Plunder in the Sunken Ship", "JRB: Can the Eel Come Out to Play?", "JRB: Treasure of the Ocean Cave",
"JRB: Blast to the Stone Pillar", "JRB: Through the Jet Stream", "JRB: Bob-omb Buddy")
jrb_upper = create_subregion(regJRB, 'JRB: Upper', "JRB: Red Coins on the Ship Afloat")
regJRB.subregions = [jrb_upper]
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(jrb_upper, "JRB: 100 Coins")

regCCM = create_region("Cool, Cool Mountain", player, world)
create_default_locs(regCCM, locCCM_table)
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(regCCM, "CCM: 100 Coins")

regBBH = create_region("Big Boo's Haunt", player, world)
Expand All @@ -118,7 +119,7 @@ def create_regions(world: MultiWorld, player: int):
bbh_third_floor = create_subregion(regBBH, "BBH: Third Floor", "BBH: Eye to Eye in the Secret Room")
bbh_roof = create_subregion(bbh_third_floor, "BBH: Roof", "BBH: Big Boo's Balcony", "BBH: 1Up Block Top of Mansion")
regBBH.subregions = [bbh_third_floor, bbh_roof]
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(regBBH, "BBH: 100 Coins")

regPSS = create_region("The Princess's Secret Slide", player, world)
Expand All @@ -141,15 +142,15 @@ def create_regions(world: MultiWorld, player: int):
hmc_red_coin_area = create_subregion(regHMC, "HMC: Red Coin Area", "HMC: Elevate for 8 Red Coins")
hmc_pit_islands = create_subregion(regHMC, "HMC: Pit Islands", "HMC: A-Maze-Ing Emergency Exit", "HMC: 1Up Block above Pit")
regHMC.subregions = [hmc_red_coin_area, hmc_pit_islands]
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(hmc_red_coin_area, "HMC: 100 Coins")

regLLL = create_region("Lethal Lava Land", player, world)
create_locs(regLLL, "LLL: Boil the Big Bully", "LLL: Bully the Bullies",
"LLL: 8-Coin Puzzle with 15 Pieces", "LLL: Red-Hot Log Rolling")
lll_upper_volcano = create_subregion(regLLL, "LLL: Upper Volcano", "LLL: Hot-Foot-It into the Volcano", "LLL: Elevator Tour in the Volcano")
regLLL.subregions = [lll_upper_volcano]
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(regLLL, "LLL: 100 Coins")

regSSL = create_region("Shifting Sand Land", player, world)
Expand All @@ -159,15 +160,15 @@ def create_regions(world: MultiWorld, player: int):
ssl_upper_pyramid = create_subregion(regSSL, "SSL: Upper Pyramid", "SSL: Inside the Ancient Pyramid",
"SSL: Stand Tall on the Four Pillars", "SSL: Pyramid Puzzle")
regSSL.subregions = [ssl_upper_pyramid]
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(regSSL, "SSL: 100 Coins")

regDDD = create_region("Dire, Dire Docks", player, world)
create_locs(regDDD, "DDD: Board Bowser's Sub", "DDD: Chests in the Current", "DDD: Through the Jet Stream",
"DDD: The Manta Ray's Reward", "DDD: Collect the Caps...")
ddd_moving_poles = create_subregion(regDDD, "DDD: Moving Poles", "DDD: Pole-Jumping for Red Coins")
regDDD.subregions = [ddd_moving_poles]
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(ddd_moving_poles, "DDD: 100 Coins")

regCotMC = create_region("Cavern of the Metal Cap", player, world)
Expand All @@ -184,7 +185,7 @@ def create_regions(world: MultiWorld, player: int):

regSL = create_region("Snowman's Land", player, world)
create_default_locs(regSL, locSL_table)
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(regSL, "SL: 100 Coins")

regWDW = create_region("Wet-Dry World", player, world)
Expand All @@ -193,7 +194,7 @@ def create_regions(world: MultiWorld, player: int):
"WDW: Secrets in the Shallows & Sky", "WDW: Bob-omb Buddy")
wdw_downtown = create_subregion(regWDW, "WDW: Downtown", "WDW: Go to Town for Red Coins", "WDW: Quick Race Through Downtown!", "WDW: 1Up Block in Downtown")
regWDW.subregions = [wdw_top, wdw_downtown]
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(wdw_top, "WDW: 100 Coins")

regTTM = create_region("Tall, Tall Mountain", player, world)
Expand All @@ -202,7 +203,7 @@ def create_regions(world: MultiWorld, player: int):
ttm_top = create_subregion(ttm_middle, "TTM: Top", "TTM: Scale the Mountain", "TTM: Mystery of the Monkey Cage",
"TTM: Mysterious Mountainside", "TTM: Breathtaking View from Bridge")
regTTM.subregions = [ttm_middle, ttm_top]
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(ttm_top, "TTM: 100 Coins")

create_region("Tiny-Huge Island (Huge)", player, world)
Expand All @@ -214,7 +215,7 @@ def create_regions(world: MultiWorld, player: int):
"THI: 1Up Block THI Large near Start", "THI: 1Up Block Windy Area")
thi_large_top = create_subregion(thi_pipes, "THI: Large Top", "THI: Make Wiggler Squirm")
regTHI.subregions = [thi_pipes, thi_large_top]
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(thi_large_top, "THI: 100 Coins")

regFloor3 = create_region("Third Floor", player, world)
Expand All @@ -225,7 +226,7 @@ def create_regions(world: MultiWorld, player: int):
ttc_upper = create_subregion(ttc_lower, "TTC: Upper", "TTC: Timed Jumps on Moving Bars", "TTC: The Pit and the Pendulums")
ttc_top = create_subregion(ttc_upper, "TTC: Top", "TTC: Stomp on the Thwomp", "TTC: 1Up Block at the Top")
regTTC.subregions = [ttc_lower, ttc_upper, ttc_top]
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(ttc_top, "TTC: 100 Coins")

regRR = create_region("Rainbow Ride", player, world)
Expand All @@ -235,7 +236,7 @@ def create_regions(world: MultiWorld, player: int):
rr_cruiser = create_subregion(regRR, "RR: Cruiser", "RR: Cruiser Crossing the Rainbow", "RR: Somewhere Over the Rainbow")
rr_house = create_subregion(regRR, "RR: House", "RR: The Big House in the Sky", "RR: 1Up Block On House in the Sky")
regRR.subregions = [rr_maze, rr_cruiser, rr_house]
if (world.EnableCoinStars[player].value):
if options.enable_coin_stars:
create_locs(rr_maze, "RR: 100 Coins")

regWMotR = create_region("Wing Mario over the Rainbow", player, world)
Expand Down
29 changes: 15 additions & 14 deletions worlds/sm64ex/Rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from BaseClasses import MultiWorld
from ..generic.Rules import add_rule, set_rule
from .Locations import location_table
from .Options import SM64Options
from .Regions import connect_regions, SM64Levels, sm64_level_to_paintings, sm64_paintings_to_level,\
sm64_level_to_secrets, sm64_secrets_to_level, sm64_entrances_to_level, sm64_level_to_entrances
from .Items import action_item_table
Expand All @@ -24,27 +25,27 @@ def fix_reg(entrance_map: Dict[SM64Levels, str], entrance: SM64Levels, invalid_r
swapdict[entrance], swapdict[rand_entrance] = rand_region, old_dest
swapdict.pop(entrance)

def set_rules(world, player: int, area_connections: dict, star_costs: dict, move_rando_bitvec: int):
def set_rules(world, options: SM64Options, player: int, area_connections: dict, star_costs: dict, move_rando_bitvec: int):
randomized_level_to_paintings = sm64_level_to_paintings.copy()
randomized_level_to_secrets = sm64_level_to_secrets.copy()
valid_move_randomizer_start_courses = [
"Bob-omb Battlefield", "Jolly Roger Bay", "Cool, Cool Mountain",
"Big Boo's Haunt", "Lethal Lava Land", "Shifting Sand Land",
"Dire, Dire Docks", "Snowman's Land"
] # Excluding WF, HMC, WDW, TTM, THI, TTC, and RR
if world.AreaRandomizer[player].value >= 1: # Some randomization is happening, randomize Courses
if options.area_rando >= 1: # Some randomization is happening, randomize Courses
randomized_level_to_paintings = shuffle_dict_keys(world,sm64_level_to_paintings)
# If not shuffling later, ensure a valid start course on move randomizer
if world.AreaRandomizer[player].value < 3 and move_rando_bitvec > 0:
if options.area_rando < 3 and move_rando_bitvec > 0:
swapdict = randomized_level_to_paintings.copy()
invalid_start_courses = {course for course in randomized_level_to_paintings.values() if course not in valid_move_randomizer_start_courses}
fix_reg(randomized_level_to_paintings, SM64Levels.BOB_OMB_BATTLEFIELD, invalid_start_courses, swapdict, world)
fix_reg(randomized_level_to_paintings, SM64Levels.WHOMPS_FORTRESS, invalid_start_courses, swapdict, world)

if world.AreaRandomizer[player].value == 2: # Randomize Secrets as well
if options.area_rando == 2: # Randomize Secrets as well
randomized_level_to_secrets = shuffle_dict_keys(world,sm64_level_to_secrets)
randomized_entrances = {**randomized_level_to_paintings, **randomized_level_to_secrets}
if world.AreaRandomizer[player].value == 3: # Randomize Courses and Secrets in one pool
if options.area_rando == 3: # Randomize Courses and Secrets in one pool
randomized_entrances = shuffle_dict_keys(world, randomized_entrances)
# Guarantee first entrance is a course
swapdict = randomized_entrances.copy()
Expand All @@ -67,7 +68,7 @@ def set_rules(world, player: int, area_connections: dict, star_costs: dict, move
area_connections.update({int(entrance_lvl): int(sm64_entrances_to_level[destination]) for (entrance_lvl,destination) in randomized_entrances.items()})
randomized_entrances_s = {sm64_level_to_entrances[entrance_lvl]: destination for (entrance_lvl,destination) in randomized_entrances.items()}

rf = RuleFactory(world, player, move_rando_bitvec)
rf = RuleFactory(world, options, player, move_rando_bitvec)

connect_regions(world, player, "Menu", randomized_entrances_s["Bob-omb Battlefield"])
connect_regions(world, player, "Menu", randomized_entrances_s["Whomp's Fortress"], lambda state: state.has("Power Star", player, 1))
Expand Down Expand Up @@ -199,7 +200,7 @@ def set_rules(world, player: int, area_connections: dict, star_costs: dict, move
# Bowser in the Sky
rf.assign_rule("BitS: Top", "CL+TJ | CL+SF+LG | MOVELESS & TJ+WK+LG")
# 100 Coin Stars
if world.EnableCoinStars[player]:
if options.enable_coin_stars:
rf.assign_rule("BoB: 100 Coins", "CANN & WC | CANNLESS & WC & TJ")
rf.assign_rule("WF: 100 Coins", "GP | MOVELESS")
rf.assign_rule("JRB: 100 Coins", "GP & {JRB: Upper}")
Expand All @@ -225,9 +226,9 @@ def set_rules(world, player: int, area_connections: dict, star_costs: dict, move

world.completion_condition[player] = lambda state: state.can_reach("BitS: Top", 'Region', player)

if world.CompletionType[player] == "last_bowser_stage":
if options.completion_type == "last_bowser_stage":
world.completion_condition[player] = lambda state: state.can_reach("BitS: Top", 'Region', player)
elif world.CompletionType[player] == "all_bowser_stages":
elif options.completion_type == "all_bowser_stages":
world.completion_condition[player] = lambda state: state.can_reach("Bowser in the Dark World", 'Region', player) and \
state.can_reach("BitFS: Upper", 'Region', player) and \
state.can_reach("BitS: Top", 'Region', player)
Expand Down Expand Up @@ -262,14 +263,14 @@ class RuleFactory:
class SM64LogicException(Exception):
pass

def __init__(self, world, player, move_rando_bitvec):
def __init__(self, world, options: SM64Options, player: int, move_rando_bitvec: int):
self.world = world
self.player = player
self.move_rando_bitvec = move_rando_bitvec
self.area_randomizer = world.AreaRandomizer[player].value > 0
self.capless = not world.StrictCapRequirements[player]
self.cannonless = not world.StrictCannonRequirements[player]
self.moveless = not world.StrictMoveRequirements[player] or not move_rando_bitvec > 0
self.area_randomizer = options.area_rando > 0
self.capless = not options.strict_cap_requirements
self.cannonless = not options.strict_cannon_requirements
self.moveless = not options.strict_move_requirements or not move_rando_bitvec > 0

def assign_rule(self, target_name: str, rule_expr: str):
target = self.world.get_location(target_name, self.player) if target_name in location_table else self.world.get_entrance(target_name, self.player)
Expand Down
Loading

0 comments on commit 98ce8f8

Please sign in to comment.