diff --git a/lua/defaultcomponents.lua b/lua/defaultcomponents.lua index 2f208bff1b..f46eafa285 100644 --- a/lua/defaultcomponents.lua +++ b/lua/defaultcomponents.lua @@ -1,4 +1,5 @@ local Buff = import("/lua/sim/buff.lua") +local Entity = import("/lua/sim/Entity.lua").Entity ---@class ShieldEffectsComponent : Unit ---@field Trash TrashBag @@ -867,8 +868,21 @@ ExternalFactoryComponent = ClassSimple { -- create the factory somewhere completely unrelated local px, py, pz = self:GetPositionXYZ(self.FactoryAttachBone) + -- the anchor entity prevents the "deploy" command from detaching + -- the external factory from the base unit + local anchorEntity = Entity({Owner = self}) + self.Trash:Add(anchorEntity) + anchorEntity:AttachTo(self, self.FactoryAttachBone) + + -- the anchor unit has the "CARRIER" category, which prevents the + -- external factory from being highlighted or selected with the cursor, but + -- doesn't prevent selecting it with the exFac button + local anchorUnit = CreateUnitHPR('ZXA0003', self.Army, px, py, pz, 0, 0, 0) + self.Trash:Add(anchorUnit) + anchorUnit:AttachTo(anchorEntity, -1) + self.ExternalFactory = CreateUnitHPR(blueprintIdExternalFactory, self.Army, px, py, pz, 0, 0, 0) --[[@as ExternalFactoryUnit]] - self.ExternalFactory:AttachTo(self, self.FactoryAttachBone) + self.ExternalFactory:AttachTo(anchorUnit, -1) self.ExternalFactory:SetCreator(self) self:SetCreator(self.ExternalFactory) self.ExternalFactory:SetParent(self) diff --git a/units/ZXA0003/ZXA0003_script.lua b/units/ZXA0003/ZXA0003_script.lua new file mode 100644 index 0000000000..8f0583c7b0 --- /dev/null +++ b/units/ZXA0003/ZXA0003_script.lua @@ -0,0 +1,41 @@ +--****************************************************************************************************** +--** Copyright (c) 2022 clyf +--** +--** Permission is hereby granted, free of charge, to any person obtaining a copy +--** of this software and associated documentation files (the "Software"), to deal +--** in the Software without restriction, including without limitation the rights +--** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +--** copies of the Software, and to permit persons to whom the Software is +--** furnished to do so, subject to the following conditions: +--** +--** The above copyright notice and this permission notice shall be included in all +--** copies or substantial portions of the Software. +--** +--** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +--** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +--** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +--** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +--** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +--** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +--** SOFTWARE. +--****************************************************************************************************** + +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, +} +TypeClass = ZXA0003 \ No newline at end of file diff --git a/units/ZXA0003/ZXA0003_unit.bp b/units/ZXA0003/ZXA0003_unit.bp new file mode 100644 index 0000000000..1e3999e690 --- /dev/null +++ b/units/ZXA0003/ZXA0003_unit.bp @@ -0,0 +1,62 @@ +UnitBlueprint{ + Categories = { + "DUMMYUNIT", + "INSIGNIFICANTUNIT", + "INVULNERABLE", + "UNSELECTABLE", + "UNSPAWNABLE", + "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, + BuildRate = 0.0001, + BuildTime = 0, + MaxBuildDistance = 100, + }, + Footprint = { + MaxSlope = 0.25, + SizeX = 1, + SizeZ = 1, + }, + General = { + CapCost = 0, + SelectionPriority = 3, + }, + Intel = { VisionRadius = 0 }, + Physics = { + BankingSlope = 0.5, + BuildOnLayerCaps = { + LAYER_Air = true, + LAYER_Land = false, + LAYER_Orbit = false, + LAYER_Seabed = false, + LAYER_Sub = false, + LAYER_Water = false, + }, + MotionType = "RULEUMT_None", + }, + SizeX = 0.01, + SizeY = 0.01, + SizeZ = 0.01, +} \ No newline at end of file