From 7d19e2562759767c6ab34e1470729e5271e54a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 28 Dec 2013 16:50:03 +0100 Subject: [PATCH 1/2] don't crash on empty orders --- OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs | 6 +++++- OpenRA.Game/WorldUtils.cs | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index 893177e572..f332424a39 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -138,7 +138,8 @@ namespace OpenRA.Widgets void ApplyOrders(World world, int2 xy, MouseInput mi) { - if (world.OrderGenerator == null) return; + if (world.OrderGenerator == null) + return; var pos = worldRenderer.Position(xy); var orders = world.OrderGenerator.Order(world, pos.ToCPos(), mi).ToArray(); @@ -149,6 +150,9 @@ namespace OpenRA.Widgets foreach (var order in orders) { var o = order; + if (o == null) + continue; + if (!flashed) { if (o.TargetActor != null) diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index db9d5f9c6c..7dbdaa9503 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -158,7 +158,12 @@ namespace OpenRA // Find an actor with a phrase to say foreach (var o in orders) { - if (o.Subject.Destroyed) continue; + if (o == null) + continue; + + if (o.Subject.Destroyed) + continue; + foreach (var v in o.Subject.TraitsImplementing()) if (Sound.PlayVoice(v.VoicePhraseForOrder(o.Subject, o), o.Subject, o.Subject.Owner.Country.Race)) From 512358eb722cd045a05447868881ac6bf2ee2b4d Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 29 Dec 2013 11:12:09 +1300 Subject: [PATCH 2/2] Disable Move OrderTargeter if the Move order is rejected. --- OpenRA.Mods.RA/Move/Mobile.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index 8b80d292e6..887c12ec03 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -251,7 +251,7 @@ namespace OpenRA.Mods.RA.Move self.World.ScreenMap.Remove(self); } - public IEnumerable Orders { get { yield return new MoveOrderTargeter(Info); } } + public IEnumerable Orders { get { yield return new MoveOrderTargeter(self, Info); } } // Note: Returns a valid order even if the unit can't move to the target public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued) @@ -504,10 +504,12 @@ namespace OpenRA.Mods.RA.Move class MoveOrderTargeter : IOrderTargeter { readonly MobileInfo unitType; + readonly bool rejectMove; - public MoveOrderTargeter(MobileInfo unitType) + public MoveOrderTargeter(Actor self, MobileInfo unitType) { this.unitType = unitType; + this.rejectMove = !self.AcceptsOrder("Move"); } public string OrderID { get { return "Move"; } } @@ -516,7 +518,7 @@ namespace OpenRA.Mods.RA.Move public bool CanTarget(Actor self, Target target, List othersAtTarget, TargetModifiers modifiers, ref string cursor) { - if (!target.IsValidFor(self)) + if (rejectMove || !target.IsValidFor(self)) return false; var location = target.CenterPosition.ToCPos();