From d22bdbe9449d94a8243133af46032328b6581fbc Mon Sep 17 00:00:00 2001 From: Gustas Date: Sat, 12 Oct 2024 00:02:13 +0300 Subject: [PATCH] Only allow docking to allied refineries if directly ordered --- .../Buildings/TransformsIntoDockClientManager.cs | 2 +- OpenRA.Mods.Common/Traits/DockClientBase.cs | 11 +++-------- OpenRA.Mods.Common/Traits/DockClientManager.cs | 8 ++++---- OpenRA.Mods.Common/Traits/Harvester.cs | 14 +++++++++++--- OpenRA.Mods.Common/TraitsInterfaces.cs | 2 +- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoDockClientManager.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoDockClientManager.cs index b1c784d9ce..ed6a99ed23 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoDockClientManager.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoDockClientManager.cs @@ -128,7 +128,7 @@ namespace OpenRA.Mods.Common.Traits /// Clone of . public bool DockingPossible(Actor target, bool forceEnter) { - return !IsTraitDisabled && target.TraitsImplementing().Any(host => dockClients.Any(client => client.IsDockingPossible(host.GetDockType))); + return !IsTraitDisabled && target.TraitsImplementing().Any(host => dockClients.Any(client => client.CanDock(host.GetDockType))); } /// Clone of . diff --git a/OpenRA.Mods.Common/Traits/DockClientBase.cs b/OpenRA.Mods.Common/Traits/DockClientBase.cs index 01040e6527..e542209199 100644 --- a/OpenRA.Mods.Common/Traits/DockClientBase.cs +++ b/OpenRA.Mods.Common/Traits/DockClientBase.cs @@ -30,20 +30,15 @@ namespace OpenRA.Mods.Common.Traits DockClientManager = self.TraitOrDefault(); } - protected virtual bool CanDock() + public virtual bool CanDock(BitSet type, bool forceEnter = false) { - return true; - } - - public virtual bool IsDockingPossible(BitSet type, bool forceEnter = false) - { - return !IsTraitDisabled && GetDockType.Overlaps(type) && (forceEnter || CanDock()); + return !IsTraitDisabled && GetDockType.Overlaps(type); } public virtual bool CanDockAt(Actor hostActor, IDockHost host, bool forceEnter = false, bool ignoreOccupancy = false) { return (forceEnter || self.Owner.IsAlliedWith(hostActor.Owner)) && - IsDockingPossible(host.GetDockType, forceEnter) && + CanDock(host.GetDockType, forceEnter) && host.IsDockingPossible(self, this, ignoreOccupancy); } diff --git a/OpenRA.Mods.Common/Traits/DockClientManager.cs b/OpenRA.Mods.Common/Traits/DockClientManager.cs index ce2f14874a..7db9f94f02 100644 --- a/OpenRA.Mods.Common/Traits/DockClientManager.cs +++ b/OpenRA.Mods.Common/Traits/DockClientManager.cs @@ -229,7 +229,7 @@ namespace OpenRA.Mods.Common.Traits /// Do we have an enabled client with matching . public bool DockingPossible(BitSet type, bool forceEnter = false) { - return !IsTraitDisabled && dockClients.Any(client => client.IsDockingPossible(type, forceEnter)); + return !IsTraitDisabled && dockClients.Any(client => client.CanDock(type, forceEnter)); } /// Does this contain at least one enabled with maching . @@ -237,7 +237,7 @@ namespace OpenRA.Mods.Common.Traits { return !IsTraitDisabled && target.TraitsImplementing() - .Any(host => dockClients.Any(client => client.IsDockingPossible(host.GetDockType, forceEnter))); + .Any(host => dockClients.Any(client => client.CanDock(host.GetDockType, forceEnter))); } /// Can we dock to this . @@ -281,7 +281,7 @@ namespace OpenRA.Mods.Common.Traits /// Does not check if is enabled. public IEnumerable AvailableDockClients(BitSet type, bool forceEnter = false) { - return dockClients.Where(client => client.IsDockingPossible(type, forceEnter)); + return dockClients.Where(client => client.CanDock(type, forceEnter)); } void INotifyKilled.Killed(Actor self, AttackInfo e) { UnreserveHost(); } @@ -327,7 +327,7 @@ namespace OpenRA.Mods.Common.Traits if (requireForceMove() && !forceEnter) return false; - if (!self.Owner.IsAlliedWith(target.Actor.Owner) || !canTarget(target.Actor, forceEnter)) + if (!canTarget(target.Actor, forceEnter)) return false; cursor = useEnterCursor(target.Actor, forceEnter) ? enterCursor : enterBlockedCursor; diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index 9fc1feaabf..87b6d09f73 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -94,6 +94,7 @@ namespace OpenRA.Mods.Common.Traits readonly IResourceLayer resourceLayer; readonly ResourceClaimLayer claimLayer; readonly IStoresResources[] storesResources; + readonly Actor self; int conditionToken = Actor.InvalidConditionToken; public override BitSet GetDockType => Info.Type; @@ -107,6 +108,7 @@ namespace OpenRA.Mods.Common.Traits storesResources = self.TraitsImplementing().Where(sr => info.Resources.Any(r => sr.HasType(r))).ToArray(); resourceLayer = self.World.WorldActor.Trait(); claimLayer = self.World.WorldActor.Trait(); + this.self = self; } protected override void Created(Actor self) @@ -124,9 +126,15 @@ namespace OpenRA.Mods.Common.Traits public bool IsEmpty => storesResources.All(sr => sr.ContentsSum == 0); public int Fullness => storesResources.Sum(sr => sr.ContentsSum * 100 / sr.Capacity) / storesResources.Length; - protected override bool CanDock() + public override bool CanDock(BitSet type, bool forceEnter = false) { - return !IsEmpty; + return base.CanDock(type, forceEnter) && (forceEnter || !IsEmpty); + } + + public override bool CanDockAt(Actor hostActor, IDockHost host, bool forceEnter = false, bool ignoreOccupancy = false) + { + return base.CanDockAt(hostActor, host, forceEnter, ignoreOccupancy) + && (self.Owner == hostActor.Owner || (ignoreOccupancy && self.Owner.IsAlliedWith(hostActor.Owner))); } void UpdateCondition(Actor self) @@ -154,7 +162,7 @@ namespace OpenRA.Mods.Common.Traits IAcceptResources acceptResources; public override void OnDockStarted(Actor self, Actor hostActor, IDockHost host) { - if (IsDockingPossible(host.GetDockType)) + if (base.CanDock(host.GetDockType)) acceptResources = hostActor.TraitOrDefault(); } diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 79e1780ce1..74e24f3316 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -225,7 +225,7 @@ namespace OpenRA.Mods.Common.Traits /// Does not check if is enabled. /// Function should only be called from within or . /// - bool IsDockingPossible(BitSet type, bool forceEnter = false); + bool CanDock(BitSet type, bool forceEnter = false); /// Is this client allowed to dock to . ///