From a6deffb9f2b09fa45edc8ffdb9a0e04c501d154f Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Sun, 11 Feb 2024 02:25:03 +0100 Subject: [PATCH] The Witness: Change all option name comparisons to strings instead of numeric values (#2503) * Refactor postgame code to be more readable * Change all references to options to strings * oops * Fix some outdated code related to yaml-disabled EPs * Small fixes to short/longbox stuff (thanks Medic) * comment * fix duplicate * Removed triplicate lmfao * Better comment * added another 'unfun' postgame consideration * comment * more option strings * oops * Remove an unnecessary comparison * another string missed * Another was missed * This would create a really bad merge error --- worlds/witness/__init__.py | 6 +- worlds/witness/hints.py | 6 +- worlds/witness/items.py | 2 +- worlds/witness/locations.py | 4 +- worlds/witness/player_logic.py | 174 +++++++++++++++++++++------------ worlds/witness/regions.py | 8 +- 6 files changed, 123 insertions(+), 77 deletions(-) diff --git a/worlds/witness/__init__.py b/worlds/witness/__init__.py index a645abc0..d99aab5c 100644 --- a/worlds/witness/__init__.py +++ b/worlds/witness/__init__.py @@ -161,7 +161,7 @@ class WitnessWorld(World): early_items = [item for item in self.items.get_early_items() if item in self.items.get_mandatory_items()] if early_items: random_early_item = self.random.choice(early_items) - if self.options.puzzle_randomization == 1: + if self.options.puzzle_randomization == "sigma_expert": # In Expert, only tag the item as early, rather than forcing it onto the gate. self.multiworld.local_early_items[self.player][random_early_item] = 1 else: @@ -184,7 +184,7 @@ class WitnessWorld(World): # Adjust the needed size for sphere 1 based on how restrictive the settings are in terms of items needed_size = 3 - needed_size += self.options.puzzle_randomization == 1 + needed_size += self.options.puzzle_randomization == "sigma_expert" needed_size += self.options.shuffle_symbols needed_size += self.options.shuffle_doors > 0 @@ -284,7 +284,7 @@ class WitnessWorld(World): audio_logs = get_audio_logs().copy() - if hint_amount != 0: + if hint_amount: generated_hints = make_hints(self, hint_amount, self.own_itempool) self.random.shuffle(audio_logs) diff --git a/worlds/witness/hints.py b/worlds/witness/hints.py index e2d1069b..0354660b 100644 --- a/worlds/witness/hints.py +++ b/worlds/witness/hints.py @@ -176,15 +176,15 @@ def get_always_hint_items(world: "WitnessWorld") -> List[str]: wincon = world.options.victory_condition if discards: - if difficulty == 1: + if difficulty == "sigma_expert": always.append("Arrows") else: always.append("Triangles") - if wincon == 0: + if wincon == "elevator": always += ["Mountain Bottom Floor Final Room Entry (Door)", "Mountain Bottom Floor Doors"] - if wincon == 1: + if wincon == "challenge": always += ["Challenge Entry (Panel)", "Caves Panels"] return always diff --git a/worlds/witness/items.py b/worlds/witness/items.py index a8c889de..3a8b3579 100644 --- a/worlds/witness/items.py +++ b/worlds/witness/items.py @@ -228,7 +228,7 @@ class WitnessPlayerItems: output = {"Dots", "Black/White Squares", "Symmetry", "Shapers", "Stars"} if self._world.options.shuffle_discarded_panels: - if self._world.options.puzzle_randomization == 1: + if self._world.options.puzzle_randomization == "sigma_expert": output.add("Arrows") else: output.add("Triangles") diff --git a/worlds/witness/locations.py b/worlds/witness/locations.py index 02697770..1f73c2c0 100644 --- a/worlds/witness/locations.py +++ b/worlds/witness/locations.py @@ -509,9 +509,9 @@ class WitnessPlayerLocations: if world.options.shuffle_vault_boxes: self.PANEL_TYPES_TO_SHUFFLE.add("Vault") - if world.options.shuffle_EPs == 1: + if world.options.shuffle_EPs == "individual": self.PANEL_TYPES_TO_SHUFFLE.add("EP") - elif world.options.shuffle_EPs == 2: + elif world.options.shuffle_EPs == "obelisk_sides": self.PANEL_TYPES_TO_SHUFFLE.add("Obelisk Side") for obelisk_loc in StaticWitnessLocations.OBELISK_SIDES: diff --git a/worlds/witness/player_logic.py b/worlds/witness/player_logic.py index 5d538e62..24dfa7d9 100644 --- a/worlds/witness/player_logic.py +++ b/worlds/witness/player_logic.py @@ -253,51 +253,101 @@ class WitnessPlayerLogic: line = self.REFERENCE_LOGIC.ENTITIES_BY_HEX[line]["checkName"] self.ADDED_CHECKS.add(line) - def make_options_adjustments(self, world: "WitnessWorld"): - """Makes logic adjustments based on options""" - adjustment_linesets_in_order = [] + @staticmethod + def handle_postgame(world: "WitnessWorld"): + # In shuffle_postgame, panels that become accessible "after or at the same time as the goal" are disabled. + # This has a lot of complicated considerations, which I'll try my best to explain. + postgame_adjustments = [] - # Postgame - - doors = world.options.shuffle_doors >= 2 - lasers = world.options.shuffle_lasers - early_caves = world.options.early_caves > 0 + # Make some quick references to some options + doors = world.options.shuffle_doors >= 2 # "Panels" mode has no overarching region accessibility implications. + early_caves = world.options.early_caves victory = world.options.victory_condition mnt_lasers = world.options.mountain_lasers chal_lasers = world.options.challenge_lasers - mountain_enterable_from_top = victory == 0 or victory == 1 or (victory == 3 and chal_lasers > mnt_lasers) + # Goal is "short box" but short box requires more lasers than long box + reverse_shortbox_goal = victory == "mountain_box_short" and mnt_lasers > chal_lasers + # Goal is "short box", and long box requires at least as many lasers as short box (as god intended) + proper_shortbox_goal = victory == "mountain_box_short" and chal_lasers >= mnt_lasers + + # Goal is "long box", but short box requires at least as many lasers than long box. + reverse_longbox_goal = victory == "mountain_box_long" and mnt_lasers >= chal_lasers + + # If goal is shortbox or "reverse longbox", you will never enter the mountain from the top before winning. + mountain_enterable_from_top = not (victory == "mountain_box_short" or reverse_longbox_goal) + + # Caves & Challenge should never have anything if doors are vanilla - definitionally "post-game" + # This is technically imprecise, but it matches player expectations better. + if not (early_caves or doors): + postgame_adjustments.append(get_caves_exclusion_list()) + postgame_adjustments.append(get_beyond_challenge_exclusion_list()) + + # If Challenge is the goal, some panels on the way need to be left on, as well as Challenge Vault box itself + if not victory == "challenge": + postgame_adjustments.append(get_path_to_challenge_exclusion_list()) + postgame_adjustments.append(get_challenge_vault_box_exclusion_list()) + + # Challenge can only have something if the goal is not challenge or longbox itself. + # In case of shortbox, it'd have to be a "reverse shortbox" situation where shortbox requires *more* lasers. + # In that case, it'd also have to be a doors mode, but that's already covered by the previous block. + if not (victory == "elevator" or reverse_shortbox_goal): + postgame_adjustments.append(get_beyond_challenge_exclusion_list()) + if not victory == "challenge": + postgame_adjustments.append(get_challenge_vault_box_exclusion_list()) + + # Mountain can't be reached if the goal is shortbox (or "reverse long box") + if not mountain_enterable_from_top: + postgame_adjustments.append(get_mountain_upper_exclusion_list()) + + # Same goes for lower mountain, but that one *can* be reached in remote doors modes. + if not doors: + postgame_adjustments.append(get_mountain_lower_exclusion_list()) + + # The Mountain Bottom Floor Discard is a bit complicated, so we handle it separately. ("it" == the Discard) + # In Elevator Goal, it is definitionally in the post-game, unless remote doors is played. + # In Challenge Goal, it is before the Challenge, so it is not post-game. + # In Short Box Goal, you can win before turning it on, UNLESS Short Box requires MORE lasers than long box. + # In Long Box Goal, it is always in the post-game because solving long box is what turns it on. + if not ((victory == "elevator" and doors) or victory == "challenge" or (reverse_shortbox_goal and doors)): + # We now know Bottom Floor Discard is in the post-game. + # This has different consequences depending on whether remote doors is being played. + # If doors are vanilla, Bottom Floor Discard locks a door to an area, which has to be disabled as well. + if doors: + postgame_adjustments.append(get_bottom_floor_discard_exclusion_list()) + else: + postgame_adjustments.append(get_bottom_floor_discard_nondoors_exclusion_list()) + + # In Challenge goal + early_caves + vanilla doors, you could find something important on Bottom Floor Discard, + # including the Caves Shortcuts themselves if playing "early_caves: start_inventory". + # This is another thing that was deemed "unfun" more than fitting the actual definition of post-game. + if victory == "challenge" and early_caves and not doors: + postgame_adjustments.append(get_bottom_floor_discard_nondoors_exclusion_list()) + + # If we have a proper short box goal, long box will never be activated first. + if proper_shortbox_goal: + postgame_adjustments.append(["Disabled Locations:", "0xFFF00 (Mountain Box Long)"]) + + return postgame_adjustments + + def make_options_adjustments(self, world: "WitnessWorld"): + """Makes logic adjustments based on options""" + adjustment_linesets_in_order = [] + + # Make condensed references to some options + + doors = world.options.shuffle_doors >= 2 # "Panels" mode has no overarching region accessibility implications. + lasers = world.options.shuffle_lasers + victory = world.options.victory_condition + mnt_lasers = world.options.mountain_lasers + chal_lasers = world.options.challenge_lasers + + # Exclude panels from the post-game if shuffle_postgame is false. if not world.options.shuffle_postgame: - if not (early_caves or doors): - adjustment_linesets_in_order.append(get_caves_exclusion_list()) - if not victory == 1: - adjustment_linesets_in_order.append(get_path_to_challenge_exclusion_list()) - adjustment_linesets_in_order.append(get_challenge_vault_box_exclusion_list()) - adjustment_linesets_in_order.append(get_beyond_challenge_exclusion_list()) - - if not ((doors or early_caves) and (victory == 0 or (victory == 2 and mnt_lasers > chal_lasers))): - adjustment_linesets_in_order.append(get_beyond_challenge_exclusion_list()) - if not victory == 1: - adjustment_linesets_in_order.append(get_challenge_vault_box_exclusion_list()) - - if not (doors or mountain_enterable_from_top): - adjustment_linesets_in_order.append(get_mountain_lower_exclusion_list()) - - if not mountain_enterable_from_top: - adjustment_linesets_in_order.append(get_mountain_upper_exclusion_list()) - - if not ((victory == 0 and doors) or victory == 1 or (victory == 2 and mnt_lasers > chal_lasers and doors)): - if doors: - adjustment_linesets_in_order.append(get_bottom_floor_discard_exclusion_list()) - else: - adjustment_linesets_in_order.append(get_bottom_floor_discard_nondoors_exclusion_list()) - - if victory == 2 and chal_lasers >= mnt_lasers: - adjustment_linesets_in_order.append(["Disabled Locations:", "0xFFF00 (Mountain Box Long)"]) + adjustment_linesets_in_order += self.handle_postgame(world) # Exclude Discards / Vaults - if not world.options.shuffle_discarded_panels: # In disable_non_randomized, the discards are needed for alternate activation triggers, UNLESS both # (remote) doors and lasers are shuffled. @@ -309,18 +359,18 @@ class WitnessPlayerLogic: if not world.options.shuffle_vault_boxes: adjustment_linesets_in_order.append(get_vault_exclusion_list()) - if not victory == 1: + if not victory == "challenge": adjustment_linesets_in_order.append(get_challenge_vault_box_exclusion_list()) # Victory Condition - if victory == 0: + if victory == "elevator": self.VICTORY_LOCATION = "0x3D9A9" - elif victory == 1: + elif victory == "challenge": self.VICTORY_LOCATION = "0x0356B" - elif victory == 2: + elif victory == "mountain_box_short": self.VICTORY_LOCATION = "0x09F7F" - elif victory == 3: + elif victory == "mountain_box_long": self.VICTORY_LOCATION = "0xFFF00" # Long box can usually only be solved by opening Mountain Entry. However, if it requires 7 lasers or less @@ -338,36 +388,36 @@ class WitnessPlayerLogic: if world.options.shuffle_symbols: adjustment_linesets_in_order.append(get_symbol_shuffle_list()) - if world.options.EP_difficulty == 0: + if world.options.EP_difficulty == "normal": adjustment_linesets_in_order.append(get_ep_easy()) - elif world.options.EP_difficulty == 1: + elif world.options.EP_difficulty == "tedious": adjustment_linesets_in_order.append(get_ep_no_eclipse()) - if world.options.door_groupings == 1: - if world.options.shuffle_doors == 1: + if world.options.door_groupings == "regional": + if world.options.shuffle_doors == "panels": adjustment_linesets_in_order.append(get_simple_panels()) - elif world.options.shuffle_doors == 2: + elif world.options.shuffle_doors == "doors": adjustment_linesets_in_order.append(get_simple_doors()) - elif world.options.shuffle_doors == 3: + elif world.options.shuffle_doors == "mixed": adjustment_linesets_in_order.append(get_simple_doors()) adjustment_linesets_in_order.append(get_simple_additional_panels()) else: - if world.options.shuffle_doors == 1: + if world.options.shuffle_doors == "panels": adjustment_linesets_in_order.append(get_complex_door_panels()) adjustment_linesets_in_order.append(get_complex_additional_panels()) - elif world.options.shuffle_doors == 2: + elif world.options.shuffle_doors == "doors": adjustment_linesets_in_order.append(get_complex_doors()) - elif world.options.shuffle_doors == 3: + elif world.options.shuffle_doors == "mixed": adjustment_linesets_in_order.append(get_complex_doors()) adjustment_linesets_in_order.append(get_complex_additional_panels()) if world.options.shuffle_boat: adjustment_linesets_in_order.append(get_boat()) - if world.options.early_caves == 2: + if world.options.early_caves == "starting_inventory": adjustment_linesets_in_order.append(get_early_caves_start_list()) - if world.options.early_caves == 1 and not doors: + if world.options.early_caves == "add_to_pool" and not doors: adjustment_linesets_in_order.append(get_early_caves_list()) if world.options.elevators_come_to_you: @@ -391,25 +441,21 @@ class WitnessPlayerLogic: else: adjustment_linesets_in_order.append(["Disabled Locations:"] + get_ep_obelisks()[1:]) - if world.options.shuffle_EPs == 0: + if not world.options.shuffle_EPs: adjustment_linesets_in_order.append(["Irrelevant Locations:"] + get_ep_all_individual()[1:]) - yaml_disabled_eps = [] - for yaml_disabled_location in self.YAML_DISABLED_LOCATIONS: if yaml_disabled_location not in self.REFERENCE_LOGIC.ENTITIES_BY_NAME: continue loc_obj = self.REFERENCE_LOGIC.ENTITIES_BY_NAME[yaml_disabled_location] - if loc_obj["entityType"] == "EP" and world.options.shuffle_EPs != 0: - yaml_disabled_eps.append(loc_obj["entity_hex"]) + if loc_obj["entityType"] == "EP": + self.COMPLETELY_DISABLED_ENTITIES.add(loc_obj["entity_hex"]) - if loc_obj["entityType"] in {"EP", "General", "Vault", "Discard"}: + elif loc_obj["entityType"] in {"General", "Vault", "Discard"}: self.EXCLUDED_LOCATIONS.add(loc_obj["entity_hex"]) - adjustment_linesets_in_order.append(["Disabled Locations:"] + yaml_disabled_eps) - for adjustment_lineset in adjustment_linesets_in_order: current_adjustment_type = None @@ -519,13 +565,13 @@ class WitnessPlayerLogic: self.DOOR_ITEMS_BY_ID: Dict[str, List[str]] = {} self.STARTING_INVENTORY = set() - self.DIFFICULTY = world.options.puzzle_randomization.value + self.DIFFICULTY = world.options.puzzle_randomization - if self.DIFFICULTY == 0: + if self.DIFFICULTY == "sigma_normal": self.REFERENCE_LOGIC = StaticWitnessLogic.sigma_normal - elif self.DIFFICULTY == 1: + elif self.DIFFICULTY == "sigma_expert": self.REFERENCE_LOGIC = StaticWitnessLogic.sigma_expert - elif self.DIFFICULTY == 2: + elif self.DIFFICULTY == "none": self.REFERENCE_LOGIC = StaticWitnessLogic.vanilla self.CONNECTIONS_BY_REGION_NAME = copy.copy(self.REFERENCE_LOGIC.STATIC_CONNECTIONS_BY_REGION_NAME) diff --git a/worlds/witness/regions.py b/worlds/witness/regions.py index e0970248..3a1a1781 100644 --- a/worlds/witness/regions.py +++ b/worlds/witness/regions.py @@ -134,13 +134,13 @@ class WitnessRegions: world.multiworld.regions += final_regions_list def __init__(self, locat: WitnessPlayerLocations, world: "WitnessWorld"): - difficulty = world.options.puzzle_randomization.value + difficulty = world.options.puzzle_randomization - if difficulty == 0: + if difficulty == "sigma_normal": self.reference_logic = StaticWitnessLogic.sigma_normal - elif difficulty == 1: + elif difficulty == "sigma_expert": self.reference_logic = StaticWitnessLogic.sigma_expert - elif difficulty == 2: + elif difficulty == "none": self.reference_logic = StaticWitnessLogic.vanilla self.locat = locat