Skip to content

Commit e5c0211

Browse files
committed
Implement Same-Speaker Voice Line Randomization
* Add a state where voice lines are randomized from the same speaker. Check config file for more information. * It affects the SomeRandom and TrulyRandom randomization states and makes them return voice lines from the same speaker.
1 parent 196819b commit e5c0211

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

build-count.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
518
1+
520

config.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ OrderedRandomDuration = 45
6767
SomeRandomDuration = 15
6868
NoRandomDuration = 15
6969

70+
# Percentage of times the conversation will have random voice lines from the same character
71+
# (For Example, Franklin voice lines will always be other Franklin voice lines)
72+
# 100 means that all voice lines will be from the same character
73+
# 0 means that all voice lines will be random
74+
# Note: It doesn't apply to OrderedRandom state.
75+
SameSpeakerPercentage = 75
76+
7077
# During Some Random state, this option decides how likely a voice line is to be randomized.
7178
# If you set this to 100, it behaves the same as TrulyRandom.
7279
# 0 is the same as NoRandom

src/common/configDefault.hh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ OrderedRandomDuration = 45
6868
SomeRandomDuration = 15
6969
NoRandomDuration = 15
7070
71+
# Percentage of times the conversation will have random voice lines from the same character
72+
# (For Example, Franklin voice lines will always be other Franklin voice lines)
73+
# 100 means that all voice lines will be from the same character
74+
# 0 means that all voice lines will be random
75+
# Note: It doesn't apply to OrderedRandom state.
76+
SameSpeakerPercentage = 75
77+
7178
# During Some Random state, this option decides how likely a voice line is to be randomized.
7279
# If you set this to 100, it behaves the same as TrulyRandom.
7380
# 0 is the same as NoRandom

src/sounds/voicelines.cc

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class VoiceLineRandomizer
6060
inline static size_t CurrentSeq;
6161
inline static uint64_t PrevSeqUpdate = 0;
6262

63+
inline static bool SameSpeakerEnabled = false;
64+
6365
const SoundPair *CurrentPair = nullptr;
6466
const SoundPair *EasterEggVoiceLine = nullptr;
6567

@@ -81,9 +83,11 @@ class VoiceLineRandomizer
8183
int OrderedRandomDuration = 45;
8284
int SomeRandomDuration = 15;
8385
int NoRandomDuration = 15;
86+
;
8487

8588
int PercentageRandomOnSomeRandom = 65;
8689
int OrderedDialogueChangeFrequency = 20;
90+
int SameSpeakerPercentage = 75;
8791

8892
bool IncludeDLCLines = true;
8993
}
@@ -109,15 +113,22 @@ class VoiceLineRandomizer
109113
static void
110114
UpdateState ()
111115
{
112-
const float EASTER_EGG_ODDS = 0.5f; // 1 in 200
116+
const float EASTER_EGG_ODDS = 0.1f; // 1 in 1000
113117
const int EASTER_EGG_DURATION = 60;
114118

115119
// Wait for next update
116120
if (time (NULL) < sm_State.NextTypeUpdate)
117121
return;
118122

123+
sm_State.SameSpeakerEnabled
124+
= RandomBool (Config ().SameSpeakerPercentage);
125+
119126
if (RandomBool (EASTER_EGG_ODDS))
120-
return sm_State.SetState (State::EasterEgg, EASTER_EGG_DURATION);
127+
{
128+
sm_State.EasterEggVoiceLine = nullptr;
129+
return sm_State.SetState (State::EasterEgg,
130+
EASTER_EGG_DURATION);
131+
}
121132

122133
// Initialise weights from duration for now
123134
static std::vector<double> Weights
@@ -139,6 +150,27 @@ class VoiceLineRandomizer
139150
#undef SET_STATE_CASE
140151
}
141152

153+
/*******************************************************/
154+
static const auto &
155+
GetRandomSoundPairNoState ()
156+
{
157+
if (!sm_State.SameSpeakerEnabled)
158+
return GetRandomElement (mSounds);
159+
160+
/* Return voice line from same speaker */
161+
std::vector<SoundPair *> validLines;
162+
for (auto &i : mSounds)
163+
{
164+
if (i.bankHash == sm_State.CurrentPair->bankHash)
165+
validLines.push_back (&i);
166+
}
167+
168+
if (validLines.size ())
169+
return *GetRandomElement (validLines);
170+
171+
return *sm_State.CurrentPair;
172+
}
173+
142174
/*******************************************************/
143175
static const auto &
144176
GetRandomSoundPair ()
@@ -149,7 +181,7 @@ class VoiceLineRandomizer
149181
{
150182
/* Return a completely random voice line */
151183
case State::TrulyRandom: {
152-
return GetRandomElement (mSounds);
184+
return GetRandomSoundPairNoState ();
153185
}
154186

155187
/* Return random dialogues in order defined in VoiceLines.txt */
@@ -171,7 +203,7 @@ class VoiceLineRandomizer
171203
/* Random a percentage of time */
172204
case State::SomeRandom: {
173205
if (RandomBool (Config ().PercentageRandomOnSomeRandom))
174-
return GetRandomElement (mSounds);
206+
return GetRandomSoundPairNoState ();
175207
[[fallthrough]];
176208
}
177209

@@ -182,9 +214,9 @@ class VoiceLineRandomizer
182214

183215
/* Same voice line repeating */
184216
case State::EasterEgg: {
185-
if (!sm_State.EasterEggVoiceLine)
217+
if (!sm_State.EasterEggVoiceLine || RandomBool (5.0f))
186218
sm_State.EasterEggVoiceLine
187-
= &GetRandomElement (mSounds);
219+
= &GetRandomSoundPairNoState ();
188220

189221
return *sm_State.EasterEggVoiceLine;
190222
}
@@ -397,6 +429,8 @@ class VoiceLineRandomizer
397429
&Config ().SomeRandomDuration),
398430
std::make_pair ("NoRandomDuration",
399431
&Config ().NoRandomDuration),
432+
std::make_pair ("SameSpeakerPercentage",
433+
&Config ().SameSpeakerPercentage),
400434
std::make_pair ("PercentageRandomOnSomeRandom",
401435
&Config ().PercentageRandomOnSomeRandom),
402436
std::make_pair ("OrderedDialogueChangeFrequency",

0 commit comments

Comments
 (0)