Allow driving under crates and crushable units
This commit is contained in:
@@ -567,30 +567,23 @@ namespace OpenRA.Mods.Common.Traits
|
||||
foreach (var n in notifyFinishedMoving)
|
||||
n.FinishedMoving(self, fromCell.Layer, toCell.Layer);
|
||||
|
||||
// Only make actor crush if it is on the ground
|
||||
// Only crush actors on having landed
|
||||
if (!self.IsAtGroundLevel())
|
||||
return;
|
||||
|
||||
var actors = self.World.ActorMap.GetActorsAt(ToCell, ToSubCell).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.LocomotorInfo.Crushes);
|
||||
CrushAction(self, (notifyCrushed) => notifyCrushed.OnCrush);
|
||||
}
|
||||
|
||||
bool AnyCrushables(List<Actor> actors)
|
||||
void CrushAction(Actor self, Func<INotifyCrushed, Action<Actor, Actor, BitSet<CrushClass>>> action)
|
||||
{
|
||||
var crushables = actors.SelectMany(a => a.TraitsImplementing<ICrushable>().Select(t => new TraitPair<ICrushable>(a, t))).ToList();
|
||||
if (crushables.Count == 0)
|
||||
return false;
|
||||
var crushables = self.World.ActorMap.GetActorsAt(ToCell, ToSubCell).Where(a => a != self)
|
||||
.SelectMany(a => a.TraitsImplementing<ICrushable>().Select(t => new TraitPair<ICrushable>(a, t)));
|
||||
|
||||
foreach (var crushes in crushables)
|
||||
if (crushes.Trait.CrushableBy(crushes.Actor, self, Info.LocomotorInfo.Crushes))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
// Only crush actors that are on the ground level
|
||||
foreach (var crushable in crushables)
|
||||
if (crushable.Trait.CrushableBy(crushable.Actor, self, Info.LocomotorInfo.Crushes) && crushable.Actor.IsAtGroundLevel())
|
||||
foreach (var notifyCrushed in crushable.Actor.TraitsImplementing<INotifyCrushed>())
|
||||
action(notifyCrushed)(crushable.Actor, self, Info.LocomotorInfo.Crushes);
|
||||
}
|
||||
|
||||
public void AddInfluence()
|
||||
@@ -792,17 +785,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void EnteringCell(Actor self)
|
||||
{
|
||||
// Only make actor crush if it is on the ground
|
||||
// Only crush actors on having landed
|
||||
if (!self.IsAtGroundLevel())
|
||||
return;
|
||||
|
||||
var actors = self.World.ActorMap.GetActorsAt(ToCell).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.LocomotorInfo.Crushes);
|
||||
CrushAction(self, (notifyCrushed) => notifyCrushed.WarnCrush);
|
||||
}
|
||||
|
||||
public Activity MoveTo(Func<BlockedByActor, List<CPos>> pathFunc) { return new Move(self, pathFunc); }
|
||||
|
||||
Reference in New Issue
Block a user