forked from OoTRandomizer/OoT-Randomizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hints.py
765 lines (635 loc) · 29.7 KB
/
Hints.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
import io
import hashlib
import logging
import os
import struct
import random
from collections import OrderedDict
from HintList import getHint, getHintGroup, Hint, hintExclusions
from Item import MakeEventItem
from Messages import update_message_by_id
from Search import Search
from TextBox import line_wrap
from Utils import random_choices
class GossipStone():
def __init__(self, name, location):
self.name = name
self.location = location
self.reachable = True
class GossipText():
def __init__(self, text, colors=None, prefix="They say that "):
text = prefix + text
text = text[:1].upper() + text[1:]
self.text = text
self.colors = colors
def to_json(self):
return {'text': self.text, 'colors': self.colors}
def __str__(self):
return get_raw_text(line_wrap(colorText(self)))
# Abbreviations
# DMC Death Mountain Crater
# DMT Death Mountain Trail
# GC Goron City
# GV Gerudo Valley
# HC Hyrule Castle
# HF Hyrule Field
# KF Kokiri Forest
# LH Lake Hylia
# LW Lost Woods
# SFM Sacred Forest Meadow
# ToT Temple of Time
# ZD Zora's Domain
# ZF Zora's Fountain
# ZR Zora's River
gossipLocations = {
0x0405: GossipStone('DMC (Bombable Wall)', 'DMC Gossip Stone'),
0x0404: GossipStone('DMT (Biggoron)', 'DMT Gossip Stone'),
0x041A: GossipStone('Colossus (Spirit Temple)', 'Colossus Gossip Stone'),
0x0414: GossipStone('Dodongos Cavern (Bombable Wall)', 'Dodongos Cavern Gossip Stone'),
0x0411: GossipStone('GV (Waterfall)', 'GV Gossip Stone'),
0x0415: GossipStone('GC (Maze)', 'GC Maze Gossip Stone'),
0x0419: GossipStone('GC (Medigoron)', 'GC Medigoron Gossip Stone'),
0x040A: GossipStone('Graveyard (Shadow Temple)', 'Graveyard Gossip Stone'),
0x0412: GossipStone('HC (Malon)', 'HC Malon Gossip Stone'),
0x040B: GossipStone('HC (Rock Wall)', 'HC Rock Wall Gossip Stone'),
0x0413: GossipStone('HC (Storms Grotto)', 'HC Storms Grotto Gossip Stone'),
0x041F: GossipStone('KF (Deku Tree Left)', 'KF Deku Tree Gossip Stone (Left)'),
0x0420: GossipStone('KF (Deku Tree Right)', 'KF Deku Tree Gossip Stone (Right)'),
0x041E: GossipStone('KF (Outside Storms)', 'KF Gossip Stone'),
0x0403: GossipStone('LH (Lab)', 'LH Lab Gossip Stone'),
0x040F: GossipStone('LH (Southeast Corner)', 'LH Gossip Stone (Southeast)'),
0x0408: GossipStone('LH (Southwest Corner)', 'LH Gossip Stone (Southwest)'),
0x041D: GossipStone('LW (Bridge)', 'LW Gossip Stone'),
0x0416: GossipStone('SFM (Maze Lower)', 'SFM Maze Gossip Stone (Lower)'),
0x0417: GossipStone('SFM (Maze Upper)', 'SFM Maze Gossip Stone (Upper)'),
0x041C: GossipStone('SFM (Saria)', 'SFM Saria Gossip Stone'),
0x0406: GossipStone('ToT (Left)', 'ToT Gossip Stone (Left)'),
0x0407: GossipStone('ToT (Left-Center)', 'ToT Gossip Stone (Left-Center)'),
0x0410: GossipStone('ToT (Right)', 'ToT Gossip Stone (Right)'),
0x040E: GossipStone('ToT (Right-Center)', 'ToT Gossip Stone (Right-Center)'),
0x0409: GossipStone('ZD (Mweep)', 'ZD Gossip Stone'),
0x0401: GossipStone('ZF (Fairy)', 'ZF Fairy Gossip Stone'),
0x0402: GossipStone('ZF (Jabu)', 'ZF Jabu Gossip Stone'),
0x040D: GossipStone('ZR (Near Grottos)', 'ZR Near Grottos Gossip Stone'),
0x040C: GossipStone('ZR (Near Domain)', 'ZR Near Domain Gossip Stone'),
0x041B: GossipStone('HF (Cow Grotto)', 'HF Cow Grotto Gossip Stone'),
0x0430: GossipStone('HF (Near Market Grotto)', 'HF Near Market Grotto Gossip Stone'),
0x0432: GossipStone('HF (Southeast Grotto)', 'HF Southeast Grotto Gossip Stone'),
0x0433: GossipStone('HF (Open Grotto)', 'HF Open Grotto Gossip Stone'),
0x0438: GossipStone('Kak (Open Grotto)', 'Kak Open Grotto Gossip Stone'),
0x0439: GossipStone('ZR (Open Grotto)', 'ZR Open Grotto Gossip Stone'),
0x043C: GossipStone('KF (Storms Grotto)', 'KF Storms Grotto Gossip Stone'),
0x0444: GossipStone('LW (Near Shortcuts Grotto)', 'LW Near Shortcuts Grotto Gossip Stone'),
0x0447: GossipStone('DMT (Storms Grotto)', 'DMT Storms Grotto Gossip Stone'),
0x044A: GossipStone('DMC (Upper Grotto)', 'DMC Upper Grotto Gossip Stone'),
}
def getItemGenericName(item):
if item.dungeonitem:
return item.type
else:
return item.name
def isRestrictedDungeonItem(dungeon, item):
if (item.map or item.compass) and dungeon.world.shuffle_mapcompass == 'dungeon':
return item in dungeon.dungeon_items
if item.smallkey and dungeon.world.shuffle_smallkeys == 'dungeon':
return item in dungeon.small_keys
if item.bosskey and dungeon.world.shuffle_bosskeys == 'dungeon':
return item in dungeon.boss_key
return False
def add_hint(spoiler, world, IDs, gossip_text, count, location=None, force_reachable=False):
random.shuffle(IDs)
skipped_ids = []
duplicates = []
first = True
success = True
# early failure if not enough
if len(IDs) < int(count):
return False
# Randomly round up, if we have enough IDs left
total = int(random.random() + count) if len(IDs) > count else int(count)
while total:
if IDs:
id = IDs.pop(0)
if gossipLocations[id].reachable:
stone_name = gossipLocations[id].location
stone_location = world.get_location(stone_name)
if not first or can_reach_stone(spoiler.worlds, stone_location, location):
if first and location:
# just name the event item after the gossip stone directly
MakeEventItem(stone_name, stone_location)
# This mostly guarantees that we don't lock the player out of an item hint
# by establishing a (hint -> item) -> hint -> item -> (first hint) loop
location.add_rule(world.parser.parse_rule(repr(stone_name)))
total -= 1
first = False
spoiler.hints[world.id][id] = gossip_text
# Immediately start choosing duplicates from stones we passed up earlier
while duplicates and total:
id = duplicates.pop(0)
total -= 1
spoiler.hints[world.id][id] = gossip_text
else:
# Temporarily skip this stone but consider it for duplicates
duplicates.append(id)
else:
if not force_reachable:
# The stones are not readable at all in logic, so we ignore any kind of logic here
if not first:
total -= 1
spoiler.hints[world.id][id] = gossip_text
else:
# Temporarily skip this stone but consider it for duplicates
duplicates.append(id)
else:
# If flagged to guarantee reachable, then skip
# If no stones are reachable, then this will place nothing
skipped_ids.append(id)
else:
# Out of IDs
if not force_reachable and len(duplicates) >= total:
# Didn't find any appropriate stones for this hint, but maybe enough completely unreachable ones.
# We'd rather not use reachable stones for this.
unr = [id for id in duplicates if not gossipLocations[id].reachable]
if len(unr) >= total:
duplicates = [id for id in duplicates if id not in unr[:total]]
for id in unr[:total]:
spoiler.hints[world.id][id] = gossip_text
# Success
break
# Failure
success = False
break
IDs.extend(duplicates)
IDs.extend(skipped_ids)
return success
def can_reach_stone(worlds, stone_location, location):
if location == None:
return True
old_item = location.item
location.item = None
search = Search.max_explore([world.state for world in worlds])
location.item = old_item
return (search.spot_access(stone_location)
and search.state_list[location.world.id].guarantee_hint())
def writeGossipStoneHints(spoiler, world, messages):
for id, gossip_text in spoiler.hints[world.id].items():
update_message_by_id(messages, id, str(gossip_text), 0x23)
def filterTrailingSpace(text):
if text.endswith('& '):
return text[:-1]
else:
return text
hintPrefixes = [
'a few ',
'some ',
'plenty of ',
'a ',
'an ',
'the ',
'',
]
def getSimpleHintNoPrefix(item):
hint = getHint(item.name, True).text
for prefix in hintPrefixes:
if hint.startswith(prefix):
# return without the prefix
return hint[len(prefix):]
# no prefex
return hint
def colorText(gossip_text):
colorMap = {
'White': '\x40',
'Red': '\x41',
'Green': '\x42',
'Blue': '\x43',
'Light Blue': '\x44',
'Pink': '\x45',
'Yellow': '\x46',
'Black': '\x47',
}
text = gossip_text.text
colors = list(gossip_text.colors) if gossip_text.colors is not None else []
color = 'White'
while '#' in text:
splitText = text.split('#', 2)
if len(colors) > 0:
color = colors.pop()
for prefix in hintPrefixes:
if splitText[1].startswith(prefix):
splitText[0] += splitText[1][:len(prefix)]
splitText[1] = splitText[1][len(prefix):]
break
splitText[1] = '\x05' + colorMap[color] + splitText[1] + '\x05\x40'
text = ''.join(splitText)
return text
def get_hint_area(spot):
if spot.parent_region.dungeon:
return spot.parent_region.dungeon.hint
elif spot.parent_region.hint:
return spot.parent_region.hint
#Breadth first search for connected regions with a max depth of 2
for entrance in spot.parent_region.entrances:
if entrance.parent_region.hint:
return entrance.parent_region.hint
for entrance in spot.parent_region.entrances:
for entrance2 in entrance.parent_region.entrances:
if entrance2.parent_region.hint:
return entrance2.parent_region.hint
raise RuntimeError('No hint area could be found for %s [World %d]' % (spot, spot.world.id))
def get_woth_hint(spoiler, world, checked):
locations = spoiler.required_locations[world.id]
locations = list(filter(lambda location:
location.name not in checked and \
not (world.woth_dungeon >= 2 and location.parent_region.dungeon),
locations))
if not locations:
return None
location = random.choice(locations)
checked.add(location.name)
if location.parent_region.dungeon:
if world.hint_dist != 'very_strong':
world.woth_dungeon += 1
location_text = getHint(location.parent_region.dungeon.name, world.clearer_hints).text
else:
location_text = get_hint_area(location)
if world.triforce_hunt:
return (GossipText('#%s# is on the path of gold.' % location_text, ['Light Blue']), location)
else:
return (GossipText('#%s# is on the way of the hero.' % location_text, ['Light Blue']), location)
def get_barren_hint(spoiler, world, checked):
areas = list(filter(lambda area:
area not in checked and \
not (world.barren_dungeon and world.empty_areas[area]['dungeon']),
world.empty_areas.keys()))
if not areas:
return None
area_weights = [world.empty_areas[area]['weight'] for area in areas]
area = random_choices(areas, weights=area_weights)[0]
if world.hint_dist != 'very_strong' and world.empty_areas[area]['dungeon']:
world.barren_dungeon = True
checked.add(area)
return (GossipText("plundering #%s# is a foolish choice." % area, ['Pink']), None)
def is_not_checked(location, checked):
return not (location.name in checked or get_hint_area(location) in checked)
def get_good_item_hint(spoiler, world, checked):
locations = [location for location in world.get_filled_locations()
if is_not_checked(location, checked) and \
location.item.majoritem and \
not location.locked]
if not locations:
return None
location = random.choice(locations)
checked.add(location.name)
item_text = getHint(getItemGenericName(location.item), world.clearer_hints).text
if location.parent_region.dungeon:
location_text = getHint(location.parent_region.dungeon.name, world.clearer_hints).text
return (GossipText('#%s# hoards #%s#.' % (location_text, item_text), ['Green', 'Red']), location)
else:
location_text = get_hint_area(location)
return (GossipText('#%s# can be found at #%s#.' % (item_text, location_text), ['Red', 'Green']), location)
def get_random_location_hint(spoiler, world, checked):
locations = [location for location in world.get_filled_locations()
if is_not_checked(location, checked) and \
location.item.type not in ('Drop', 'Event', 'Shop', 'DungeonReward') and \
not (location.parent_region.dungeon and \
isRestrictedDungeonItem(location.parent_region.dungeon, location.item)) and
not location.locked]
if not locations:
return None
location = random.choice(locations)
checked.add(location.name)
dungeon = location.parent_region.dungeon
item_text = getHint(getItemGenericName(location.item), world.clearer_hints).text
if dungeon:
location_text = getHint(dungeon.name, world.clearer_hints).text
return (GossipText('#%s# hoards #%s#.' % (location_text, item_text), ['Green', 'Red']), location)
else:
location_text = get_hint_area(location)
return (GossipText('#%s# can be found at #%s#.' % (item_text, location_text), ['Red', 'Green']), location)
def get_specific_hint(spoiler, world, checked, type):
hintGroup = getHintGroup(type, world)
hintGroup = list(filter(lambda hint: is_not_checked(world.get_location(hint.name), checked), hintGroup))
if not hintGroup:
return None
hint = random.choice(hintGroup)
location = world.get_location(hint.name)
checked.add(location.name)
location_text = hint.text
if '#' not in location_text:
location_text = '#%s#' % location_text
item_text = getHint(getItemGenericName(location.item), world.clearer_hints).text
return (GossipText('%s #%s#.' % (location_text, item_text), ['Green', 'Red']), location)
def get_sometimes_hint(spoiler, world, checked):
return get_specific_hint(spoiler, world, checked, 'sometimes')
def get_song_hint(spoiler, world, checked):
return get_specific_hint(spoiler, world, checked, 'song')
def get_overworld_hint(spoiler, world, checked):
return get_specific_hint(spoiler, world, checked, 'overworld')
def get_dungeon_hint(spoiler, world, checked):
return get_specific_hint(spoiler, world, checked, 'dungeon')
def get_entrance_hint(spoiler, world, checked):
if world.entrance_shuffle == 'off':
return None
entrance_hints = getHintGroup('entrance', world)
entrance_hints = list(filter(lambda hint: hint.name not in checked, entrance_hints))
valid_entrance_hints = [entrance_hint for entrance_hint in entrance_hints if world.get_entrance(entrance_hint.name).shuffled]
if not valid_entrance_hints:
return None
entrance_hint = random.choice(valid_entrance_hints)
entrance = world.get_entrance(entrance_hint.name)
checked.add(entrance.name)
entrance_text = entrance_hint.text
if '#' not in entrance_text:
entrance_text = '#%s#' % entrance_text
connected_region = entrance.connected_region
if connected_region.dungeon:
region_text = getHint(connected_region.dungeon.name, world.clearer_hints).text
else:
region_text = getHint(connected_region.name, world.clearer_hints).text
if '#' not in region_text:
region_text = '#%s#' % region_text
return (GossipText('%s %s.' % (entrance_text, region_text), ['Light Blue', 'Green']), None)
def get_junk_hint(spoiler, world, checked):
hints = getHintGroup('junk', world)
hints = list(filter(lambda hint: hint.name not in checked, hints))
if not hints:
return None
hint = random.choice(hints)
checked.add(hint.name)
return (GossipText(hint.text, prefix=''), None)
hint_func = {
'trial': lambda spoiler, world, checked: None,
'always': lambda spoiler, world, checked: None,
'woth': get_woth_hint,
'barren': get_barren_hint,
'item': get_good_item_hint,
'sometimes':get_sometimes_hint,
'song': get_song_hint,
'ow': get_overworld_hint,
'dungeon': get_dungeon_hint,
'entrance': get_entrance_hint,
'random': get_random_location_hint,
'junk': get_junk_hint,
}
# (relative weight, count)
# count: number of times each hint is placed. 0 means none!
# trial and always are special, and their weights irrelevant.
hint_dist_sets = {
'useless': {
'trial': (0.0, 0),
'always': (0.0, 0),
'woth': (0.0, 0),
'barren': (0.0, 0),
'item': (0.0, 0),
'song': (0.0, 0),
'ow': (0.0, 0),
'dungeon': (0.0, 0),
'entrance': (0.0, 0),
'random': (0.0, 0),
'junk': (9.0, 1),
},
'balanced': {
'trial': (0.0, 1),
'always': (0.0, 1),
'woth': (3.5, 1),
'barren': (2.0, 1),
'item': (5.0, 1),
'song': (1.0, 1),
'ow': (2.0, 1),
'dungeon': (1.5, 1),
'entrance': (3.0, 1),
'random': (6.0, 1),
'junk': (3.0, 1),
},
'strong': {
'trial': (0.0, 1),
'always': (0.0, 2),
'woth': (3.0, 2),
'barren': (3.0, 1),
'item': (1.0, 1),
'song': (0.33, 1),
'ow': (0.66, 1),
'dungeon': (0.66, 1),
'entrance': (1.0, 1),
'random': (2.0, 1),
'junk': (0.0, 0),
},
'very_strong': {
'trial': (0.0, 1),
'always': (0.0, 2),
'woth': (3.0, 2),
'barren': (3.0, 1),
'item': (1.0, 1),
'song': (0.5, 1),
'ow': (1.5, 1),
'dungeon': (1.5, 1),
'entrance': (2.0, 1),
'random': (0.0, 0),
'junk': (0.0, 0),
},
'tournament': OrderedDict({
# (number of hints, count per hint)
'trial': (0.0, 2),
'always': (0.0, 2),
'woth': (5.0, 2),
'barren': (3.0, 2),
'entrance': (4.0, 2),
'sometimes': (0.0, 2),
'random': (0.0, 2),
}),
}
def buildGossipHints(spoiler, worlds):
checkedLocations = dict()
# Add Light Arrow locations to "checked" locations if Ganondorf is reachable without it.
for world in worlds:
location = world.light_arrow_location
if location is None:
continue
# Didn't you know that Ganondorf is a gossip stone?
if can_reach_stone(worlds, world.get_location("Ganondorf Hint"), location):
light_arrow_world = location.world
if light_arrow_world.id not in checkedLocations:
checkedLocations[light_arrow_world.id] = set()
checkedLocations[light_arrow_world.id].add(location.name)
# Build all the hints.
for world in worlds:
world.update_useless_areas(spoiler)
buildWorldGossipHints(spoiler, world, checkedLocations.pop(world.id, None))
#builds out general hints based on location and whether an item is required or not
def buildWorldGossipHints(spoiler, world, checkedLocations=None):
# rebuild hint exclusion list
hintExclusions(world, clear_cache=True)
world.barren_dungeon = False
world.woth_dungeon = 0
search = Search.max_explore([w.state for w in spoiler.worlds])
for stone in gossipLocations.values():
stone.reachable = (
search.spot_access(world.get_location(stone.location))
and search.state_list[world.id].guarantee_hint())
if checkedLocations is None:
checkedLocations = set()
stoneIDs = list(gossipLocations.keys())
world.distribution.configure_gossip(spoiler, stoneIDs)
random.shuffle(stoneIDs)
hint_dist = hint_dist_sets[world.hint_dist]
hint_types, hint_prob = zip(*hint_dist.items())
hint_prob, _ = zip(*hint_prob)
# Add required location hints
alwaysLocations = getHintGroup('always', world)
for hint in alwaysLocations:
location = world.get_location(hint.name)
checkedLocations.add(hint.name)
location_text = getHint(location.name, world.clearer_hints).text
if '#' not in location_text:
location_text = '#%s#' % location_text
item_text = getHint(getItemGenericName(location.item), world.clearer_hints).text
add_hint(spoiler, world, stoneIDs, GossipText('%s #%s#.' % (location_text, item_text), ['Green', 'Red']), hint_dist['always'][1], location, force_reachable=True)
# Add trial hints
if world.trials_random and world.trials == 6:
add_hint(spoiler, world, stoneIDs, GossipText("#Ganon's Tower# is protected by a powerful barrier.", ['Pink']), hint_dist['trial'][1], force_reachable=True)
elif world.trials_random and world.trials == 0:
add_hint(spoiler, world, stoneIDs, GossipText("Sheik dispelled the barrier around #Ganon's Tower#.", ['Yellow']), hint_dist['trial'][1], force_reachable=True)
elif world.trials < 6 and world.trials > 3:
for trial,skipped in world.skipped_trials.items():
if skipped:
add_hint(spoiler, world, stoneIDs,GossipText("the #%s Trial# was dispelled by Sheik." % trial, ['Yellow']), hint_dist['trial'][1], force_reachable=True)
elif world.trials <= 3 and world.trials > 0:
for trial,skipped in world.skipped_trials.items():
if not skipped:
add_hint(spoiler, world, stoneIDs, GossipText("the #%s Trial# protects Ganon's Tower." % trial, ['Pink']), hint_dist['trial'][1], force_reachable=True)
hint_types = list(hint_types)
hint_prob = list(hint_prob)
hint_counts = {}
if world.hint_dist == "tournament":
fixed_hint_types = []
for hint_type in hint_types:
fixed_hint_types.extend([hint_type] * int(hint_dist[hint_type][0]))
fill_hint_types = ['sometimes', 'random']
current_fill_type = fill_hint_types.pop(0)
while stoneIDs:
if world.hint_dist == "tournament":
if fixed_hint_types:
hint_type = fixed_hint_types.pop(0)
else:
hint_type = current_fill_type
else:
try:
# Weight the probabilities such that hints that are over the expected proportion
# will be drawn less, and hints that are under will be drawn more.
# This tightens the variance quite a bit. The variance can be adjusted via the power
weighted_hint_prob = []
for w1_type, w1_prob in zip(hint_types, hint_prob):
p = w1_prob
if p != 0: # If the base prob is 0, then it's 0
for w2_type, w2_prob in zip(hint_types, hint_prob):
if w2_prob != 0: # If the other prob is 0, then it has no effect
# Raising this term to a power greater than 1 will decrease variance
# Conversely, a power less than 1 will increase variance
p = p * (((hint_counts.get(w2_type, 0) / w2_prob) + 1) / ((hint_counts.get(w1_type, 0) / w1_prob) + 1))
weighted_hint_prob.append(p)
hint_type = random_choices(hint_types, weights=weighted_hint_prob)[0]
except IndexError:
raise Exception('Not enough valid hints to fill gossip stone locations.')
hint = hint_func[hint_type](spoiler, world, checkedLocations)
if hint == None:
index = hint_types.index(hint_type)
hint_prob[index] = 0
if world.hint_dist == "tournament" and hint_type == current_fill_type:
logging.getLogger('').info('Not enough valid %s hints for tournament distribution.', hint_type)
if fill_hint_types:
current_fill_type = fill_hint_types.pop(0)
logging.getLogger('').info('Switching to %s hints to fill remaining gossip stone locations.', current_fill_type)
else:
raise Exception('Not enough valid hints for tournament distribution.')
else:
gossip_text, location = hint
place_ok = add_hint(spoiler, world, stoneIDs, gossip_text, hint_dist[hint_type][1], location)
if place_ok:
hint_counts[hint_type] = hint_counts.get(hint_type, 0) + 1
if not place_ok and world.hint_dist == "tournament":
logging.getLogger('').debug('Failed to place %s hint for %s.', hint_type, location.name)
fixed_hint_types.insert(0, hint_type)
# builds boss reward text that is displayed at the temple of time altar for child and adult, pull based off of item in a fixed order.
def buildBossRewardHints(world, messages):
# text that appears at altar as a child.
bossRewardsSpiritualStones = [
('Kokiri Emerald', 'Green'),
('Goron Ruby', 'Red'),
('Zora Sapphire', 'Blue'),
]
child_text = '\x08'
child_text += getHint('Spiritual Stone Text Start', world.clearer_hints).text
for (reward, color) in bossRewardsSpiritualStones:
child_text += buildBossString(reward, color, world)
child_text += getHint('Spiritual Stone Text End', world.clearer_hints).text
child_text += '\x0B'
update_message_by_id(messages, 0x707A, get_raw_text(child_text), 0x20)
# text that appears at altar as an adult.
bossRewardsMedallions = [
('Light Medallion', 'Light Blue'),
('Forest Medallion', 'Green'),
('Fire Medallion', 'Red'),
('Water Medallion', 'Blue'),
('Shadow Medallion', 'Pink'),
('Spirit Medallion', 'Yellow'),
]
adult_text = '\x08'
adult_text += getHint('Medallion Text Start', world.clearer_hints).text
for (reward, color) in bossRewardsMedallions:
adult_text += buildBossString(reward, color, world)
adult_text += getHint('Medallion Text End', world.clearer_hints).text
adult_text += '\x0B'
update_message_by_id(messages, 0x7057, get_raw_text(adult_text), 0x20)
# pulls text string from hintlist for reward after sending the location to hintlist.
def buildBossString(reward, color, world):
for location in world.get_filled_locations():
if location.item.name == reward:
item_icon = chr(location.item.special['item_id'])
location_text = getHint(location.name, world.clearer_hints).text
return str(GossipText("\x08\x13%s%s" % (item_icon, location_text), [color], prefix='')) + '\x04'
return ''
# fun new lines for Ganon during the final battle
def buildGanonText(world, messages):
# empty now unused messages to make space for ganon lines
update_message_by_id(messages, 0x70C8, " ")
update_message_by_id(messages, 0x70C9, " ")
update_message_by_id(messages, 0x70CA, " ")
# lines before battle
ganonLines = getHintGroup('ganonLine', world)
random.shuffle(ganonLines)
text = get_raw_text(ganonLines.pop().text)
update_message_by_id(messages, 0x70CB, text)
# light arrow hint or validation chest item
if world.distribution.get_starting_item('Light Arrows') > 0:
text = get_raw_text(getHint('Light Arrow Location', world.clearer_hints).text)
text += "\x05\x42your pocket\x05\x40"
elif world.light_arrow_location:
text = get_raw_text(getHint('Light Arrow Location', world.clearer_hints).text)
location = world.light_arrow_location
location_hint = get_hint_area(location).replace('Ganon\'s Castle', 'my castle')
if world.id != location.world.id:
text += "\x05\x42Player %d's\x05\x40 %s" % (location.world.id +1, get_raw_text(location_hint))
else:
text += get_raw_text(location_hint)
else:
text = get_raw_text(getHint('Validation Line', world.clearer_hints).text)
for location in world.get_filled_locations():
if location.name == 'Ganons Tower Boss Key Chest':
text += get_raw_text(getHint(getItemGenericName(location.item), world.clearer_hints).text)
break
text += '!'
update_message_by_id(messages, 0x70CC, text)
def get_raw_text(string):
text = ''
for char in string:
if char == '^':
text += '\x04' # box break
elif char == '&':
text += '\x01' #new line
elif char == '@':
text += '\x0F' #print player name
elif char == '#':
text += '\x05\x40' #sets color to white
else:
text += char
return text