@@ -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