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)
|
CPos FindNextResource(Actor actor, Harvester harv)
|
||||||
{
|
{
|
||||||
var locomotorInfo = actor.Info.TraitInfo<MobileInfo>().LocomotorInfo;
|
var locomotorInfo = actor.Info.TraitInfo<MobileInfo>().LocomotorInfo;
|
||||||
var passable = (uint)locomotorInfo.GetMovementClass(World.Map.Rules.TileSet);
|
|
||||||
|
|
||||||
Func<CPos, bool> isValidResource = cell =>
|
Func<CPos, bool> isValidResource = cell =>
|
||||||
domainIndex.IsPassable(actor.Location, cell, locomotorInfo, passable) &&
|
domainIndex.IsPassable(actor.Location, cell, locomotorInfo) &&
|
||||||
harv.CanHarvestCell(actor, cell) &&
|
harv.CanHarvestCell(actor, cell) &&
|
||||||
claimLayer.CanClaimCell(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.
|
// You might be tempted to move these lookups into Activate() but that causes null reference exception.
|
||||||
var domainIndex = first.World.WorldActor.Trait<DomainIndex>();
|
var domainIndex = first.World.WorldActor.Trait<DomainIndex>();
|
||||||
var locomotorInfo = first.Info.TraitInfo<MobileInfo>().LocomotorInfo;
|
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
|
var navalProductions = owner.World.ActorsHavingTrait<Building>().Where(a
|
||||||
=> owner.Bot.Info.BuildingCommonNames.NavalProduction.Contains(a.Info.Name)
|
=> 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));
|
&& a.AppearsHostileTo(first));
|
||||||
|
|
||||||
if (navalProductions.Any())
|
if (navalProductions.Any())
|
||||||
|
|||||||
@@ -126,10 +126,9 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
var searchRadiusSquared = searchRadius * searchRadius;
|
var searchRadiusSquared = searchRadius * searchRadius;
|
||||||
|
|
||||||
// Find any harvestable resources:
|
// Find any harvestable resources:
|
||||||
var passable = (uint)locomotorInfo.GetMovementClass(self.World.Map.Rules.TileSet);
|
|
||||||
List<CPos> path;
|
List<CPos> path;
|
||||||
using (var search = PathSearch.Search(self.World, locomotorInfo, self, true, loc =>
|
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 =>
|
.WithCustomCost(loc =>
|
||||||
{
|
{
|
||||||
if ((avoidCell.HasValue && loc == avoidCell.Value) ||
|
if ((avoidCell.HasValue && loc == avoidCell.Value) ||
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
protected readonly Mobile Mobile;
|
protected readonly Mobile Mobile;
|
||||||
readonly IPathFinder pathFinder;
|
readonly IPathFinder pathFinder;
|
||||||
readonly DomainIndex domainIndex;
|
readonly DomainIndex domainIndex;
|
||||||
readonly uint movementClass;
|
|
||||||
|
|
||||||
Target target;
|
Target target;
|
||||||
bool canHideUnderFog;
|
bool canHideUnderFog;
|
||||||
@@ -56,7 +55,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
Mobile = self.Trait<Mobile>();
|
Mobile = self.Trait<Mobile>();
|
||||||
pathFinder = self.World.WorldActor.Trait<IPathFinder>();
|
pathFinder = self.World.WorldActor.Trait<IPathFinder>();
|
||||||
domainIndex = self.World.WorldActor.Trait<DomainIndex>();
|
domainIndex = self.World.WorldActor.Trait<DomainIndex>();
|
||||||
movementClass = (uint)Mobile.Info.LocomotorInfo.GetMovementClass(self.World.Map.Rules.TileSet);
|
|
||||||
|
|
||||||
if (target.IsValidFor(self))
|
if (target.IsValidFor(self))
|
||||||
targetPosition = self.World.Map.CellContaining(target.CenterPosition);
|
targetPosition = self.World.Map.CellContaining(target.CenterPosition);
|
||||||
@@ -142,7 +140,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
var loc = self.Location;
|
var loc = self.Location;
|
||||||
|
|
||||||
foreach (var cell in targetCells)
|
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);
|
searchCells.Add(cell);
|
||||||
|
|
||||||
if (!searchCells.Any())
|
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
|
// Try to find an alternative landing spot if we can't land at the current destination
|
||||||
if (!aircraft.CanLand(destination) && dropRange > 0)
|
if (!aircraft.CanLand(destination) && dropRange > 0)
|
||||||
{
|
{
|
||||||
var mobiles = cargo != null ? cargo.Passengers.Select(a =>
|
var locomotors = cargo.Passengers
|
||||||
{
|
.Select(a => a.Info.TraitInfoOrDefault<MobileInfo>())
|
||||||
var mobile = a.TraitOrDefault<Mobile>();
|
.Where(m => m != null)
|
||||||
if (mobile == null)
|
.Distinct()
|
||||||
return new Pair<LocomotorInfo, uint>(null, 0);
|
.Select(m => m.LocomotorInfo)
|
||||||
|
.ToList();
|
||||||
var locomotorInfo = mobile.Info.LocomotorInfo;
|
|
||||||
return new Pair<LocomotorInfo, uint>(locomotorInfo, (uint)locomotorInfo.GetMovementClass(a.World.Map.Rules.TileSet));
|
|
||||||
}) : new Pair<LocomotorInfo, uint>[0];
|
|
||||||
|
|
||||||
foreach (var c in transport.World.Map.FindTilesInCircle(destination, dropRange))
|
foreach (var c in transport.World.Map.FindTilesInCircle(destination, dropRange))
|
||||||
{
|
{
|
||||||
if (!aircraft.CanLand(c))
|
if (!aircraft.CanLand(c))
|
||||||
continue;
|
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;
|
continue;
|
||||||
|
|
||||||
destination = c;
|
destination = c;
|
||||||
|
|||||||
@@ -48,9 +48,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
var aircraftInfo = producee.TraitInfoOrDefault<AircraftInfo>();
|
var aircraftInfo = producee.TraitInfoOrDefault<AircraftInfo>();
|
||||||
var mobileInfo = producee.TraitInfoOrDefault<MobileInfo>();
|
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 destination = rp != null ? rp.Location : self.Location;
|
||||||
|
|
||||||
var location = spawnLocation;
|
var location = spawnLocation;
|
||||||
@@ -60,8 +58,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
location = self.World.Map.ChooseClosestEdgeCell(self.Location);
|
location = self.World.Map.ChooseClosestEdgeCell(self.Location);
|
||||||
|
|
||||||
if (mobileInfo != null)
|
if (mobileInfo != null)
|
||||||
|
{
|
||||||
|
var locomotorInfo = mobileInfo.LocomotorInfo;
|
||||||
location = self.World.Map.ChooseClosestMatchingEdgeCell(self.Location,
|
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.
|
// No suitable spawn location could be found, so production has failed.
|
||||||
|
|||||||
@@ -23,12 +23,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public class DomainIndex : IWorldLoaded
|
public class DomainIndex : IWorldLoaded
|
||||||
{
|
{
|
||||||
|
TileSet tileSet;
|
||||||
Dictionary<uint, MovementClassDomainIndex> domainIndexes;
|
Dictionary<uint, MovementClassDomainIndex> domainIndexes;
|
||||||
|
|
||||||
public void WorldLoaded(World world, WorldRenderer wr)
|
public void WorldLoaded(World world, WorldRenderer wr)
|
||||||
{
|
{
|
||||||
domainIndexes = new Dictionary<uint, MovementClassDomainIndex>();
|
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 locomotors = world.WorldActor.TraitsImplementing<Locomotor>().Where(l => !string.IsNullOrEmpty(l.Info.Name));
|
||||||
var movementClasses = locomotors.Select(t => (uint)t.Info.GetMovementClass(tileSet)).Distinct();
|
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);
|
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
|
// HACK: Work around units in other movement layers from being blocked
|
||||||
// when the point in the main layer is not pathable
|
// when the point in the main layer is not pathable
|
||||||
@@ -44,9 +45,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
// HACK: Workaround until we can generalize movement classes
|
// HACK: Workaround until we can generalize movement classes
|
||||||
if (loco is SubterraneanLocomotorInfo || loco is JumpjetLocomotorInfo)
|
if (li is SubterraneanLocomotorInfo || li is JumpjetLocomotorInfo)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
var movementClass = li.GetMovementClass(tileSet);
|
||||||
return domainIndexes[movementClass].IsPassable(p1, p2);
|
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();
|
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)
|
public int TileSetMovementHash(TileSet tileSet)
|
||||||
|
|||||||
@@ -67,12 +67,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
// If a water-land transition is required, bail early
|
// If a water-land transition is required, bail early
|
||||||
var domainIndex = world.WorldActor.TraitOrDefault<DomainIndex>();
|
var domainIndex = world.WorldActor.TraitOrDefault<DomainIndex>();
|
||||||
if (domainIndex != null)
|
if (domainIndex != null && !domainIndex.IsPassable(source, target, li))
|
||||||
{
|
|
||||||
var passable = li.GetMovementClass(world.Map.Rules.TileSet);
|
|
||||||
if (!domainIndex.IsPassable(source, target, li, (uint)passable))
|
|
||||||
return EmptyPath;
|
return EmptyPath;
|
||||||
}
|
|
||||||
|
|
||||||
List<CPos> pb;
|
List<CPos> pb;
|
||||||
using (var fromSrc = PathSearch.FromPoint(world, li, self, target, source, true).WithIgnoredActor(ignoreActor))
|
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>();
|
var domainIndex = world.WorldActor.TraitOrDefault<DomainIndex>();
|
||||||
if (domainIndex != null)
|
if (domainIndex != null)
|
||||||
{
|
{
|
||||||
var passable = li.GetMovementClass(world.Map.Rules.TileSet);
|
tilesInRange = new List<CPos>(tilesInRange.Where(t => domainIndex.IsPassable(source, t, li)));
|
||||||
tilesInRange = new List<CPos>(tilesInRange.Where(t => domainIndex.IsPassable(source, t, li, (uint)passable)));
|
|
||||||
if (!tilesInRange.Any())
|
if (!tilesInRange.Any())
|
||||||
return EmptyPath;
|
return EmptyPath;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user