Don't pass movement class via IsPassable directly
Let IsPassable get that info from the locomotor instead.
This commit is contained in:
@@ -48,9 +48,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var aircraftInfo = producee.TraitInfoOrDefault<AircraftInfo>();
|
||||
var mobileInfo = producee.TraitInfoOrDefault<MobileInfo>();
|
||||
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.
|
||||
|
||||
@@ -23,12 +23,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public class DomainIndex : IWorldLoaded
|
||||
{
|
||||
TileSet tileSet;
|
||||
Dictionary<uint, MovementClassDomainIndex> domainIndexes;
|
||||
|
||||
public void WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
domainIndexes = new Dictionary<uint, MovementClassDomainIndex>();
|
||||
var tileSet = world.Map.Rules.TileSet;
|
||||
tileSet = world.Map.Rules.TileSet;
|
||||
var locomotors = world.WorldActor.TraitsImplementing<Locomotor>().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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -67,12 +67,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// If a water-land transition is required, bail early
|
||||
var domainIndex = world.WorldActor.TraitOrDefault<DomainIndex>();
|
||||
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<CPos> 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<DomainIndex>();
|
||||
if (domainIndex != null)
|
||||
{
|
||||
var passable = li.GetMovementClass(world.Map.Rules.TileSet);
|
||||
tilesInRange = new List<CPos>(tilesInRange.Where(t => domainIndex.IsPassable(source, t, li, (uint)passable)));
|
||||
tilesInRange = new List<CPos>(tilesInRange.Where(t => domainIndex.IsPassable(source, t, li)));
|
||||
if (!tilesInRange.Any())
|
||||
return EmptyPath;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user