diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index 6df5f22378..7761814912 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -7,6 +7,7 @@ using IjwFramework.Types; using System.Drawing; using OpenRa.Game.Traits; using OpenRa.Game.Graphics; +using OpenRa.Game.GameRules; namespace OpenRa.Game { @@ -110,10 +111,33 @@ namespace OpenRa.Game public Cursor ChooseCursor() { var c = (orderGenerator is UnitOrderGenerator) ? orderGenerator.Order(dragEnd.ToInt2(), false) - .Select(a => a.Cursor) + .Select(a => CursorForOrderString( a.OrderString, a.Subject, a.TargetLocation )) .FirstOrDefault(a => a != null) : null; return c ?? (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any() ? Cursor.Select : Cursor.Default); } + + Cursor CursorForOrderString( string s, Actor a, int2 location ) + { + switch( s ) + { + case "Attack": return Cursor.Attack; + case "Move": + if( Game.IsCellBuildable( location, UnitMovementType.Wheel, a ) ) + return Cursor.Move; + else + return Cursor.MoveBlocked; + case "DeployMcv": + var factBuildingInfo = (UnitInfo.BuildingInfo)Rules.UnitInfo[ "fact" ]; + if( Game.CanPlaceBuilding( factBuildingInfo, a.Location - new int2( 1, 1 ), a, false ) ) + return Cursor.Deploy; + else + return Cursor.DeployBlocked; + case "DeliverOre": return Cursor.Enter; + case "Harvest": return Cursor.Attack; // TODO: special harvest cursor? + default: + return null; + } + } } } diff --git a/OpenRa.Game/Order.cs b/OpenRa.Game/Order.cs index 6e29ad9623..c66f2387ef 100644 --- a/OpenRa.Game/Order.cs +++ b/OpenRa.Game/Order.cs @@ -15,9 +15,8 @@ namespace OpenRa.Game public readonly Actor TargetActor; public readonly int2 TargetLocation; public readonly string TargetString; - public readonly Cursor Cursor; - Order(Player player, string orderString, Actor subject, Actor targetActor, int2 targetLocation, string targetString, Cursor cursor) + Order(Player player, string orderString, Actor subject, Actor targetActor, int2 targetLocation, string targetString) { this.Player = player; this.OrderString = orderString; @@ -25,7 +24,6 @@ namespace OpenRa.Game this.TargetActor = targetActor; this.TargetLocation = targetLocation; this.TargetString = targetString; - this.Cursor = cursor; } public byte[] Serialize() @@ -74,7 +72,7 @@ namespace OpenRa.Game var targetString = null as string; if (r.ReadBoolean()) targetString = r.ReadString(); - return new Order(player, order, subject, targetActor, targetLocation, targetString, null); + return new Order(player, order, subject, targetActor, targetLocation, targetString); } default: throw new NotImplementedException(); @@ -89,59 +87,57 @@ namespace OpenRa.Game public static Order Chat(Player subject, string text) { - return new Order(subject, "Chat", null, null, int2.Zero, text, null); + return new Order(subject, "Chat", null, null, int2.Zero, text); } public static Order Attack(Actor subject, Actor target) { - return new Order(subject.Owner, "Attack", subject, target, int2.Zero, null, Cursor.Attack); + return new Order(subject.Owner, "Attack", subject, target, int2.Zero, null); } - public static Order Move(Actor subject, int2 target, bool isBlocked) + public static Order Move(Actor subject, int2 target) { - return new Order(subject.Owner, "Move", subject, null, target, null, - isBlocked ? Cursor.MoveBlocked : Cursor.Move); + return new Order(subject.Owner, "Move", subject, null, target, null); } - public static Order DeployMcv(Actor subject, bool isBlocked) + public static Order DeployMcv(Actor subject) { - return new Order(subject.Owner, "DeployMcv", subject, null, int2.Zero, isBlocked ? "nop" : null, - isBlocked ? Cursor.DeployBlocked : Cursor.Deploy); + return new Order(subject.Owner, "DeployMcv", subject, null, int2.Zero, null); } public static Order PlaceBuilding(Player subject, int2 target, string buildingName) { - return new Order(subject, "PlaceBuilding", null, null, target, buildingName, Cursor.None); + return new Order(subject, "PlaceBuilding", null, null, target, buildingName); } public static Order DeliverOre(Actor subject, Actor target) { - return new Order(subject.Owner, "DeliverOre", subject, target, int2.Zero, null, Cursor.Enter); + return new Order(subject.Owner, "DeliverOre", subject, target, int2.Zero, null); } public static Order Harvest(Actor subject, int2 target) { - return new Order(subject.Owner, "Harvest", subject, null, target, null, Cursor.Attack); /* todo: special `harvest` cursor? */ + return new Order(subject.Owner, "Harvest", subject, null, target, null); } public static Order StartProduction(Player subject, string item) { - return new Order(subject, "StartProduction", null, null, int2.Zero, item, Cursor.Default ); + return new Order(subject, "StartProduction", null, null, int2.Zero, item ); } public static Order PauseProduction(Player subject, string item, bool pause) { - return new Order( subject, "PauseProduction", null, null, new int2(pause ?1:0,0), item, Cursor.Default ); + return new Order( subject, "PauseProduction", null, null, new int2(pause ?1:0,0), item ); } public static Order CancelProduction(Player subject, string item) { - return new Order( subject, "CancelProduction", null, null, int2.Zero, item, Cursor.Default ); + return new Order( subject, "CancelProduction", null, null, int2.Zero, item ); } public static Order SetRallyPoint(Actor subject, int2 target) { - return new Order(subject.Owner, "SetRallyPoint", subject, null, target, null, Cursor.Move); + return new Order(subject.Owner, "SetRallyPoint", subject, null, target, null ); } } } diff --git a/OpenRa.Game/Traits/Helicopter.cs b/OpenRa.Game/Traits/Helicopter.cs index 471e73809e..ba14e9a031 100644 --- a/OpenRa.Game/Traits/Helicopter.cs +++ b/OpenRa.Game/Traits/Helicopter.cs @@ -23,8 +23,7 @@ namespace OpenRa.Game.Traits if (lmb) return null; if (underCursor == null) - return OpenRa.Game.Order.Move(self, xy, - !Game.IsCellBuildable(xy, UnitMovementType.Foot)); + return OpenRa.Game.Order.Move(self, xy); return null; } diff --git a/OpenRa.Game/Traits/McvDeploy.cs b/OpenRa.Game/Traits/McvDeploy.cs index 06a2866b98..da4ca3ecd1 100644 --- a/OpenRa.Game/Traits/McvDeploy.cs +++ b/OpenRa.Game/Traits/McvDeploy.cs @@ -13,11 +13,9 @@ namespace OpenRa.Game.Traits public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor) { if (lmb) return null; - if( xy != self.Location ) return null; - var factBuildingInfo = (UnitInfo.BuildingInfo)Rules.UnitInfo[ "fact" ]; - return OpenRa.Game.Order.DeployMcv(self, !Game.CanPlaceBuilding(factBuildingInfo, xy - new int2(1,1), self, false)); + return OpenRa.Game.Order.DeployMcv(self); } } } diff --git a/OpenRa.Game/Traits/Mobile.cs b/OpenRa.Game/Traits/Mobile.cs index a8dcb4dbec..b476d8e848 100644 --- a/OpenRa.Game/Traits/Mobile.cs +++ b/OpenRa.Game/Traits/Mobile.cs @@ -34,8 +34,7 @@ namespace OpenRa.Game.Traits if (xy == toCell) return null; - return OpenRa.Game.Order.Move( self, xy, - !Game.IsCellBuildable(xy, GetMovementType()) ); + return OpenRa.Game.Order.Move( self, xy ); } public IEnumerable OccupiedCells()