From 7c146a9d5d8d0b975aea84e6a5ab0cb7c81784c1 Mon Sep 17 00:00:00 2001 From: geckosoft Date: Sat, 13 Nov 2010 02:43:16 +0100 Subject: [PATCH] Changed: Made "Move" orders queueable --- OpenRA.Mods.RA/Move/Mobile.cs | 60 ++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index 3a2ab98a23..d6649ddefb 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using OpenRA.Effects; +using OpenRA.Mods.RA.Activities; using OpenRA.Traits.Activities; using OpenRA.FileFormats; using System.Diagnostics; @@ -169,31 +170,46 @@ namespace OpenRA.Mods.RA.Move // Couldn't find a cell return target; } - + + protected void PerformMove(Actor self, int2 targetLocation, bool queued) + { + var ph = new QueuedActivity( + (qa) => + { + int2 currentLocation = NearestMoveableCell(targetLocation); + + if (!CanEnterCell(currentLocation)) + { + if (queued) self.CancelActivity(); + return; + } + + if (!queued) self.CancelActivity(); + + ticksBeforePathing = avgTicksBeforePathing + self.World.SharedRandom.Next(-spreadTicksBeforePathing, spreadTicksBeforePathing); + + qa.Insert(new Move(currentLocation, 8)); + + if (self.Owner == self.World.LocalPlayer) + self.World.AddFrameEndTask( + w => + { + if (self.Destroyed) return; + w.Add(new MoveFlash(self.World, targetLocation)); + var line = self.TraitOrDefault(); + if (line != null) + line.SetTarget(self, Target.FromCell(currentLocation), + Color.Green); + }); + }); + + self.QueueActivity(queued ? ph : ph.Run(self)); + } + public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "Move") - { - int2 currentLocation = NearestMoveableCell(order.TargetLocation); - if (!CanEnterCell(currentLocation)) - return; - - if( !order.Queued ) self.CancelActivity(); - - self.QueueActivity(new Move(currentLocation, 8)); - - if (self.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask(w => - { - if (self.Destroyed) return; - w.Add(new MoveFlash(self.World, order.TargetLocation)); - var line = self.TraitOrDefault(); - if (line != null) - line.SetTarget(self, Target.FromCell(currentLocation), Color.Green); - }); - ticksBeforePathing = avgTicksBeforePathing + - self.World.SharedRandom.Next( -spreadTicksBeforePathing, spreadTicksBeforePathing ); - } + PerformMove(self, order.TargetLocation, order.Queued && !self.IsIdle); } public string VoicePhraseForOrder(Actor self, Order order)