Use Mobile.Pathfinder to reduce trait look-ups
This commit is contained in:
@@ -25,7 +25,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
readonly HarvesterInfo harvInfo;
|
||||
readonly Mobile mobile;
|
||||
readonly ResourceClaimLayer claimLayer;
|
||||
readonly IPathFinder pathFinder;
|
||||
readonly DomainIndex domainIndex;
|
||||
|
||||
Actor deliverActor;
|
||||
@@ -43,7 +42,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
harvInfo = self.Info.TraitInfo<HarvesterInfo>();
|
||||
mobile = self.Trait<Mobile>();
|
||||
claimLayer = self.World.WorldActor.Trait<ResourceClaimLayer>();
|
||||
pathFinder = self.World.WorldActor.Trait<IPathFinder>();
|
||||
domainIndex = self.World.WorldActor.Trait<DomainIndex>();
|
||||
this.deliverActor = deliverActor;
|
||||
}
|
||||
@@ -218,7 +216,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
})
|
||||
.FromPoint(searchFromLoc)
|
||||
.FromPoint(self.Location))
|
||||
path = pathFinder.FindPath(search);
|
||||
path = mobile.Pathfinder.FindPath(search);
|
||||
|
||||
if (path.Count > 0)
|
||||
return path[0];
|
||||
|
||||
@@ -24,7 +24,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
static readonly List<CPos> NoPath = new List<CPos>();
|
||||
|
||||
protected readonly Mobile Mobile;
|
||||
readonly IPathFinder pathFinder;
|
||||
readonly DomainIndex domainIndex;
|
||||
readonly Color? targetLineColor;
|
||||
|
||||
@@ -40,7 +39,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
this.target = target;
|
||||
this.targetLineColor = targetLineColor;
|
||||
Mobile = self.Trait<Mobile>();
|
||||
pathFinder = self.World.WorldActor.Trait<IPathFinder>();
|
||||
domainIndex = self.World.WorldActor.Trait<DomainIndex>();
|
||||
ChildHasPriority = false;
|
||||
|
||||
@@ -136,7 +134,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
using (var fromSrc = PathSearch.FromPoints(self.World, Mobile.Locomotor, self, searchCells, loc, check))
|
||||
using (var fromDest = PathSearch.FromPoint(self.World, Mobile.Locomotor, self, loc, lastVisibleTargetLocation, check).Reverse())
|
||||
return pathFinder.FindBidiPath(fromSrc, fromDest);
|
||||
return Mobile.Pathfinder.FindBidiPath(fromSrc, fromDest);
|
||||
}
|
||||
|
||||
public override IEnumerable<Target> GetTargets(Actor self)
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Prefer refineries with less occupancy (multiplier is to offset distance cost):
|
||||
return occupancy * Info.UnloadQueueCostModifier;
|
||||
}))
|
||||
path = self.World.WorldActor.Trait<IPathFinder>().FindPath(search);
|
||||
path = mobile.Pathfinder.FindPath(search);
|
||||
|
||||
if (path.Count != 0)
|
||||
return refineries[path.Last()].First().Actor;
|
||||
|
||||
@@ -803,12 +803,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (CanEnterCell(above))
|
||||
return above;
|
||||
|
||||
var pathFinder = self.World.WorldActor.Trait<IPathFinder>();
|
||||
List<CPos> path;
|
||||
using (var search = PathSearch.Search(self.World, Locomotor, self, BlockedByActor.All,
|
||||
loc => loc.Layer == 0 && CanEnterCell(loc))
|
||||
.FromPoint(self.Location))
|
||||
path = pathFinder.FindPath(search);
|
||||
path = Pathfinder.FindPath(search);
|
||||
|
||||
if (path.Count > 0)
|
||||
return path[0];
|
||||
|
||||
Reference in New Issue
Block a user