From 7352290c9476482bad9c1771286d18c9486857f9 Mon Sep 17 00:00:00 2001 From: atlimit8 Date: Wed, 23 Sep 2015 15:50:48 -0500 Subject: [PATCH] Move SpawnActorOnDeath to OpenRA.Mods.Common & fix spawned death actor teleportation --- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 7 +++- OpenRA.Mods.Common/Traits/Husk.cs | 7 +++- OpenRA.Mods.Common/Traits/Mobile.cs | 12 ++++++- .../Traits/SpawnActorOnDeath.cs | 33 ++----------------- OpenRA.Mods.Common/Traits/Turreted.cs | 15 ++++++++- OpenRA.Mods.Common/TraitsInterfaces.cs | 6 ++++ OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 - OpenRA.Mods.RA/Traits/Chronoshiftable.cs | 23 ++++++++++++- 9 files changed, 69 insertions(+), 36 deletions(-) rename {OpenRA.Mods.RA => OpenRA.Mods.Common}/Traits/SpawnActorOnDeath.cs (74%) diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 83eed25a60..ecc12a91e3 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -701,6 +701,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 5176edb85a..5d34afa073 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits bool IOccupySpaceInfo.SharesCell { get { return false; } } } - public class Aircraft : ITick, ISync, IFacing, IPositionable, IMove, IIssueOrder, IResolveOrder, IOrderVoice, + public class Aircraft : ITick, ISync, IFacing, IPositionable, IMove, IIssueOrder, IResolveOrder, IOrderVoice, IDeathActorInitModifier, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyActorDisposing { static readonly Pair[] NoCells = { }; @@ -328,6 +328,11 @@ namespace OpenRA.Mods.Common.Traits yield return new Repair(a); } + public void ModifyDeathActorInit(Actor self, TypeDictionary init) + { + init.Add(new FacingInit(Facing)); + } + #region Implement IPositionable public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any) { return false; } // TODO: Handle landing diff --git a/OpenRA.Mods.Common/Traits/Husk.cs b/OpenRA.Mods.Common/Traits/Husk.cs index e1e6eac582..b5ab9c1134 100644 --- a/OpenRA.Mods.Common/Traits/Husk.cs +++ b/OpenRA.Mods.Common/Traits/Husk.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits bool IOccupySpaceInfo.SharesCell { get { return false; } } } - public class Husk : IPositionable, IFacing, ISync, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld, IDisable + public class Husk : IPositionable, IFacing, ISync, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld, IDisable, IDeathActorInitModifier { readonly HuskInfo info; readonly Actor self; @@ -127,6 +127,11 @@ namespace OpenRA.Mods.Common.Traits { get { return true; } } + + public void ModifyDeathActorInit(Actor self, TypeDictionary init) + { + init.Add(new FacingInit(Facing)); + } } public class HuskSpeedInit : IActorInit diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 2d33a2d624..79faf36081 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -304,7 +304,8 @@ namespace OpenRA.Mods.Common.Traits bool IOccupySpaceInfo.SharesCell { get { return SharesCell; } } } - public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove, IFacing, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove + public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove, IFacing, ISync, IDeathActorInitModifier, + INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove { const int AverageTicksBeforePathing = 5; const int SpreadTicksBeforePathing = 5; @@ -793,5 +794,14 @@ namespace OpenRA.Mods.Common.Traits var facing = Util.GetFacing(toPos - fromPos, Facing); return Util.SequenceActivities(new Turn(self, facing), new Drag(self, fromPos, toPos, length)); } + + public void ModifyDeathActorInit(Actor self, TypeDictionary init) + { + init.Add(new FacingInit(facing)); + + // Allows the husk to drag to its final position + if (CanEnterCell(self.Location, self, false)) + init.Add(new HuskSpeedInit(MovementSpeedForCell(self, self.Location))); + } } } diff --git a/OpenRA.Mods.RA/Traits/SpawnActorOnDeath.cs b/OpenRA.Mods.Common/Traits/SpawnActorOnDeath.cs similarity index 74% rename from OpenRA.Mods.RA/Traits/SpawnActorOnDeath.cs rename to OpenRA.Mods.Common/Traits/SpawnActorOnDeath.cs index 01661e6bd8..a8acbe4aa1 100644 --- a/OpenRA.Mods.RA/Traits/SpawnActorOnDeath.cs +++ b/OpenRA.Mods.Common/Traits/SpawnActorOnDeath.cs @@ -10,12 +10,11 @@ using System.Collections.Generic; using System.Linq; -using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Warheads; using OpenRA.Primitives; using OpenRA.Traits; -namespace OpenRA.Mods.RA.Traits +namespace OpenRA.Mods.Common.Traits { public enum OwnerType { Victim, Killer, InternalName } @@ -96,34 +95,8 @@ namespace OpenRA.Mods.RA.Traits if (info.SkipMakeAnimations) td.Add(new SkipMakeAnimsInit()); - // Allows the husk to drag to its final position - var mobile = self.TraitOrDefault(); - if (mobile != null) - { - if (!mobile.CanEnterCell(self.Location, self, false)) return; - td.Add(new HuskSpeedInit(mobile.MovementSpeedForCell(self, self.Location))); - } - - var facing = self.TraitOrDefault(); - if (facing != null) - td.Add(new FacingInit(facing.Facing)); - - var turreted = self.TraitsImplementing(); - if (turreted.Any()) - { - var turretFacings = new Dictionary(); - foreach (var t in turreted) - turretFacings.Add(t.Name, t.TurretFacing); - td.Add(new TurretFacingsInit(turretFacings)); - } - - // TODO: untie this and move to Mods.Common - var chronoshiftable = self.TraitOrDefault(); - if (chronoshiftable != null && chronoshiftable.ReturnTicks > 0) - { - td.Add(new ChronoshiftOriginInit(chronoshiftable.Origin)); - td.Add(new ChronoshiftReturnInit(chronoshiftable.ReturnTicks)); - } + foreach (var modifier in self.TraitsImplementing()) + modifier.ModifyDeathActorInit(self, td); var huskActor = self.TraitsImplementing() .Select(ihm => ihm.HuskActor(self)) diff --git a/OpenRA.Mods.Common/Traits/Turreted.cs b/OpenRA.Mods.Common/Traits/Turreted.cs index 58df1e7e2b..5b3666f324 100644 --- a/OpenRA.Mods.Common/Traits/Turreted.cs +++ b/OpenRA.Mods.Common/Traits/Turreted.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -30,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits public virtual object Create(ActorInitializer init) { return new Turreted(init, this); } } - public class Turreted : ITick, ISync, INotifyCreated + public class Turreted : ITick, ISync, INotifyCreated, IDeathActorInitModifier { readonly TurretedInfo info; AttackTurreted attack; @@ -135,6 +136,18 @@ namespace OpenRA.Mods.Common.Traits var facing = Util.QuantizeFacing(local.Yaw.Angle / 4, QuantizedFacings) * (256 / QuantizedFacings); return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)); } + + public void ModifyDeathActorInit(Actor self, TypeDictionary init) + { + var facings = init.GetOrDefault(); + if (facings == null) + { + facings = new TurretFacingsInit(); + init.Add(facings); + } + + facings.Value(self.World).Add(Name, facing.Facing); + } } public class TurretFacingInit : IActorInit diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 4fc7fd370e..26f0403e3a 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -14,6 +14,7 @@ using OpenRA.Activities; using OpenRA.Graphics; using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Graphics; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -115,4 +116,9 @@ namespace OpenRA.Mods.Common.Traits void MovementCancelled(Actor self); void RequestTransport(CPos destination, Activity afterLandActivity); } + + public interface IDeathActorInitModifier + { + void ModifyDeathActorInit(Actor self, TypeDictionary init); + } } diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index d023e3e648..aa84c96aa3 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -111,7 +111,6 @@ - diff --git a/OpenRA.Mods.RA/Traits/Chronoshiftable.cs b/OpenRA.Mods.RA/Traits/Chronoshiftable.cs index 567b4dfec2..b545740166 100644 --- a/OpenRA.Mods.RA/Traits/Chronoshiftable.cs +++ b/OpenRA.Mods.RA/Traits/Chronoshiftable.cs @@ -11,6 +11,7 @@ using System.Drawing; using OpenRA.Mods.Common.Traits; using OpenRA.Mods.RA.Activities; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.RA.Traits @@ -24,7 +25,7 @@ namespace OpenRA.Mods.RA.Traits public object Create(ActorInitializer init) { return new Chronoshiftable(init, this); } } - public class Chronoshiftable : ITick, ISync, ISelectionBar + public class Chronoshiftable : ITick, ISync, ISelectionBar, IDeathActorInitModifier { readonly ChronoshiftableInfo info; readonly Actor self; @@ -46,6 +47,9 @@ namespace OpenRA.Mods.RA.Traits if (init.Contains()) Origin = init.Get(); + + if (init.Contains()) + chronosphere = init.Get(); } public void Tick(Actor self) @@ -107,6 +111,16 @@ namespace OpenRA.Mods.RA.Traits } public Color GetColor() { return Color.White; } + + public void ModifyDeathActorInit(Actor self, TypeDictionary init) + { + if (ReturnTicks <= 0) + return; + init.Add(new ChronoshiftOriginInit(Origin)); + init.Add(new ChronoshiftReturnInit(ReturnTicks)); + if (chronosphere != self) + init.Add(new ChronoshiftChronosphereInit(chronosphere)); + } } public class ChronoshiftReturnInit : IActorInit @@ -123,4 +137,11 @@ namespace OpenRA.Mods.RA.Traits public ChronoshiftOriginInit(CPos init) { value = init; } public CPos Value(World world) { return value; } } + + public class ChronoshiftChronosphereInit : IActorInit + { + readonly Actor value; + public ChronoshiftChronosphereInit(Actor init) { value = init; } + public Actor Value(World world) { return value; } + } }