Rework harvester unblock and idle behavior.
This commit is contained in:
@@ -67,23 +67,24 @@ namespace OpenRA.Mods.Common.Activities
|
||||
// or get out of the way and do not disturb.
|
||||
if (!closestHarvestablePosition.HasValue)
|
||||
{
|
||||
if (!harv.IsEmpty)
|
||||
return NextActivity;
|
||||
|
||||
harv.LastSearchFailed = true;
|
||||
|
||||
var unblockCell = harv.LastHarvestedCell ?? (self.Location + harvInfo.UnblockCell);
|
||||
var moveTo = mobile.NearestMoveableCell(unblockCell, 2, 5);
|
||||
|
||||
foreach (var n in self.TraitsImplementing<INotifyHarvesterAction>())
|
||||
n.MovingToResources(self, moveTo, new FindResources(self));
|
||||
|
||||
self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false);
|
||||
var randFrames = self.World.SharedRandom.Next(100, 175);
|
||||
var lastproc = harv.LastLinkedProc ?? harv.LinkedProc;
|
||||
if (lastproc != null && !lastproc.Disposed)
|
||||
{
|
||||
var deliveryLoc = lastproc.Location + lastproc.Trait<IAcceptResources>().DeliveryOffset;
|
||||
if (self.Location == deliveryLoc && harv.IsEmpty)
|
||||
{
|
||||
// Get out of the way:
|
||||
var unblockCell = deliveryLoc + harv.Info.UnblockCell;
|
||||
var moveTo = mobile.NearestMoveableCell(unblockCell, 1, 5);
|
||||
self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Green, false);
|
||||
QueueChild(self, mobile.MoveTo(moveTo, 1), true);
|
||||
QueueChild(self, new Wait(randFrames));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
// Attempt to claim the target cell
|
||||
if (!claimLayer.TryClaimCell(self, closestHarvestablePosition.Value))
|
||||
|
||||
@@ -961,6 +961,7 @@
|
||||
<Compile Include="UpdateRules\Rules\20181215\RefactorResourceLevelAnimating.cs" />
|
||||
<Compile Include="UpdateRules\Rules\20190314\StreamlineRepairableTraits.cs" />
|
||||
<Compile Include="UpdateRules\Rules\20190314\ReplaceSpecialMoveConsiderations.cs" />
|
||||
<Compile Include="UpdateRules\Rules\20190314\RefactorHarvesterIdle.cs" />
|
||||
<Compile Include="Traits\Player\PlayerResources.cs" />
|
||||
<Compile Include="UtilityCommands\DumpSequenceSheetsCommand.cs" />
|
||||
<Compile Include="Traits\Render\WithBuildingRepairDecoration.cs" />
|
||||
|
||||
@@ -148,8 +148,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
dockOrder.QueueChild(self, DockSequence(harv, self));
|
||||
dockOrder.QueueChild(self, new CallFunc(() => dockedHarv = null, false));
|
||||
}
|
||||
|
||||
dockOrder.QueueChild(self, new CallFunc(() => harv.Trait<Harvester>().ContinueHarvesting(harv)));
|
||||
}
|
||||
|
||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
|
||||
@@ -62,10 +62,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Search radius (in cells) from the last harvest order location to find more resources.")]
|
||||
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.")]
|
||||
[Desc("Duration to wait before searching for resources again.")]
|
||||
public readonly int WaitDuration = 25;
|
||||
|
||||
[Desc("Find a new refinery to unload at if more than this many harvesters are already waiting.")]
|
||||
@@ -174,7 +171,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public void ContinueHarvesting(Actor self)
|
||||
{
|
||||
// Move out of the refinery dock and continue harvesting
|
||||
UnblockRefinery(self);
|
||||
self.QueueActivity(new FindResources(self));
|
||||
}
|
||||
|
||||
@@ -248,28 +244,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
UpdateCondition(self);
|
||||
}
|
||||
|
||||
public void UnblockRefinery(Actor self)
|
||||
{
|
||||
// Check that we're not in a critical location and being useless (refinery drop-off):
|
||||
var lastproc = LastLinkedProc ?? LinkedProc;
|
||||
if (lastproc != null && !lastproc.Disposed)
|
||||
{
|
||||
var deliveryLoc = lastproc.Location + lastproc.Trait<IAcceptResources>().DeliveryOffset;
|
||||
if (self.Location == deliveryLoc)
|
||||
{
|
||||
// Get out of the way:
|
||||
var unblockCell = LastHarvestedCell ?? (deliveryLoc + Info.UnblockCell);
|
||||
var moveTo = mobile.NearestMoveableCell(unblockCell, 1, 5);
|
||||
|
||||
// FindResources takes care of calling INotifyHarvesterAction
|
||||
self.QueueActivity(new FindResources(self));
|
||||
|
||||
self.QueueActivity(mobile.MoveTo(moveTo, 1));
|
||||
self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void INotifyBlockingMove.OnNotifyBlockingMove(Actor self, Actor blocking)
|
||||
{
|
||||
// I'm blocking someone else from moving to my location:
|
||||
@@ -303,17 +277,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
}
|
||||
|
||||
UnblockRefinery(self);
|
||||
idleDuration += 1;
|
||||
|
||||
// Wait a bit before queueing Wait activity
|
||||
if (idleDuration > Info.MaxIdleDuration)
|
||||
if (LastSearchFailed)
|
||||
{
|
||||
idleDuration = 0;
|
||||
|
||||
// Wait for a bit before becoming idle again:
|
||||
self.QueueActivity(new Wait(Info.WaitDuration));
|
||||
// Wait a bit before searching again.
|
||||
idleDuration += 1;
|
||||
if (idleDuration <= Info.WaitDuration)
|
||||
return;
|
||||
}
|
||||
|
||||
idleDuration = 0;
|
||||
self.QueueActivity(new FindResources(self));
|
||||
}
|
||||
|
||||
// Returns true when unloading is complete
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2019 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||
{
|
||||
public class RefactorHarvesterIdle : UpdateRule
|
||||
{
|
||||
public override string Name { get { return "Refactor harvester idle behavior."; } }
|
||||
public override string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return "The MaxIdleDuration parameter has been removed from the Harvester trait as part of a\n" +
|
||||
" refactoring of harvester idling behavior.";
|
||||
}
|
||||
}
|
||||
|
||||
readonly List<string> locations = new List<string>();
|
||||
|
||||
public override IEnumerable<string> AfterUpdate(ModData modData)
|
||||
{
|
||||
if (locations.Any())
|
||||
yield return "The MaxIdleDuration parameter has been removed from the harvester logic on the following actors:\n" +
|
||||
UpdateUtils.FormatMessageList(locations) + "\n\n";
|
||||
|
||||
locations.Clear();
|
||||
}
|
||||
|
||||
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
|
||||
{
|
||||
foreach (var t in actorNode.ChildrenMatching("Harvester"))
|
||||
if (t.RemoveNodes("MaxIdleDuration") > 0)
|
||||
locations.Add("{0} ({1})".F(actorNode.Key, actorNode.Location.Filename));
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,6 +123,7 @@ namespace OpenRA.Mods.Common.UpdateRules
|
||||
new MakeMobilePausableConditional(),
|
||||
new StreamlineRepairableTraits(),
|
||||
new ReplaceSpecialMoveConsiderations(),
|
||||
new RefactorHarvesterIdle(),
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user