Skip to content

Commit

Permalink
Merge 'Fix Suns Song + Random Melodies interaction - The Very Final' (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cjohnson57 committed Jul 31, 2023
2 parents c2936af + 39169c5 commit 95c6d00
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
29 changes: 27 additions & 2 deletions OcarinaSongs.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,27 @@ def increase_duration_to(self, duration: int) -> None:
self.playback.append({'note': 0xFF, 'duration': duration_needed, 'volume': 0})
self.format_playback_data()

def fix_song_duration(self, duration: int) -> None:
if self.total_duration == duration:
return

# If too short, we just increase it.
if self.total_duration < duration:
self.increase_duration_to(duration)
return

# Else reduce the duration equitably.
total_duration_to_cut = self.total_duration - duration
duration_to_cut_for_each_note = total_duration_to_cut // len(self.playback) + 1
for note_index, note in enumerate(self.playback):
if note['duration'] <= duration_to_cut_for_each_note:
raise ShuffleError('Could not fix song duration')
note['duration'] -= duration_to_cut_for_each_note
self.format_playback_data()
duration_to_add_back_on_last = duration - self.total_duration
self.playback[-1]['duration'] += duration_to_add_back_on_last
self.format_playback_data()

def two_piece_playback(self, piece: list[int], extra_position: str = 'none', activation_transform: ActivationTransform = identity,
playback_transform: PlaybackTransform = identity) -> None:
piece_length = len(piece)
Expand Down Expand Up @@ -416,10 +437,14 @@ def patch_songs(world: World, rom: Rom) -> None:
if str(song) == SONG_TABLE[name][2]:
continue # song activation is vanilla (possibly because this row wasn't randomized), don't randomize playback

# fix the song of time and sun's song
if name == 'Song of Time' or name == 'Suns Song':
# fix the song of time
if name == 'Song of Time':
song.increase_duration_to(260)

# Suns Song having a different length than vanilla duration can lead to it sometimes not working, notably in MQ Spirit Symphony room.
if name == 'Suns Song':
song.fix_song_duration(208)

# write the song to the activation table
cur_offset = ACTIVATION_START + SONG_TABLE[name][0] * ACTIVATION_LENGTH
rom.write_bytes(cur_offset, song.activation_data)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ issue. You should always Hard Reset to avoid this issue entirely.
* A crash when diving and resurfacing in very shallow water present in the original game has been fixed.
* Various miscellaneous logic issues have been addressed.
* A minor bug related to checking time of day access has been corrected.
* Fix a softlock caused by 8-note Sun's Songs when using `Randomize Ocarina Song Notes`, again.
* **Hints**
* Fix the cryptic hint for Ganon's Castle Boss Key.
* Fix missing punctuation in dual hints.
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '7.1.156'
__version__ = '7.1.157'

# This is a supplemental version number for branches based off of main dev.
supplementary_version = 0
Expand Down

0 comments on commit 95c6d00

Please sign in to comment.