Begin to unhack unit movement/cursors; Flying units no longer show move-blocked cursor on water

This commit is contained in:
Paul Chote
2009-12-21 03:09:47 -08:00
parent 7fa1da0d7d
commit 7aea135113
9 changed files with 46 additions and 15 deletions

View File

@@ -128,11 +128,12 @@ namespace OpenRa.Game
Cursor CursorForOrderString( string s, Actor a, int2 location )
{
var movement = a.traits.WithInterface<IMovement>().FirstOrDefault();
switch( s )
{
case "Attack": return Cursor.Attack;
case "Move":
if( Game.IsCellBuildable( location, a.Info.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel, a ) )
if (movement.CanEnterCell(location))
return Cursor.Move;
else
return Cursor.MoveBlocked;
@@ -143,12 +144,12 @@ namespace OpenRa.Game
else
return Cursor.DeployBlocked;
case "ActivatePortableChronoshift": return Cursor.Deploy;
case "UsePortableChronoshift":
if (Game.IsCellBuildable(location, a.Info.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel, a))
case "UsePortableChronoshift":
if (movement.CanEnterCell(location))
return Cursor.Chronoshift;
else
return Cursor.MoveBlocked;
case "DeliverOre": return Cursor.Enter;
case "Enter": return Cursor.Enter;
case "Harvest": return Cursor.Attack; // TODO: special harvest cursor?
default:
return null;

View File

@@ -169,9 +169,9 @@ namespace OpenRa.Game
return new Order("PlaceBuilding", subject.PlayerActor, null, target, buildingName);
}
public static Order DeliverOre(Actor subject, Actor target)
public static Order Enter(Actor subject, Actor target)
{
return new Order("DeliverOre", subject, target, int2.Zero, null);
return new Order("Enter", subject, target, int2.Zero, null);
}
public static Order Harvest(Actor subject, int2 target)

View File

@@ -8,6 +8,7 @@ namespace OpenRa.Game
Track = 1,
Wheel = 2,
Float = 3,
Fly = 4,
}
enum TerrainMovementType : byte

View File

@@ -32,7 +32,7 @@ namespace OpenRa.Game.Traits
if (underCursor != null
&& underCursor.Owner == self.Owner
&& underCursor.traits.Contains<AcceptsOre>() && !IsEmpty)
return Order.DeliverOre(self, underCursor);
return Order.Enter(self, underCursor);
if (underCursor == null && Rules.Map.ContainsResource(xy))
return Order.Harvest(self, xy);
@@ -48,7 +48,7 @@ namespace OpenRa.Game.Traits
self.QueueActivity(new Traits.Activities.Move(order.TargetLocation, 0));
self.QueueActivity(new Traits.Activities.Harvest());
}
else if (order.OrderString == "DeliverOre")
else if (order.OrderString == "Enter")
{
self.CancelActivity();
self.QueueActivity(new Traits.Activities.DeliverOre(order.TargetActor));

View File

@@ -4,7 +4,7 @@ using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits
{
class Helicopter : ITick, IOrder
class Helicopter : ITick, IOrder, IMovement
{
public int2 targetLocation;
@@ -74,5 +74,14 @@ namespace OpenRa.Game.Traits
/* todo: bob slightly when hovering */
}
public UnitMovementType GetMovementType()
{
return UnitMovementType.Fly;
}
public bool CanEnterCell(int2 location)
{
return true; // Planes can go anywhere (?)
}
}
}

View File

@@ -5,7 +5,7 @@ using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits
{
class Mobile : IOrder, IOccupySpace
class Mobile : IOrder, IOccupySpace, IMovement
{
readonly Actor self;
@@ -74,11 +74,16 @@ namespace OpenRa.Game.Traits
case "Ship":
return UnitMovementType.Float;
case "Plane":
return UnitMovementType.Track; // FIXME: remove this when planes actually fly.
return UnitMovementType.Fly;
default:
throw new InvalidOperationException("GetMovementType on unit that shouldn't be aable to move.");
}
}
public bool CanEnterCell(int2 location)
{
return Game.IsCellBuildable( location, GetMovementType(), self );
}
public IEnumerable<int2> GetCurrentPath()
{

View File

@@ -6,7 +6,7 @@ using OpenRa.Game.Traits.Activities;
namespace OpenRa.Game.Traits
{
class Plane : IOrder
class Plane : IOrder, IMovement
{
public Plane(Actor self)
{
@@ -19,7 +19,7 @@ namespace OpenRa.Game.Traits
return Order.Move(self, xy);
if (underCursor.Info == Rules.UnitInfo["AFLD"]
&& underCursor.Owner == self.Owner)
return Order.DeliverOre(self, underCursor); /* brutal hack */
return Order.Enter(self, underCursor);
return null;
}
@@ -31,11 +31,21 @@ namespace OpenRa.Game.Traits
self.QueueActivity(new Circle(order.TargetLocation));
}
if (order.OrderString == "DeliverOre")
if (order.OrderString == "Enter")
{
self.CancelActivity();
self.QueueActivity(new ReturnToBase(self, order.TargetActor.CenterLocation));
}
}
public UnitMovementType GetMovementType()
{
return UnitMovementType.Fly;
}
public bool CanEnterCell(int2 location)
{
return true; // Planes can go anywhere (?)
}
}
}

View File

@@ -29,4 +29,9 @@ namespace OpenRa.Game.Traits
interface ISpeedModifier { float GetSpeedModifier(); }
interface IPips { IEnumerable<PipType> GetPips(); }
interface ITags { IEnumerable<TagType> GetTags(); }
interface IMovement
{
UnitMovementType GetMovementType();
bool CanEnterCell(int2 location);
}
}

View File

@@ -15,7 +15,7 @@ namespace OpenRa.Game
case "Move":
case "Attack":
case "DeployMcv":
case "DeliverOre":
case "Enter":
case "Harvest":
case "SetRallyPoint":
case "StartProduction":