From 08d84c5b90dedc234657562fd755ed77f10653c0 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Mon, 12 Sep 2016 14:42:45 +0200 Subject: [PATCH 1/2] Fix the support power SpeechNotifications not being played to the correct player --- .../Traits/SupportPowers/AirstrikePower.cs | 7 +++++-- .../Traits/SupportPowers/NukePower.cs | 20 ++++++++----------- .../Traits/SupportPowers/ParatroopersPower.cs | 7 +++++-- 3 files changed, 18 insertions(+), 16 deletions(-) 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; From 620e005cfdc0e245dbea55aabb00ce7d0cb8d846 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Tue, 6 Sep 2016 14:08:08 +0200 Subject: [PATCH 2/2] Create a PlayLaunchSounds method in SupportPower.cs --- .../Traits/SupportPowers/AirstrikePower.cs | 9 +-------- OpenRA.Mods.Common/Traits/SupportPowers/NukePower.cs | 10 +--------- .../Traits/SupportPowers/SupportPower.cs | 12 ++++++++++++ .../Traits/SupportPowers/ParatroopersPower.cs | 9 +-------- 4 files changed, 15 insertions(+), 25 deletions(-) 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;