From 12a350b89fe2c88d60613e539dfc456b16d33014 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 7 Jul 2010 21:27:34 +1200 Subject: [PATCH] fix crash on selecting husks (and other things with Unit but Selectable.Voice = null) --- OpenRA.Game/Controller.cs | 7 +------ OpenRA.Game/Selection.cs | 2 +- OpenRA.Game/WorldUtils.cs | 5 +++++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/OpenRA.Game/Controller.cs b/OpenRA.Game/Controller.cs index cc45896b7a..6edd449494 100644 --- a/OpenRA.Game/Controller.cs +++ b/OpenRA.Game/Controller.cs @@ -48,11 +48,6 @@ namespace OpenRA } } - static bool HasVoice(Actor a) - { - return a.Info.Traits.Contains() && a.Info.Traits.Get().Voice != null; - } - void ApplyOrders(World world, float2 xy, MouseInput mi) { if (orderGenerator == null) return; @@ -61,7 +56,7 @@ namespace OpenRA Game.orderManager.IssueOrders( orders ); var voicedActor = orders.Select(o => o.Subject) - .FirstOrDefault(a => a.Owner == world.LocalPlayer && HasVoice(a)); + .FirstOrDefault(a => a.Owner == world.LocalPlayer && a.HasVoice()); var isMove = orders.Any(o => o.OrderString == "Move"); var isAttack = orders.Any( o => o.OrderString == "Attack" ); diff --git a/OpenRA.Game/Selection.cs b/OpenRA.Game/Selection.cs index 60c6274613..bc8782387e 100644 --- a/OpenRA.Game/Selection.cs +++ b/OpenRA.Game/Selection.cs @@ -41,7 +41,7 @@ namespace OpenRA else actors = (isCombine ? oldSelection.Union(newSelection) : newSelection).ToList(); - var voicedUnit = actors.FirstOrDefault(a => a.traits.Contains() && a.Owner == world.LocalPlayer); + var voicedUnit = actors.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.HasVoice()); Sound.PlayVoice("Select", voicedUnit); foreach (var ns in world.WorldActor.traits.WithInterface()) diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 1e927ceb14..8e0dded95c 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -222,5 +222,10 @@ namespace OpenRA return "{0:D2}:{1:D2}".F(minutes, seconds % 60); } + + public static bool HasVoice(this Actor a) + { + return a.Info.Traits.Contains() && a.Info.Traits.Get().Voice != null; + } } }