From c1f522db636d9765e14e3f93c8144d898f891eb5 Mon Sep 17 00:00:00 2001 From: Curtis S Date: Thu, 15 Sep 2011 20:49:33 -0600 Subject: [PATCH] Fix #1157: Removed HARV minining from cell in front / using MoveAdjacentTo in logic. Was causing harvesters to get stuck - need to revisit this. --- OpenRA.Mods.RA/Activities/FindResources.cs | 59 ++++++++++++------ OpenRA.Mods.RA/Activities/HarvestResource.cs | 63 -------------------- OpenRA.Mods.RA/Harvester.cs | 13 ++-- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 6 +- 4 files changed, 51 insertions(+), 90 deletions(-) delete mode 100755 OpenRA.Mods.RA/Activities/HarvestResource.cs diff --git a/OpenRA.Mods.RA/Activities/FindResources.cs b/OpenRA.Mods.RA/Activities/FindResources.cs index 037256cb2d..0bf6eb3992 100755 --- a/OpenRA.Mods.RA/Activities/FindResources.cs +++ b/OpenRA.Mods.RA/Activities/FindResources.cs @@ -8,10 +8,10 @@ */ #endregion -using System; -using System.Collections.Generic; -using System.Drawing; using System.Linq; +using System.Drawing; +using System.Collections.Generic; +using OpenRA.Mods.RA.Render; using OpenRA.Traits; using OpenRA.Traits.Activities; using OpenRA.Mods.RA.Move; @@ -20,36 +20,61 @@ namespace OpenRA.Mods.RA.Activities { public class FindResources : Activity { - public override Activity Tick( Actor self ) + public override Activity Tick(Actor self) { - if( IsCanceled || NextActivity != null) return NextActivity; + if (IsCanceled || NextActivity != null) return NextActivity; var harv = self.Trait(); - if( harv.IsFull ) - return Util.SequenceActivities( new DeliverResources(), NextActivity ); + if (harv.IsFull) + return Util.SequenceActivities(new DeliverResources(), NextActivity); - var mobileInfo = self.Info.Traits.Get(); var harvInfo = self.Info.Traits.Get(); + var mobile = self.Trait(); + var mobileInfo = self.Info.Traits.Get(); var res = self.World.WorldActor.Trait(); - - Func canHarvest = loc => loc != self.Location && - res.GetResource(loc) != null && - harvInfo.Resources.Contains( res.GetResource(loc).info.Name ); - var path = self.World.WorldActor.Trait().FindPath(PathSearch.Search(self.World, mobileInfo, self.Owner, true) - .WithHeuristic(loc => canHarvest(loc) ? 0 : 1) - .FromPoint(self.Location)); + .WithHeuristic(loc => (res.GetResource(loc) != null && harvInfo.Resources.Contains(res.GetResource(loc).info.Name)) ? 0 : 1) + .FromPoint(self.Location)); if (path.Count == 0) return NextActivity; self.SetTargetLine(Target.FromCell(path[0]), Color.Red, false); - return Util.SequenceActivities( new MoveAdjacentTo(Target.FromCell(path[0])), new HarvestResource(self, path[0]), this ); + return Util.SequenceActivities(mobile.MoveTo(path[0], 1), new HarvestResource(), this); } - public override IEnumerable GetTargets( Actor self ) + public override IEnumerable GetTargets(Actor self) { yield return Target.FromPos(self.Location); } } + + public class HarvestResource : Activity + { + bool isHarvesting = false; + + public override Activity Tick(Actor self) + { + if (isHarvesting) return this; + if (IsCanceled) return NextActivity; + var harv = self.Trait(); + harv.LastHarvestedCell = self.Location; + + if (harv.IsFull) + return NextActivity; + + var renderUnit = self.Trait(); /* better have one of these! */ + var resource = self.World.WorldActor.Trait().Harvest(self.Location); + if (resource == null) + return NextActivity; + + if (renderUnit.anim.CurrentSequence.Name != "harvest") + { + isHarvesting = true; + renderUnit.PlayCustomAnimation(self, "harvest", () => isHarvesting = false); + } + harv.AcceptResource(resource); + return this; + } + } } diff --git a/OpenRA.Mods.RA/Activities/HarvestResource.cs b/OpenRA.Mods.RA/Activities/HarvestResource.cs deleted file mode 100755 index 3a1984838f..0000000000 --- a/OpenRA.Mods.RA/Activities/HarvestResource.cs +++ /dev/null @@ -1,63 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see COPYING. - */ -#endregion - -using OpenRA.Traits; -using OpenRA.Traits.Activities; -using OpenRA.Mods.RA.Render; - -namespace OpenRA.Mods.RA.Activities -{ - public class HarvestResource : Activity - { - Harvester harv; - IFacing facing; - RenderUnit renderUnit; - ResourceLayer resourceLayer; - bool isHarvesting = false; - int2 harvestCell; - - public HarvestResource(Actor self, int2 cell) - { - harv = self.Trait(); - facing = self.Trait(); - renderUnit = self.Trait(); - resourceLayer = self.World.WorldActor.Trait(); - harvestCell = cell; - } - - public override Activity Tick( Actor self ) - { - if( isHarvesting ) return this; - if( IsCanceled ) return NextActivity; - harv.LastHarvestedCell = harvestCell; - - if( harv.IsFull ) - return NextActivity; - - int2 dir = harvestCell - self.Location; - var f = Util.GetFacing( dir, facing.Facing ); - if( f != facing.Facing ) - return Util.SequenceActivities( new Turn(f), this ); - - var resource = resourceLayer.Harvest(harvestCell); - if (resource == null) - return NextActivity; - - if (renderUnit.anim.CurrentSequence.Name != "harvest") - { - isHarvesting = true; - renderUnit.PlayCustomAnimation(self, "harvest", () => isHarvesting = false); - } - - harv.AcceptResource(resource); - return this; - } - } -} diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index 304fe401da..ff29131f44 100644 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -61,9 +61,9 @@ namespace OpenRA.Mods.RA { if (LastHarvestedCell.HasValue) { - var target = Target.FromCell(LastHarvestedCell.Value); - self.QueueActivity( new MoveAdjacentTo(target) ); - self.SetTargetLine(target, Color.Red, false); + var mobile = self.Trait(); + self.QueueActivity( mobile.MoveTo(LastHarvestedCell.Value, 5) ); + self.SetTargetLine(Target.FromCell(LastHarvestedCell.Value), Color.Red, false); } self.QueueActivity( new FindResources() ); } @@ -152,12 +152,11 @@ namespace OpenRA.Mods.RA { if (order.OrderString == "Harvest") { - var target = Target.FromOrder(order); + var mobile = self.Trait(); self.CancelActivity(); - self.QueueActivity(new MoveAdjacentTo(target)); - self.QueueActivity(new HarvestResource(self, order.TargetLocation)); + self.QueueActivity(mobile.MoveTo(order.TargetLocation, 0)); self.QueueActivity(new FindResources()); - self.SetTargetLine(target, Color.Red); + self.SetTargetLine(Target.FromOrder(order), Color.Red); } else if (order.OrderString == "Deliver") { diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 3d0280ca41..fe2096d86b 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -1,4 +1,4 @@ - + Debug @@ -67,7 +67,6 @@ - @@ -334,6 +333,7 @@ + @@ -386,4 +386,4 @@ copy "$(TargetPath)" "$(SolutionDir)mods/ra/" cd "$(SolutionDir)" - + \ No newline at end of file