Skip to content

Commit

Permalink
Discourage harvesters from wandering too far from the refinery.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Aug 11, 2019
1 parent ea80a13 commit 4fd0bc2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ public override bool Tick(Actor self)
}

// Determine where to search from and how far to search:
var searchFromLoc = lastHarvestedCell ?? GetSearchFromProcLocation(self);
var procLoc = GetSearchFromProcLocation(self);
var searchFromLoc = lastHarvestedCell ?? procLoc;
var searchRadius = lastHarvestedCell.HasValue ? harvInfo.SearchFromHarvesterRadius : harvInfo.SearchFromProcRadius;
if (!searchFromLoc.HasValue)
{
Expand All @@ -184,6 +185,7 @@ public override bool Tick(Actor self)
}

var searchRadiusSquared = searchRadius * searchRadius;
var goalLoc = procLoc ?? lastHarvestedCell ?? self.Location;

// Find any harvestable resources:
List<CPos> path;
Expand All @@ -194,6 +196,10 @@ public override bool Tick(Actor self)
if ((loc - searchFromLoc.Value).LengthSquared > searchRadiusSquared)
return int.MaxValue;
// Prefer cells that are closer to the goal location (usually the refinery)
if (harv.CanHarvestCell(self, loc))
return (goalLoc - loc).Length;
return 0;
})
.FromPoint(searchFromLoc.Value)
Expand Down

0 comments on commit 4fd0bc2

Please sign in to comment.