Changed most references of trait Mobile -> IMove.

In Mobile.cs IsMoving now has a public set as opposed to the initial internal. 
Added IMoveInfo interface to go with *Info classes that require IMove.
WithRotor now uses IMove.IsMoving instead of (self.CenterPosition.Z > 0) as part of a check.
This commit is contained in:
Taryn
2014-02-02 01:30:21 -06:00
parent 4b38390907
commit 9c4ad15d1e
13 changed files with 34 additions and 28 deletions

View File

@@ -148,6 +148,7 @@ namespace OpenRA.Traits
void SetVisualPosition(Actor self, WPos pos); void SetVisualPosition(Actor self, WPos pos);
} }
public interface IMoveInfo { }
public interface IMove public interface IMove
{ {
Activity MoveTo(CPos cell, int nearEnough); Activity MoveTo(CPos cell, int nearEnough);
@@ -155,6 +156,7 @@ namespace OpenRA.Traits
Activity MoveWithinRange(Target target, WRange range); Activity MoveWithinRange(Target target, WRange range);
Activity MoveFollow(Actor self, Target target, WRange range); Activity MoveFollow(Actor self, Target target, WRange range);
CPos NearestMoveableCell(CPos target); CPos NearestMoveableCell(CPos target);
bool IsMoving { get; set; }
} }
public interface INotifyBlockingMove { void OnNotifyBlockingMove(Actor self, Actor blocking); } public interface INotifyBlockingMove { void OnNotifyBlockingMove(Actor self, Actor blocking); }

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA.Activities
nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread, nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread,
delayBetweenPathingAttempts + delaySpread); delayBetweenPathingAttempts + delaySpread);
return (AllowMovement) ? Util.SequenceActivities(self.Trait<Mobile>().MoveWithinRange(Target, Range), this) : NextActivity; return (AllowMovement) ? Util.SequenceActivities(self.Trait<IMove>().MoveWithinRange(Target, Range), this) : NextActivity;
} }
var desiredFacing = Util.GetFacing(Target.CenterPosition - self.CenterPosition, 0); var desiredFacing = Util.GetFacing(Target.CenterPosition - self.CenterPosition, 0);

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities
if (NextActivity != null) if (NextActivity != null)
return NextActivity; return NextActivity;
var mobile = self.Trait<Mobile>(); var movement = self.Trait<IMove>();
var harv = self.Trait<Harvester>(); var harv = self.Trait<Harvester>();
// Find the nearest best refinery if not explicitly ordered to a specific refinery: // Find the nearest best refinery if not explicitly ordered to a specific refinery:
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA.Activities
self.SetTargetLine(Target.FromActor(proc), Color.Green, false); self.SetTargetLine(Target.FromActor(proc), Color.Green, false);
if (self.Location != proc.Location + iao.DeliverOffset) if (self.Location != proc.Location + iao.DeliverOffset)
return Util.SequenceActivities(mobile.MoveTo(proc.Location + iao.DeliverOffset, 0), this); return Util.SequenceActivities(movement.MoveTo(proc.Location + iao.DeliverOffset, 0), this);
if (!isDocking) if (!isDocking)
{ {

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Activities
{ {
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
var mobile = self.Trait<Mobile>(); var movement = self.Trait<IMove>();
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>(); var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
if (!limitedAmmo.HasAmmo()) if (!limitedAmmo.HasAmmo())
{ {
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Activities
return Util.SequenceActivities( return Util.SequenceActivities(
new MoveAdjacentTo(self, Target.FromActor(rearmTarget)), new MoveAdjacentTo(self, Target.FromActor(rearmTarget)),
mobile.MoveTo(rearmTarget.CenterPosition.ToCPos(), rearmTarget), movement.MoveTo(rearmTarget.CenterPosition.ToCPos(), rearmTarget),
new Rearm(self), new Rearm(self),
new Repair(rearmTarget), new Repair(rearmTarget),
this ); this );
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA.Activities
{ {
var p = ml.minefield.Random(self.World.SharedRandom); var p = ml.minefield.Random(self.World.SharedRandom);
if (ShouldLayMine(self, p)) if (ShouldLayMine(self, p))
return Util.SequenceActivities( mobile.MoveTo(p, 0), this ); return Util.SequenceActivities( movement.MoveTo(p, 0), this );
} }
// TODO: return somewhere likely to be safe (near fix) so we're not sitting out in the minefield. // TODO: return somewhere likely to be safe (near fix) so we're not sitting out in the minefield.

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
class HelicopterInfo : AircraftInfo class HelicopterInfo : AircraftInfo, IMoveInfo
{ {
public readonly WRange IdealSeparation = new WRange(1706); public readonly WRange IdealSeparation = new WRange(1706);
public readonly bool LandWhenIdle = true; public readonly bool LandWhenIdle = true;
@@ -30,6 +30,7 @@ namespace OpenRA.Mods.RA.Air
public HelicopterInfo Info; public HelicopterInfo Info;
Actor self; Actor self;
bool firstTick = true; bool firstTick = true;
public bool IsMoving { get { return self.CenterPosition.Z > 0; } set { } }
public Helicopter(ActorInitializer init, HelicopterInfo info) public Helicopter(ActorInitializer init, HelicopterInfo info)
: base(init, info) : base(init, info)

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
public class PlaneInfo : AircraftInfo public class PlaneInfo : AircraftInfo, IMoveInfo
{ {
public readonly WAngle MaximumPitch = WAngle.FromDegrees(10); public readonly WAngle MaximumPitch = WAngle.FromDegrees(10);
@@ -26,6 +26,7 @@ namespace OpenRA.Mods.RA.Air
public readonly PlaneInfo Info; public readonly PlaneInfo Info;
[Sync] public WPos RTBPathHash; [Sync] public WPos RTBPathHash;
Actor self; Actor self;
public bool IsMoving { get { return self.CenterPosition.Z > 0; } set { } }
public Plane(ActorInitializer init, PlaneInfo info) public Plane(ActorInitializer init, PlaneInfo info)
: base(init, info) : base(init, info)

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Move
public override Activity Tick(Actor self) public override Activity Tick(Actor self)
{ {
var positionable = self.Trait<IPositionable>(); var positionable = self.Trait<IPositionable>();
var mobile = positionable as Mobile; var movement = self.Trait<IMove>();
var pos = length > 1 var pos = length > 1
? WPos.Lerp(start, end, ticks, length - 1) ? WPos.Lerp(start, end, ticks, length - 1)
@@ -38,14 +38,14 @@ namespace OpenRA.Mods.RA.Move
positionable.SetVisualPosition(self, pos); positionable.SetVisualPosition(self, pos);
if (++ticks >= length) if (++ticks >= length)
{ {
if (mobile != null) if (movement != null)
mobile.IsMoving = false; movement.IsMoving = false;
return NextActivity; return NextActivity;
} }
if (mobile != null) if (movement != null)
mobile.IsMoving = true; movement.IsMoving = true;
return this; return this;
} }

View File

@@ -19,7 +19,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Move namespace OpenRA.Mods.RA.Move
{ {
[Desc("Unit is able to move.")] [Desc("Unit is able to move.")]
public class MobileInfo : ITraitInfo, IOccupySpaceInfo, IFacingInfo, UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit> public class MobileInfo : ITraitInfo, IOccupySpaceInfo, IFacingInfo, IMoveInfo, UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit>
{ {
[FieldLoader.LoadUsing("LoadSpeeds")] [FieldLoader.LoadUsing("LoadSpeeds")]
[Desc("Set Water: 0 for ground units and lower the value on rough terrain.")] [Desc("Set Water: 0 for ground units and lower the value on rough terrain.")]
@@ -148,7 +148,7 @@ namespace OpenRA.Mods.RA.Move
{ {
public readonly Actor self; public readonly Actor self;
public readonly MobileInfo Info; public readonly MobileInfo Info;
public bool IsMoving { get; internal set; } public bool IsMoving { get; set; }
int __facing; int __facing;
CPos __fromCell, __toCell; CPos __fromCell, __toCell;

View File

@@ -35,12 +35,12 @@ namespace OpenRA.Mods.RA.Render
IdleAnimating IdleAnimating
} }
protected bool dirty = false; Mobile mobile;
RenderInfantryInfo info; RenderInfantryInfo info;
public bool IsMoving { get; set; }
protected bool dirty = false;
string idleSequence; string idleSequence;
int idleDelay; int idleDelay;
Mobile mobile;
protected virtual string NormalizeInfantrySequence(Actor self, string baseSequence) protected virtual string NormalizeInfantrySequence(Actor self, string baseSequence)
{ {

View File

@@ -34,12 +34,14 @@ namespace OpenRA.Mods.RA.Render
{ {
WithRotorInfo info; WithRotorInfo info;
Animation rotorAnim; Animation rotorAnim;
IMove movement;
public WithRotor(Actor self, WithRotorInfo info) public WithRotor(Actor self, WithRotorInfo info)
{ {
this.info = info; this.info = info;
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
var body = self.Trait<IBodyOrientation>(); var body = self.Trait<IBodyOrientation>();
movement = self.Trait<IMove>();
rotorAnim = new Animation(rs.GetImage(self)); rotorAnim = new Animation(rs.GetImage(self));
rotorAnim.PlayRepeating(info.Sequence); rotorAnim.PlayRepeating(info.Sequence);
@@ -50,7 +52,7 @@ namespace OpenRA.Mods.RA.Render
public void Tick(Actor self) public void Tick(Actor self)
{ {
var isFlying = self.CenterPosition.Z > 0 && !self.IsDead(); var isFlying = movement.IsMoving && !self.IsDead();
if (isFlying ^ (rotorAnim.CurrentSequence.Name != info.Sequence)) if (isFlying ^ (rotorAnim.CurrentSequence.Name != info.Sequence))
return; return;

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render namespace OpenRA.Mods.RA.Render
{ {
public class WithVoxelWalkerBodyInfo : ITraitInfo, Requires<RenderVoxelsInfo>, Requires<MobileInfo> public class WithVoxelWalkerBodyInfo : ITraitInfo, Requires<RenderVoxelsInfo>, Requires<IMoveInfo>
{ {
public readonly int TickRate = 5; public readonly int TickRate = 5;
public object Create(ActorInitializer init) { return new WithVoxelWalkerBody(init.self, this); } public object Create(ActorInitializer init) { return new WithVoxelWalkerBody(init.self, this); }
@@ -25,14 +25,14 @@ namespace OpenRA.Mods.RA.Render
public class WithVoxelWalkerBody : IAutoSelectionSize, ITick public class WithVoxelWalkerBody : IAutoSelectionSize, ITick
{ {
WithVoxelWalkerBodyInfo info; WithVoxelWalkerBodyInfo info;
Mobile mobile; IMove movement;
int2 size; int2 size;
uint tick, frame, frames; uint tick, frame, frames;
public WithVoxelWalkerBody(Actor self, WithVoxelWalkerBodyInfo info) public WithVoxelWalkerBody(Actor self, WithVoxelWalkerBodyInfo info)
{ {
this.info = info; this.info = info;
mobile = self.Trait<Mobile>(); movement = self.Trait<IMove>();
var body = self.Trait<IBodyOrientation>(); var body = self.Trait<IBodyOrientation>();
var rv = self.Trait<RenderVoxels>(); var rv = self.Trait<RenderVoxels>();
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.RA.Render
public void Tick(Actor self) public void Tick(Actor self)
{ {
if (mobile.IsMoving) if (movement.IsMoving)
tick++; tick++;
if (tick < info.TickRate) if (tick < info.TickRate)

View File

@@ -73,13 +73,13 @@ namespace OpenRA.Mods.RA
if( !CanRepairAt( order.TargetActor ) || !CanRepair() ) if( !CanRepairAt( order.TargetActor ) || !CanRepair() )
return; return;
var mobile = self.Trait<Mobile>(); var movement = self.Trait<IMove>();
var target = Target.FromOrder(order); var target = Target.FromOrder(order);
self.SetTargetLine(target, Color.Green); self.SetTargetLine(target, Color.Green);
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new MoveAdjacentTo(self, target)); self.QueueActivity(new MoveAdjacentTo(self, target));
self.QueueActivity(mobile.MoveTo(order.TargetActor.CenterPosition.ToCPos(), order.TargetActor)); self.QueueActivity(movement.MoveTo(order.TargetActor.CenterPosition.ToCPos(), order.TargetActor));
self.QueueActivity(new Rearm(self)); self.QueueActivity(new Rearm(self));
self.QueueActivity(new Repair(order.TargetActor)); self.QueueActivity(new Repair(order.TargetActor));
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.RA
self.QueueActivity(new CallFunc(() => self.QueueActivity(new CallFunc(() =>
{ {
self.SetTargetLine(Target.FromCell(rp.rallyPoint), Color.Green); self.SetTargetLine(Target.FromCell(rp.rallyPoint), Color.Green);
self.QueueActivity(mobile.MoveTo(rp.rallyPoint, order.TargetActor)); self.QueueActivity(movement.MoveTo(rp.rallyPoint, order.TargetActor));
})); }));
} }
} }

View File

@@ -65,11 +65,11 @@ namespace OpenRA.Mods.RA
{ {
if (order.OrderString == "RepairNear" && CanRepairAt(order.TargetActor) && ShouldRepair()) if (order.OrderString == "RepairNear" && CanRepairAt(order.TargetActor) && ShouldRepair())
{ {
var mobile = self.Trait<Mobile>(); var movement = self.Trait<IMove>();
var target = Target.FromOrder(order); var target = Target.FromOrder(order);
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(mobile.MoveWithinRange(target, new WRange(1024*info.CloseEnough))); self.QueueActivity(movement.MoveWithinRange(target, new WRange(1024*info.CloseEnough)));
self.QueueActivity(new Repair(order.TargetActor)); self.QueueActivity(new Repair(order.TargetActor));
self.SetTargetLine(target, Color.Green, false); self.SetTargetLine(target, Color.Green, false);