diff --git a/changelog/snippets/fix.6913.md b/changelog/snippets/fix.6913.md new file mode 100644 index 0000000000..bd8a72c817 --- /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. diff --git a/lua/sim/Unit.lua b/lua/sim/Unit.lua index 9aa7077bb6..bfe41e10c6 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 @@ -2535,8 +2536,10 @@ 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()) self:ForkThread(function() WaitTicks(1) if self.Dead then return end @@ -2910,10 +2913,12 @@ 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) self:SetActiveConsumptionInactive() self:DoOnUnitBuiltCallbacks(built) @@ -2930,8 +2935,10 @@ 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') self:DoOnFailedToBuildCallbacks() self:StopUnitAmbientSound('ConstructLoop') end, diff --git a/lua/sim/units/FactoryUnit.lua b/lua/sim/units/FactoryUnit.lua index 074c118afb..3f765af7a6 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) @@ -138,8 +139,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 @@ -196,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) @@ -256,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)