Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move RollOfUnit() to after the "finished building" animation #6456

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
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.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
Loading