Add crushing logic to aircraft.
This commit is contained in:
@@ -52,6 +52,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Can the actor be ordered to move in to shroud?")]
|
||||
public readonly bool MoveIntoShroud = true;
|
||||
|
||||
[Desc("e.g. crate, wall, infantry")]
|
||||
public readonly BitSet<CrushClass> Crushes = default(BitSet<CrushClass>);
|
||||
|
||||
[Desc("Types of damage that are caused while crushing. Leave empty for no damage types.")]
|
||||
public readonly BitSet<DamageType> CrushDamageTypes = default(BitSet<DamageType>);
|
||||
|
||||
[VoiceReference] public readonly string Voice = "Action";
|
||||
|
||||
[GrantedConditionReference]
|
||||
@@ -166,6 +172,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyActorDisposing, INotifyBecomingIdle,
|
||||
IActorPreviewInitModifier, IIssueDeployOrder, IObservesVariables
|
||||
{
|
||||
static readonly Pair<CPos, SubCell>[] NoCells = { };
|
||||
|
||||
public readonly AircraftInfo Info;
|
||||
readonly Actor self;
|
||||
|
||||
@@ -183,7 +191,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public Actor ReservedActor { get; private set; }
|
||||
public bool MayYieldReservation { get; private set; }
|
||||
public bool ForceLanding { get; private set; }
|
||||
CPos landingCell;
|
||||
CPos? landingCell;
|
||||
|
||||
bool airborne;
|
||||
bool cruising;
|
||||
@@ -495,7 +503,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public Pair<CPos, SubCell>[] OccupiedCells()
|
||||
{
|
||||
if (!self.IsAtGroundLevel())
|
||||
return new[] { Pair.New(landingCell, SubCell.FullCell) };
|
||||
{
|
||||
if (landingCell.HasValue)
|
||||
return new[] { Pair.New(landingCell.Value, SubCell.FullCell) };
|
||||
|
||||
return NoCells;
|
||||
}
|
||||
|
||||
return new[] { Pair.New(TopLeft, SubCell.FullCell) };
|
||||
}
|
||||
@@ -517,16 +530,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return false;
|
||||
|
||||
foreach (var otherActor in self.World.ActorMap.GetActorsAt(cell))
|
||||
{
|
||||
if (otherActor != ignoreActor)
|
||||
if (IsBlockedBy(self, otherActor, ignoreActor))
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var otherActor in self.World.ActorMap.GetActorsAt(cell))
|
||||
{
|
||||
if (AircraftCanEnter(otherActor))
|
||||
return true;
|
||||
}
|
||||
|
||||
var type = self.World.Map.GetTerrainInfo(cell).Type;
|
||||
return Info.LandableTerrainTypes.Contains(type);
|
||||
@@ -542,6 +551,35 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return repairable != null && repairable.Info.RepairActors.Contains(host.Info.Name) && self.GetDamageState() != DamageState.Undamaged;
|
||||
}
|
||||
|
||||
bool IsBlockedBy(Actor self, Actor otherActor, Actor ignoreActor)
|
||||
{
|
||||
// We are not blocked by the actor we are ignoring.
|
||||
if (otherActor == self || otherActor == ignoreActor)
|
||||
return false;
|
||||
|
||||
// PERF: Only perform ITemporaryBlocker trait look-up if mod/map rules contain any actors that are temporary blockers
|
||||
if (self.World.RulesContainTemporaryBlocker)
|
||||
{
|
||||
// If there is a temporary blocker in our path, but we can remove it, we are not blocked.
|
||||
var temporaryBlocker = otherActor.TraitOrDefault<ITemporaryBlocker>();
|
||||
if (temporaryBlocker != null && temporaryBlocker.CanRemoveBlockage(otherActor, self))
|
||||
return false;
|
||||
}
|
||||
|
||||
// If we cannot crush the other actor in our way, we are blocked.
|
||||
if (Info.Crushes.IsEmpty)
|
||||
return true;
|
||||
|
||||
// If the other actor in our way cannot be crushed, we are blocked.
|
||||
// PERF: Avoid LINQ.
|
||||
var crushables = otherActor.TraitsImplementing<ICrushable>();
|
||||
foreach (var crushable in crushables)
|
||||
if (crushable.CrushableBy(otherActor, self, Info.Crushes))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual IEnumerable<Activity> GetResupplyActivities(Actor a)
|
||||
{
|
||||
// The ResupplyAircraft activity guarantees that we're on the helipad/repair depot
|
||||
@@ -589,7 +627,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
else if (!Info.CanHover && !atLandAltitude)
|
||||
self.QueueActivity(new FlyCircle(self, -1, Info.IdleTurnSpeed > -1 ? Info.IdleTurnSpeed : TurnSpeed));
|
||||
else if (atLandAltitude && !CanLand(self.Location, self) && ReservedActor == null)
|
||||
else if (atLandAltitude && !CanLand(self.Location) && ReservedActor == null)
|
||||
self.QueueActivity(new TakeOff(self));
|
||||
else if (Info.CanHover && self.Info.HasTraitInfo<AutoCarryallInfo>() && Info.IdleTurnSpeed > -1)
|
||||
{
|
||||
@@ -629,16 +667,59 @@ namespace OpenRA.Mods.Common.Traits
|
||||
self.World.UpdateMaps(self, this);
|
||||
|
||||
var altitude = self.World.Map.DistanceAboveTerrain(CenterPosition);
|
||||
|
||||
var isAirborne = altitude.Length >= Info.MinAirborneAltitude;
|
||||
if (isAirborne && !airborne)
|
||||
OnAirborneAltitudeReached();
|
||||
else if (!isAirborne && airborne)
|
||||
OnAirborneAltitudeLeft();
|
||||
|
||||
var isCruising = altitude == Info.CruiseAltitude;
|
||||
if (isCruising && !cruising)
|
||||
OnCruisingAltitudeReached();
|
||||
else if (!isCruising && cruising)
|
||||
OnCruisingAltitudeLeft();
|
||||
|
||||
FinishedMoving(self);
|
||||
}
|
||||
|
||||
public void FinishedMoving(Actor self)
|
||||
{
|
||||
// Only make actor crush if it is on the ground
|
||||
if (!self.IsAtGroundLevel())
|
||||
return;
|
||||
|
||||
var actors = self.World.ActorMap.GetActorsAt(TopLeft).Where(a => a != self).ToList();
|
||||
if (!AnyCrushables(actors))
|
||||
return;
|
||||
|
||||
var notifiers = actors.SelectMany(a => a.TraitsImplementing<INotifyCrushed>().Select(t => new TraitPair<INotifyCrushed>(a, t)));
|
||||
foreach (var notifyCrushed in notifiers)
|
||||
notifyCrushed.Trait.OnCrush(notifyCrushed.Actor, self, Info.Crushes);
|
||||
}
|
||||
|
||||
bool AnyCrushables(List<Actor> actors)
|
||||
{
|
||||
var crushables = actors.SelectMany(a => a.TraitsImplementing<ICrushable>().Select(t => new TraitPair<ICrushable>(a, t))).ToList();
|
||||
if (crushables.Count == 0)
|
||||
return false;
|
||||
|
||||
foreach (var crushes in crushables)
|
||||
if (crushes.Trait.CrushableBy(crushes.Actor, self, Info.Crushes))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void EnteringCell(Actor self)
|
||||
{
|
||||
var actors = self.World.ActorMap.GetActorsAt(TopLeft).Where(a => a != self).ToList();
|
||||
if (!AnyCrushables(actors))
|
||||
return;
|
||||
|
||||
var notifiers = actors.SelectMany(a => a.TraitsImplementing<INotifyCrushed>().Select(t => new TraitPair<INotifyCrushed>(a, t)));
|
||||
foreach (var notifyCrushed in notifiers)
|
||||
notifyCrushed.Trait.WarnCrush(notifyCrushed.Actor, self, Info.Crushes);
|
||||
}
|
||||
|
||||
public void AddInfluence(CPos landingCell)
|
||||
@@ -652,6 +733,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (self.IsInWorld)
|
||||
self.World.ActorMap.RemoveInfluence(self, this);
|
||||
|
||||
landingCell = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -213,7 +213,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return false;
|
||||
}
|
||||
|
||||
return !IsEmpty(self) && (aircraft == null || aircraft.CanLand(self.Location, self))
|
||||
return !IsEmpty(self) && (aircraft == null || aircraft.CanLand(self.Location))
|
||||
&& CurrentAdjacentCells != null && CurrentAdjacentCells.Any(c => Passengers.Any(p => p.Trait<IPositionable>().CanEnterCell(c, null, immediate)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user