Add Sound.Play overloads that play a random sound from a list

This commit is contained in:
abcdefg30
2019-04-07 23:20:20 +02:00
committed by reaperrr
parent 5f6c8ba5d3
commit 1bb319425b
15 changed files with 27 additions and 22 deletions

View File

@@ -101,7 +101,7 @@ namespace OpenRA.Mods.Common.Activities
if (!soundPlayed && aircraft.Info.TakeoffSounds.Length > 0 && self.IsAtGroundLevel())
{
Game.Sound.Play(SoundType.World, aircraft.Info.TakeoffSounds.Random(self.World.SharedRandom), aircraft.CenterPosition);
Game.Sound.Play(SoundType.World, aircraft.Info.TakeoffSounds, self.World, aircraft.CenterPosition);
soundPlayed = true;
}

View File

@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Activities
if (!soundPlayed && aircraft.Info.TakeoffSounds.Length > 0 && self.IsAtGroundLevel())
{
Game.Sound.Play(SoundType.World, aircraft.Info.TakeoffSounds.Random(self.World.SharedRandom), aircraft.CenterPosition);
Game.Sound.Play(SoundType.World, aircraft.Info.TakeoffSounds, self.World, aircraft.CenterPosition);
soundPlayed = true;
}

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Activities
if (!soundPlayed && aircraft.Info.LandingSounds.Length > 0 && !self.IsAtGroundLevel())
{
Game.Sound.Play(SoundType.World, aircraft.Info.LandingSounds.Random(self.World.SharedRandom), aircraft.CenterPosition);
Game.Sound.Play(SoundType.World, aircraft.Info.LandingSounds, self.World, aircraft.CenterPosition);
soundPlayed = true;
}

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Activities
if (!soundPlayed && aircraft.Info.LandingSounds.Length > 0 && !self.IsAtGroundLevel())
{
Game.Sound.Play(SoundType.World, aircraft.Info.LandingSounds.Random(self.World.SharedRandom), aircraft.CenterPosition);
Game.Sound.Play(SoundType.World, aircraft.Info.LandingSounds, self.World, aircraft.CenterPosition);
soundPlayed = true;
}

View File

@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Effects
{
anim.PlayRepeating(upSequence);
if (weapon.Report != null && weapon.Report.Any())
Game.Sound.Play(SoundType.World, weapon.Report.Random(firedBy.World.SharedRandom), pos);
Game.Sound.Play(SoundType.World, weapon.Report, world, pos);
world.ScreenMap.Add(this, pos, anim.Image);
isLaunched = true;

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCashTransfer.OnAcceptingCash(Actor self, Actor donor)
{
if (info.Sounds.Length > 0)
Game.Sound.Play(SoundType.World, info.Sounds.Random(self.World.SharedRandom), self.CenterPosition);
Game.Sound.Play(SoundType.World, info.Sounds, self.World, self.CenterPosition);
}
void INotifyCashTransfer.OnDeliveringCash(Actor self, Actor acceptor) { }

View File

@@ -327,10 +327,10 @@ namespace OpenRA.Mods.Common.Traits
self.World.Add(projectile);
if (args.Weapon.Report != null && args.Weapon.Report.Any())
Game.Sound.Play(SoundType.World, args.Weapon.Report.Random(self.World.SharedRandom), self.CenterPosition);
Game.Sound.Play(SoundType.World, args.Weapon.Report, self.World, self.CenterPosition);
if (Burst == args.Weapon.Burst && args.Weapon.StartBurstReport != null && args.Weapon.StartBurstReport.Any())
Game.Sound.Play(SoundType.World, args.Weapon.StartBurstReport.Random(self.World.SharedRandom), self.CenterPosition);
Game.Sound.Play(SoundType.World, args.Weapon.StartBurstReport, self.World, self.CenterPosition);
foreach (var na in notifyAttacks)
na.Attacking(self, target, this, barrel);
@@ -356,12 +356,7 @@ namespace OpenRA.Mods.Common.Traits
Burst = Weapon.Burst;
if (Weapon.AfterFireSound != null && Weapon.AfterFireSound.Any())
{
ScheduleDelayedAction(Weapon.AfterFireSoundDelay, () =>
{
Game.Sound.Play(SoundType.World, Weapon.AfterFireSound.Random(self.World.SharedRandom), self.CenterPosition);
});
}
ScheduleDelayedAction(Weapon.AfterFireSoundDelay, () => Game.Sound.Play(SoundType.World, Weapon.AfterFireSound, self.World, self.CenterPosition));
foreach (var nbc in notifyBurstComplete)
nbc.FiredBurst(self, target, this);

View File

@@ -222,7 +222,7 @@ namespace OpenRA.Mods.Common.Traits
return;
if (Info.DeploySounds != null && Info.DeploySounds.Any())
Game.Sound.Play(SoundType.World, Info.DeploySounds.Random(self.World.LocalRandom), self.CenterPosition);
Game.Sound.Play(SoundType.World, Info.DeploySounds, self.World, self.CenterPosition);
// Revoke condition that is applied while undeployed.
if (!init)
@@ -246,7 +246,7 @@ namespace OpenRA.Mods.Common.Traits
return;
if (Info.UndeploySounds != null && Info.UndeploySounds.Any())
Game.Sound.Play(SoundType.World, Info.UndeploySounds.Random(self.World.LocalRandom), self.CenterPosition);
Game.Sound.Play(SoundType.World, Info.UndeploySounds, self.World, self.CenterPosition);
if (!init)
OnUndeployStarted();

View File

@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCashTransfer.OnDeliveringCash(Actor self, Actor acceptor)
{
if (info.Sounds.Length > 0)
Game.Sound.Play(SoundType.World, info.Sounds.Random(self.World.SharedRandom), self.CenterPosition);
Game.Sound.Play(SoundType.World, info.Sounds, self.World, self.CenterPosition);
}
public class DeliversCashOrderTargeter : UnitOrderTargeter

View File

@@ -110,7 +110,7 @@ namespace OpenRA.Mods.Common.Traits
var source = Info.DamageSource == DamageSource.Self ? self : e.Attacker;
if (weapon.Report != null && weapon.Report.Any())
Game.Sound.Play(SoundType.World, weapon.Report.Random(source.World.SharedRandom), self.CenterPosition);
Game.Sound.Play(SoundType.World, weapon.Report, self.World, self.CenterPosition);
if (Info.Type == ExplosionType.Footprint && buildingInfo != null)
{

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
void PlaySound(Actor self)
{
if (info.Sounds.Any())
Game.Sound.Play(SoundType.World, info.Sounds.Random(self.World.SharedRandom), self.CenterPosition);
Game.Sound.Play(SoundType.World, info.Sounds, self.World, self.CenterPosition);
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)

View File

@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits
self.World.Add(projectile);
if (args.Weapon.Report != null && args.Weapon.Report.Any())
Game.Sound.Play(SoundType.World, args.Weapon.Report.Random(self.World.SharedRandom), self.CenterPosition);
Game.Sound.Play(SoundType.World, args.Weapon.Report, self.World, self.CenterPosition);
}
});
}