Move Facing and Altitude onto IMove impls, with associated pile of cleanups

This commit is contained in:
Paul Chote
2010-07-31 22:59:43 +12:00
parent 88cb942430
commit 207ee49da3
51 changed files with 186 additions and 184 deletions

View File

@@ -136,8 +136,8 @@ namespace OpenRA
if (useAltitude) if (useAltitude)
{ {
var unit = traits.GetOrDefault<Unit>(); var move = traits.GetOrDefault<IMove>();
if (unit != null) loc -= new float2(0, unit.Altitude); if (move != null) loc -= new float2(0, move.Altitude);
} }
return new RectangleF(loc.X, loc.Y, size.X, size.Y); return new RectangleF(loc.X, loc.Y, size.X, size.Y);

View File

@@ -90,7 +90,6 @@ namespace OpenRA.Traits.Activities
public IActivity Tick( Actor self ) public IActivity Tick( Actor self )
{ {
var unit = self.traits.Get<Unit>();
var mobile = self.traits.Get<Mobile>(); var mobile = self.traits.Get<Mobile>();
if( move != null ) if( move != null )
@@ -127,8 +126,8 @@ namespace OpenRA.Traits.Activities
return this; return this;
int2 dir = nextCell.Value - mobile.fromCell; int2 dir = nextCell.Value - mobile.fromCell;
var firstFacing = Util.GetFacing( dir, unit.Facing ); var firstFacing = Util.GetFacing( dir, mobile.Facing );
if( firstFacing != unit.Facing ) if( firstFacing != mobile.Facing )
{ {
path.Add( nextCell.Value ); path.Add( nextCell.Value );
@@ -140,8 +139,8 @@ namespace OpenRA.Traits.Activities
move = new MoveFirstHalf( move = new MoveFirstHalf(
Util.CenterOfCell( mobile.fromCell ), Util.CenterOfCell( mobile.fromCell ),
Util.BetweenCells( mobile.fromCell, mobile.toCell ), Util.BetweenCells( mobile.fromCell, mobile.toCell ),
unit.Facing, mobile.Facing,
unit.Facing, mobile.Facing,
0 ); 0 );
move.TickMove( self, mobile, this ); move.TickMove( self, mobile, this );
@@ -262,9 +261,9 @@ namespace OpenRA.Traits.Activities
self.CenterLocation = float2.Lerp( from, to, frac ); self.CenterLocation = float2.Lerp( from, to, frac );
if( moveFraction >= moveFractionTotal ) if( moveFraction >= moveFractionTotal )
unit.Facing = toFacing & 0xFF; mobile.Facing = toFacing & 0xFF;
else else
unit.Facing = ( fromFacing + ( toFacing - fromFacing ) * moveFraction / moveFractionTotal ) & 0xFF; mobile.Facing = ( fromFacing + ( toFacing - fromFacing ) * moveFraction / moveFractionTotal ) & 0xFF;
} }
protected abstract MovePart OnComplete( Actor self, Mobile mobile, Move parent ); protected abstract MovePart OnComplete( Actor self, Mobile mobile, Move parent );
@@ -289,8 +288,8 @@ namespace OpenRA.Traits.Activities
var ret = new MoveFirstHalf( var ret = new MoveFirstHalf(
Util.BetweenCells( mobile.fromCell, mobile.toCell ), Util.BetweenCells( mobile.fromCell, mobile.toCell ),
Util.BetweenCells( mobile.toCell, nextCell.Value ), Util.BetweenCells( mobile.toCell, nextCell.Value ),
unit.Facing, mobile.Facing,
Util.GetNearestFacing( unit.Facing, Util.GetFacing( nextCell.Value - mobile.toCell, unit.Facing ) ), Util.GetNearestFacing( mobile.Facing, Util.GetFacing( nextCell.Value - mobile.toCell, mobile.Facing ) ),
moveFraction - moveFractionTotal ); moveFraction - moveFractionTotal );
mobile.fromCell = mobile.toCell; mobile.fromCell = mobile.toCell;
mobile.toCell = nextCell.Value; mobile.toCell = nextCell.Value;
@@ -302,8 +301,8 @@ namespace OpenRA.Traits.Activities
var ret2 = new MoveSecondHalf( var ret2 = new MoveSecondHalf(
Util.BetweenCells( mobile.fromCell, mobile.toCell ), Util.BetweenCells( mobile.fromCell, mobile.toCell ),
Util.CenterOfCell( mobile.toCell ), Util.CenterOfCell( mobile.toCell ),
unit.Facing, mobile.Facing,
unit.Facing, mobile.Facing,
moveFraction - moveFractionTotal ); moveFraction - moveFractionTotal );
mobile.fromCell = mobile.toCell; mobile.fromCell = mobile.toCell;
return ret2; return ret2;

View File

@@ -25,22 +25,22 @@ namespace OpenRA.Traits.Activities
public IActivity Tick( Actor self ) public IActivity Tick( Actor self )
{ {
var unit = self.traits.Get<Unit>(); var mobile = self.traits.Get<IMove>();
var ROT = self.traits.Get<IMove>().ROT; var ROT = self.traits.Get<IMove>().ROT;
if( desiredFacing == unit.Facing ) if( desiredFacing == mobile.Facing )
return NextActivity; return NextActivity;
Util.TickFacing(ref unit.Facing, desiredFacing, ROT); mobile.Facing = Util.TickFacing(mobile.Facing, desiredFacing, ROT);
return this; return this;
} }
public void Cancel( Actor self ) public void Cancel( Actor self )
{ {
var unit = self.traits.Get<Unit>(); var mobile = self.traits.Get<IMove>();
desiredFacing = unit.Facing; desiredFacing = mobile.Facing;
NextActivity = null; NextActivity = null;
} }
} }

View File

@@ -39,6 +39,13 @@ namespace OpenRA.Traits
public readonly Dictionary<string,float> TerrainSpeed; public readonly Dictionary<string,float> TerrainSpeed;
[Sync] [Sync]
public int Facing { get; set; }
[Sync]
public int Altitude { get; set; }
[Sync]
public int ROT { get { return Info.ROT; } }
public int InitialFacing { get { return Info.InitialFacing; } }
int2 __fromCell, __toCell; int2 __fromCell, __toCell;
public int2 fromCell public int2 fromCell
{ {
@@ -90,9 +97,6 @@ namespace OpenRA.Traits
TerrainSpeed.Add(info.TerrainTypes[i], info.TerrainSpeeds[i]); TerrainSpeed.Add(info.TerrainTypes[i], info.TerrainSpeeds[i]);
} }
} }
public int ROT { get { return Info.ROT; } }
public int InitialFacing { get { return Info.InitialFacing; } }
public void SetPosition(Actor self, int2 cell) public void SetPosition(Actor self, int2 cell)
{ {

View File

@@ -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<Unit>().Facing = CreationFacing( self, newUnit ); ; newUnit.traits.Get<IMove>().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

@@ -156,11 +156,10 @@ namespace OpenRA.Traits
{ {
if (!Game.world.LocalPlayer.PlayerActor.traits.Get<DeveloperMode>().PathDebug) return; if (!Game.world.LocalPlayer.PlayerActor.traits.Get<DeveloperMode>().PathDebug) return;
var mobile = self.traits.WithInterface<IMove>().FirstOrDefault(); var mobile = self.traits.GetOrDefault<IMove>();
if (mobile != null) if (mobile != null)
{ {
var unit = self.traits.Get<Unit>(); var alt = new float2(0, -mobile.Altitude);
var alt = (unit != null)? new float2(0, -unit.Altitude) : float2.Zero;
var path = mobile.GetCurrentPath(self); var path = mobile.GetCurrentPath(self);
var start = self.CenterLocation + alt; var start = self.CenterLocation + alt;

View File

@@ -111,6 +111,8 @@ namespace OpenRA.Traits
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 ROT { get; }
int Altitude { get; set; }
int Facing { get; set; }
int InitialFacing { get; } int InitialFacing { get; }
} }

View File

@@ -10,12 +10,12 @@
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
class TurretedInfo : ITraitInfo public class TurretedInfo : ITraitInfo
{ {
public readonly int ROT = 255; public readonly int ROT = 255;
public readonly int InitialFacing = 128; public readonly int InitialFacing = 128;
public object Create(ActorInitializer init) { return new Turreted(init.self); } public object Create(ActorInitializer init) { return new Turreted(init.self, this); }
} }
public class Turreted : ITick public class Turreted : ITick
@@ -23,16 +23,20 @@ namespace OpenRA.Traits
[Sync] [Sync]
public int turretFacing = 0; public int turretFacing = 0;
public int? desiredFacing; public int? desiredFacing;
TurretedInfo Info;
public Turreted(Actor self) IMove Move;
public Turreted(Actor self, TurretedInfo info)
{ {
turretFacing = self.Info.Traits.Get<TurretedInfo>().InitialFacing; Info = info;
turretFacing = info.InitialFacing;
Move = self.traits.GetOrDefault<IMove>();
} }
public void Tick( Actor self ) public void Tick( Actor self )
{ {
var df = desiredFacing ?? ( self.traits.Contains<Unit>() ? self.traits.Get<Unit>().Facing : turretFacing ); var df = desiredFacing ?? ( Move != null ? Move.Facing : turretFacing );
Util.TickFacing(ref turretFacing, df, self.Info.Traits.Get<TurretedInfo>().ROT); turretFacing = Util.TickFacing(turretFacing, df, Info.ROT);
} }
} }
} }

View File

@@ -20,12 +20,7 @@ namespace OpenRA.Traits
} }
public class Unit : INotifyDamage, IRadarSignature public class Unit : INotifyDamage, IRadarSignature
{ {
[Sync]
public int Facing;
[Sync]
public int Altitude;
public void Damaged(Actor self, AttackInfo e) public void Damaged(Actor self, AttackInfo e)
{ {
if (e.DamageState == DamageState.Dead) if (e.DamageState == DamageState.Dead)

View File

@@ -17,16 +17,16 @@ namespace OpenRA.Traits
{ {
public static class Util public static class Util
{ {
public static void TickFacing( ref int facing, int desiredFacing, int rot ) public static int TickFacing( int facing, int desiredFacing, int rot )
{ {
var leftTurn = ( facing - desiredFacing ) & 0xFF; var leftTurn = ( facing - desiredFacing ) & 0xFF;
var rightTurn = ( desiredFacing - facing ) & 0xFF; var rightTurn = ( desiredFacing - facing ) & 0xFF;
if( Math.Min( leftTurn, rightTurn ) < rot ) if( Math.Min( leftTurn, rightTurn ) < rot )
facing = desiredFacing & 0xFF; return desiredFacing & 0xFF;
else if( rightTurn < leftTurn ) else if( rightTurn < leftTurn )
facing = ( facing + rot ) & 0xFF; return ( facing + rot ) & 0xFF;
else else
facing = ( facing - rot ) & 0xFF; return ( facing - rot ) & 0xFF;
} }
static float2[] fvecs = Graphics.Util.MakeArray<float2>( 32, static float2[] fvecs = Graphics.Util.MakeArray<float2>( 32,

View File

@@ -84,17 +84,17 @@ namespace OpenRA.Traits
int offsetTicks = 0; int offsetTicks = 0;
public void Tick(Actor self) public void Tick(Actor self)
{ {
var unit = self.traits.Get<Unit>(); var move = self.traits.Get<IMove>();
//if (unit.Altitude <= 0) //if (unit.Altitude <= 0)
// return; // return;
if (unit.Altitude < AirInfo.CruiseAltitude) if (move.Altitude < AirInfo.CruiseAltitude)
unit.Altitude++; move.Altitude++;
if (--offsetTicks <= 0) if (--offsetTicks <= 0)
{ {
self.CenterLocation += AirInfo.InstabilityMagnitude * self.World.SharedRandom.Gauss2D(5); self.CenterLocation += AirInfo.InstabilityMagnitude * self.World.SharedRandom.Gauss2D(5);
unit.Altitude += (int)(AirInfo.InstabilityMagnitude * self.World.SharedRandom.Gauss1D(5)); move.Altitude += (int)(AirInfo.InstabilityMagnitude * self.World.SharedRandom.Gauss1D(5));
offsetTicks = AirInfo.InstabilityTicks; offsetTicks = AirInfo.InstabilityTicks;
} }
} }

View File

@@ -40,8 +40,9 @@ 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>();
a.traits.Get<Unit>().Facing = 64; var aMove = a.traits.Get<IMove>();
a.traits.Get<Unit>().Altitude = a.Info.Traits.Get<PlaneInfo>().CruiseAltitude; aMove.Facing = 64;
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);
@@ -58,8 +59,8 @@ namespace OpenRA.Mods.Cnc
self.World.AddFrameEndTask(ww => self.World.AddFrameEndTask(ww =>
{ {
ww.Add(actor); ww.Add(actor);
actor.traits.WithInterface<IMove>().FirstOrDefault().SetPosition(actor, self.Location + unloadOffset); actor.traits.Get<IMove>().SetPosition(actor, self.Location + unloadOffset);
newUnit.traits.Get<Unit>().Facing = 192; newUnit.traits.Get<IMove>().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,7 +30,7 @@ namespace OpenRA.Mods.RA.Activities
public IActivity Tick( Actor self ) public IActivity Tick( Actor self )
{ {
var unit = self.traits.Get<Unit>(); var move = self.traits.Get<IMove>();
if (!Target.IsValid) if (!Target.IsValid)
return NextActivity; return NextActivity;
@@ -45,7 +45,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(unit.Facing, numDirs) if (Util.QuantizeFacing(move.Facing, numDirs)
!= Util.QuantizeFacing(desiredFacing, numDirs)) != Util.QuantizeFacing(desiredFacing, numDirs))
{ {
return new Turn( desiredFacing ) { NextActivity = this }; return new Turn( desiredFacing ) { NextActivity = this };

View File

@@ -34,15 +34,14 @@ namespace OpenRA.Mods.RA.Activities
if (d.LengthSquared < 50) /* close enough */ if (d.LengthSquared < 50) /* close enough */
return NextActivity; return NextActivity;
var unit = self.traits.Get<Unit>(); var aircraft = self.traits.Get<Aircraft>();
var desiredFacing = Util.GetFacing(d, unit.Facing); var desiredFacing = Util.GetFacing(d, aircraft.Facing);
if (unit.Altitude == cruiseAltitude) if (aircraft.Altitude == cruiseAltitude)
Util.TickFacing(ref unit.Facing, desiredFacing, aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);
self.Info.Traits.Get<AircraftInfo>().ROT);
if (unit.Altitude < cruiseAltitude) if (aircraft.Altitude < cruiseAltitude)
++unit.Altitude; ++aircraft.Altitude;
FlyUtil.Fly(self, cruiseAltitude); FlyUtil.Fly(self, cruiseAltitude);
return this; return this;
@@ -55,16 +54,12 @@ namespace OpenRA.Mods.RA.Activities
{ {
public static void Fly(Actor self, int desiredAltitude ) public static void Fly(Actor self, int desiredAltitude )
{ {
var unit = self.traits.Get<Unit>();
var mobile = self.traits.WithInterface<IMove>().FirstOrDefault();
var speed = .2f * mobile.MovementSpeedForCell(self, self.Location);
var angle = unit.Facing / 128f * Math.PI;
var aircraft = self.traits.Get<Aircraft>(); var aircraft = self.traits.Get<Aircraft>();
var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location);
var angle = aircraft.Facing / 128f * Math.PI;
self.CenterLocation += speed * -float2.FromAngle((float)angle); self.CenterLocation += speed * -float2.FromAngle((float)angle);
aircraft.Location = Util.CellContaining(self.CenterLocation); aircraft.Location = Util.CellContaining(self.CenterLocation);
aircraft.Altitude += Math.Sign(desiredAltitude - aircraft.Altitude);
unit.Altitude += Math.Sign(desiredAltitude - unit.Altitude);
} }
} }
} }

View File

@@ -32,22 +32,21 @@ namespace OpenRA.Mods.RA.Activities
self.QueueActivity(new HeliReturn()); self.QueueActivity(new HeliReturn());
return NextActivity; return NextActivity;
} }
var unit = self.traits.Get<Unit>();
var aircraft = self.traits.Get<Aircraft>();
var info = self.Info.Traits.Get<HelicopterInfo>(); var info = self.Info.Traits.Get<HelicopterInfo>();
if (unit.Altitude != info.CruiseAltitude) if (aircraft.Altitude != info.CruiseAltitude)
{ {
unit.Altitude += Math.Sign(info.CruiseAltitude - unit.Altitude); aircraft.Altitude += Math.Sign(info.CruiseAltitude - aircraft.Altitude);
return this; return this;
} }
var range = self.traits.Get<AttackBase>().GetMaximumRange() - 1; var range = self.traits.Get<AttackBase>().GetMaximumRange() - 1;
var dist = target.CenterLocation - self.CenterLocation; var dist = target.CenterLocation - self.CenterLocation;
var desiredFacing = Util.GetFacing(dist, unit.Facing); var desiredFacing = Util.GetFacing(dist, aircraft.Facing);
Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.Traits.Get<AircraftInfo>().ROT); aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);
var rawSpeed = .2f * aircraft.MovementSpeedForCell(self, self.Location);
var mobile = self.traits.WithInterface<IMove>().FirstOrDefault();
var rawSpeed = .2f * mobile.MovementSpeedForCell(self, self.Location);
if (!float2.WithinEpsilon(float2.Zero, dist, range * Game.CellSize)) if (!float2.WithinEpsilon(float2.Zero, dist, range * Game.CellSize))
self.CenterLocation += (rawSpeed / dist.Length) * dist; self.CenterLocation += (rawSpeed / dist.Length) * dist;

View File

@@ -30,13 +30,12 @@ namespace OpenRA.Mods.RA.Activities
if (isCanceled) if (isCanceled)
return NextActivity; return NextActivity;
var unit = self.traits.Get<Unit>();
var info = self.Info.Traits.Get<HelicopterInfo>(); var info = self.Info.Traits.Get<HelicopterInfo>();
var aircraft = self.traits.Get<Aircraft>(); var aircraft = self.traits.Get<Aircraft>();
if (unit.Altitude != info.CruiseAltitude) if (aircraft.Altitude != info.CruiseAltitude)
{ {
unit.Altitude += Math.Sign(info.CruiseAltitude - unit.Altitude); aircraft.Altitude += Math.Sign(info.CruiseAltitude - aircraft.Altitude);
return this; return this;
} }
@@ -48,12 +47,11 @@ namespace OpenRA.Mods.RA.Activities
return NextActivity; return NextActivity;
} }
var desiredFacing = Util.GetFacing(dist, unit.Facing); var desiredFacing = Util.GetFacing(dist, aircraft.Facing);
Util.TickFacing(ref unit.Facing, desiredFacing, aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing,
self.Info.Traits.Get<AircraftInfo>().ROT); aircraft.ROT);
var mobile = self.traits.WithInterface<IMove>().FirstOrDefault(); var rawSpeed = .2f * aircraft.MovementSpeedForCell(self, self.Location);
var rawSpeed = .2f * mobile.MovementSpeedForCell(self, self.Location);
self.CenterLocation += (rawSpeed / dist.Length) * dist; self.CenterLocation += (rawSpeed / dist.Length) * dist;
aircraft.Location = Util.CellContaining(self.CenterLocation); aircraft.Location = Util.CellContaining(self.CenterLocation);

View File

@@ -23,14 +23,14 @@ namespace OpenRA.Mods.RA.Activities
public IActivity Tick(Actor self) public IActivity Tick(Actor self)
{ {
if (isCanceled) return NextActivity; if (isCanceled) return NextActivity;
var unit = self.traits.Get<Unit>(); var aircraft = self.traits.Get<Aircraft>();
if (unit.Altitude == 0) if (aircraft.Altitude == 0)
return NextActivity; return NextActivity;
if (requireSpace && !self.traits.Get<IMove>().CanEnterCell(self.Location)) if (requireSpace && !aircraft.CanEnterCell(self.Location))
return this; return this;
--unit.Altitude; --aircraft.Altitude;
return this; return this;
} }

View File

@@ -39,17 +39,15 @@ namespace OpenRA.Mods.RA.Activities
if (d.LengthSquared < 50) /* close enough */ if (d.LengthSquared < 50) /* close enough */
return NextActivity; return NextActivity;
var unit = self.traits.Get<Unit>();
var aircraft = self.traits.Get<Aircraft>(); var aircraft = self.traits.Get<Aircraft>();
if (unit.Altitude > 0) if (aircraft.Altitude > 0)
--unit.Altitude; --aircraft.Altitude;
var desiredFacing = Util.GetFacing(d, unit.Facing); var desiredFacing = Util.GetFacing(d, aircraft.Facing);
Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.Traits.Get<AircraftInfo>().ROT); aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);
var mobile = self.traits.WithInterface<IMove>().FirstOrDefault(); var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location);
var speed = .2f * mobile.MovementSpeedForCell(self, self.Location); var angle = aircraft.Facing / 128f * Math.PI;
var angle = unit.Facing / 128f * Math.PI;
self.CenterLocation += speed * -float2.FromAngle((float)angle); self.CenterLocation += speed * -float2.FromAngle((float)angle);
aircraft.Location = Util.CellContaining(self.CenterLocation); aircraft.Location = Util.CellContaining(self.CenterLocation);

View File

@@ -41,15 +41,15 @@ namespace OpenRA.Mods.RA.Activities
self.traits.Get<Plane>().reservation = res.Reserve(self); self.traits.Get<Plane>().reservation = res.Reserve(self);
var landPos = dest.CenterLocation; var landPos = dest.CenterLocation;
var unit = self.traits.Get<Unit>(); var aircraft = self.traits.Get<Aircraft>();
var mobile = self.traits.WithInterface<IMove>().FirstOrDefault();
var speed = .2f * mobile.MovementSpeedForCell(self, self.Location); var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location);
var approachStart = landPos - new float2(unit.Altitude * speed, 0); var approachStart = landPos - new float2(aircraft.Altitude * speed, 0);
var turnRadius = (128f / self.Info.Traits.Get<AircraftInfo>().ROT) * speed / (float)Math.PI; var turnRadius = (128f / self.Info.Traits.Get<AircraftInfo>().ROT) * speed / (float)Math.PI;
/* work out the center points */ /* work out the center points */
var fwd = -float2.FromAngle(unit.Facing / 128f * (float)Math.PI); var fwd = -float2.FromAngle(aircraft.Facing / 128f * (float)Math.PI);
var side = new float2(-fwd.Y, fwd.X); /* rotate */ var side = new float2(-fwd.Y, fwd.X); /* rotate */
var sideTowardBase = new[] { side, -side } var sideTowardBase = new[] { side, -side }
.OrderBy(a => float2.Dot(a, self.CenterLocation - approachStart)) .OrderBy(a => float2.Dot(a, self.CenterLocation - approachStart))

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 unit = a.traits.GetOrDefault<Unit>(); var move = a.traits.GetOrDefault<IMove>();
if (unit != null) if (move != null)
unit.Facing = facing; move.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 unit = self.traits.GetOrDefault<Unit>(); var move = self.traits.GetOrDefault<IMove>();
var unloadFacing = self.Info.Traits.Get<CargoInfo>().UnloadFacing; var unloadFacing = self.Info.Traits.Get<CargoInfo>().UnloadFacing;
if (unit != null && unit.Facing != unloadFacing) if (move != null && move.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

@@ -32,6 +32,11 @@ namespace OpenRA.Mods.RA
{ {
[Sync] [Sync]
public int2 Location; public int2 Location;
[Sync]
public int Facing { get; set; }
[Sync]
public int Altitude { get; set; }
AircraftInfo Info; AircraftInfo Info;
public Aircraft( ActorInitializer init , AircraftInfo info) public Aircraft( ActorInitializer init , AircraftInfo info)

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS) * Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
@@ -102,15 +102,13 @@ namespace OpenRA.Mods.RA
{ {
if( !CanAttack( self ) ) return; if( !CanAttack( self ) ) return;
var unit = self.traits.GetOrDefault<Unit>(); var move = self.traits.GetOrDefault<IMove>();
var info = self.Info.Traits.Get<AttackBaseInfo>();
foreach (var w in Weapons) foreach (var w in Weapons)
if (CheckFire(self, unit, w)) if (CheckFire(self, move, w))
w.FiredShot(); w.FiredShot();
} }
bool CheckFire(Actor self, Unit unit, Weapon w) bool CheckFire(Actor self, IMove move, Weapon w)
{ {
if (w.FireDelay > 0) return false; if (w.FireDelay > 0) return false;
@@ -124,8 +122,7 @@ namespace OpenRA.Mods.RA
if (!w.IsValidAgainst(target)) return false; if (!w.IsValidAgainst(target)) return false;
var barrel = w.Barrels[w.Burst % w.Barrels.Length]; var barrel = w.Barrels[w.Burst % w.Barrels.Length];
var destMove = target.IsActor ? target.Actor.traits.GetOrDefault<IMove>() : null;
var destUnit = target.IsActor ? target.Actor.traits.GetOrDefault<Unit>() : null;
var args = new ProjectileArgs var args = new ProjectileArgs
{ {
@@ -135,15 +132,15 @@ namespace OpenRA.Mods.RA
target = this.target, target = this.target,
src = (self.CenterLocation src = (self.CenterLocation
+ Combat.GetTurretPosition(self, unit, w.Turret) + Combat.GetTurretPosition(self, move, w.Turret)
+ Combat.GetBarrelPosition(self, unit, w.Turret, barrel)).ToInt2(), + Combat.GetBarrelPosition(self, move, w.Turret, barrel)).ToInt2(),
srcAltitude = unit != null ? unit.Altitude : 0, srcAltitude = move != null ? move.Altitude : 0,
dest = target.CenterLocation.ToInt2(), dest = target.CenterLocation.ToInt2(),
destAltitude = destUnit != null ? destUnit.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 :
unit != null ? unit.Facing : Util.GetFacing(target.CenterLocation - self.CenterLocation, 0)), move != null ? move.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 unit = self.traits.Get<Unit>(); var move = self.traits.Get<IMove>();
var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, unit.Facing); var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, move.Facing);
if (Math.Abs(facingToTarget - unit.Facing) % 256 < FacingTolerance) if (Math.Abs(facingToTarget - move.Facing) % 256 < FacingTolerance)
DoAttack(self); DoAttack(self);
} }
} }

View File

@@ -51,8 +51,8 @@ namespace OpenRA.Mods.RA
return false; return false;
// Cannot unload mid-air // Cannot unload mid-air
var unit = self.traits.GetOrDefault<Unit>(); var move = self.traits.GetOrDefault<IMove>();
if (unit != null && unit.Altitude > 0) if (move != null && move.Altitude > 0)
return false; return false;
// Todo: Check if there is a free tile to unload to // Todo: Check if there is a free tile to unload to

View File

@@ -43,13 +43,14 @@ 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 = self.traits.Get<Unit>().Altitude, srcAltitude = move.Altitude,
destAltitude = 0, destAltitude = 0,
src = self.CenterLocation.ToInt2(), src = self.CenterLocation.ToInt2(),
dest = self.CenterLocation.ToInt2(), dest = self.CenterLocation.ToInt2(),
facing = self.traits.Get<Unit>().Facing, facing = move.Facing,
firedBy = self, firedBy = self,
weapon = weapon weapon = weapon
}; };

View File

@@ -193,13 +193,13 @@ namespace OpenRA.Mods.RA
return Util.RotateVectorByFacing(localRecoil, facing, .7f); return Util.RotateVectorByFacing(localRecoil, facing, .7f);
} }
public static float2 GetTurretPosition(Actor self, Unit unit, Turret turret) public static float2 GetTurretPosition(Actor self, IMove move, Turret turret)
{ {
if (unit == null) return turret.ScreenSpacePosition; if(move == 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 = unit.Facing; var bodyFacing = move.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 +208,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, Unit unit, Turret turret, Barrel barrel) public static float2 GetBarrelPosition(Actor self, IMove move, Turret turret, Barrel barrel)
{ {
var turreted = self.traits.GetOrDefault<Turreted>(); var turreted = self.traits.GetOrDefault<Turreted>();
if (turreted == null && unit == null) if (turreted == null && move == null)
return float2.Zero; return float2.Zero;
var turretFacing = turreted != null ? turreted.turretFacing : unit.Facing; var turretFacing = turreted != null ? turreted.turretFacing : move.Facing;
return Util.RotateVectorByFacing(barrel.Position, turretFacing, .7f); return Util.RotateVectorByFacing(barrel.Position, turretFacing, .7f);
} }

View File

@@ -72,7 +72,8 @@ namespace OpenRA.Mods.RA
var startPos = w.ChooseRandomEdgeCell(); var startPos = w.ChooseRandomEdgeCell();
var plane = w.CreateActor("BADR", startPos, w.WorldActor.Owner); var plane = w.CreateActor("BADR", startPos, w.WorldActor.Owner);
plane.traits.Get<Unit>().Facing = Util.GetFacing(p - startPos, 0); var aircraft = plane.traits.Get<Aircraft>();
aircraft.Facing = Util.GetFacing(p - startPos, 0);
plane.CancelActivity(); plane.CancelActivity();
plane.QueueActivity(new FlyCircle(p)); plane.QueueActivity(new FlyCircle(p));
plane.traits.Get<ParaDrop>().SetLZ(p, null); plane.traits.Get<ParaDrop>().SetLZ(p, null);

View File

@@ -33,9 +33,9 @@ namespace OpenRA.Mods.RA
public void Detonate(Actor self, Actor detonatedBy) public void Detonate(Actor self, Actor detonatedBy)
{ {
var unit = self.traits.GetOrDefault<Unit>(); var move = self.traits.GetOrDefault<IMove>();
var info = self.Info.Traits.Get<AttackBaseInfo>(); var info = self.Info.Traits.Get<AttackBaseInfo>();
var altitude = unit != null ? unit.Altitude : 0; var altitude = move != null ? move.Altitude : 0;
self.World.AddFrameEndTask( w => self.World.AddFrameEndTask( w =>
{ {

View File

@@ -76,11 +76,11 @@ namespace OpenRA.Mods.RA.Effects
var targetPosition = Args.target.CenterLocation + offset; var targetPosition = Args.target.CenterLocation + offset;
var targetAltitude = 0; var targetAltitude = 0;
if (Args.target.IsActor && Args.target.Actor.traits.Contains<Unit>()) if (Args.target.IsActor && Args.target.Actor.traits.Contains<IMove>())
targetAltitude = Args.target.Actor.traits.Get<Unit>().Altitude; targetAltitude = Args.target.Actor.traits.Get<IMove>().Altitude;
Altitude += Math.Sign(targetAltitude - Altitude); Altitude += Math.Sign(targetAltitude - Altitude);
Traits.Util.TickFacing(ref Facing, Facing = Traits.Util.TickFacing(Facing,
Traits.Util.GetFacing(targetPosition - Pos, Facing), Traits.Util.GetFacing(targetPosition - Pos, Facing),
Info.ROT); Info.ROT);

View File

@@ -30,8 +30,8 @@ namespace OpenRA.Mods.RA
var weapon = ChooseWeaponForExplosion(self); var weapon = ChooseWeaponForExplosion(self);
if (weapon != null) if (weapon != null)
{ {
var unit = self.traits.GetOrDefault<Unit>(); var move = self.traits.GetOrDefault<IMove>();
var altitude = unit != null ? unit.Altitude : 0; var altitude = move != null ? move.Altitude : 0;
Combat.DoExplosion(e.Attacker, weapon, self.CenterLocation, altitude); Combat.DoExplosion(e.Attacker, weapon, self.CenterLocation, altitude);
} }
} }

View File

@@ -33,10 +33,10 @@ 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 unit = a.traits.WithInterface<Unit>().FirstOrDefault();
var move = a.traits.GetOrDefault<IMove>();
if (unit != null) if (move != null)
unit.Facing = info.Facing; move.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

@@ -129,12 +129,11 @@ namespace OpenRA.Mods.RA
int offsetTicks = 0; int offsetTicks = 0;
public void Tick(Actor self) public void Tick(Actor self)
{ {
var unit = self.traits.Get<Unit>(); var aircraft = self.traits.Get<Aircraft>();
if (unit.Altitude <= 0) if (aircraft.Altitude <= 0)
return; return;
var mobile = self.traits.WithInterface<IMove>().FirstOrDefault(); var rawSpeed = .2f * aircraft.MovementSpeedForCell(self, self.Location);
var rawSpeed = .2f * mobile.MovementSpeedForCell(self, self.Location);
var otherHelis = self.World.FindUnitsInCircle(self.CenterLocation, Info.IdealSeparation) var otherHelis = self.World.FindUnitsInCircle(self.CenterLocation, Info.IdealSeparation)
.Where(a => a.traits.Contains<Helicopter>()); .Where(a => a.traits.Contains<Helicopter>());
@@ -147,7 +146,7 @@ namespace OpenRA.Mods.RA
if (--offsetTicks <= 0) if (--offsetTicks <= 0)
{ {
self.CenterLocation += Info.InstabilityMagnitude * self.World.SharedRandom.Gauss2D(5); self.CenterLocation += Info.InstabilityMagnitude * self.World.SharedRandom.Gauss2D(5);
unit.Altitude += (int)(Info.InstabilityMagnitude * self.World.SharedRandom.Gauss1D(5)); aircraft.Altitude += (int)(Info.InstabilityMagnitude * self.World.SharedRandom.Gauss1D(5));
offsetTicks = Info.InstabilityTicks; offsetTicks = Info.InstabilityTicks;
} }

View File

@@ -28,8 +28,10 @@ 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;
husk.traits.Get<Unit>().Altitude = self.traits.Get<Unit>().Altitude; var move = self.traits.Get<IMove>();
husk.traits.Get<Unit>().Facing = self.traits.Get<Unit>().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

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

View File

@@ -24,10 +24,10 @@ 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 unit = harv.traits.Get<Unit>(); var move = harv.traits.Get<IMove>();
var harvester = harv.traits.Get<Harvester>(); var harvester = harv.traits.Get<Harvester>();
if (unit.Facing != 64) if (move.Facing != 64)
harv.QueueActivity (new Turn (64)); harv.QueueActivity (new Turn (64));
harv.QueueActivity (new CallFunc (() => harv.QueueActivity (new CallFunc (() =>

View File

@@ -57,10 +57,11 @@ namespace OpenRA.Mods.RA
var a = cargo.Unload(self); var a = cargo.Unload(self);
var rs = a.traits.Get<RenderSimple>(); var rs = a.traits.Get<RenderSimple>();
var aircraft = self.traits.Get<IMove>();
self.World.AddFrameEndTask(w => w.Add( self.World.AddFrameEndTask(w => w.Add(
new Parachute(self.Owner, rs.anim.Name, new Parachute(self.Owner, rs.anim.Name,
Util.CenterOfCell(Util.CellContaining(self.CenterLocation)), Util.CenterOfCell(Util.CellContaining(self.CenterLocation)),
self.traits.Get<Unit>().Altitude, a))); aircraft.Altitude, a)));
Sound.Play(info.ChuteSound, self.CenterLocation); Sound.Play(info.ChuteSound, self.CenterLocation);
} }

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
if (firstTick) if (firstTick)
{ {
firstTick = false; firstTick = false;
if (self.traits.Get<Unit>().Altitude == 0) if (self.traits.Get<IMove>().Altitude == 0)
{ {
/* not spawning in the air, so try to assoc. with our afld. this is a hack. */ /* not spawning in the air, so try to assoc. with our afld. this is a hack. */
var res = self.World.FindUnits(self.CenterLocation, self.CenterLocation) var res = self.World.FindUnits(self.CenterLocation, self.CenterLocation)

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<Unit>().Facing = CreationFacing( self, newUnit ); ; newUnit.traits.Get<IMove>().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<Unit>().Facing) : base(self, () => self.traits.Get<IMove>().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.Get<Unit>().Facing) : base(self, () => self.traits.Contains<IMove>() ? self.traits.Get<IMove>().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,20 @@ 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)
{ {
var unit = self.traits.Get<Unit>(); move = self.traits.Get<IMove>();
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, unit, new Turret(info.PrimaryOffset)), () => Combat.GetTurretPosition( self, move, new Turret(info.PrimaryOffset)),
null) { ZOffset = 1 }); null ) { ZOffset = 1 } );
if (info.SecondaryOffset == null) return; if (info.SecondaryOffset == null) return;
@@ -44,18 +45,15 @@ 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, unit, new Turret(info.SecondaryOffset)), () => Combat.GetTurretPosition(self, move, new Turret(info.SecondaryOffset)),
null) { ZOffset = 1 }); null) { ZOffset = 1 });
} }
public override void Tick(Actor self) public override void Tick(Actor self)
{ {
base.Tick(self); base.Tick(self);
var unit = self.traits.Get<Unit>();
var isFlying = unit.Altitude > 0; var isFlying = move.Altitude > 0;
if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor")) if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor"))
return; return;

View File

@@ -24,14 +24,14 @@ namespace OpenRA.Mods.RA.Render
public RenderUnitSpinner(Actor self) public RenderUnitSpinner(Actor self)
: base(self) : base(self)
{ {
var unit = self.traits.Get<Unit>(); 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, unit, new Turret(info.Offset)), () => Combat.GetTurretPosition(self, move, 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 unit = self.traits.Get<Unit>(); var move = self.traits.Get<IMove>();
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, unit, turret ), () => Combat.GetTurretPosition( self, move, 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, unit, turret), () => Combat.GetTurretPosition(self, move, turret),
() => turret.Recoil <= 0)); () => turret.Recoil <= 0));
} }
} }

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA
{ {
public void Idle(Actor self) public void Idle(Actor self)
{ {
var altitude = self.traits.Get<Unit>().Altitude; var altitude = self.traits.Get<Aircraft>().Altitude;
if (altitude == 0) return; // we're on the ground, let's stay there. if (altitude == 0) return; // we're on the ground, let's stay there.
var airfield = ReturnToBase.ChooseAirfield(self); var airfield = ReturnToBase.ChooseAirfield(self);

View File

@@ -48,8 +48,9 @@ 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);
a.traits.Get<Unit>().Facing = Util.GetFacing(order.TargetLocation - startPos, 0); var aMove = a.traits.Get<IMove>();
a.traits.Get<Unit>().Altitude = a.Info.Traits.Get<PlaneInfo>().CruiseAltitude; aMove.Facing = Util.GetFacing(order.TargetLocation - startPos, 0);
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,8 +61,9 @@ 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);
a.traits.Get<Unit>().Facing = Util.GetFacing(p - startPos, 0); var aMove = a.traits.Get<IMove>();
a.traits.Get<Unit>().Altitude = a.Info.Traits.Get<PlaneInfo>().CruiseAltitude; aMove.Facing = Util.GetFacing(p - startPos, 0);
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,8 +46,9 @@ 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);
plane.traits.Get<Unit>().Altitude = plane.Info.Traits.Get<PlaneInfo>().CruiseAltitude; var planeMove = plane.traits.Get<IMove>();
plane.traits.Get<Unit>().Facing = Util.GetFacing(order.TargetLocation - enterCell, 0); planeMove.Altitude = plane.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
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,7 +48,8 @@ namespace OpenRA.Mods.RA
if (info != null) if (info != null)
{ {
alt = 0; alt = 0;
pos = Combat.GetTurretPosition(self, self.traits.Get<Unit>(), new Turret(info.Offset)); var move = self.traits.Get<IMove>();
pos = Combat.GetTurretPosition(self, move, 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();
@@ -56,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 ?? self.traits.Get<Unit>().Facing; facing = InitialFacing ?? move.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,11 @@ namespace OpenRA.Mods.RA
public WithMuzzleFlash(Actor self) public WithMuzzleFlash(Actor self)
{ {
var unit = self.traits.Get<Unit>(); 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), () => unit.Facing); muzzleFlash = new Animation(render.GetImage(self), () => move.Facing);
muzzleFlash.Play("muzzle"); muzzleFlash.Play("muzzle");
render.anims.Add("muzzle", new RenderSimple.AnimationWithOffset( render.anims.Add("muzzle", new RenderSimple.AnimationWithOffset(

View File

@@ -20,11 +20,11 @@ namespace OpenRA.Mods.RA
{ {
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r) public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{ {
var unit = self.traits.Get<Unit>(); var move = self.traits.Get<IMove>();
var shadowSprites = r.Select(a => a.WithPalette("shadow")); var shadowSprites = r.Select(a => a.WithPalette("shadow"));
var flyingSprites = (unit.Altitude <= 0) ? r var flyingSprites = (move.Altitude <= 0) ? r
: r.Select(a => a.WithPos(a.Pos - new float2(0, unit.Altitude)).WithZOffset(3)); : r.Select(a => a.WithPos(a.Pos - new float2(0, move.Altitude)).WithZOffset(3));
return shadowSprites.Concat(flyingSprites); return shadowSprites.Concat(flyingSprites);
} }