Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions OpenRA.Mods.AS/Traits/AutoDeployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
}
Expand All @@ -48,10 +49,7 @@ public class AutoDeployerInfo : ConditionalTraitInfo
public class AutoDeployer : ConditionalTrait<AutoDeployerInfo>, 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;
Expand All @@ -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<AutoDeployer>(self, this));
Expand All @@ -80,15 +78,15 @@ void TryDeploy(Actor self)

void Undeploy(Actor self)
{
if (autoDeployManager.IsTraitDisabled)
if (!autoDeployManager.ManagerRunning || autoDeployManager.IsTraitDisabled)
return;

autoDeployManager.AddUndeployOrders(new Order("GrantConditionOnDeploy", self, false));
}

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))
Expand All @@ -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)
{
Expand All @@ -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))
Expand All @@ -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))
Expand Down
9 changes: 9 additions & 0 deletions OpenRA.Mods.AS/Traits/Player/AutoDeployManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ public class AutoDeployManager : ConditionalTrait<AutoDeployManagerInfo>, IBotTi
readonly HashSet<Order> undeployOrders = new HashSet<Order>();
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<AutoDeployer> entry)
Expand All @@ -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)
Expand Down