Add Sound.Play overloads that play a random sound from a list
This commit is contained in:
@@ -147,6 +147,16 @@ namespace OpenRA
|
||||
public ISound PlayLooped(SoundType type, string name) { return Play(type, null, name, true, WPos.Zero, 1f, true); }
|
||||
public ISound PlayLooped(SoundType type, string name, WPos pos) { return Play(type, null, name, false, pos, 1f, true); }
|
||||
|
||||
public ISound Play(SoundType type, string[] names, World world, Player player = null, float volumeModifier = 1f)
|
||||
{
|
||||
return Play(type, player, names.Random(world.LocalRandom), true, WPos.Zero, volumeModifier);
|
||||
}
|
||||
|
||||
public ISound Play(SoundType type, string[] names, World world, WPos pos, Player player = null, float volumeModifier = 1f)
|
||||
{
|
||||
return Play(type, player, names.Random(world.LocalRandom), false, pos, volumeModifier);
|
||||
}
|
||||
|
||||
public void PlayVideo(byte[] raw, int channels, int sampleBits, int sampleRate)
|
||||
{
|
||||
StopVideo();
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Cnc.Effects
|
||||
anim.PlayThen(sequence, () => Finish(world));
|
||||
|
||||
if (weapon.Report != null && weapon.Report.Any())
|
||||
Game.Sound.Play(SoundType.World, weapon.Report.Random(firedBy.World.SharedRandom), launchPos);
|
||||
Game.Sound.Play(SoundType.World, weapon.Report, world, launchPos);
|
||||
}
|
||||
|
||||
public void Tick(World world)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) { }
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace OpenRA.Mods.D2k.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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user