diff --git a/OpenRA.Mods.Common/AI/AIHarvesterManager.cs b/OpenRA.Mods.Common/AI/AIHarvesterManager.cs index c7fd65d877..51b1701fe6 100644 --- a/OpenRA.Mods.Common/AI/AIHarvesterManager.cs +++ b/OpenRA.Mods.Common/AI/AIHarvesterManager.cs @@ -42,10 +42,9 @@ namespace OpenRA.Mods.Common.AI CPos FindNextResource(Actor actor, Harvester harv) { var locomotorInfo = actor.Info.TraitInfo().LocomotorInfo; - var passable = (uint)locomotorInfo.GetMovementClass(World.Map.Rules.TileSet); Func isValidResource = cell => - domainIndex.IsPassable(actor.Location, cell, locomotorInfo, passable) && + domainIndex.IsPassable(actor.Location, cell, locomotorInfo) && harv.CanHarvestCell(actor, cell) && claimLayer.CanClaimCell(actor, cell); diff --git a/OpenRA.Mods.Common/AI/States/NavyStates.cs b/OpenRA.Mods.Common/AI/States/NavyStates.cs index da14dbc750..9caec881c0 100644 --- a/OpenRA.Mods.Common/AI/States/NavyStates.cs +++ b/OpenRA.Mods.Common/AI/States/NavyStates.cs @@ -31,11 +31,10 @@ namespace OpenRA.Mods.Common.AI // You might be tempted to move these lookups into Activate() but that causes null reference exception. var domainIndex = first.World.WorldActor.Trait(); var locomotorInfo = first.Info.TraitInfo().LocomotorInfo; - var passable = (uint)locomotorInfo.GetMovementClass(first.World.Map.Rules.TileSet); var navalProductions = owner.World.ActorsHavingTrait().Where(a => owner.Bot.Info.BuildingCommonNames.NavalProduction.Contains(a.Info.Name) - && domainIndex.IsPassable(first.Location, a.Location, locomotorInfo, passable) + && domainIndex.IsPassable(first.Location, a.Location, locomotorInfo) && a.AppearsHostileTo(first)); if (navalProductions.Any()) diff --git a/OpenRA.Mods.Common/Activities/FindResources.cs b/OpenRA.Mods.Common/Activities/FindResources.cs index 97870cd214..6b91843d5d 100644 --- a/OpenRA.Mods.Common/Activities/FindResources.cs +++ b/OpenRA.Mods.Common/Activities/FindResources.cs @@ -126,10 +126,9 @@ namespace OpenRA.Mods.Common.Activities var searchRadiusSquared = searchRadius * searchRadius; // Find any harvestable resources: - var passable = (uint)locomotorInfo.GetMovementClass(self.World.Map.Rules.TileSet); List path; using (var search = PathSearch.Search(self.World, locomotorInfo, self, true, loc => - domainIndex.IsPassable(self.Location, loc, locomotorInfo, passable) && harv.CanHarvestCell(self, loc) && claimLayer.CanClaimCell(self, loc)) + domainIndex.IsPassable(self.Location, loc, locomotorInfo) && harv.CanHarvestCell(self, loc) && claimLayer.CanClaimCell(self, loc)) .WithCustomCost(loc => { if ((avoidCell.HasValue && loc == avoidCell.Value) || diff --git a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs index db32440d72..e7e6bd9379 100644 --- a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs +++ b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs @@ -26,7 +26,6 @@ namespace OpenRA.Mods.Common.Activities protected readonly Mobile Mobile; readonly IPathFinder pathFinder; readonly DomainIndex domainIndex; - readonly uint movementClass; Target target; bool canHideUnderFog; @@ -56,7 +55,6 @@ namespace OpenRA.Mods.Common.Activities Mobile = self.Trait(); pathFinder = self.World.WorldActor.Trait(); domainIndex = self.World.WorldActor.Trait(); - movementClass = (uint)Mobile.Info.LocomotorInfo.GetMovementClass(self.World.Map.Rules.TileSet); if (target.IsValidFor(self)) targetPosition = self.World.Map.CellContaining(target.CenterPosition); @@ -142,7 +140,7 @@ namespace OpenRA.Mods.Common.Activities var loc = self.Location; foreach (var cell in targetCells) - if (domainIndex.IsPassable(loc, cell, Mobile.Info.LocomotorInfo, movementClass) && Mobile.CanEnterCell(cell)) + if (domainIndex.IsPassable(loc, cell, Mobile.Info.LocomotorInfo) && Mobile.CanEnterCell(cell)) searchCells.Add(cell); if (!searchCells.Any()) diff --git a/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs index 63c86a2f57..63895dda0f 100644 --- a/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs @@ -159,22 +159,19 @@ namespace OpenRA.Mods.Common.Scripting // Try to find an alternative landing spot if we can't land at the current destination if (!aircraft.CanLand(destination) && dropRange > 0) { - var mobiles = cargo != null ? cargo.Passengers.Select(a => - { - var mobile = a.TraitOrDefault(); - if (mobile == null) - return new Pair(null, 0); - - var locomotorInfo = mobile.Info.LocomotorInfo; - return new Pair(locomotorInfo, (uint)locomotorInfo.GetMovementClass(a.World.Map.Rules.TileSet)); - }) : new Pair[0]; + var locomotors = cargo.Passengers + .Select(a => a.Info.TraitInfoOrDefault()) + .Where(m => m != null) + .Distinct() + .Select(m => m.LocomotorInfo) + .ToList(); foreach (var c in transport.World.Map.FindTilesInCircle(destination, dropRange)) { if (!aircraft.CanLand(c)) continue; - if (!mobiles.All(m => m.First == null || domainIndex.IsPassable(destination, c, m.First, m.Second))) + if (!locomotors.All(m => domainIndex.IsPassable(destination, c, m))) continue; destination = c; diff --git a/OpenRA.Mods.Common/Traits/ProductionFromMapEdge.cs b/OpenRA.Mods.Common/Traits/ProductionFromMapEdge.cs index 812711a802..9c58a25a03 100644 --- a/OpenRA.Mods.Common/Traits/ProductionFromMapEdge.cs +++ b/OpenRA.Mods.Common/Traits/ProductionFromMapEdge.cs @@ -48,9 +48,7 @@ namespace OpenRA.Mods.Common.Traits var aircraftInfo = producee.TraitInfoOrDefault(); var mobileInfo = producee.TraitInfoOrDefault(); - var locomotorInfo = mobileInfo.LocomotorInfo; - var passable = mobileInfo != null ? (uint)locomotorInfo.GetMovementClass(self.World.Map.Rules.TileSet) : 0; var destination = rp != null ? rp.Location : self.Location; var location = spawnLocation; @@ -60,8 +58,11 @@ namespace OpenRA.Mods.Common.Traits location = self.World.Map.ChooseClosestEdgeCell(self.Location); if (mobileInfo != null) + { + var locomotorInfo = mobileInfo.LocomotorInfo; location = self.World.Map.ChooseClosestMatchingEdgeCell(self.Location, - c => mobileInfo.CanEnterCell(self.World, null, c) && domainIndex.IsPassable(c, destination, locomotorInfo, passable)); + c => mobileInfo.CanEnterCell(self.World, null, c) && domainIndex.IsPassable(c, destination, locomotorInfo)); + } } // No suitable spawn location could be found, so production has failed. diff --git a/OpenRA.Mods.Common/Traits/World/DomainIndex.cs b/OpenRA.Mods.Common/Traits/World/DomainIndex.cs index 0364a4d0e9..6cf3ace648 100644 --- a/OpenRA.Mods.Common/Traits/World/DomainIndex.cs +++ b/OpenRA.Mods.Common/Traits/World/DomainIndex.cs @@ -23,12 +23,13 @@ namespace OpenRA.Mods.Common.Traits public class DomainIndex : IWorldLoaded { + TileSet tileSet; Dictionary domainIndexes; public void WorldLoaded(World world, WorldRenderer wr) { domainIndexes = new Dictionary(); - var tileSet = world.Map.Rules.TileSet; + tileSet = world.Map.Rules.TileSet; var locomotors = world.WorldActor.TraitsImplementing().Where(l => !string.IsNullOrEmpty(l.Info.Name)); var movementClasses = locomotors.Select(t => (uint)t.Info.GetMovementClass(tileSet)).Distinct(); @@ -36,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits domainIndexes[mc] = new MovementClassDomainIndex(world, mc); } - public bool IsPassable(CPos p1, CPos p2, LocomotorInfo loco, uint movementClass) + public bool IsPassable(CPos p1, CPos p2, LocomotorInfo li) { // HACK: Work around units in other movement layers from being blocked // when the point in the main layer is not pathable @@ -44,9 +45,10 @@ namespace OpenRA.Mods.Common.Traits return true; // HACK: Workaround until we can generalize movement classes - if (loco is SubterraneanLocomotorInfo || loco is JumpjetLocomotorInfo) + if (li is SubterraneanLocomotorInfo || li is JumpjetLocomotorInfo) return true; + var movementClass = li.GetMovementClass(tileSet); return domainIndexes[movementClass].IsPassable(p1, p2); } diff --git a/OpenRA.Mods.Common/Traits/World/Locomotor.cs b/OpenRA.Mods.Common/Traits/World/Locomotor.cs index 09c606a190..ebd7fcb27b 100644 --- a/OpenRA.Mods.Common/Traits/World/Locomotor.cs +++ b/OpenRA.Mods.Common/Traits/World/Locomotor.cs @@ -169,9 +169,9 @@ namespace OpenRA.Mods.Common.Traits return TilesetTerrainInfo[tileset].Select(ti => ti.Cost < int.MaxValue).ToBits(); } - public int GetMovementClass(TileSet tileset) + public uint GetMovementClass(TileSet tileset) { - return TilesetMovementClass[tileset]; + return (uint)TilesetMovementClass[tileset]; } public int TileSetMovementHash(TileSet tileSet) diff --git a/OpenRA.Mods.Common/Traits/World/PathFinder.cs b/OpenRA.Mods.Common/Traits/World/PathFinder.cs index 51906d339c..ab0c7b0d2c 100644 --- a/OpenRA.Mods.Common/Traits/World/PathFinder.cs +++ b/OpenRA.Mods.Common/Traits/World/PathFinder.cs @@ -67,12 +67,8 @@ namespace OpenRA.Mods.Common.Traits // If a water-land transition is required, bail early var domainIndex = world.WorldActor.TraitOrDefault(); - if (domainIndex != null) - { - var passable = li.GetMovementClass(world.Map.Rules.TileSet); - if (!domainIndex.IsPassable(source, target, li, (uint)passable)) - return EmptyPath; - } + if (domainIndex != null && !domainIndex.IsPassable(source, target, li)) + return EmptyPath; List pb; using (var fromSrc = PathSearch.FromPoint(world, li, self, target, source, true).WithIgnoredActor(ignoreActor)) @@ -104,8 +100,7 @@ namespace OpenRA.Mods.Common.Traits var domainIndex = world.WorldActor.TraitOrDefault(); if (domainIndex != null) { - var passable = li.GetMovementClass(world.Map.Rules.TileSet); - tilesInRange = new List(tilesInRange.Where(t => domainIndex.IsPassable(source, t, li, (uint)passable))); + tilesInRange = new List(tilesInRange.Where(t => domainIndex.IsPassable(source, t, li))); if (!tilesInRange.Any()) return EmptyPath; }