diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 4361998394..c857a32a33 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -74,6 +74,8 @@ namespace OpenRA.Traits public interface INotifyOwnerChanged { void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner); } public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); } public interface INotifyOtherCaptured { void OnActorCaptured(Actor self, Actor captured, Actor captor, Player oldOwner, Player newOwner); } + public interface INotifyHarvest { void Harvested(Actor self, ResourceType resource); } + public interface IAcceptInfiltrator { void OnInfiltrate(Actor self, Actor infiltrator); } public interface IStoreOre { int Capacity { get; } } public interface IToolTip diff --git a/OpenRA.Mods.RA/Activities/FindResources.cs b/OpenRA.Mods.RA/Activities/FindResources.cs index f48226ba57..c1240d08ec 100755 --- a/OpenRA.Mods.RA/Activities/FindResources.cs +++ b/OpenRA.Mods.RA/Activities/FindResources.cs @@ -135,16 +135,13 @@ namespace OpenRA.Mods.RA.Activities public class HarvestResource : Activity { - bool isHarvesting = false; - public override Activity Tick(Actor self) { - if (isHarvesting) return this; - var territory = self.World.WorldActor.TraitOrDefault(); if (IsCanceled) { - if (territory != null) territory.UnclaimByActor(self); + if (territory != null) + territory.UnclaimByActor(self); return NextActivity; } @@ -153,7 +150,8 @@ namespace OpenRA.Mods.RA.Activities if (harv.IsFull) { - if (territory != null) territory.UnclaimByActor(self); + if (territory != null) + territory.UnclaimByActor(self); return NextActivity; } @@ -161,19 +159,18 @@ namespace OpenRA.Mods.RA.Activities var resource = resLayer.Harvest(self.Location); if (resource == null) { - if (territory != null) territory.UnclaimByActor(self); + if (territory != null) + territory.UnclaimByActor(self); return NextActivity; } - var renderUnit = self.Trait(); /* better have one of these! */ - if (renderUnit.anim.CurrentSequence.Name != "harvest") - { - isHarvesting = true; - renderUnit.PlayCustomAnimation(self, "harvest", () => isHarvesting = false); - } - harv.AcceptResource(resource); - return this; + + foreach (var t in self.TraitsImplementing()) + t.Harvested(self, resource); + + var harvInfo = self.Info.Traits.Get(); + return Util.SequenceActivities(new Wait(harvInfo.LoadTicksPerBale), this); } } } diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index e959e489d6..a84651c080 100644 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -21,6 +21,7 @@ namespace OpenRA.Mods.RA public class HarvesterInfo : ITraitInfo { public readonly int Capacity = 28; + public readonly int LoadTicksPerBale = 4; public readonly int UnloadTicksPerBale = 4; public readonly int PipCount = 7; public readonly string[] Resources = { }; diff --git a/OpenRA.Mods.RA/Render/RenderHarvester.cs b/OpenRA.Mods.RA/Render/RenderHarvester.cs index 0bef4c064e..705ef6f668 100644 --- a/OpenRA.Mods.RA/Render/RenderHarvester.cs +++ b/OpenRA.Mods.RA/Render/RenderHarvester.cs @@ -18,22 +18,24 @@ namespace OpenRA.Mods.RA.Render { class RenderHarvesterInfo : RenderUnitInfo, Requires { - public readonly string[] ImagesByFullness = { "harvempty", "harvhalf", "harv" }; + public readonly string[] ImagesByFullness = {"harv"}; public override object Create(ActorInitializer init) { return new RenderHarvester(init.self, this); } } - class RenderHarvester : RenderUnit + class RenderHarvester : RenderUnit, INotifyHarvest { Harvester harv; RenderHarvesterInfo info; - public RenderHarvester(Actor self, RenderHarvesterInfo info) : base(self) + public RenderHarvester(Actor self, RenderHarvesterInfo info) + : base(self) { this.info = info; - harv = self.Trait(); - foreach( var image in info.ImagesByFullness ) - new Animation( image ); /* just force these to get loaded upfront */ + + // HACK: Force images to be loaded up-front + foreach (var image in info.ImagesByFullness) + new Animation(image); } public override void Tick(Actor self) @@ -42,9 +44,15 @@ namespace OpenRA.Mods.RA.Render var desiredImage = info.ImagesByFullness[desiredState]; if (anim.Name != desiredImage) - anim.ChangeImage( desiredImage, "idle" ); + anim.ChangeImage(desiredImage, "idle"); base.Tick(self); } + + public void Harvested(Actor self, ResourceType resource) + { + if (anim.CurrentSequence.Name != "harvest") + PlayCustomAnim(self, "harvest"); + } } } \ No newline at end of file diff --git a/mods/cnc/rules/vehicles.yaml b/mods/cnc/rules/vehicles.yaml index c8dd847d1b..568e1664c6 100644 --- a/mods/cnc/rules/vehicles.yaml +++ b/mods/cnc/rules/vehicles.yaml @@ -58,6 +58,7 @@ HARV: Resources: Tiberium, BlueTiberium PipCount: 7 Capacity: 20 + LoadTicksPerBale: 6 UnloadTicksPerBale: 12 SearchFromProcRadius: 24 SearchFromOrderRadius: 12 @@ -75,6 +76,8 @@ HARV: LeavesHusk: HuskActor: HARV.Husk -GainsExperience: + -RenderUnit: + RenderHarvester: APC: Inherits: ^Tank diff --git a/mods/ra/rules/vehicles.yaml b/mods/ra/rules/vehicles.yaml index 2aefff50d9..f72d8ad7bb 100644 --- a/mods/ra/rules/vehicles.yaml +++ b/mods/ra/rules/vehicles.yaml @@ -261,6 +261,7 @@ HARV: RevealsShroud: Range: 4 RenderHarvester: + ImagesByFullness: harvempty, harvhalf, harv -AttackMove: GpsDot: String:Harvester