forked from OoTRandomizer/OoT-Randomizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
World.py
1302 lines (1141 loc) · 75.7 KB
/
World.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
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from collections import OrderedDict
import copy
import logging
import random
import json
from Entrance import Entrance
from Goals import Goal, GoalCategory
from HintList import getRequiredHints, misc_item_hint_table, misc_location_hint_table
from Hints import HintArea, hint_dist_keys, HintDistFiles
from Item import ItemFactory, ItemInfo, MakeEventItem
from Location import Location, LocationFactory
from LocationList import business_scrubs, location_groups
from Plandomizer import InvalidFileException
from Region import Region, TimeOfDay
from RuleParser import Rule_AST_Transformer
from SettingsList import get_setting_info, get_settings_from_section
from State import State
from Utils import read_logic_file
class World(object):
def __init__(self, id, settings, resolveRandomizedSettings=True):
self.id = id
self.dungeons = []
self.regions = []
self.itempool = []
self._cached_locations = None
self._entrance_cache = {}
self._region_cache = {}
self._location_cache = {}
self.required_locations = []
self.shop_prices = {}
self.scrub_prices = {}
self.maximum_wallets = 0
self.hinted_dungeon_reward_locations = {}
self.misc_hint_item_locations = {}
self.misc_hint_location_items = {}
self.triforce_count = 0
self.total_starting_triforce_count = 0
self.bingosync_url = None
self.parser = Rule_AST_Transformer(self)
self.event_items = set()
# dump settings directly into world's namespace
# this gives the world an attribute for every setting listed in Settings.py
self.settings = settings
self.distribution = settings.distribution.world_dists[id]
# rename a few attributes...
self.keysanity = settings.shuffle_smallkeys in ['keysanity', 'remove', 'any_dungeon', 'overworld', 'regional']
self.check_beatable_only = settings.reachable_locations != 'all'
self.shuffle_special_interior_entrances = settings.shuffle_interior_entrances == 'all'
self.shuffle_interior_entrances = settings.shuffle_interior_entrances in ['simple', 'all']
self.shuffle_special_dungeon_entrances = settings.shuffle_dungeon_entrances == 'all'
self.shuffle_dungeon_entrances = settings.shuffle_dungeon_entrances in ['simple', 'all']
self.entrance_shuffle = (
self.shuffle_interior_entrances or settings.shuffle_grotto_entrances or self.shuffle_dungeon_entrances
or settings.shuffle_overworld_entrances or settings.owl_drops or settings.warp_songs
or settings.spawn_positions or (settings.shuffle_bosses != 'off')
)
self.ensure_tod_access = self.shuffle_interior_entrances or settings.shuffle_overworld_entrances or settings.spawn_positions
self.disable_trade_revert = self.shuffle_interior_entrances or settings.shuffle_overworld_entrances
if (
settings.open_forest == 'closed'
and (
self.shuffle_special_interior_entrances or settings.shuffle_overworld_entrances
or settings.warp_songs or settings.spawn_positions or (settings.shuffle_bosses != 'off')
)
):
self.settings.open_forest = 'closed_deku'
if settings.triforce_goal_per_world > settings.triforce_count_per_world:
raise ValueError("Triforces required cannot be more than the triforce count.")
self.triforce_goal = settings.triforce_goal_per_world * settings.world_count
if settings.triforce_hunt:
# Pin shuffle_ganon_bosskey to 'triforce' when triforce_hunt is enabled
# (specifically, for randomize_settings)
self.settings.shuffle_ganon_bosskey = 'triforce'
# trials that can be skipped will be decided later
self.skipped_trials = {
'Forest': False,
'Fire': False,
'Water': False,
'Spirit': False,
'Shadow': False,
'Light': False
}
# empty dungeons will be decided later
class EmptyDungeons(dict):
class EmptyDungeonInfo:
def __init__(self, boss_name):
self.empty = False
self.boss_name = boss_name
self.hint_name = None
def __init__(self):
super().__init__()
self['Deku Tree'] = self.EmptyDungeonInfo('Queen Gohma')
self['Dodongos Cavern'] = self.EmptyDungeonInfo('King Dodongo')
self['Jabu Jabus Belly'] = self.EmptyDungeonInfo('Barinade')
self['Forest Temple'] = self.EmptyDungeonInfo('Phantom Ganon')
self['Fire Temple'] = self.EmptyDungeonInfo('Volvagia')
self['Water Temple'] = self.EmptyDungeonInfo('Morpha')
self['Spirit Temple'] = self.EmptyDungeonInfo('Twinrova')
self['Shadow Temple'] = self.EmptyDungeonInfo('Bongo Bongo')
for area in HintArea:
if area.is_dungeon and area.dungeon_name in self:
self[area.dungeon_name].hint_name = area
def __missing__(self, dungeon_name):
return self.EmptyDungeonInfo(None)
self.empty_dungeons = EmptyDungeons()
# dungeon forms will be decided later
self.dungeon_mq = {
'Deku Tree': False,
'Dodongos Cavern': False,
'Jabu Jabus Belly': False,
'Bottom of the Well': False,
'Ice Cavern': False,
'Gerudo Training Ground': False,
'Forest Temple': False,
'Fire Temple': False,
'Water Temple': False,
'Spirit Temple': False,
'Shadow Temple': False,
'Ganons Castle': False
}
if resolveRandomizedSettings:
self.resolve_random_settings()
if len(settings.hint_dist_user) == 0:
for d in HintDistFiles():
with open(d, 'r') as dist_file:
dist = json.load(dist_file)
if dist['name'] == self.settings.hint_dist:
self.hint_dist_user = dist
else:
self.settings.hint_dist = 'custom'
self.hint_dist_user = self.settings.hint_dist_user
# Hack for legacy hint distributions from before the goal, dual and dual_always hint
# types was created. Keeps validation happy.
for hint_type in ('goal', 'dual', 'dual_always', 'entrance_always'):
if 'distribution' in self.hint_dist_user and hint_type not in self.hint_dist_user['distribution']:
self.hint_dist_user['distribution'][hint_type] = {"order": 0, "weight": 0.0, "fixed": 0, "copies": 0}
if 'use_default_goals' not in self.hint_dist_user:
self.hint_dist_user['use_default_goals'] = True
if 'upgrade_hints' not in self.hint_dist_user:
self.hint_dist_user['upgrade_hints'] = 'off'
# Validate hint distribution format
# Originally built when I was just adding the type distributions
# Location/Item Additions and Overrides are not validated
hint_dist_valid = False
if all(key in self.hint_dist_user['distribution'] for key in hint_dist_keys):
hint_dist_valid = True
sub_keys = {'order', 'weight', 'fixed', 'copies'}
for key in self.hint_dist_user['distribution']:
if not all(sub_key in sub_keys for sub_key in self.hint_dist_user['distribution'][key]):
hint_dist_valid = False
if not hint_dist_valid:
raise InvalidFileException("""Hint distributions require all hint types be present in the distro
(trial, always, dual_always, woth, barren, item, song, overworld, dungeon, entrance,
sometimes, dual, random, junk, named-item, goal). If a hint type should not be
shuffled, set its order to 0. Hint type format is \"type\": {
\"order\": 0, \"weight\": 0.0, \"fixed\": 0, \"copies\": 0 }""")
self.added_hint_types = {}
self.item_added_hint_types = {}
self.hint_exclusions = set()
if settings.shuffle_child_trade == 'skip_child_zelda':
self.hint_exclusions.add('Song from Impa')
self.hint_type_overrides = {}
self.item_hint_type_overrides = {}
for dist in hint_dist_keys:
self.added_hint_types[dist] = []
for loc in self.hint_dist_user['add_locations']:
if 'types' in loc:
if dist in loc['types']:
self.added_hint_types[dist].append(loc['location'])
self.item_added_hint_types[dist] = []
for i in self.hint_dist_user['add_items']:
if dist in i['types']:
self.item_added_hint_types[dist].append(i['item'])
self.hint_type_overrides[dist] = []
for loc in self.hint_dist_user['remove_locations']:
if dist in loc['types']:
self.hint_type_overrides[dist].append(loc['location'])
self.item_hint_type_overrides[dist] = []
for i in self.hint_dist_user['remove_items']:
if dist in i['types']:
self.item_hint_type_overrides[dist].append(i['item'])
# Make empty dungeons non-hintable as barren dungeons
if settings.empty_dungeons_mode != 'none':
for info in self.empty_dungeons.values():
if info.empty:
self.hint_type_overrides['barren'].append(info.hint_name)
self.hint_text_overrides = {}
for loc in self.hint_dist_user['add_locations']:
if 'text' in loc:
# Arbitrarily throw an error at 80 characters to prevent overfilling the text box.
if len(loc['text']) > 80:
raise Exception('Custom hint text too large for %s', loc['location'])
self.hint_text_overrides.update({loc['location']: loc['text']})
self.item_hints = self.settings.item_hints + self.item_added_hint_types["named-item"]
self.named_item_pool = list(self.item_hints)
self.always_hints = [hint.name for hint in getRequiredHints(self)]
self.dungeon_rewards_hinted = 'altar' in settings.misc_hints or settings.enhance_map_compass
self.misc_hint_items = {hint_type: self.hint_dist_user.get('misc_hint_items', {}).get(hint_type, data['default_item']) for hint_type, data in misc_item_hint_table.items()}
self.misc_hint_locations = {hint_type: self.hint_dist_user.get('misc_hint_locations', {}).get(hint_type, data['item_location']) for hint_type, data in misc_location_hint_table.items()}
self.state = State(self)
# Allows us to cut down on checking whether some items are required
self.max_progressions = {name: item.special.get('progressive', 1) for name, item in ItemInfo.items.items()}
max_tokens = 0
if self.settings.bridge == 'tokens':
max_tokens = max(max_tokens, self.settings.bridge_tokens)
if self.settings.lacs_condition == 'tokens':
max_tokens = max(max_tokens, self.settings.lacs_tokens)
if self.settings.shuffle_ganon_bosskey == 'tokens':
max_tokens = max(max_tokens, self.settings.ganon_bosskey_tokens)
tokens = [50, 40, 30, 20, 10]
for t in tokens:
if f'Kak {t} Gold Skulltula Reward' not in self.settings.disabled_locations:
max_tokens = max(max_tokens, t)
break
self.max_progressions['Gold Skulltula Token'] = max_tokens
max_hearts = 0
if self.settings.bridge == 'hearts':
max_hearts = max(max_hearts, self.settings.bridge_hearts)
if self.settings.lacs_condition == 'hearts':
max_hearts = max(max_hearts, self.settings.lacs_hearts)
if self.settings.shuffle_ganon_bosskey == 'hearts':
max_hearts = max(max_hearts, self.settings.ganon_bosskey_hearts)
self.max_progressions['Heart Container'] = max_hearts
self.max_progressions['Piece of Heart'] = max_hearts * 4
self.max_progressions['Piece of Heart (Treasure Chest Game)'] = max_hearts * 4
# Additional Ruto's Letter become Bottle, so we may have to collect two.
self.max_progressions['Rutos Letter'] = 2
# Available Gold Skulltula Tokens in world. Set to proper value in ItemPool.py.
self.available_tokens = 100
# Disable goal hints if the hint distro does not require them.
# WOTH locations are always searched.
self.enable_goal_hints = False
if ('distribution' in self.hint_dist_user and
'goal' in self.hint_dist_user['distribution'] and
(self.hint_dist_user['distribution']['goal']['fixed'] != 0 or
self.hint_dist_user['distribution']['goal']['weight'] != 0)):
self.enable_goal_hints = True
# Initialize default goals for win condition
self.goal_categories = OrderedDict()
if self.hint_dist_user['use_default_goals']:
self.set_goals()
# import goals from hint plando
if 'custom_goals' in self.hint_dist_user:
for category in self.hint_dist_user['custom_goals']:
if category['category'] in self.goal_categories:
cat = self.goal_categories[category['category']]
else:
cat = GoalCategory(category['category'], category['priority'], minimum_goals=category['minimum_goals'])
for goal in category['goals']:
cat.add_goal(Goal(self, goal['name'], goal['hint_text'], goal['color'], items=list({'name': i['name'], 'quantity': i['quantity'], 'minimum': i['minimum'], 'hintable': i['hintable']} for i in goal['items'])))
if 'count_override' in category:
cat.goal_count = category['count_override']
else:
cat.goal_count = len(cat.goals)
if 'lock_entrances' in category:
cat.lock_entrances = list(category['lock_entrances'])
self.goal_categories[cat.name] = cat
# Sort goal hint categories by priority
# For most settings this will be Bridge, GBK
self.goal_categories = OrderedDict(sorted(self.goal_categories.items(), key=lambda kv: kv[1].priority))
# Turn on one hint per goal if all goal categories contain the same goals.
# Reduces the changes of randomly choosing one smaller category over and
# over again after the first round through the categories.
if len(self.goal_categories) > 0:
self.one_hint_per_goal = True
goal_list1 = [goal.name for goal in list(self.goal_categories.values())[0].goals]
for category in self.goal_categories.values():
if goal_list1 != [goal.name for goal in category.goals]:
self.one_hint_per_goal = False
# initialize category check for first rounds of goal hints
self.hinted_categories = []
# Quick item lookup for All Goals Reachable setting
self.goal_items = []
for cat_name, category in self.goal_categories.items():
for goal in category.goals:
for item in goal.items:
self.goal_items.append(item['name'])
# Separate goal categories into locked and unlocked for search optimization
self.locked_goal_categories = dict(filter(lambda category: category[1].lock_entrances, self.goal_categories.items()))
self.unlocked_goal_categories = dict(filter(lambda category: not category[1].lock_entrances, self.goal_categories.items()))
def copy(self):
new_world = World(self.id, self.settings, False)
new_world.skipped_trials = copy.copy(self.skipped_trials)
new_world.dungeon_mq = copy.copy(self.dungeon_mq)
new_world.empty_dungeons = copy.copy(self.empty_dungeons)
new_world.shop_prices = copy.copy(self.shop_prices)
new_world.triforce_goal = self.triforce_goal
new_world.triforce_count = self.triforce_count
new_world.total_starting_triforce_count = self.total_starting_triforce_count
new_world.maximum_wallets = self.maximum_wallets
new_world.distribution = self.distribution
new_world.regions = [region.copy(new_world) for region in self.regions]
for region in new_world.regions:
for exit in region.exits:
exit.connect(new_world.get_region(exit.connected_region))
new_world.dungeons = [dungeon.copy(new_world) for dungeon in self.dungeons]
new_world.itempool = [item.copy(new_world) for item in self.itempool]
new_world.state = self.state.copy(new_world)
# copy any randomized settings to match the original copy
new_world.randomized_list = list(self.randomized_list)
for randomized_item in new_world.randomized_list:
setattr(new_world, randomized_item, getattr(self.settings, randomized_item))
new_world.always_hints = list(self.always_hints)
new_world.max_progressions = copy.copy(self.max_progressions)
new_world.available_tokens = self.available_tokens
return new_world
def set_random_bridge_values(self):
if self.settings.bridge == 'medallions':
self.settings.bridge_medallions = 6
self.randomized_list.append('bridge_medallions')
if self.settings.bridge == 'dungeons':
self.settings.bridge_rewards = 9
self.randomized_list.append('bridge_rewards')
if self.settings.bridge == 'stones':
self.settings.bridge_stones = 3
self.randomized_list.append('bridge_stones')
def resolve_random_settings(self):
# evaluate settings (important for logic, nice for spoiler)
self.randomized_list = []
dist_keys = []
if '_settings' in self.distribution.distribution.src_dict:
dist_keys = self.distribution.distribution.src_dict['_settings'].keys()
if self.settings.randomize_settings:
setting_info = get_setting_info('randomize_settings')
self.randomized_list.extend(setting_info.disable[True]['settings'])
for section in setting_info.disable[True]['sections']:
self.randomized_list.extend(get_settings_from_section(section))
# Remove settings specified in the distribution
self.randomized_list = [x for x in self.randomized_list if x not in dist_keys]
for setting in list(self.randomized_list):
if (setting == 'bridge_medallions' and self.settings.bridge != 'medallions') \
or (setting == 'bridge_stones' and self.settings.bridge != 'stones') \
or (setting == 'bridge_rewards' and self.settings.bridge != 'dungeons') \
or (setting == 'bridge_tokens' and self.settings.bridge != 'tokens') \
or (setting == 'bridge_hearts' and self.settings.bridge != 'hearts') \
or (setting == 'lacs_medallions' and self.settings.lacs_condition != 'medallions') \
or (setting == 'lacs_stones' and self.settings.lacs_condition != 'stones') \
or (setting == 'lacs_rewards' and self.settings.lacs_condition != 'dungeons') \
or (setting == 'lacs_tokens' and self.settings.lacs_condition != 'tokens') \
or (setting == 'lacs_hearts' and self.settings.lacs_condition != 'hearts') \
or (setting == 'ganon_bosskey_medallions' and self.settings.shuffle_ganon_bosskey != 'medallions') \
or (setting == 'ganon_bosskey_stones' and self.settings.shuffle_ganon_bosskey != 'stones') \
or (setting == 'ganon_bosskey_rewards' and self.settings.shuffle_ganon_bosskey != 'dungeons') \
or (setting == 'ganon_bosskey_tokens' and self.settings.shuffle_ganon_bosskey != 'tokens') \
or (setting == 'ganon_bosskey_hearts' and self.settings.shuffle_ganon_bosskey != 'hearts'):
self.randomized_list.remove(setting)
if self.settings.big_poe_count_random and 'big_poe_count' not in dist_keys:
self.settings.big_poe_count = random.randint(1, 10)
self.randomized_list.append('big_poe_count')
# If set to random in GUI, we don't want to randomize if it was specified as non-random in the distribution
if (self.settings.starting_tod == 'random'
and ('starting_tod' not in dist_keys
or self.distribution.distribution.src_dict['_settings']['starting_tod'] == 'random')):
setting_info = get_setting_info('starting_tod')
choices = [ch for ch in setting_info.choices if ch not in ['default', 'random']]
self.settings.starting_tod = random.choice(choices)
self.randomized_list.append('starting_tod')
if (self.settings.starting_age == 'random'
and ('starting_age' not in dist_keys
or self.distribution.distribution.src_dict['_settings']['starting_age'] == 'random')):
if self.settings.open_forest == 'closed':
# adult is not compatible
self.settings.starting_age = 'child'
else:
self.settings.starting_age = random.choice(['child', 'adult'])
self.randomized_list.append('starting_age')
if self.settings.chicken_count_random and 'chicken_count' not in dist_keys:
self.settings.chicken_count = random.randint(0, 7)
self.randomized_list.append('chicken_count')
# Determine dungeons with shortcuts
dungeons = ['Deku Tree', 'Dodongos Cavern', 'Jabu Jabus Belly', 'Forest Temple', 'Fire Temple', 'Water Temple', 'Shadow Temple', 'Spirit Temple']
if (self.settings.dungeon_shortcuts_choice == 'random'):
self.settings.dungeon_shortcuts = random.sample(dungeons, random.randint(0, len(dungeons)))
self.randomized_list.append('dungeon_shortcuts')
elif (self.settings.dungeon_shortcuts_choice == 'all'):
self.settings.dungeon_shortcuts = dungeons
# Determine area with keyring
if (self.settings.key_rings_choice == 'random'):
areas = ['Thieves Hideout', 'Forest Temple', 'Fire Temple', 'Water Temple', 'Shadow Temple', 'Spirit Temple', 'Bottom of the Well', 'Gerudo Training Ground', 'Ganons Castle']
self.settings.key_rings = random.sample(areas, random.randint(0, len(areas)))
self.randomized_list.append('key_rings')
elif (self.settings.key_rings_choice == 'all'):
self.settings.key_rings = ['Thieves Hideout', 'Forest Temple', 'Fire Temple', 'Water Temple', 'Shadow Temple', 'Spirit Temple', 'Bottom of the Well', 'Gerudo Training Ground', 'Ganons Castle']
# Handle random Rainbow Bridge condition
if (self.settings.bridge == 'random'
and ('bridge' not in dist_keys
or self.distribution.distribution.src_dict['_settings']['bridge'] == 'random')):
possible_bridge_requirements = ["open", "medallions", "dungeons", "stones", "vanilla"]
self.settings.bridge = random.choice(possible_bridge_requirements)
self.set_random_bridge_values()
self.randomized_list.append('bridge')
# Determine Ganon Trials
trial_pool = list(self.skipped_trials)
dist_chosen = self.distribution.configure_trials(trial_pool)
dist_num_chosen = len(dist_chosen)
if self.settings.trials_random and 'trials' not in dist_keys:
self.settings.trials = dist_num_chosen + random.randint(0, len(trial_pool))
self.randomized_list.append('trials')
num_trials = int(self.settings.trials)
if num_trials < dist_num_chosen:
raise RuntimeError("%d trials set to active on world %d, but only %d active trials allowed." % (dist_num_chosen, self.id, num_trials))
chosen_trials = random.sample(trial_pool, num_trials - dist_num_chosen)
for trial in self.skipped_trials:
if trial not in chosen_trials and trial not in dist_chosen:
self.skipped_trials[trial] = True
# Determine empty and MQ Dungeons (avoid having both empty & MQ dungeons unless necessary)
mq_dungeon_pool = list(self.dungeon_mq)
empty_dungeon_pool = list(self.empty_dungeons)
dist_num_mq, dist_num_empty = self.distribution.configure_dungeons(self, mq_dungeon_pool, empty_dungeon_pool)
if self.settings.empty_dungeons_mode == 'specific':
for dung in self.settings.empty_dungeons_specific:
self.empty_dungeons[dung].empty = True
if self.settings.mq_dungeons_mode == 'specific':
for dung in self.settings.mq_dungeons_specific:
self.dungeon_mq[dung] = True
if self.settings.empty_dungeons_mode == 'count':
nb_to_pick = self.settings.empty_dungeons_count - dist_num_empty
if nb_to_pick < 0:
raise RuntimeError(f"{dist_num_empty} dungeons are set to empty on world {self.id+1}, but only {self.settings.empty_dungeons_count} empty dungeons allowed")
if len(empty_dungeon_pool) < nb_to_pick:
non_empty = 8 - dist_num_empty - len(empty_dungeon_pool)
raise RuntimeError(f"On world {self.id+1}, {dist_num_empty} dungeons are set to empty and {non_empty} to non-empty. Can't reach {self.settings.empty_dungeons_count} empty dungeons.")
# Prioritize non-MQ dungeons
non_mq, mq = [], []
for dung in empty_dungeon_pool:
(mq if self.dungeon_mq[dung] else non_mq).append(dung)
for dung in random.sample(non_mq, min(nb_to_pick, len(non_mq))):
self.empty_dungeons[dung].empty = True
nb_to_pick -= 1
if nb_to_pick > 0:
for dung in random.sample(mq, nb_to_pick):
self.empty_dungeons[dung].empty = True
if self.settings.mq_dungeons_mode == 'random' and 'mq_dungeons_count' not in dist_keys:
for dungeon in mq_dungeon_pool:
self.dungeon_mq[dungeon] = random.choice([True, False])
self.randomized_list.append('mq_dungeons_count')
elif self.settings.mq_dungeons_mode in ['mq', 'vanilla']:
for dung in self.dungeon_mq.keys():
self.dungeon_mq[dung] = (self.settings.mq_dungeons_mode == 'mq')
elif self.settings.mq_dungeons_mode != 'specific':
nb_to_pick = self.settings.mq_dungeons_count - dist_num_mq
if nb_to_pick < 0:
raise RuntimeError("%d dungeons are set to MQ on world %d, but only %d MQ dungeons allowed." % (dist_num_mq, self.id+1, self.settings.mq_dungeons_count))
if len(mq_dungeon_pool) < nb_to_pick:
non_mq = 8 - dist_num_mq - len(mq_dungeon_pool)
raise RuntimeError(f"On world {self.id+1}, {dist_num_mq} dungeons are set to MQ and {non_mq} to non-MQ. Can't reach {self.settings.mq_dungeons_count} MQ dungeons.")
# Prioritize non-empty dungeons
non_empty, empty = [], []
for dung in mq_dungeon_pool:
(empty if self.empty_dungeons[dung].empty else non_empty).append(dung)
for dung in random.sample(non_empty, min(nb_to_pick, len(non_empty))):
self.dungeon_mq[dung] = True
nb_to_pick -= 1
if nb_to_pick > 0:
for dung in random.sample(empty, nb_to_pick):
self.dungeon_mq[dung] = True
self.settings.mq_dungeons_count = list(self.dungeon_mq.values()).count(True)
self.distribution.configure_randomized_settings(self)
def load_regions_from_json(self, file_path):
region_json = read_logic_file(file_path)
for region in region_json:
new_region = Region(region['region_name'])
new_region.world = self
if 'scene' in region:
new_region.scene = region['scene']
if 'hint' in region:
new_region.hint_name = region['hint']
if 'alt_hint' in region:
new_region.alt_hint_name = region['alt_hint']
if 'dungeon' in region:
new_region.dungeon = region['dungeon']
if 'is_boss_room' in region:
new_region.is_boss_room = region['is_boss_room']
if 'time_passes' in region:
new_region.time_passes = region['time_passes']
new_region.provides_time = TimeOfDay.ALL
if new_region.name == 'Ganons Castle Grounds':
new_region.provides_time = TimeOfDay.DAMPE
if 'locations' in region:
for location, rule in region['locations'].items():
new_location = LocationFactory(location)
new_location.parent_region = new_region
new_location.rule_string = rule
if self.settings.logic_rules != 'none':
self.parser.parse_spot_rule(new_location)
if new_location.never:
# We still need to fill the location even if ALR is off.
logging.getLogger('').debug('Unreachable location: %s', new_location.name)
new_location.world = self
new_region.locations.append(new_location)
if 'events' in region:
for event, rule in region['events'].items():
# Allow duplicate placement of events
lname = '%s from %s' % (event, new_region.name)
new_location = Location(lname, type='Event', parent=new_region)
new_location.rule_string = rule
if self.settings.logic_rules != 'none':
self.parser.parse_spot_rule(new_location)
if new_location.never:
logging.getLogger('').debug('Dropping unreachable event: %s', new_location.name)
else:
new_location.world = self
new_region.locations.append(new_location)
MakeEventItem(event, new_location)
if 'exits' in region:
for exit, rule in region['exits'].items():
new_exit = Entrance('%s -> %s' % (new_region.name, exit), new_region)
new_exit.connected_region = exit
new_exit.rule_string = rule
if self.settings.logic_rules != 'none':
self.parser.parse_spot_rule(new_exit)
new_region.exits.append(new_exit)
self.regions.append(new_region)
def create_internal_locations(self):
self.parser.create_delayed_rules()
assert self.parser.events <= self.event_items, 'Parse error: undefined items %r' % (self.parser.events - self.event_items)
def initialize_entrances(self):
for region in self.regions:
for exit in region.exits:
exit.connect(self.get_region(exit.connected_region))
exit.world = self
def initialize_regions(self):
for region in self.regions:
region.world = self
for location in region.locations:
location.world = self
def initialize_items(self):
for item in self.itempool:
item.world = self
if self.settings.shuffle_hideoutkeys in ['fortress', 'regional'] and item.type == 'HideoutSmallKey':
item.priority = True
for region in self.regions:
for location in region.locations:
if location.item != None:
location.item.world = self
for item in [item for dungeon in self.dungeons for item in dungeon.all_items]:
item.world = self
def random_shop_prices(self):
shop_item_indexes = ['7', '5', '8', '6']
self.shop_prices = {}
for region in self.regions:
if self.settings.shopsanity == 'random':
shop_item_count = random.randint(0,4)
else:
shop_item_count = int(self.settings.shopsanity)
for location in region.locations:
if location.type == 'Shop':
if location.name[-1:] in shop_item_indexes[:shop_item_count]:
if self.settings.shopsanity_prices == 'random':
self.shop_prices[location.name] = int(random.betavariate(1.5, 2) * 60) * 5
elif self.settings.shopsanity_prices == 'random_starting':
self.shop_prices[location.name] = random.randrange(0,100,5)
elif self.settings.shopsanity_prices == 'random_adult':
self.shop_prices[location.name] = random.randrange(0,201,5)
elif self.settings.shopsanity_prices == 'random_giant':
self.shop_prices[location.name] = random.randrange(0,501,5)
elif self.settings.shopsanity_prices == 'random_tycoon':
self.shop_prices[location.name] = random.randrange(0,1000,5)
elif self.settings.shopsanity_prices == 'affordable':
self.shop_prices[location.name] = 10
def set_scrub_prices(self):
# Get Deku Scrub Locations
scrub_locations = [location for location in self.get_locations() if location.type in ['Scrub', 'GrottoScrub']]
scrub_dictionary = {}
for location in scrub_locations:
if location.default not in scrub_dictionary:
scrub_dictionary[location.default] = []
scrub_dictionary[location.default].append(location)
# Loop through each type of scrub.
for (scrub_item, default_price, text_id, text_replacement) in business_scrubs:
price = default_price
if self.settings.shuffle_scrubs == 'low':
price = 10
elif self.settings.shuffle_scrubs == 'random':
# this is a random value between 0-99
# average value is ~33 rupees
price = int(random.betavariate(1, 2) * 99)
# Set price in the dictionary as well as the location.
self.scrub_prices[scrub_item] = price
if scrub_item in scrub_dictionary:
for location in scrub_dictionary[scrub_item]:
location.price = price
if location.item is not None:
location.item.price = price
rewardlist = (
'Kokiri Emerald',
'Goron Ruby',
'Zora Sapphire',
'Forest Medallion',
'Fire Medallion',
'Water Medallion',
'Spirit Medallion',
'Shadow Medallion',
'Light Medallion'
)
def fill_bosses(self, bossCount=9):
boss_rewards = ItemFactory(self.rewardlist, self)
boss_locations = [self.get_location(loc) for loc in location_groups['Boss']]
placed_prizes = [loc.item.name for loc in boss_locations if loc.item is not None]
unplaced_prizes = [item for item in boss_rewards if item.name not in placed_prizes]
empty_boss_locations = [loc for loc in boss_locations if loc.item is None]
prizepool = list(unplaced_prizes)
prize_locs = list(empty_boss_locations)
bossCount -= self.distribution.fill_bosses(self, prize_locs, prizepool)
while bossCount:
bossCount -= 1
random.shuffle(prizepool)
random.shuffle(prize_locs)
item = prizepool.pop()
loc = prize_locs.pop()
self.push_item(loc, item)
def set_goals(self):
# Default goals are divided into 3 primary categories:
# Bridge, Ganon's Boss Key, and Trials
# The Triforce Hunt goal is mutually exclusive with
# these categories given the vastly different playstyle.
#
# Goal priorities determine where hintable locations are placed.
# For example, an item required for both trials and bridge would
# be hinted only for bridge. This accomplishes two objectives:
# 1) Locations are not double counted for different stages
# of the game
# 2) Later category location lists are not diluted by early
# to mid game locations
#
# Entrance locks set restrictions on all goals in a category to
# ensure unreachable goals are not hintable. This is only used
# for the Rainbow Bridge to filter out goals hard-locked by
# Inside Ganon's Castle access.
#
# Minimum goals for a category tell the randomizer if the
# category meta-goal is satisfied by starting items. This
# is straightforward for dungeon reward goals where X rewards
# is the same as the minimum goals. For Triforce Hunt, Trials,
# and Skull conditions, there is only one goal in the category
# requesting X copies within the goal, so minimum goals has to
# be 1 for these.
b = GoalCategory('rainbow_bridge', 10, lock_entrances=['Ganons Castle Grounds -> Ganons Castle Lobby'])
gbk = GoalCategory('ganon_bosskey', 20)
trials = GoalCategory('trials', 30, minimum_goals=1)
th = GoalCategory('triforce_hunt', 30, goal_count=round(self.settings.triforce_goal_per_world / 10), minimum_goals=1)
trial_goal = Goal(self, 'the Tower', 'path to #the Tower#', 'White', items=[], create_empty=True)
if self.settings.triforce_hunt and self.settings.triforce_goal_per_world > 0:
# "Hintable" value of False means the goal items themselves cannot
# be hinted directly. This is used for Triforce Hunt and Skull
# conditions to restrict hints to useful items instead of the win
# condition. Dungeon rewards do not need this restriction as they are
# already unhintable at a lower level.
#
# This restriction does NOT apply to Light Arrows or Ganon's Castle Boss
# Key, which makes these items directly hintable in their respective goals
# assuming they do not get hinted by another hint type (always, woth with
# an earlier order in the hint distro, etc).
th.add_goal(Goal(self, 'gold', 'path of #gold#', 'Yellow', items=[{'name': 'Triforce Piece', 'quantity': self.settings.triforce_count_per_world, 'minimum': self.settings.triforce_goal_per_world, 'hintable': False}]))
self.goal_categories[th.name] = th
# Category goals are defined for each possible setting for each category.
# Bridge can be Stones, Medallions, Dungeons, Skulls, or Vanilla.
# Ganon's Boss Key can be Stones, Medallions, Dungeons, Skulls, LACS or
# one of the keysanity variants.
# Trials is one goal that is only on if at least one trial is on in the world.
# If there are no win conditions beyond Kill Ganon (open bridge, GBK removed,
# no trials), a fallback "path of the hero" clone of WOTH is created. Path
# wording is used to distinguish the hint type even though the hintable location
# set is identical to WOTH.
if not self.settings.triforce_hunt:
# Bridge goals will always be defined as they have the most immediate priority
if self.settings.bridge != 'open' and not self.shuffle_special_dungeon_entrances:
# "Replace" hint text dictionaries are used to reference the
# dungeon boss holding the specified reward. Only boss names/paths
# are defined for this feature, and it is not extendable via plando.
# Goal hint text colors are based on the dungeon reward, not the boss.
if ((self.settings.bridge_stones > 0 and self.settings.bridge == 'stones') or (self.settings.bridge_rewards > 0 and self.settings.bridge == 'dungeons')):
b.add_goal(Goal(self, 'Kokiri Emerald', { 'replace': 'Kokiri Emerald' }, 'Light Blue', items=[{'name': 'Kokiri Emerald', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
b.add_goal(Goal(self, 'Goron Ruby', { 'replace': 'Goron Ruby' }, 'Light Blue', items=[{'name': 'Goron Ruby', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
b.add_goal(Goal(self, 'Zora Sapphire', { 'replace': 'Zora Sapphire' }, 'Light Blue', items=[{'name': 'Zora Sapphire', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
b.minimum_goals = self.settings.bridge_stones if self.settings.bridge == 'stones' else self.settings.bridge_rewards
if (self.settings.bridge_medallions > 0 and self.settings.bridge == 'medallions') or (self.settings.bridge_rewards > 0 and self.settings.bridge == 'dungeons'):
b.add_goal(Goal(self, 'Forest Medallion', { 'replace': 'Forest Medallion' }, 'Green', items=[{'name': 'Forest Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
b.add_goal(Goal(self, 'Fire Medallion', { 'replace': 'Fire Medallion' }, 'Red', items=[{'name': 'Fire Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
b.add_goal(Goal(self, 'Water Medallion', { 'replace': 'Water Medallion' }, 'Blue', items=[{'name': 'Water Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
b.add_goal(Goal(self, 'Shadow Medallion', { 'replace': 'Shadow Medallion' }, 'Pink', items=[{'name': 'Shadow Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
b.add_goal(Goal(self, 'Spirit Medallion', { 'replace': 'Spirit Medallion' }, 'Yellow', items=[{'name': 'Spirit Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
b.add_goal(Goal(self, 'Light Medallion', { 'replace': 'Light Medallion' }, 'Light Blue', items=[{'name': 'Light Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
b.minimum_goals = self.settings.bridge_medallions if self.settings.bridge == 'medallions' else self.settings.bridge_rewards
if self.settings.bridge == 'vanilla':
b.add_goal(Goal(self, 'Shadow Medallion', { 'replace': 'Shadow Medallion' }, 'Pink', items=[{'name': 'Shadow Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
b.add_goal(Goal(self, 'Spirit Medallion', { 'replace': 'Spirit Medallion' }, 'Yellow', items=[{'name': 'Spirit Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
min_goals = 2
# With plentiful item pool, multiple copies of Light Arrows are available,
# but both are not guaranteed reachable. Setting a goal quantity of the
# item pool value with a minimum quantity of 1 attempts to hint all items
# required to get all copies of Light Arrows, but will fall back to just
# one copy if the other is unreachable.
#
# Similar criteria is used for Ganon's Boss Key in plentiful keysanity.
if not 'Light Arrows' in self.item_added_hint_types['always']:
if self.settings.item_pool_value == 'plentiful':
arrows = 2
else:
arrows = 1
b.add_goal(Goal(self, 'Evil\'s Bane', 'path to #Evil\'s Bane#', 'Light Blue', items=[{'name': 'Light Arrows', 'quantity': arrows, 'minimum': 1, 'hintable': True}]))
min_goals += 1
b.minimum_goals = min_goals
# Goal count within a category is currently unused. Testing is in progress
# to potentially use this for weighting certain goals for hint selection.
b.goal_count = len(b.goals)
if (self.settings.bridge_tokens > 0
and self.settings.bridge == 'tokens'
and (self.settings.shuffle_ganon_bosskey != 'tokens'
or self.settings.bridge_tokens >= self.settings.ganon_bosskey_tokens)
and (self.settings.shuffle_ganon_bosskey != 'on_lacs' or self.settings.lacs_condition != 'tokens'
or self.settings.bridge_tokens >= self.settings.lacs_tokens)):
b.add_goal(Goal(self, 'Skulls', 'path of #Skulls#', 'Pink', items=[{'name': 'Gold Skulltula Token', 'quantity': 100, 'minimum': self.settings.bridge_tokens, 'hintable': False}]))
b.goal_count = round(self.settings.bridge_tokens / 10)
b.minimum_goals = 1
if (self.settings.bridge_hearts > self.settings.starting_hearts
and self.settings.bridge == 'hearts'
and (self.settings.shuffle_ganon_bosskey != 'hearts'
or self.settings.bridge_hearts >= self.settings.ganon_bosskey_hearts)
and (self.settings.shuffle_ganon_bosskey != 'on_lacs' or self.settings.lacs_condition != 'hearts'
or self.settings.bridge_hearts >= self.settings.lacs_hearts)):
b.add_goal(Goal(self, 'hearts', 'path of #hearts#', 'Red', items=[{'name': 'Piece of Heart', 'quantity': (20 - self.settings.starting_hearts) * 4, 'minimum': (self.settings.bridge_hearts - self.settings.starting_hearts) * 4, 'hintable': False}]))
b.goal_count = round((self.settings.bridge_hearts - 3) / 2)
b.minimum_goals = 1
self.goal_categories[b.name] = b
# If the Ganon's Boss Key condition is the same or similar conditions
# as Bridge, do not create the goals if Bridge goals already cover
# GBK goals. For example, 3 dungeon GBK would not have its own goals
# if it is 4 medallion bridge.
#
# Even if created, there is no guarantee GBK goals will find new
# locations to hint. If duplicate goals are defined for Bridge and
# all of these goals are accessible without Ganon's Castle access,
# the GBK category is redundant and not used for hint selection.
if ((self.settings.ganon_bosskey_stones > 0
and self.settings.shuffle_ganon_bosskey == 'stones'
and (self.shuffle_special_dungeon_entrances or self.settings.ganon_bosskey_stones > self.settings.bridge_stones or self.settings.bridge != 'stones'))
or (self.settings.lacs_stones > 0
and self.settings.shuffle_ganon_bosskey == 'on_lacs' and self.settings.lacs_condition == 'stones'
and (self.shuffle_special_dungeon_entrances or self.settings.lacs_stones > self.settings.bridge_stones or self.settings.bridge != 'stones'))
or (self.settings.ganon_bosskey_rewards > 0
and self.settings.shuffle_ganon_bosskey == 'dungeons'
and (self.shuffle_special_dungeon_entrances or self.settings.ganon_bosskey_rewards > self.settings.bridge_medallions or self.settings.bridge != 'medallions')
and (self.shuffle_special_dungeon_entrances or self.settings.ganon_bosskey_rewards > self.settings.bridge_stones or self.settings.bridge != 'stones')
and (self.shuffle_special_dungeon_entrances or self.settings.ganon_bosskey_rewards > self.settings.bridge_rewards or self.settings.bridge != 'dungeons')
and (self.shuffle_special_dungeon_entrances or self.settings.ganon_bosskey_rewards > 2 or self.settings.bridge != 'vanilla'))
or (self.settings.lacs_rewards > 0
and self.settings.shuffle_ganon_bosskey == 'on_lacs' and self.settings.lacs_condition == 'dungeons'
and (self.shuffle_special_dungeon_entrances or self.settings.lacs_rewards > self.settings.bridge_medallions or self.settings.bridge != 'medallions')
and (self.shuffle_special_dungeon_entrances or self.settings.lacs_rewards > self.settings.bridge_stones or self.settings.bridge != 'stones')
and (self.shuffle_special_dungeon_entrances or self.settings.lacs_rewards > self.settings.bridge_rewards or self.settings.bridge != 'dungeons')
and (self.shuffle_special_dungeon_entrances or self.settings.lacs_rewards > 2 or self.settings.bridge != 'vanilla'))):
gbk.add_goal(Goal(self, 'Kokiri Emerald', { 'replace': 'Kokiri Emerald' }, 'Yellow', items=[{'name': 'Kokiri Emerald', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
gbk.add_goal(Goal(self, 'Goron Ruby', { 'replace': 'Goron Ruby' }, 'Yellow', items=[{'name': 'Goron Ruby', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
gbk.add_goal(Goal(self, 'Zora Sapphire', { 'replace': 'Zora Sapphire' }, 'Yellow', items=[{'name': 'Zora Sapphire', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
gbk.minimum_goals = (self.settings.ganon_bosskey_stones if self.settings.shuffle_ganon_bosskey == 'stones'
else self.settings.lacs_stones if self.settings.shuffle_ganon_bosskey == 'on_lacs' and self.settings.lacs_condition == 'stones'
else self.settings.ganon_bosskey_rewards if self.settings.shuffle_ganon_bosskey == 'dungeons'
else self.settings.lacs_rewards)
if ((self.settings.ganon_bosskey_medallions > 0
and self.settings.shuffle_ganon_bosskey == 'medallions'
and (self.shuffle_special_dungeon_entrances or self.settings.ganon_bosskey_medallions > self.settings.bridge_medallions or self.settings.bridge != 'medallions')
and (self.shuffle_special_dungeon_entrances or self.settings.ganon_bosskey_medallions > 2 or self.settings.bridge != 'vanilla'))
or (self.settings.lacs_medallions > 0
and self.settings.shuffle_ganon_bosskey == 'on_lacs' and self.settings.lacs_condition == 'medallions'
and (self.shuffle_special_dungeon_entrances or self.settings.lacs_medallions > self.settings.bridge_medallions or self.settings.bridge != 'medallions')
and (self.shuffle_special_dungeon_entrances or self.settings.lacs_medallions > 2 or self.settings.bridge != 'vanilla'))
or (self.settings.ganon_bosskey_rewards > 0
and self.settings.shuffle_ganon_bosskey == 'dungeons'
and (self.shuffle_special_dungeon_entrances or self.settings.ganon_bosskey_rewards > self.settings.bridge_medallions or self.settings.bridge != 'medallions')
and (self.shuffle_special_dungeon_entrances or self.settings.ganon_bosskey_rewards > self.settings.bridge_stones or self.settings.bridge != 'stones')
and (self.shuffle_special_dungeon_entrances or self.settings.ganon_bosskey_rewards > self.settings.bridge_rewards or self.settings.bridge != 'dungeons')
and (self.shuffle_special_dungeon_entrances or self.settings.ganon_bosskey_rewards > 2 or self.settings.bridge != 'vanilla'))
or (self.settings.lacs_rewards > 0
and self.settings.shuffle_ganon_bosskey == 'on_lacs' and self.settings.lacs_condition == 'dungeons'
and (self.shuffle_special_dungeon_entrances or self.settings.lacs_rewards > self.settings.bridge_medallions or self.settings.bridge != 'medallions')
and (self.shuffle_special_dungeon_entrances or self.settings.lacs_rewards > self.settings.bridge_stones or self.settings.bridge != 'stones')
and (self.shuffle_special_dungeon_entrances or self.settings.lacs_rewards > self.settings.bridge_rewards or self.settings.bridge != 'dungeons')
and (self.shuffle_special_dungeon_entrances or self.settings.lacs_rewards > 2 or self.settings.bridge != 'vanilla'))):
gbk.add_goal(Goal(self, 'Forest Medallion', { 'replace': 'Forest Medallion' }, 'Green', items=[{'name': 'Forest Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
gbk.add_goal(Goal(self, 'Fire Medallion', { 'replace': 'Fire Medallion' }, 'Red', items=[{'name': 'Fire Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
gbk.add_goal(Goal(self, 'Water Medallion', { 'replace': 'Water Medallion' }, 'Blue', items=[{'name': 'Water Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
gbk.add_goal(Goal(self, 'Shadow Medallion', { 'replace': 'Shadow Medallion' }, 'Pink', items=[{'name': 'Shadow Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
gbk.add_goal(Goal(self, 'Spirit Medallion', { 'replace': 'Spirit Medallion' }, 'Yellow', items=[{'name': 'Spirit Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
gbk.add_goal(Goal(self, 'Light Medallion', { 'replace': 'Light Medallion' }, 'Light Blue', items=[{'name': 'Light Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
gbk.minimum_goals = (self.settings.ganon_bosskey_medallions if self.settings.shuffle_ganon_bosskey == 'medallions'
else self.settings.lacs_medallions if self.settings.shuffle_ganon_bosskey == 'on_lacs' and self.settings.lacs_condition == 'medallions'
else self.settings.ganon_bosskey_rewards if self.settings.shuffle_ganon_bosskey == 'dungeons'
else self.settings.lacs_rewards)
if self.settings.shuffle_ganon_bosskey == 'on_lacs' and self.settings.lacs_condition == 'vanilla':
gbk.add_goal(Goal(self, 'Shadow Medallion', { 'replace': 'Shadow Medallion' }, 'Pink', items=[{'name': 'Shadow Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
gbk.add_goal(Goal(self, 'Spirit Medallion', { 'replace': 'Spirit Medallion' }, 'Yellow', items=[{'name': 'Spirit Medallion', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
gbk.minimum_goals = 2
gbk.goal_count = len(gbk.goals)
if (self.settings.ganon_bosskey_tokens > 0
and self.settings.shuffle_ganon_bosskey == 'tokens'
and (self.shuffle_special_dungeon_entrances
or self.settings.bridge != 'tokens'
or self.settings.bridge_tokens < self.settings.ganon_bosskey_tokens)):
gbk.add_goal(Goal(self, 'Skulls', 'path of #Skulls#', 'Pink', items=[{'name': 'Gold Skulltula Token', 'quantity': 100, 'minimum': self.settings.ganon_bosskey_tokens, 'hintable': False}]))
gbk.goal_count = round(self.settings.ganon_bosskey_tokens / 10)
gbk.minimum_goals = 1
if (self.settings.lacs_tokens > 0
and self.settings.shuffle_ganon_bosskey == 'on_lacs' and self.settings.lacs_condition == 'tokens'
and (self.shuffle_special_dungeon_entrances
or self.settings.bridge != 'tokens'
or self.settings.bridge_tokens < self.settings.lacs_tokens)):
gbk.add_goal(Goal(self, 'Skulls', 'path of #Skulls#', 'Pink', items=[{'name': 'Gold Skulltula Token', 'quantity': 100, 'minimum': self.settings.lacs_tokens, 'hintable': False}]))
gbk.goal_count = round(self.settings.lacs_tokens / 10)
gbk.minimum_goals = 1
if (self.settings.ganon_bosskey_hearts > self.settings.starting_hearts
and self.settings.shuffle_ganon_bosskey == 'hearts'
and (self.settings.bridge != 'hearts'
or self.settings.bridge_hearts < self.settings.ganon_bosskey_hearts)):
gbk.add_goal(Goal(self, 'hearts', 'path of #hearts#', 'Red', items=[{'name': 'Piece of Heart', 'quantity': (20 - self.settings.starting_hearts) * 4, 'minimum': (self.settings.ganon_bosskey_hearts - self.settings.starting_hearts) * 4, 'hintable': False}]))
gbk.goal_count = round((self.settings.ganon_bosskey_hearts - 3) / 2)
gbk.minimum_goals = 1
if (self.settings.lacs_hearts > self.settings.starting_hearts
and self.settings.shuffle_ganon_bosskey == 'on_lacs' and self.settings.lacs_condition == 'hearts'
and (self.settings.bridge != 'hearts'
or self.settings.bridge_hearts < self.settings.lacs_hearts)):
gbk.add_goal(Goal(self, 'hearts', 'path of #hearts#', 'Red', items=[{'name': 'Piece of Heart', 'quantity': (20 - self.settings.starting_hearts) * 4, 'minimum': (self.settings.lacs_hearts - self.settings.starting_hearts) * 4, 'hintable': False}]))
gbk.goal_count = round((self.settings.lacs_hearts - 3) / 2)
gbk.minimum_goals = 1
# Ganon's Boss Key shuffled directly in the world will always
# generate a category/goal pair, though locations are not
# guaranteed if the higher priority Bridge category contains
# all required locations for GBK
if self.settings.shuffle_ganon_bosskey in ['dungeon', 'overworld', 'any_dungeon', 'keysanity', 'regional']:
# Make priority even with trials as the goal is no longer centered around dungeon completion or collectibles
gbk.priority = 30
gbk.goal_count = 1
if self.settings.item_pool_value == 'plentiful':
keys = 2
else:
keys = 1
gbk.add_goal(Goal(self, 'the Key', 'path to #the Key#', 'Light Blue', items=[{'name': 'Boss Key (Ganons Castle)', 'quantity': keys, 'minimum': 1, 'hintable': True}]))
gbk.minimum_goals = 1
if gbk.goals:
self.goal_categories[gbk.name] = gbk
# To avoid too many goals in the hint selection phase,
# trials are reduced to one goal with six items to obtain.
if self.skipped_trials['Forest'] == False:
trial_goal.items.append({'name': 'Forest Trial Clear', 'quantity': 1, 'minimum': 1, 'hintable': True})
trials.goal_count += 1
if self.skipped_trials['Fire'] == False:
trial_goal.items.append({'name': 'Fire Trial Clear', 'quantity': 1, 'minimum': 1, 'hintable': True})
trials.goal_count += 1
if self.skipped_trials['Water'] == False:
trial_goal.items.append({'name': 'Water Trial Clear', 'quantity': 1, 'minimum': 1, 'hintable': True})
trials.goal_count += 1
if self.skipped_trials['Shadow'] == False:
trial_goal.items.append({'name': 'Shadow Trial Clear', 'quantity': 1, 'minimum': 1, 'hintable': True})
trials.goal_count += 1
if self.skipped_trials['Spirit'] == False:
trial_goal.items.append({'name': 'Spirit Trial Clear', 'quantity': 1, 'minimum': 1, 'hintable': True})
trials.goal_count += 1
if self.skipped_trials['Light'] == False:
trial_goal.items.append({'name': 'Light Trial Clear', 'quantity': 1, 'minimum': 1, 'hintable': True})
trials.goal_count += 1
# Trials category is finalized and saved only if at least one trial is on
# If random trials are on and one world in multiworld gets 0 trials, still
# add the goal to prevent key errors. Since no items fulfill the goal, it
# will always be invalid for that world and not generate hints.
if self.settings.trials > 0 or self.settings.trials_random:
trials.add_goal(trial_goal)
self.goal_categories[trials.name] = trials
if (self.shuffle_special_dungeon_entrances or self.settings.bridge == 'open') and (self.settings.shuffle_ganon_bosskey == 'remove' or self.settings.shuffle_ganon_bosskey == 'vanilla') and self.settings.trials == 0:
g = GoalCategory('ganon', 30, goal_count=1)
# Equivalent to WOTH, but added in case WOTH hints are disabled in favor of goal hints
g.add_goal(Goal(self, 'the hero', 'path of #the hero#', 'White', items=[{'name': 'Triforce', 'quantity': 1, 'minimum': 1, 'hintable': True}]))
g.minimum_goals = 1
self.goal_categories[g.name] = g
def get_region(self, regionname):
if isinstance(regionname, Region):
return regionname
try:
return self._region_cache[regionname]
except KeyError:
for region in self.regions:
if region.name == regionname:
self._region_cache[regionname] = region
return region
raise KeyError('No such region %s' % regionname)
def get_entrance(self, entrance):
if isinstance(entrance, Entrance):
return entrance
try:
return self._entrance_cache[entrance]
except KeyError:
for region in self.regions:
for exit in region.exits:
if exit.name == entrance:
self._entrance_cache[entrance] = exit
return exit
raise KeyError('No such entrance %s' % entrance)
def get_location(self, location):