Rename IMovement -> IMove; Move GetCurrentPath from Mobile to IMove and implement for aircraft; fix regressions in Helicopter (ITick) and remove unused cruft from Aircraft (IOccupySpace).

This commit is contained in:
Paul Chote
2010-06-23 14:54:24 +12:00
parent 3be5b946ad
commit 7d717592c7
15 changed files with 46 additions and 35 deletions

View File

@@ -64,7 +64,7 @@ namespace OpenRA
if (voicedActor != null)
{
if(voicedActor.traits.GetOrDefault<IMovement>().CanEnterCell(xy.ToInt2()))
if(voicedActor.traits.GetOrDefault<IMove>().CanEnterCell(xy.ToInt2()))
Sound.PlayVoice(isAttack ? "Attack" : "Move", voicedActor);
if (isMove)

View File

@@ -236,18 +236,15 @@ namespace OpenRA.Graphics
if (Game.Settings.PathDebug)
{
var mobile = selectedUnit.traits.GetOrDefault<Mobile>();
var mobile = selectedUnit.traits.WithInterface<IMove>().FirstOrDefault();
if (mobile != null)
{
var path = mobile.GetCurrentPath();
var start = selectedUnit.Location;
var path = mobile.GetCurrentPath(selectedUnit);
var start = selectedUnit.CenterLocation;
foreach (var step in path)
{
lineRenderer.DrawLine(
Game.CellSize * start + new float2(12, 12),
Game.CellSize * step + new float2(12, 12),
Color.Red, Color.Red);
lineRenderer.DrawLine(start, step, Color.Red, Color.Red);
start = step;
}
}

View File

@@ -92,7 +92,7 @@ namespace OpenRA.Orders
case "Heal": return "heal";
case "C4": return "c4";
case "Move":
if (a.traits.GetOrDefault<IMovement>().CanEnterCell(location))
if (a.traits.GetOrDefault<IMove>().CanEnterCell(location))
return "move";
else
return "move-blocked";

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Traits
public object Create(ActorInitializer init) { return new Mobile(init); }
}
public class Mobile : IIssueOrder, IResolveOrder, IOccupySpace, IMovement
public class Mobile : IIssueOrder, IResolveOrder, IOccupySpace, IMove
{
readonly Actor self;
@@ -95,7 +95,7 @@ namespace OpenRA.Traits
{
if (order.OrderString == "Move")
{
if (self.traits.GetOrDefault<IMovement>().CanEnterCell(order.TargetLocation))
if (self.traits.GetOrDefault<IMove>().CanEnterCell(order.TargetLocation))
{
if( !order.Queued ) self.CancelActivity();
self.QueueActivity(new Activities.Move(order.TargetLocation, 8));
@@ -132,11 +132,12 @@ namespace OpenRA.Traits
.GetCost(GetMovementType()) < float.PositiveInfinity;
}
public IEnumerable<int2> GetCurrentPath()
public IEnumerable<float2> GetCurrentPath(Actor self)
{
var move = self.GetCurrentActivity() as Activities.Move;
if (move == null || move.path == null) return new int2[] { };
return Enumerable.Reverse(move.path);
if (move == null || move.path == null) return new float2[] { };
return Enumerable.Reverse(move.path).Select( c => Game.CellSize * c + new float2(12,12) );
}
}
}

View File

@@ -96,10 +96,11 @@ namespace OpenRA.Traits
public interface IPaletteModifier { void AdjustPalette(Bitmap b); }
public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
public interface ITags { IEnumerable<TagType> GetTags(); }
public interface IMovement
public interface IMove
{
UnitMovementType GetMovementType();
bool CanEnterCell(int2 location);
IEnumerable<float2> GetCurrentPath(Actor self);
}
public interface ICrushable

View File

@@ -61,7 +61,7 @@ namespace OpenRA
public static bool IsActorCrushableByActor(this World world, Actor a, Actor b)
{
var movement = b.traits.GetOrDefault<IMovement>();
var movement = b.traits.GetOrDefault<IMove>();
return movement != null && world.IsActorCrushableByMovementType(a, movement.GetMovementType());
}

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Aftermath
return;
}
var movement = self.traits.GetOrDefault<IMovement>();
var movement = self.traits.GetOrDefault<IMove>();
if (order.OrderString == "ChronoshiftSelf" && movement.CanEnterCell(order.TargetLocation))
{
if (self.Owner == self.World.LocalPlayer)

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Aftermath.Orders
if (!world.LocalPlayer.Shroud.IsExplored(xy))
return "move-blocked";
var movement = self.traits.GetOrDefault<IMovement>();
var movement = self.traits.GetOrDefault<IMove>();
return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked";
}
}

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities
{
public class Fly : IActivity
{
readonly float2 Pos;
public readonly float2 Pos;
bool isCanceled;
public Fly(float2 pos) { Pos = pos; }

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Activities
{
class HeliFly : IActivity
{
readonly float2 Dest;
public readonly float2 Dest;
public HeliFly(float2 dest)
{
Dest = dest;

View File

@@ -22,8 +22,9 @@ using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Traits;
namespace OpenRA.Traits
namespace OpenRA.Mods.RA
{
public class AircraftInfo : ITraitInfo
{
@@ -34,7 +35,7 @@ namespace OpenRA.Traits
public virtual object Create( ActorInitializer init ) { return new Aircraft( init ); }
}
public class Aircraft : IOccupySpace, IMovement
public class Aircraft : IMove
{
[Sync]
public int2 Location;
@@ -49,12 +50,6 @@ namespace OpenRA.Traits
get { return Location; }
}
public IEnumerable<int2> OccupiedCells()
{
// TODO: make helis on the ground occupy a space.
yield break;
}
public bool AircraftCanEnter(Actor self, Actor a)
{
var aircraft = self.Info.Traits.Get<AircraftInfo>();
@@ -62,6 +57,14 @@ namespace OpenRA.Traits
|| aircraft.RepairBuildings.Contains( a.Info.Name );
}
public virtual IEnumerable<float2> GetCurrentPath(Actor self)
{
var move = self.GetCurrentActivity() as Activities.Fly;
if (move == null) return new float2[] { };
return new float2[] { move.Pos };
}
public UnitMovementType GetMovementType() { return UnitMovementType.Fly; }
public bool CanEnterCell(int2 location) { return true; }
}

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA
Game.controller.CancelInputMode();
// Ensure the target cell is valid for the unit
var movement = order.TargetActor.traits.GetOrDefault<IMovement>();
var movement = order.TargetActor.traits.GetOrDefault<IMove>();
if (!movement.CanEnterCell(order.TargetLocation))
return;
@@ -152,7 +152,7 @@ namespace OpenRA.Mods.RA
if (!world.LocalPlayer.Shroud.IsExplored(xy))
return "move-blocked";
var movement = self.traits.GetOrDefault<IMovement>();
var movement = self.traits.GetOrDefault<IMove>();
return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked";
}
}

View File

@@ -19,6 +19,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits.Activities;
using OpenRA.GameRules;
@@ -37,7 +38,7 @@ namespace OpenRA.Mods.RA
public override object Create( ActorInitializer init ) { return new Helicopter( init ); }
}
class Helicopter : Aircraft, IIssueOrder, IResolveOrder
class Helicopter : Aircraft, ITick, IIssueOrder, IResolveOrder
{
public IDisposable reservation;
@@ -49,7 +50,7 @@ namespace OpenRA.Mods.RA
if (underCursor == null)
{
if (self.traits.GetOrDefault<IMovement>().CanEnterCell(xy))
if (self.traits.GetOrDefault<IMove>().CanEnterCell(xy))
return new Order("Move", self, xy);
}
@@ -143,5 +144,13 @@ namespace OpenRA.Mods.RA
return float2.FromAngle((float)self.World.SharedRandom.NextDouble() * 3.14f);
return (5 / d.LengthSquared) * d;
}
public override IEnumerable<float2> GetCurrentPath(Actor self)
{
var move = self.GetCurrentActivity() as Activities.HeliFly;
if (move == null) return new float2[] { };
return new float2[] { move.Dest };
}
}
}

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.RA
if (self.Owner == self.World.LocalPlayer)
Game.controller.CancelInputMode();
var movement = self.traits.Get<IMovement>();
var movement = self.traits.Get<IMove>();
minefield = GetMinefieldCells(minefieldStart, order.TargetLocation,
self.Info.Traits.Get<MinelayerInfo>().MinefieldDepth)
@@ -126,7 +126,7 @@ namespace OpenRA.Mods.RA
public void Render(World world)
{
var ml = minelayer.traits.Get<Minelayer>();
var movement = minelayer.traits.Get<IMovement>();
var movement = minelayer.traits.Get<IMove>();
var minefield = GetMinefieldCells(ml.minefieldStart, lastMousePos, minelayer.Info.Traits.Get<MinelayerInfo>().MinefieldDepth)
.Where(p => movement.CanEnterCell(p)).ToArray();

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA
if (cargo == null || cargo.IsFull(underCursor))
return null;
var umt = self.traits.Get<IMovement>().GetMovementType();
var umt = self.traits.Get<IMove>().GetMovementType();
if (!underCursor.Info.Traits.Get<CargoInfo>().PassengerTypes.Contains(umt))
return null;