From 2a9fe9b84eba29efc6d3dcddc0d4e73f3c7cbb4d Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 22 Aug 2025 04:07:41 -0700 Subject: [PATCH 1/4] Better implementation of #6700 - Only call for the edge case when the build does not fail but the unit is incomplete. - Use proper callbacks instead of relying on the normal finish build behavior to stop build fx and destroying the unit manually --- lua/sim/units/FactoryUnit.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/sim/units/FactoryUnit.lua b/lua/sim/units/FactoryUnit.lua index 074c118afb0..2813b11d4fc 100644 --- a/lua/sim/units/FactoryUnit.lua +++ b/lua/sim/units/FactoryUnit.lua @@ -138,8 +138,10 @@ FactoryUnit = ClassUnit(StructureUnit) { end -- Factory can stop building but still have an unbuilt unit if a mobile build order is issued and the order is cancelled - if unitBeingBuilt:GetFractionComplete() < 1 then - unitBeingBuilt:Destroy() + if not unitBeingBuilt.isFinishedUnit and not self.FactoryBuildFailed then + unitBeingBuilt:OnFailedToBeBuilt() + self:OnFailedToBuild() + return end if not (self.FactoryBuildFailed or IsDestroyed(self)) then From d542a8d3b29e1f6711a5621e5175174d13cd8d78 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 22 Aug 2025 04:11:11 -0700 Subject: [PATCH 2/4] Debug logging --- lua/sim/Unit.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/sim/Unit.lua b/lua/sim/Unit.lua index 9aa7077bb67..0a8f6ea2f98 100644 --- a/lua/sim/Unit.lua +++ b/lua/sim/Unit.lua @@ -2386,6 +2386,7 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni ---@param layer Layer ---@return boolean OnStopBeingBuilt = function(self, builder, layer) + self:DebugLog('OnStopBeingBuilt', GetGameTick(), debug.traceback()) if self.Dead or self:BeenDestroyed() then -- Sanity check, can prevent strange shield bugs and stuff self:Kill() return false @@ -2537,6 +2538,7 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni ---@param self Unit OnFailedToBeBuilt = function(self) + self:DebugLog('OnFailedToBeBuilt', GetGameTick(), debug.traceback()) self:ForkThread(function() WaitTicks(1) if self.Dead then return end @@ -2914,6 +2916,7 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni ---@param built Unit ---@param order string OnStopBuild = function(self, built, order) + self:DebugLog('OnStopBuild') self:StopBuildingEffects(built) self:SetActiveConsumptionInactive() self:DoOnUnitBuiltCallbacks(built) @@ -2932,6 +2935,7 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni ---@param self Unit OnFailedToBuild = function(self) + self:DebugLog('OnFailedToBuild') self:DoOnFailedToBuildCallbacks() self:StopUnitAmbientSound('ConstructLoop') end, From d50d3c0be28ac3f07c967d6a382a7a471e165b53 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 22 Aug 2025 04:28:01 -0700 Subject: [PATCH 3/4] Update annotations --- lua/sim/Unit.lua | 5 ++++- lua/sim/units/FactoryUnit.lua | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lua/sim/Unit.lua b/lua/sim/Unit.lua index 0a8f6ea2f98..bfe41e10c60 100644 --- a/lua/sim/Unit.lua +++ b/lua/sim/Unit.lua @@ -2536,6 +2536,7 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni self.OnBeingBuiltEffectsBag:Destroy() end, + --- Called by the engine when the unit's factory's build order is cancelled. ---@param self Unit OnFailedToBeBuilt = function(self) self:DebugLog('OnFailedToBeBuilt', GetGameTick(), debug.traceback()) @@ -2912,9 +2913,10 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni return true end, + --- Called by the engine when the unit finishes a build order or cancels a mobile build order. ---@param self Unit ---@param built Unit - ---@param order string + ---@param order BuildOrderType OnStopBuild = function(self, built, order) self:DebugLog('OnStopBuild') self:StopBuildingEffects(built) @@ -2933,6 +2935,7 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni self.Brain:OnUnitStopBuild(self, built, order) end, + --- Called by the engine when a build order is cancelled. ---@param self Unit OnFailedToBuild = function(self) self:DebugLog('OnFailedToBuild') diff --git a/lua/sim/units/FactoryUnit.lua b/lua/sim/units/FactoryUnit.lua index 2813b11d4fc..3f765af7a68 100644 --- a/lua/sim/units/FactoryUnit.lua +++ b/lua/sim/units/FactoryUnit.lua @@ -123,9 +123,10 @@ FactoryUnit = ClassUnit(StructureUnit) { end, --- Introduce a rolloff delay, where defined. + --- Called by the engine when the unit finishes a build order or cancels a mobile build order. ---@param self FactoryUnit ---@param unitBeingBuilt Unit - ---@param order string + ---@param order BuildOrderType OnStopBuild = function(self, unitBeingBuilt, order) StructureUnitOnStopBuild(self, unitBeingBuilt, order) @@ -198,6 +199,7 @@ FactoryUnit = ClassUnit(StructureUnit) { self:CreateBlinkingLights() end, + --- Called by the engine when a build order is cancelled. ---@param self FactoryUnit OnFailedToBuild = function(self) StructureUnitOnFailedToBuild(self) @@ -258,7 +260,7 @@ FactoryUnit = ClassUnit(StructureUnit) { ---@param self FactoryUnit ---@param unitBeingBuilt Unit - ---@param order boolean + ---@param order BuildOrderType ---@param rollOffPointSpin number? FinishBuildThread = function(self, unitBeingBuilt, order, rollOffPointSpin) self:SetBusy(true) From f333a8986dacc5cb6bcdbb7d14bbd42933a5ad17 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 22 Aug 2025 04:38:55 -0700 Subject: [PATCH 4/4] Create fix.6913.md --- changelog/snippets/fix.6913.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/snippets/fix.6913.md diff --git a/changelog/snippets/fix.6913.md b/changelog/snippets/fix.6913.md new file mode 100644 index 00000000000..bd8a72c817c --- /dev/null +++ b/changelog/snippets/fix.6913.md @@ -0,0 +1 @@ +- (#6913) Improve implementation of the edge case fix from #6700 related to using mobile build orders on factories.