-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogic.py
942 lines (829 loc) · 19.8 KB
/
logic.py
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
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
"""
Functions used to describe Metroid: Zero Mission logic rules
"""
from __future__ import annotations
import builtins
import functools
from typing import TYPE_CHECKING, Any, Callable, NamedTuple
from BaseClasses import CollectionState
if TYPE_CHECKING:
from . import MZMWorld
class Requirement(NamedTuple):
rule: Callable[[MZMWorld, CollectionState], bool]
def create_rule(self, world: MZMWorld):
return functools.partial(self.rule, world)
@classmethod
def item(cls, item: str, count: int = 1):
return cls(lambda world, state: state.has(item, world.player, count))
@classmethod
def location(cls, location: str):
return cls(lambda world, state: state.can_reach_location(location, world.player))
@classmethod
def entrance(cls, entrance: str):
return cls(lambda world, state: state.can_reach_entrance(entrance, world.player))
@classmethod
def setting_enabled(cls, setting: str):
return cls(lambda world, _: getattr(world.options, setting))
@classmethod
def setting_is(cls, setting: str, value: Any):
return cls(lambda world, _: getattr(world.options, setting) == value)
@classmethod
def setting_atleast(cls, setting: str, value: int):
return cls(lambda world, _: getattr(world.options, setting) >= value)
def all(*args: Requirement):
return Requirement(lambda world, state: builtins.all(req.rule(world, state) for req in args))
def any(*args: Requirement):
return Requirement(lambda world, state: builtins.any(req.rule(world, state) for req in args))
Ziplines = Requirement.item("Ziplines Activated")
KraidBoss = Requirement.item("Kraid Defeated")
RidleyBoss = Requirement.item("Ridley Defeated")
MotherBrainBoss = Requirement.item("Mother Brain Defeated")
ChozoGhostBoss = Requirement.item("Chozo Ghost Defeated")
MechaRidleyBoss = Requirement.item("Mecha Ridley Defeated")
CanReachLocation = lambda n: Requirement.location(n)
CanReachEntrance = lambda n: Requirement.entrance(n)
UnknownItem1 = Requirement.location("Crateria Unknown Item Statue")
UnknownItem2 = Requirement.location("Kraid Unknown Item Statue")
UnknownItem3 = Requirement.location("Ridley Unknown Item Statue")
CanUseUnknownItems = any(
Requirement.setting_enabled("unknown_items_always_usable"),
ChozoGhostBoss,
)
LayoutPatches = Requirement.setting_enabled("layout_patches")
EnergyTanks = lambda n: Requirement.item("Energy Tank", n)
MissileTanks = lambda n: Requirement.item("Missile Tank", n)
SuperMissileTanks = lambda n: Requirement.item("Super Missile Tank", n)
PowerBombTanks = lambda n: Requirement.item("Power Bomb Tank", n)
LongBeam = Requirement.item("Long Beam")
ChargeBeam = Requirement.item("Charge Beam")
IceBeam = Requirement.item("Ice Beam")
WaveBeam = Requirement.item("Wave Beam")
PlasmaBeam = all(
Requirement.item("Plasma Beam"),
CanUseUnknownItems,
)
Bomb = Requirement.item("Bomb")
VariaSuit = Requirement.item("Varia Suit")
GravitySuit = all(
Requirement.item("Gravity Suit"),
CanUseUnknownItems
)
MorphBall = Requirement.item("Morph Ball")
SpeedBooster = Requirement.item("Speed Booster")
HiJump = Requirement.item("Hi-Jump")
ScrewAttack = Requirement.item("Screw Attack")
SpaceJump = all(
Requirement.item("Space Jump"),
CanUseUnknownItems
)
PowerGrip = Requirement.item("Power Grip")
Missiles = any(
MissileTanks(1),
SuperMissileTanks(1),
)
MissileCount = lambda n: Requirement(
# TODO: account for Hard
lambda world, state:
5 * state.count("Missile Tank", world.player) + 2 * state.count("Super Missile Tank", world.player) >= n
)
SuperMissiles = SuperMissileTanks(1)
PowerBombs = PowerBombTanks(1)
PowerBombCount = lambda n: PowerBombTanks(n // 2) # TODO: account for Hard
# Various morph/bomb rules
CanRegularBomb = all(
MorphBall,
Bomb
)
# Morph tunnels or bomb chains--any block that Screw Attack can't break
CanBombTunnelBlock = all(
MorphBall,
any(
Bomb,
PowerBombTanks(1),
),
)
CanSingleBombBlock = any(
CanBombTunnelBlock,
ScrewAttack
)
CanBallCannon = CanRegularBomb
CanBallspark = all(
MorphBall,
SpeedBooster,
HiJump,
)
CanBallJump = all(
MorphBall,
any(
Bomb,
HiJump
)
)
CanLongBeam = any(
LongBeam,
MissileCount(1),
CanBombTunnelBlock,
)
# Logic option rules
AdvancedLogic = Requirement.setting_atleast("logic_difficulty", 1)
CanIBJ = all(
Requirement.setting_atleast("ibj_in_logic", 1),
CanRegularBomb,
)
CanHorizontalIBJ = all(
CanIBJ,
Requirement.setting_atleast("ibj_in_logic", 2)
)
CanWallJump = Requirement.setting_atleast("walljumps_in_logic", 1)
CanTrickySparks = all(
Requirement.setting_enabled("tricky_shinesparks"),
SpeedBooster,
)
Hellrun = lambda n: all(
Requirement.setting_enabled("heatruns_lavadives"),
EnergyTanks(n),
)
# Miscellaneous rules
CanFly = any( # infinite vertical
CanIBJ,
SpaceJump
)
CanFlyWall = any( # infinite vertical with a usable wall
CanFly,
CanWallJump
)
CanVertical = any( # fka can_hj_sj_ibj_or_grip
HiJump,
PowerGrip,
CanFly
)
CanVerticalWall = any(
CanVertical,
CanWallJump
)
CanHiGrip = all(
HiJump,
PowerGrip
)
CanEnterHighMorphTunnel = any(
CanIBJ,
all(
MorphBall,
PowerGrip
)
)
CanEnterMediumMorphTunnel = any(
CanEnterHighMorphTunnel,
all(
MorphBall,
HiJump
)
)
ChozodiaCombat = all(
any(
IceBeam,
PlasmaBeam
),
EnergyTanks(4)
)
RuinsTestEscape = all(
any(
all(
AdvancedLogic,
CanHiGrip,
CanWallJump
),
CanIBJ,
Requirement.item("Space Jump") # Need SJ to escape, but it doesn't need to be active yet
),
CanEnterMediumMorphTunnel
)
# Goal
ReachedGoal = any(
all(
Requirement.setting_is("goal", 0)
),
all(
Requirement.setting_is("goal", 1),
MotherBrainBoss,
ChozoGhostBoss
),
)
# Regional connection requirements
# brinstar main to past-hives, top to past-hives is different
def brinstar_past_hives():
return all(
MorphBall,
Missiles,
any(
AdvancedLogic,
MissileCount(10),
SuperMissiles,
LongBeam,
IceBeam,
WaveBeam,
PlasmaBeam,
ScrewAttack
)
)
def brinstar_main_to_brinstar_top():
return any(
all(
CanSingleBombBlock,
CanBallJump
),
all(
AdvancedLogic,
IceBeam,
CanWallJump,
PowerBombs
) # truly cursed strat
)
def brinstar_pasthives_to_brinstar_top():
return all(
any(
CanFly,
all(
HiJump,
IceBeam,
CanWallJump
)
),
CanBallJump
)
# this works for now. it's kind of tricky, cause all you need just to get there is PBs and bombs,
# but to actually do anything (including get to ship) you need IBJ/speed/sj. it only checks for speed
# for now since the only thing you'd potentially need this entrance for is Landing Site Ballspark
# (this assumption changes if/when entrance/elevator rando happens)
def brinstar_crateria_ballcannon():
return all(
PowerBombs,
CanBallCannon,
CanVertical,
SpeedBooster
)
# used for the items in this area as well as determining whether the ziplines can be activated
def kraid_upper_right():
return all(
Missiles,
CanBallCannon,
any(
CanHorizontalIBJ,
PowerGrip,
all(
IceBeam,
CanBallJump
)
)
)
# access to lower kraid
def kraid_left_shaft_access():
return all(
any(
CanHorizontalIBJ,
PowerGrip,
HiJump
),
CanBallJump,
CanBombTunnelBlock,
any(
Ziplines,
SpaceJump,
all(
GravitySuit,
any(
CanTrickySparks,
CanIBJ
)
),
all( # Acid Worm Skip
AdvancedLogic,
PowerGrip
)
)
)
def kraid_left_shaft_to_bottom():
return UnknownItem2
def kraid_bottom_to_lower_norfair():
return all(
ScrewAttack,
PowerBombs,
Missiles,
MorphBall
)
def norfair_main_to_crateria():
return all(
MorphBall,
any(
CanLongBeam,
CanBallspark
),
any(
LayoutPatches,
CanEnterMediumMorphTunnel
)
)
def norfair_right_shaft_access():
return any(
CanVertical,
SpeedBooster
)
def norfair_upper_right_shaft():
return any(
CanVerticalWall,
IceBeam
)
def norfair_behind_ice_beam():
return all(
CanReachLocation("Norfair Ice Beam"),
any(
CanLongBeam,
WaveBeam
),
MorphBall,
any(
all(
PowerGrip,
any(
CanWallJump,
SpaceJump,
IceBeam
)
),
CanIBJ,
all(
IceBeam,
HiJump
)
)
)
def norfair_behind_ice_to_bottom():
return all(
Missiles,
CanBombTunnelBlock,
any(
PowerGrip,
CanHorizontalIBJ,
all(
IceBeam,
CanBallJump
)
),
any(
CanIBJ,
all(
AdvancedLogic,
PowerBombs,
HiJump
),
all(
PowerGrip,
any(
CanWallJump,
SpaceJump
)
)
)
)
def norfair_lower_right_shaft():
return any(
ScrewAttack,
all(
SpeedBooster,
any(
CanBallCannon,
# TODO: This does nothing. Figure out a way to make it do what you intended
CanReachEntrance("Norfair Right Shaft -> Lower Norfair")
)
)
)
def norfair_lower_right_shaft_to_lower_norfair():
return all(
Missiles,
CanBombTunnelBlock,
any(
SpaceJump,
CanWallJump,
all(
Bomb,
any(
PowerGrip,
CanHorizontalIBJ,
all(
AdvancedLogic,
SuperMissiles,
IceBeam
)
)
),
),
any(
VariaSuit,
Hellrun(6)
),
any(
SpaceJump,
CanHorizontalIBJ,
all(
CanSingleBombBlock,
SpeedBooster
)
)
)
def lower_norfair_to_screwattack():
return any(
CanTrickySparks,
all(
ScrewAttack,
any(
CanWallJump,
SpaceJump
)
),
all(
MissileCount(5),
any(
CanFlyWall,
all(
AdvancedLogic,
IceBeam,
HiJump
)
)
)
)
# This is necessary if your only way to the Screw Attack region is the ballcannon near the Ridley elevator
def screw_to_lower_norfair():
return any(
MissileCount(4),
ScrewAttack
)
def lower_norfair_to_kraid():
return all(
ScrewAttack,
PowerBombs,
Missiles,
any(
CanIBJ,
PowerGrip,
all(
HiJump,
IceBeam
),
all(
CanTrickySparks,
CanBallspark
)
)
)
# The two items in Lower Norfair behind the Super Missile door right under the Screw Attack area
def lower_norfair_to_spaceboost_room():
return all(
SuperMissiles,
any(
SpeedBooster,
Bomb,
PowerBombCount(2),
all(
WaveBeam,
LongBeam,
any(
PowerGrip,
all(
GravitySuit,
HiJump
)
)
)
),
CanVertical
)
def lower_norfair_to_bottom_norfair():
return all(
MissileCount(2),
SpeedBooster,
any(
VariaSuit,
Hellrun(1)
),
any(
WaveBeam,
CanTrickySparks
),
CanEnterMediumMorphTunnel
)
def bottom_norfair_to_lower_shaft():
return any(
all(
Missiles,
CanFlyWall,
any(
PowerGrip,
CanIBJ
)
),
all(
SpeedBooster,
AdvancedLogic
),
)
def bottom_norfair_to_ridley():
return any(
all(
MissileCount(6), # Covers the case where you only have Supers; 1 normal missile is enough from drops
any(
IceBeam,
AdvancedLogic
)
),
PowerBombs
)
def bottom_norfair_to_screw():
return all(
RidleyBoss,
SpeedBooster,
any(
CanBallCannon,
CanTrickySparks,
AdvancedLogic
),
any(
IceBeam,
CanVerticalWall
)
)
def ridley_main_to_left_shaft():
return all(
SuperMissiles,
any(
CanVerticalWall,
IceBeam
),
any(
VariaSuit,
Hellrun(1),
all(
CanFly,
CanBombTunnelBlock
)
),
MorphBall
)
# shortcut to the right of elevator
def ridley_main_to_right_shaft():
return all(
Missiles,
any(
CanIBJ,
all(
PowerGrip,
CanBombTunnelBlock,
any(
SpaceJump,
HiJump,
IceBeam
)
)
)
)
def ridley_left_shaft_to_sw_puzzle():
return all(
SpeedBooster,
CanVerticalWall
)
# The alcove to the right of the right shaft
def ridley_speed_puzzles_access():
return all(
SpeedBooster,
any(
CanVerticalWall,
IceBeam
)
)
# getting into the gap at the start of "ball room" and subsequently into the general area of ridley himself
def ridley_right_shaft_to_central():
return CanEnterMediumMorphTunnel
# Ridley, Unknown 3, and the item behind Unknown 3
def ridley_central_to_ridley_room():
return all(
any(
AdvancedLogic,
all(
MissileCount(40),
EnergyTanks(3),
)
),
any(
CanFly,
all(
IceBeam,
CanVerticalWall
)
)
)
def tourian_to_chozodia():
return all(
MotherBrainBoss,
RuinsTestEscape
)
# Getting to Unknown 1 and everything above
def crateria_main_to_crateria_upper():
return any(
CanBallJump,
all(
LayoutPatches,
CanFly
),
all(
AdvancedLogic,
ScrewAttack,
any(
SpaceJump,
all(
PowerBombs,
CanTrickySparks,
CanWallJump
)
)
)
)
# Upper Crateria door to Ruins, the two items right by it, and the Triple Crawling Pirates
def crateria_upper_to_chozo_ruins():
return all(
PowerBombs,
MorphBall,
Missiles,
any(
CanFly,
CanReachLocation("Crateria Northeast Corner")
),
any(
MotherBrainBoss,
Requirement.setting_is("chozodia_access", 0)
)
)
# Ruins to Chozo Ghost, the three items in that general area, and the lava dive item
def chozo_ruins_to_ruins_test():
return all(
MorphBall,
PowerBombs,
any(
Bomb,
PowerBombCount(3)
),
any(
AdvancedLogic,
ChozodiaCombat
),
RuinsTestEscape
)
def chozo_ruins_to_chozodia_tube():
return any(
all( # Getting up to the tube is doable with just walljumps but tricky enough to be advanced imo
AdvancedLogic,
CanWallJump
),
CanFly
)
# Specifically getting to the room with Crateria Upper Door location. Might need another empty region for region rando
def chozodia_tube_to_chozo_ruins():
return all(
any(
CanFlyWall,
CanHiGrip
),
CanBombTunnelBlock
)
def crateria_to_under_tube():
return all(
PowerBombs,
MorphBall,
any( # To get to the save station and warp out
SpeedBooster,
CanFlyWall,
CanHiGrip
),
any(
MotherBrainBoss,
Requirement.setting_is("chozodia_access", 0)
)
)
def under_tube_to_tube():
return any(
SpeedBooster,
all(
CanFly,
PowerBombs,
ChozoGhostBoss # Change if basepatch makes the tube breakable before Charlie
)
)
def under_tube_to_crateria():
return any(
CanIBJ,
all(
PowerGrip,
CanFlyWall
),
all(
CanTrickySparks,
CanBallspark
)
)
def tube_to_under_tube():
return all(
ChozoGhostBoss,
PowerBombs
)
def chozodia_tube_to_mothership_central():
return all(
any(
AdvancedLogic,
ChozodiaCombat
),
any(
CanFly,
all(
CanWallJump,
HiJump
)
)
)
def mothership_central_to_cockpit():
return all(
any(
Bomb,
PowerBombCount(2)
),
any(
ScrewAttack,
MissileCount(5)
),
any(
SuperMissiles,
PowerGrip,
CanFly
),
any(
AdvancedLogic,
EnergyTanks(6)
)
)
def cockpit_to_original_pb():
return all(
any(
CanWallJump,
HiJump,
PowerGrip,
SpaceJump
), # cannot IBJ to escape to cockpit
any(
CanIBJ,
all(
PowerGrip,
any(
CanFlyWall,
HiJump
)
),
all(
AdvancedLogic,
IceBeam,
CanBallJump
)
)
)
def cockpit_to_mecha_ridley():
return all(
CanBombTunnelBlock,
any(
CanIBJ,
PowerGrip,
all(
AdvancedLogic,
IceBeam,
HiJump
)
),
CanBallJump,
any(
PowerBombCount(2),
all(
Bomb,
PowerBombs
),
all(
AdvancedLogic,
any(
CanIBJ,
all(
PowerGrip,
any(
HiJump,
SpaceJump,
CanWallJump
)
)
)
)
)
)