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

The Witness: Make location order in the spoiler log deterministic #3895

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions worlds/witness/data/static_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def read_logic_file(self, lines: List[str]) -> None:
"entityType": location_id,
"locationType": None,
"area": current_area,
"order": len(self.ENTITIES_BY_HEX),
}

self.ENTITIES_BY_NAME[self.ENTITIES_BY_HEX[entity_hex]["checkName"]] = self.ENTITIES_BY_HEX[entity_hex]
Expand Down Expand Up @@ -186,6 +187,7 @@ def read_logic_file(self, lines: List[str]) -> None:
"entityType": entity_type,
"locationType": location_type,
"area": current_area,
"order": len(self.ENTITIES_BY_HEX),
}

self.ENTITY_ID_TO_NAME[entity_hex] = full_entity_name
Expand Down
29 changes: 21 additions & 8 deletions worlds/witness/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,41 @@ def create_regions(self, world: "WitnessWorld", player_logic: WitnessPlayerLogic
if k not in player_logic.UNREACHABLE_REGIONS
}

event_locations_per_region = defaultdict(list)
event_locations_per_region = defaultdict(dict)

for event_location, event_item_and_entity in player_logic.EVENT_ITEM_PAIRS.items():
region = static_witness_logic.ENTITIES_BY_HEX[event_item_and_entity[1]]["region"]
if region is None:
region_name = "Entry"
else:
region_name = region["name"]
event_locations_per_region[region_name].append(event_location)
order = self.reference_logic.ENTITIES_BY_HEX[event_item_and_entity[1]]["order"]
event_locations_per_region[region_name][event_location] = order

for region_name, region in regions_to_create.items():
locations_for_this_region = [
self.reference_logic.ENTITIES_BY_HEX[panel]["checkName"] for panel in region["entities"]
if self.reference_logic.ENTITIES_BY_HEX[panel]["checkName"]
in self.player_locations.CHECK_LOCATION_TABLE
location_entities_for_this_region = [
self.reference_logic.ENTITIES_BY_HEX[entity] for entity in region["entities"]
]
locations_for_this_region = {
entity["checkName"]: entity["order"] for entity in location_entities_for_this_region
if entity["checkName"] in self.player_locations.CHECK_LOCATION_TABLE
}

locations_for_this_region += event_locations_per_region[region_name]
events = event_locations_per_region[region_name]
locations_for_this_region.update(events)

# First, sort by keys.
locations_for_this_region = dict(sorted(locations_for_this_region.items()))

# Then, sort by game order (values)
locations_for_this_region = dict(sorted(
locations_for_this_region.items(),
key=lambda location_name_and_order: location_name_and_order[1]
))

all_locations = all_locations | set(locations_for_this_region)

new_region = create_region(world, region_name, self.player_locations, locations_for_this_region)
new_region = create_region(world, region_name, self.player_locations, list(locations_for_this_region))

regions_by_name[region_name] = new_region

Expand Down
Loading