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
1 change: 1 addition & 0 deletions changelog/snippets/fix.6913.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (#6913) Improve implementation of the edge case fix from #6700 related to using mobile build orders on factories.
9 changes: 8 additions & 1 deletion lua/sim/Unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions lua/sim/units/FactoryUnit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading