Skip to content

Commit

Permalink
LostArtefacts#397 TR1-3 Pitch Variance
Browse files Browse the repository at this point in the history
Adds an option to allow the game to vary the pitch on all sound effects.
  • Loading branch information
lahm86 committed Nov 10, 2022
1 parent bcd7896 commit 2fce9b2
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 3 deletions.
19 changes: 19 additions & 0 deletions TRLevelReader/Model/Base/TRSoundDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ public int NumSounds
}
}

public bool Wibble
{
get
{
return (Characteristics & 0x2000) > 0;
}
set
{
if (value)
{
Characteristics |= 0x2000;
}
else
{
Characteristics = (ushort)(Characteristics & ~0x2000);
}
}
}

public override string ToString()
{
StringBuilder sb = new StringBuilder(base.ToString());
Expand Down
19 changes: 19 additions & 0 deletions TRLevelReader/Model/TR3/TR3SoundDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ public class TR3SoundDetails : ISerializableCompact

public int NumSounds => (Characteristics & 0x00FC) >> 2; // get bits 2-7

public bool Wibble
{
get
{
return (Characteristics & 0x2000) > 0;
}
set
{
if (value)
{
Characteristics |= 0x2000;
}
else
{
Characteristics = (short)(Characteristics & ~0x2000);
}
}
}

public byte[] Serialize()
{
using (MemoryStream stream = new MemoryStream())
Expand Down
3 changes: 3 additions & 0 deletions TRRandomizerCore/Editors/RandomizerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public class RandomizerSettings
public bool LinkCreatureSFX { get; set; }
public uint UncontrolledSFXCount { get; set; }
public bool UncontrolledSFXAssaultCourse { get; set; }
public bool RandomizeWibble { get; set; }
public bool RotateStartPositionOnly { get; set; }
public bool RandomizeWaterLevels { get; set; }
public bool RandomizeSlotPositions { get; set; }
Expand Down Expand Up @@ -241,6 +242,7 @@ public void ApplyConfig(Config config)
LinkCreatureSFX = config.GetBool(nameof(LinkCreatureSFX));
UncontrolledSFXCount = config.GetUInt(nameof(UncontrolledSFXCount), 0);
UncontrolledSFXAssaultCourse = config.GetBool(nameof(UncontrolledSFXAssaultCourse));
RandomizeWibble = config.GetBool(nameof(RandomizeWibble));

RandomizeStartPosition = config.GetBool(nameof(RandomizeStartPosition));
StartPositionSeed = config.GetInt(nameof(StartPositionSeed), defaultSeed);
Expand Down Expand Up @@ -369,6 +371,7 @@ public void StoreConfig(Config config)
config[nameof(LinkCreatureSFX)] = LinkCreatureSFX;
config[nameof(UncontrolledSFXCount)] = UncontrolledSFXCount;
config[nameof(UncontrolledSFXAssaultCourse)] = UncontrolledSFXAssaultCourse;
config[nameof(RandomizeWibble)] = RandomizeWibble;

config[nameof(RandomizeStartPosition)] = RandomizeStartPosition;
config[nameof(StartPositionSeed)] = StartPositionSeed;
Expand Down
21 changes: 21 additions & 0 deletions TRRandomizerCore/Randomizers/TR1/TR1AudioRandomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public override void Randomize(int seed)

RandomizeSoundEffects(_levelInstance);

RandomizeWibble(_levelInstance);

SaveLevelInstance();

if (!TriggerProgress())
Expand Down Expand Up @@ -288,5 +290,24 @@ private short ImportSoundEffect(TRLevel level, TR1SFXDefinition definition)

return (short)(level.NumSoundDetails - 1);
}

private void RandomizeWibble(TR1CombinedLevel level)
{
if (Settings.RandomizeWibble)
{
// The engine does the actual randomization, we just tell it that every
// sound effect should be included.
foreach (TRSoundDetails details in level.Data.SoundDetails)
{
details.Wibble = true;
}

if (ScriptEditor.Edition.IsCommunityPatch)
{
(ScriptEditor.Script as TR1Script).EnablePitchedSounds = true;
ScriptEditor.SaveScript();
}
}
}
}
}
13 changes: 13 additions & 0 deletions TRRandomizerCore/Randomizers/TR2/TR2AudioRandomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public override void Randomize(int seed)

RandomizeSoundEffects(_levelInstance);

RandomizeWibble(_levelInstance);

SaveLevelInstance();

if (!TriggerProgress())
Expand Down Expand Up @@ -317,5 +319,16 @@ private short ImportSoundEffect(TR2Level level, TRSFXDefinition<TRSoundDetails>

return (short)(level.NumSoundDetails - 1);
}

private void RandomizeWibble(TR2CombinedLevel level)
{
if (Settings.RandomizeWibble)
{
foreach (TRSoundDetails details in level.Data.SoundDetails)
{
details.Wibble = true;
}
}
}
}
}
13 changes: 13 additions & 0 deletions TRRandomizerCore/Randomizers/TR3/TR3AudioRandomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public override void Randomize(int seed)

RandomizeSoundEffects(_levelInstance);

RandomizeWibble(_levelInstance);

SaveLevelInstance();

if (!TriggerProgress())
Expand Down Expand Up @@ -282,5 +284,16 @@ private short ImportSoundEffect(TR3Level level, TRSFXDefinition<TR3SoundDetails>

return (short)(level.NumSoundDetails - 1);
}

private void RandomizeWibble(TR3CombinedLevel level)
{
if (Settings.RandomizeWibble)
{
foreach (TR3SoundDetails details in level.Data.SoundDetails)
{
details.Wibble = true;
}
}
}
}
}
6 changes: 6 additions & 0 deletions TRRandomizerCore/TRRandomizerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,12 @@ public bool UncontrolledSFXAssaultCourse
set => LevelRandomizer.UncontrolledSFXAssaultCourse = value;
}

public bool RandomizeWibble
{
get => LevelRandomizer.RandomizeWibble;
set => LevelRandomizer.RandomizeWibble = value;
}

public bool RandomizeStartPosition
{
get => LevelRandomizer.RandomizeStartPosition;
Expand Down
22 changes: 20 additions & 2 deletions TRRandomizerView/Model/ControllerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ControllerOptions : INotifyPropertyChanged
private BoolItemControlClass _includeKeyItems, _includeExtraPickups, _randomizeItemTypes, _randomizeItemLocations;
private BoolItemControlClass _crossLevelEnemies, _protectMonks, _docileWillard, _swapEnemyAppearance, _allowEmptyEggs, _hideEnemies, _removeLevelEndingLarson;
private BoolItemControlClass _persistTextures, _randomizeWaterColour, _retainLevelTextures, _retainKeySpriteTextures, _retainSecretSpriteTextures;
private BoolItemControlClass _changeAmbientTracks, _includeBlankTracks, _changeTriggerTracks, _separateSecretTracks, _changeWeaponSFX, _changeCrashSFX, _changeEnemySFX, _changeDoorSFX, _linkCreatureSFX;
private BoolItemControlClass _changeAmbientTracks, _includeBlankTracks, _changeTriggerTracks, _separateSecretTracks, _changeWeaponSFX, _changeCrashSFX, _changeEnemySFX, _changeDoorSFX, _linkCreatureSFX, _randomizeWibble;
private BoolItemControlClass _persistOutfits, _removeRobeDagger, _allowGymOutfit;
private BoolItemControlClass _retainKeyItemNames, _retainLevelNames;
private BoolItemControlClass _rotateStartPosition;
Expand Down Expand Up @@ -1333,6 +1333,16 @@ public BoolItemControlClass LinkCreatureSFX
}
}

public BoolItemControlClass RandomizeWibble
{
get => _randomizeWibble;
set
{
_randomizeWibble = value;
FirePropertyChanged();
}
}

public uint UncontrolledSFXCount
{
get => _uncontrolledSFXCount;
Expand Down Expand Up @@ -2443,6 +2453,12 @@ public ControllerOptions()
Description = "Enforce the use of human sounds for human enemies and animal sounds for animal enemies."
};
BindingOperations.SetBinding(LinkCreatureSFX, BoolItemControlClass.IsActiveProperty, randomizeAudioBinding);
RandomizeWibble = new BoolItemControlClass
{
Title = "Apply maximum pitch variance",
Description = "Allow the engine to randomize the pitch of all sound effects and not just the defaults."
};
BindingOperations.SetBinding(RandomizeWibble, BoolItemControlClass.IsActiveProperty, randomizeAudioBinding);

// Outfits
Binding randomizeOutfitsBinding = new Binding(nameof(RandomizeOutfits)) { Source = this };
Expand Down Expand Up @@ -2544,7 +2560,7 @@ public ControllerOptions()
AudioBoolItemControls = new List<BoolItemControlClass>()
{
_changeAmbientTracks, _includeBlankTracks, _changeTriggerTracks, _separateSecretTracks, _changeWeaponSFX,
_changeCrashSFX, _changeEnemySFX, _changeDoorSFX, _linkCreatureSFX
_changeCrashSFX, _changeEnemySFX, _changeDoorSFX, _linkCreatureSFX, _randomizeWibble
};
OutfitBoolItemControls = new List<BoolItemControlClass>()
{
Expand Down Expand Up @@ -2669,6 +2685,7 @@ public void Load(TRRandomizerController controller)
ChangeEnemySFX.Value = _controller.ChangeEnemySFX;
ChangeDoorSFX.Value = _controller.ChangeDoorSFX;
LinkCreatureSFX.Value = _controller.LinkCreatureSFX;
RandomizeWibble.Value = _controller.RandomizeWibble;
UncontrolledSFXCount = _controller.UncontrolledSFXCount;
UncontrolledSFXAssaultCourse = _controller.UncontrolledSFXAssaultCourse;

Expand Down Expand Up @@ -2924,6 +2941,7 @@ public void Save()
_controller.ChangeEnemySFX = ChangeEnemySFX.Value;
_controller.ChangeDoorSFX = ChangeDoorSFX.Value;
_controller.LinkCreatureSFX = LinkCreatureSFX.Value;
_controller.RandomizeWibble = RandomizeWibble.Value;
_controller.UncontrolledSFXCount = UncontrolledSFXCount;
_controller.UncontrolledSFXAssaultCourse = UncontrolledSFXAssaultCourse;

Expand Down
2 changes: 1 addition & 1 deletion TRRandomizerView/Windows/Tomb1MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@
<CheckBox IsChecked="{Binding ControllerProxy.EnablePitchedSounds, Mode=TwoWay}"
VerticalAlignment="Center">
<Label Padding="0"
Content="Enable pitched sounds" />
Content="Enable pitched sounds *" />
</CheckBox>
</Border>
<Border Grid.Row="2"
Expand Down

0 comments on commit 2fce9b2

Please sign in to comment.