From 7779d0c27c592db69bb20d0fcb01a23445184165 Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Fri, 3 Jan 2025 17:23:58 +0200 Subject: [PATCH] Add smart deploy --- .../Conditions/GrantConditionOnDeploy.cs | 24 ++++++++++++++++++- mods/d2k/rules/infantry.yaml | 1 + mods/ts/rules/gdi-vehicles.yaml | 1 + mods/ts/rules/nod-vehicles.yaml | 3 +++ mods/ts/rules/shared-vehicles.yaml | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDeploy.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDeploy.cs index a63596461d..02be42033c 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDeploy.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDeploy.cs @@ -37,6 +37,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Can this actor deploy on slopes?")] public readonly bool CanDeployOnRamps = false; + [Desc("Does this actor need to synchronize its deployment with other actors?")] + public readonly bool SmartDeploy = false; + [CursorReference] [Desc("Cursor to display when able to (un)deploy the actor.")] public readonly string DeployCursor = "deploy"; @@ -183,7 +186,26 @@ namespace OpenRA.Mods.Common.Traits return new Order("GrantConditionOnDeploy", self, queued); } - bool IIssueDeployOrder.CanIssueDeployOrder(Actor self, bool queued) { return !IsTraitPaused && !IsTraitDisabled; } + bool IIssueDeployOrder.CanIssueDeployOrder(Actor self, bool queued) + { + if (IsTraitPaused || IsTraitDisabled || self.IsDead || self.Disposed) + return false; + + if (queued || !Info.SmartDeploy || DeployState == DeployState.Undeployed || DeployState == DeployState.Undeploying) + return true; + + foreach (var actor in self.World.Selection.Actors) + { + if (actor == self || actor.IsDead || !actor.IsInWorld) + continue; + + if (actor.TraitsImplementing() + .Any(d => !d.IsTraitPaused && !d.IsTraitDisabled && (d.DeployState == DeployState.Undeployed || d.DeployState == DeployState.Undeploying))) + return false; + } + + return true; + } public void ResolveOrder(Actor self, Order order) { diff --git a/mods/d2k/rules/infantry.yaml b/mods/d2k/rules/infantry.yaml index bdc892570c..e4366a3b14 100644 --- a/mods/d2k/rules/infantry.yaml +++ b/mods/d2k/rules/infantry.yaml @@ -135,6 +135,7 @@ thumper: UndeployOnMove: true Facing: 512 AllowedTerrainTypes: Sand, Spice, Dune, SpiceSand + SmartDeploy: true Encyclopedia: Description: actor-thumper.encyclopedia Order: 40 diff --git a/mods/ts/rules/gdi-vehicles.yaml b/mods/ts/rules/gdi-vehicles.yaml index 18a754dc46..ef24ac19ea 100644 --- a/mods/ts/rules/gdi-vehicles.yaml +++ b/mods/ts/rules/gdi-vehicles.yaml @@ -371,6 +371,7 @@ JUGG: DeploySounds: place2.aud UndeploySounds: clicky1.aud Voice: Move + SmartDeploy: true EntersTunnels: RequireForceMoveCondition: !undeployed Repairable: diff --git a/mods/ts/rules/nod-vehicles.yaml b/mods/ts/rules/nod-vehicles.yaml index e0e29ca58f..ea62bb6d63 100644 --- a/mods/ts/rules/nod-vehicles.yaml +++ b/mods/ts/rules/nod-vehicles.yaml @@ -140,6 +140,7 @@ TTNK: DeploySounds: place2.aud UndeploySounds: clicky1.aud Voice: Move + SmartDeploy: true EntersTunnels: RequireForceMoveCondition: !undeployed Repairable: @@ -252,6 +253,7 @@ ART2: DeploySounds: place2.aud UndeploySounds: clicky1.aud Voice: Move + SmartDeploy: true EntersTunnels: RequireForceMoveCondition: !undeployed Repairable: @@ -605,6 +607,7 @@ SGEN: DeploySounds: place2.aud UndeploySounds: clicky1.aud Voice: Move + SmartDeploy: true EntersTunnels: RequireForceMoveCondition: !undeployed Repairable: diff --git a/mods/ts/rules/shared-vehicles.yaml b/mods/ts/rules/shared-vehicles.yaml index 2e96fb26a6..9c0208b234 100644 --- a/mods/ts/rules/shared-vehicles.yaml +++ b/mods/ts/rules/shared-vehicles.yaml @@ -169,6 +169,7 @@ LPST: DeploySounds: place2.aud UndeploySounds: clicky1.aud Voice: Move + SmartDeploy: true EntersTunnels: RequireForceMoveCondition: !undeployed Repairable: