No. Just No. GTFO. Orders do NOT store cursors. That is all

This commit is contained in:
Bob
2009-11-25 19:44:38 +13:00
parent 390fc8f2d1
commit e9b87640bd
5 changed files with 43 additions and 27 deletions

View File

@@ -7,6 +7,7 @@ using IjwFramework.Types;
using System.Drawing; using System.Drawing;
using OpenRa.Game.Traits; using OpenRa.Game.Traits;
using OpenRa.Game.Graphics; using OpenRa.Game.Graphics;
using OpenRa.Game.GameRules;
namespace OpenRa.Game namespace OpenRa.Game
{ {
@@ -110,10 +111,33 @@ namespace OpenRa.Game
public Cursor ChooseCursor() public Cursor ChooseCursor()
{ {
var c = (orderGenerator is UnitOrderGenerator) ? orderGenerator.Order(dragEnd.ToInt2(), false) 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; .FirstOrDefault(a => a != null) : null;
return c ?? (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any() ? Cursor.Select : Cursor.Default); 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;
}
}
} }
} }

View File

@@ -15,9 +15,8 @@ namespace OpenRa.Game
public readonly Actor TargetActor; public readonly Actor TargetActor;
public readonly int2 TargetLocation; public readonly int2 TargetLocation;
public readonly string TargetString; 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.Player = player;
this.OrderString = orderString; this.OrderString = orderString;
@@ -25,7 +24,6 @@ namespace OpenRa.Game
this.TargetActor = targetActor; this.TargetActor = targetActor;
this.TargetLocation = targetLocation; this.TargetLocation = targetLocation;
this.TargetString = targetString; this.TargetString = targetString;
this.Cursor = cursor;
} }
public byte[] Serialize() public byte[] Serialize()
@@ -74,7 +72,7 @@ namespace OpenRa.Game
var targetString = null as string; var targetString = null as string;
if (r.ReadBoolean()) if (r.ReadBoolean())
targetString = r.ReadString(); targetString = r.ReadString();
return new Order(player, order, subject, targetActor, targetLocation, targetString, null); return new Order(player, order, subject, targetActor, targetLocation, targetString);
} }
default: default:
throw new NotImplementedException(); throw new NotImplementedException();
@@ -89,59 +87,57 @@ namespace OpenRa.Game
public static Order Chat(Player subject, string text) 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) 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, return new Order(subject.Owner, "Move", subject, null, target, null);
isBlocked ? Cursor.MoveBlocked : Cursor.Move);
} }
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, return new Order(subject.Owner, "DeployMcv", subject, null, int2.Zero, null);
isBlocked ? Cursor.DeployBlocked : Cursor.Deploy);
} }
public static Order PlaceBuilding(Player subject, int2 target, string buildingName) 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) 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) 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) 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) 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) 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) 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 );
} }
} }
} }

View File

@@ -23,8 +23,7 @@ namespace OpenRa.Game.Traits
if (lmb) return null; if (lmb) return null;
if (underCursor == null) if (underCursor == null)
return OpenRa.Game.Order.Move(self, xy, return OpenRa.Game.Order.Move(self, xy);
!Game.IsCellBuildable(xy, UnitMovementType.Foot));
return null; return null;
} }

View File

@@ -13,11 +13,9 @@ namespace OpenRa.Game.Traits
public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor) public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor)
{ {
if (lmb) return null; if (lmb) return null;
if( xy != self.Location ) return null; if( xy != self.Location ) return null;
var factBuildingInfo = (UnitInfo.BuildingInfo)Rules.UnitInfo[ "fact" ]; return OpenRa.Game.Order.DeployMcv(self);
return OpenRa.Game.Order.DeployMcv(self, !Game.CanPlaceBuilding(factBuildingInfo, xy - new int2(1,1), self, false));
} }
} }
} }

View File

@@ -34,8 +34,7 @@ namespace OpenRa.Game.Traits
if (xy == toCell) return null; if (xy == toCell) return null;
return OpenRa.Game.Order.Move( self, xy, return OpenRa.Game.Order.Move( self, xy );
!Game.IsCellBuildable(xy, GetMovementType()) );
} }
public IEnumerable<int2> OccupiedCells() public IEnumerable<int2> OccupiedCells()