summary refs log tree commit diff stats
path: root/locations.py
diff options
context:
space:
mode:
Diffstat (limited to 'locations.py')
-rw-r--r--locations.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/locations.py b/locations.py new file mode 100644 index 0000000..5903d60 --- /dev/null +++ b/locations.py
@@ -0,0 +1,80 @@
1from enum import Flag, auto
2from typing import Dict, List, NamedTuple
3
4from BaseClasses import Location
5from .static_logic import DOORS_BY_ROOM, PANELS_BY_ROOM, RoomAndPanel, get_door_location_id, get_panel_location_id
6
7
8class LocationClassification(Flag):
9 normal = auto()
10 reduced = auto()
11 insanity = auto()
12
13
14class LocationData(NamedTuple):
15 """
16 LocationData for a location in Lingo
17 """
18 code: int
19 room: str
20 panels: List[RoomAndPanel]
21 classification: LocationClassification
22
23 def panel_ids(self):
24 ids = set()
25 for panel in self.panels:
26 effective_room = self.room if panel.room is None else panel.room
27 panel_data = PANELS_BY_ROOM[effective_room][panel.panel]
28 ids = ids | set(panel_data.internal_ids)
29 return ids
30
31
32class LingoLocation(Location):
33 """
34 Location from the game Lingo
35 """
36 game: str = "Lingo"
37
38
39ALL_LOCATION_TABLE: Dict[str, LocationData] = {}
40
41
42def load_location_data():
43 global ALL_LOCATION_TABLE
44
45 for room_name, panels in PANELS_BY_ROOM.items():
46 for panel_name, panel in panels.items():
47 location_name = f"{room_name} - {panel_name}"
48
49 classification = LocationClassification.insanity
50 if panel.check:
51 classification |= LocationClassification.normal
52
53 if not panel.exclude_reduce:
54 classification |= LocationClassification.reduced
55
56 ALL_LOCATION_TABLE[location_name] = \
57 LocationData(get_panel_location_id(room_name, panel_name), room_name,
58 [RoomAndPanel(None, panel_name)], classification)
59
60 for room_name, doors in DOORS_BY_ROOM.items():
61 for door_name, door in doors.items():
62 if door.skip_location or door.event or door.panels is None:
63 continue
64
65 location_name = door.location_name
66 classification = LocationClassification.normal
67 if door.include_reduce:
68 classification |= LocationClassification.reduced
69
70 if location_name in ALL_LOCATION_TABLE:
71 new_id = ALL_LOCATION_TABLE[location_name].code
72 classification |= ALL_LOCATION_TABLE[location_name].classification
73 else:
74 new_id = get_door_location_id(room_name, door_name)
75
76 ALL_LOCATION_TABLE[location_name] = LocationData(new_id, room_name, door.panels, classification)
77
78
79# Initialize location data on the module scope.
80load_location_data()