more of attack-ground (order wiring, etc); doesn't work.
This commit is contained in:
@@ -70,6 +70,16 @@ namespace OpenRA.Traits.Activities
|
||||
this.nearEnough = range;
|
||||
}
|
||||
|
||||
public Move(Target target, int range)
|
||||
: this()
|
||||
{
|
||||
this.getPath = self => self.World.PathFinder.FindUnitPathToRange(
|
||||
self.Location, Util.CellContaining(target.CenterLocation),
|
||||
range, self);
|
||||
this.destination = null;
|
||||
this.nearEnough = range;
|
||||
}
|
||||
|
||||
public Move(Func<List<int2>> getPath)
|
||||
: this()
|
||||
{
|
||||
|
||||
@@ -165,6 +165,9 @@ namespace OpenRA.Traits
|
||||
|
||||
public static Target FromActor(Actor a) { return new Target { actor = a, valid = true }; }
|
||||
public static Target FromPos(float2 p) { return new Target { pos = p, valid = true }; }
|
||||
public static Target FromOrder(Order o) { return o.TargetActor != null ? Target.FromActor(o.TargetActor) : Target.FromPos(o.TargetLocation); }
|
||||
|
||||
public static readonly Target None = new Target();
|
||||
|
||||
public bool IsValid { get { return valid && (actor == null || actor.IsInWorld); } }
|
||||
public float2 CenterLocation { get { return actor != null ? actor.CenterLocation : pos; } }
|
||||
|
||||
@@ -57,9 +57,6 @@ namespace OpenRA.Mods.RA.Activities
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Cancel(Actor self)
|
||||
{
|
||||
Target = new Target();
|
||||
}
|
||||
public void Cancel(Actor self) { Target = Target.None; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ namespace OpenRA.Mods.RA.Activities
|
||||
public class FlyAttack : IActivity
|
||||
{
|
||||
public IActivity NextActivity { get; set; }
|
||||
Actor Target;
|
||||
Target Target;
|
||||
|
||||
public FlyAttack(Actor target) { Target = target; }
|
||||
public FlyAttack(Target target) { Target = target; }
|
||||
|
||||
public IActivity Tick(Actor self)
|
||||
{
|
||||
if (Target == null || Target.IsDead)
|
||||
if (!Target.IsValid)
|
||||
return NextActivity;
|
||||
|
||||
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>();
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
this);
|
||||
}
|
||||
|
||||
public void Cancel(Actor self) { Target = null; NextActivity = null; }
|
||||
public void Cancel(Actor self) { Target = Target.None; NextActivity = null; }
|
||||
}
|
||||
|
||||
public class FlyCircle : IActivity
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class Follow : IActivity
|
||||
{
|
||||
Actor Target;
|
||||
Target Target;
|
||||
int Range;
|
||||
|
||||
public Follow(Actor target, int range)
|
||||
public Follow(Target target, int range)
|
||||
{
|
||||
Target = target;
|
||||
Range = range;
|
||||
@@ -28,10 +28,10 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
public IActivity Tick( Actor self )
|
||||
{
|
||||
if (Target == null || Target.IsDead)
|
||||
if (!Target.IsValid)
|
||||
return NextActivity;
|
||||
|
||||
var inRange = ( Target.Location - self.Location ).LengthSquared < Range * Range;
|
||||
var inRange = ( Util.CellContaining( Target.CenterLocation ) - self.Location ).LengthSquared < Range * Range;
|
||||
|
||||
if( !inRange )
|
||||
return new Move( Target, Range ) { NextActivity = this };
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
public void Cancel(Actor self)
|
||||
{
|
||||
Target = null;
|
||||
Target = Target.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,14 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
public class HeliAttack : IActivity
|
||||
{
|
||||
Actor target;
|
||||
public HeliAttack( Actor target ) { this.target = target; }
|
||||
Target target;
|
||||
public HeliAttack( Target target ) { this.target = target; }
|
||||
|
||||
public IActivity NextActivity { get; set; }
|
||||
|
||||
public IActivity Tick(Actor self)
|
||||
{
|
||||
if (target == null || target.IsDead)
|
||||
if (!target.IsValid)
|
||||
return NextActivity;
|
||||
|
||||
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>();
|
||||
@@ -55,6 +55,6 @@ namespace OpenRA.Mods.RA.Activities
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Cancel(Actor self) { target = null; NextActivity = null; }
|
||||
public void Cancel(Actor self) { target = Target.None; NextActivity = null; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,26 +203,36 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
{
|
||||
if (mi.Button == MouseButton.Left || underCursor == null || underCursor.Owner == null) return null;
|
||||
if (mi.Button == MouseButton.Left) return null;
|
||||
if (self == underCursor) return null;
|
||||
|
||||
var target = underCursor == null ? Target.FromPos(Util.CenterOfCell(xy)) : Target.FromActor(underCursor);
|
||||
|
||||
var isHeal = self.GetPrimaryWeapon().Warheads.First().Damage < 0;
|
||||
var forceFire = mi.Modifiers.HasModifier(Modifiers.Ctrl);
|
||||
|
||||
if (isHeal)
|
||||
{
|
||||
if (underCursor.Owner == null)
|
||||
return null;
|
||||
if (self.Owner.Stances[ underCursor.Owner ] != Stance.Ally && !forceFire)
|
||||
return null;
|
||||
if (underCursor.Health >= underCursor.GetMaxHP())
|
||||
return null; // don't allow healing of fully-healed stuff!
|
||||
// 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.Health >= underCursor.GetMaxHP()) return null;
|
||||
}
|
||||
else
|
||||
if ((self.Owner.Stances[ underCursor.Owner ] != Stance.Enemy) && !forceFire)
|
||||
return null;
|
||||
{
|
||||
if (!target.IsActor)
|
||||
{
|
||||
if (!forceFire) return null;
|
||||
return new Order("Attack", self, xy);
|
||||
}
|
||||
|
||||
if (!Combat.HasAnyValidWeapons(self, Target.FromActor(underCursor))) return null;
|
||||
if ((self.Owner.Stances[underCursor.Owner] != Stance.Enemy) && !forceFire)
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!Combat.HasAnyValidWeapons(self, target)) return null;
|
||||
|
||||
return new Order(isHeal ? "Heal" : "Attack", self, underCursor);
|
||||
}
|
||||
@@ -234,11 +244,11 @@ namespace OpenRA.Mods.RA
|
||||
self.CancelActivity();
|
||||
QueueAttack(self, order);
|
||||
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
if (self.Owner == self.World.LocalPlayer && order.TargetActor != null)
|
||||
self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor)));
|
||||
}
|
||||
else
|
||||
target = new Target();
|
||||
target = Target.None;
|
||||
}
|
||||
|
||||
public string CursorForOrderString(string s, Actor a, int2 location)
|
||||
@@ -255,8 +265,9 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
/* todo: choose the appropriate weapon, when only one works against this target */
|
||||
var weapon = self.GetPrimaryWeapon() ?? self.GetSecondaryWeapon();
|
||||
|
||||
self.QueueActivity(new Activities.Attack(Target.FromActor(order.TargetActor),
|
||||
self.QueueActivity(
|
||||
new Activities.Attack(
|
||||
Target.FromOrder(order),
|
||||
Math.Max(0, (int)weapon.Range)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
protected override void QueueAttack(Actor self, Order order)
|
||||
{
|
||||
target = Target.FromActor(order.TargetActor);
|
||||
self.QueueActivity(new HeliAttack(order.TargetActor));
|
||||
target = Target.FromOrder(order);
|
||||
self.QueueActivity(new HeliAttack(target));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
protected override void QueueAttack(Actor self, Order order)
|
||||
{
|
||||
target = Target.FromActor(order.TargetActor);
|
||||
target = Target.FromOrder(order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
protected override void QueueAttack(Actor self, Order order)
|
||||
{
|
||||
target = Target.FromActor(order.TargetActor);
|
||||
self.QueueActivity(new FlyAttack(order.TargetActor));
|
||||
target = Target.FromOrder(order);
|
||||
self.QueueActivity(new FlyAttack(target));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,12 +52,11 @@ namespace OpenRA.Mods.RA
|
||||
/* todo: choose the appropriate weapon, when only one works against this target */
|
||||
var weapon = order.Subject.GetPrimaryWeapon() ?? order.Subject.GetSecondaryWeapon();
|
||||
|
||||
target = Target.FromOrder(order);
|
||||
|
||||
if (self.traits.Contains<Mobile>())
|
||||
self.QueueActivity( new Follow( order.TargetActor,
|
||||
self.QueueActivity( new Follow( target,
|
||||
Math.Max( 0, (int)weapon.Range - RangeTolerance ) ) );
|
||||
|
||||
target = Target.FromActor(order.TargetActor);
|
||||
|
||||
}
|
||||
|
||||
bool buildComplete = false;
|
||||
|
||||
@@ -162,7 +162,8 @@ namespace OpenRA.Mods.RA
|
||||
public static bool WeaponValidForTarget(WeaponInfo weapon, Target target)
|
||||
{
|
||||
// todo: fix this properly.
|
||||
if (!target.IsValid || !target.IsActor) return false;
|
||||
if (!target.IsValid) return false;
|
||||
if (!target.IsActor) return weapon.ValidTargets.Contains("Ground"); // hack!
|
||||
|
||||
var ownedInfo = target.Actor.Info.Traits.GetOrDefault<OwnedActorInfo>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user