diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs index 6514bd4f45..6ae356a9ea 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs @@ -127,11 +127,7 @@ namespace OpenRA.Mods.Common.Traits self.World.AddFrameEndTask(w => { - var isAllied = self.Owner.IsAlliedWith(self.World.RenderPlayer); - Game.Sound.Play(isAllied ? Info.LaunchSound : Info.IncomingSound); - - var speech = isAllied ? Info.LaunchSpeechNotification : Info.IncomingSpeechNotification; - Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", speech, self.Owner.Faction.InternalName); + PlayLaunchSounds(); Actor distanceTestActor = null; for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++) diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs index acf6296ae5..2d3423b689 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs @@ -92,19 +92,7 @@ namespace OpenRA.Mods.Common.Traits public override void Activate(Actor self, Order order, SupportPowerManager manager) { base.Activate(self, order, manager); - - if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) - { - Game.Sound.Play(Info.LaunchSound); - Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", - Info.LaunchSpeechNotification, self.Owner.Faction.InternalName); - } - else - { - Game.Sound.Play(Info.IncomingSound); - Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", - Info.IncomingSpeechNotification, self.Owner.Faction.InternalName); - } + PlayLaunchSounds(); if (!string.IsNullOrEmpty(info.ActivationSequence)) { diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs index 184b65591a..48ec944a29 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs @@ -120,5 +120,17 @@ namespace OpenRA.Mods.Common.Traits Info.RadarPingDuration); } } + + public virtual void PlayLaunchSounds() + { + var renderPlayer = Self.World.RenderPlayer; + var isAllied = Self.Owner.IsAlliedWith(renderPlayer); + Game.Sound.Play(isAllied ? Info.LaunchSound : Info.IncomingSound); + + // IsAlliedWith returns true if renderPlayer is null, so we are safe here. + var toPlayer = isAllied ? renderPlayer ?? Self.Owner : renderPlayer; + var speech = isAllied ? Info.LaunchSpeechNotification : Info.IncomingSpeechNotification; + Game.Sound.PlayNotification(Self.World.Map.Rules, toPlayer, "Speech", speech, toPlayer.Faction.InternalName); + } } } diff --git a/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs index 3a4b4981ac..a48efa983a 100644 --- a/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs @@ -153,11 +153,7 @@ namespace OpenRA.Mods.RA.Traits self.World.AddFrameEndTask(w => { - var isAllied = self.Owner.IsAlliedWith(self.World.RenderPlayer); - Game.Sound.Play(isAllied ? Info.LaunchSound : Info.IncomingSound); - - var speech = isAllied ? Info.LaunchSpeechNotification : Info.IncomingSpeechNotification; - Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", speech, self.Owner.Faction.InternalName); + PlayLaunchSounds(); Actor distanceTestActor = null;