diff --git a/OpenRA.Mods.RA/Activities/Harvest.cs b/OpenRA.Mods.RA/Activities/Harvest.cs index 2d72e74418..084c229169 100755 --- a/OpenRA.Mods.RA/Activities/Harvest.cs +++ b/OpenRA.Mods.RA/Activities/Harvest.cs @@ -17,7 +17,36 @@ using System.Collections.Generic; namespace OpenRA.Mods.RA.Activities { - public class Harvest : Activity + public class FindResources : Activity + { + public override Activity Tick( Actor self ) + { + if( IsCanceled ) return NextActivity; + if( NextActivity != null ) return NextActivity; + var harv = self.Trait(); + if( harv.IsFull ) + return Util.SequenceActivities( new DeliverResources(), NextActivity ); + + var harvInfo = self.Info.Traits.Get(); + var mobile = self.Trait(); + var mobileInfo = self.Info.Traits.Get(); + var res = self.World.WorldActor.Trait(); + var path = self.World.WorldActor.Trait().FindPath(PathSearch.Search(self.World, mobileInfo, true) + .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; + return Util.SequenceActivities( mobile.MoveTo(path[0], 1), new HarvestResource(), this ); + } + + public override IEnumerable GetTargets( Actor self ) + { + yield return Target.FromPos(self.Location); + } + } + + public class HarvestResource : Activity { bool isHarvesting = false; @@ -25,21 +54,24 @@ namespace OpenRA.Mods.RA.Activities { if( isHarvesting ) return this; if( IsCanceled ) return NextActivity; - if( NextActivity != null ) return NextActivity; - var harv = self.Trait(); harv.LastHarvestedCell = self.Location; if( harv.IsFull ) - return Util.SequenceActivities( new DeliverResources(), NextActivity ); - - if (HarvestThisTile(self)) - return this; - else - { - FindMoreResource(self); 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; } bool HarvestThisTile(Actor self) @@ -59,26 +91,5 @@ namespace OpenRA.Mods.RA.Activities harv.AcceptResource(resource); return true; } - - void FindMoreResource(Actor self) - { - var mobile = self.Trait(); - var res = self.World.WorldActor.Trait(); - var harv = self.Info.Traits.Get(); - var mobileInfo = self.Info.Traits.Get(); - self.QueueActivity(mobile.MoveTo( - () => - { - return self.World.WorldActor.Trait().FindPath(PathSearch.Search(self.World, mobileInfo, true) - .WithHeuristic(loc => (res.GetResource(loc) != null && harv.Resources.Contains( res.GetResource(loc).info.Name )) ? 0 : 1) - .FromPoint(self.Location)); - })); - self.QueueActivity(new Harvest()); - } - - public override IEnumerable GetTargets( Actor self ) - { - yield return Target.FromPos(self.Location); - } } } diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index e444ca1baa..807da22482 100644 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -65,7 +65,7 @@ namespace OpenRA.Mods.RA self.QueueActivity( mobile.MoveTo(LastHarvestedCell.Value, 5) ); self.SetTargetLine(Target.FromCell(LastHarvestedCell.Value), Color.Red, false); } - self.QueueActivity( new Harvest() ); + self.QueueActivity( new FindResources() ); } Actor ClosestProc(Actor self, Actor ignore) @@ -156,7 +156,7 @@ namespace OpenRA.Mods.RA var mobile = self.Trait(); self.CancelActivity(); self.QueueActivity(mobile.MoveTo(order.TargetLocation, 0)); - self.QueueActivity(new Harvest()); + self.QueueActivity(new FindResources()); } else if (order.OrderString == "Deliver") { diff --git a/mods/cnc/rules/structures.yaml b/mods/cnc/rules/structures.yaml index 8522d7976a..79adda668c 100644 --- a/mods/cnc/rules/structures.yaml +++ b/mods/cnc/rules/structures.yaml @@ -97,7 +97,7 @@ PROC: Value: 500 FreeActor: Actor: HARV - InitialActivity: Harvest + InitialActivity: FindResources SpawnOffset: 1,2 Facing: 64