Skip to content

Commit

Permalink
Dialogue rando: Get working properly for intro scrolling text
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Mar 31, 2018
1 parent d100dc0 commit bddc5b0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions constants/dos_randomizer_constants.rb
Expand Up @@ -73,6 +73,8 @@
MAGICAL_TICKET_X_POS_OFFSET = 0x02308920+0x2C
MAGICAL_TICKET_Y_POS_OFFSET = 0x02308920+0x30

INTRO_TEXT_ID = 0x4A6

BGM_RANDO_AVAILABLE_SONG_INDEXES = [
0x0D, # Pitch Black Intrusion
0x11, # Demon Guest House
Expand Down
2 changes: 2 additions & 0 deletions constants/ooe_randomizer_constants.rb
Expand Up @@ -85,6 +85,8 @@
MAGICAL_TICKET_X_POS_OFFSET = 0x02037B10
MAGICAL_TICKET_Y_POS_OFFSET = 0x02037B04

INTRO_TEXT_ID = 0x660

BGM_RANDO_AVAILABLE_SONG_INDEXES = [
0x0E, # An Empty Tome
0x0E, # An Empty Tome
Expand Down
2 changes: 2 additions & 0 deletions constants/por_randomizer_constants.rb
Expand Up @@ -99,6 +99,8 @@
MAGICAL_TICKET_X_POS_OFFSET = 0x0203A298
MAGICAL_TICKET_Y_POS_OFFSET = 0x0203A284

INTRO_TEXT_ID = 0x6BD

BGM_RANDO_AVAILABLE_SONG_INDEXES = [
0x01, # Invitation of a Crazed Moon
0x02, # Silent Prison
Expand Down
39 changes: 34 additions & 5 deletions randomizers/cosmetic/dialogue_randomizer.rb
Expand Up @@ -6,14 +6,41 @@ def randomize_dialogue
markov = Markov.new(rng)

events = game.text_database.text_list[TEXT_REGIONS["Events"]]
intro_text = game.text_database.text_list[INTRO_TEXT_ID]
events -= [intro_text]

events.each do |text|
# Build the markov chain's dictionary.
(events + [intro_text]).each do |text|
lines = text.decoded_string.gsub(/\\n/, "").split(/\{[^}]+\}/)
lines.each do |line|
markov.parse_string(line)
end
end

# Randomize scrolling intro text.
if GAME == "ooe"
num_intro_lines = 30
else
num_intro_lines = 10
end
if GAME == "por"
intro_max_line_length = 36
else
intro_max_line_length = 40
end
new_intro_lines = []
num_intro_lines.times do
sentence = markov.generate_sentence()
wordwrapped_sentence_lines = word_wrap_string(sentence, intro_max_line_length)
new_intro_lines += wordwrapped_sentence_lines
end
new_intro_text = new_intro_lines.join("\\n")
if GAME == "ooe"
new_intro_text += "\\n"*13
end
intro_text.decoded_string = new_intro_text

# Randomize event dialogue.
events.each do |text|
new_lines = []

Expand All @@ -27,17 +54,15 @@ def randomize_dialogue
# Generate a new line of dialogue.
sentence = markov.generate_sentence()

# Wordwrap.
max_line_length = 40
wordwrapped_sentence_lines = sentence.scan(/\S.{0,#{max_line_length-2}}\S(?=\s|$)|\S+/)
wordwrapped_sentence_lines = word_wrap_string(sentence)

# If the new line takes up more than 3 lines, it won't fit on screen.
# So we need to break it up into multiple lines that the player can click through.
groups_of_3_lines = wordwrapped_sentence_lines.each_slice(3).map{|three_lines| three_lines.join("\\n\n")}

new_line = groups_of_3_lines.join("{WAITINPUT}{SAMECHAR}")

new_lines << new_line + "\\n\n"
new_lines << new_line + "\\n"
end
end

Expand All @@ -46,6 +71,10 @@ def randomize_dialogue

game.text_database.write_to_rom()
end

def word_wrap_string(string, max_line_length=40)
return string.scan(/\S.{0,#{max_line_length-2}}\S(?=\s|$)|\S+/)
end
end

class Markov
Expand Down

0 comments on commit bddc5b0

Please sign in to comment.