Skip to content

Commit

Permalink
Implement Same-Speaker Voice Line Randomization
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Parik27 committed Dec 23, 2021
1 parent 196819b commit e5c0211
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build-count.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
518
520
7 changes: 7 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ OrderedRandomDuration = 45
SomeRandomDuration = 15
NoRandomDuration = 15

# Percentage of times the conversation will have random voice lines from the same character
# (For Example, Franklin voice lines will always be other Franklin voice lines)
# 100 means that all voice lines will be from the same character
# 0 means that all voice lines will be random
# Note: It doesn't apply to OrderedRandom state.
SameSpeakerPercentage = 75

# During Some Random state, this option decides how likely a voice line is to be randomized.
# If you set this to 100, it behaves the same as TrulyRandom.
# 0 is the same as NoRandom
Expand Down
7 changes: 7 additions & 0 deletions src/common/configDefault.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ OrderedRandomDuration = 45
SomeRandomDuration = 15
NoRandomDuration = 15
# Percentage of times the conversation will have random voice lines from the same character
# (For Example, Franklin voice lines will always be other Franklin voice lines)
# 100 means that all voice lines will be from the same character
# 0 means that all voice lines will be random
# Note: It doesn't apply to OrderedRandom state.
SameSpeakerPercentage = 75
# During Some Random state, this option decides how likely a voice line is to be randomized.
# If you set this to 100, it behaves the same as TrulyRandom.
# 0 is the same as NoRandom
Expand Down
46 changes: 40 additions & 6 deletions src/sounds/voicelines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class VoiceLineRandomizer
inline static size_t CurrentSeq;
inline static uint64_t PrevSeqUpdate = 0;

inline static bool SameSpeakerEnabled = false;

const SoundPair *CurrentPair = nullptr;
const SoundPair *EasterEggVoiceLine = nullptr;

Expand All @@ -81,9 +83,11 @@ class VoiceLineRandomizer
int OrderedRandomDuration = 45;
int SomeRandomDuration = 15;
int NoRandomDuration = 15;
;

int PercentageRandomOnSomeRandom = 65;
int OrderedDialogueChangeFrequency = 20;
int SameSpeakerPercentage = 75;

bool IncludeDLCLines = true;
}
Expand All @@ -109,15 +113,22 @@ class VoiceLineRandomizer
static void
UpdateState ()
{
const float EASTER_EGG_ODDS = 0.5f; // 1 in 200
const float EASTER_EGG_ODDS = 0.1f; // 1 in 1000
const int EASTER_EGG_DURATION = 60;

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

sm_State.SameSpeakerEnabled
= RandomBool (Config ().SameSpeakerPercentage);

if (RandomBool (EASTER_EGG_ODDS))
return sm_State.SetState (State::EasterEgg, EASTER_EGG_DURATION);
{
sm_State.EasterEggVoiceLine = nullptr;
return sm_State.SetState (State::EasterEgg,
EASTER_EGG_DURATION);
}

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

/*******************************************************/
static const auto &
GetRandomSoundPairNoState ()
{
if (!sm_State.SameSpeakerEnabled)
return GetRandomElement (mSounds);

/* Return voice line from same speaker */
std::vector<SoundPair *> validLines;
for (auto &i : mSounds)
{
if (i.bankHash == sm_State.CurrentPair->bankHash)
validLines.push_back (&i);
}

if (validLines.size ())
return *GetRandomElement (validLines);

return *sm_State.CurrentPair;
}

/*******************************************************/
static const auto &
GetRandomSoundPair ()
Expand All @@ -149,7 +181,7 @@ class VoiceLineRandomizer
{
/* Return a completely random voice line */
case State::TrulyRandom: {
return GetRandomElement (mSounds);
return GetRandomSoundPairNoState ();
}

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

Expand All @@ -182,9 +214,9 @@ class VoiceLineRandomizer

/* Same voice line repeating */
case State::EasterEgg: {
if (!sm_State.EasterEggVoiceLine)
if (!sm_State.EasterEggVoiceLine || RandomBool (5.0f))
sm_State.EasterEggVoiceLine
= &GetRandomElement (mSounds);
= &GetRandomSoundPairNoState ();

return *sm_State.EasterEggVoiceLine;
}
Expand Down Expand Up @@ -397,6 +429,8 @@ class VoiceLineRandomizer
&Config ().SomeRandomDuration),
std::make_pair ("NoRandomDuration",
&Config ().NoRandomDuration),
std::make_pair ("SameSpeakerPercentage",
&Config ().SameSpeakerPercentage),
std::make_pair ("PercentageRandomOnSomeRandom",
&Config ().PercentageRandomOnSomeRandom),
std::make_pair ("OrderedDialogueChangeFrequency",
Expand Down

0 comments on commit e5c0211

Please sign in to comment.