defer landing decision until needed
This commit is contained in:
@@ -7,15 +7,14 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
{
|
{
|
||||||
class ReturnToBase : IActivity
|
class ReturnToBase : IActivity
|
||||||
{
|
{
|
||||||
// todo: defer decision-making until we are first scheduled!
|
|
||||||
public IActivity NextActivity { get; set; }
|
public IActivity NextActivity { get; set; }
|
||||||
|
|
||||||
bool isCanceled;
|
bool isCanceled;
|
||||||
|
bool isCalculated;
|
||||||
|
Actor dest;
|
||||||
|
|
||||||
readonly float2 w1, w2, w3; /* tangent points to turn circles */
|
float2 w1, w2, w3; /* tangent points to turn circles */
|
||||||
readonly float2 landPoint;
|
float2 landPoint;
|
||||||
|
|
||||||
public ReturnToBase(Actor self)
|
|
||||||
: this( self, null ) {}
|
|
||||||
|
|
||||||
Actor ChooseAirfield(Actor self)
|
Actor ChooseAirfield(Actor self)
|
||||||
{
|
{
|
||||||
@@ -32,10 +31,9 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
return airfield;
|
return airfield;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReturnToBase(Actor self, Actor dest)
|
void Calculate(Actor self)
|
||||||
{
|
{
|
||||||
if (dest == null)
|
if (dest == null) dest = ChooseAirfield(self);
|
||||||
dest = ChooseAirfield(self);
|
|
||||||
|
|
||||||
var landPos = dest.CenterLocation;
|
var landPos = dest.CenterLocation;
|
||||||
var unit = self.traits.Get<Unit>();
|
var unit = self.traits.Get<Unit>();
|
||||||
@@ -67,22 +65,26 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
w2 = c2 + f;
|
w2 = c2 + f;
|
||||||
w3 = approachStart;
|
w3 = approachStart;
|
||||||
landPoint = landPos;
|
landPoint = landPos;
|
||||||
|
|
||||||
|
isCalculated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReturnToBase(Actor self, Actor dest)
|
||||||
|
{
|
||||||
|
this.dest = dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActivity Tick(Actor self)
|
public IActivity Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (isCanceled) return NextActivity;
|
if (isCanceled) return NextActivity;
|
||||||
var unit = self.traits.Get<Unit>();
|
if (!isCalculated)
|
||||||
return new Fly(w1)
|
Calculate(self);
|
||||||
{
|
|
||||||
NextActivity = new Fly(w2)
|
return Util.SequenceActivities(
|
||||||
{
|
new Fly(w1),
|
||||||
NextActivity = new Fly(w3)
|
new Fly(w2),
|
||||||
{
|
new Fly(w3),
|
||||||
NextActivity = new Land(landPoint)
|
new Land(landPoint));
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
|
public void Cancel(Actor self) { isCanceled = true; NextActivity = null; }
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRa.Game.Traits
|
|||||||
self.CancelActivity();
|
self.CancelActivity();
|
||||||
target = order.TargetActor;
|
target = order.TargetActor;
|
||||||
self.QueueActivity(new FlyAttack(order.TargetActor));
|
self.QueueActivity(new FlyAttack(order.TargetActor));
|
||||||
self.QueueActivity(new ReturnToBase(self));
|
self.QueueActivity(new ReturnToBase(self, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user