Added attack order. Cursor is currently incorrect.

This commit is contained in:
Bob
2009-10-26 23:25:35 +13:00
parent 612490e5b8
commit 3ef0f90b00
5 changed files with 52 additions and 22 deletions

View File

@@ -67,8 +67,10 @@ namespace OpenRa.Game
if (Owner != Game.LocalPlayer) if (Owner != Game.LocalPlayer)
return null; return null;
var underCursor = Game.UnitInfluence.GetUnitAt( xy ) ?? Game.BuildingInfluence.GetBuildingAt( xy );
return traits.WithInterface<Traits.IOrder>() return traits.WithInterface<Traits.IOrder>()
.Select( x => x.Order( this, xy, lmb ) ) .Select( x => x.Order( this, xy, lmb, underCursor ) )
.FirstOrDefault( x => x != null ); .FirstOrDefault( x => x != null );
} }

View File

@@ -5,7 +5,7 @@ using System.Text;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class AttackTurreted : ITick class AttackTurreted : ITick, IOrder
{ {
public Actor target; public Actor target;
@@ -52,5 +52,30 @@ namespace OpenRa.Game.Traits
return true; return true;
} }
public Order Order( Actor self, int2 xy, bool lmb, Actor underCursor )
{
if( underCursor == null ) return null;
if( underCursor.Owner == self.Owner ) return null;
return new AttackOrder( self, underCursor );
}
}
class AttackOrder : Order
{
public readonly Actor Attacker;
public readonly Actor Target;
public AttackOrder( Actor attacker, Actor target )
{
this.Attacker = attacker;
this.Target = target;
}
public override void Apply()
{
Attacker.traits.Get<AttackTurreted>().target = Target;
}
} }
} }

View File

@@ -11,7 +11,7 @@ namespace OpenRa.Game.Traits
{ {
} }
public Order Order(Actor self, int2 xy, bool lmb) public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor)
{ {
if( lmb ) return null; if( lmb ) return null;

View File

@@ -47,10 +47,13 @@ namespace OpenRa.Game.Traits
fromCell = toCell; fromCell = toCell;
} }
public Order Order(Actor self, int2 xy, bool lmb) public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor)
{ {
if( lmb ) return null; if( lmb ) return null;
if( underCursor != null )
return null;
if (xy != toCell) if (xy != toCell)
return new MoveOrder(self, xy); return new MoveOrder(self, xy);

View File

@@ -9,5 +9,5 @@ namespace OpenRa.Game.Traits
{ {
interface ITick { void Tick(Actor self); } interface ITick { void Tick(Actor self); }
interface IRender { IEnumerable<Pair<Sprite, float2>> Render(Actor self); } interface IRender { IEnumerable<Pair<Sprite, float2>> Render(Actor self); }
interface IOrder { Order Order(Actor self, int2 xy, bool lmb); } interface IOrder { Order Order(Actor self, int2 xy, bool lmb, Actor underCursor); }
} }