diff --git a/changelog/snippets/fix.6863md b/changelog/snippets/fix.6863md new file mode 100644 index 00000000000..9b439084988 --- /dev/null +++ b/changelog/snippets/fix.6863md @@ -0,0 +1 @@ +- (#6863) Fix `OnAdjacentTo` error caused by dummy units attached to external factories and UEF engineering drones. diff --git a/engine/Core/Categories.lua b/engine/Core/Categories.lua index 4135b201199..d97dd2788dd 100644 --- a/engine/Core/Categories.lua +++ b/engine/Core/Categories.lua @@ -59,6 +59,7 @@ categories = { CANNOTUSEAIRSTAGING = categoryValue, CANTRANSPORTCOMMANDER = categoryValue, CAPTURE = categoryValue, + --- Changes engine behavior of units attached to this unit: Hides units and makes them unselectable. CARRIER = categoryValue, --- Allows the unit to land on water. Is introduced by https://github.com/FAForever/FA-Binary-Patches/pull/20 CANLANDONWATER = categoryValue, diff --git a/lua/sim/units/components/DebugUnitComponent.lua b/lua/sim/units/components/DebugUnitComponent.lua index 6fa678e86a5..aee3d9887c8 100644 --- a/lua/sim/units/components/DebugUnitComponent.lua +++ b/lua/sim/units/components/DebugUnitComponent.lua @@ -22,6 +22,17 @@ local DebugComponent = import("/lua/shared/components/debugcomponent.lua").DebugComponent +---@type UnitState[] +UnitStates = { 'Immobile', 'Moving', 'Attacking', 'Guarding', 'Building', 'Upgrading', + 'WaitingForTransport', 'TransportLoading', 'TransportUnloading', 'MovingDown', 'MovingUp', + 'Patrolling', 'Busy', 'Attached', 'BeingReclaimed', 'Repairing', 'Diving', 'Surfacing', + 'Teleporting', 'Ferrying', 'WaitForFerry', 'AssistMoving', 'PathFinding', 'ProblemGettingToGoal', + 'NeedToTerminateTask', 'Capturing', 'BeingCaptured', 'Reclaiming', 'AssistingCommander', + 'Refueling', 'GuardBusy', 'ForceSpeedThrough', 'UnSelectable', 'DoNotTarget', 'LandingOnPlatform', + 'CannotFindPlaceToLand', 'BeingUpgraded', 'Enhancing', 'BeingBuilt', 'NoReclaim', 'NoCost', + 'BlockCommandQueue', 'MakingAttackRun', 'HoldingPattern', 'SiloBuildingAmmo', +} + ---@class DebugUnitComponent : DebugComponent DebugUnitComponent = Class(DebugComponent) { @@ -118,4 +129,19 @@ DebugUnitComponent = Class(DebugComponent) { local blueprint = self.Blueprint DrawCircle(self:GetPosition(), math.max(blueprint.SizeX, blueprint.SizeY, blueprint.SizeZ), color) end, + + DebugActiveStates = function(self) + if not self.EnabledLogging then + return + end + + local activeStates = {} + for _, state in UnitStates do + if self:IsUnitState(state) then + table.insert(activeStates, state) + end + end + + self:DebugLog('Active states: ' .. table.concat(activeStates, ', ')) + end, } diff --git a/lua/sim/units/uef/TConstructionPodUnit.lua b/lua/sim/units/uef/TConstructionPodUnit.lua index 50633e90bdb..5333fcbc443 100644 --- a/lua/sim/units/uef/TConstructionPodUnit.lua +++ b/lua/sim/units/uef/TConstructionPodUnit.lua @@ -5,7 +5,6 @@ local oldGetGuards = TConstructionUnit.GetGuards ---@field Pod string ---@field Parent? UEL0301 | UEL0001 # Only these two units set the parent properly ---@field guardCache table ----@field guardDummy Unit ---@field rebuildDrone boolean # If true, the parent should rebuild the pod. Caches script bit 1. TConstructionPodUnit = ClassUnit(TConstructionUnit) { Parent = nil, @@ -13,9 +12,6 @@ TConstructionPodUnit = ClassUnit(TConstructionUnit) { ---@param self TConstructionPodUnit OnCreate = function(self) TConstructionUnit.OnCreate(self) - self.guardDummy = CreateUnitHPR('ZXA0003', self:GetArmy(), 0,0,0,0,0,0) - self.guardDummy:AttachTo(self, -1) - self.Trash:Add(self.guardDummy) end, ---@param self TConstructionPodUnit @@ -40,22 +36,11 @@ TConstructionPodUnit = ClassUnit(TConstructionUnit) { ---@param transport Unit ---@param bone number OnAttachedToTransport = function(self, transport, bone) - local guards = self:GetGuards() - IssueClearCommands(guards) - IssueGuard(guards, self.guardDummy) + -- Removing the state allows guards to keep assisting the drone + self:SetUnitState("Attached", false) TConstructionUnit.OnAttachedToTransport(self, transport, bone) end, - ---@param self TConstructionPodUnit - ---@param transport Unit - ---@param bone number - OnDetachedFromTransport = function(self, transport, bone) - TConstructionUnit.OnDetachedFromTransport(self, transport, bone) - local guards = self.guardDummy:GetGuards() - IssueClearCommands(guards) - IssueGuard(guards, self) - end, - ---@param self TConstructionPodUnit ---@param parent UEL0301 | UEL0001 # Only these two implement the function `NotifyOfPodDeath` ---@param podName string @@ -95,7 +80,7 @@ TConstructionPodUnit = ClassUnit(TConstructionUnit) { ---@param target Unit|Prop OnStopReclaim = function(self, target) TConstructionUnit.OnStopReclaim(self, target) - -- Check if we finished our reclaim task and clear our cached commaand if so + -- Check if we finished our reclaim task and clear our cached command if so if self.guardCache and table.empty(target) then self.guardCache = nil end diff --git a/units/ZXA0002/ZXA0002_unit.bp b/units/ZXA0002/ZXA0002_unit.bp index bf4d521d406..eb559a7a509 100644 --- a/units/ZXA0002/ZXA0002_unit.bp +++ b/units/ZXA0002/ZXA0002_unit.bp @@ -5,12 +5,13 @@ UnitBlueprint { 'FACTORY', 'CONSTRUCTION', 'SELECTABLE', - 'UNTARGETTABLE', + 'UNTARGETABLE', 'RALLYPOINT', 'SORTCONSTRUCTION', 'DRAGBUILD', 'SHOWQUEUE', - 'EXTERNALFACTORYUNIT' + 'EXTERNALFACTORYUNIT', + 'UNSPAWNABLE', }, Defense = { Health = 100000, diff --git a/units/ZXA0003/ZXA0003_script.lua b/units/ZXA0003/ZXA0003_script.lua index 8f0583c7b04..a0f0b281a5d 100644 --- a/units/ZXA0003/ZXA0003_script.lua +++ b/units/ZXA0003/ZXA0003_script.lua @@ -24,17 +24,6 @@ local DummyUnit = import('/lua/sim/unit.lua').DummyUnit ---@class ZXA0003 : DummyUnit ZXA0003 = ClassUnit(DummyUnit) { - - OnCreate = function (self) - self:HideBone(0, true) - -- do not allow the unit to be killed or to take damage - self.CanTakeDamage = false - - -- do not allow the unit to be reclaimed or targeted by weapons - self:SetReclaimable(false) - self:SetDoNotTarget(true) - end, - DetachFrom = function(self) end, } diff --git a/units/ZXA0003/ZXA0003_unit.bp b/units/ZXA0003/ZXA0003_unit.bp index 00877047646..af09eb475de 100644 --- a/units/ZXA0003/ZXA0003_unit.bp +++ b/units/ZXA0003/ZXA0003_unit.bp @@ -8,40 +8,12 @@ UnitBlueprint{ "UNTARGETABLE", "CARRIER", }, - Defense = { - Health = 30, - MaxHealth = 30, - }, - Display = { - Mesh = { - IconFadeInZoom = 2000, - LODs = { - { - ShaderName = 'Unit', - MeshName = '/Units/UEA0001/UEA0001_lod0.scm', - AlbedoName = '/Units/UEA0001/UEA0001_Albedo.dds', - NormalsName = '/Units/UEA0001/UEA0001_normalsTS.dds', - SpecularName = '/Units/UEA0001/UEA0001_SpecTeam.dds', - }, - }, - }, - UniformScale = 0.12, - }, - Economy = { - BuildCostEnergy = 0, - BuildCostMass = 0, - BuildTime = 0, - }, General = { CapCost = 0, - Category = '', - SelectionPriority = 3, }, Intel = { VisionRadius = 0 }, Physics = { MotionType = "RULEUMT_None", }, - SizeX = 0, - SizeY = 0, - SizeZ = 0, + CollisionShape = "None" }