Skip to content

Commit

Permalink
Merge branch 'develop' into OrdersLuaAnnotations
Browse files Browse the repository at this point in the history
  • Loading branch information
clyfordv committed Nov 26, 2024
2 parents 52433bf + 4eeccb8 commit 1013d46
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
1 change: 1 addition & 0 deletions changelog/snippets/fix.6456.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (#6456) Fix engineers not rotating towards the optimal rolloff point in factories with "build finished" animations such as the UEF and Cybran air factories.
39 changes: 22 additions & 17 deletions lua/sim/units/FactoryUnit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,22 @@ FactoryUnit = ClassUnit(StructureUnit) {
end

if not (self.FactoryBuildFailed or IsDestroyed(self)) then
self:StopBuildFx()

-- Moving off factory has to be issued this tick so that rally points are issued after it
-- Air units don't need the move order since they fly off the factory by themselves
-- Pass the spin up so that engineers can be rotated towards the rolloff point after the "build finished" animation

local spin = nil
if not EntityCategoryContains(categoriesAIR, unitBeingBuilt) then
self:RollOffUnit()
local rollOffPoint = self.RollOffPoint
local x, y, z
spin, x, y, z = self:CalculateRollOffPoint()
rollOffPoint[1], rollOffPoint[2], rollOffPoint[3] = x, y, z
IssueToUnitMoveOffFactory(unitBeingBuilt, rollOffPoint)
end
self:StopBuildFx()
self:ForkThread(self.FinishBuildThread, unitBeingBuilt, order)

self:ForkThread(self.FinishBuildThread, unitBeingBuilt, order, spin)
end

end,
Expand Down Expand Up @@ -211,7 +222,8 @@ FactoryUnit = ClassUnit(StructureUnit) {
---@param self FactoryUnit
---@param unitBeingBuilt Unit
---@param order boolean
FinishBuildThread = function(self, unitBeingBuilt, order)
---@param rollOffPointSpin number?
FinishBuildThread = function(self, unitBeingBuilt, order, rollOffPointSpin)
self:SetBusy(true)
self:SetBlockCommandQueue(true)
local bp = self.Blueprint
Expand All @@ -222,6 +234,12 @@ FactoryUnit = ClassUnit(StructureUnit) {
WaitTicks(1)
WaitFor(self.RollOffAnim)
end

-- engineers can only be rotated during rolloff after the "build finished" animation ends
if rollOffPointSpin and unitBeingBuilt and EntityCategoryContains(categoriesENGINEER, unitBeingBuilt) then
unitBeingBuilt:SetRotation(rollOffPointSpin)
end

if unitBeingBuilt and not unitBeingBuilt.Dead then
unitBeingBuilt:DetachFrom(true)
end
Expand Down Expand Up @@ -249,19 +267,6 @@ FactoryUnit = ClassUnit(StructureUnit) {
return target_bp.General.Category ~= 'Factory'
end,

---@param self FactoryUnit
RollOffUnit = function(self)
local rollOffPoint = self.RollOffPoint
local unitBeingBuilt = self.UnitBeingBuilt --[[@as Unit]]
if unitBeingBuilt and EntityCategoryContains(categoriesENGINEER, unitBeingBuilt) then
local spin, x, y, z = self:CalculateRollOffPoint()
unitBeingBuilt:SetRotation(spin)
rollOffPoint[1], rollOffPoint[2], rollOffPoint[3] = x, y, z
end

IssueToUnitMoveOffFactory(unitBeingBuilt, rollOffPoint)
end,

---@param self FactoryUnit
CalculateRollOffPoint = function(self)
local px, py, pz = self:GetPositionXYZ()
Expand Down

0 comments on commit 1013d46

Please sign in to comment.