diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs index 508230ce4f..6ae356a9ea 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs @@ -127,14 +127,7 @@ namespace OpenRA.Mods.Common.Traits self.World.AddFrameEndTask(w => { - 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); + 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 a9ef911c02..2d3423b689 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs @@ -92,15 +92,7 @@ namespace OpenRA.Mods.Common.Traits public override void Activate(Actor self, Order order, SupportPowerManager manager) { base.Activate(self, order, manager); - - 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); + 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 75e1cf1197..a48efa983a 100644 --- a/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs @@ -153,14 +153,7 @@ namespace OpenRA.Mods.RA.Traits self.World.AddFrameEndTask(w => { - 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); + PlayLaunchSounds(); Actor distanceTestActor = null;