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")

This commit is contained in:
Bob
2010-01-26 12:43:23 +13:00
parent c979372d27
commit f3f8fdef90
17 changed files with 42 additions and 53 deletions

View File

@@ -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");
}
}

View File

@@ -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];

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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");
}
}
}

View File

@@ -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;

View File

@@ -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,

View File

@@ -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();

View File

@@ -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();

View File

@@ -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);
} );

View File

@@ -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");
}
}
}

View File

@@ -53,9 +53,9 @@ namespace OpenRa.Traits
_ =>
{
var isBuilding = unit.Traits.Contains<BuildingInfo>();
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 )

View File

@@ -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); }

View File

@@ -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()
{

View File

@@ -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();

View File

@@ -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<PipType> GetPips(Actor self)

View File

@@ -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<OwnedActorInfo>().WaterBound
? "navylst1.aud" : "unitlst1.aud");
Sound.PlayToPlayer(self.Owner,
self.Info.Traits.Get<OwnedActorInfo>().WaterBound ? "navylst1.aud" : "unitlst1.aud");
}
}
}