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:
@@ -64,7 +64,7 @@ namespace OpenRA
|
|||||||
if (voicedActor != null)
|
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);
|
Sound.PlayVoice(isAttack ? "Attack" : "Move", voicedActor);
|
||||||
|
|
||||||
if (isMove)
|
if (isMove)
|
||||||
|
|||||||
@@ -236,18 +236,15 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
if (Game.Settings.PathDebug)
|
if (Game.Settings.PathDebug)
|
||||||
{
|
{
|
||||||
var mobile = selectedUnit.traits.GetOrDefault<Mobile>();
|
var mobile = selectedUnit.traits.WithInterface<IMove>().FirstOrDefault();
|
||||||
if (mobile != null)
|
if (mobile != null)
|
||||||
{
|
{
|
||||||
var path = mobile.GetCurrentPath();
|
var path = mobile.GetCurrentPath(selectedUnit);
|
||||||
var start = selectedUnit.Location;
|
var start = selectedUnit.CenterLocation;
|
||||||
|
|
||||||
foreach (var step in path)
|
foreach (var step in path)
|
||||||
{
|
{
|
||||||
lineRenderer.DrawLine(
|
lineRenderer.DrawLine(start, step, Color.Red, Color.Red);
|
||||||
Game.CellSize * start + new float2(12, 12),
|
|
||||||
Game.CellSize * step + new float2(12, 12),
|
|
||||||
Color.Red, Color.Red);
|
|
||||||
start = step;
|
start = step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace OpenRA.Orders
|
|||||||
case "Heal": return "heal";
|
case "Heal": return "heal";
|
||||||
case "C4": return "c4";
|
case "C4": return "c4";
|
||||||
case "Move":
|
case "Move":
|
||||||
if (a.traits.GetOrDefault<IMovement>().CanEnterCell(location))
|
if (a.traits.GetOrDefault<IMove>().CanEnterCell(location))
|
||||||
return "move";
|
return "move";
|
||||||
else
|
else
|
||||||
return "move-blocked";
|
return "move-blocked";
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace OpenRA.Traits
|
|||||||
public object Create(ActorInitializer init) { return new Mobile(init); }
|
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;
|
readonly Actor self;
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
if (order.OrderString == "Move")
|
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();
|
if( !order.Queued ) self.CancelActivity();
|
||||||
self.QueueActivity(new Activities.Move(order.TargetLocation, 8));
|
self.QueueActivity(new Activities.Move(order.TargetLocation, 8));
|
||||||
@@ -132,11 +132,12 @@ namespace OpenRA.Traits
|
|||||||
.GetCost(GetMovementType()) < float.PositiveInfinity;
|
.GetCost(GetMovementType()) < float.PositiveInfinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<int2> GetCurrentPath()
|
public IEnumerable<float2> GetCurrentPath(Actor self)
|
||||||
{
|
{
|
||||||
var move = self.GetCurrentActivity() as Activities.Move;
|
var move = self.GetCurrentActivity() as Activities.Move;
|
||||||
if (move == null || move.path == null) return new int2[] { };
|
if (move == null || move.path == null) return new float2[] { };
|
||||||
return Enumerable.Reverse(move.path);
|
|
||||||
|
return Enumerable.Reverse(move.path).Select( c => Game.CellSize * c + new float2(12,12) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,10 +96,11 @@ namespace OpenRA.Traits
|
|||||||
public interface IPaletteModifier { void AdjustPalette(Bitmap b); }
|
public interface IPaletteModifier { void AdjustPalette(Bitmap b); }
|
||||||
public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
|
public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
|
||||||
public interface ITags { IEnumerable<TagType> GetTags(); }
|
public interface ITags { IEnumerable<TagType> GetTags(); }
|
||||||
public interface IMovement
|
public interface IMove
|
||||||
{
|
{
|
||||||
UnitMovementType GetMovementType();
|
UnitMovementType GetMovementType();
|
||||||
bool CanEnterCell(int2 location);
|
bool CanEnterCell(int2 location);
|
||||||
|
IEnumerable<float2> GetCurrentPath(Actor self);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ICrushable
|
public interface ICrushable
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static bool IsActorCrushableByActor(this World world, Actor a, Actor b)
|
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());
|
return movement != null && world.IsActorCrushableByMovementType(a, movement.GetMovementType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Aftermath
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var movement = self.traits.GetOrDefault<IMovement>();
|
var movement = self.traits.GetOrDefault<IMove>();
|
||||||
if (order.OrderString == "ChronoshiftSelf" && movement.CanEnterCell(order.TargetLocation))
|
if (order.OrderString == "ChronoshiftSelf" && movement.CanEnterCell(order.TargetLocation))
|
||||||
{
|
{
|
||||||
if (self.Owner == self.World.LocalPlayer)
|
if (self.Owner == self.World.LocalPlayer)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Aftermath.Orders
|
|||||||
if (!world.LocalPlayer.Shroud.IsExplored(xy))
|
if (!world.LocalPlayer.Shroud.IsExplored(xy))
|
||||||
return "move-blocked";
|
return "move-blocked";
|
||||||
|
|
||||||
var movement = self.traits.GetOrDefault<IMovement>();
|
var movement = self.traits.GetOrDefault<IMove>();
|
||||||
return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked";
|
return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
{
|
{
|
||||||
public class Fly : IActivity
|
public class Fly : IActivity
|
||||||
{
|
{
|
||||||
readonly float2 Pos;
|
public readonly float2 Pos;
|
||||||
bool isCanceled;
|
bool isCanceled;
|
||||||
|
|
||||||
public Fly(float2 pos) { Pos = pos; }
|
public Fly(float2 pos) { Pos = pos; }
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
{
|
{
|
||||||
class HeliFly : IActivity
|
class HeliFly : IActivity
|
||||||
{
|
{
|
||||||
readonly float2 Dest;
|
public readonly float2 Dest;
|
||||||
public HeliFly(float2 dest)
|
public HeliFly(float2 dest)
|
||||||
{
|
{
|
||||||
Dest = dest;
|
Dest = dest;
|
||||||
|
|||||||
@@ -22,8 +22,9 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.GameRules;
|
using OpenRA.GameRules;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Traits
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
public class AircraftInfo : ITraitInfo
|
public class AircraftInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
@@ -34,7 +35,7 @@ namespace OpenRA.Traits
|
|||||||
public virtual object Create( ActorInitializer init ) { return new Aircraft( init ); }
|
public virtual object Create( ActorInitializer init ) { return new Aircraft( init ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Aircraft : IOccupySpace, IMovement
|
public class Aircraft : IMove
|
||||||
{
|
{
|
||||||
[Sync]
|
[Sync]
|
||||||
public int2 Location;
|
public int2 Location;
|
||||||
@@ -49,12 +50,6 @@ namespace OpenRA.Traits
|
|||||||
get { return Location; }
|
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)
|
public bool AircraftCanEnter(Actor self, Actor a)
|
||||||
{
|
{
|
||||||
var aircraft = self.Info.Traits.Get<AircraftInfo>();
|
var aircraft = self.Info.Traits.Get<AircraftInfo>();
|
||||||
@@ -62,6 +57,14 @@ namespace OpenRA.Traits
|
|||||||
|| aircraft.RepairBuildings.Contains( a.Info.Name );
|
|| 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 UnitMovementType GetMovementType() { return UnitMovementType.Fly; }
|
||||||
public bool CanEnterCell(int2 location) { return true; }
|
public bool CanEnterCell(int2 location) { return true; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA
|
|||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
|
|
||||||
// Ensure the target cell is valid for the unit
|
// 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))
|
if (!movement.CanEnterCell(order.TargetLocation))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (!world.LocalPlayer.Shroud.IsExplored(xy))
|
if (!world.LocalPlayer.Shroud.IsExplored(xy))
|
||||||
return "move-blocked";
|
return "move-blocked";
|
||||||
|
|
||||||
var movement = self.traits.GetOrDefault<IMovement>();
|
var movement = self.traits.GetOrDefault<IMove>();
|
||||||
return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked";
|
return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Traits.Activities;
|
using OpenRA.Traits.Activities;
|
||||||
using OpenRA.GameRules;
|
using OpenRA.GameRules;
|
||||||
@@ -37,7 +38,7 @@ namespace OpenRA.Mods.RA
|
|||||||
public override object Create( ActorInitializer init ) { return new Helicopter( init ); }
|
public override object Create( ActorInitializer init ) { return new Helicopter( init ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Helicopter : Aircraft, IIssueOrder, IResolveOrder
|
class Helicopter : Aircraft, ITick, IIssueOrder, IResolveOrder
|
||||||
{
|
{
|
||||||
public IDisposable reservation;
|
public IDisposable reservation;
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
if (underCursor == null)
|
if (underCursor == null)
|
||||||
{
|
{
|
||||||
if (self.traits.GetOrDefault<IMovement>().CanEnterCell(xy))
|
if (self.traits.GetOrDefault<IMove>().CanEnterCell(xy))
|
||||||
return new Order("Move", self, 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 float2.FromAngle((float)self.World.SharedRandom.NextDouble() * 3.14f);
|
||||||
return (5 / d.LengthSquared) * d;
|
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 };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (self.Owner == self.World.LocalPlayer)
|
if (self.Owner == self.World.LocalPlayer)
|
||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
|
|
||||||
var movement = self.traits.Get<IMovement>();
|
var movement = self.traits.Get<IMove>();
|
||||||
|
|
||||||
minefield = GetMinefieldCells(minefieldStart, order.TargetLocation,
|
minefield = GetMinefieldCells(minefieldStart, order.TargetLocation,
|
||||||
self.Info.Traits.Get<MinelayerInfo>().MinefieldDepth)
|
self.Info.Traits.Get<MinelayerInfo>().MinefieldDepth)
|
||||||
@@ -126,7 +126,7 @@ namespace OpenRA.Mods.RA
|
|||||||
public void Render(World world)
|
public void Render(World world)
|
||||||
{
|
{
|
||||||
var ml = minelayer.traits.Get<Minelayer>();
|
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)
|
var minefield = GetMinefieldCells(ml.minefieldStart, lastMousePos, minelayer.Info.Traits.Get<MinelayerInfo>().MinefieldDepth)
|
||||||
.Where(p => movement.CanEnterCell(p)).ToArray();
|
.Where(p => movement.CanEnterCell(p)).ToArray();
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (cargo == null || cargo.IsFull(underCursor))
|
if (cargo == null || cargo.IsFull(underCursor))
|
||||||
return null;
|
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))
|
if (!underCursor.Info.Traits.Get<CargoInfo>().PassengerTypes.Contains(umt))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user