diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 4abc737c77..9320f9204e 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -73,6 +73,7 @@ namespace OpenRA.Traits public interface IDisable { bool Disabled { get; } } public interface IExplodeModifier { bool ShouldExplode(Actor self); } + public interface IHuskModifier { string HuskActor(Actor self); } public interface INudge { void OnNudge(Actor self, Actor nudger, bool force); } public interface IRadarSignature diff --git a/OpenRA.Mods.RA/HarvesterHuskModifier.cs b/OpenRA.Mods.RA/HarvesterHuskModifier.cs new file mode 100644 index 0000000000..47150ca1e5 --- /dev/null +++ b/OpenRA.Mods.RA/HarvesterHuskModifier.cs @@ -0,0 +1,39 @@ +#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.FileFormats; +using OpenRA.Traits; +using OpenRA.Mods.RA.Move; + +namespace OpenRA.Mods.RA +{ + public class HarvesterHuskModifierInfo : ITraitInfo, Requires + { + [ActorReference] + public readonly string FullHuskActor = null; + public readonly int FullnessThreshold = 50; + + public object Create( ActorInitializer init ) { return new HarvesterHuskModifier(this); } + } + + public class HarvesterHuskModifier : IHuskModifier + { + HarvesterHuskModifierInfo Info; + public HarvesterHuskModifier(HarvesterHuskModifierInfo info) + { + Info = info; + } + + public string HuskActor(Actor self) + { + return self.Trait().Fullness > Info.FullnessThreshold ? Info.FullHuskActor : null; + } + } +} diff --git a/OpenRA.Mods.RA/LeavesHusk.cs b/OpenRA.Mods.RA/LeavesHusk.cs index 2fbbeb1460..060fda54e7 100644 --- a/OpenRA.Mods.RA/LeavesHusk.cs +++ b/OpenRA.Mods.RA/LeavesHusk.cs @@ -8,25 +8,33 @@ */ #endregion +using System.Linq; using OpenRA.FileFormats; using OpenRA.Traits; using OpenRA.Mods.RA.Move; namespace OpenRA.Mods.RA { - class LeavesHuskInfo : TraitInfo + public class LeavesHuskInfo : ITraitInfo { [ActorReference] public readonly string HuskActor = null; + + public object Create( ActorInitializer init ) { return new LeavesHusk(this); } } - class LeavesHusk : INotifyKilled + public class LeavesHusk : INotifyKilled { + LeavesHuskInfo Info; + public LeavesHusk(LeavesHuskInfo info) + { + Info = info; + } + public void Killed(Actor self, AttackInfo e) { self.World.AddFrameEndTask(w => { - var info = self.Info.Traits.Get(); var td = new TypeDictionary() { new LocationInit( self.Location ), @@ -43,7 +51,11 @@ namespace OpenRA.Mods.RA if (mobile != null) td.Add(new HuskSpeedInit(mobile.MovementSpeedForCell(self, self.Location))); - var husk = w.CreateActor(info.HuskActor, td); + var huskActor = self.TraitsImplementing() + .Select(ihm => ihm.HuskActor(self)) + .FirstOrDefault(a => a != null); + + var husk = w.CreateActor(huskActor ?? Info.HuskActor, td); var turreted = self.TraitOrDefault(); if (turreted != null) foreach (var p in husk.TraitsImplementing()) diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 84006c9143..a99a7ed269 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -357,6 +357,7 @@ + diff --git a/mods/ra/bits/hhusk2.shp b/mods/ra/bits/hhusk2.shp new file mode 100644 index 0000000000..32ef803bdc Binary files /dev/null and b/mods/ra/bits/hhusk2.shp differ diff --git a/mods/ra/rules/vehicles.yaml b/mods/ra/rules/vehicles.yaml index 98812e075c..f9bc022a5b 100644 --- a/mods/ra/rules/vehicles.yaml +++ b/mods/ra/rules/vehicles.yaml @@ -229,7 +229,10 @@ HARV: GpsDot: String:Harvester LeavesHusk: - HuskActor: HARV.Husk + HuskActor: HARV.EmptyHusk + HarvesterHuskModifier: + FullHuskActor: HARV.FullHusk + FullnessThreshold: 50 MCV: Inherits: ^Vehicle @@ -468,13 +471,20 @@ TRUK: Speed: 6 AnimKey: turret -HARV.Husk: +HARV.FullHusk: Inherits: ^Husk Tooltip: Name: Husk (Harvester) RenderUnit: Image: hhusk +HARV.EmptyHusk: + Inherits: ^Husk + Tooltip: + Name: Husk (Harvester) + RenderUnit: + Image: hhusk2 + MCV.Husk: Inherits: ^Husk Tooltip: diff --git a/mods/ra/sequences.yaml b/mods/ra/sequences.yaml index c1bbe2f75a..583d1865bf 100644 --- a/mods/ra/sequences.yaml +++ b/mods/ra/sequences.yaml @@ -437,6 +437,11 @@ hhusk: Start: 0 Facings: 32 +hhusk2: + idle: + Start: 0 + Facings: 32 + 1tnk: idle: Start: 0