Set produced unit position via an ActorInitializer. Fixes #3214.

This commit is contained in:
Paul Chote
2013-05-04 12:11:43 +12:00
parent 5877f72345
commit 55d5db0f02
5 changed files with 23 additions and 21 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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<IHasLocation>().PxPosition + exitinfo.SpawnOffsetVector;
var teleportable = newUnit.Trait<ITeleportable>();
var facing = newUnit.TraitOrDefault<IFacing>();
// 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<IFacingInfo>();
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<ITeleportable>();
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<Mobile>();
if (mobile != null)
{