planes return to base after attacking
This commit is contained in:
@@ -14,7 +14,8 @@ namespace OpenRa.Game.Traits.Activities
|
||||
|
||||
public IActivity Tick(Actor self)
|
||||
{
|
||||
if (Target == null || Target.IsDead) return NextActivity;
|
||||
if (Target == null || Target.IsDead)
|
||||
return NextActivity;
|
||||
|
||||
var limitedAmmo = self.traits.GetOrDefault<LimitedAmmo>();
|
||||
if (limitedAmmo != null && !limitedAmmo.HasAmmo())
|
||||
|
||||
@@ -7,14 +7,37 @@ namespace OpenRa.Game.Traits.Activities
|
||||
{
|
||||
class ReturnToBase : IActivity
|
||||
{
|
||||
// todo: defer decision-making until we are first scheduled!
|
||||
public IActivity NextActivity { get; set; }
|
||||
bool isCanceled;
|
||||
|
||||
readonly float2 w1, w2, w3; /* tangent points to turn circles */
|
||||
readonly float2 landPoint;
|
||||
|
||||
public ReturnToBase(Actor self, float2 landPos)
|
||||
public ReturnToBase(Actor self)
|
||||
: this( self, null ) {}
|
||||
|
||||
Actor ChooseAirfield(Actor self)
|
||||
{
|
||||
// todo: handle reservations
|
||||
|
||||
var airfield = Game.world.Actors
|
||||
.Where(a => a.Info == Rules.UnitInfo["AFLD"]
|
||||
&& a.Owner == self.Owner)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (airfield == null)
|
||||
throw new NotImplementedException("nowhere to land; what to do?");
|
||||
|
||||
return airfield;
|
||||
}
|
||||
|
||||
public ReturnToBase(Actor self, Actor dest)
|
||||
{
|
||||
if (dest == null)
|
||||
dest = ChooseAirfield(self);
|
||||
|
||||
var landPos = dest.CenterLocation;
|
||||
var unit = self.traits.Get<Unit>();
|
||||
var speed = .2f * Util.GetEffectiveSpeed(self);
|
||||
var approachStart = landPos - new float2(unit.Altitude * speed, 0);
|
||||
|
||||
@@ -31,8 +31,10 @@ namespace OpenRa.Game.Traits
|
||||
|
||||
protected override void QueueAttack(Actor self, Order order)
|
||||
{
|
||||
self.QueueActivity(new FlyAttack(order.TargetActor));
|
||||
self.CancelActivity();
|
||||
target = order.TargetActor;
|
||||
self.QueueActivity(new FlyAttack(order.TargetActor));
|
||||
self.QueueActivity(new ReturnToBase(self));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRa.Game.Traits
|
||||
if (order.OrderString == "Enter")
|
||||
{
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new ReturnToBase(self, order.TargetActor.CenterLocation));
|
||||
self.QueueActivity(new ReturnToBase(self, order.TargetActor));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace OpenRa.Game.Traits
|
||||
|
||||
public static IActivity SequenceActivities(params IActivity[] acts)
|
||||
{
|
||||
return acts.Reverse().Aggregate((IActivity)null,
|
||||
return acts.Reverse().Aggregate(
|
||||
(next, a) => { a.NextActivity = next; return a; });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user