Skip to content

Commit

Permalink
The Witness: Automatic Postgame & Disabled Panels Calculation (Archip…
Browse files Browse the repository at this point in the history
…elagoMW#2698)

* 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

* New classification changes (Credit: Exempt-Medic)

* Don't need to pass world

* Comments

* Replace it with another magic system because why not at this point :DDDDDD

* oops

* Oops

* Another was missed

* Make events conditions. Disable_Non_Randomized will no longer just 'have all events'

* What the fuck? Has this just always been broken?

* Don't have boolean function with 'not' in the name

* Another useful classification

* slight code refactor

* Funny haha booleans

* This would create a really bad merge error

* I can't believe this actually kind of works

* And here's the punchline. + some bugfixes

* Comment dat code

* Comments galore

* LMAO OOPS

* so nice I did it twice

* debug x2

* Careful

* Add more comments

* That comment is a bit unnecessary now

* Fix overriding region connections

* Correct a comment

* Correct again

* Rename variable

* Idk I guess this is in this branch now

* More tweaking of postgame & comments

* This is commit just exists to fix that grammar error

* I think I can just fucking delete this now???

* Forgot to reset something here

* Delete dead codepath

* Obelisk Keys were getting yote erroneously

* More comments

* Fix duplicate connections

* Oopsington III

* performance improvements & cleanup

* More rules cleanup and performance improvements

* Oh cool I can do this huh

* Okay but this is even more swag tho

* Lazy eval

* remove some implicit checks

* Is this too magical yet

* more guard magic

* Maaaaaaaagiccccccccc

* Laaaaaaaaaaaaaaaazzzzzzyyyyyyyyyyy

* Make it docstring

* Newline bc I like that better

* this is a little spooky lol

* lol

* Wait

* spoO

* Better variable name and comment

* Improved comment again

* better API

* oops I deleted a deepcopy

* lol help

* Help???

* player_regionsns lmao

* Add some comments

* Make doors disabled properly again. I hope this works

* Don't disable lasers

* Omega oops

* Make Floor 2 Exit not exist

* Make a fix that's warps compatible

* I think this was an oversight, I tested a seed and it seems to have the same result

* This is definitely less Violet than before

* Does this feel more violet lol

* Exception if a laser gets disabled, cleanup

* Ruff

* >:(

* consistent utils import

* Make autopostgame more reviewable (hopefully)

* more reviewability

* WitnessRule

* replace another instance of it

* lint

* style

* comment

* found the bug

* Move comment

* Get rid of cache and ugly allow_victory

* comments and lint
  • Loading branch information
NewSoupVi authored Jun 1, 2024
1 parent da33d15 commit e49b1f9
Show file tree
Hide file tree
Showing 19 changed files with 628 additions and 503 deletions.
4 changes: 2 additions & 2 deletions worlds/witness/data/WitnessLogic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1028,15 +1028,15 @@ Mountain Floor 1 Bridge (Mountain Floor 1) - Mountain Floor 1 At Door - TrueOneW
Mountain Floor 1 At Door (Mountain Floor 1) - Mountain Floor 2 - 0x09E54:
Door - 0x09E54 (Exit) - 0x09EAF & 0x09F6E & 0x09E6B & 0x09E7B

Mountain Floor 2 (Mountain Floor 2) - Mountain Floor 2 Light Bridge Room Near - 0x09FFB - Mountain Floor 2 Beyond Bridge - 0x09E86 - Mountain Floor 2 At Door - 0x09ED8 & 0x09E86 - Mountain Pink Bridge EP - TrueOneWay:
Mountain Floor 2 (Mountain Floor 2) - Mountain Floor 2 Light Bridge Room Near - 0x09FFB - Mountain Floor 2 Beyond Bridge - 0x09E86 - Mountain Floor 2 Above The Abyss - True - Mountain Pink Bridge EP - TrueOneWay:
158426 - 0x09FD3 (Near Row 1) - True - Stars & Colored Squares & Stars + Same Colored Symbol
158427 - 0x09FD4 (Near Row 2) - 0x09FD3 - Stars & Colored Squares & Stars + Same Colored Symbol
158428 - 0x09FD6 (Near Row 3) - 0x09FD4 - Stars & Colored Squares & Stars + Same Colored Symbol
158429 - 0x09FD7 (Near Row 4) - 0x09FD6 - Stars & Colored Squares & Stars + Same Colored Symbol & Shapers
158430 - 0x09FD8 (Near Row 5) - 0x09FD7 - Symmetry & Colored Dots
Door - 0x09FFB (Staircase Near) - 0x09FD8

Mountain Floor 2 At Door (Mountain Floor 2) - Mountain Floor 2 Elevator Room - 0x09EDD:
Mountain Floor 2 Above The Abyss (Mountain Floor 2) - Mountain Floor 2 Elevator Room - 0x09EDD & 0x09ED8 & 0x09E86:
Door - 0x09EDD (Elevator Room Entry) - 0x09ED8 & 0x09E86

Mountain Floor 2 Light Bridge Room Near (Mountain Floor 2):
Expand Down
4 changes: 2 additions & 2 deletions worlds/witness/data/WitnessLogicExpert.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1028,15 +1028,15 @@ Mountain Floor 1 Bridge (Mountain Floor 1) - Mountain Floor 1 At Door - TrueOneW
Mountain Floor 1 At Door (Mountain Floor 1) - Mountain Floor 2 - 0x09E54:
Door - 0x09E54 (Exit) - 0x09EAF & 0x09F6E & 0x09E6B & 0x09E7B

Mountain Floor 2 (Mountain Floor 2) - Mountain Floor 2 Light Bridge Room Near - 0x09FFB - Mountain Floor 2 Beyond Bridge - 0x09E86 - Mountain Floor 2 At Door - 0x09ED8 & 0x09E86 - Mountain Pink Bridge EP - TrueOneWay:
Mountain Floor 2 (Mountain Floor 2) - Mountain Floor 2 Light Bridge Room Near - 0x09FFB - Mountain Floor 2 Beyond Bridge - 0x09E86 - Mountain Floor 2 Above The Abyss - True - Mountain Pink Bridge EP - TrueOneWay:
158426 - 0x09FD3 (Near Row 1) - True - Stars & Colored Squares & Stars + Same Colored Symbol
158427 - 0x09FD4 (Near Row 2) - 0x09FD3 - Stars & Triangles & Stars + Same Colored Symbol
158428 - 0x09FD6 (Near Row 3) - 0x09FD4 - Stars & Shapers & Negative Shapers & Stars + Same Colored Symbol
158429 - 0x09FD7 (Near Row 4) - 0x09FD6 - Stars
158430 - 0x09FD8 (Near Row 5) - 0x09FD7 - Stars & Stars + Same Colored Symbol & Rotated Shapers & Eraser
Door - 0x09FFB (Staircase Near) - 0x09FD8

Mountain Floor 2 At Door (Mountain Floor 2) - Mountain Floor 2 Elevator Room - 0x09EDD:
Mountain Floor 2 Above The Abyss (Mountain Floor 2) - Mountain Floor 2 Elevator Room - 0x09EDD & 0x09ED8 & 0x09E86:
Door - 0x09EDD (Elevator Room Entry) - 0x09ED8 & 0x09E86

Mountain Floor 2 Light Bridge Room Near (Mountain Floor 2):
Expand Down
4 changes: 2 additions & 2 deletions worlds/witness/data/WitnessLogicVanilla.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1028,15 +1028,15 @@ Mountain Floor 1 Bridge (Mountain Floor 1) - Mountain Floor 1 At Door - TrueOneW
Mountain Floor 1 At Door (Mountain Floor 1) - Mountain Floor 2 - 0x09E54:
Door - 0x09E54 (Exit) - 0x09EAF & 0x09F6E & 0x09E6B & 0x09E7B

Mountain Floor 2 (Mountain Floor 2) - Mountain Floor 2 Light Bridge Room Near - 0x09FFB - Mountain Floor 2 Beyond Bridge - 0x09E86 - Mountain Floor 2 At Door - 0x09ED8 & 0x09E86 - Mountain Pink Bridge EP - TrueOneWay:
Mountain Floor 2 (Mountain Floor 2) - Mountain Floor 2 Light Bridge Room Near - 0x09FFB - Mountain Floor 2 Beyond Bridge - 0x09E86 - Mountain Floor 2 Above The Abyss - True - Mountain Pink Bridge EP - TrueOneWay:
158426 - 0x09FD3 (Near Row 1) - True - Colored Squares
158427 - 0x09FD4 (Near Row 2) - 0x09FD3 - Colored Squares & Dots
158428 - 0x09FD6 (Near Row 3) - 0x09FD4 - Stars & Colored Squares & Stars + Same Colored Symbol
158429 - 0x09FD7 (Near Row 4) - 0x09FD6 - Stars & Colored Squares & Stars + Same Colored Symbol & Shapers
158430 - 0x09FD8 (Near Row 5) - 0x09FD7 - Colored Squares
Door - 0x09FFB (Staircase Near) - 0x09FD8

Mountain Floor 2 At Door (Mountain Floor 2) - Mountain Floor 2 Elevator Room - 0x09EDD:
Mountain Floor 2 Above The Abyss (Mountain Floor 2) - Mountain Floor 2 Elevator Room - 0x09EDD & 0x09ED8 & 0x09E86:
Door - 0x09EDD (Elevator Room Entry) - 0x09ED8 & 0x09E86

Mountain Floor 2 Light Bridge Room Near (Mountain Floor 2):
Expand Down
14 changes: 0 additions & 14 deletions worlds/witness/data/settings/Exclusions/Disable_Unrandomized.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,3 @@ Disabled Locations:
0x17E67 (Bunker UV Room 2)
0x09DE0 (Bunker Laser)
0x0A079 (Bunker Elevator Control)

0x034A7 (Monastery Left Shutter EP)
0x034AD (Monastery Middle Shutter EP)
0x034AF (Monastery Right Shutter EP)
0x339B6 (Theater Eclipse EP)
0x33A29 (Theater Window EP)
0x33A2A (Theater Door EP)
0x33B06 (Theater Church EP)
0x3352F (Tutorial Gate EP)
0x33600 (Tutorial Patio Flowers EP)
0x035F5 (Bunker Tinted Door EP)
0x000D3 (Bunker Green Room Flowers EP)
0x33A20 (Theater Flowers EP)
0x03BE2 (Monastery Garden Left EP)
23 changes: 0 additions & 23 deletions worlds/witness/data/settings/Exclusions/Vaults.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
Disabled Locations:
0x033D4 (Outside Tutorial Vault)
0x03481 (Outside Tutorial Vault Box)
0x033D0 (Outside Tutorial Vault Door)
0x0CC7B (Desert Vault)
0x0339E (Desert Vault Box)
0x03444 (Desert Vault Door)
0x00AFB (Shipwreck Vault)
0x03535 (Shipwreck Vault Box)
0x17BB4 (Shipwreck Vault Door)
0x15ADD (Jungle Vault)
0x03702 (Jungle Vault Box)
0x15287 (Jungle Vault Door)
0x002A6 (Mountainside Vault)
0x03542 (Mountainside Vault Box)
0x00085 (Mountainside Vault Door)
0x2FAF6 (Tunnels Vault Box)
0x00815 (Theater Video Input)
0x03553 (Theater Tutorial Video)
0x03552 (Theater Desert Video)
0x0354E (Theater Jungle Video)
0x03549 (Theater Challenge Video)
0x0354F (Theater Shipwreck Video)
0x03545 (Theater Mountain Video)
0x03505 (Tutorial Gate Close)
0x339B6 (Theater clipse EP)
0x33A29 (Theater Window EP)
0x33A2A (Theater Door EP)
0x33B06 (Theater Church EP)
0x33A20 (Theater Flowers EP)
0x3352F (Tutorial Gate EP)
4 changes: 0 additions & 4 deletions worlds/witness/data/settings/Postgame/Beyond_Challenge.txt

This file was deleted.

This file was deleted.

This file was deleted.

22 changes: 0 additions & 22 deletions worlds/witness/data/settings/Postgame/Challenge_Vault_Box.txt

This file was deleted.

27 changes: 0 additions & 27 deletions worlds/witness/data/settings/Postgame/Mountain_Lower.txt

This file was deleted.

41 changes: 0 additions & 41 deletions worlds/witness/data/settings/Postgame/Mountain_Upper.txt

This file was deleted.

30 changes: 0 additions & 30 deletions worlds/witness/data/settings/Postgame/Path_To_Challenge.txt

This file was deleted.

51 changes: 45 additions & 6 deletions worlds/witness/data/static_logic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import defaultdict
from functools import lru_cache
from typing import Dict, List
from typing import Dict, List, Set, Tuple

from .item_definition_classes import (
CATEGORY_NAME_MAPPINGS,
Expand All @@ -10,11 +11,13 @@
WeightedItemDefinition,
)
from .utils import (
WitnessRule,
define_new_region,
get_items,
get_sigma_expert_logic,
get_sigma_normal_logic,
get_vanilla_logic,
logical_or_witness_rules,
parse_lambda,
)

Expand All @@ -41,7 +44,8 @@ def read_logic_file(self, lines) -> None:
current_region = new_region_and_connections[0]
region_name = current_region["name"]
self.ALL_REGIONS_BY_NAME[region_name] = current_region
self.STATIC_CONNECTIONS_BY_REGION_NAME[region_name] = new_region_and_connections[1]
for connection in new_region_and_connections[1]:
self.CONNECTIONS_WITH_DUPLICATES[region_name][connection[0]].add(connection[1])
current_area["regions"].append(region_name)
continue

Expand Down Expand Up @@ -80,13 +84,15 @@ def read_logic_file(self, lines) -> None:
self.ENTITIES_BY_NAME[self.ENTITIES_BY_HEX[entity_hex]["checkName"]] = self.ENTITIES_BY_HEX[entity_hex]

self.STATIC_DEPENDENT_REQUIREMENTS_BY_HEX[entity_hex] = {
"panels": parse_lambda(required_panel_lambda)
"entities": parse_lambda(required_panel_lambda)
}

# Lasers and Doors exist in a region, but don't have a regional *requirement*
# If a laser is activated, you don't need to physically walk up to it for it to count
# As such, logically, they behave more as if they were part of the "Entry" region
self.ALL_REGIONS_BY_NAME["Entry"]["panels"].append(entity_hex)
self.ALL_REGIONS_BY_NAME["Entry"]["entities"].append(entity_hex)
# However, it will also be important to keep track of their physical location for postgame purposes.
current_region["physical_entities"].append(entity_hex)
continue

required_item_lambda = line_split.pop(0)
Expand Down Expand Up @@ -117,7 +123,7 @@ def read_logic_file(self, lines) -> None:
required_items = frozenset(required_items)

requirement = {
"panels": required_panels,
"entities": required_panels,
"items": required_items
}

Expand Down Expand Up @@ -145,7 +151,37 @@ def read_logic_file(self, lines) -> None:
self.ENTITIES_BY_NAME[self.ENTITIES_BY_HEX[entity_hex]["checkName"]] = self.ENTITIES_BY_HEX[entity_hex]
self.STATIC_DEPENDENT_REQUIREMENTS_BY_HEX[entity_hex] = requirement

current_region["panels"].append(entity_hex)
current_region["entities"].append(entity_hex)
current_region["physical_entities"].append(entity_hex)

def reverse_connection(self, source_region: str, connection: Tuple[str, Set[WitnessRule]]):
target = connection[0]
traversal_options = connection[1]

# Reverse this connection with all its possibilities, except the ones marked as "OneWay".
for requirement in traversal_options:
remaining_options = set()
for option in requirement:
if not any(req == "TrueOneWay" for req in option):
remaining_options.add(option)

if remaining_options:
self.CONNECTIONS_WITH_DUPLICATES[target][source_region].add(frozenset(remaining_options))

def reverse_connections(self):
# Iterate all connections
for region_name, connections in list(self.CONNECTIONS_WITH_DUPLICATES.items()):
for connection in connections.items():
self.reverse_connection(region_name, connection)

def combine_connections(self):
# All regions need to be present, and this dict is copied later - Thus, defaultdict is not the correct choice.
self.STATIC_CONNECTIONS_BY_REGION_NAME = {region_name: set() for region_name in self.ALL_REGIONS_BY_NAME}

for source, connections in self.CONNECTIONS_WITH_DUPLICATES.items():
for target, requirement in connections.items():
combined_req = logical_or_witness_rules(requirement)
self.STATIC_CONNECTIONS_BY_REGION_NAME[source].add((target, combined_req))

def __init__(self, lines=None) -> None:
if lines is None:
Expand All @@ -154,6 +190,7 @@ def __init__(self, lines=None) -> None:
# All regions with a list of panels in them and the connections to other regions, before logic adjustments
self.ALL_REGIONS_BY_NAME = dict()
self.ALL_AREAS_BY_NAME = dict()
self.CONNECTIONS_WITH_DUPLICATES = defaultdict(lambda: defaultdict(lambda: set()))
self.STATIC_CONNECTIONS_BY_REGION_NAME = dict()

self.ENTITIES_BY_HEX = dict()
Expand All @@ -167,6 +204,8 @@ def __init__(self, lines=None) -> None:
self.ENTITY_ID_TO_NAME = dict()

self.read_logic_file(lines)
self.reverse_connections()
self.combine_connections()


# Item data parsed from WitnessItems.txt
Expand Down
Loading

0 comments on commit e49b1f9

Please sign in to comment.