From 027d7e2c2b451e638da6e5430ca7741c0c97b877 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 23 May 2010 16:07:59 +1200 Subject: [PATCH] filtering of unusable cells in minefield support; rationalize mobile a bit --- OpenRA.Game/Traits/Mobile.cs | 24 +++++++----------------- OpenRA.Mods.RA/Minelayer.cs | 7 +++++-- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index 165016362a..f8690fac56 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -114,26 +114,16 @@ namespace OpenRA.Traits return self.Info.Traits.Get().MovementType; } - public bool CanEnterCell(int2 a) + public bool CanEnterCell(int2 p) { - if (!self.World.WorldActor.traits.Get().CanMoveHere(a)) return false; + if (!self.World.WorldActor.traits.Get().CanMoveHere(p)) return false; - var crushable = true; - foreach (Actor actor in self.World.WorldActor.traits.Get().GetUnitsAt(a)) - { - if (actor == self) continue; - - if (!self.World.IsActorCrushableByActor(actor, self)) - { - crushable = false; - break; - } - } + if (self.World.WorldActor.traits.Get().GetUnitsAt(p).Any( + a => a != self && !self.World.IsActorCrushableByActor(a, self))) + return false; - if (!crushable) return false; - - return self.World.Map.IsInMap(a.X, a.Y) && - Rules.TerrainTypes[self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[a.X, a.Y])] + return self.World.Map.IsInMap(p.X, p.Y) && + Rules.TerrainTypes[self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[p.X, p.Y])] .GetCost(GetMovementType()) < float.PositiveInfinity; } diff --git a/OpenRA.Mods.RA/Minelayer.cs b/OpenRA.Mods.RA/Minelayer.cs index 405c54fe43..5095536275 100644 --- a/OpenRA.Mods.RA/Minelayer.cs +++ b/OpenRA.Mods.RA/Minelayer.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA class Minelayer : IIssueOrder, IResolveOrder { - int2[] minefield = null; + public int2[] minefield = null; int2 minefieldStart; /* nosync! */ public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) @@ -60,8 +60,11 @@ namespace OpenRA.Mods.RA if (self.Owner == self.World.LocalPlayer) Game.controller.CancelInputMode(); + var movement = self.traits.Get(); + minefield = GetMinefieldCells(minefieldStart, order.TargetLocation, - self.Info.Traits.Get().MinefieldDepth).ToArray(); + self.Info.Traits.Get().MinefieldDepth) + .Where(p => movement.CanEnterCell(p)).ToArray(); /* todo: start the mnly actually laying mines there */ }