Remove harvester dependency on RenderUnit.

This commit is contained in:
Paul Chote
2013-06-22 16:58:40 +12:00
parent 6d24eb14d7
commit 80c3cf479d
6 changed files with 34 additions and 22 deletions

View File

@@ -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

View File

@@ -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<ResourceClaimLayer>();
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<RenderUnit>(); /* 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<INotifyHarvest>())
t.Harvested(self, resource);
var harvInfo = self.Info.Traits.Get<HarvesterInfo>();
return Util.SequenceActivities(new Wait(harvInfo.LoadTicksPerBale), this);
}
}
}

View File

@@ -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 = { };

View File

@@ -18,22 +18,24 @@ namespace OpenRA.Mods.RA.Render
{
class RenderHarvesterInfo : RenderUnitInfo, Requires<HarvesterInfo>
{
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<Harvester>();
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");
}
}
}

View File

@@ -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

View File

@@ -261,6 +261,7 @@ HARV:
RevealsShroud:
Range: 4
RenderHarvester:
ImagesByFullness: harvempty, harvhalf, harv
-AttackMove:
GpsDot:
String:Harvester