Fix harvesters refusing to queue dock orders whenn empty

(cherry picked from commit 19040126046a53fd5092515f2a4895fdd5c9c87a)
This commit is contained in:
Gustas
2024-12-02 14:57:41 +02:00
committed by Pavel Penev
parent fc08f18663
commit 52102da839
5 changed files with 64 additions and 25 deletions

View File

@@ -160,7 +160,7 @@ namespace OpenRA.Mods.Common.Traits
Info.EnterCursor,
Info.EnterBlockedCursor,
() => requireForceMove,
DockingPossible,
CanQueueDockAt,
(target, forceEnter) => CanDockAt(target, forceEnter, true));
}
}
@@ -194,9 +194,10 @@ namespace OpenRA.Mods.Common.Traits
if (order.Target.Type != TargetType.Actor || IsTraitDisabled)
return null;
if (order.OrderString == "Dock" && CanDockAt(order.Target.Actor, false, true))
return Info.Voice;
else if (order.OrderString == "ForceDock" && CanDockAt(order.Target.Actor, true, true))
if (order.OrderString != "Dock" && order.OrderString != "ForceDock")
return null;
if (CanQueueDockAt(order.Target.Actor, order.OrderString == "ForceDock", order.Queued))
return Info.Voice;
return null;
@@ -225,13 +226,13 @@ namespace OpenRA.Mods.Common.Traits
}
/// <summary>Do we have an enabled client with matching <paramref name="type"/>.</summary>
public bool DockingPossible(BitSet<DockType> type, bool forceEnter = false)
public bool CanDock(BitSet<DockType> type, bool forceEnter = false)
{
return !IsTraitDisabled && dockClients.Any(client => client.CanDock(type, forceEnter));
}
/// <summary>Does this <paramref name="target"/> contain at least one enabled <see cref="IDockHost"/> with maching <see cref="DockType"/>.</summary>
public bool DockingPossible(Actor target, bool forceEnter = false)
public bool CanDock(Actor target, bool forceEnter = false)
{
return !IsTraitDisabled &&
target.TraitsImplementing<IDockHost>()
@@ -252,6 +253,14 @@ namespace OpenRA.Mods.Common.Traits
host => dockClients.Any(client => client.CanDockAt(target, host, forceEnter, ignoreOccupancy)));
}
/// <summary>Can we dock to this <paramref name="target"/>.</summary>
public bool CanQueueDockAt(Actor target, bool forceEnter, bool isQueued)
{
return !IsTraitDisabled
&& target.TraitsImplementing<IDockHost>()
.Any(host => dockClients.Any(client => client.CanQueueDockAt(target, host, forceEnter, isQueued)));
}
/// <summary>Find the closest viable <see cref="IDockHost"/>.</summary>
/// <remarks>If <paramref name="type"/> is not set, scans all clients. Does not check if <see cref="DockClientManager"/> is enabled.</remarks>
public TraitPair<IDockHost>? ClosestDock(IDockHost ignore, BitSet<DockType> type = default, bool forceEnter = false, bool ignoreOccupancy = false)
@@ -292,11 +301,11 @@ namespace OpenRA.Mods.Common.Traits
readonly string enterCursor;
readonly string enterBlockedCursor;
readonly Func<bool> requireForceMove;
readonly Func<Actor, bool, bool> canTarget;
readonly Func<Actor, bool, bool, bool> canTarget;
readonly Func<Actor, bool, bool> useEnterCursor;
public DockActorTargeter(int priority, string enterCursor, string enterBlockedCursor,
Func<bool> requireForceMove, Func<Actor, bool, bool> canTarget, Func<Actor, bool, bool> useEnterCursor)
Func<bool> requireForceMove, Func<Actor, bool, bool, bool> canTarget, Func<Actor, bool, bool> useEnterCursor)
{
OrderID = "Dock";
OrderPriority = priority;
@@ -325,10 +334,13 @@ namespace OpenRA.Mods.Common.Traits
if (requireForceMove() && !forceEnter)
return false;
if (!canTarget(target.Actor, forceEnter))
if (!canTarget(target.Actor, forceEnter, IsQueued))
return false;
cursor = useEnterCursor(target.Actor, forceEnter) ? enterCursor : enterBlockedCursor;
cursor = IsQueued || useEnterCursor(target.Actor, forceEnter)
? enterCursor
: enterBlockedCursor;
return true;
}