From 78dfcbca8f86571c37d236fe0829c33c940e6580 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Sun, 24 Nov 2024 05:13:00 -0800 Subject: [PATCH 1/2] Move `RollOfUnit()` to after the "finished building" animation (#6456) Fixes #5625. UEF and Cybran air factories have an animation that locks the unit's orientation, interfering with the rolloff rotation. The changes move the rolloff rotation to happen after the animation finishes. --- changelog/snippets/fix.6456.md | 1 + lua/sim/units/FactoryUnit.lua | 39 +++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 changelog/snippets/fix.6456.md diff --git a/changelog/snippets/fix.6456.md b/changelog/snippets/fix.6456.md new file mode 100644 index 0000000000..2d0cfe2350 --- /dev/null +++ b/changelog/snippets/fix.6456.md @@ -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. diff --git a/lua/sim/units/FactoryUnit.lua b/lua/sim/units/FactoryUnit.lua index 9d38529545..be8e2e05f0 100644 --- a/lua/sim/units/FactoryUnit.lua +++ b/lua/sim/units/FactoryUnit.lua @@ -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, @@ -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 @@ -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 @@ -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() From 4eeccb8ca0dca714c6e48721b28a52924c584610 Mon Sep 17 00:00:00 2001 From: clyf Date: Mon, 25 Nov 2024 22:18:21 -0500 Subject: [PATCH 2/2] Prevent siloes from cancelling missiles when issued a hard-stop command (#6557) ## Description of the proposed changes - Silos without engineering suites (SML, TML, SML subs, Sera battleship) will pause missile construction instead of cancelling (and wasting progress) when issued a hard stop command mid-build. - Silos with engineering suites (ACUs and SACUs) are unchanged, and will cancel missiles under construction when issued a hard-stop. This is to prevent a situation where you want to construct something with the unit but don't want to spend additional resources on constructing a missile at the same time. - Code changes: `Stop` is moved below `ClearCommands` to prevent LLS errors/be next to soft stop. Unnecessary local redefinition of `units` at the beginning of `Stop` and `SoftStop` is removed. ## Testing done on the proposed changes Spawn the following units and issue soft- and hard-stop commands. SACUs and ACUs will cancel missile orders when issued a hard-stop command. All other units will pause construction except Yolona (which can't be paused). Naval unit spawn: CreateUnitAtMouse('urs0304', 0, -4.50, -0.79, -1.05475) CreateUnitAtMouse('xss0302', 0, 13.22, 2.00, -0.92170) CreateUnitAtMouse('uas0304', 0, -11.28, -0.49, -1.09571) CreateUnitAtMouse('ues0304', 0, 2.56, -0.72, -1.05031) Land unit and structure spawn: CreateUnitAtMouse('urb2305', 0, -4.89, -20.43, 0.00000) CreateUnitAtMouse('xrb0304', 0, -5.89, 18.57, -0.00000) CreateUnitAtMouse('xrb0304', 0, -7.89, 18.57, -0.00000) CreateUnitAtMouse('xrb0304', 0, -1.89, 18.57, -0.00000) CreateUnitAtMouse('xrb0304', 0, -3.89, 18.57, -0.00000) CreateUnitAtMouse('xsl0001', 0, 3.24, -3.47, 0.00000) CreateUnitAtMouse('xsl0301', 0, 0.24, -3.47, 0.00000) CreateUnitAtMouse('uel0001', 0, -2.76, -3.47, 0.00000) CreateUnitAtMouse('xrb0304', 0, 8.11, 18.57, -0.00000) CreateUnitAtMouse('xrb0304', 0, 6.11, 18.57, -0.00000) CreateUnitAtMouse('urb2108', 0, 2.11, -8.43, 0.00000) CreateUnitAtMouse('xrb0304', 0, 10.11, 18.57, -0.00000) CreateUnitAtMouse('xsb2305', 0, 4.11, -20.43, 0.00000) CreateUnitAtMouse('xsb2108', 0, 6.11, -8.43, 0.00000) CreateUnitAtMouse('uab2305', 0, 13.11, -20.43, 0.00000) CreateUnitAtMouse('ueb2305', 0, -12.89, -20.43, 0.00000) CreateUnitAtMouse('xsb2401', 0, 0.11, -29.43, 0.00000) CreateUnitAtMouse('xrb0304', 0, 4.11, 18.57, -0.00000) CreateUnitAtMouse('ueb2108', 0, -5.89, -8.43, 0.00000) CreateUnitAtMouse('uab2108', 0, -1.89, -8.43, 0.00000) CreateUnitAtMouse('xrb0304', 0, 2.11, 18.57, -0.00000) CreateUnitAtMouse('xrb0304', 0, 0.11, 18.57, -0.00000) CreateUnitAtMouse('xab1401', 0, -11.89, -30.43, -0.00000) --- changelog/snippets/feature.6557.md | 1 + lua/ui/game/orders.lua | 32 +++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 changelog/snippets/feature.6557.md diff --git a/changelog/snippets/feature.6557.md b/changelog/snippets/feature.6557.md new file mode 100644 index 0000000000..26859a6561 --- /dev/null +++ b/changelog/snippets/feature.6557.md @@ -0,0 +1 @@ +- (#6557) Siloes without engineering suites will not cancel missile construction when issued a hard-stop order (siloes will pause construction instead). \ No newline at end of file diff --git a/lua/ui/game/orders.lua b/lua/ui/game/orders.lua index 4712dd898b..a79942c9af 100644 --- a/lua/ui/game/orders.lua +++ b/lua/ui/game/orders.lua @@ -298,14 +298,6 @@ local function MomentaryOrderBehavior(self, modifiers) self:SetCheck(false) end -function Stop(units) - local units = units or GetSelectedUnits() - - if units[1] then - IssueUnitCommand(units, 'Stop') - end -end - function ClearCommands(units) local cb = {Func = 'ClearCommands'} @@ -326,8 +318,30 @@ function ClearCommands(units) SimCallback(cb, true) end +-- This command (hard stop) will filter out non-construction silo units to avoid wasting partially completed missiles +-- Those units will have their commands cleared, but will be paused instead of stopped +function Stop(units) + units = units or GetSelectedUnits() + local silos = EntityCategoryFilterDown(categories.SILO - categories.CONSTRUCTION, units) + if silos[1] then + ClearCommands(silos) + for _, silo in silos do + if not GetIsPausedOfUnit(silo) then + local missileInfo = silo:GetMissileInfo() + if missileInfo.nukeSiloBuildCount > 0 or missileInfo.tacticalSiloBuildCount > 0 then + IssueUnitCommand(silo, 'Pause') + end + end + end + end + units = EntityCategoryFilterOut(categories.SILO - categories.CONSTRUCTION, units) + if units[1] then + IssueUnitCommand(units, 'Stop') + end +end + function SoftStop(units) - local units = units or GetSelectedUnits() + units = units or GetSelectedUnits() Construction.ResetOrderQueues(units) ClearCommands(EntityCategoryFilterDown(categories.SILO, units)) Stop(EntityCategoryFilterOut((categories.SHOWQUEUE * categories.STRUCTURE) + categories.FACTORY + categories.SILO, units))