Don't pass movement class via IsPassable directly
Let IsPassable get that info from the locomotor instead.
This commit is contained in:
@@ -42,10 +42,9 @@ namespace OpenRA.Mods.Common.AI
|
||||
CPos FindNextResource(Actor actor, Harvester harv)
|
||||
{
|
||||
var locomotorInfo = actor.Info.TraitInfo<MobileInfo>().LocomotorInfo;
|
||||
var passable = (uint)locomotorInfo.GetMovementClass(World.Map.Rules.TileSet);
|
||||
|
||||
Func<CPos, bool> isValidResource = cell =>
|
||||
domainIndex.IsPassable(actor.Location, cell, locomotorInfo, passable) &&
|
||||
domainIndex.IsPassable(actor.Location, cell, locomotorInfo) &&
|
||||
harv.CanHarvestCell(actor, cell) &&
|
||||
claimLayer.CanClaimCell(actor, cell);
|
||||
|
||||
|
||||
@@ -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<DomainIndex>();
|
||||
var locomotorInfo = first.Info.TraitInfo<MobileInfo>().LocomotorInfo;
|
||||
var passable = (uint)locomotorInfo.GetMovementClass(first.World.Map.Rules.TileSet);
|
||||
|
||||
var navalProductions = owner.World.ActorsHavingTrait<Building>().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())
|
||||
|
||||
@@ -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<CPos> 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) ||
|
||||
|
||||
@@ -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<Mobile>();
|
||||
pathFinder = self.World.WorldActor.Trait<IPathFinder>();
|
||||
domainIndex = self.World.WorldActor.Trait<DomainIndex>();
|
||||
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())
|
||||
|
||||
@@ -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<Mobile>();
|
||||
if (mobile == null)
|
||||
return new Pair<LocomotorInfo, uint>(null, 0);
|
||||
|
||||
var locomotorInfo = mobile.Info.LocomotorInfo;
|
||||
return new Pair<LocomotorInfo, uint>(locomotorInfo, (uint)locomotorInfo.GetMovementClass(a.World.Map.Rules.TileSet));
|
||||
}) : new Pair<LocomotorInfo, uint>[0];
|
||||
var locomotors = cargo.Passengers
|
||||
.Select(a => a.Info.TraitInfoOrDefault<MobileInfo>())
|
||||
.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;
|
||||
|
||||
@@ -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