Rework harvester unblock and idle behavior.

This commit is contained in:
tovl
2019-03-01 02:19:08 +01:00
committed by reaperrr
parent 3bfa32ca33
commit bc7516989e
6 changed files with 75 additions and 52 deletions

View File

@@ -67,22 +67,23 @@ namespace OpenRA.Mods.Common.Activities
// or get out of the way and do not disturb. // or get out of the way and do not disturb.
if (!closestHarvestablePosition.HasValue) if (!closestHarvestablePosition.HasValue)
{ {
if (!harv.IsEmpty)
return NextActivity;
harv.LastSearchFailed = true; harv.LastSearchFailed = true;
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);
return this;
}
}
var unblockCell = harv.LastHarvestedCell ?? (self.Location + harvInfo.UnblockCell); return NextActivity;
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);
QueueChild(self, mobile.MoveTo(moveTo, 1), true);
QueueChild(self, new Wait(randFrames));
return this;
} }
// Attempt to claim the target cell // Attempt to claim the target cell

View File

@@ -961,6 +961,7 @@
<Compile Include="UpdateRules\Rules\20181215\RefactorResourceLevelAnimating.cs" /> <Compile Include="UpdateRules\Rules\20181215\RefactorResourceLevelAnimating.cs" />
<Compile Include="UpdateRules\Rules\20190314\StreamlineRepairableTraits.cs" /> <Compile Include="UpdateRules\Rules\20190314\StreamlineRepairableTraits.cs" />
<Compile Include="UpdateRules\Rules\20190314\ReplaceSpecialMoveConsiderations.cs" /> <Compile Include="UpdateRules\Rules\20190314\ReplaceSpecialMoveConsiderations.cs" />
<Compile Include="UpdateRules\Rules\20190314\RefactorHarvesterIdle.cs" />
<Compile Include="Traits\Player\PlayerResources.cs" /> <Compile Include="Traits\Player\PlayerResources.cs" />
<Compile Include="UtilityCommands\DumpSequenceSheetsCommand.cs" /> <Compile Include="UtilityCommands\DumpSequenceSheetsCommand.cs" />
<Compile Include="Traits\Render\WithBuildingRepairDecoration.cs" /> <Compile Include="Traits\Render\WithBuildingRepairDecoration.cs" />

View File

@@ -148,8 +148,6 @@ namespace OpenRA.Mods.Common.Traits
dockOrder.QueueChild(self, DockSequence(harv, self)); dockOrder.QueueChild(self, DockSequence(harv, self));
dockOrder.QueueChild(self, new CallFunc(() => dockedHarv = null, false)); 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) void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)

View File

@@ -62,10 +62,7 @@ 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.")] [Desc("Duration to wait before searching for resources again.")]
public readonly int MaxIdleDuration = 25;
[Desc("Duration to wait before becoming idle again.")]
public readonly int WaitDuration = 25; public readonly int WaitDuration = 25;
[Desc("Find a new refinery to unload at if more than this many harvesters are already waiting.")] [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) public void ContinueHarvesting(Actor self)
{ {
// Move out of the refinery dock and continue harvesting // Move out of the refinery dock and continue harvesting
UnblockRefinery(self);
self.QueueActivity(new FindResources(self)); self.QueueActivity(new FindResources(self));
} }
@@ -248,28 +244,6 @@ namespace OpenRA.Mods.Common.Traits
UpdateCondition(self); 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) void INotifyBlockingMove.OnNotifyBlockingMove(Actor self, Actor blocking)
{ {
// I'm blocking someone else from moving to my location: // I'm blocking someone else from moving to my location:
@@ -303,17 +277,16 @@ namespace OpenRA.Mods.Common.Traits
return; return;
} }
UnblockRefinery(self); if (LastSearchFailed)
idleDuration += 1;
// Wait a bit before queueing Wait activity
if (idleDuration > Info.MaxIdleDuration)
{ {
idleDuration = 0; // Wait a bit before searching again.
idleDuration += 1;
// Wait for a bit before becoming idle again: if (idleDuration <= Info.WaitDuration)
self.QueueActivity(new Wait(Info.WaitDuration)); return;
} }
idleDuration = 0;
self.QueueActivity(new FindResources(self));
} }
// Returns true when unloading is complete // Returns true when unloading is complete

View File

@@ -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;
}
}
}

View File

@@ -123,6 +123,7 @@ namespace OpenRA.Mods.Common.UpdateRules
new MakeMobilePausableConditional(), new MakeMobilePausableConditional(),
new StreamlineRepairableTraits(), new StreamlineRepairableTraits(),
new ReplaceSpecialMoveConsiderations(), new ReplaceSpecialMoveConsiderations(),
new RefactorHarvesterIdle(),
}) })
}; };