diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 437bf80096..30d6c152d2 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -141,10 +141,9 @@ namespace OpenRA.Traits { int ROT { get; } int Facing { get; set; } - int InitialFacing { get; } } - public interface IFacingInfo {} /* tag interface for infoclasses whose corresponding trait has IFacing */ + public interface IFacingInfo { int GetInitialFacing(); } public interface ICrushable { diff --git a/OpenRA.Mods.RA/Air/Aircraft.cs b/OpenRA.Mods.RA/Air/Aircraft.cs index b1e3eda26a..3104c922a3 100755 --- a/OpenRA.Mods.RA/Air/Aircraft.cs +++ b/OpenRA.Mods.RA/Air/Aircraft.cs @@ -80,6 +80,7 @@ namespace OpenRA.Mods.RA.Air public readonly string[] LandableTerrainTypes = { }; public virtual object Create( ActorInitializer init ) { return new Aircraft( init , this ); } + public int GetInitialFacing() { return InitialFacing; } } public class Aircraft : IMove, IFacing, IOccupySpace, ISync, INotifyKilled, IIssueOrder, IOrderVoice @@ -146,8 +147,6 @@ namespace OpenRA.Mods.RA.Air public int ROT { get { return Info.ROT; } } - public int InitialFacing { get { return Info.InitialFacing; } } - public void SetPosition(Actor self, CPos cell) { SetPxPosition( self, Util.CenterOfCell( cell ) ); diff --git a/OpenRA.Mods.RA/Husk.cs b/OpenRA.Mods.RA/Husk.cs index 9ba955a348..7c8a03c701 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -18,6 +18,8 @@ namespace OpenRA.Mods.RA class HuskInfo : ITraitInfo, IFacingInfo { public object Create( ActorInitializer init ) { return new Husk( init ); } + + public int GetInitialFacing() { return 128; } } class Husk : IOccupySpace, IFacing, ISync @@ -28,7 +30,6 @@ namespace OpenRA.Mods.RA [Sync] public int Facing { get; set; } public int ROT { get { return 0; } } - public int InitialFacing { get { return 128; } } public Husk(ActorInitializer init) { diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index 8fab43952b..f0e9dd977d 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -127,6 +127,8 @@ namespace OpenRA.Mods.RA.Move return true; } + + public int GetInitialFacing() { return InitialFacing; } } public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, IOccupySpace, IMove, IFacing, ISync @@ -150,7 +152,6 @@ namespace OpenRA.Mods.RA.Move [Sync] public int Altitude { get; set; } public int ROT { get { return Info.ROT; } } - public int InitialFacing { get { return Info.InitialFacing; } } [Sync] public PPos PxPosition { get; set; } [Sync] public CPos fromCell { get { return __fromCell; } } diff --git a/OpenRA.Mods.RA/Production.cs b/OpenRA.Mods.RA/Production.cs index e94d4dbbd8..ffdbcf8fdb 100755 --- a/OpenRA.Mods.RA/Production.cs +++ b/OpenRA.Mods.RA/Production.cs @@ -49,25 +49,27 @@ namespace OpenRA.Mods.RA public void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo) { - var newUnit = self.World.CreateActor(false, producee.Name, new TypeDictionary - { - new OwnerInit( self.Owner ), - }); - var exit = self.Location + exitinfo.ExitCellVector; var spawn = self.Trait().PxPosition + exitinfo.SpawnOffsetVector; - - var teleportable = newUnit.Trait(); - var facing = newUnit.TraitOrDefault(); - - // Set the physical position of the unit as the exit cell - teleportable.SetPosition(newUnit,exit); var to = Util.CenterOfCell(exit); - teleportable.AdjustPxPosition(newUnit, spawn); - if (facing != null) - facing.Facing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, facing.Facing) : exitinfo.Facing; - self.World.Add(newUnit); + var fi = producee.Traits.Get(); + var initialFacing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, fi.GetInitialFacing()) : exitinfo.Facing; + + var newUnit = self.World.CreateActor(producee.Name, new TypeDictionary + { + new OwnerInit(self.Owner), + new LocationInit(exit), + new FacingInit(initialFacing) + }); + + // TODO: Move this into an *Init + // TODO: We should be adjusting the actual position for aircraft, not just visuals. + var teleportable = newUnit.Trait(); + teleportable.AdjustPxPosition(newUnit, spawn); + + // TODO: Generalize this for non-mobile (e.g. aircraft) too + // Remember to update the Enter activity too var mobile = newUnit.TraitOrDefault(); if (mobile != null) {