Split facing into its own interface; fix husks

This commit is contained in:
Paul Chote
2010-07-31 23:38:36 +12:00
parent 207ee49da3
commit d29e3f3f0e
29 changed files with 81 additions and 90 deletions

View File

@@ -15,7 +15,6 @@ namespace OpenRA.Traits.Activities
public class Turn : IActivity public class Turn : IActivity
{ {
public IActivity NextActivity { get; set; } public IActivity NextActivity { get; set; }
int desiredFacing; int desiredFacing;
public Turn( int desiredFacing ) public Turn( int desiredFacing )
@@ -25,22 +24,18 @@ namespace OpenRA.Traits.Activities
public IActivity Tick( Actor self ) public IActivity Tick( Actor self )
{ {
var mobile = self.traits.Get<IMove>(); var facing = self.traits.Get<IFacing>();
var ROT = self.traits.Get<IMove>().ROT;
if( desiredFacing == mobile.Facing ) if( desiredFacing == facing.Facing )
return NextActivity; return NextActivity;
facing.Facing = Util.TickFacing(facing.Facing, desiredFacing, facing.ROT);
mobile.Facing = Util.TickFacing(mobile.Facing, desiredFacing, ROT);
return this; return this;
} }
public void Cancel( Actor self ) public void Cancel( Actor self )
{ {
var mobile = self.traits.Get<IMove>(); desiredFacing = self.traits.Get<IFacing>().Facing;
desiredFacing = mobile.Facing;
NextActivity = null; NextActivity = null;
} }
} }

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Traits
public virtual object Create(ActorInitializer init) { return new Mobile(init, this); } public virtual object Create(ActorInitializer init) { return new Mobile(init, this); }
} }
public class Mobile : IIssueOrder, IResolveOrder, IOrderCursor, IOrderVoice, IOccupySpace, IMove, INudge public class Mobile : IIssueOrder, IResolveOrder, IOrderCursor, IOrderVoice, IOccupySpace, IMove, IFacing, INudge
{ {
public readonly Actor self; public readonly Actor self;
public readonly MobileInfo Info; public readonly MobileInfo Info;

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Traits
public virtual int CreationFacing( Actor self, Actor newUnit ) public virtual int CreationFacing( Actor self, Actor newUnit )
{ {
return newUnit.traits.Get<IMove>().InitialFacing; return newUnit.traits.Get<IFacing>().InitialFacing;
} }
public virtual bool Produce( Actor self, ActorInfo producee ) public virtual bool Produce( Actor self, ActorInfo producee )
@@ -56,7 +56,7 @@ namespace OpenRA.Traits
return false; return false;
var newUnit = self.World.CreateActor( producee.Name, location.Value, self.Owner ); var newUnit = self.World.CreateActor( producee.Name, location.Value, self.Owner );
newUnit.traits.Get<IMove>().Facing = CreationFacing( self, newUnit ); ; newUnit.traits.Get<IFacing>().Facing = CreationFacing( self, newUnit ); ;
var pi = self.Info.Traits.Get<ProductionInfo>(); var pi = self.Info.Traits.Get<ProductionInfo>();
var rp = self.traits.GetOrDefault<RallyPoint>(); var rp = self.traits.GetOrDefault<RallyPoint>();

View File

@@ -110,8 +110,12 @@ namespace OpenRA.Traits
float MovementCostForCell(Actor self, int2 cell); float MovementCostForCell(Actor self, int2 cell);
float MovementSpeedForCell(Actor self, int2 cell); float MovementSpeedForCell(Actor self, int2 cell);
IEnumerable<float2> GetCurrentPath(Actor self); IEnumerable<float2> GetCurrentPath(Actor self);
int ROT { get; }
int Altitude { get; set; } int Altitude { get; set; }
}
public interface IFacing
{
int ROT { get; }
int Facing { get; set; } int Facing { get; set; }
int InitialFacing { get; } int InitialFacing { get; }
} }

View File

@@ -23,20 +23,20 @@ namespace OpenRA.Traits
[Sync] [Sync]
public int turretFacing = 0; public int turretFacing = 0;
public int? desiredFacing; public int? desiredFacing;
TurretedInfo Info; TurretedInfo info;
IMove Move; IFacing facing;
public Turreted(Actor self, TurretedInfo info) public Turreted(Actor self, TurretedInfo info)
{ {
Info = info; this.info = info;
turretFacing = info.InitialFacing; turretFacing = info.InitialFacing;
Move = self.traits.GetOrDefault<IMove>(); facing = self.traits.GetOrDefault<IFacing>();
} }
public void Tick( Actor self ) public void Tick( Actor self )
{ {
var df = desiredFacing ?? ( Move != null ? Move.Facing : turretFacing ); var df = desiredFacing ?? ( facing != null ? facing.Facing : turretFacing );
turretFacing = Util.TickFacing(turretFacing, df, Info.ROT); turretFacing = Util.TickFacing(turretFacing, df, info.ROT);
} }
} }
} }

View File

@@ -40,9 +40,8 @@ namespace OpenRA.Mods.Cnc
{ {
var a = w.CreateActor("C17", startPos, owner); var a = w.CreateActor("C17", startPos, owner);
var cargo = a.traits.Get<Cargo>(); var cargo = a.traits.Get<Cargo>();
var aMove = a.traits.Get<IMove>(); a.traits.Get<IFacing>().Facing = 64;
aMove.Facing = 64; a.traits.Get<IMove>().Altitude = a.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
aMove.Altitude = a.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
var newUnit = new Actor(self.World, producee.Name, new int2(0, 0), self.Owner); var newUnit = new Actor(self.World, producee.Name, new int2(0, 0), self.Owner);
cargo.Load(a, newUnit); cargo.Load(a, newUnit);
@@ -60,7 +59,7 @@ namespace OpenRA.Mods.Cnc
{ {
ww.Add(actor); ww.Add(actor);
actor.traits.Get<IMove>().SetPosition(actor, self.Location + unloadOffset); actor.traits.Get<IMove>().SetPosition(actor, self.Location + unloadOffset);
newUnit.traits.Get<IMove>().Facing = 192; newUnit.traits.Get<IFacing>().Facing = 192;
actor.CancelActivity(); actor.CancelActivity();
actor.QueueActivity(new Move(self.Location + exitOffset, self)); actor.QueueActivity(new Move(self.Location + exitOffset, self));
actor.QueueActivity(new Move(rp.rallyPoint, 0)); actor.QueueActivity(new Move(rp.rallyPoint, 0));

View File

@@ -30,8 +30,7 @@ namespace OpenRA.Mods.RA.Activities
public IActivity Tick( Actor self ) public IActivity Tick( Actor self )
{ {
var move = self.traits.Get<IMove>(); var facing = self.traits.Get<IFacing>();
if (!Target.IsValid) if (!Target.IsValid)
return NextActivity; return NextActivity;
@@ -45,7 +44,7 @@ namespace OpenRA.Mods.RA.Activities
var numDirs = (renderUnit != null) var numDirs = (renderUnit != null)
? renderUnit.anim.CurrentSequence.Facings : 8; ? renderUnit.anim.CurrentSequence.Facings : 8;
if (Util.QuantizeFacing(move.Facing, numDirs) if (Util.QuantizeFacing(facing.Facing, numDirs)
!= Util.QuantizeFacing(desiredFacing, numDirs)) != Util.QuantizeFacing(desiredFacing, numDirs))
{ {
return new Turn( desiredFacing ) { NextActivity = this }; return new Turn( desiredFacing ) { NextActivity = this };

View File

@@ -58,9 +58,9 @@ namespace OpenRA.Mods.RA.Activities
if (oldHealth != null && newHealth != null) if (oldHealth != null && newHealth != null)
newHealth.HPFraction = oldHealth.HPFraction; newHealth.HPFraction = oldHealth.HPFraction;
var move = a.traits.GetOrDefault<IMove>(); var ifacing = a.traits.GetOrDefault<IFacing>();
if (move != null) if (ifacing != null)
move.Facing = facing; ifacing.Facing = facing;
if (selected) if (selected)
w.Selection.Add(w, a); w.Selection.Add(w, a);

View File

@@ -44,9 +44,9 @@ namespace OpenRA.Mods.RA.Activities
// if we're a thing that can turn, turn to the // if we're a thing that can turn, turn to the
// right facing for the unload animation // right facing for the unload animation
var move = self.traits.GetOrDefault<IMove>(); var facing = self.traits.GetOrDefault<IFacing>();
var unloadFacing = self.Info.Traits.Get<CargoInfo>().UnloadFacing; var unloadFacing = self.Info.Traits.Get<CargoInfo>().UnloadFacing;
if (move != null && move.Facing != unloadFacing) if (facing != null && facing.Facing != unloadFacing)
return new Turn(unloadFacing) { NextActivity = this }; return new Turn(unloadFacing) { NextActivity = this };
// todo: handle the BS of open/close sequences, which are inconsistent, // todo: handle the BS of open/close sequences, which are inconsistent,

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA
public virtual object Create( ActorInitializer init ) { return new Aircraft( init , this ); } public virtual object Create( ActorInitializer init ) { return new Aircraft( init , this ); }
} }
public class Aircraft : IMove, IOccupySpace public class Aircraft : IMove, IFacing, IOccupySpace
{ {
[Sync] [Sync]
public int2 Location; public int2 Location;

View File

@@ -103,13 +103,14 @@ namespace OpenRA.Mods.RA
if( !CanAttack( self ) ) return; if( !CanAttack( self ) ) return;
var move = self.traits.GetOrDefault<IMove>(); var move = self.traits.GetOrDefault<IMove>();
var facing = self.traits.GetOrDefault<IFacing>();
foreach (var w in Weapons) foreach (var w in Weapons)
if (CheckFire(self, move, w)) if (CheckFire(self, move, facing, w))
w.FiredShot(); w.FiredShot();
} }
bool CheckFire(Actor self, IMove move, Weapon w) bool CheckFire(Actor self, IMove move, IFacing facing, Weapon w)
{ {
if (w.FireDelay > 0) return false; if (w.FireDelay > 0) return false;
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>(); var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>();
@@ -132,15 +133,15 @@ namespace OpenRA.Mods.RA
target = this.target, target = this.target,
src = (self.CenterLocation src = (self.CenterLocation
+ Combat.GetTurretPosition(self, move, w.Turret) + Combat.GetTurretPosition(self, facing, w.Turret)
+ Combat.GetBarrelPosition(self, move, w.Turret, barrel)).ToInt2(), + Combat.GetBarrelPosition(self, facing, w.Turret, barrel)).ToInt2(),
srcAltitude = move != null ? move.Altitude : 0, srcAltitude = move != null ? move.Altitude : 0,
dest = target.CenterLocation.ToInt2(), dest = target.CenterLocation.ToInt2(),
destAltitude = destMove != null ? destMove.Altitude : 0, destAltitude = destMove != null ? destMove.Altitude : 0,
facing = barrel.Facing + facing = barrel.Facing +
(self.traits.Contains<Turreted>() ? self.traits.Get<Turreted>().turretFacing : (self.traits.Contains<Turreted>() ? self.traits.Get<Turreted>().turretFacing :
move != null ? move.Facing : Util.GetFacing(target.CenterLocation - self.CenterLocation, 0)), facing != null ? facing.Facing : Util.GetFacing(target.CenterLocation - self.CenterLocation, 0)),
}; };
ScheduleDelayedAction( FireDelay( self, self.Info.Traits.Get<AttackBaseInfo>() ), () => ScheduleDelayedAction( FireDelay( self, self.Info.Traits.Get<AttackBaseInfo>() ), () =>

View File

@@ -26,10 +26,10 @@ namespace OpenRA.Mods.RA
if (!target.IsValid) return; if (!target.IsValid) return;
var move = self.traits.Get<IMove>(); var facing = self.traits.Get<IFacing>().Facing;
var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, move.Facing); var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, facing);
if (Math.Abs(facingToTarget - move.Facing) % 256 < FacingTolerance) if (Math.Abs(facingToTarget - facing) % 256 < FacingTolerance)
DoAttack(self); DoAttack(self);
} }
} }

View File

@@ -43,14 +43,13 @@ namespace OpenRA.Mods.RA
var weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()]; var weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()];
dropDelay = weapon.ROF; dropDelay = weapon.ROF;
var move = self.traits.Get<IMove>();
var args = new ProjectileArgs var args = new ProjectileArgs
{ {
srcAltitude = move.Altitude, srcAltitude = self.traits.Get<IMove>().Altitude,
destAltitude = 0, destAltitude = 0,
src = self.CenterLocation.ToInt2(), src = self.CenterLocation.ToInt2(),
dest = self.CenterLocation.ToInt2(), dest = self.CenterLocation.ToInt2(),
facing = move.Facing, facing = self.traits.Get<IFacing>().Facing,
firedBy = self, firedBy = self,
weapon = weapon weapon = weapon
}; };

View File

@@ -192,14 +192,13 @@ namespace OpenRA.Mods.RA
return Util.RotateVectorByFacing(localRecoil, facing, .7f); return Util.RotateVectorByFacing(localRecoil, facing, .7f);
} }
public static float2 GetTurretPosition(Actor self, IFacing facing, Turret turret)
public static float2 GetTurretPosition(Actor self, IMove move, Turret turret)
{ {
if(move == null) return turret.ScreenSpacePosition; /* things that don't have a rotating base don't need the turrets repositioned */ if(facing == null) return turret.ScreenSpacePosition; /* things that don't have a rotating base don't need the turrets repositioned */
var ru = self.traits.GetOrDefault<RenderUnit>(); var ru = self.traits.GetOrDefault<RenderUnit>();
var numDirs = (ru != null) ? ru.anim.CurrentSequence.Facings : 8; var numDirs = (ru != null) ? ru.anim.CurrentSequence.Facings : 8;
var bodyFacing = move.Facing; var bodyFacing = facing.Facing;
var quantizedFacing = Util.QuantizeFacing(bodyFacing, numDirs) * (256 / numDirs); var quantizedFacing = Util.QuantizeFacing(bodyFacing, numDirs) * (256 / numDirs);
return (Util.RotateVectorByFacing(turret.UnitSpacePosition, quantizedFacing, .7f) return (Util.RotateVectorByFacing(turret.UnitSpacePosition, quantizedFacing, .7f)
@@ -208,14 +207,14 @@ namespace OpenRA.Mods.RA
} }
// gets the screen-space position of a barrel. // gets the screen-space position of a barrel.
public static float2 GetBarrelPosition(Actor self, IMove move, Turret turret, Barrel barrel) public static float2 GetBarrelPosition(Actor self, IFacing facing, Turret turret, Barrel barrel)
{ {
var turreted = self.traits.GetOrDefault<Turreted>(); var turreted = self.traits.GetOrDefault<Turreted>();
if (turreted == null && move == null) if (turreted == null && facing == null)
return float2.Zero; return float2.Zero;
var turretFacing = turreted != null ? turreted.turretFacing : move.Facing; var turretFacing = turreted != null ? turreted.turretFacing : facing.Facing;
return Util.RotateVectorByFacing(barrel.Position, turretFacing, .7f); return Util.RotateVectorByFacing(barrel.Position, turretFacing, .7f);
} }

View File

@@ -34,9 +34,9 @@ namespace OpenRA.Mods.RA
var a = w.CreateActor(info.Actor, self.Location var a = w.CreateActor(info.Actor, self.Location
+ info.SpawnOffset, self.Owner); + info.SpawnOffset, self.Owner);
var move = a.traits.GetOrDefault<IMove>(); var facing = a.traits.GetOrDefault<IFacing>();
if (move != null) if (facing != null)
move.Facing = info.Facing; facing.Facing = info.Facing;
if (info.InitialActivity != null) if (info.InitialActivity != null)
a.QueueActivity(Game.CreateObject<IActivity>(info.InitialActivity)); a.QueueActivity(Game.CreateObject<IActivity>(info.InitialActivity));

View File

@@ -18,11 +18,16 @@ namespace OpenRA.Mods.RA
public object Create( ActorInitializer init ) { return new Husk( init ); } public object Create( ActorInitializer init ) { return new Husk( init ); }
} }
class Husk : IOccupySpace class Husk : IOccupySpace, IFacing
{ {
Actor self; Actor self;
[Sync] [Sync]
int2 location; int2 location;
[Sync]
public int Facing { get; set; }
public int ROT { get { return 0; } }
public int InitialFacing { get { return 0; } }
public Husk(ActorInitializer init) public Husk(ActorInitializer init)
{ {

View File

@@ -28,10 +28,7 @@ namespace OpenRA.Mods.RA
var info = self.Info.Traits.Get<LeavesHuskInfo>(); var info = self.Info.Traits.Get<LeavesHuskInfo>();
var husk = w.CreateActor(info.HuskActor, self.Location, self.Owner); var husk = w.CreateActor(info.HuskActor, self.Location, self.Owner);
husk.CenterLocation = self.CenterLocation; husk.CenterLocation = self.CenterLocation;
var move = self.traits.Get<IMove>(); husk.traits.Get<IFacing>().Facing = self.traits.Get<IFacing>().Facing;
var huskMove = husk.traits.Get<IMove>();
huskMove.Altitude = move.Altitude;
huskMove.Facing = move.Facing;
var turreted = self.traits.GetOrDefault<Turreted>(); var turreted = self.traits.GetOrDefault<Turreted>();
if (turreted != null) if (turreted != null)

View File

@@ -24,10 +24,9 @@ namespace OpenRA.Mods.RA
Actor dockedHarv = null; Actor dockedHarv = null;
public void OnDock(Actor self, Actor harv, DeliverResources dockOrder) public void OnDock(Actor self, Actor harv, DeliverResources dockOrder)
{ {
var move = harv.traits.Get<IMove>();
var harvester = harv.traits.Get<Harvester>(); var harvester = harv.traits.Get<Harvester>();
if (move.Facing != 64) if (harv.traits.Get<IFacing>().Facing != 64)
harv.QueueActivity (new Turn (64)); harv.QueueActivity (new Turn (64));
harv.QueueActivity (new CallFunc (() => harv.QueueActivity (new CallFunc (() =>

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
return false; return false;
var newUnit = self.World.CreateActor( producee.Name, location.Value, self.Owner ); var newUnit = self.World.CreateActor( producee.Name, location.Value, self.Owner );
newUnit.traits.Get<IMove>().Facing = CreationFacing( self, newUnit ); ; newUnit.traits.Get<IFacing>().Facing = CreationFacing( self, newUnit ); ;
var pi = self.Info.Traits.Get<ProductionInfo>(); var pi = self.Info.Traits.Get<ProductionInfo>();
var rp = self.traits.GetOrDefault<RallyPoint>(); var rp = self.traits.GetOrDefault<RallyPoint>();

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Render
public class RenderInfantry : RenderSimple, INotifyAttack, INotifyDamage public class RenderInfantry : RenderSimple, INotifyAttack, INotifyDamage
{ {
public RenderInfantry(Actor self) public RenderInfantry(Actor self)
: base(self, () => self.traits.Get<IMove>().Facing) : base(self, () => self.traits.Get<IFacing>().Facing)
{ {
anim.Play("stand"); anim.Play("stand");
} }

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Render
public class RenderUnit : RenderSimple, INotifyDamage public class RenderUnit : RenderSimple, INotifyDamage
{ {
public RenderUnit(Actor self) public RenderUnit(Actor self)
: base(self, () => self.traits.Contains<IMove>() ? self.traits.Get<IMove>().Facing : 0) : base(self, () => self.traits.Contains<IFacing>() ? self.traits.Get<IFacing>().Facing : 0)
{ {
anim.Play("idle"); anim.Play("idle");
anims.Add( "smoke", new AnimationWithOffset( new Animation( "smoke_m" ), null, () => !isSmoking ) ); anims.Add( "smoke", new AnimationWithOffset( new Animation( "smoke_m" ), null, () => !isSmoking ) );

View File

@@ -24,19 +24,18 @@ namespace OpenRA.Mods.RA.Render
class RenderUnitRotor : RenderUnit class RenderUnitRotor : RenderUnit
{ {
public Animation rotorAnim, secondRotorAnim; public Animation rotorAnim, secondRotorAnim;
IMove move;
public RenderUnitRotor(Actor self) public RenderUnitRotor( Actor self )
: base(self) : base(self)
{ {
move = self.traits.Get<IMove>(); var facing = self.traits.Get<IFacing>();
var info = self.Info.Traits.Get<RenderUnitRotorInfo>(); var info = self.Info.Traits.Get<RenderUnitRotorInfo>();
rotorAnim = new Animation(GetImage(self)); rotorAnim = new Animation(GetImage(self));
rotorAnim.PlayRepeating("rotor"); rotorAnim.PlayRepeating("rotor");
anims.Add("rotor_1", new AnimationWithOffset( anims.Add("rotor_1", new AnimationWithOffset(
rotorAnim, rotorAnim,
() => Combat.GetTurretPosition( self, move, new Turret(info.PrimaryOffset)), () => Combat.GetTurretPosition( self, facing, new Turret(info.PrimaryOffset)),
null ) { ZOffset = 1 } ); null ) { ZOffset = 1 } );
if (info.SecondaryOffset == null) return; if (info.SecondaryOffset == null) return;
@@ -45,7 +44,7 @@ namespace OpenRA.Mods.RA.Render
secondRotorAnim.PlayRepeating("rotor2"); secondRotorAnim.PlayRepeating("rotor2");
anims.Add("rotor_2", new AnimationWithOffset( anims.Add("rotor_2", new AnimationWithOffset(
secondRotorAnim, secondRotorAnim,
() => Combat.GetTurretPosition(self, move, new Turret(info.SecondaryOffset)), () => Combat.GetTurretPosition(self, facing, new Turret(info.SecondaryOffset)),
null) { ZOffset = 1 }); null) { ZOffset = 1 });
} }
@@ -53,7 +52,7 @@ namespace OpenRA.Mods.RA.Render
{ {
base.Tick(self); base.Tick(self);
var isFlying = move.Altitude > 0; var isFlying = self.traits.Get<IMove>().Altitude > 0;
if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor")) if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor"))
return; return;

View File

@@ -24,15 +24,14 @@ namespace OpenRA.Mods.RA.Render
public RenderUnitSpinner(Actor self) public RenderUnitSpinner(Actor self)
: base(self) : base(self)
{ {
var move = self.traits.Get<IMove>();
var info = self.Info.Traits.Get<RenderUnitSpinnerInfo>(); var info = self.Info.Traits.Get<RenderUnitSpinnerInfo>();
var spinnerAnim = new Animation(GetImage(self)); var spinnerAnim = new Animation(GetImage(self));
spinnerAnim.PlayRepeating("spinner"); spinnerAnim.PlayRepeating("spinner");
anims.Add("spinner", new AnimationWithOffset( anims.Add("spinner", new AnimationWithOffset(
spinnerAnim, spinnerAnim,
() => Combat.GetTurretPosition(self, move, new Turret(info.Offset)), () => Combat.GetTurretPosition( self, self.traits.Get<IFacing>(), new Turret(info.Offset)),
null) { ZOffset = 1 }); null ) { ZOffset = 1 } );
} }
} }
} }

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Render
public RenderUnitTurreted(Actor self) public RenderUnitTurreted(Actor self)
: base(self) : base(self)
{ {
var move = self.traits.Get<IMove>(); var facing = self.traits.Get<IFacing>();
var turreted = self.traits.Get<Turreted>(); var turreted = self.traits.Get<Turreted>();
var attack = self.traits.GetOrDefault<AttackBase>(); var attack = self.traits.GetOrDefault<AttackBase>();
var attackInfo = self.Info.Traits.Get<AttackBaseInfo>(); var attackInfo = self.Info.Traits.Get<AttackBaseInfo>();
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Render
var turret = attack.Turrets[i]; var turret = attack.Turrets[i];
anims.Add( "turret_{0}".F(i), anims.Add( "turret_{0}".F(i),
new AnimationWithOffset( turretAnim, new AnimationWithOffset( turretAnim,
() => Combat.GetTurretPosition( self, move, turret ), () => Combat.GetTurretPosition( self, facing, turret ),
null) { ZOffset = 1 }); null) { ZOffset = 1 });
if (attackInfo.MuzzleFlash) if (attackInfo.MuzzleFlash)
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Render
() => (int)(turret.Recoil * 5.9f)); /* hack: dumb crap */ () => (int)(turret.Recoil * 5.9f)); /* hack: dumb crap */
anims.Add("muzzle_flash_{0}".F(i), anims.Add("muzzle_flash_{0}".F(i),
new AnimationWithOffset(muzzleFlash, new AnimationWithOffset(muzzleFlash,
() => Combat.GetTurretPosition(self, move, turret), () => Combat.GetTurretPosition(self, facing, turret),
() => turret.Recoil <= 0)); () => turret.Recoil <= 0));
} }
} }

View File

@@ -48,9 +48,8 @@ namespace OpenRA.Mods.RA
var flare = flareType != null ? w.CreateActor(flareType, order.TargetLocation, Owner) : null; var flare = flareType != null ? w.CreateActor(flareType, order.TargetLocation, Owner) : null;
var a = w.CreateActor((Info as AirstrikePowerInfo).UnitType, startPos, Owner); var a = w.CreateActor((Info as AirstrikePowerInfo).UnitType, startPos, Owner);
var aMove = a.traits.Get<IMove>(); a.traits.Get<IFacing>().Facing = Util.GetFacing(order.TargetLocation - startPos, 0);
aMove.Facing = Util.GetFacing(order.TargetLocation - startPos, 0); a.traits.Get<IMove>().Altitude = a.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
aMove.Altitude = a.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
a.traits.Get<CarpetBomb>().SetTarget(order.TargetLocation); a.traits.Get<CarpetBomb>().SetTarget(order.TargetLocation);
a.CancelActivity(); a.CancelActivity();

View File

@@ -61,9 +61,8 @@ namespace OpenRA.Mods.RA
var flare = flareType != null ? w.CreateActor(flareType, p, owner) : null; var flare = flareType != null ? w.CreateActor(flareType, p, owner) : null;
var a = w.CreateActor((Info as ParatroopersPowerInfo).UnitType, startPos, owner); var a = w.CreateActor((Info as ParatroopersPowerInfo).UnitType, startPos, owner);
var aMove = a.traits.Get<IMove>(); a.traits.Get<IFacing>().Facing = Util.GetFacing(p - startPos, 0);
aMove.Facing = Util.GetFacing(p - startPos, 0); a.traits.Get<IMove>().Altitude = a.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
aMove.Altitude = a.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
a.CancelActivity(); a.CancelActivity();
a.QueueActivity(new FlyCircle(p)); a.QueueActivity(new FlyCircle(p));

View File

@@ -46,9 +46,8 @@ namespace OpenRA.Mods.RA
var enterCell = self.World.ChooseRandomEdgeCell(); var enterCell = self.World.ChooseRandomEdgeCell();
var plane = self.World.CreateActor("U2", enterCell, self.Owner); var plane = self.World.CreateActor("U2", enterCell, self.Owner);
var planeMove = plane.traits.Get<IMove>(); plane.traits.Get<IMove>().Altitude = plane.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
planeMove.Altitude = plane.Info.Traits.Get<PlaneInfo>().CruiseAltitude; plane.traits.Get<IFacing>().Facing = Util.GetFacing(order.TargetLocation - enterCell, 0);
planeMove.Facing = Util.GetFacing(order.TargetLocation - enterCell, 0);
plane.CancelActivity(); plane.CancelActivity();
plane.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation))); plane.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation)));

View File

@@ -48,8 +48,8 @@ namespace OpenRA.Mods.RA
if (info != null) if (info != null)
{ {
alt = 0; alt = 0;
var move = self.traits.Get<IMove>(); var ifacing = self.traits.Get<IFacing>();
pos = Combat.GetTurretPosition(self, move, new Turret(info.Offset)); pos = Combat.GetTurretPosition(self, ifacing, new Turret(info.Offset));
var ru = self.traits.Get<RenderUnit>(); var ru = self.traits.Get<RenderUnit>();
v = Game.CosmeticRandom.Gauss2D(1) * info.Spread.RelOffset(); v = Game.CosmeticRandom.Gauss2D(1) * info.Spread.RelOffset();
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA
va = info.Speed; va = info.Speed;
if (!info.UseTurretFacing) InitialFacing = null; if (!info.UseTurretFacing) InitialFacing = null;
facing = InitialFacing ?? move.Facing; facing = InitialFacing ?? ifacing.Facing;
var anim = new Animation(ru.GetImage(self), () => (int)facing); var anim = new Animation(ru.GetImage(self), () => (int)facing);
anim.PlayRepeating(info.Anim); anim.PlayRepeating(info.Anim);

View File

@@ -25,11 +25,10 @@ namespace OpenRA.Mods.RA
public WithMuzzleFlash(Actor self) public WithMuzzleFlash(Actor self)
{ {
var move = self.traits.Get<IMove>();
var attackInfo = self.Info.Traits.Get<AttackBaseInfo>(); var attackInfo = self.Info.Traits.Get<AttackBaseInfo>();
var render = self.traits.Get<RenderSimple>(); var render = self.traits.Get<RenderSimple>();
muzzleFlash = new Animation(render.GetImage(self), () => move.Facing); muzzleFlash = new Animation(render.GetImage(self), () => self.traits.Get<IFacing>().Facing);
muzzleFlash.Play("muzzle"); muzzleFlash.Play("muzzle");
render.anims.Add("muzzle", new RenderSimple.AnimationWithOffset( render.anims.Add("muzzle", new RenderSimple.AnimationWithOffset(