Skip to content

Commit 6a0c0ae

Browse files
committed
Merge pull request OpenRA#4340 from pchote/harv-delivery
Allow DeliveryBuildings: to be specified on Harvester
2 parents b6d5f53 + b55b64e commit 6a0c0ae

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

OpenRA.Mods.RA/Harvester.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace OpenRA.Mods.RA
2020
{
2121
public class HarvesterInfo : ITraitInfo
2222
{
23+
public readonly string[] DeliveryBuildings = { };
2324
public readonly int Capacity = 28;
2425
public readonly int LoadTicksPerBale = 4;
2526
public readonly int UnloadTicksPerBale = 4;
@@ -101,12 +102,18 @@ public void ContinueHarvesting(Actor self)
101102
self.QueueActivity(new FindResources());
102103
}
103104

105+
bool IsAcceptableProcType(Actor proc)
106+
{
107+
return Info.DeliveryBuildings.Length == 0 ||
108+
Info.DeliveryBuildings.Contains(proc.Info.Name);
109+
}
110+
104111
Actor ClosestProc(Actor self, Actor ignore)
105112
{
106113
// Find all refineries and their occupancy count:
107114
var refs = (
108115
from r in self.World.ActorsWithTrait<IAcceptOre>()
109-
where r.Actor != ignore && r.Actor.Owner == self.Owner
116+
where r.Actor != ignore && r.Actor.Owner == self.Owner && IsAcceptableProcType(r.Actor)
110117
let linkedHarvs = self.World.ActorsWithTrait<Harvester>().Where(a => a.Trait.LinkedProc == r.Actor).Count()
111118
select new { Location = r.Actor.Location + r.Trait.DeliverOffset, Actor = r.Actor, Occupancy = linkedHarvs }
112119
).ToDictionary(r => r.Location);
@@ -239,7 +246,8 @@ public IEnumerable<IOrderTargeter> Orders
239246
{
240247
get
241248
{
242-
yield return new EnterAlliedActorTargeter<IAcceptOre>("Deliver", 5, _ => true,
249+
yield return new EnterAlliedActorTargeter<IAcceptOre>("Deliver", 5,
250+
proc => IsAcceptableProcType(proc),
243251
proc => !IsEmpty && proc.Trait<IAcceptOre>().AllowDocking);
244252
yield return new HarvestOrderTargeter();
245253
}
@@ -316,7 +324,7 @@ public void ResolveOrder(Actor self, Order order)
316324
{
317325
// NOTE: An explicit deliver order forces the harvester to always deliver to this refinery.
318326
var iao = order.TargetActor.TraitOrDefault<IAcceptOre>();
319-
if (iao == null || !iao.AllowDocking)
327+
if (iao == null || !iao.AllowDocking || !IsAcceptableProcType(order.TargetActor))
320328
return;
321329

322330
if (order.TargetActor != OwnerLinkedProc)

0 commit comments

Comments
 (0)