use IIssueOrder2 in AttackBase
This commit is contained in:
@@ -111,6 +111,7 @@ namespace OpenRA.Orders
|
||||
var actorsAt = uim.GetUnitsAt( xy ).ToList();
|
||||
|
||||
string cursor = null;
|
||||
if( underCursor != null )
|
||||
if( o.Order.CanTargetUnit( self, underCursor, mi.Modifiers.HasModifier( Modifiers.Ctrl ), mi.Modifiers.HasModifier( Modifiers.Alt ), ref cursor ) )
|
||||
return new UnitOrderResult( self, o.Order, o.Trait, cursor, Target.FromActor( underCursor ) );
|
||||
if( o.Order.CanTargetLocation( self, xy, actorsAt, mi.Modifiers.HasModifier( Modifiers.Ctrl ), mi.Modifiers.HasModifier( Modifiers.Alt ), ref cursor ) )
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public class Mobile : IIssueOrder2, IResolveOrder, IOrderCursor, IOrderVoice, IOccupySpace, IMove, IFacing, INudge
|
||||
public class Mobile : IIssueOrder2, IResolveOrder, IOrderVoice, IOccupySpace, IMove, IFacing, INudge
|
||||
{
|
||||
public readonly Actor self;
|
||||
public readonly MobileInfo Info;
|
||||
@@ -167,7 +167,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Move" || order.OrderString == "Move-Blocked")
|
||||
if (order.OrderString == "Move")
|
||||
{
|
||||
int2 currentLocation = NearestMoveableCell(order.TargetLocation);
|
||||
if (!CanEnterCell(currentLocation))
|
||||
@@ -187,20 +187,9 @@ namespace OpenRA.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public string CursorForOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Move")
|
||||
return "move";
|
||||
|
||||
if (order.OrderString == "Move-Blocked")
|
||||
return "move-blocked";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Move" || order.OrderString == "Move-Blocked")
|
||||
if (order.OrderString == "Move")
|
||||
return "Move";
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA
|
||||
public virtual object Create(ActorInitializer init) { return new AttackBase(init.self); }
|
||||
}
|
||||
|
||||
public class AttackBase : IIssueOrder, IResolveOrder, ITick, IExplodeModifier, IOrderCursor, IOrderVoice
|
||||
public class AttackBase : IIssueOrder2, IResolveOrder, ITick, IExplodeModifier, IOrderVoice
|
||||
{
|
||||
public bool IsAttacking { get; internal set; }
|
||||
public Target target;
|
||||
@@ -179,50 +179,25 @@ namespace OpenRA.Mods.RA
|
||||
return info.FireDelay;
|
||||
}
|
||||
|
||||
public int OrderPriority(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
bool IsHeal { get { return Weapons[ 0 ].Info.Warheads[ 0 ].Damage < 0; } }
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
return mi.Modifiers.HasModifier(Modifiers.Ctrl) ? 1000 : 1;
|
||||
get { yield return new AttackOrderTargeter( "Attack", 6, IsHeal ); }
|
||||
}
|
||||
|
||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
public Order IssueOrder( Actor self, IOrderTargeter order, Target target )
|
||||
{
|
||||
if (mi.Button == MouseButton.Left) return null;
|
||||
if (self == underCursor) return null;
|
||||
|
||||
var target = underCursor == null ? Target.FromCell(xy) : Target.FromActor(underCursor);
|
||||
|
||||
var isHeal = Weapons[0].Info.Warheads[0].Damage < 0;
|
||||
var forceFire = mi.Modifiers.HasModifier(Modifiers.Ctrl);
|
||||
|
||||
if (isHeal)
|
||||
if( order is AttackOrderTargeter )
|
||||
{
|
||||
// we can never "heal ground"; that makes no sense.
|
||||
if (!target.IsActor) return null;
|
||||
|
||||
// unless forced, only heal allies.
|
||||
if (self.Owner.Stances[underCursor.Owner] != Stance.Ally && !forceFire) return null;
|
||||
|
||||
// don't allow healing of fully-healed stuff!
|
||||
if (underCursor.GetDamageState() == DamageState.Undamaged) return null;
|
||||
}
|
||||
if( target.IsActor )
|
||||
return new Order( IsHeal ? "Heal" : "Attack", self, target.Actor );
|
||||
else
|
||||
{
|
||||
if (!target.IsActor)
|
||||
{
|
||||
if (!forceFire) return null;
|
||||
if (!self.Info.Traits.Get<AttackBaseInfo>().CanAttackGround) return null;
|
||||
return new Order("Attack", self, xy);
|
||||
return new Order( IsHeal ? "Heal" : "Attack", self, Util.CellContaining( target.CenterLocation ) );
|
||||
}
|
||||
|
||||
if ((self.Owner.Stances[underCursor.Owner] != Stance.Enemy) && !forceFire)
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!HasAnyValidWeapons(target)) return null;
|
||||
|
||||
return new Order(isHeal ? "Heal" : "Attack", self, underCursor);
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Attack" || order.OrderString == "Heal")
|
||||
@@ -252,16 +227,6 @@ namespace OpenRA.Mods.RA
|
||||
}
|
||||
}
|
||||
|
||||
public string CursorForOrder(Actor self, Order order)
|
||||
{
|
||||
switch (order.OrderString)
|
||||
{
|
||||
case "Attack": return "attack";
|
||||
case "Heal": return "heal";
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
return (order.OrderString == "Attack" || order.OrderString == "Heal") ? "Attack" : null;
|
||||
@@ -282,5 +247,48 @@ namespace OpenRA.Mods.RA
|
||||
public float GetMaximumRange() { return Weapons.Max(w => w.Info.Range); }
|
||||
|
||||
public Weapon ChooseWeaponForTarget(Target t) { return Weapons.FirstOrDefault(w => w.IsValidAgainst(t)); }
|
||||
|
||||
class AttackOrderTargeter : IOrderTargeter
|
||||
{
|
||||
readonly bool isHeal;
|
||||
|
||||
public AttackOrderTargeter( string order, int priority, bool isHeal )
|
||||
{
|
||||
this.OrderID = order;
|
||||
this.OrderPriority = priority;
|
||||
this.isHeal = isHeal;
|
||||
}
|
||||
|
||||
public string OrderID { get; private set; }
|
||||
public int OrderPriority { get; private set; }
|
||||
|
||||
public bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor )
|
||||
{
|
||||
cursor = isHeal ? "heal" : "attack";
|
||||
if( self == target ) return false;
|
||||
if( !self.Trait<AttackBase>().HasAnyValidWeapons( Target.FromActor( target ) ) ) return false;
|
||||
|
||||
var playerRelationship = self.Owner.Stances[ target.Owner ];
|
||||
|
||||
if( isHeal )
|
||||
return playerRelationship == Stance.Ally || forceAttack;
|
||||
|
||||
else
|
||||
return playerRelationship == Stance.Enemy || forceAttack;
|
||||
}
|
||||
|
||||
public bool CanTargetLocation( Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceMove, ref string cursor )
|
||||
{
|
||||
cursor = isHeal ? "heal" : "attack";
|
||||
if( isHeal ) return false;
|
||||
if( !self.Trait<AttackBase>().HasAnyValidWeapons( Target.FromCell( location ) ) ) return false;
|
||||
|
||||
if( forceAttack )
|
||||
if( self.Info.Traits.Get<AttackBaseInfo>().CanAttackGround )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user