Resolve rally point target on first run.

This commit is contained in:
reaperrr
2019-06-02 02:32:07 +00:00
committed by Paul Chote
parent e6402d28a3
commit 8589e26dc2
3 changed files with 20 additions and 14 deletions

View File

@@ -20,8 +20,9 @@ namespace OpenRA.Mods.Common.Activities
{ {
readonly Aircraft aircraft; readonly Aircraft aircraft;
readonly IMove move; readonly IMove move;
readonly Target target; Target target;
bool moveToRallyPoint; bool moveToRallyPoint;
bool assignTargetOnFirstRun;
public TakeOff(Actor self, Target target) public TakeOff(Actor self, Target target)
{ {
@@ -31,16 +32,9 @@ namespace OpenRA.Mods.Common.Activities
} }
public TakeOff(Actor self) public TakeOff(Actor self)
: this(self, Target.FromCell(self.World, self.Location)) : this(self, Target.Invalid)
{ {
var host = aircraft.GetActorBelow(); assignTargetOnFirstRun = true;
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;
} }
protected override void OnFirstRun(Actor self) protected override void OnFirstRun(Actor self)
@@ -48,6 +42,18 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.ForceLanding) if (aircraft.ForceLanding)
return; 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. // We are taking off, so remove reservation and influence in ground cells.
aircraft.UnReserve(); aircraft.UnReserve();
aircraft.RemoveInfluence(); aircraft.RemoveInfluence();

View File

@@ -494,7 +494,7 @@ namespace OpenRA.Mods.Common.Traits
MayYieldReservation = true; MayYieldReservation = true;
} }
public void UnReserve() public void UnReserve(bool takeOff = false)
{ {
if (reservation == null) if (reservation == null)
return; return;
@@ -504,7 +504,7 @@ namespace OpenRA.Mods.Common.Traits
ReservedActor = null; ReservedActor = null;
MayYieldReservation = false; 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)); self.QueueActivity(new TakeOff(self));
} }

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
public IDisposable Reserve(Actor self, Actor forActor, Aircraft forAircraft) public IDisposable Reserve(Actor self, Actor forActor, Aircraft forAircraft)
{ {
if (reservedForAircraft != null && reservedForAircraft.MayYieldReservation) if (reservedForAircraft != null && reservedForAircraft.MayYieldReservation)
reservedForAircraft.UnReserve(); reservedForAircraft.UnReserve(true);
reservedFor = forActor; reservedFor = forActor;
reservedForAircraft = forAircraft; reservedForAircraft = forAircraft;
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits
private void UnReserve() private void UnReserve()
{ {
if (reservedForAircraft != null) if (reservedForAircraft != null)
reservedForAircraft.UnReserve(); reservedForAircraft.UnReserve(true);
} }
void INotifyActorDisposing.Disposing(Actor self) { UnReserve(); } void INotifyActorDisposing.Disposing(Actor self) { UnReserve(); }