Make aircraft occupy cells when landed.

This commit is contained in:
tovl
2019-02-15 15:39:54 +01:00
committed by reaperrr
parent 04a71a6c6a
commit c633e07410
11 changed files with 101 additions and 22 deletions

View File

@@ -105,6 +105,9 @@ namespace OpenRA.Mods.Common.Activities
soundPlayed = true;
}
if (self.IsAtGroundLevel())
aircraft.RemoveInfluence();
// Inside the target annulus, so we're done
var insideMaxRange = maxRange.Length > 0 && checkTarget.IsInRange(aircraft.CenterPosition, maxRange);
var insideMinRange = minRange.Length > 0 && checkTarget.IsInRange(aircraft.CenterPosition, minRange);

View File

@@ -98,6 +98,9 @@ namespace OpenRA.Mods.Common.Activities
soundPlayed = true;
}
if (self.IsAtGroundLevel())
aircraft.RemoveInfluence();
if (AdjustAltitude(self, aircraft, aircraft.Info.CruiseAltitude))
return this;

View File

@@ -19,26 +19,42 @@ namespace OpenRA.Mods.Common.Activities
readonly Aircraft aircraft;
readonly WDist landAltitude;
readonly bool requireSpace;
readonly Actor ignoreActor;
bool soundPlayed;
bool landingInitiated;
public HeliLand(Actor self, bool requireSpace)
: this(self, requireSpace, self.Info.TraitInfo<AircraftInfo>().LandAltitude) { }
public HeliLand(Actor self, bool requireSpace, Actor ignoreActor = null)
: this(self, requireSpace, self.Info.TraitInfo<AircraftInfo>().LandAltitude, ignoreActor) { }
public HeliLand(Actor self, bool requireSpace, WDist landAltitude)
public HeliLand(Actor self, bool requireSpace, WDist landAltitude, Actor ignoreActor = null)
{
this.requireSpace = requireSpace;
this.landAltitude = landAltitude;
this.ignoreActor = ignoreActor;
aircraft = self.Trait<Aircraft>();
}
public override Activity Tick(Actor self)
{
if (IsCanceling)
{
aircraft.RemoveInfluence();
return NextActivity;
}
if (requireSpace && !aircraft.CanLand(self.Location))
return this;
if (requireSpace && !landingInitiated)
{
var landingCell = self.Location;
if (!aircraft.CanLand(landingCell, ignoreActor))
{
self.NotifyBlocker(landingCell);
return this;
}
aircraft.AddInfluence(landingCell);
landingInitiated = true;
}
if (!soundPlayed && aircraft.Info.LandingSounds.Length > 0 && !self.IsAtGroundLevel())
{

View File

@@ -19,22 +19,52 @@ namespace OpenRA.Mods.Common.Activities
{
readonly Target target;
readonly Aircraft aircraft;
readonly bool requireSpace;
readonly Actor ignoreActor;
bool landingInitiated;
bool soundPlayed;
public Land(Actor self, Target t)
public Land(Actor self, Target t, bool requireSpace, Actor ignoreActor = null)
{
target = t;
aircraft = self.Trait<Aircraft>();
this.requireSpace = requireSpace;
this.ignoreActor = ignoreActor;
}
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
if (!target.IsValidFor(self))
Cancel(self);
return NextActivity;
if (IsCanceling)
{
aircraft.RemoveInfluence();
return NextActivity;
}
if (requireSpace && !landingInitiated)
{
var landingCell = self.World.Map.CellContaining(target.CenterPosition);
if (!aircraft.CanLand(landingCell, ignoreActor))
{
// Maintain holding pattern.
QueueChild(self, new FlyCircle(self, 25), true);
self.NotifyBlocker(landingCell);
return this;
}
aircraft.AddInfluence(landingCell);
landingInitiated = true;
}
if (!soundPlayed && aircraft.Info.LandingSounds.Length > 0 && !self.IsAtGroundLevel())
{

View File

@@ -230,10 +230,10 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.Info.TurnToDock)
QueueChild(self, new Turn(self, aircraft.Info.InitialFacing), true);
QueueChild(self, new HeliLand(self, false), true);
QueueChild(self, new HeliLand(self, true, dest), true);
}
else
QueueChild(self, new Land(self, Target.FromPos(dest.CenterPosition + offset)), true);
QueueChild(self, new Land(self, Target.FromPos(dest.CenterPosition + offset), true, dest), true);
QueueChild(self, new ResupplyAircraft(self), true);
resupplied = true;