Merge pull request #10632 from reaperrr/cleanup-harv
Improve Harvester-related code
This commit is contained in:
@@ -702,9 +702,7 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
{
|
{
|
||||||
var act = harvester.GetCurrentActivity();
|
var act = harvester.GetCurrentActivity();
|
||||||
|
|
||||||
// A Wait activity is technically idle:
|
if (act.NextActivity == null || act.NextActivity.GetType() != typeof(FindResources))
|
||||||
if ((act.GetType() != typeof(Wait)) &&
|
|
||||||
(act.NextActivity == null || act.NextActivity.GetType() != typeof(FindResources)))
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,17 +67,10 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (!harv.IsEmpty)
|
if (!harv.IsEmpty)
|
||||||
return deliver;
|
return deliver;
|
||||||
|
|
||||||
var cachedPosition = self.Location;
|
|
||||||
harv.UnblockRefinery(self);
|
|
||||||
|
|
||||||
// Only do this if UnblockRefinery did nothing.
|
|
||||||
if (self.Location == cachedPosition)
|
|
||||||
{
|
|
||||||
var unblockCell = harv.LastHarvestedCell ?? (self.Location + harvInfo.UnblockCell);
|
var unblockCell = harv.LastHarvestedCell ?? (self.Location + harvInfo.UnblockCell);
|
||||||
var moveTo = mobile.NearestMoveableCell(unblockCell, 2, 5);
|
var moveTo = mobile.NearestMoveableCell(unblockCell, 2, 5);
|
||||||
self.QueueActivity(mobile.MoveTo(moveTo, 1));
|
self.QueueActivity(mobile.MoveTo(moveTo, 1));
|
||||||
self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false);
|
self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false);
|
||||||
}
|
|
||||||
|
|
||||||
var randFrames = self.World.SharedRandom.Next(100, 175);
|
var randFrames = self.World.SharedRandom.Next(100, 175);
|
||||||
return ActivityUtils.SequenceActivities(NextActivity, new Wait(randFrames), this);
|
return ActivityUtils.SequenceActivities(NextActivity, new Wait(randFrames), this);
|
||||||
|
|||||||
@@ -57,6 +57,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Search radius (in cells) from the last harvest order location to find more resources.")]
|
[Desc("Search radius (in cells) from the last harvest order location to find more resources.")]
|
||||||
public readonly int SearchFromOrderRadius = 12;
|
public readonly int SearchFromOrderRadius = 12;
|
||||||
|
|
||||||
|
[Desc("Maximum duration of being idle before queueing a Wait activity.")]
|
||||||
|
public readonly int MaxIdleDuration = 25;
|
||||||
|
|
||||||
|
[Desc("Duration to wait before becoming idle again.")]
|
||||||
|
public readonly int WaitDuration = 25;
|
||||||
|
|
||||||
[VoiceReference] public readonly string HarvestVoice = "Action";
|
[VoiceReference] public readonly string HarvestVoice = "Action";
|
||||||
[VoiceReference] public readonly string DeliverVoice = "Action";
|
[VoiceReference] public readonly string DeliverVoice = "Action";
|
||||||
|
|
||||||
@@ -215,17 +221,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var moveTo = mobile.NearestMoveableCell(unblockCell, 1, 5);
|
var moveTo = mobile.NearestMoveableCell(unblockCell, 1, 5);
|
||||||
self.QueueActivity(mobile.MoveTo(moveTo, 1));
|
self.QueueActivity(mobile.MoveTo(moveTo, 1));
|
||||||
self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false);
|
self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false);
|
||||||
|
|
||||||
var territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>();
|
|
||||||
if (territory != null)
|
|
||||||
territory.ClaimResource(self, moveTo);
|
|
||||||
|
|
||||||
var notify = self.TraitsImplementing<INotifyHarvesterAction>();
|
|
||||||
var next = new FindResources(self);
|
|
||||||
foreach (var n in notify)
|
|
||||||
n.MovingToResources(self, moveTo, next);
|
|
||||||
|
|
||||||
self.QueueActivity(next);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,6 +245,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int idleDuration;
|
||||||
public void TickIdle(Actor self)
|
public void TickIdle(Actor self)
|
||||||
{
|
{
|
||||||
// Should we be intelligent while idle?
|
// Should we be intelligent while idle?
|
||||||
@@ -263,9 +259,16 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
UnblockRefinery(self);
|
UnblockRefinery(self);
|
||||||
|
idleDuration += 1;
|
||||||
|
|
||||||
|
// Wait a bit before queueing Wait activity
|
||||||
|
if (idleDuration > Info.MaxIdleDuration)
|
||||||
|
{
|
||||||
|
idleDuration = 0;
|
||||||
|
|
||||||
// Wait for a bit before becoming idle again:
|
// Wait for a bit before becoming idle again:
|
||||||
self.QueueActivity(new Wait(10));
|
self.QueueActivity(new Wait(Info.WaitDuration));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true when unloading is complete
|
// Returns true when unloading is complete
|
||||||
|
|||||||
Reference in New Issue
Block a user