From b3de37cb2ee64b41a99fecd0aefc2ddc95a9bdd2 Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 30 May 2024 09:17:50 +0100 Subject: [PATCH] Code Formatting Units V1 (#5759) Co-authored-by: lL1l1 <82986251+lL1l1@users.noreply.github.com> --- changelog/snippets/fix.5759.md | 1 + changelog/snippets/other.5759.md | 3 + engine/Sim.lua | 2 +- engine/Sim/CRotateManipulator.lua | 2 +- lua/seraphimweapons.lua | 2 + .../LightningSmallCollisionBeam.lua | 25 ++++ .../LightningSmallSurfaceCollisionBeam.lua | 63 ++++++++++ .../weapons/seraphim/SAALightningWeapon.lua | 12 ++ units/DAA0206/DAA0206_script.lua | 14 +-- units/DAL0310/DAL0310_Script.lua | 4 +- units/DEA0202/DEA0202_Script.lua | 54 +++++--- units/DELK002/DELK002_script.lua | 28 +++-- units/DRA0202/DRA0202_Script.lua | 93 ++++++++------ units/DRLK001/DRLK001_Script.lua | 4 +- units/DSLK004/DSLK004_script.lua | 115 +++--------------- units/DSLK004/DSLK004_unit.bp | 4 +- units/UAA0104/UAA0104_script.lua | 21 +++- units/UAA0203/UAA0203_script.lua | 7 +- units/UAA0304/UAA0304_Script.lua | 4 +- units/UAA0310/UAA0310_script.lua | 54 ++++++-- units/UAB0303/UAB0303_script.lua | 13 +- units/UAB0304/UAB0304_script.lua | 10 +- units/UAB1102/UAB1102_script.lua | 14 ++- units/UAB1103/UAB1103_script.lua | 42 +++++-- units/UAB1104/UAB1104_Script.lua | 82 ++++++++----- units/UAB1106/UAB1106_script.lua | 15 +-- units/UAB1201/UAB1201_script.lua | 13 +- units/UAB1301/UAB1301_script.lua | 14 ++- units/UAB1302/UAB1302_script.lua | 34 ++++-- units/UAB1303/UAB1303_script.lua | 21 ++-- units/UAB2109/UAB2109_script.lua | 29 +++-- units/UAB2204/UAB2204_script.lua | 25 ++-- units/UAB2205/UAB2205_script.lua | 8 +- units/UAB2305/UAB2305_script.lua | 30 +++-- units/UAB3101/UAB3101_script.lua | 26 ++-- units/UAB3104/UAB3104_script.lua | 50 +++++--- units/UAB3201/UAB3201_script.lua | 51 +++++--- units/UAB4201/UAB4201_script.lua | 17 ++- units/UAB4202/UAB4202_script.lua | 57 +++++---- units/XSL0402/XSL0402_script.lua | 2 +- 40 files changed, 675 insertions(+), 390 deletions(-) create mode 100644 changelog/snippets/fix.5759.md create mode 100644 changelog/snippets/other.5759.md create mode 100644 lua/sim/collisionBeams/LightningSmallCollisionBeam.lua create mode 100644 lua/sim/collisionBeams/LightningSmallSurfaceCollisionBeam.lua create mode 100644 lua/sim/weapons/seraphim/SAALightningWeapon.lua diff --git a/changelog/snippets/fix.5759.md b/changelog/snippets/fix.5759.md new file mode 100644 index 0000000000..53b705b864 --- /dev/null +++ b/changelog/snippets/fix.5759.md @@ -0,0 +1 @@ +- (#5759) Fix rotators on Aeon T2 shield never restarting and on T3 Mass Fabricator never stopping. diff --git a/changelog/snippets/other.5759.md b/changelog/snippets/other.5759.md new file mode 100644 index 0000000000..2ffcbc5d54 --- /dev/null +++ b/changelog/snippets/other.5759.md @@ -0,0 +1,3 @@ +- (#5759) Refactor Seraphim Lightning Tank's weapons and collision beams. + +- (#5759) Reduce overhead of many unit scripts. diff --git a/engine/Sim.lua b/engine/Sim.lua index 3a38573d56..7ea935bd12 100644 --- a/engine/Sim.lua +++ b/engine/Sim.lua @@ -334,7 +334,7 @@ end --- Creates a manipulator which rotates on a unit's bone ---@param object BoneObject ---@param bone Bone ----@param axis "x" | "y" | "z" +---@param axis "x" | "y" | "z" | "-x" | "-y" | "-z" ---@param goal? unknown ---@param speed? number ---@param accel? number diff --git a/engine/Sim/CRotateManipulator.lua b/engine/Sim/CRotateManipulator.lua index 668ec407e9..b55f081fc3 100644 --- a/engine/Sim/CRotateManipulator.lua +++ b/engine/Sim/CRotateManipulator.lua @@ -41,7 +41,7 @@ end function CRotateManipulator:SetSpeed(degreesPerSecond) end ---- +--- When `true`, first decelerates to 2% target speed and then stops at 0 degrees. Does not stop if at negative 2% speed ---@param spinDown boolean function CRotateManipulator:SetSpinDown(spinDown) end diff --git a/lua/seraphimweapons.lua b/lua/seraphimweapons.lua index bf8afa5bb2..d057ce8558 100644 --- a/lua/seraphimweapons.lua +++ b/lua/seraphimweapons.lua @@ -5,6 +5,7 @@ -- Copyright © 2007 Gas Powered Games, Inc. All rights reserved. ----------------------------------------------------------------------------------------------------------- +SAALightningWeapon = import("/lua/sim/weapons/seraphim/SAALightningWeapon.lua").SAALightningWeapon SANAnaitTorpedo = import('/lua/sim/weapons/seraphim/SANAnaitTorpedo.lua').SANAnaitTorpedo SDFExperimentalPhasonProj = import('/lua/sim/weapons/seraphim/SDFExperimentalPhasonProj.lua').SDFExperimentalPhasonProj SDFAireauWeapon = import('/lua/sim/weapons/seraphim/SDFAireauWeapon.lua').SDFAireauWeapon @@ -52,6 +53,7 @@ SDFHeavyQuarnonCannon = import('/lua/sim/weapons/seraphim/SDFHeavyQuarnonCannon. SDFSniperShotNormalMode = import('/lua/sim/weapons/seraphim/SDFSniperShotNormalMode.lua').SDFSniperShotNormalMode SDFSniperShotSniperMode = import('/lua/sim/weapons/seraphim/SDFSniperShotSniperMode.lua').SDFSniperShotSniperMode SB0OhwalliExperimentalStrategicBombWeapon = import('/lua/sim/weapons/seraphim/SB0OhwalliExperimentalStrategicBombWeapon.lua').SB0OhwalliExperimentalStrategicBombWeapon +SAALightningWeapon = import("/lua/sim/weapons/seraphim/SAALightningWeapon.lua").SAALightningWeapon --- Kept Mod Support local WeaponFile = import("/lua/sim/defaultweapons.lua") diff --git a/lua/sim/collisionBeams/LightningSmallCollisionBeam.lua b/lua/sim/collisionBeams/LightningSmallCollisionBeam.lua new file mode 100644 index 0000000000..f9ebb38aab --- /dev/null +++ b/lua/sim/collisionBeams/LightningSmallCollisionBeam.lua @@ -0,0 +1,25 @@ +local SCCollisionBeam = import("/lua/sim/collisionBeams/SCCollisionBeam.lua").SCCollisionBeam + +LightningSmallCollisionBeam = Class(SCCollisionBeam) { + FxBeamStartPoint = { + '/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_01_emit.bp', + '/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_02_emit.bp', + '/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_03_emit.bp', + '/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_04_emit.bp', + '/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_05_emit.bp', + '/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_06_emit.bp', + '/Effects/Emitters/seraphim_electricity_emit.bp' + }, + FxBeam = { + '/Effects/Emitters/seraphim_lightning_beam_01_emit.bp', + }, + FxBeamEndPoint = { + '/Effects/Emitters/seraphim_lightning_hit_01_emit.bp', + '/Effects/Emitters/seraphim_lightning_hit_02_emit.bp', + '/Effects/Emitters/seraphim_lightning_hit_03_emit.bp', + '/Effects/Emitters/seraphim_lightning_hit_04_emit.bp', + }, + + TerrainImpactType = 'LargeBeam01', + TerrainImpactScale = 0.2, +} diff --git a/lua/sim/collisionBeams/LightningSmallSurfaceCollisionBeam.lua b/lua/sim/collisionBeams/LightningSmallSurfaceCollisionBeam.lua new file mode 100644 index 0000000000..470e1ca1b8 --- /dev/null +++ b/lua/sim/collisionBeams/LightningSmallSurfaceCollisionBeam.lua @@ -0,0 +1,63 @@ +local EffectTemplate = import("/lua/effecttemplates.lua") +local Util = import("/lua/utilities.lua") + +local CollisionBeam = import("/lua/sim/collisionbeam.lua").CollisionBeam +local LightningSmallCollisionBeam = import("/lua/sim/collisionBeams/LightningSmallCollisionBeam.lua").LightningSmallCollisionBeam + +LightningSmallSurfaceCollisionBeam = Class(LightningSmallCollisionBeam) { + TerrainImpactScale = 0.1, + FxBeam = { '/Effects/Emitters/seraphim_lightning_beam_02_emit.bp', }, + + SplatTexture = 'czar_mark01_albedo', + ScorchSplatDropTime = 0.25, + + ---@param self LightningSmallSurfaceCollisionBeam + ---@param impactType ImpactType + ---@param targetEntity? Prop|Unit + OnImpact = function(self, impactType, targetEntity) + if impactType ~= 'Shield' and impactType ~= 'Water' and impactType ~= 'Air' and impactType ~= 'UnitAir' and impactType ~= 'Projectile' then + if self.Scorching == nil then + self.Scorching = self:ForkThread(self.ScorchThread) + end + else + KillThread(self.Scorching) + self.Scorching = nil + end + CollisionBeam.OnImpact(self, impactType, targetEntity) + end, + + ---@param self LightningSmallSurfaceCollisionBeam + OnDisable = function(self) + CollisionBeam.OnDisable(self) + KillThread(self.Scorching) + self.Scorching = nil + end, + + ---@param self LightningSmallSurfaceCollisionBeam + ScorchThread = function(self) + local army = self:GetArmy() + local size = 1.1 + (Random() * 1.1) + local CurrentPosition = self:GetPosition(1) + local LastPosition = Vector(0,0,0) + local skipCount = 1 + -- local FriendlyFire = self.DamageData.DamageFriendly + + while true do + if Util.GetDistanceBetweenTwoVectors(CurrentPosition, LastPosition) > 0.25 or skipCount > 100 then + CreateSplat( CurrentPosition, Util.GetRandomFloat(0,2*math.pi), self.SplatTexture, size, size, 100, 100, army ) + LastPosition = CurrentPosition + skipCount = 1 + + -- commented due to hard-crash potential + -- DamageArea(self, CurrentPosition, size, 1, 'Force', FriendlyFire) + -- DamageArea(self, CurrentPosition, size, 1, 'Force', FriendlyFire) + else + skipCount = skipCount + self.ScorchSplatDropTime + end + + WaitSeconds(self.ScorchSplatDropTime) + size = 1 + (Random() * 1.1) + CurrentPosition = self:GetPosition(1) + end + end, +} diff --git a/lua/sim/weapons/seraphim/SAALightningWeapon.lua b/lua/sim/weapons/seraphim/SAALightningWeapon.lua new file mode 100644 index 0000000000..70adec4770 --- /dev/null +++ b/lua/sim/weapons/seraphim/SAALightningWeapon.lua @@ -0,0 +1,12 @@ +local DefaultBeamWeapon = import("/lua/sim/defaultweapons.lua").DefaultBeamWeapon +local EffectTemplate = import('/lua/effecttemplates.lua') +local LightningSmallCollisionBeam = import("/lua/sim/collisionBeams/LightningSmallCollisionBeam.lua").LightningSmallCollisionBeam + +--- Used by DSLK004 +---@class SAALightningWeapon : DefaultProjectileWeapon +SAALightningWeapon = ClassWeapon(DefaultBeamWeapon) { + BeamType = LightningSmallCollisionBeam, + FxMuzzleFlash = { }, + FxUpackingChargeEffects = EffectTemplate.CMicrowaveLaserCharge01, + FxUpackingChargeEffectScale = 0.2, +} diff --git a/units/DAA0206/DAA0206_script.lua b/units/DAA0206/DAA0206_script.lua index 25efbbc062..196ecd8866 100644 --- a/units/DAA0206/DAA0206_script.lua +++ b/units/DAA0206/DAA0206_script.lua @@ -5,30 +5,25 @@ -- Copyright © 2007 Gas Powered Games, Inc. All rights reserved. ------------------------------------------------------------------------------ - local AAirUnit = import("/lua/aeonunits.lua").AAirUnit local DefaultProjectileWeapon = import("/lua/sim/defaultweapons.lua").DefaultProjectileWeapon -local VisionMarker = import("/lua/sim/vizmarker.lua").VisionMarkerOpti ---@class DAA0206 : AAirUnit DAA0206 = ClassUnit(AAirUnit) { - --ContrailEffects = { - -- '/effects/emitters/contrail_ser_ohw_polytrail_01_emit.bp', - --}, - Weapons = { Suicide = ClassWeapon(DefaultProjectileWeapon) {} }, + ---@param self DAA0206 OnRunOutOfFuel = function(self) self:Kill() end, + ---@param self DAA0206 ProjectileFired = function(self) self:GetWeapon(1).IdleState.Main = function(self) end self:PlayUnitSound('Killed') - self:PlayUnitSound('Destroyed') - + self:PlayUnitSound('Destroyed') self:Destroy() end, } @@ -36,4 +31,5 @@ TypeClass = DAA0206 -- Kept for Mod Backwards Compatablity local EffectTemplate = import('/lua/effecttemplates.lua') -local EffectUtils = import('/lua/effectutilities.lua') \ No newline at end of file +local EffectUtils = import('/lua/effectutilities.lua') +local VisionMarker = import("/lua/sim/vizmarker.lua").VisionMarkerOpti diff --git a/units/DAL0310/DAL0310_Script.lua b/units/DAL0310/DAL0310_Script.lua index 5e91d41e2c..659b2ff6cb 100644 --- a/units/DAL0310/DAL0310_Script.lua +++ b/units/DAL0310/DAL0310_Script.lua @@ -14,8 +14,10 @@ DAL0310 = ClassUnit(AHoverLandUnit) { Weapons = { MainGun = ClassWeapon(ADFDisruptorCannonWeapon) { CreateProjectileAtMuzzle = function(self, muzzle) + local bp = self.Blueprint + local proj = ADFDisruptorCannonWeapon.CreateProjectileAtMuzzle(self, muzzle) - local data = self:GetBlueprint().DamageToShields + local data = bp.DamageToShields if proj and not proj:BeenDestroyed() then proj:PassData(data) end diff --git a/units/DEA0202/DEA0202_Script.lua b/units/DEA0202/DEA0202_Script.lua index 08c6059fb8..10604bbdf1 100644 --- a/units/DEA0202/DEA0202_Script.lua +++ b/units/DEA0202/DEA0202_Script.lua @@ -12,6 +12,9 @@ local TAirUnit = import("/lua/terranunits.lua").TAirUnit local TAirToAirLinkedRailgun = import("/lua/terranweapons.lua").TAirToAirLinkedRailgun local TIFCarpetBombWeapon = import("/lua/terranweapons.lua").TIFCarpetBombWeapon +-- upvalue for perfomance +local TrashBagAdd = TrashBag.Add + ---@class DEA0202 : TAirUnit DEA0202 = ClassUnit(TAirUnit) { Weapons = { @@ -20,60 +23,72 @@ DEA0202 = ClassUnit(TAirUnit) { Bomb = ClassWeapon(TIFCarpetBombWeapon) { IdleState = State(TIFCarpetBombWeapon.IdleState) { + + ---@param self DEA0202 Main = function(self) TIFCarpetBombWeapon.IdleState.Main(self) end, + ---@param self DEA0202 OnGotTarget = function(self) - if self.unit:IsUnitState('Moving') then - self.unit:SetSpeedMult(1.0) + local unit = self.unit + + if unit:IsUnitState('Moving') then + unit:SetSpeedMult(1.0) else - self.unit:SetBreakOffTriggerMult(2.0) - self.unit:SetBreakOffDistanceMult(8.0) - self.unit:SetSpeedMult(0.67) + unit:SetBreakOffTriggerMult(2.0) + unit:SetBreakOffDistanceMult(8.0) + unit:SetSpeedMult(0.67) TIFCarpetBombWeapon.IdleState.OnGotTarget(self) end end, + + ---@param self DEA0202 OnFire = function(self) - self.unit:RotateWings(self:GetCurrentTarget()) + local unit = self.unit + unit:RotateWings(self:GetCurrentTarget()) TIFCarpetBombWeapon.IdleState.OnFire(self) end, }, OnFire = function(self) - self.unit:RotateWings(self:GetCurrentTarget()) + local unit = self.unit + unit:RotateWings(self:GetCurrentTarget()) TIFCarpetBombWeapon.OnFire(self) end, OnGotTarget = function(self) - if self.unit:IsUnitState('Moving') then - self.unit:SetSpeedMult(1.0) + local unit = self.unit + if unit:IsUnitState('Moving') then + unit:SetSpeedMult(1.0) else - self.unit:SetBreakOffTriggerMult(2.0) - self.unit:SetBreakOffDistanceMult(8.0) - self.unit:SetSpeedMult(0.67) + unit:SetBreakOffTriggerMult(2.0) + unit:SetBreakOffDistanceMult(8.0) + unit:SetSpeedMult(0.67) TIFCarpetBombWeapon.OnGotTarget(self) end end, OnLostTarget = function(self) - self.unit:SetBreakOffTriggerMult(1.0) - self.unit:SetBreakOffDistanceMult(1.0) - self.unit:SetSpeedMult(1.0) + local unit = self.unit + unit:SetBreakOffTriggerMult(1.0) + unit:SetBreakOffDistanceMult(1.0) + unit:SetSpeedMult(1.0) TIFCarpetBombWeapon.OnLostTarget(self) end, }, }, - RotateWings = function(self, target) + local trash = self.Trash + if not self.LWingRotator then self.LWingRotator = CreateRotator(self, 'Left_Wing', 'y') - self.Trash:Add(self.LWingRotator) + TrashBagAdd(trash, self.LWingRotator) end if not self.RWingRotator then self.RWingRotator = CreateRotator(self, 'Right_Wing', 'y') - self.Trash:Add(self.RWingRotator) + TrashBagAdd(trash, self.RWingRotator) end local fighterAngle = -105 local bomberAngle = 0 @@ -101,7 +116,8 @@ DEA0202 = ClassUnit(TAirUnit) { OnCreate = function(self) TAirUnit.OnCreate(self) - self:ForkThread(self.MonitorWings) + local trash = self.Trash + TrashBagAdd(trash, ForkThread(self.MonitorWings, self)) end, MonitorWings = function(self) diff --git a/units/DELK002/DELK002_script.lua b/units/DELK002/DELK002_script.lua index aa9c5cc8a2..bc63a72ef4 100644 --- a/units/DELK002/DELK002_script.lua +++ b/units/DELK002/DELK002_script.lua @@ -10,6 +10,9 @@ local TAAPhalanxWeapon = import("/lua/kirvesweapons.lua").TAAPhalanxWeapon local EffectUtils = import("/lua/effectutilities.lua") local Effects = import("/lua/effecttemplates.lua") +-- upvalue for performance +local CreateRotator = CreateRotator +local TrashBagAdd = TrashBag.Add ---@class DELK002 : TLandUnit DELK002 = ClassUnit(TLandUnit) { @@ -17,29 +20,35 @@ DELK002 = ClassUnit(TLandUnit) { GatlingCannon = ClassWeapon(TAAPhalanxWeapon) { PlayFxWeaponPackSequence = function(self) + local unit = self.unit + local army = self.Army + if self.SpinManip1 then self.SpinManip1:SetTargetSpeed(0) end if self.SpinManip2 then self.SpinManip2:SetTargetSpeed(0) end - EffectUtils.CreateBoneEffectsOpti(self.unit, 'Left_Muzzle', self.unit.Army, Effects.WeaponSteam01) - EffectUtils.CreateBoneEffectsOpti(self.unit, 'Right_Muzzle', self.unit.Army, Effects.WeaponSteam01) + EffectUtils.CreateBoneEffectsOpti(unit, 'Left_Muzzle', army, Effects.WeaponSteam01) + EffectUtils.CreateBoneEffectsOpti(unit, 'Right_Muzzle', army, Effects.WeaponSteam01) TAAPhalanxWeapon.PlayFxWeaponPackSequence(self) end, PlayFxRackSalvoChargeSequence = function(self) + local trash = self.Trash + local unit = self.unit + if not self.SpinManip1 then - self.SpinManip1 = CreateRotator(self.unit, 'Right_Barrel', 'z', nil, 360, 180, 60) - self.unit.Trash:Add(self.SpinManip1) + self.SpinManip1 = CreateRotator(unit, 'Right_Barrel', 'z', nil, 360, 180, 60) + TrashBagAdd(trash, self.SpinManip1) end if self.SpinManip1 then self.SpinManip1:SetTargetSpeed(500) end if not self.SpinManip2 then - self.SpinManip2 = CreateRotator(self.unit, 'Left_Barrel', 'z', nil, 360, 180, 60) - self.unit.Trash:Add(self.SpinManip2) + self.SpinManip2 = CreateRotator(unit, 'Left_Barrel', 'z', nil, 360, 180, 60) + TrashBagAdd(trash, self.SpinManip2) end if self.SpinManip2 then @@ -49,14 +58,17 @@ DELK002 = ClassUnit(TLandUnit) { end, PlayFxRackSalvoReloadSequence = function(self) + local unit = self.unit + local army = self.Army + if self.SpinManip1 then self.SpinManip1:SetTargetSpeed(200) end if self.SpinManip2 then self.SpinManip2:SetTargetSpeed(200) end - EffectUtils.CreateBoneEffectsOpti(self.unit, 'Left_Muzzle', self.unit.Army, Effects.WeaponSteam01) - EffectUtils.CreateBoneEffectsOpti(self.unit, 'Right_Muzzle', self.unit.Army, Effects.WeaponSteam01) + EffectUtils.CreateBoneEffectsOpti(unit, 'Left_Muzzle', army, Effects.WeaponSteam01) + EffectUtils.CreateBoneEffectsOpti(unit, 'Right_Muzzle', army, Effects.WeaponSteam01) TAAPhalanxWeapon.PlayFxRackSalvoChargeSequence(self) end, }, diff --git a/units/DRA0202/DRA0202_Script.lua b/units/DRA0202/DRA0202_Script.lua index edfc2bf49b..5a24958192 100644 --- a/units/DRA0202/DRA0202_Script.lua +++ b/units/DRA0202/DRA0202_Script.lua @@ -12,67 +12,82 @@ local CAirUnit = import("/lua/cybranunits.lua").CAirUnit local CAAMissileNaniteWeapon = import("/lua/cybranweapons.lua").CAAMissileNaniteWeapon local CIFMissileCorsairWeapon = import("/lua/cybranweapons.lua").CIFMissileCorsairWeapon +-- upvalaue for perfomance +local TrashBagAdd = TrashBag.Add +local WaitSeconds = WaitSeconds +local EntityCategoryContains = EntityCategoryContains +local CreateRotator = CreateRotator + ---@class DRA0202 : CAirUnit DRA0202 = ClassUnit(CAirUnit) { Weapons = { AntiAirMissiles = ClassWeapon(CAAMissileNaniteWeapon) {}, GroundMissile = ClassWeapon(CIFMissileCorsairWeapon) { - - IdleState = State (CIFMissileCorsairWeapon.IdleState) { - Main = function(self) - CIFMissileCorsairWeapon.IdleState.Main(self) - end, - - OnGotTarget = function(self) - if self.unit:IsUnitState('Moving') then - self.unit:SetSpeedMult(1.0) - else - self.unit:SetBreakOffTriggerMult(2.0) - self.unit:SetBreakOffDistanceMult(8.0) - self.unit:SetSpeedMult(0.67) - CIFMissileCorsairWeapon.IdleState.OnGotTarget(self) - end - end, + + IdleState = State (CIFMissileCorsairWeapon.IdleState) { + + Main = function(self) + CIFMissileCorsairWeapon.IdleState.Main(self) + end, + + OnGotTarget = function(self) + if self.unit:IsUnitState('Moving') then + self.unit:SetSpeedMult(1.0) + else + self.unit:SetBreakOffTriggerMult(2.0) + self.unit:SetBreakOffDistanceMult(8.0) + self.unit:SetSpeedMult(0.67) + CIFMissileCorsairWeapon.IdleState.OnGotTarget(self) + end + end, }, - + OnGotTarget = function(self) - if self.unit:IsUnitState('Moving') then - self.unit:SetSpeedMult(1.0) + local unit = self.unit + + if unit:IsUnitState('Moving') then + unit:SetSpeedMult(1.0) else - self.unit:SetBreakOffTriggerMult(2.0) - self.unit:SetBreakOffDistanceMult(8.0) - self.unit:SetSpeedMult(0.67) + unit:SetBreakOffTriggerMult(2.0) + unit:SetBreakOffDistanceMult(8.0) + unit:SetSpeedMult(0.67) CIFMissileCorsairWeapon.OnGotTarget(self) end end, - + OnLostTarget = function(self) - self.unit:SetBreakOffTriggerMult(1.0) - self.unit:SetBreakOffDistanceMult(1.0) - self.unit:SetSpeedMult(1.0) + local unit = self.unit + + unit:SetBreakOffTriggerMult(1.0) + unit:SetBreakOffDistanceMult(1.0) + unit:SetSpeedMult(1.0) CIFMissileCorsairWeapon.OnLostTarget(self) end, }, }, + OnStopBeingBuilt = function(self,builder,layer) CAirUnit.OnStopBeingBuilt(self,builder,layer) self:SetMaintenanceConsumptionInactive() self:SetScriptBit('RULEUTC_StealthToggle', true) self:RequestRefreshUI() end, - + RotateWings = function(self, target) + local trash = self.Trash + if not self.LWingRotator then self.LWingRotator = CreateRotator(self, 'B01', 'x') - self.Trash:Add(self.LWingRotator) + TrashBagAdd(trash, self.LWingRotator) end if not self.RWingRotator then self.RWingRotator = CreateRotator(self, 'B03', 'x') - self.Trash:Add(self.RWingRotator) + TrashBagAdd(trash,self.RWingRotator) end local fighterAngle = 0 local bomberAngle = -90 local wingSpeed = 45 + if target and EntityCategoryContains(categories.AIR, target) then if self.LWingRotator then self.LWingRotator:SetSpeed(wingSpeed) @@ -90,15 +105,16 @@ DRA0202 = ClassUnit(CAirUnit) { if self.RWingRotator then self.RWingRotator:SetSpeed(wingSpeed) self.RWingRotator:SetGoal(bomberAngle) - end - end - end, - + end + end + end, + OnCreate = function(self) CAirUnit.OnCreate(self) - self:ForkThread(self.MonitorWings) + local trash = self.Trash + TrashBagAdd(trash,ForkThread(self.MonitorWings,self)) end, - + MonitorWings = function(self) local airTarget while self and not self.Dead do @@ -108,15 +124,14 @@ DRA0202 = ClassUnit(CAirUnit) { end if airTarget then - self:RotateWings(airTarget) + self:RotateWings(airTarget) else self:RotateWings(nil) end - + WaitSeconds(1) end - end, - + end, } TypeClass = DRA0202 diff --git a/units/DRLK001/DRLK001_Script.lua b/units/DRLK001/DRLK001_Script.lua index d349f5fd23..76aac671b2 100644 --- a/units/DRLK001/DRLK001_Script.lua +++ b/units/DRLK001/DRLK001_Script.lua @@ -15,8 +15,8 @@ DRLK001 = ClassUnit(CWalkingLandUnit) { TargetPainter = ClassWeapon(TargetingLaser) { FxMuzzleFlash = {'/effects/emitters/particle_cannon_muzzle_02_emit.bp'}, }, - - AAGun = ClassWeapon(CAANanoDartWeapon) { + + AAGun = ClassWeapon(CAANanoDartWeapon) { IdleState = State (CAANanoDartWeapon.IdleState) { OnGotTarget = function(self) CAANanoDartWeapon.IdleState.OnGotTarget(self) diff --git a/units/DSLK004/DSLK004_script.lua b/units/DSLK004/DSLK004_script.lua index 0e36ec59cd..3da67d597d 100644 --- a/units/DSLK004/DSLK004_script.lua +++ b/units/DSLK004/DSLK004_script.lua @@ -5,116 +5,33 @@ ------------------------------------------------------------------------------ local SLandUnit = import("/lua/seraphimunits.lua").SLandUnit ---local CollisionBeamFile = import("/lua/kirvesbeams.lua") -local DefaultBeamWeapon = import("/lua/sim/defaultweapons.lua").DefaultBeamWeapon ---local Dummy = import("/lua/kirvesweapons.lua").Dummy -local EffectTemplate = import("/lua/effecttemplates.lua") - -local CollisionBeam = import("/lua/sim/collisionbeam.lua").CollisionBeam -local SCCollisionBeam = import("/lua/defaultcollisionbeams.lua").SCCollisionBeam - -local PhasonCollisionBeam = ClassWeapon(SCCollisionBeam) { - - FxBeamStartPoint = { - '/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_01_emit.bp', - '/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_02_emit.bp', - '/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_03_emit.bp', - '/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_04_emit.bp', - '/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_05_emit.bp', - '/Effects/Emitters/seraphim_experimental_phasonproj_muzzle_flash_06_emit.bp', - '/Effects/Emitters/seraphim_electricity_emit.bp' - }, - FxBeam = { - '/Effects/Emitters/seraphim_lightning_beam_01_emit.bp', - }, - FxBeamEndPoint = { - '/Effects/Emitters/seraphim_lightning_hit_01_emit.bp', - '/Effects/Emitters/seraphim_lightning_hit_02_emit.bp', - '/Effects/Emitters/seraphim_lightning_hit_03_emit.bp', - '/Effects/Emitters/seraphim_lightning_hit_04_emit.bp', - }, - - - TerrainImpactType = 'LargeBeam01', - TerrainImpactScale = 0.2, - SplatTexture = 'czar_mark01_albedo', - ScorchSplatDropTime = 0.25, -} - -local PhasonCollisionBeam2 = ClassWeapon(PhasonCollisionBeam) { - FxBeam = { '/Effects/Emitters/seraphim_lightning_beam_02_emit.bp', }, - TerrainImpactScale = 0.1, - - OnImpact = function(self, impactType, targetEntity) - if impactType == 'Terrain' then - if self.Scorching == nil then - self.Scorching = self:ForkThread(self.ScorchThread) - end - elseif not impactType == 'Unit' then - KillThread(self.Scorching) - self.Scorching = nil - end - PhasonCollisionBeam.OnImpact(self, impactType, targetEntity) - end, - - OnDisable = function(self) - PhasonCollisionBeam.OnDisable(self) - KillThread(self.Scorching) - self.Scorching = nil - end, - - ScorchThread = function(self) - local size = 1 + (Random() * 1.1) - local CurrentPosition = self:GetPosition(1) - local LastPosition = Vector(0,0,0) - local skipCount = 1 - local Util = import("/lua/utilities.lua") - - while true do - if Util.GetDistanceBetweenTwoVectors(CurrentPosition, LastPosition) > 0.25 or skipCount > 100 then - CreateSplat(CurrentPosition, Util.GetRandomFloat(0,2*math.pi), self.SplatTexture, size, size, 100, 100, self.Army) - LastPosition = CurrentPosition - skipCount = 1 - else - skipCount = skipCount + self.ScorchSplatDropTime - end - - WaitSeconds(self.ScorchSplatDropTime) - size = 1 + (Random() * 1.1) - CurrentPosition = self:GetPosition(1) - end - end, -} - -local PhasonBeam = ClassWeapon(DefaultBeamWeapon) { - BeamType = PhasonCollisionBeam, - FxMuzzleFlash = { }, - FxChargeMuzzleFlash = { }, - FxUpackingChargeEffects = EffectTemplate.CMicrowaveLaserCharge01, - FxUpackingChargeEffectScale = 0.2, -} +local SAALightningWeapon = import("/lua/seraphimweapons.lua").SAALightningWeapon +local LightningSmallSurfaceCollisionBeam = import("/lua/sim/collisionBeams/LightningSmallSurfaceCollisionBeam.lua").LightningSmallSurfaceCollisionBeam ---@class DSLK004 : SLandUnit DSLK004 = ClassUnit(SLandUnit) { Weapons = { - PhasonBeamAir = ClassWeapon(PhasonBeam) {}, - PhasonBeamGround = ClassWeapon(PhasonBeam) { - BeamType = PhasonCollisionBeam2, + PhasonBeamAir = ClassWeapon(SAALightningWeapon){}, + PhasonBeamGround = ClassWeapon(SAALightningWeapon){ + BeamType = LightningSmallSurfaceCollisionBeam, FxBeamEndPointScale = 0.01, }, }, OnStopBeingBuilt = function(self,builder,layer) SLandUnit.OnStopBeingBuilt(self,builder,layer) + local army = self.Army - local EfctTempl = { - '/Effects/Emitters/orbeffect_01.bp', - '/Effects/Emitters/orbeffect_02.bp', - } - for k, v in EfctTempl do - CreateAttachedEmitter(self, 'Orb', self.Army, v) - end + CreateAttachedEmitter(self, "Orb", army, "/effects/emitters/orbeffect_01.bp") + CreateAttachedEmitter(self, "Orb", army, "/effects/emitters/orbeffect_02.bp") end, } -TypeClass = DSLK004 \ No newline at end of file + +TypeClass = DSLK004 + +-- kept for backwards compatibility +local DefaultBeamWeapon = import("/lua/sim/defaultweapons.lua").DefaultBeamWeapon +local EffectTemplate = import("/lua/effecttemplates.lua") +local CollisionBeam = import("/lua/sim/collisionbeam.lua").CollisionBeam +local SCCollisionBeam = import("/lua/defaultcollisionbeams.lua").SCCollisionBeam diff --git a/units/DSLK004/DSLK004_unit.bp b/units/DSLK004/DSLK004_unit.bp index 5d0338e24c..85cc253c55 100644 --- a/units/DSLK004/DSLK004_unit.bp +++ b/units/DSLK004/DSLK004_unit.bp @@ -189,7 +189,7 @@ UnitBlueprint{ DamageFriendly = false, DamageRadius = 1, DamageType = "Normal", - DisplayName = "Unstable Phason Laser 2", + DisplayName = "Lightning Surface Projector", FireTargetLayerCapsTable = { Land = "Land|Water|Seabed" }, FiringTolerance = 0, Label = "PhasonBeamGround", @@ -258,7 +258,7 @@ UnitBlueprint{ DamageFriendly = false, DamageRadius = 1, DamageType = "Normal", - DisplayName = "Unstable Phason Laser", + DisplayName = "Lightning Projector", FireTargetLayerCapsTable = { Land = "Air" }, FiringRandomness = 0, FiringTolerance = 2, diff --git a/units/UAA0104/UAA0104_script.lua b/units/UAA0104/UAA0104_script.lua index 0463b7868f..c9ec132725 100644 --- a/units/UAA0104/UAA0104_script.lua +++ b/units/UAA0104/UAA0104_script.lua @@ -9,6 +9,15 @@ local util = import("/lua/utilities.lua") local aWeapons = import("/lua/aeonweapons.lua") local AAASonicPulseBatteryWeapon = aWeapons.AAASonicPulseBatteryWeapon +-- upvalue for perfomance +local ClassWeapon = ClassWeapon +local ForkThread = ForkThread +local WaitSeconds = WaitSeconds +local TrashBagAdd = TrashBag.Add +local MathFloor = math.floor +local GetRandomInt = util.GetRandomInt +local GetRandomFloat = util.GetRandomFloat + ---@class UAA0104 : AirTransport UAA0104 = ClassUnit(AirTransport) { AirDestructionEffectBones = { 'Exhaust', 'Wing_Right', 'Wing_Left', 'Turret_Right', 'Turret_Left', @@ -25,15 +34,19 @@ UAA0104 = ClassUnit(AirTransport) { }, -- Override air destruction effects so we can do something custom here + ---@param self UAA0104 + ---@param scale number unused CreateUnitAirDestructionEffects = function(self, scale) - self.Trash:Add(ForkThread(self.AirDestructionEffectsThread, self)) + local trash = self.Trash + TrashBagAdd(trash, ForkThread(self.AirDestructionEffectsThread, self)) end, AirDestructionEffectsThread = function(self) - local numExplosions = math.floor(table.getn(self.AirDestructionEffectBones) * 0.5) + local airDestructionEffectBones = self.AirDestructionEffectBones + local numExplosions = MathFloor(table.getn(airDestructionEffectBones) * 0.5) for i = 0, numExplosions do - explosion.CreateDefaultHitExplosionAtBone(self, self.AirDestructionEffectBones[util.GetRandomInt(1, numExplosions)], 0.5) - WaitSeconds(util.GetRandomFloat(0.2, 0.9)) + explosion.CreateDefaultHitExplosionAtBone(self, airDestructionEffectBones[GetRandomInt(1, numExplosions)], 0.5) + WaitSeconds(GetRandomFloat(0.2, 0.9)) end end, } diff --git a/units/UAA0203/UAA0203_script.lua b/units/UAA0203/UAA0203_script.lua index 2fbe868134..13d8591959 100644 --- a/units/UAA0203/UAA0203_script.lua +++ b/units/UAA0203/UAA0203_script.lua @@ -13,13 +13,14 @@ UAA0203 = ClassUnit(AAirUnit) { FxChassisMuzzleFlash = { '/effects/emitters/aeon_gunship_body_illumination_01_emit.bp', }, PlayFxMuzzleSequence = function(self, muzzle) - local army = self.unit.Army + local unit = self.unit + local army = self.Army for k, v in self.FxMuzzleFlash do - CreateAttachedEmitter(self.unit, muzzle, army, v) + CreateAttachedEmitter(unit, muzzle, army, v) end for k, v in self.FxChassisMuzzleFlash do - CreateAttachedEmitter(self.unit, -1, army, v) + CreateAttachedEmitter(unit, -1, army, v) end end, }, diff --git a/units/UAA0304/UAA0304_Script.lua b/units/UAA0304/UAA0304_Script.lua index 1463207b5a..48335153aa 100644 --- a/units/UAA0304/UAA0304_Script.lua +++ b/units/UAA0304/UAA0304_Script.lua @@ -14,7 +14,9 @@ UAA0304 = ClassUnit(AAirUnit) { }, OnDamage = function(self, instigator, amount, vector, damageType) - if instigator and instigator.Blueprint.CategoriesHash.STRATEGICBOMBER and instigator.Army == self.Army then + local army = self.Army + + if instigator and instigator.Blueprint.CategoriesHash.STRATEGICBOMBER and instigator.Army == army then return end AAirUnit.OnDamage(self, instigator, amount, vector, damageType) diff --git a/units/UAA0310/UAA0310_script.lua b/units/UAA0310/UAA0310_script.lua index 5ee2fd1597..cb6938d3c0 100644 --- a/units/UAA0310/UAA0310_script.lua +++ b/units/UAA0310/UAA0310_script.lua @@ -17,6 +17,10 @@ local CreateAeonCZARBuildingEffects = import("/lua/effectutilities.lua").CreateA local ExternalFactoryComponent = import("/lua/defaultcomponents.lua").ExternalFactoryComponent +-- upvalue for perfomance +local ClassWeapon = ClassWeapon +local TrashBagAdd = TrashBag.Add + ---@class UAA0310 : AirTransport, ExternalFactoryComponent UAA0310 = ClassUnit(AirTransport, ExternalFactoryComponent) { DestroyNoFallRandomChance = 1.1, @@ -35,11 +39,18 @@ UAA0310 = ClassUnit(AirTransport, ExternalFactoryComponent) { AAFizz02 = ClassWeapon(AAATemporalFizzWeapon) {}, }, + ---@param self UAA0310 + ---@param builder Unit + ---@param layer Layer StartBeingBuiltEffects = function(self, builder, layer) AirTransport.StartBeingBuiltEffects(self, builder, layer) CreateAeonCZARBuildingEffects(self) end, + ---@param self UAA0310 + ---@param instigator Unit + ---@param type string + ---@param overkillRatio number OnKilled = function(self, instigator, type, overkillRatio) ExternalFactoryComponent.OnKilled(self, instigator, type, overkillRatio) @@ -52,18 +63,23 @@ UAA0310 = ClassUnit(AirTransport, ExternalFactoryComponent) { v.Beam:Destroy() end - self.detector = CreateCollisionDetector(self) - self.Trash:Add(self.detector) - self.detector:WatchBone('Left_Turret01_Muzzle') - self.detector:WatchBone('Right_Turret01_Muzzle') - self.detector:WatchBone('Left_Turret02_WepFocus') - self.detector:WatchBone('Right_Turret02_WepFocus') - self.detector:WatchBone('Left_Turret03_Muzzle') - self.detector:WatchBone('Right_Turret03_Muzzle') - self.detector:WatchBone('Attachpoint01') - self.detector:WatchBone('Attachpoint02') - self.detector:EnableTerrainCheck(true) - self.detector:Enable() + local trash = self.Trash + local detector = self.detector + if not detector then + detector = CreateCollisionDetector(self) + TrashBagAdd(trash, detector) + self.detector = detector + end + detector:WatchBone('Left_Turret01_Muzzle') + detector:WatchBone('Right_Turret01_Muzzle') + detector:WatchBone('Left_Turret02_WepFocus') + detector:WatchBone('Right_Turret02_WepFocus') + detector:WatchBone('Left_Turret03_Muzzle') + detector:WatchBone('Right_Turret03_Muzzle') + detector:WatchBone('Attachpoint01') + detector:WatchBone('Attachpoint02') + detector:EnableTerrainCheck(true) + detector:Enable() AirTransport.OnKilled(self, instigator, type, overkillRatio) end, @@ -75,6 +91,11 @@ UAA0310 = ClassUnit(AirTransport, ExternalFactoryComponent) { AirTransport.OnLayerChange(self, new, old) end, + ---@param self UAA0310 + ---@param bone string + ---@param x number + ---@param y number + ---@param z number OnAnimTerrainCollision = function(self, bone, x, y, z) local blueprint = self.Blueprint local position = { x, y, z } @@ -85,26 +106,33 @@ UAA0310 = ClassUnit(AirTransport, ExternalFactoryComponent) { { blueprint.SizeX, blueprint.SizeY, blueprint.SizeZ }) end, + ---@param self UAA0310 + ---@param builder Unit + ---@param layer Layer OnStopBeingBuilt = function(self, builder, layer) AirTransport.OnStopBeingBuilt(self, builder, layer) ExternalFactoryComponent.OnStopBeingBuilt(self, builder, layer) ChangeState(self, self.IdleState) end, + ---@param self UAA0310 OnFailedToBuild = function(self) AirTransport.OnFailedToBuild(self) ChangeState(self, self.IdleState) end, + ---@param self UAA0310 + ---@param bpShield table CreateShield = function(self, bpShield) local bpShield = table.deepcopy(bpShield) + local trash = self.Trash self:DestroyShield() self.MyShield = CzarShield(bpShield, self) self:SetFocusEntity(self.MyShield) self:EnableShield() - self.Trash:Add(self.MyShield) + TrashBagAdd(trash,self.MyShield) end, IdleState = State { diff --git a/units/UAB0303/UAB0303_script.lua b/units/UAB0303/UAB0303_script.lua index 752cfad3c1..ea8ab05973 100644 --- a/units/UAB0303/UAB0303_script.lua +++ b/units/UAB0303/UAB0303_script.lua @@ -4,12 +4,21 @@ -- Copyright © 2005 Gas Powered Games, Inc. All rights reserved. ------------------------------------------------------------------ local ASeaFactoryUnit = import("/lua/aeonunits.lua").ASeaFactoryUnit + +-- upvalue for perfomance +local TrashBagAdd = TrashBag.Add + ---@class UAB0303 : ASeaFactoryUnit UAB0303 = ClassUnit(ASeaFactoryUnit) { + + ---@param self UAB0303 OnCreate = function(self) ASeaFactoryUnit.OnCreate(self) - self.BuildPointSlider = CreateSlider(self, self.Blueprint.Display.BuildAttachBone or 0, -15, 0, 0, -1) - self.Trash:Add(self.BuildPointSlider) + local bp = self.Blueprint + local trash = self.Trash + + self.BuildPointSlider = CreateSlider(self, bp.Display.BuildAttachBone or 0, -15, 0, 0, -1) + TrashBagAdd(trash, self.BuildPointSlider) end, } diff --git a/units/UAB0304/UAB0304_script.lua b/units/UAB0304/UAB0304_script.lua index 9c719695e0..024014d75d 100644 --- a/units/UAB0304/UAB0304_script.lua +++ b/units/UAB0304/UAB0304_script.lua @@ -8,9 +8,15 @@ local AQuantumGateAmbient = import("/lua/effecttemplates.lua").AQuantumGateAmbie ---@class UAB0304 : AQuantumGateUnit UAB0304 = ClassUnit(AQuantumGateUnit) { - OnStopBeingBuilt = function(self,builder,layer) + + ---@param self UAB0304 + ---@param builder Unit + ---@param layer string + OnStopBeingBuilt = function(self, builder, layer) + local army = self.Army + for k, v in AQuantumGateAmbient do - CreateAttachedEmitter(self, 'UAB0304', self.Army, v) + CreateAttachedEmitter(self, 'UAB0304', army, v) end AQuantumGateUnit.OnStopBeingBuilt(self, builder, layer) end, diff --git a/units/UAB1102/UAB1102_script.lua b/units/UAB1102/UAB1102_script.lua index 6179543302..9d0b1f68bb 100644 --- a/units/UAB1102/UAB1102_script.lua +++ b/units/UAB1102/UAB1102_script.lua @@ -4,6 +4,11 @@ -- Copyright © 2005 Gas Powered Games, Inc. All rights reserved. ------------------------------------------------------------------- local AEnergyCreationUnit = import("/lua/aeonunits.lua").AEnergyCreationUnit + +-- upvalue for perfomance +local CreateAttachedEmitter = CreateAttachedEmitter +local TrashBagAdd = TrashBag.Add + ---@class UAB1102 : AEnergyCreationUnit UAB1102 = ClassUnit(AEnergyCreationUnit) { AirEffects = {'/effects/emitters/hydrocarbon_smoke_01_emit.bp',}, @@ -11,11 +16,14 @@ UAB1102 = ClassUnit(AEnergyCreationUnit) { WaterEffects = {'/effects/emitters/underwater_idle_bubbles_01_emit.bp',}, WaterEffectsBones = {'Extension02'}, - OnStopBeingBuilt = function(self,builder,layer) - AEnergyCreationUnit.OnStopBeingBuilt(self,builder,layer) + OnStopBeingBuilt = function(self, builder, layer) + AEnergyCreationUnit.OnStopBeingBuilt(self, builder, layer) local effects = {} local bones = {} local scale = 0.75 + local trash = self.Trash + local army = self.Army + if self:GetCurrentLayer() == 'Land' then effects = self.AirEffects bones = self.AirEffectsBones @@ -26,7 +34,7 @@ UAB1102 = ClassUnit(AEnergyCreationUnit) { end for keys, values in effects do for keysbones, valuesbones in bones do - self.Trash:Add(CreateAttachedEmitter(self, valuesbones, self.Army, values):ScaleEmitter(scale):OffsetEmitter(0,-0.2,1)) + TrashBagAdd(trash, CreateAttachedEmitter(self, valuesbones, army, values):ScaleEmitter(scale):OffsetEmitter(0, -0.2, 1)) end end end, diff --git a/units/UAB1103/UAB1103_script.lua b/units/UAB1103/UAB1103_script.lua index 6517579dae..7f6691bdfa 100644 --- a/units/UAB1103/UAB1103_script.lua +++ b/units/UAB1103/UAB1103_script.lua @@ -5,35 +5,53 @@ ------------------------------------------------------------------- local AMassCollectionUnit = import("/lua/aeonunits.lua").AMassCollectionUnit +-- upvalue for perfomance +local CreateAnimator = CreateAnimator +local TrashBagAdd = TrashBag.Add + + ---@class UAB1103 : AMassCollectionUnit UAB1103 = ClassUnit(AMassCollectionUnit) { OnStartBuild = function(self, unitBeingBuilt, order) AMassCollectionUnit.OnStartBuild(self, unitBeingBuilt, order) - if not self.AnimationManipulator then return end - self.AnimationManipulator:SetRate(0) - self.AnimationManipulator:Destroy() - self.AnimationManipulator = nil + local animManip = self.AnimationManipulator + if animManip then + animManip:SetRate(0) + animManip:Destroy() + self.AnimationManipulator = nil + end end, PlayActiveAnimation = function(self) AMassCollectionUnit.PlayActiveAnimation(self) - if not self.AnimationManipulator then - self.AnimationManipulator = CreateAnimator(self) - self.Trash:Add(self.AnimationManipulator) + local trash = self.Trash + + local animManip = self.AnimationManipulator + if not animManip then + animManip = CreateAnimator(self) + TrashBagAdd(trash, animManip) + self.AnimationManipulator = animManip end - self.AnimationManipulator:PlayAnim(self.Blueprint.Display.AnimationActivate, true) + + animManip:PlayAnim(self.Blueprint.Display.AnimationActivate, true) end, OnProductionPaused = function(self) AMassCollectionUnit.OnProductionPaused(self) - if not self.AnimationManipulator then return end - self.AnimationManipulator:SetRate(0) + + local animManip = self.AnimationManipulator + if animManip then + animManip:SetRate(0) + end end, OnProductionUnpaused = function(self) AMassCollectionUnit.OnProductionUnpaused(self) - if not self.AnimationManipulator then return end - self.AnimationManipulator:SetRate(1) + + local animManip = self.AnimationManipulator + if animManip then + animManip:SetRate(1) + end end, } diff --git a/units/UAB1104/UAB1104_Script.lua b/units/UAB1104/UAB1104_Script.lua index 2d568867b8..c50fd9dd4d 100644 --- a/units/UAB1104/UAB1104_Script.lua +++ b/units/UAB1104/UAB1104_Script.lua @@ -5,17 +5,34 @@ ------------------------------------------------------------------- local AMassFabricationUnit = import("/lua/aeonunits.lua").AMassFabricationUnit +-- upvalue for perfomance +local CreateAnimator = CreateAnimator +local CreateRotator = CreateRotator +local Random = Random +local WaitFor = WaitFor +local TrashBagAdd = TrashBag.Add + + ---@class UAB1104 : AMassFabricationUnit +---@field Damaged boolean +---@field Open boolean +---@field AnimFinished boolean +---@field RotFinished boolean +---@field Clockwise boolean +---@field AnimManip moho.AnimationManipulator +---@field Goal number UAB1104 = ClassUnit(AMassFabricationUnit) { OnCreate = function(self) AMassFabricationUnit.OnCreate(self) + local trash = self.Trash + self.Damaged = false self.Open = false self.AnimFinished = true self.RotFinished = true self.Clockwise = true self.AnimManip = CreateAnimator(self) - self.Trash:Add(self.AnimManip) + TrashBagAdd(trash, self.AnimManip) end, OnStopBeingBuilt = function(self,builder,layer) @@ -25,6 +42,10 @@ UAB1104 = ClassUnit(AMassFabricationUnit) { OpenState = State { Main = function(self) + local bp = self.Blueprint + local army = self.Army + local trash = self.Trash + if self.AmbientEffects then self.AmbientEffects:Destroy() self.AmbientEffects = nil @@ -32,37 +53,39 @@ UAB1104 = ClassUnit(AMassFabricationUnit) { if not self.Open then self.Open = true - self.AnimManip:PlayAnim(self.Blueprint.Display.AnimationOpen):SetRate(1) + self.AnimManip:PlayAnim(bp.Display.AnimationOpen):SetRate(1) WaitFor(self.AnimManip) end - if not self.Rotator then - self.Rotator = CreateRotator(self, 'Axis', 'z', nil, 0, 50, 0) - self.Trash:Add(self.Rotator) + local rotator = self.Rotator + if not rotator then + rotator = CreateRotator(self, 'Axis', 'z', nil, 0, 50, 0) + TrashBagAdd(trash, rotator) + self.Rotator = rotator else - self.Rotator:SetSpinDown(false) + rotator:SetSpinDown(false) end self.Goal = Random(120, 300) -- Ambient effects - self.AmbientEffects = CreateEmitterAtEntity(self, self.Army, '/effects/emitters/aeon_t1_massfab_ambient_01_emit.bp') - self.Trash:Add(self.AmbientEffects) + self.AmbientEffects = CreateEmitterAtEntity(self, army, '/effects/emitters/aeon_t1_massfab_ambient_01_emit.bp') + TrashBagAdd(trash, self.AmbientEffects) while not self.Dead do -- spin clockwise if not self.Clockwise then - self.Rotator:SetTargetSpeed(self.Goal) + rotator:SetTargetSpeed(self.Goal) self.Clockwise = true else - self.Rotator:SetTargetSpeed(-self.Goal) + rotator:SetTargetSpeed(-self.Goal) self.Clockwise = false end - WaitFor(self.Rotator) + WaitFor(rotator) -- slow down to change directions - self.Rotator:SetTargetSpeed(0) - WaitFor(self.Rotator) - self.Rotator:SetSpeed(0) + rotator:SetTargetSpeed(0) + WaitFor(rotator) + rotator:SetSpeed(0) self.Goal = Random(120, 300) end end, @@ -80,23 +103,26 @@ UAB1104 = ClassUnit(AMassFabricationUnit) { self.AmbientEffects = nil end - if self.Open and self.Rotator then - if self.Clockwise == true then - self.Rotator:SetSpinDown(true) - self.Rotator:SetTargetSpeed(self.Goal) - else - self.Rotator:SetTargetSpeed(0) - WaitFor(self.Rotator) - self.Rotator:SetSpinDown(true) - self.Rotator:SetTargetSpeed(self.Goal) + if self.Open then + local rotator = self.Rotator + if rotator then + if self.Clockwise == true then + rotator:SetSpinDown(true) + rotator:SetTargetSpeed(self.Goal) + else + rotator:SetTargetSpeed(0) + WaitFor(rotator) + rotator:SetSpinDown(true) + rotator:SetTargetSpeed(self.Goal) + end + WaitFor(rotator) end - WaitFor(self.Rotator) - end - if self.Open then - self.AnimManip:SetRate(-1) + local animManip = self.AnimManip + + animManip:SetRate(-1) self.Open = false - WaitFor(self.AnimManip) + WaitFor(animManip) end end, diff --git a/units/UAB1106/UAB1106_script.lua b/units/UAB1106/UAB1106_script.lua index b9fa4ba711..1851263f41 100644 --- a/units/UAB1106/UAB1106_script.lua +++ b/units/UAB1106/UAB1106_script.lua @@ -10,16 +10,17 @@ local AMassStorageUnit = import("/lua/aeonunits.lua").AMassStorageUnit +-- upvalue for perfomance +local TrashBagAdd = TrashBag.Add + + ---@class UAB1106 : AMassStorageUnit UAB1106 = ClassUnit(AMassStorageUnit) { - OnStopBeingBuilt = function(self,builder,layer) - AMassStorageUnit.OnStopBeingBuilt(self,builder,layer) - self.Trash:Add(CreateStorageManip(self, 'B01', 'MASS', 0, 0, 0, 0, 0, .41)) - end, - - AnimThread = function(self) - + OnStopBeingBuilt = function(self, builder, layer) + AMassStorageUnit.OnStopBeingBuilt(self, builder, layer) + local trash = self.Trash + TrashBagAdd(trash, CreateStorageManip(self, 'B01', 'MASS', 0, 0, 0, 0, 0, .41)) end, } diff --git a/units/UAB1201/UAB1201_script.lua b/units/UAB1201/UAB1201_script.lua index 9e0868ce4f..2e6f7ee0d0 100644 --- a/units/UAB1201/UAB1201_script.lua +++ b/units/UAB1201/UAB1201_script.lua @@ -9,15 +9,22 @@ --**************************************************************************** local AEnergyCreationUnit = import("/lua/aeonunits.lua").AEnergyCreationUnit +-- upvalue for perfomance +local CreateRotator = CreateRotator +local TrashBagAdd = TrashBag.Add +local Random = Random + ---@class UAB1201 : AEnergyCreationUnit UAB1201 = ClassUnit(AEnergyCreationUnit) { AmbientEffects = 'AT2PowerAmbient', OnStopBeingBuilt = function(self, builder, layer) AEnergyCreationUnit.OnStopBeingBuilt(self, builder, layer) - self.Trash:Add(CreateRotator(self, 'Sphere', 'x', nil, 0, 15, 80 + Random(0, 20))) - self.Trash:Add(CreateRotator(self, 'Sphere', 'y', nil, 0, 15, 80 + Random(0, 20))) - self.Trash:Add(CreateRotator(self, 'Sphere', 'z', nil, 0, 15, 80 + Random(0, 20))) + local trash = self.Trash + + TrashBagAdd(trash, CreateRotator(self, 'Sphere', 'x', nil, 0, 15, 80 + Random(0, 20))) + TrashBagAdd(trash, CreateRotator(self, 'Sphere', 'y', nil, 0, 15, 80 + Random(0, 20))) + TrashBagAdd(trash, CreateRotator(self, 'Sphere', 'z', nil, 0, 15, 80 + Random(0, 20))) end, } diff --git a/units/UAB1301/UAB1301_script.lua b/units/UAB1301/UAB1301_script.lua index e8b23f1e0f..fc4eebd3b9 100644 --- a/units/UAB1301/UAB1301_script.lua +++ b/units/UAB1301/UAB1301_script.lua @@ -9,15 +9,21 @@ --**************************************************************************** local AEnergyCreationUnit = import("/lua/aeonunits.lua").AEnergyCreationUnit +-- upvalue for perfomance +local TrashBagAdd = TrashBag.Add +local Random = Random + ---@class UAB1301 : AEnergyCreationUnit UAB1301 = ClassUnit(AEnergyCreationUnit) { AmbientEffects = 'AT3PowerAmbient', - + OnStopBeingBuilt = function(self, builder, layer) AEnergyCreationUnit.OnStopBeingBuilt(self, builder, layer) - self.Trash:Add(CreateRotator(self, 'Sphere', 'x', nil, 0, 15, 80 + Random(0, 20))) - self.Trash:Add(CreateRotator(self, 'Sphere', 'y', nil, 0, 15, 80 + Random(0, 20))) - self.Trash:Add(CreateRotator(self, 'Sphere', 'z', nil, 0, 15, 80 + Random(0, 20))) + local trash = self.Trash + + TrashBagAdd(trash, CreateRotator(self, 'Sphere', 'x', nil, 0, 15, 80 + Random(0, 20))) + TrashBagAdd(trash, CreateRotator(self, 'Sphere', 'y', nil, 0, 15, 80 + Random(0, 20))) + TrashBagAdd(trash, CreateRotator(self, 'Sphere', 'z', nil, 0, 15, 80 + Random(0, 20))) end, } diff --git a/units/UAB1302/UAB1302_script.lua b/units/UAB1302/UAB1302_script.lua index 6d2d1f4344..13541b23b0 100644 --- a/units/UAB1302/UAB1302_script.lua +++ b/units/UAB1302/UAB1302_script.lua @@ -5,7 +5,14 @@ ------------------------------------------------------------------- local AMassCollectionUnit = import("/lua/aeonunits.lua").AMassCollectionUnit +-- upvalue for perfomance +local TrashBagAdd = TrashBag.Add +local Waitfor = WaitFor + + ---@class UAB1302 : AMassCollectionUnit +---@field ExtractionAnimManip moho.AnimationManipulator +---@field ArmsUp boolean UAB1302 = ClassUnit(AMassCollectionUnit) { OnCreate = function(self) @@ -14,18 +21,25 @@ UAB1302 = ClassUnit(AMassCollectionUnit) { end, OnStopBeingBuilt = function(self, builder, layer) - self.ExtractionAnimManip:PlayAnim(self.Blueprint.Display.AnimationActivate):SetRate(1) - self.Trash:Add(self.ExtractionAnimManip) + local animationActivate = self.Blueprint.Display.AnimationActivate + local trash = self.Trash + local extractionAnimManip = self.ExtractionAnimManip + + extractionAnimManip:PlayAnim(animationActivate):SetRate(1) + TrashBagAdd(trash, extractionAnimManip) AMassCollectionUnit.OnStopBeingBuilt(self, builder, layer) ChangeState(self, self.ActiveState) end, ActiveState = State { Main = function(self) - WaitFor(self.ExtractionAnimManip) + local animationActivate = self.Blueprint.Display.AnimationActivate + local extractionAnimManip = self.ExtractionAnimManip + + WaitFor(extractionAnimManip) while not self:IsDead() do - self.ExtractionAnimManip:PlayAnim(self.Blueprint.Display.AnimationActivate):SetRate(1) - WaitFor(self.ExtractionAnimManip) + self.ExtractionAnimManip:PlayAnim(animationActivate):SetRate(1) + WaitFor(extractionAnimManip) end end, @@ -37,13 +51,15 @@ UAB1302 = ClassUnit(AMassCollectionUnit) { InActiveState = State { Main = function(self) - WaitFor(self.ExtractionAnimManip) + local extractionAnimManip = self.ExtractionAnimManip + + WaitFor(extractionAnimManip) if self.ArmsUp == true then - self.ExtractionAnimManip:SetRate(-1) - WaitFor(self.ExtractionAnimManip) + extractionAnimManip:SetRate(-1) + WaitFor(extractionAnimManip) self.ArmsUp = false end - WaitFor(self.ExtractionAnimManip) + WaitFor(extractionAnimManip) end, OnProductionUnpaused = function(self) diff --git a/units/UAB1303/UAB1303_script.lua b/units/UAB1303/UAB1303_script.lua index feef6d7235..cc33e50236 100644 --- a/units/UAB1303/UAB1303_script.lua +++ b/units/UAB1303/UAB1303_script.lua @@ -5,24 +5,31 @@ ------------------------------------------------------------------- local AMassFabricationUnit = import("/lua/aeonunits.lua").AMassFabricationUnit +-- upvalue for perfomance +local CreateRotator = CreateRotator +local Random = Random +local TrashBagAdd = TrashBag.Add + + ---@class UAB1303 : AMassFabricationUnit UAB1303 = ClassUnit(AMassFabricationUnit) { OnStopBeingBuilt = function(self, builder, layer) AMassFabricationUnit.OnStopBeingBuilt(self, builder, layer) local num = self:GetRandomDir() + local trash = self.Trash self.RingManip1 = CreateRotator(self, 'B01', 'x', nil, 0, 15, 45) - self.Trash:Add(self.RingManip1) - self.RingManip2 = CreateRotator(self, 'B02', 'x', nil, 0, 15, -45) - self.Trash:Add(self.RingManip2) + TrashBagAdd(trash, self.RingManip1) + self.RingManip2 = CreateRotator(self, 'B02', '-x', nil, 0, 15, 45) + TrashBagAdd(trash, self.RingManip2) self.BallManip = CreateRotator(self, 'B03', 'y', nil, 0, 15, 80 + Random(0, 20) * num) - self.Trash:Add(self.BallManip) + TrashBagAdd(trash, self.BallManip) self.ParentManip1 = CreateRotator(self, 'B04', 'z', nil, 0, 15, 80 + Random(0, 20) * num) - self.Trash:Add(self.ParentManip1) + TrashBagAdd(trash, self.ParentManip1) self.ParentManip2 = CreateRotator(self, 'B04', 'y', nil, 0, 15, 80 + Random(0, 20) * num) - self.Trash:Add(self.ParentManip2) + TrashBagAdd(trash, self.ParentManip2) self.ParentManip3 = CreateRotator(self, 'B04', 'x', nil, 0, 15, 80 + Random(0, 20) * num) - self.Trash:Add(self.ParentManip3) + TrashBagAdd(trash, self.ParentManip3) end, OnProductionPaused = function(self) diff --git a/units/UAB2109/UAB2109_script.lua b/units/UAB2109/UAB2109_script.lua index e1edea32b8..24a8bf8228 100644 --- a/units/UAB2109/UAB2109_script.lua +++ b/units/UAB2109/UAB2109_script.lua @@ -8,26 +8,35 @@ --** Copyright © 2005 Gas Powered Games, Inc. All rights reserved. --**************************************************************************** +local Entity = import("/lua/sim/entity.lua").Entity + local AStructureUnit = import("/lua/aeonunits.lua").AStructureUnit local AANChronoTorpedoWeapon = import("/lua/aeonweapons.lua").AANChronoTorpedoWeapon +-- upvalue for perfomance +local TrashBagAdd = TrashBag.Add + ---@class UAB2109 : AStructureUnit UAB2109 = ClassUnit(AStructureUnit) { Weapons = { Turret01 = ClassWeapon(AANChronoTorpedoWeapon) {}, }, + OnCreate = function(self) AStructureUnit.OnCreate(self) + + local trash = self.Trash - self.DomeEntity = import("/lua/sim/entity.lua").Entity({Owner = self,}) - self.DomeEntity:AttachBoneTo( -1, self, 'UAB2109' ) - self.DomeEntity:SetMesh('/effects/Entities/UAB2109_Dome/UAB2109_Dome_mesh') - self.DomeEntity:SetDrawScale(0.3) - self.DomeEntity:SetVizToAllies('Intel') - self.DomeEntity:SetVizToNeutrals('Intel') - self.DomeEntity:SetVizToEnemies('Intel') - self.Trash:Add(self.DomeEntity) - end, + local domeEntity = Entity { Owner = self } + self.DomeEntity = domeEntity + domeEntity:AttachBoneTo( -1, self, 'UAB2109' ) + domeEntity:SetMesh('/effects/Entities/UAB2109_Dome/UAB2109_Dome_mesh') + domeEntity:SetDrawScale(0.3) + domeEntity:SetVizToAllies('Intel') + domeEntity:SetVizToNeutrals('Intel') + domeEntity:SetVizToEnemies('Intel') + TrashBagAdd(trash, domeEntity) + end, } -TypeClass = UAB2109 \ No newline at end of file +TypeClass = UAB2109 diff --git a/units/UAB2204/UAB2204_script.lua b/units/UAB2204/UAB2204_script.lua index f9fb8cb0db..4f3f536872 100644 --- a/units/UAB2204/UAB2204_script.lua +++ b/units/UAB2204/UAB2204_script.lua @@ -1,15 +1,15 @@ -----**************************************************************************** -----** -----** File : /cdimage/units/UAB2204/UAB2204_script.lua -----** Author(s): John Comes, David Tomandl, Jessica St. Croix, Gordon Duclos -----** -----** Summary : Aeon Flak Cannon -----** -----** Copyright © 2005 Gas Powered Games, Inc. All rights reserved. -----**************************************************************************** +----------------------------------------------------------------------------- +-- File : /cdimage/units/UAB2204/UAB2204_script.lua +-- Author(s): John Comes, David Tomandl, Jessica St. Croix, Gordon Duclos +-- Summary : Aeon Flak Cannon +-- Copyright © 2005 Gas Powered Games, Inc. All rights reserved. +----------------------------------------------------------------------------- local AStructureUnit = import("/lua/aeonunits.lua").AStructureUnit local AAATemporalFizzWeapon = import("/lua/aeonweapons.lua").AAATemporalFizzWeapon +-- upvalue for perfomance +local CreateAttachedEmitter = CreateAttachedEmitter + ---@class UAB2204 : AStructureUnit UAB2204 = ClassUnit(AStructureUnit) { Weapons = { @@ -17,9 +17,12 @@ UAB2204 = ClassUnit(AStructureUnit) { ChargeEffectMuzzles = {'Turret_Right_Muzzle', 'Turret_Left_Muzzle'}, PlayFxRackSalvoChargeSequence = function(self) + local unit = self.unit + local army = unit.Army + AAATemporalFizzWeapon.PlayFxRackSalvoChargeSequence(self) - CreateAttachedEmitter(self.unit, 'Turret_Right_Muzzle', self.unit.Army, '/effects/emitters/temporal_fizz_muzzle_charge_02_emit.bp') - CreateAttachedEmitter(self.unit, 'Turret_Left_Muzzle', self.unit.Army, '/effects/emitters/temporal_fizz_muzzle_charge_03_emit.bp') + CreateAttachedEmitter(unit, 'Turret_Right_Muzzle', army, '/effects/emitters/temporal_fizz_muzzle_charge_02_emit.bp') + CreateAttachedEmitter(unit, 'Turret_Left_Muzzle', army, '/effects/emitters/temporal_fizz_muzzle_charge_03_emit.bp') end, }, }, diff --git a/units/UAB2205/UAB2205_script.lua b/units/UAB2205/UAB2205_script.lua index 79db60b074..f45cbdb9c3 100644 --- a/units/UAB2205/UAB2205_script.lua +++ b/units/UAB2205/UAB2205_script.lua @@ -11,14 +11,18 @@ local AStructureUnit = import("/lua/aeonunits.lua").AStructureUnit local AANChronoTorpedoWeapon = import("/lua/aeonweapons.lua").AANChronoTorpedoWeapon +-- upvalue for perfomance +local TrashBagAdd = TrashBag.Add + ---@class UAB2205 : AStructureUnit UAB2205 = ClassUnit(AStructureUnit) { Weapons = { Turret01 = ClassWeapon(AANChronoTorpedoWeapon) {}, }, - + OnCreate = function(self) AStructureUnit.OnCreate(self) + local trash = self.Trash self.DomeEntity = import("/lua/sim/entity.lua").Entity({Owner = self,}) self.DomeEntity:AttachBoneTo( -1, self, 'UAB2205' ) @@ -27,7 +31,7 @@ UAB2205 = ClassUnit(AStructureUnit) { self.DomeEntity:SetVizToAllies('Intel') self.DomeEntity:SetVizToNeutrals('Intel') self.DomeEntity:SetVizToEnemies('Intel') - self.Trash:Add(self.DomeEntity) + TrashBagAdd(trash,self.DomeEntity) end, } diff --git a/units/UAB2305/UAB2305_script.lua b/units/UAB2305/UAB2305_script.lua index cb3431889a..9109ed5b9f 100644 --- a/units/UAB2305/UAB2305_script.lua +++ b/units/UAB2305/UAB2305_script.lua @@ -8,14 +8,26 @@ local AStructureUnit = import("/lua/aeonunits.lua").AStructureUnit local AIFQuantumWarhead = import("/lua/aeonweapons.lua").AIFQuantumWarhead +-- upvalue for perfomance +local WaitTicks = WaitTicks +local ForkThread = ForkThread +local CreateAnimator = CreateAnimator +local CreateAttachedEmitter = CreateAttachedEmitter +local TrashBagAdd = TrashBag.Add + + ---@class UAB2305 : AStructureUnit UAB2305 = ClassUnit(AStructureUnit) { Weapons = { QuantumMissiles = ClassWeapon(AIFQuantumWarhead) { UnpackEffects01 = { '/effects/emitters/aeon_nuke_unpack_01_emit.bp', }, + PlayFxWeaponUnpackSequence = function(self) + local unit = self.unit + local army = unit.Army + for k, v in self.UnpackEffects01 do - CreateAttachedEmitter(self.unit, 'B04', self.unit.Army, v) + CreateAttachedEmitter(unit, 'B04', army, v) end AIFQuantumWarhead.PlayFxWeaponUnpackSequence(self) end, @@ -25,19 +37,21 @@ UAB2305 = ClassUnit(AStructureUnit) { OnStopBeingBuilt = function(self, builder, layer) AStructureUnit.OnStopBeingBuilt(self, builder, layer) local bp = self.Blueprint - self.Trash:Add(CreateAnimator(self):PlayAnim(bp.Display.AnimationOpen)) - self.Trash:Add(ForkThread(self.PlayArmSounds,self)) + local trash = self.Trash + + TrashBagAdd(trash, CreateAnimator(self):PlayAnim(bp.Display.AnimationOpen)) + TrashBagAdd(trash, ForkThread(self.PlayArmSounds,self)) end, PlayArmSounds = function(self) - local myBlueprint = self.Blueprint - if myBlueprint.Audio.Open and myBlueprint.Audio.Activate then + local activateSound = self.Blueprint.Audio.Activate + if activateSound then WaitTicks(48) - self:PlaySound(myBlueprint.Audio.Activate) + self:PlaySound(activateSound) WaitTicks(38) - self:PlaySound(myBlueprint.Audio.Activate) + self:PlaySound(activateSound) WaitTicks(39) - self:PlaySound(myBlueprint.Audio.Activate) + self:PlaySound(activateSound) end end, } diff --git a/units/UAB3101/UAB3101_script.lua b/units/UAB3101/UAB3101_script.lua index 0fabeacd3e..a10c0aeed8 100644 --- a/units/UAB3101/UAB3101_script.lua +++ b/units/UAB3101/UAB3101_script.lua @@ -10,22 +10,34 @@ local ARadarUnit = import("/lua/aeonunits.lua").ARadarUnit +-- upvalaue for perfomance +local CreateRotator = CreateRotator +local TrashBagAdd = TrashBag.Add + ---@class UAB3101 : ARadarUnit -UAB3101 = ClassUnit(ARadarUnit) { +UAB3101 = ClassUnit(ARadarUnit) { + + ---@param self UAB3101 + ---@param intel any OnIntelDisabled = function(self, intel) ARadarUnit.OnIntelDisabled(self, intel) + self.Rotator1:SetSpinDown(true) end, OnIntelEnabled = function(self, intel) + local rotator = self.Rotator1 + local trash = self.Trash + ARadarUnit.OnIntelEnabled(self, intel) - if not self.Rotator1 then - self.Rotator1 = CreateRotator(self, 'B01', 'y') - self.Trash:Add(self.Rotator1) + if not rotator then + rotator = CreateRotator(self, 'B01', 'y') + TrashBagAdd(trash, rotator) + self.Rotator1 = rotator end - self.Rotator1:SetSpinDown(false) - self.Rotator1:SetTargetSpeed(30) - self.Rotator1:SetAccel(20) + rotator:SetSpinDown(false) + rotator:SetTargetSpeed(30) + rotator:SetAccel(20) end, } diff --git a/units/UAB3104/UAB3104_script.lua b/units/UAB3104/UAB3104_script.lua index 5549997535..d4e66c6328 100644 --- a/units/UAB3104/UAB3104_script.lua +++ b/units/UAB3104/UAB3104_script.lua @@ -10,11 +10,16 @@ local ARadarUnit = import("/lua/aeonunits.lua").ARadarUnit +-- upvalue for perfomance +local CreateRotator = CreateRotator +local TrashBagAdd = TrashBag.Add + ---@class UAB3104 : ARadarUnit UAB3104 = ClassUnit(ARadarUnit) { - + OnIntelDisabled = function(self, intel) ARadarUnit.OnIntelDisabled(self, intel) + self.Rotator1:SetSpinDown(true) self.Rotator2:SetSpinDown(true) self.Rotator3:SetSpinDown(true) @@ -23,30 +28,37 @@ UAB3104 = ClassUnit(ARadarUnit) { OnIntelEnabled = function(self, intel) ARadarUnit.OnIntelEnabled(self, intel) + local rotator1 = self.Rotator1 + local rotator2 = self.Rotator2 + local rotator3 = self.Rotator3 + local trash = self.Trash - if not self.Rotator1 then - self.Rotator1 = CreateRotator(self, 'B03', 'y') - self.Trash:Add(self.Rotator1) + if not rotator1 then + rotator1 = CreateRotator(self, 'B03', 'y') + TrashBagAdd(trash, rotator1) + self.Rotator1 = rotator1 end - self.Rotator1:SetSpinDown(false) - self.Rotator1:SetTargetSpeed(30) - self.Rotator1:SetAccel(20) + rotator1:SetSpinDown(false) + rotator1:SetTargetSpeed(30) + rotator1:SetAccel(20) - if not self.Rotator2 then - self.Rotator2 = CreateRotator(self, 'B02', 'y') - self.Trash:Add(self.Rotator2) + if not rotator2 then + rotator2 = CreateRotator(self, 'B02', 'y') + TrashBagAdd(trash, rotator2) + self.Rotator2 = rotator2 end - self.Rotator2:SetSpinDown(false) - self.Rotator2:SetTargetSpeed(60) - self.Rotator2:SetAccel(20) + rotator2:SetSpinDown(false) + rotator2:SetTargetSpeed(60) + rotator2:SetAccel(20) - if not self.Rotator3 then - self.Rotator3 = CreateRotator(self, 'B01', 'y') - self.Trash:Add(self.Rotator3) + if not rotator3 then + rotator3 = CreateRotator(self, 'B01', 'y') + TrashBagAdd(trash, rotator3) + self.Rotator3 = rotator3 end - self.Rotator3:SetSpinDown(false) - self.Rotator3:SetTargetSpeed(120) - self.Rotator3:SetAccel(20) + rotator3:SetSpinDown(false) + rotator3:SetTargetSpeed(120) + rotator3:SetAccel(20) end, } diff --git a/units/UAB3201/UAB3201_script.lua b/units/UAB3201/UAB3201_script.lua index cb2e4e0974..3f6735b5e6 100644 --- a/units/UAB3201/UAB3201_script.lua +++ b/units/UAB3201/UAB3201_script.lua @@ -10,37 +10,48 @@ local ARadarUnit = import("/lua/aeonunits.lua").ARadarUnit +-- upvalue for performance +local CreateRotator = CreateRotator +local TrashBagAdd = TrashBag.Add + ---@class UAB3201 : ARadarUnit UAB3201 = ClassUnit(ARadarUnit) { OnIntelDisabled = function(self, intel) ARadarUnit.OnIntelDisabled(self, intel) - self.Rotator1:SetSpinDown(true) - self.Rotator1:SetAccel(60) - self.Rotator2:SetSpinDown(true) - self.Rotator2:SetAccel(60) + local rotator1 = self.Rotator1 + local rotator2 = self.Rotator2 + + rotator1:SetSpinDown(true) + rotator1:SetAccel(60) + rotator2:SetSpinDown(true) + rotator2:SetAccel(60) end, OnIntelEnabled = function(self, intel) ARadarUnit.OnIntelEnabled(self, intel) - - if not self.Rotator1 then - self.Rotator1 = CreateRotator(self, 'B02', 'y') - self.Trash:Add(self.Rotator1) - end - self.Rotator1:SetSpinDown(false) - self.Rotator1:SetTargetSpeed(30) - self.Rotator1:SetAccel(20) - - - if not self.Rotator2 then - self.Rotator2 = CreateRotator(self, 'B01', 'y') - self.Trash:Add(self.Rotator2) + local rotator1 = self.Rotator1 + local rotator2 = self.Rotator2 + local trash = self.Trash + + if not rotator1 then + rotator1 = CreateRotator(self, 'B02', 'y') + TrashBagAdd(trash, rotator1) + self.Rotator1 = rotator1 + end + rotator1:SetSpinDown(false) + rotator1:SetTargetSpeed(30) + rotator1:SetAccel(20) + + if not rotator2 then + rotator2 = CreateRotator(self, 'B01', 'y') + TrashBagAdd(trash,rotator2) + self.Rotator2 = rotator2 end - self.Rotator2:SetSpinDown(false) - self.Rotator2:SetTargetSpeed(60) - self.Rotator2:SetAccel(20) + rotator2:SetSpinDown(false) + rotator2:SetTargetSpeed(60) + rotator2:SetAccel(20) end, } diff --git a/units/UAB4201/UAB4201_script.lua b/units/UAB4201/UAB4201_script.lua index 7f10485973..8f9a99a875 100644 --- a/units/UAB4201/UAB4201_script.lua +++ b/units/UAB4201/UAB4201_script.lua @@ -11,20 +11,29 @@ local AStructureUnit = import("/lua/aeonunits.lua").AStructureUnit local AAMWillOWisp = import("/lua/aeonweapons.lua").AAMWillOWisp +-- upvalue for perfomance +local CreateRotator = CreateRotator +local TrashBagAdd = TrashBag.Add + + ---@class UAB4201 : AStructureUnit UAB4201 = ClassUnit(AStructureUnit) { Weapons = { AntiMissile = ClassWeapon(AAMWillOWisp) { PlayRackRecoil = function(self, rackList) AAMWillOWisp.PlayRackRecoil(self, rackList) + + local unit = self.unit + local rotatorManipulator = self.RotatorManipulator + --CreateRotator(unit, bone, axis, [goal], [speed], [accel], [goalspeed]) - if not self.RotatorManipulator then - self.RotatorManipulator = CreateRotator(self.unit, 'Dome', 'z', 20, 40, 40, 40) - self.RotatorManipulator:SetGoal(45) + if not rotatorManipulator then + rotatorManipulator = CreateRotator(unit, 'Dome', 'z', 20, 40, 40, 40) + rotatorManipulator:SetGoal(45) self.RotatorManipulatorCounter = 1 else self.RotatorManipulatorCounter = self.RotatorManipulatorCounter + 1 - self.RotatorManipulator:SetGoal(45 * self.RotatorManipulatorCounter) + rotatorManipulator:SetGoal(45 * self.RotatorManipulatorCounter) end self.unit.Trash:Add(self.RotatorManipulator) end, diff --git a/units/UAB4202/UAB4202_script.lua b/units/UAB4202/UAB4202_script.lua index 6e75196e04..46e4f6353d 100644 --- a/units/UAB4202/UAB4202_script.lua +++ b/units/UAB4202/UAB4202_script.lua @@ -10,6 +10,10 @@ local AShieldStructureUnit = import("/lua/aeonunits.lua").AShieldStructureUnit local ShieldEffectsComponent = import("/lua/defaultcomponents.lua").ShieldEffectsComponent +-- upvalue for perfomance +local TrashBagAdd = TrashBag.Add + + ---@class UAB4202 : AShieldStructureUnit UAB4202 = ClassUnit(AShieldStructureUnit, ShieldEffectsComponent) { @@ -30,46 +34,41 @@ UAB4202 = ClassUnit(AShieldStructureUnit, ShieldEffectsComponent) { AShieldStructureUnit.OnShieldEnabled(self) ShieldEffectsComponent.OnShieldEnabled(self) - if not self.OrbManip1 then - self.OrbManip1 = CreateRotator(self, 'Orb', 'x', nil, 0, 45, -45) - self.Trash:Add(self.OrbManip1) - end + local trash = self.Trash - self.OrbManip1:SetTargetSpeed(-45) - - if not self.OrbManip2 then - self.OrbManip2 = CreateRotator(self, 'Orb', 'z', nil, 0, 45, 45) - self.Trash:Add(self.OrbManip2) + local orbManip1 = self.OrbManip1 + if not orbManip1 then + orbManip1 = CreateRotator(self, 'Orb', '-x', nil, 0, 45, 45) + TrashBagAdd(trash, orbManip1) + self.OrbManip1 = orbManip1 + else + orbManip1:SetSpinDown(false) + orbManip1:SetTargetSpeed(45) end - self.OrbManip2:SetTargetSpeed(45) + local orbManip2 = self.OrbManip2 + if not orbManip2 then + orbManip2 = CreateRotator(self, 'Orb', 'z', nil, 0, 45, 45) + TrashBagAdd(trash, orbManip2) + self.OrbManip2 = orbManip2 + else + orbManip2:SetSpinDown(false) + orbManip2:SetTargetSpeed(45) + end end, OnShieldDisabled = function(self) AShieldStructureUnit.OnShieldDisabled(self) ShieldEffectsComponent.OnShieldDisabled(self) - if self.OrbManip1 then - self.OrbManip1:SetSpinDown(true) - self.OrbManip1:SetTargetSpeed(0) - end - - if self.OrbManip2 then - self.OrbManip2:SetSpinDown(true) - self.OrbManip2:SetTargetSpeed(0) - end - end, - - OnKilled = function(self, instigator, type, overkillRatio) - AShieldStructureUnit.OnKilled(self, instigator, type, overkillRatio) - if self.OrbManip1 then - self.OrbManip1:Destroy() - self.OrbManip1 = nil + local orbManip1 = self.OrbManip1 + if orbManip1 then + orbManip1:SetSpinDown(true) end - if self.OrbManip2 then - self.OrbManip2:Destroy() - self.OrbManip2 = nil + local orbManip2 = self.OrbManip2 + if orbManip2 then + orbManip2:SetSpinDown(true) end end, } diff --git a/units/XSL0402/XSL0402_script.lua b/units/XSL0402/XSL0402_script.lua index 283b76b473..3eb667b3af 100644 --- a/units/XSL0402/XSL0402_script.lua +++ b/units/XSL0402/XSL0402_script.lua @@ -32,4 +32,4 @@ XSL0402 = ClassUnit(SEnergyBallUnit) { end, } -TypeClass = XSL0402 \ No newline at end of file +TypeClass = XSL0402