From f3f8fdef907a073f35a574110d3d89dfb2e2cf01 Mon Sep 17 00:00:00 2001 From: Bob Date: Tue, 26 Jan 2010 12:43:23 +1300 Subject: [PATCH] added Sound.PlayToPlayer. changed existing `if(localPlayer) Play()` idiom to use it. fixed two places that used Play where PlayToPlayer was correct (mcvUndeploy and "spyplane ready") --- OpenRa.Game/Player.cs | 30 +++++++++----------- OpenRa.Game/Sound.cs | 6 ++++ OpenRa.Game/Traits/Activities/DeployMcv.cs | 7 ++--- OpenRa.Game/Traits/Activities/UndeployMcv.cs | 2 +- OpenRa.Game/Traits/CanPowerDown.cs | 3 +- OpenRa.Game/Traits/ChronoshiftPower.cs | 6 ++-- OpenRa.Game/Traits/GpsPower.cs | 3 +- OpenRa.Game/Traits/IronCurtainPower.cs | 4 +-- OpenRa.Game/Traits/NukePower.cs | 4 +-- OpenRa.Game/Traits/PlaceBuilding.cs | 7 ++--- OpenRa.Game/Traits/Production.cs | 3 +- OpenRa.Game/Traits/ProductionQueue.cs | 4 +-- OpenRa.Game/Traits/RenderBuilding.cs | 4 +-- OpenRa.Game/Traits/SonarPulsePower.cs | 2 +- OpenRa.Game/Traits/SpyPlanePower.cs | 2 +- OpenRa.Game/Traits/StoresOre.cs | 3 +- OpenRa.Game/Traits/Unit.cs | 5 ++-- 17 files changed, 42 insertions(+), 53 deletions(-) diff --git a/OpenRa.Game/Player.cs b/OpenRa.Game/Player.cs index c12f96c5e1..25060cd970 100644 --- a/OpenRa.Game/Player.cs +++ b/OpenRa.Game/Player.cs @@ -88,10 +88,9 @@ namespace OpenRa void GiveAdvice(string advice) { - if (this != World.LocalPlayer) return; // todo: store the condition or something. // repeat after Rules.General.SpeakDelay, as long as the condition holds. - Sound.Play(advice); + Sound.PlayToPlayer(this, advice); } public void GiveCash( int num ) { Cash += num; } @@ -129,22 +128,19 @@ namespace OpenRa UpdateOreCapacity(); Shroud.Tick( World ); - if (this == World.LocalPlayer) - { - var totalMoney = Cash + Ore; + var totalMoney = Cash + Ore; - if (DisplayCash < totalMoney) - { - DisplayCash += Math.Min(displayCashDeltaPerFrame, - totalMoney - DisplayCash); - Sound.Play("cashup1.aud"); - } - else if (DisplayCash > totalMoney) - { - DisplayCash -= Math.Min(displayCashDeltaPerFrame, - DisplayCash - totalMoney); - Sound.Play("cashdn1.aud"); - } + if (DisplayCash < totalMoney) + { + DisplayCash += Math.Min(displayCashDeltaPerFrame, + totalMoney - DisplayCash); + Sound.PlayToPlayer(this, "cashup1.aud"); + } + else if (DisplayCash > totalMoney) + { + DisplayCash -= Math.Min(displayCashDeltaPerFrame, + DisplayCash - totalMoney); + Sound.PlayToPlayer(this, "cashdn1.aud"); } } diff --git a/OpenRa.Game/Sound.cs b/OpenRa.Game/Sound.cs index 6956d2a43f..17a0a2abc4 100644 --- a/OpenRa.Game/Sound.cs +++ b/OpenRa.Game/Sound.cs @@ -41,6 +41,12 @@ namespace OpenRa soundEngine.Play2D(sound, false); } + public static void PlayToPlayer(Player player, string name) + { + if( player == player.World.LocalPlayer ) + Play( name ); + } + public static void PlayMusic(string name) { var sound = sounds[name]; diff --git a/OpenRa.Game/Traits/Activities/DeployMcv.cs b/OpenRa.Game/Traits/Activities/DeployMcv.cs index f3bf4c9fc7..cd8d0f3e1f 100755 --- a/OpenRa.Game/Traits/Activities/DeployMcv.cs +++ b/OpenRa.Game/Traits/Activities/DeployMcv.cs @@ -12,11 +12,8 @@ namespace OpenRa.Traits.Activities { self.Health = 0; self.World.Remove( self ); - if (self.Owner == self.World.LocalPlayer) - { - Sound.Play("placbldg.aud"); - Sound.Play("build5.aud"); - } + Sound.PlayToPlayer(self.Owner, "placbldg.aud"); + Sound.PlayToPlayer(self.Owner, "build5.aud"); self.World.CreateActor( "fact", self.Location - new int2( 1, 1 ), self.Owner ); } ); return this; diff --git a/OpenRa.Game/Traits/Activities/UndeployMcv.cs b/OpenRa.Game/Traits/Activities/UndeployMcv.cs index 4f5f23c6c9..9122083777 100644 --- a/OpenRa.Game/Traits/Activities/UndeployMcv.cs +++ b/OpenRa.Game/Traits/Activities/UndeployMcv.cs @@ -26,7 +26,7 @@ namespace OpenRa.Traits.Activities rb.PlayCustomAnimBackwards(self, "make", () => self.World.AddFrameEndTask(w => DoUndeploy(w,self))); - Sound.Play("cashturn.aud"); + Sound.PlayToPlayer(self.Owner, "cashturn.aud"); started = true; } diff --git a/OpenRa.Game/Traits/CanPowerDown.cs b/OpenRa.Game/Traits/CanPowerDown.cs index a43a50f14b..57b5665fb4 100644 --- a/OpenRa.Game/Traits/CanPowerDown.cs +++ b/OpenRa.Game/Traits/CanPowerDown.cs @@ -34,8 +34,7 @@ namespace OpenRa.Traits if (order.OrderString == "PowerDown") { IsDisabled = !IsDisabled; - if (self.Owner == self.World.LocalPlayer) - Sound.Play(IsDisabled ? "bleep12.aud" : "bleep11.aud"); + Sound.PlayToPlayer(self.Owner, IsDisabled ? "bleep12.aud" : "bleep11.aud"); } } } diff --git a/OpenRa.Game/Traits/ChronoshiftPower.cs b/OpenRa.Game/Traits/ChronoshiftPower.cs index 94cc5ba2f8..8d77432ff3 100644 --- a/OpenRa.Game/Traits/ChronoshiftPower.cs +++ b/OpenRa.Game/Traits/ChronoshiftPower.cs @@ -17,8 +17,8 @@ namespace OpenRa.Traits class ChronoshiftPower : SupportPower, IResolveOrder { public ChronoshiftPower(Actor self, ChronoshiftPowerInfo info) : base(self, info) { } - protected override void OnBeginCharging() { if (Owner == Owner.World.LocalPlayer) Sound.Play("chrochr1.aud"); } - protected override void OnFinishCharging() { if (Owner == Owner.World.LocalPlayer) Sound.Play("chrordy1.aud"); } + protected override void OnBeginCharging() { Sound.PlayToPlayer(Owner, "chrochr1.aud"); } + protected override void OnFinishCharging() { Sound.PlayToPlayer(Owner, "chrordy1.aud"); } protected override void OnActivate() { Game.controller.orderGenerator = new SelectTarget(); @@ -36,7 +36,7 @@ namespace OpenRa.Traits { if (self.Owner == self.World.LocalPlayer) Game.controller.CancelInputMode(); - + // Cannot chronoshift into unexplored location if (!self.Owner.Shroud.IsExplored(order.TargetLocation)) return; diff --git a/OpenRa.Game/Traits/GpsPower.cs b/OpenRa.Game/Traits/GpsPower.cs index 4f1908c8e8..dc16b770b9 100644 --- a/OpenRa.Game/Traits/GpsPower.cs +++ b/OpenRa.Game/Traits/GpsPower.cs @@ -27,8 +27,7 @@ namespace OpenRa.Traits Owner.World.AddFrameEndTask(w => { - if (Owner == Owner.World.LocalPlayer) - Sound.Play("satlnch1.aud"); + Sound.PlayToPlayer(Owner, "satlnch1.aud"); w.Add(new SatelliteLaunch(launchSite)); w.Add(new DelayedAction((Info as GpsPowerInfo).RevealDelay * 25, diff --git a/OpenRa.Game/Traits/IronCurtainPower.cs b/OpenRa.Game/Traits/IronCurtainPower.cs index 8460659074..77adbe0e72 100644 --- a/OpenRa.Game/Traits/IronCurtainPower.cs +++ b/OpenRa.Game/Traits/IronCurtainPower.cs @@ -16,8 +16,8 @@ namespace OpenRa.Traits { public IronCurtainPower(Actor self, IronCurtainPowerInfo info) : base(self, info) { } - protected override void OnBeginCharging() { if (Owner == Owner.World.LocalPlayer) Sound.Play("ironchg1.aud"); } - protected override void OnFinishCharging() { if (Owner == Owner.World.LocalPlayer) Sound.Play("ironrdy1.aud"); } + protected override void OnBeginCharging() { Sound.PlayToPlayer(Owner, "ironchg1.aud"); } + protected override void OnFinishCharging() { Sound.PlayToPlayer(Owner, "ironrdy1.aud"); } protected override void OnActivate() { Game.controller.orderGenerator = new SelectTarget(); diff --git a/OpenRa.Game/Traits/NukePower.cs b/OpenRa.Game/Traits/NukePower.cs index fc07b3c4be..226e6b855d 100644 --- a/OpenRa.Game/Traits/NukePower.cs +++ b/OpenRa.Game/Traits/NukePower.cs @@ -14,8 +14,8 @@ namespace OpenRa.Traits { public NukePower(Actor self, NukePowerInfo info) : base(self, info) { } - protected override void OnBeginCharging() { if (Owner == Owner.World.LocalPlayer) Sound.Play("aprep1.aud"); } - protected override void OnFinishCharging() { if (Owner == Owner.World.LocalPlayer) Sound.Play("aready1.aud"); } + protected override void OnBeginCharging() { Sound.PlayToPlayer(Owner, "aprep1.aud"); } + protected override void OnFinishCharging() { Sound.PlayToPlayer(Owner, "aready1.aud"); } protected override void OnActivate() { Game.controller.orderGenerator = new SelectTarget(); diff --git a/OpenRa.Game/Traits/PlaceBuilding.cs b/OpenRa.Game/Traits/PlaceBuilding.cs index bd28b1ff04..9225100e2d 100755 --- a/OpenRa.Game/Traits/PlaceBuilding.cs +++ b/OpenRa.Game/Traits/PlaceBuilding.cs @@ -23,11 +23,8 @@ namespace OpenRa.Traits return; self.World.CreateActor( order.TargetString, order.TargetLocation, order.Player ); - if (order.Player == self.World.LocalPlayer) - { - Sound.Play("placbldg.aud"); - Sound.Play("build5.aud"); - } + Sound.PlayToPlayer(order.Player, "placbldg.aud"); + Sound.PlayToPlayer(order.Player, "build5.aud"); queue.FinishProduction(unit.Category); } ); diff --git a/OpenRa.Game/Traits/Production.cs b/OpenRa.Game/Traits/Production.cs index bc4ffb004a..ecaecaf12c 100755 --- a/OpenRa.Game/Traits/Production.cs +++ b/OpenRa.Game/Traits/Production.cs @@ -96,8 +96,7 @@ namespace OpenRa.Traits } isPrimary = true; - if (self.Owner == self.World.LocalPlayer) - Sound.Play("pribldg1.aud"); + Sound.PlayToPlayer(self.Owner, "pribldg1.aud"); } } } diff --git a/OpenRa.Game/Traits/ProductionQueue.cs b/OpenRa.Game/Traits/ProductionQueue.cs index 7f698f3ce7..20b8b218b9 100755 --- a/OpenRa.Game/Traits/ProductionQueue.cs +++ b/OpenRa.Game/Traits/ProductionQueue.cs @@ -53,9 +53,9 @@ namespace OpenRa.Traits _ => { var isBuilding = unit.Traits.Contains(); - if( !hasPlayedSound && order.Player == self.World.LocalPlayer ) + if( !hasPlayedSound ) { - Sound.Play( isBuilding ? "conscmp1.aud" : "unitrdy1.aud" ); + Sound.PlayToPlayer( order.Player, isBuilding ? "conscmp1.aud" : "unitrdy1.aud" ); hasPlayedSound = true; } if( !isBuilding ) diff --git a/OpenRa.Game/Traits/RenderBuilding.cs b/OpenRa.Game/Traits/RenderBuilding.cs index 4bbe74540d..dea269569c 100644 --- a/OpenRa.Game/Traits/RenderBuilding.cs +++ b/OpenRa.Game/Traits/RenderBuilding.cs @@ -95,9 +95,7 @@ namespace OpenRa.Traits public void Selling( Actor self ) { anim.PlayBackwardsThen( "make", null ); - - if (self.Owner == self.World.LocalPlayer) - Sound.Play("cashturn.aud"); + Sound.PlayToPlayer(self.Owner, "cashturn.aud"); } public void Sold(Actor self) { DoBib(self, true); } diff --git a/OpenRa.Game/Traits/SonarPulsePower.cs b/OpenRa.Game/Traits/SonarPulsePower.cs index a9741ced13..e20a0209aa 100644 --- a/OpenRa.Game/Traits/SonarPulsePower.cs +++ b/OpenRa.Game/Traits/SonarPulsePower.cs @@ -15,7 +15,7 @@ namespace OpenRa.Traits public SonarPulsePower(Actor self, SonarPulsePowerInfo info) : base(self, info) { } protected override void OnBeginCharging() { } - protected override void OnFinishCharging() { if (Owner == Owner.World.LocalPlayer) Sound.Play("pulse1.aud"); } + protected override void OnFinishCharging() { Sound.PlayToPlayer(Owner, "pulse1.aud"); } protected override void OnActivate() { diff --git a/OpenRa.Game/Traits/SpyPlanePower.cs b/OpenRa.Game/Traits/SpyPlanePower.cs index 9430abd2cc..d13ed824fd 100644 --- a/OpenRa.Game/Traits/SpyPlanePower.cs +++ b/OpenRa.Game/Traits/SpyPlanePower.cs @@ -16,7 +16,7 @@ namespace OpenRa.Traits { public SpyPlanePower(Actor self, SpyPlanePowerInfo info) : base(self, info) { } - protected override void OnFinishCharging() { Sound.Play("spypln1.aud"); } + protected override void OnFinishCharging() { Sound.PlayToPlayer(Owner, "spypln1.aud"); } protected override void OnActivate() { Game.controller.orderGenerator = new SelectTarget(); diff --git a/OpenRa.Game/Traits/StoresOre.cs b/OpenRa.Game/Traits/StoresOre.cs index ef99c154c9..93218ef937 100644 --- a/OpenRa.Game/Traits/StoresOre.cs +++ b/OpenRa.Game/Traits/StoresOre.cs @@ -18,8 +18,7 @@ namespace OpenRa.Traits self.Owner.TakeCash(toSteal); thief.Owner.GiveCash(toSteal); - if (self.World.LocalPlayer == thief.Owner) - Sound.Play("credit1.aud"); + Sound.PlayToPlayer(thief.Owner, "credit1.aud"); } public IEnumerable GetPips(Actor self) diff --git a/OpenRa.Game/Traits/Unit.cs b/OpenRa.Game/Traits/Unit.cs index 0c1a423afc..bacf8b40d7 100755 --- a/OpenRa.Game/Traits/Unit.cs +++ b/OpenRa.Game/Traits/Unit.cs @@ -23,9 +23,8 @@ namespace OpenRa.Traits public void Damaged(Actor self, AttackInfo e) { if (e.DamageState == DamageState.Dead) - if (self.Owner == self.World.LocalPlayer) - Sound.Play(self.Info.Traits.Get().WaterBound - ? "navylst1.aud" : "unitlst1.aud"); + Sound.PlayToPlayer(self.Owner, + self.Info.Traits.Get().WaterBound ? "navylst1.aud" : "unitlst1.aud"); } } }