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

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
Info.EnterCursor, Info.EnterCursor,
Info.EnterBlockedCursor, Info.EnterBlockedCursor,
() => Info.RequiresForceMove, () => Info.RequiresForceMove,
DockingPossible, CanQueueDockAt,
CanDockAt); CanDockAt);
} }
} }
@@ -109,9 +109,13 @@ namespace OpenRA.Mods.Common.Traits
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order) string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
{ {
if (order.OrderString == "Dock" && CanDockAt(order.Target.Actor, false)) if (order.Target.Type != TargetType.Actor || IsTraitDisabled)
return Info.Voice; return null;
else if (order.OrderString == "ForceDock" && CanDockAt(order.Target.Actor, true))
if (order.OrderString != "Dock" && order.OrderString != "ForceDock")
return null;
if (CanQueueDockAt(order.Target.Actor, order.OrderString == "ForceDock", order.Queued))
return Info.Voice; return Info.Voice;
return null; return null;
@@ -125,12 +129,6 @@ namespace OpenRA.Mods.Common.Traits
return null; return null;
} }
/// <summary>Clone of <see cref="DockClientManager.DockingPossible(Actor, bool)"/>.</summary>
public bool DockingPossible(Actor target, bool forceEnter)
{
return !IsTraitDisabled && target.TraitsImplementing<DockHost>().Any(host => dockClients.Any(client => client.CanDock(host.GetDockType)));
}
/// <summary>Clone of <see cref="DockClientManager.CanDockAt(Actor, bool, bool)"/>.</summary> /// <summary>Clone of <see cref="DockClientManager.CanDockAt(Actor, bool, bool)"/>.</summary>
public bool CanDockAt(Actor target, bool forceEnter) public bool CanDockAt(Actor target, bool forceEnter)
{ {
@@ -140,5 +138,16 @@ namespace OpenRA.Mods.Common.Traits
return !IsTraitDisabled && target.TraitsImplementing<DockHost>().Any( return !IsTraitDisabled && target.TraitsImplementing<DockHost>().Any(
host => dockClients.Any(client => client.CanDockAt(target, host, forceEnter, true))); host => dockClients.Any(client => client.CanDockAt(target, host, forceEnter, true)));
} }
/// <summary>Clone of <see cref="DockClientManager.CanQueueDockAt(Actor, bool, bool)"/>.</summary>
public bool CanQueueDockAt(Actor target, bool forceEnter, bool isQueued)
{
if (Info.RequiresForceMove && !forceEnter)
return false;
return (!IsTraitDisabled)
&& target.TraitsImplementing<IDockHost>().Any(
host => dockClients.Any(client => client.CanQueueDockAt(target, host, forceEnter, isQueued)));
}
} }
} }

View File

@@ -37,9 +37,14 @@ namespace OpenRA.Mods.Common.Traits
public virtual bool CanDockAt(Actor hostActor, IDockHost host, bool forceEnter = false, bool ignoreOccupancy = false) public virtual bool CanDockAt(Actor hostActor, IDockHost host, bool forceEnter = false, bool ignoreOccupancy = false)
{ {
return (forceEnter || self.Owner.IsAlliedWith(hostActor.Owner)) && return CanDock(host.GetDockType, forceEnter)
CanDock(host.GetDockType, forceEnter) && && host.IsDockingPossible(self, this, ignoreOccupancy);
host.IsDockingPossible(self, this, ignoreOccupancy); }
public virtual bool CanQueueDockAt(Actor hostActor, IDockHost host, bool forceEnter, bool isQueued)
{
return CanDock(host.GetDockType, true)
&& host.IsDockingPossible(self, this, true);
} }
public virtual void OnDockStarted(Actor self, Actor hostActor, IDockHost host) { } public virtual void OnDockStarted(Actor self, Actor hostActor, IDockHost host) { }

View File

@@ -160,7 +160,7 @@ namespace OpenRA.Mods.Common.Traits
Info.EnterCursor, Info.EnterCursor,
Info.EnterBlockedCursor, Info.EnterBlockedCursor,
() => requireForceMove, () => requireForceMove,
DockingPossible, CanQueueDockAt,
(target, forceEnter) => CanDockAt(target, forceEnter, true)); (target, forceEnter) => CanDockAt(target, forceEnter, true));
} }
} }
@@ -194,9 +194,10 @@ namespace OpenRA.Mods.Common.Traits
if (order.Target.Type != TargetType.Actor || IsTraitDisabled) if (order.Target.Type != TargetType.Actor || IsTraitDisabled)
return null; return null;
if (order.OrderString == "Dock" && CanDockAt(order.Target.Actor, false, true)) if (order.OrderString != "Dock" && order.OrderString != "ForceDock")
return Info.Voice; return null;
else if (order.OrderString == "ForceDock" && CanDockAt(order.Target.Actor, true, true))
if (CanQueueDockAt(order.Target.Actor, order.OrderString == "ForceDock", order.Queued))
return Info.Voice; return Info.Voice;
return null; return null;
@@ -225,13 +226,13 @@ namespace OpenRA.Mods.Common.Traits
} }
/// <summary>Do we have an enabled client with matching <paramref name="type"/>.</summary> /// <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)); 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> /// <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 && return !IsTraitDisabled &&
target.TraitsImplementing<IDockHost>() target.TraitsImplementing<IDockHost>()
@@ -252,6 +253,14 @@ namespace OpenRA.Mods.Common.Traits
host => dockClients.Any(client => client.CanDockAt(target, host, forceEnter, ignoreOccupancy))); 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> /// <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> /// <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) 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 enterCursor;
readonly string enterBlockedCursor; readonly string enterBlockedCursor;
readonly Func<bool> requireForceMove; readonly Func<bool> requireForceMove;
readonly Func<Actor, bool, bool> canTarget; readonly Func<Actor, bool, bool, bool> canTarget;
readonly Func<Actor, bool, bool> useEnterCursor; readonly Func<Actor, bool, bool> useEnterCursor;
public DockActorTargeter(int priority, string enterCursor, string enterBlockedCursor, 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"; OrderID = "Dock";
OrderPriority = priority; OrderPriority = priority;
@@ -325,10 +334,13 @@ namespace OpenRA.Mods.Common.Traits
if (requireForceMove() && !forceEnter) if (requireForceMove() && !forceEnter)
return false; return false;
if (!canTarget(target.Actor, forceEnter)) if (!canTarget(target.Actor, forceEnter, IsQueued))
return false; return false;
cursor = useEnterCursor(target.Actor, forceEnter) ? enterCursor : enterBlockedCursor; cursor = IsQueued || useEnterCursor(target.Actor, forceEnter)
? enterCursor
: enterBlockedCursor;
return true; return true;
} }

View File

@@ -137,6 +137,12 @@ namespace OpenRA.Mods.Common.Traits
&& (self.Owner == hostActor.Owner || (ignoreOccupancy && self.Owner.IsAlliedWith(hostActor.Owner))); && (self.Owner == hostActor.Owner || (ignoreOccupancy && self.Owner.IsAlliedWith(hostActor.Owner)));
} }
public override bool CanQueueDockAt(Actor hostActor, IDockHost host, bool forceEnter, bool isQueued)
{
return base.CanQueueDockAt(hostActor, host, forceEnter, isQueued)
&& self.Owner.IsAlliedWith(hostActor.Owner);
}
void UpdateCondition(Actor self) void UpdateCondition(Actor self)
{ {
if (string.IsNullOrEmpty(Info.EmptyCondition)) if (string.IsNullOrEmpty(Info.EmptyCondition))

View File

@@ -220,19 +220,26 @@ namespace OpenRA.Mods.Common.Traits
bool OnDockTick(Actor self, Actor hostActor, IDockHost dock); bool OnDockTick(Actor self, Actor hostActor, IDockHost dock);
void OnDockCompleted(Actor self, Actor hostActor, IDockHost host); void OnDockCompleted(Actor self, Actor hostActor, IDockHost host);
/// <summary>Is this client allowed to dock.</summary> /// <summary>Are we allowed to dock.</summary>
/// <remarks> /// <remarks>
/// Does not check if <see cref="Traits.DockClientManager"/> is enabled. /// Does not check if <see cref="Traits.DockClientManager"/> is enabled.
/// Function should only be called from within <see cref="IDockClient"/> or <see cref="Traits.DockClientManager"/>. /// Function should only be called from within <see cref="IDockClient"/> or <see cref="Traits.DockClientManager"/>.
/// </remarks> /// </remarks>
bool CanDock(BitSet<DockType> type, bool forceEnter = false); bool CanDock(BitSet<DockType> type, bool forceEnter = false);
/// <summary>Is this client allowed to dock to <paramref name="host"/>.</summary> /// <summary>Are we allowed to dock to this <paramref name="host"/>.</summary>
/// <remarks> /// <remarks>
/// Does not check if <see cref="Traits.DockClientManager"/> is enabled. /// Does not check if <see cref="Traits.DockClientManager"/> is enabled.
/// Function should only be called from within <see cref="IDockClient"/> or <see cref="Traits.DockClientManager"/>. /// Function should only be called from within <see cref="IDockClient"/> or <see cref="Traits.DockClientManager"/>.
/// </remarks> /// </remarks>
bool CanDockAt(Actor hostActor, IDockHost host, bool forceEnter = false, bool ignoreOccupancy = false); bool CanDockAt(Actor hostActor, IDockHost host, bool forceEnter = false, bool ignoreOccupancy = false);
/// <summary>Are we allowed to give a docking order for this <paramref name="host"/>.</summary>
/// <remarks>
/// Does not check if <see cref="Traits.DockClientManager"/> is enabled.
/// Function should only be called from within <see cref="IDockClient"/> or <see cref="Traits.DockClientManager"/>.
/// </remarks>
bool CanQueueDockAt(Actor hostActor, IDockHost host, bool forceEnter, bool isQueued);
} }
public interface IDockHostInfo : ITraitInfoInterface { } public interface IDockHostInfo : ITraitInfoInterface { }