about summary refs log tree commit diff stats
path: root/data/maps/the_revitalized/rooms
Commit message (Collapse)AuthorAgeFilesLines
* Changed how door location names are formattedStar Rauchenberger2025-08-307-7/+0
| | | | | | | | | | | | | | | | | | STANDARD type doors with at most four panels in the same map area and no other trigger objects will have their location names generated from the names of the panels used to open the door, similar to Lingo 1. Other door types will use the door's name. In either case, the name can be overridden using the new location_name field. Rooms can also set a panel_display_name field, which will be used in location names for doors, and is used to group panels into areas. Panels themselves can set display names, which differentiates their locations from other panels in the same area. Many maps were updated for this, but note that the_symbolic and the_unyielding have validator failures because of duplicate panel names. This won't matter until panelsanity is implemented.
* Converted puzzle symbols to an enumStar Rauchenberger2025-08-207-7/+7
|
* Added the_revitalizedStar Rauchenberger2025-08-187-0/+68
us revision' href='/lingo2-archipelago/blame/apworld/player_logic.py?h=v8.1.1&id=3c26cedd030c464e3b8a5576a98c19eb45134658'>^
447a222 ^




18e64c9 ^

447a222 ^




a3972a6 ^
447a222 ^
447a222 ^
ebda0b6 ^
447a222 ^



7426eb8 ^




447a222 ^

a3972a6 ^
447a222 ^
447a222 ^
ebda0b6 ^
447a222 ^
7426eb8 ^

447a222 ^
e187853 ^











447a222 ^



a3972a6 ^


447a222 ^


447a222 ^


ebda0b6 ^

447a222 ^
8ea8aef ^
447a222 ^
7426eb8 ^








8ea8aef ^
7426eb8 ^






8ea8aef ^
7426eb8 ^


8ea8aef ^
7426eb8 ^
8de745f ^

e187853 ^













b2b8769 ^





e187853 ^




b2b8769 ^


e187853 ^














8de745f ^
462a547 ^






















18e64c9 ^



a3972a6 ^

18e64c9 ^

18e64c9 ^

ebda0b6 ^

18e64c9 ^

7426eb8 ^



fd70071 ^
18e64c9 ^
447a222 ^
c9da387 ^
c9da387 ^
447a222 ^
c9da387 ^

ebda0b6 ^





c9da387 ^
447a222 ^

dcecbb8 ^

c9da387 ^
4ae885f ^

a3972a6 ^
c9da387 ^
447a222 ^





ebda0b6 ^
b53d1f9 ^
ebda0b6 ^
c9da387 ^
447a222 ^
c9da387 ^
4ae885f ^
a17b7e1 ^
447a222 ^



ebda0b6 ^
c9da387 ^
dcecbb8 ^




8cfee29 ^


85bb357 ^

52990b2 ^

10c762e ^

dcecbb8 ^





ea87cbb ^






a3972a6 ^


dcecbb8 ^



a3972a6 ^


d79984b ^
6af543b ^
424f5d4 ^
6af543b ^

424f5d4 ^
6af543b ^
57a08a3 ^


6af543b ^
d79984b ^

dcecbb8 ^

d79984b ^
dcecbb8 ^




d79984b ^
a17b7e1 ^


dcecbb8 ^


d79984b ^












a3972a6 ^
bb4e4e3 ^


d79984b ^


a17b7e1 ^
6af543b ^






dcecbb8 ^





6af543b ^

dcecbb8 ^
6af543b ^
c9da387 ^
dcecbb8 ^


8662f88 ^
447a222 ^


9ca8681 ^
dcecbb8 ^


447a222 ^

ebda0b6 ^

b0f474b ^


ebda0b6 ^
b0f474b ^



ebda0b6 ^

18e64c9 ^
ebda0b6 ^

18e64c9 ^
9ca8681 ^
dcecbb8 ^


447a222 ^


ea87cbb ^



bcf5038 ^
dcecbb8 ^


ea87cbb ^

91f829a ^
ea87cbb ^
a4b9a8f ^

bcf5038 ^
4ae885f ^
ea87cbb ^
4ae885f ^


b53d1f9 ^
4ae885f ^


7f82beb ^


dcecbb8 ^


7f82beb ^
ebda0b6 ^


7f82beb ^



8de745f ^



447a222 ^


















ebda0b6 ^
447a222 ^
18e64c9 ^
8de745f ^
18e64c9 ^
447a222 ^

ebda0b6 ^
447a222 ^
8de745f ^




4ae885f ^
8de745f ^
4ae885f ^
ebda0b6 ^
4ae885f ^
8de745f ^



18e64c9 ^
8de745f ^

447a222 ^
ebda0b6 ^
447a222 ^
8de745f ^


447a222 ^

a17b7e1 ^
447a222 ^






a17b7e1 ^

447a222 ^









4ae885f ^




8de745f ^









447a222 ^
7426eb8 ^



4ae885f ^
3b77044 ^
8dffc0d ^
3b77044 ^
ebda0b6 ^
3b77044 ^
8dffc0d ^
6af543b ^
ebda0b6 ^
6af543b ^
8de745f ^

6af543b ^


8dffc0d ^
18e64c9 ^

ebda0b6 ^

18e64c9 ^




4ae885f ^


ea87cbb ^


a825f80 ^
ea87cbb ^

a4b9a8f ^
4ae885f ^


c474cb2 ^
e187853 ^

447a222 ^
a17b7e1 ^





a3972a6 ^





a17b7e1 ^



ebda0b6 ^




































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601

                              
                                           
                               

                                            
                                                     
 



                             




                                                                

                                                                    




                         
                                
                   
                           
               



                                              




                                                                                                                      

                          
                                  
                          
                             
                          
                              

                                   
 











                                                                                                          



                                                 


                                                                                 


                                


                                                                          

                                              
                                          
                                                                             
 








                                                                                                                     
                                                                                           






                                                         
                                                                                             


                                                    
                                                                                        
 

                                                                                                                        













                                                                                                                       





                                                                                                            




                                            


                                                       














                                                                                 
 






















                                                                     



                                               

                                                             

                                               

                                                   

                                       

                                                     



                                                               
                                                             
 
 
                                 
                    
                            

 





                              
                        

                        

                           
                                                      

                                                     
                                            
 





                                                        
                                        
                     
 
                                             
                          
                                   
                                        
                              



                                
                                          
 




                                                            


                                                                                 

                                                                                    

                                                                                    

                                                                                





                                                                                            






                                                                          


                                                                       



                                                                                 


                                                                                       
                                                                 
                                                                   
                                                                                                 

                                                                           
                                                                                                                 
                            


                                                                         
                 

                        

                                                                                                           
 




                                                                  
 


                                                                                                                      


                                                     












                                                                                                                     
 


                                                                                                                    


                                                                             
 






                                                                                                                      





                                                                                                              

                                                                      
                                                           
 
                                                     


                                                     
                                                                                                                        


                                                                                                                       
                                                         


                                                                                           

                                                                                                              

                                                                          


                                                                                        
                                                                                                               



                                                                                                                   

                                                          
 

                                                                                                                        
 
                                                            


                                                                                            


                                                                                                               



                                                                                                            
                                                         


                                                                                           

                                                                                                                     
                                                                                                          
                                                                                           

                                                                                                                  
 
                                                                        
                                


                                                                                                          
                                                  


                                                                                              


                                                                   


                                                                                                      
                                               


                                                                                                 



                                                                                                                   



                                                     


















                                                                                                              
                                                
                                    
                              
                                  
 

                                                 
                                                                
 




                                                    
 
                                                                                                       
                                                 
                                                                
 



                                                    
 

                                                   
             
                                                      
 


                                                        

                                           
                                                                    






                                                                                             

                                                                                                                       









                                                                       




                                                                                                                 









                                                                                                                 
             



                                                                                                                 
 
                                                 
                                                                           
                                                        
                                                                   
 
                               
                                                                                           
                                                            
                                                                                                    

                                                                                        


                                                                                       
 

                                                 

                                                                                              




                                                                                            


                                                                              


                                                                                          
 

                                                                                             
 


                                                           
 

                       
                   





                                                                                                                     





                                                              



                                              




































                                                                                                                       
from enum import IntEnum, auto

from .generated import data_pb2 as data_pb2
from .items import SYMBOL_ITEMS
from typing import TYPE_CHECKING, NamedTuple

from .options import ShuffleLetters, CyanDoorBehavior

if TYPE_CHECKING:
    from . import Lingo2World


def calculate_letter_histogram(solution: str) -> dict[str, int]:
    histogram = dict()
    for l in solution:
        if l.isalpha():
            real_l = l.upper()
            histogram[real_l] = min(histogram.get(real_l, 0) + 1, 2)

    return histogram


class AccessRequirements:
    items: set[str]
    progressives: dict[str, int]
    rooms: set[str]
    letters: dict[str, int]
    cyans: bool

    # This is an AND of ORs.
    or_logic: list[list["AccessRequirements"]]

    # When complete_at is set, at least that many of the requirements in possibilities must be accessible. This should
    # only be used for doors with complete_at > 1, as or_logic is more efficient for complete_at == 1.
    complete_at: int | None
    possibilities: list["AccessRequirements"]

    def __init__(self):
        self.items = set()
        self.progressives = dict()
        self.rooms = set()
        self.letters = dict()
        self.cyans = False
        self.or_logic = list()
        self.complete_at = None
        self.possibilities = list()

    def copy(self) -> "AccessRequirements":
        reqs = AccessRequirements()
        reqs.items = self.items.copy()
        reqs.progressives = self.progressives.copy()
        reqs.rooms = self.rooms.copy()
        reqs.letters = self.letters.copy()
        reqs.cyans = self.cyans
        reqs.or_logic = [[other_req.copy() for other_req in disjunction] for disjunction in self.or_logic]
        reqs.complete_at = self.complete_at
        reqs.possibilities = self.possibilities.copy()
        return reqs

    def merge(self, other: "AccessRequirements"):
        for item in other.items:
            self.items.add(item)

        for item, amount in other.progressives.items():
            self.progressives[item] = max(amount, self.progressives.get(item, 0))

        for room in other.rooms:
            self.rooms.add(room)

        for letter, level in other.letters.items():
            self.letters[letter] = max(self.letters.get(letter, 0), level)

        self.cyans = self.cyans or other.cyans

        for disjunction in other.or_logic:
            self.or_logic.append([sub_req.copy() for sub_req in disjunction])

        if other.complete_at is not None:
            # Merging multiple requirements that use complete_at sucks, and is part of why we want to minimize use of
            # it. If both requirements use complete_at, we will cheat by using the or_logic field, which supports
            # conjunctions of requirements.
            if self.complete_at is not None:
                print("Merging requirements with complete_at > 1. This is messy and should be avoided!")

                left_req = AccessRequirements()
                left_req.complete_at = self.complete_at
                left_req.possibilities = [sub_req.copy() for sub_req in self.possibilities]
                self.or_logic.append([left_req])

                self.complete_at = None
                self.possibilities = list()

                right_req = AccessRequirements()
                right_req.complete_at = other.complete_at
                right_req.possibilities = [sub_req.copy() for sub_req in other.possibilities]
                self.or_logic.append([right_req])
            else:
                self.complete_at = other.complete_at
                self.possibilities = [sub_req.copy() for sub_req in other.possibilities]

    def is_empty(self) -> bool:
        return (len(self.items) == 0 and len(self.progressives) == 0 and len(self.rooms) == 0 and len(self.letters) == 0
                and not self.cyans and len(self.or_logic) == 0 and self.complete_at is None)

    def __eq__(self, other: "AccessRequirements"):
        return (self.items == other.items and self.progressives == other.progressives and self.rooms == other.rooms and
                self.letters == other.letters and self.cyans == other.cyans and self.or_logic == other.or_logic and
                self.complete_at == other.complete_at and self.possibilities == other.possibilities)

    def simplify(self):
        resimplify = False

        if len(self.or_logic) > 0:
            old_or_logic = self.or_logic

            def remove_redundant(sub_reqs: "AccessRequirements"):
                new_reqs = sub_reqs.copy()
                new_reqs.letters = {l: v for l, v in new_reqs.letters.items() if self.letters.get(l, 0) < v}
                if new_reqs != sub_reqs:
                    return new_reqs
                else:
                    return sub_reqs

            self.or_logic = []
            for disjunction in old_or_logic:
                new_disjunction = []
                for ssr in disjunction:
                    new_ssr = remove_redundant(ssr)
                    if not new_ssr.is_empty():
                        new_disjunction.append(new_ssr)
                    else:
                        new_disjunction.clear()
                        break
                if len(new_disjunction) == 1:
                    self.merge(new_disjunction[0])
                    resimplify = True
                elif len(new_disjunction) > 1:
                    if all(cjr == new_disjunction[0] for cjr in new_disjunction):
                        self.merge(new_disjunction[0])
                        resimplify = True
                    else:
                        self.or_logic.append(new_disjunction)

        if resimplify:
            self.simplify()

    def get_referenced_rooms(self):
        result = set(self.rooms)

        for disjunction in self.or_logic:
            for sub_req in disjunction:
                result = result.union(sub_req.get_referenced_rooms())

        for sub_req in self.possibilities:
            result = result.union(sub_req.get_referenced_rooms())

        return result

    def remove_room(self, room: str):
        if room in self.rooms:
            self.rooms.remove(room)

        for disjunction in self.or_logic:
            for sub_req in disjunction:
                sub_req.remove_room(room)

        for sub_req in self.possibilities:
            sub_req.remove_room(room)

    def __repr__(self):
        parts = []
        if len(self.items) > 0:
            parts.append(f"items={self.items}")
        if len(self.progressives) > 0:
            parts.append(f"progressives={self.progressives}")
        if len(self.rooms) > 0:
            parts.append(f"rooms={self.rooms}")
        if len(self.letters) > 0:
            parts.append(f"letters={self.letters}")
        if self.cyans:
            parts.append(f"cyans=True")
        if len(self.or_logic) > 0:
            parts.append(f"or_logic={self.or_logic}")
        if self.complete_at is not None:
            parts.append(f"complete_at={self.complete_at}")
        if len(self.possibilities) > 0:
            parts.append(f"possibilities={self.possibilities}")
        return "AccessRequirements(" + ", ".join(parts) + ")"


class PlayerLocation(NamedTuple):
    code: int | None
    reqs: AccessRequirements


class LetterBehavior(IntEnum):
    VANILLA = auto()
    ITEM = auto()
    UNLOCKED = auto()


class Lingo2PlayerLogic:
    world: "Lingo2World"

    shuffled_maps: set[int]

    locations_by_room: dict[int, list[PlayerLocation]]
    event_loc_item_by_room: dict[int, dict[str, str]]

    item_by_door: dict[int, tuple[str, int]]

    panel_reqs: dict[int, AccessRequirements]
    proxy_reqs: dict[int, dict[str, AccessRequirements]]
    door_reqs: dict[int, AccessRequirements]

    real_items: list[str]

    double_letter_amount: dict[str, int]
    goal_room_id: int

    def __init__(self, world: "Lingo2World"):
        self.world = world
        self.locations_by_room = {}
        self.event_loc_item_by_room = {}
        self.item_by_door = {}
        self.panel_reqs = dict()
        self.proxy_reqs = dict()
        self.door_reqs = dict()
        self.real_items = list()
        self.double_letter_amount = dict()

        def should_shuffle_map(game_map) -> bool:
            if game_map.type == data_pb2.MapType.NORMAL_MAP:
                return True
            elif game_map.type == data_pb2.MapType.ICARUS:
                return bool(world.options.enable_icarus)
            elif game_map.type == data_pb2.MapType.GIFT_MAP:
                if game_map.name == "the_advanced":
                    return "The Advanced" in world.options.enable_gift_maps.value
                elif game_map.name == "the_charismatic":
                    return "The Charismatic" in world.options.enable_gift_maps.value
                elif game_map.name == "the_crystalline":
                    return "The Crystalline" in world.options.enable_gift_maps.value
                elif game_map.name == "the_stellar":
                    return "The Stellar" in world.options.enable_gift_maps.value

            return False

        self.shuffled_maps = set(game_map.id for game_map in world.static_logic.objects.maps
                                 if should_shuffle_map(game_map))

        maximum_masteries = 13 + len(world.options.enable_gift_maps.value)
        if world.options.enable_icarus:
            maximum_masteries += 1

        if world.options.masteries_requirement > maximum_masteries:
            world.options.masteries_requirement.value = maximum_masteries

        if self.world.options.shuffle_doors:
            for progressive in world.static_logic.objects.progressives:
                for i in range(0, len(progressive.doors)):
                    door = world.static_logic.objects.doors[progressive.doors[i]]
                    if door.map_id not in self.shuffled_maps:
                        continue

                    self.item_by_door[progressive.doors[i]] = (progressive.name, i + 1)
                    self.real_items.append(progressive.name)

        for door_group in world.static_logic.objects.door_groups:
            if door_group.type == data_pb2.DoorGroupType.CONNECTOR:
                if not self.world.options.shuffle_doors or self.world.options.shuffle_worldports:
                    continue
            elif door_group.type == data_pb2.DoorGroupType.COLOR_CONNECTOR:
                if not self.world.options.shuffle_control_center_colors or self.world.options.shuffle_worldports:
                    continue
            elif door_group.type == data_pb2.DoorGroupType.SHUFFLE_GROUP:
                if not self.world.options.shuffle_doors:
                    continue
            else:
                continue

            shuffleable_doors = [door_id for door_id in door_group.doors
                                 if world.static_logic.objects.doors[door_id].map_id in self.shuffled_maps]

            if len(shuffleable_doors) > 0:
                for door in shuffleable_doors:
                    self.item_by_door[door] = (door_group.name, 1)

                self.real_items.append(door_group.name)

        # We iterate through the doors in two parts because it is essential that we determine which doors are shuffled
        # before we calculate any access requirements.
        for door in world.static_logic.objects.doors:
            if door.map_id not in self.shuffled_maps:
                continue

            if door.type in [data_pb2.DoorType.EVENT, data_pb2.DoorType.LOCATION_ONLY, data_pb2.DoorType.GRAVESTONE]:
                continue

            if door.id in self.item_by_door:
                continue

            if (door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.ITEM_ONLY] and
                    not self.world.options.shuffle_doors):
                continue

            if (door.type == data_pb2.DoorType.CONTROL_CENTER_COLOR and
                    not self.world.options.shuffle_control_center_colors):
                continue

            if door.type == data_pb2.DoorType.GALLERY_PAINTING and not self.world.options.shuffle_gallery_paintings:
                continue

            door_item_name = self.world.static_logic.get_door_item_name(door)
            self.item_by_door[door.id] = (door_item_name, 1)
            self.real_items.append(door_item_name)

        # We handle cyan_door_behavior = Item after door shuffle, because cyan doors that are impacted by door shuffle
        # should be exempt from cyan_door_behavior.
        if world.options.cyan_door_behavior == CyanDoorBehavior.option_item:
            for door_group in world.static_logic.objects.door_groups:
                if door_group.type != data_pb2.DoorGroupType.CYAN_DOORS:
                    continue

                shuffleable_doors = [door_id for door_id in door_group.doors
                                     if world.static_logic.objects.doors[door_id].map_id in self.shuffled_maps
                                     and door_id not in self.item_by_door]

                if len(shuffleable_doors) > 0:
                    for door in shuffleable_doors:
                        self.item_by_door[door] = (door_group.name, 1)

                    self.real_items.append(door_group.name)

        for door in world.static_logic.objects.doors:
            if door.map_id not in self.shuffled_maps:
                continue

            if door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.LOCATION_ONLY, data_pb2.DoorType.GRAVESTONE]:
                self.locations_by_room.setdefault(door.room_id, []).append(PlayerLocation(door.ap_id,
                                                                                          self.get_door_reqs(door.id)))

        for letter in world.static_logic.objects.letters:
            if world.static_logic.get_room_object_map_id(letter) not in self.shuffled_maps:
                continue

            self.locations_by_room.setdefault(letter.room_id, []).append(PlayerLocation(letter.ap_id,
                                                                                        AccessRequirements()))
            behavior = self.get_letter_behavior(letter.key, letter.level2)
            if behavior == LetterBehavior.VANILLA:
                if not world.for_tracker:
                    letter_name = f"{letter.key.upper()}{'2' if letter.level2 else '1'}"
                    event_name = f"{letter_name} (Collected)"
                    self.event_loc_item_by_room.setdefault(letter.room_id, {})[event_name] = letter.key.upper()

                    if letter.level2:
                        event_name = f"{letter_name} (Double Collected)"
                        self.event_loc_item_by_room.setdefault(letter.room_id, {})[event_name] = letter.key.upper()
            elif behavior == LetterBehavior.ITEM:
                self.real_items.append(letter.key.upper())

            if behavior != LetterBehavior.UNLOCKED:
                self.double_letter_amount[letter.key.upper()] = self.double_letter_amount.get(letter.key.upper(), 0) + 1

        for mastery in world.static_logic.objects.masteries:
            if world.static_logic.get_room_object_map_id(mastery) not in self.shuffled_maps:
                continue

            self.locations_by_room.setdefault(mastery.room_id, []).append(PlayerLocation(mastery.ap_id,
                                                                                         AccessRequirements()))

            if world.options.masteries_requirement > 0:
                event_name = f"{world.static_logic.get_room_object_map_name(mastery)} - Mastery (Collected)"
                self.event_loc_item_by_room.setdefault(mastery.room_id, {})[event_name] = "Mastery"

        for ending in world.static_logic.objects.endings:
            if world.static_logic.get_room_object_map_id(ending) not in self.shuffled_maps:
                continue

            # Don't create a location for your selected ending. Also don't create a location for White Ending if it's
            # necessarily in the postgame, i.e. it requires all 12 other endings.
            if world.options.victory_condition.current_key.removesuffix("_ending").upper() != ending.name\
                    and (ending.name != "WHITE" or world.options.endings_requirement < 12):
                self.locations_by_room.setdefault(ending.room_id, []).append(PlayerLocation(ending.ap_id,
                                                                                            AccessRequirements()))

            event_name = f"{ending.name.capitalize()} Ending (Achieved)"
            item_name = "Ending"

            if world.options.victory_condition.current_key.removesuffix("_ending").upper() == ending.name:
                item_name = "Victory"
                self.goal_room_id = ending.room_id

            self.event_loc_item_by_room.setdefault(ending.room_id, {})[event_name] = item_name

        if self.world.options.keyholder_sanity:
            for keyholder in world.static_logic.objects.keyholders:
                if keyholder.HasField("key"):
                    if world.static_logic.get_room_object_map_id(keyholder) not in self.shuffled_maps:
                        continue

                    reqs = AccessRequirements()

                    if self.get_letter_behavior(keyholder.key, False) != LetterBehavior.UNLOCKED:
                        reqs.letters[keyholder.key.upper()] = 1

                    self.locations_by_room.setdefault(keyholder.room_id, []).append(PlayerLocation(keyholder.ap_id,
                                                                                                   reqs))

        if self.world.options.shuffle_symbols:
            for symbol_name in SYMBOL_ITEMS.values():
                self.real_items.append(symbol_name)

    def get_panel_reqs(self, panel_id: int, answer: str | None) -> AccessRequirements:
        if answer is None:
            if panel_id not in self.panel_reqs:
                self.panel_reqs[panel_id] = self.calculate_panel_reqs(panel_id, answer)

            return self.panel_reqs.get(panel_id)
        else:
            if panel_id not in self.proxy_reqs or answer not in self.proxy_reqs.get(panel_id):
                self.proxy_reqs.setdefault(panel_id, {})[answer] = self.calculate_panel_reqs(panel_id, answer)

            return self.proxy_reqs.get(panel_id).get(answer)

    def calculate_panel_reqs(self, panel_id: int, answer: str | None) -> AccessRequirements:
        panel = self.world.static_logic.objects.panels[panel_id]
        reqs = AccessRequirements()

        reqs.rooms.add(self.world.static_logic.get_room_region_name(panel.room_id))

        if answer is not None:
            self.add_solution_reqs(reqs, answer)
        elif len(panel.proxies) > 0:
            possibilities = []
            already_filled = False

            for proxy in panel.proxies:
                proxy_reqs = AccessRequirements()
                self.add_solution_reqs(proxy_reqs, proxy.answer)

                if not proxy_reqs.is_empty():
                    possibilities.append(proxy_reqs)
                else:
                    already_filled = True
                    break

            if not already_filled and not any(proxy.answer == panel.answer for proxy in panel.proxies):
                proxy_reqs = AccessRequirements()
                self.add_solution_reqs(proxy_reqs, panel.answer)

                if not proxy_reqs.is_empty():
                    possibilities.append(proxy_reqs)
                else:
                    already_filled = True

            if not already_filled:
                reqs.or_logic.append(possibilities)
        else:
            self.add_solution_reqs(reqs, panel.answer)

        if self.world.options.shuffle_symbols:
            for symbol in panel.symbols:
                reqs.items.add(SYMBOL_ITEMS.get(symbol))

        if panel.HasField("required_door"):
            door_reqs = self.get_door_open_reqs(panel.required_door)
            reqs.merge(door_reqs)

        if panel.HasField("required_room"):
            reqs.rooms.add(self.world.static_logic.get_room_region_name(panel.required_room))

        return reqs

    # This gets/calculates the requirements described by the door object. This is most notably used as the requirements
    # for clearing a location, or opening a door when the door is not shuffled.
    def get_door_reqs(self, door_id: int) -> AccessRequirements:
        if door_id not in self.door_reqs:
            self.door_reqs[door_id] = self.calculate_door_reqs(door_id)

        return self.door_reqs.get(door_id)

    def calculate_door_reqs(self, door_id: int) -> AccessRequirements:
        door = self.world.static_logic.objects.doors[door_id]
        reqs = AccessRequirements()

        if not door.HasField("complete_at") or door.complete_at == 0:
            for proxy in door.panels:
                panel_reqs = self.get_panel_reqs(proxy.panel, proxy.answer if proxy.HasField("answer") else None)
                reqs.merge(panel_reqs)
        elif door.complete_at == 1:
            disjunction = []
            for proxy in door.panels:
                proxy_reqs = self.get_panel_reqs(proxy.panel, proxy.answer if proxy.HasField("answer") else None)
                if proxy_reqs.is_empty():
                    disjunction.clear()
                    break
                else:
                    disjunction.append(proxy_reqs)
            if len(disjunction) > 0:
                reqs.or_logic.append(disjunction)
        else:
            reqs.complete_at = door.complete_at
            for proxy in door.panels:
                panel_reqs = self.get_panel_reqs(proxy.panel, proxy.answer if proxy.HasField("answer") else None)
                reqs.possibilities.append(panel_reqs)

        if door.HasField("control_center_color"):
            # TODO: Logic for ensuring two CC states aren't needed at once.
            reqs.rooms.add("Control Center - Main Area")
            self.add_solution_reqs(reqs, door.control_center_color)

        if door.double_letters:
            if self.world.options.cyan_door_behavior == CyanDoorBehavior.option_collect_h2:
                reqs.rooms.add("The Repetitive - Main Room")
            elif self.world.options.cyan_door_behavior == CyanDoorBehavior.option_any_double_letter:
                if self.world.options.shuffle_letters != ShuffleLetters.option_unlocked:
                    reqs.cyans = True
            elif self.world.options.cyan_door_behavior == CyanDoorBehavior.option_item:
                # There shouldn't be any locations that are cyan doors.
                pass

        for keyholder_uses in door.keyholders:
            key_name = keyholder_uses.key.upper()
            if (self.get_letter_behavior(keyholder_uses.key, False) != LetterBehavior.UNLOCKED
                    and key_name not in reqs.letters):
                reqs.letters[key_name] = 1

            keyholder = self.world.static_logic.objects.keyholders[keyholder_uses.keyholder]
            reqs.rooms.add(self.world.static_logic.get_room_region_name(keyholder.room_id))

        for room in door.rooms:
            reqs.rooms.add(self.world.static_logic.get_room_region_name(room))

        if door.white_ending:
            if self.world.options.endings_requirement > 0:
                reqs.progressives["Ending"] = self.world.options.endings_requirement.value

            if self.world.options.masteries_requirement > 0:
                reqs.progressives["Mastery"] = self.world.options.masteries_requirement.value

        for sub_door_id in door.doors:
            sub_reqs = self.get_door_open_reqs(sub_door_id)
            reqs.merge(sub_reqs)

        reqs.simplify()

        return reqs

    # This gets the requirements to open a door within the world. When a door is shuffled, this means having the item
    # that acts as the door's key.
    def get_door_open_reqs(self, door_id: int) -> AccessRequirements:
        if door_id in self.item_by_door:
            reqs = AccessRequirements()

            item_name, amount = self.item_by_door.get(door_id)
            if amount == 1:
                reqs.items.add(item_name)
            else:
                reqs.progressives[item_name] = amount

            return reqs
        else:
            return self.get_door_reqs(door_id)

    def get_letter_behavior(self, letter: str, level2: bool) -> LetterBehavior:
        if self.world.options.shuffle_letters == ShuffleLetters.option_unlocked:
            return LetterBehavior.UNLOCKED

        if self.world.options.shuffle_letters in [ShuffleLetters.option_vanilla_cyan, ShuffleLetters.option_item_cyan]:
            if level2:
                if self.world.options.shuffle_letters == ShuffleLetters.option_vanilla_cyan:
                    return LetterBehavior.VANILLA
                else:
                    return LetterBehavior.ITEM
            else:
                return LetterBehavior.UNLOCKED

        if not level2 and letter in ["h", "i", "n", "t"]:
            return LetterBehavior.UNLOCKED

        if self.world.options.shuffle_letters == ShuffleLetters.option_progressive:
            return LetterBehavior.ITEM

        return LetterBehavior.VANILLA

    def add_solution_reqs(self, reqs: AccessRequirements, solution: str):
        histogram = calculate_letter_histogram(solution)

        for l, a in histogram.items():
            needed = min(a, 2)
            level2 = (needed == 2)

            if level2 and self.get_letter_behavior(l.lower(), True) == LetterBehavior.UNLOCKED:
                needed = 1

            if self.get_letter_behavior(l.lower(), False) == LetterBehavior.UNLOCKED:
                needed = needed - 1

            if needed > 0:
                reqs.letters[l] = max(reqs.letters.get(l, 0), needed)