From 24ec7b0ad7958ea357194a4cc82e950d4048f07e Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Fri, 29 Jan 2016 21:40:15 +0100 Subject: [PATCH] Fix the mobile trait spamming crush-notifications --- OpenRA.Mods.Common/Traits/Mobile.cs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 806f82f2db..11c6aeacf5 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -594,8 +594,11 @@ namespace OpenRA.Mods.Common.Traits if (!self.IsAtGroundLevel()) return; - var notifiers = self.World.ActorMap.GetActorsAt(ToCell).Where(a => a != self) - .SelectMany(a => a.TraitsImplementing().Select(t => new TraitPair(a, t))); + var actors = self.World.ActorMap.GetActorsAt(ToCell).Where(a => a != self).ToList(); + if (!AnyCrushables(actors)) + return; + + var notifiers = actors.SelectMany(a => a.TraitsImplementing().Select(t => new TraitPair(a, t))); foreach (var notifyCrushed in notifiers) notifyCrushed.Trait.WarnCrush(notifyCrushed.Actor, self, Info.Crushes); } @@ -606,12 +609,28 @@ namespace OpenRA.Mods.Common.Traits if (!self.IsAtGroundLevel()) return; - var notifiers = self.World.ActorMap.GetActorsAt(ToCell).Where(a => a != self) - .SelectMany(a => a.TraitsImplementing().Select(t => new TraitPair(a, t))); + var actors = self.World.ActorMap.GetActorsAt(ToCell).Where(a => a != self).ToList(); + if (!AnyCrushables(actors)) + return; + + var notifiers = actors.SelectMany(a => a.TraitsImplementing().Select(t => new TraitPair(a, t))); foreach (var notifyCrushed in notifiers) notifyCrushed.Trait.OnCrush(notifyCrushed.Actor, self, Info.Crushes); } + bool AnyCrushables(List actors) + { + var crushables = actors.SelectMany(a => a.TraitsImplementing().Select(t => new TraitPair(a, t))).ToList(); + if (crushables.Count == 0) + return false; + + foreach (var crushes in crushables) + if (!crushes.Trait.CrushableBy(crushes.Actor, self, Info.Crushes)) + return false; + + return true; + } + public int MovementSpeedForCell(Actor self, CPos cell) { var index = self.World.Map.GetTerrainIndex(cell);