Resolve rally point target on first run.
This commit is contained in:
@@ -20,8 +20,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
readonly Aircraft aircraft;
|
||||
readonly IMove move;
|
||||
readonly Target target;
|
||||
Target target;
|
||||
bool moveToRallyPoint;
|
||||
bool assignTargetOnFirstRun;
|
||||
|
||||
public TakeOff(Actor self, Target target)
|
||||
{
|
||||
@@ -31,16 +32,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
}
|
||||
|
||||
public TakeOff(Actor self)
|
||||
: this(self, Target.FromCell(self.World, self.Location))
|
||||
: this(self, Target.Invalid)
|
||||
{
|
||||
var host = aircraft.GetActorBelow();
|
||||
var rp = host != null ? host.TraitOrDefault<RallyPoint>() : null;
|
||||
|
||||
var rallyPointDestination = rp != null ? rp.Location :
|
||||
(host != null ? self.World.Map.CellContaining(host.CenterPosition) : self.Location);
|
||||
|
||||
this.target = Target.FromCell(self.World, rallyPointDestination);
|
||||
moveToRallyPoint = NextActivity == null && rallyPointDestination != self.Location;
|
||||
assignTargetOnFirstRun = true;
|
||||
}
|
||||
|
||||
protected override void OnFirstRun(Actor self)
|
||||
@@ -48,6 +42,18 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (aircraft.ForceLanding)
|
||||
return;
|
||||
|
||||
if (assignTargetOnFirstRun)
|
||||
{
|
||||
var host = aircraft.GetActorBelow();
|
||||
var rp = host != null ? host.TraitOrDefault<RallyPoint>() : null;
|
||||
|
||||
var rallyPointDestination = rp != null ? rp.Location :
|
||||
(host != null ? self.World.Map.CellContaining(host.CenterPosition) : self.Location);
|
||||
|
||||
target = Target.FromCell(self.World, rallyPointDestination);
|
||||
moveToRallyPoint = self.CurrentActivity.NextActivity == null && rallyPointDestination != self.Location;
|
||||
}
|
||||
|
||||
// We are taking off, so remove reservation and influence in ground cells.
|
||||
aircraft.UnReserve();
|
||||
aircraft.RemoveInfluence();
|
||||
|
||||
@@ -494,7 +494,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
MayYieldReservation = true;
|
||||
}
|
||||
|
||||
public void UnReserve()
|
||||
public void UnReserve(bool takeOff = false)
|
||||
{
|
||||
if (reservation == null)
|
||||
return;
|
||||
@@ -504,7 +504,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
ReservedActor = null;
|
||||
MayYieldReservation = false;
|
||||
|
||||
if (self.World.Map.DistanceAboveTerrain(CenterPosition).Length <= LandAltitude.Length)
|
||||
if (takeOff && self.World.Map.DistanceAboveTerrain(CenterPosition).Length <= LandAltitude.Length)
|
||||
self.QueueActivity(new TakeOff(self));
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public IDisposable Reserve(Actor self, Actor forActor, Aircraft forAircraft)
|
||||
{
|
||||
if (reservedForAircraft != null && reservedForAircraft.MayYieldReservation)
|
||||
reservedForAircraft.UnReserve();
|
||||
reservedForAircraft.UnReserve(true);
|
||||
|
||||
reservedFor = forActor;
|
||||
reservedForAircraft = forAircraft;
|
||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
private void UnReserve()
|
||||
{
|
||||
if (reservedForAircraft != null)
|
||||
reservedForAircraft.UnReserve();
|
||||
reservedForAircraft.UnReserve(true);
|
||||
}
|
||||
|
||||
void INotifyActorDisposing.Disposing(Actor self) { UnReserve(); }
|
||||
|
||||
Reference in New Issue
Block a user