Changed the harvester heuristic so that now takes into account the distance from the initial search location. This makes harvesters somewhat more "intelligent" and gather nearer resources. Also solved several regressions introduced in the recent changes in the Pathfinder
This commit is contained in:
1
AUTHORS
1
AUTHORS
@@ -38,6 +38,7 @@ Also thanks to:
|
||||
* D2k Sardaukar
|
||||
* Daniel Derejvanik (Harisson)
|
||||
* Danny Keary (Dan9550)
|
||||
* David Jiménez (Rydra)
|
||||
* David Russell (DavidARussell)
|
||||
* DeadlySurprise
|
||||
* Erasmus Schroder (rasco)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
@@ -58,28 +59,28 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
// Avoid this cell:
|
||||
if (avoidCell.HasValue && loc == avoidCell.Value)
|
||||
return Constants.CellCost;
|
||||
return EstimateDistance(loc, searchFromLoc) + Constants.CellCost;
|
||||
|
||||
// Don't harvest out of range:
|
||||
var distSquared = (loc - searchFromLoc).LengthSquared;
|
||||
if (distSquared > searchRadiusSquared)
|
||||
return Constants.CellCost * 2;
|
||||
return EstimateDistance(loc, searchFromLoc) + Constants.CellCost * 2;
|
||||
|
||||
// Get the resource at this location:
|
||||
var resType = resLayer.GetResource(loc);
|
||||
if (resType == null)
|
||||
return Constants.CellCost;
|
||||
return EstimateDistance(loc, searchFromLoc) + Constants.CellCost;
|
||||
|
||||
// Can the harvester collect this kind of resource?
|
||||
if (!harvInfo.Resources.Contains(resType.Info.Name))
|
||||
return Constants.CellCost;
|
||||
return EstimateDistance(loc, searchFromLoc) + Constants.CellCost;
|
||||
|
||||
if (territory != null)
|
||||
{
|
||||
// Another harvester has claimed this resource:
|
||||
ResourceClaim claim;
|
||||
if (territory.IsClaimedByAnyoneElse(self, loc, out claim))
|
||||
return Constants.CellCost;
|
||||
return EstimateDistance(loc, searchFromLoc) + Constants.CellCost;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -123,6 +124,15 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return Util.SequenceActivities(mobile.MoveTo(path[0], 1), new HarvestResource(), new FindResources());
|
||||
}
|
||||
|
||||
// Diagonal distance heuristic
|
||||
static int EstimateDistance(CPos here, CPos destination)
|
||||
{
|
||||
var diag = Math.Min(Math.Abs(here.X - destination.X), Math.Abs(here.Y - destination.Y));
|
||||
var straight = Math.Abs(here.X - destination.X) + Math.Abs(here.Y - destination.Y);
|
||||
|
||||
return Constants.CellCost * straight + (Constants.DiagonalCellCost - 2 * Constants.CellCost) * diag;
|
||||
}
|
||||
|
||||
public override IEnumerable<Target> GetTargets(Actor self)
|
||||
{
|
||||
yield return Target.FromCell(self.World, self.Location);
|
||||
|
||||
@@ -60,7 +60,6 @@ namespace OpenRA.Mods.Common.Pathfinder
|
||||
return null;
|
||||
}
|
||||
|
||||
cached.Tick = world.WorldTick;
|
||||
return cached.Result;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,13 @@ namespace OpenRA.Mods.Common.Pathfinder
|
||||
var currentCell = Graph[currentMinNode];
|
||||
Graph[currentMinNode] = new CellInfo(currentCell.CostSoFar, currentCell.EstimatedTotal, currentCell.PreviousPos, CellStatus.Closed);
|
||||
|
||||
if (Graph.CustomCost != null)
|
||||
{
|
||||
var c = Graph.CustomCost(currentMinNode);
|
||||
if (c == int.MaxValue)
|
||||
return currentMinNode;
|
||||
}
|
||||
|
||||
foreach (var connection in Graph.GetConnections(currentMinNode))
|
||||
{
|
||||
// Calculate the cost up to that point
|
||||
|
||||
Reference in New Issue
Block a user