diff --git a/OpenRA.Mods.AS/Traits/AutoDeployer.cs b/OpenRA.Mods.AS/Traits/AutoDeployer.cs index bad4a7dad938..e0ed4921e1cf 100644 --- a/OpenRA.Mods.AS/Traits/AutoDeployer.cs +++ b/OpenRA.Mods.AS/Traits/AutoDeployer.cs @@ -38,8 +38,9 @@ public class AutoDeployerInfo : ConditionalTraitInfo [Desc("Delay between two successful deploy orders.")] public readonly int DeployTicks = 2500; - [Desc("Delay to wait for the actor to undeploy (if capable to) after a successful deploy.")] - public readonly int UndeployTicks = 450; + [Desc("Delay to wait for the actor to undeploy (if capable to) after a successful deploy.", + "Note: this option is for GrantConditionOnDeploy only. Set it to -1 to disable.")] + public readonly int UndeployTicks = -1; public override object Create(ActorInitializer init) { return new AutoDeployer(this); } } @@ -48,10 +49,7 @@ public class AutoDeployerInfo : ConditionalTraitInfo public class AutoDeployer : ConditionalTrait, INotifyAttack, ITick, INotifyDamage, INotifyCreated, ISync, INotifyOwnerChanged, INotifyDeployComplete, INotifyBecomingIdle { public const string PrimaryBuildingOrderID = "PrimaryProducer"; - - [Sync] int undeployTicks = -1, deployTicks; - bool deployed; public bool PrimaryBuilding; public IIssueDeployOrder[] DeployTraits; @@ -69,7 +67,7 @@ protected override void Created(Actor self) void TryDeploy(Actor self) { - if (deployTicks > 0 || autoDeployManager.IsTraitDisabled) + if (!autoDeployManager.ManagerRunning || deployTicks > 0 || autoDeployManager.IsTraitDisabled) return; autoDeployManager.AddEntry(new TraitPair(self, this)); @@ -80,7 +78,7 @@ void TryDeploy(Actor self) void Undeploy(Actor self) { - if (autoDeployManager.IsTraitDisabled) + if (!autoDeployManager.ManagerRunning || autoDeployManager.IsTraitDisabled) return; autoDeployManager.AddUndeployOrders(new Order("GrantConditionOnDeploy", self, false)); @@ -88,7 +86,7 @@ void Undeploy(Actor self) void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel) { - if (IsTraitDisabled || autoDeployManager.IsTraitDisabled) + if (!autoDeployManager.ManagerRunning || IsTraitDisabled || autoDeployManager.IsTraitDisabled) return; if (Info.DeployTrigger.HasFlag(DeployTriggers.Attack)) @@ -99,10 +97,10 @@ void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Bar void ITick.Tick(Actor self) { - if (IsTraitDisabled || autoDeployManager.IsTraitDisabled) + if (!autoDeployManager.ManagerRunning || IsTraitDisabled || autoDeployManager.IsTraitDisabled) return; - if (deployed) + if (deployed && Info.UndeployTicks > -1) { if (--undeployTicks < 0) { @@ -119,7 +117,7 @@ void ITick.Tick(Actor self) void INotifyDamage.Damaged(Actor self, AttackInfo e) { - if (IsTraitDisabled || autoDeployManager.IsTraitDisabled) + if (!autoDeployManager.ManagerRunning || IsTraitDisabled || autoDeployManager.IsTraitDisabled) return; if (e.Damage.Value > 0 && Info.DeployTrigger.HasFlag(DeployTriggers.Damage)) @@ -146,7 +144,7 @@ void INotifyDeployComplete.FinishedUndeploy(Actor self) void INotifyBecomingIdle.OnBecomingIdle(Actor self) { - if (IsTraitDisabled || autoDeployManager.IsTraitDisabled) + if (!autoDeployManager.ManagerRunning || IsTraitDisabled || autoDeployManager.IsTraitDisabled) return; if (Info.DeployTrigger.HasFlag(DeployTriggers.BecomingIdle)) diff --git a/OpenRA.Mods.AS/Traits/Player/AutoDeployManager.cs b/OpenRA.Mods.AS/Traits/Player/AutoDeployManager.cs index 3154993daf4d..51dd33bf56e6 100644 --- a/OpenRA.Mods.AS/Traits/Player/AutoDeployManager.cs +++ b/OpenRA.Mods.AS/Traits/Player/AutoDeployManager.cs @@ -28,10 +28,13 @@ public class AutoDeployManager : ConditionalTrait, IBotTi readonly HashSet undeployOrders = new HashSet(); readonly World world; + public bool ManagerRunning { get; private set; } + public AutoDeployManager(Actor self, AutoDeployManagerInfo info) : base(info) { world = self.World; + ManagerRunning = false; } public void AddEntry(TraitPair entry) @@ -46,6 +49,12 @@ public void AddUndeployOrders(Order order) void IBotTick.BotTick(IBot bot) { + // "ManagerRunning = true" means IBotTick is running, and the game is + // 1. not a replay + // 2. not saved game still loading + // 3. the game running on the host where AI is enabled + ManagerRunning = true; + foreach (var entry in active) { if (entry.Actor.IsDead || !entry.Actor.IsInWorld)