diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs index 6514bd4f45..508230ce4f 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs @@ -127,11 +127,14 @@ namespace OpenRA.Mods.Common.Traits self.World.AddFrameEndTask(w => { - var isAllied = self.Owner.IsAlliedWith(self.World.RenderPlayer); + 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, self.Owner, "Speech", speech, self.Owner.Faction.InternalName); + Game.Sound.PlayNotification(self.World.Map.Rules, toPlayer, "Speech", speech, toPlayer.Faction.InternalName); 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..a9ef911c02 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs @@ -93,18 +93,14 @@ namespace OpenRA.Mods.Common.Traits { 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); - } + 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); if (!string.IsNullOrEmpty(info.ActivationSequence)) { diff --git a/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs index 3a4b4981ac..75e1cf1197 100644 --- a/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.RA/Traits/SupportPowers/ParatroopersPower.cs @@ -153,11 +153,14 @@ namespace OpenRA.Mods.RA.Traits self.World.AddFrameEndTask(w => { - var isAllied = self.Owner.IsAlliedWith(self.World.RenderPlayer); + 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, self.Owner, "Speech", speech, self.Owner.Faction.InternalName); + Game.Sound.PlayNotification(self.World.Map.Rules, toPlayer, "Speech", speech, toPlayer.Faction.InternalName); Actor distanceTestActor = null;