Merge pull request #9359 from RoosterDragon/fix-pathfinder-layer-pooling

Fixed pooling of layers used for pathfinding
This commit is contained in:
Matthias Mailänder
2015-09-19 13:07:33 +02:00
11 changed files with 158 additions and 170 deletions

View File

@@ -167,23 +167,24 @@ namespace OpenRA.Mods.Common.Traits
.ToDictionary(r => r.Location);
// Start a search from each refinery's delivery location:
List<CPos> path;
var mi = self.Info.Traits.Get<MobileInfo>();
var path = self.World.WorldActor.Trait<IPathFinder>().FindPath(
PathSearch.FromPoints(self.World, mi, self, refs.Values.Select(r => r.Location), self.Location, false)
.WithCustomCost(loc =>
{
if (!refs.ContainsKey(loc))
return 0;
using (var search = PathSearch.FromPoints(self.World, mi, self, refs.Values.Select(r => r.Location), self.Location, false)
.WithCustomCost(loc =>
{
if (!refs.ContainsKey(loc))
return 0;
var occupancy = refs[loc].Occupancy;
var occupancy = refs[loc].Occupancy;
// 4 harvesters clogs up the refinery's delivery location:
if (occupancy >= 3)
return Constants.InvalidNode;
// 4 harvesters clogs up the refinery's delivery location:
if (occupancy >= 3)
return Constants.InvalidNode;
// Prefer refineries with less occupancy (multiplier is to offset distance cost):
return occupancy * 12;
}));
// Prefer refineries with less occupancy (multiplier is to offset distance cost):
return occupancy * 12;
}))
path = self.World.WorldActor.Trait<IPathFinder>().FindPath(search);
if (path.Count != 0)
return refs[path.Last()].Actor;