From 2953c0afab0a8e9a8055fb8e28be0d11d9dc8b67 Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 31 Oct 2024 16:32:06 +0000 Subject: [PATCH 01/13] Cybran Script Update - Added Snipet - Added Annotaions - Added Script Changes --- changelog/snippets/other.6503.md | 1 + units/URL0001/URL0001_script.lua | 621 ++++++++++++++++++------------- 2 files changed, 366 insertions(+), 256 deletions(-) create mode 100644 changelog/snippets/other.6503.md diff --git a/changelog/snippets/other.6503.md b/changelog/snippets/other.6503.md new file mode 100644 index 0000000000..4f8b4e9002 --- /dev/null +++ b/changelog/snippets/other.6503.md @@ -0,0 +1 @@ +- (#6503) Refactor the Enhancement section in the Cybran unit script file to replace the long if/else chain with a more modular design. Each enhancement should have its own dedicated function, enabling cleaner code organization and easier maintenance. The CreateEnhancement function will then call the appropriate enhancement function based on specific enhancement criteria. diff --git a/units/URL0001/URL0001_script.lua b/units/URL0001/URL0001_script.lua index a84201fff8..c8908137bf 100644 --- a/units/URL0001/URL0001_script.lua +++ b/units/URL0001/URL0001_script.lua @@ -31,6 +31,7 @@ local CDFOverchargeWeapon = CWeapons.CDFOverchargeWeapon local CANTorpedoLauncherWeapon = CWeapons.CANTorpedoLauncherWeapon local Entity = import("/lua/sim/entity.lua").Entity +---@class URL0001 : ACUUnit, CCommandUnit URL0001 = ClassUnit(ACUUnit, CCommandUnit) { Weapons = { DeathWeapon = ClassWeapon(ACUDeathWeapon) {}, @@ -57,10 +58,13 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { AutoOverCharge = ClassWeapon(CDFOverchargeWeapon) {}, }, + ---@param self URL0001 __init = function(self) ACUUnit.__init(self, 'RightRipper') end, + --- + ---@param self URL0001 OnCreate = function(self) ACUUnit.OnCreate(self) CCommandUnit.OnCreate(self) @@ -85,6 +89,9 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end end, + ---@param self URL0001 + ---@param builder Unit + ---@param layer Layer OnStopBeingBuilt = function(self, builder, layer) ACUUnit.OnStopBeingBuilt(self, builder, layer) self:SetWeaponEnabledByLabel('RightRipper', true) @@ -100,6 +107,9 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { self.Trash:Add(ForkThread(self.GiveInitialResources,self)) end, + ---@param self URL0001 + ---@param unitBeingBuilt Unit + ---@param order string OnStartBuild = function(self, unitBeingBuilt, order) ACUUnit.OnStartBuild(self, unitBeingBuilt, order) self.UnitBeingBuilt = unitBeingBuilt @@ -107,274 +117,366 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { self.BuildingUnit = true end, - CreateEnhancement = function(self, enh) - ACUUnit.CreateEnhancement(self, enh) - local bp = self.Blueprint.Enhancements[enh] - if enh == 'Teleporter' then - self:AddCommandCap('RULEUCC_Teleport') - elseif enh == 'TeleporterRemove' then - RemoveUnitEnhancement(self, 'Teleporter') - RemoveUnitEnhancement(self, 'TeleporterRemove') - self:RemoveCommandCap('RULEUCC_Teleport') - elseif enh == 'StealthGenerator' then - self:AddToggleCap('RULEUTC_StealthToggle') - self.StealthEnh = true - self:EnableUnitIntel('Enhancement', 'RadarStealth') - self:EnableUnitIntel('Enhancement', 'SonarStealth') - if not Buffs['CybranACUStealthBonus'] then - BuffBlueprint { - Name = 'CybranACUStealthBonus', - DisplayName = 'CybranACUStealthBonus', - BuffType = 'ACUSTEALTHBONUS', - Stacks = 'ALWAYS', - Duration = -1, - Affects = { - MaxHealth = { - Add = bp.NewHealth, - Mult = 1.0, - }, - Regen = { - Add = bp.NewRegenRate, - Mult = 1.0, - } + --====================================================================================================== + -- Enhancements + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementTeleporter = function(self, bp) + self:AddCommandCap('RULEUCC_Teleport') + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementTeleporterRemove = function(self, bp) + RemoveUnitEnhancement(self, 'Teleporter') + RemoveUnitEnhancement(self, 'TeleporterRemove') + self:RemoveCommandCap('RULEUCC_Teleport') + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementStealthGenerator = function(self, bp) + self:AddToggleCap('RULEUTC_StealthToggle') + self.StealthEnh = true + self:EnableUnitIntel('Enhancement', 'RadarStealth') + self:EnableUnitIntel('Enhancement', 'SonarStealth') + if not Buffs['CybranACUStealthBonus'] then + BuffBlueprint { + Name = 'CybranACUStealthBonus', + DisplayName = 'CybranACUStealthBonus', + BuffType = 'ACUSTEALTHBONUS', + Stacks = 'ALWAYS', + Duration = -1, + Affects = { + MaxHealth = { + Add = bp.NewHealth, + Mult = 1.0, }, - } - end - if not Buff.HasBuff(self, 'CybranACUStealthBonus') then - Buff.ApplyBuff(self, 'CybranACUStealthBonus') - end - elseif enh == 'StealthGeneratorRemove' then - self:RemoveToggleCap('RULEUTC_StealthToggle') - self:DisableUnitIntel('Enhancement', 'RadarStealth') - self:DisableUnitIntel('Enhancement', 'SonarStealth') - self.StealthEnh = nil - if Buff.HasBuff(self, 'CybranACUStealthBonus') then - Buff.RemoveBuff(self, 'CybranACUStealthBonus') - end - elseif enh == 'FAF_SelfRepairSystem' then - if not Buffs['CybranACURegenerateBonus'] then - BuffBlueprint { - Name = 'CybranACURegenerateBonus', - DisplayName = 'CybranACURegenerateBonus', - BuffType = 'ACUNANO', - Stacks = 'ALWAYS', - Duration = -1, - Affects = { - MaxHealth = { - Add = bp.NewHealth, - Mult = 1.0, - }, - Regen = { - Add = bp.NewRegenRate, - Mult = 1.0, - } + Regen = { + Add = bp.NewRegenRate, + Mult = 1.0, + } + }, + } + end + if not Buff.HasBuff(self, 'CybranACUStealthBonus') then + Buff.ApplyBuff(self, 'CybranACUStealthBonus') + end + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementStealthGeneratorRemove = function(self, bp) + self:RemoveToggleCap('RULEUTC_StealthToggle') + self:DisableUnitIntel('Enhancement', 'RadarStealth') + self:DisableUnitIntel('Enhancement', 'SonarStealth') + self.StealthEnh = nil + if Buff.HasBuff(self, 'CybranACUStealthBonus') then + Buff.RemoveBuff(self, 'CybranACUStealthBonus') + end + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementFAF_SelfRepairSystem = function(self, bp) + if not Buffs['CybranACURegenerateBonus'] then + BuffBlueprint { + Name = 'CybranACURegenerateBonus', + DisplayName = 'CybranACURegenerateBonus', + BuffType = 'ACUNANO', + Stacks = 'ALWAYS', + Duration = -1, + Affects = { + MaxHealth = { + Add = bp.NewHealth, + Mult = 1.0, }, - } - end - if not Buff.HasBuff(self, 'CybranACURegenerateBonus') then - Buff.ApplyBuff(self, 'CybranACURegenerateBonus') - end - elseif enh == 'FAF_SelfRepairSystemRemove' then - -- remove prerequisites - self:RemoveToggleCap('RULEUTC_StealthToggle') - self:DisableUnitIntel('Enhancement', 'RadarStealth') - self:DisableUnitIntel('Enhancement', 'SonarStealth') - self.StealthEnh = nil - if Buff.HasBuff(self, 'CybranACUStealthBonus') then - Buff.RemoveBuff(self, 'CybranACUStealthBonus') - end + Regen = { + Add = bp.NewRegenRate, + Mult = 1.0, + } + }, + } + end + if not Buff.HasBuff(self, 'CybranACURegenerateBonus') then + Buff.ApplyBuff(self, 'CybranACURegenerateBonus') + end + end, - -- remove repair system - if Buff.HasBuff(self, 'CybranACURegenerateBonus') then - Buff.RemoveBuff(self, 'CybranACURegenerateBonus') - end - elseif enh == 'CloakingGenerator' then - if not bp then return end - self:RemoveToggleCap('RULEUTC_StealthToggle') - self:AddToggleCap('RULEUTC_CloakToggle') - self.StealthEnh = nil - self.CloakEnh = true - self:EnableUnitIntel('Enhancement', 'Cloak') - if not Buffs['CybranACUCloakBonus'] then - BuffBlueprint { - Name = 'CybranACUCloakBonus', - DisplayName = 'CybranACUCloakBonus', - BuffType = 'ACUCLOAKBONUS', - Stacks = 'ALWAYS', - Duration = -1, - Affects = { - MaxHealth = { - Add = bp.NewHealth, - Mult = 1.0, - }, + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementFAF_SelfRepairSystemRemove = function(self, bp) + -- remove prerequisites + self:RemoveToggleCap('RULEUTC_StealthToggle') + self:DisableUnitIntel('Enhancement', 'RadarStealth') + self:DisableUnitIntel('Enhancement', 'SonarStealth') + self.StealthEnh = nil + if Buff.HasBuff(self, 'CybranACUStealthBonus') then + Buff.RemoveBuff(self, 'CybranACUStealthBonus') + end + + -- remove repair system + if Buff.HasBuff(self, 'CybranACURegenerateBonus') then + Buff.RemoveBuff(self, 'CybranACURegenerateBonus') + end + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementCloakingGenerator = function(self, bp) + if not bp then return end + self:RemoveToggleCap('RULEUTC_StealthToggle') + self:AddToggleCap('RULEUTC_CloakToggle') + self.StealthEnh = nil + self.CloakEnh = true + self:EnableUnitIntel('Enhancement', 'Cloak') + if not Buffs['CybranACUCloakBonus'] then + BuffBlueprint { + Name = 'CybranACUCloakBonus', + DisplayName = 'CybranACUCloakBonus', + BuffType = 'ACUCLOAKBONUS', + Stacks = 'ALWAYS', + Duration = -1, + Affects = { + MaxHealth = { + Add = bp.NewHealth, + Mult = 1.0, }, - } - end - if not Buff.HasBuff(self, 'CybranACUCloakBonus') then - Buff.ApplyBuff(self, 'CybranACUCloakBonus') - end - elseif enh == 'CloakingGeneratorRemove' then - -- remove prerequisites - self:RemoveToggleCap('RULEUTC_CloakToggle') - self:DisableUnitIntel('Enhancement', 'RadarStealth') - self:DisableUnitIntel('Enhancement', 'SonarStealth') - self.StealthEnh = nil - if Buff.HasBuff(self, 'CybranACUStealthBonus') then - Buff.RemoveBuff(self, 'CybranACUStealthBonus') - end - if Buff.HasBuff(self, 'CybranACURegenerateBonus') then - Buff.RemoveBuff(self, 'CybranACURegenerateBonus') - end + }, + } + end + if not Buff.HasBuff(self, 'CybranACUCloakBonus') then + Buff.ApplyBuff(self, 'CybranACUCloakBonus') + end + end, - -- remove cloak - self:RemoveToggleCap('RULEUTC_CloakToggle') - self:DisableUnitIntel('Enhancement', 'Cloak') - self.CloakEnh = nil - if Buff.HasBuff(self, 'CybranACUCloakBonus') then - Buff.RemoveBuff(self, 'CybranACUCloakBonus') - end - elseif enh == 'ResourceAllocation' then - local bpEcon = self.Blueprint.Economy - if not bp then return end - self:SetProductionPerSecondEnergy((bp.ProductionPerSecondEnergy + bpEcon.ProductionPerSecondEnergy) or 0) - self:SetProductionPerSecondMass((bp.ProductionPerSecondMass + bpEcon.ProductionPerSecondMass) or 0) - elseif enh == 'ResourceAllocationRemove' then - local bpEcon = self.Blueprint.Economy - self:SetProductionPerSecondEnergy(bpEcon.ProductionPerSecondEnergy or 0) - self:SetProductionPerSecondMass(bpEcon.ProductionPerSecondMass or 0) - elseif enh =='AdvancedEngineering' then - self.BuildBotTotal = 3 - if not bp then return end - local cat = ParseEntityCategory(bp.BuildableCategoryAdds) - self:RemoveBuildRestriction(cat) - if not Buffs['CybranACUT2BuildRate'] then - BuffBlueprint { - Name = 'CybranACUT2BuildRate', - DisplayName = 'CybranACUT2BuildRate', - BuffType = 'ACUBUILDRATE', - Stacks = 'REPLACE', - Duration = -1, - Affects = { - BuildRate = { - Add = bp.NewBuildRate - self.Blueprint.Economy.BuildRate, - Mult = 1.0, - }, - MaxHealth = { - Add = bp.NewHealth, - Mult = 1.0, - }, - Regen = { - Add = bp.NewRegenRate, - Mult = 1.0, - }, + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementCloakingGeneratorRemove = function(self, bp) + -- remove prerequisites + self:RemoveToggleCap('RULEUTC_CloakToggle') + self:DisableUnitIntel('Enhancement', 'RadarStealth') + self:DisableUnitIntel('Enhancement', 'SonarStealth') + self.StealthEnh = nil + if Buff.HasBuff(self, 'CybranACUStealthBonus') then + Buff.RemoveBuff(self, 'CybranACUStealthBonus') + end + if Buff.HasBuff(self, 'CybranACURegenerateBonus') then + Buff.RemoveBuff(self, 'CybranACURegenerateBonus') + end + + -- remove cloak + self:RemoveToggleCap('RULEUTC_CloakToggle') + self:DisableUnitIntel('Enhancement', 'Cloak') + self.CloakEnh = nil + if Buff.HasBuff(self, 'CybranACUCloakBonus') then + Buff.RemoveBuff(self, 'CybranACUCloakBonus') + end + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementResourceAllocation = function(self, bp) + local bpEcon = self.Blueprint.Economy + if not bp then return end + self:SetProductionPerSecondEnergy((bp.ProductionPerSecondEnergy + bpEcon.ProductionPerSecondEnergy) or 0) + self:SetProductionPerSecondMass((bp.ProductionPerSecondMass + bpEcon.ProductionPerSecondMass) or 0) + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementResourceAllocationRemove = function(self, bp) + local bpEcon = self.Blueprint.Economy + self:SetProductionPerSecondEnergy(bpEcon.ProductionPerSecondEnergy or 0) + self:SetProductionPerSecondMass(bpEcon.ProductionPerSecondMass or 0) + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementAdvancedEngineering = function(self, bp) + self.BuildBotTotal = 3 + if not bp then return end + local cat = ParseEntityCategory(bp.BuildableCategoryAdds) + self:RemoveBuildRestriction(cat) + if not Buffs['CybranACUT2BuildRate'] then + BuffBlueprint { + Name = 'CybranACUT2BuildRate', + DisplayName = 'CybranACUT2BuildRate', + BuffType = 'ACUBUILDRATE', + Stacks = 'REPLACE', + Duration = -1, + Affects = { + BuildRate = { + Add = bp.NewBuildRate - self.Blueprint.Economy.BuildRate, + Mult = 1.0, }, - } - end - Buff.ApplyBuff(self, 'CybranACUT2BuildRate') - elseif enh == 'AdvancedEngineeringRemove' then - self.BuildBotTotal = 2 - local buildRate = self.Blueprint.Economy.BuildRate - if not buildRate then return end - self:RestoreBuildRestrictions() - self:AddBuildRestriction(categories.CYBRAN * - (categories.BUILTBYTIER2COMMANDER + categories.BUILTBYTIER3COMMANDER)) - if Buff.HasBuff(self, 'CybranACUT2BuildRate') then - Buff.RemoveBuff(self, 'CybranACUT2BuildRate') - end - elseif enh =='T3Engineering' then - self.BuildBotTotal = 4 - if not bp then return end - local cat = ParseEntityCategory(bp.BuildableCategoryAdds) - self:RemoveBuildRestriction(cat) - if not Buffs['CybranACUT3BuildRate'] then - BuffBlueprint { - Name = 'CybranACUT3BuildRate', - DisplayName = 'CybranCUT3BuildRate', - BuffType = 'ACUBUILDRATE', - Stacks = 'REPLACE', - Duration = -1, - Affects = { - BuildRate = { - Add = bp.NewBuildRate - self.Blueprint.Economy.BuildRate, - Mult = 1.0, - }, - MaxHealth = { - Add = bp.NewHealth, - Mult = 1.0, - }, - Regen = { - Add = bp.NewRegenRate, - Mult = 1.0, - }, + MaxHealth = { + Add = bp.NewHealth, + Mult = 1.0, }, - } - end - Buff.ApplyBuff(self, 'CybranACUT3BuildRate') - elseif enh == 'T3EngineeringRemove' then + Regen = { + Add = bp.NewRegenRate, + Mult = 1.0, + }, + }, + } + end + Buff.ApplyBuff(self, 'CybranACUT2BuildRate') + end, - self.BuildBotTotal = 2 + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementAdvancedEngineeringRemove = function(self, bp) + self.BuildBotTotal = 2 + local buildRate = self.Blueprint.Economy.BuildRate + if not buildRate then return end + self:RestoreBuildRestrictions() + self:AddBuildRestriction(categories.CYBRAN * + (categories.BUILTBYTIER2COMMANDER + categories.BUILTBYTIER3COMMANDER)) + if Buff.HasBuff(self, 'CybranACUT2BuildRate') then + Buff.RemoveBuff(self, 'CybranACUT2BuildRate') + end + end, - local buildRate = self.Blueprint.Economy.BuildRate - if not buildRate then return end - self:RestoreBuildRestrictions() - if Buff.HasBuff(self, 'CybranACUT3BuildRate') then - Buff.RemoveBuff(self, 'CybranACUT3BuildRate') - end - self:AddBuildRestriction(categories.CYBRAN * (categories.BUILTBYTIER2COMMANDER + categories.BUILTBYTIER3COMMANDER)) - elseif enh =='CoolingUpgrade' then - local wep = self:GetWeaponByLabel('RightRipper') - wep:ChangeMaxRadius(bp.NewMaxRadius or 30) - self.normalRange = bp.NewMaxRadius or 30 - wep:ChangeRateOfFire(bp.NewRateOfFire or 2) - local microwave = self:GetWeaponByLabel('MLG') - microwave:ChangeMaxRadius(bp.NewMaxRadius or 30) - local oc = self:GetWeaponByLabel('OverCharge') - oc:ChangeMaxRadius(bp.NewMaxRadius or 30) - local aoc = self:GetWeaponByLabel('AutoOverCharge') - aoc:ChangeMaxRadius(bp.NewMaxRadius or 30) - if not (self.Layer == 'Seabed' and self:HasEnhancement('NaniteTorpedoTube')) then - self:GetWeaponByLabel('DummyWeapon'):ChangeMaxRadius(self.normalRange) - end - elseif enh == 'CoolingUpgradeRemove' then - local wep = self:GetWeaponByLabel('RightRipper') - local wepBp = self.Blueprint.Weapon - for _, v in wepBp do - if v.Label == 'RightRipper' then - local newRange = v.MaxRadius or 22 - wep:ChangeRateOfFire(v.RateOfFire or 1) - wep:ChangeMaxRadius(newRange) - self.normalRange = newRange - self:GetWeaponByLabel('MLG'):ChangeMaxRadius(newRange) - self:GetWeaponByLabel('OverCharge'):ChangeMaxRadius(newRange) - self:GetWeaponByLabel('AutoOverCharge'):ChangeMaxRadius(newRange) - self.normalRange = newRange - if not (self.Layer == 'Seabed' and self:HasEnhancement('NaniteTorpedoTube')) then - self:GetWeaponByLabel('DummyWeapon'):ChangeMaxRadius(self.normalRange) - end - break + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementT3Engineering = function(self, bp) + self.BuildBotTotal = 4 + if not bp then return end + local cat = ParseEntityCategory(bp.BuildableCategoryAdds) + self:RemoveBuildRestriction(cat) + if not Buffs['CybranACUT3BuildRate'] then + BuffBlueprint { + Name = 'CybranACUT3BuildRate', + DisplayName = 'CybranCUT3BuildRate', + BuffType = 'ACUBUILDRATE', + Stacks = 'REPLACE', + Duration = -1, + Affects = { + BuildRate = { + Add = bp.NewBuildRate - self.Blueprint.Economy.BuildRate, + Mult = 1.0, + }, + MaxHealth = { + Add = bp.NewHealth, + Mult = 1.0, + }, + Regen = { + Add = bp.NewRegenRate, + Mult = 1.0, + }, + }, + } + end + Buff.ApplyBuff(self, 'CybranACUT3BuildRate') + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementT3EngineeringRemove = function(self, bp) + self.BuildBotTotal = 2 + local buildRate = self.Blueprint.Economy.BuildRate + if not buildRate then return end + self:RestoreBuildRestrictions() + if Buff.HasBuff(self, 'CybranACUT3BuildRate') then + Buff.RemoveBuff(self, 'CybranACUT3BuildRate') + end + self:AddBuildRestriction(categories.CYBRAN * (categories.BUILTBYTIER2COMMANDER + categories.BUILTBYTIER3COMMANDER)) + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementCoolingUpgrade = function(self, bp) + local wep = self:GetWeaponByLabel('RightRipper') + wep:ChangeMaxRadius(bp.NewMaxRadius or 30) + self.normalRange = bp.NewMaxRadius or 30 + wep:ChangeRateOfFire(bp.NewRateOfFire or 2) + local microwave = self:GetWeaponByLabel('MLG') + microwave:ChangeMaxRadius(bp.NewMaxRadius or 30) + local oc = self:GetWeaponByLabel('OverCharge') + oc:ChangeMaxRadius(bp.NewMaxRadius or 30) + local aoc = self:GetWeaponByLabel('AutoOverCharge') + aoc:ChangeMaxRadius(bp.NewMaxRadius or 30) + if not (self.Layer == 'Seabed' and self:HasEnhancement('NaniteTorpedoTube')) then + self:GetWeaponByLabel('DummyWeapon'):ChangeMaxRadius(self.normalRange) + end + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementCoolingUpgradeRemove = function(self, bp) + local wep = self:GetWeaponByLabel('RightRipper') + local wepBp = self.Blueprint.Weapon + for _, v in wepBp do + if v.Label == 'RightRipper' then + local newRange = v.MaxRadius or 22 + wep:ChangeRateOfFire(v.RateOfFire or 1) + wep:ChangeMaxRadius(newRange) + self.normalRange = newRange + self:GetWeaponByLabel('MLG'):ChangeMaxRadius(newRange) + self:GetWeaponByLabel('OverCharge'):ChangeMaxRadius(newRange) + self:GetWeaponByLabel('AutoOverCharge'):ChangeMaxRadius(newRange) + self.normalRange = newRange + if not (self.Layer == 'Seabed' and self:HasEnhancement('NaniteTorpedoTube')) then + self:GetWeaponByLabel('DummyWeapon'):ChangeMaxRadius(self.normalRange) end + break end - elseif enh == 'MicrowaveLaserGenerator' then - self:SetWeaponEnabledByLabel('MLG', true) - elseif enh == 'MicrowaveLaserGeneratorRemove' then - self:SetWeaponEnabledByLabel('MLG', false) - elseif enh == 'NaniteTorpedoTube' then - local enhbp = self.Blueprint.Enhancements[enh] - self:SetWeaponEnabledByLabel('Torpedo', true) - self:SetIntelRadius('Sonar', enhbp.NewSonarRadius or 60) - self:EnableUnitIntel('Enhancement', 'Sonar') - if self.Layer == 'Seabed' then - self:GetWeaponByLabel('DummyWeapon'):ChangeMaxRadius(self.torpRange) - end - elseif enh == 'NaniteTorpedoTubeRemove' then - local bpIntel = self.Blueprint.Intel - self:SetWeaponEnabledByLabel('Torpedo', false) - self:SetIntelRadius('Sonar', bpIntel.SonarRadius or 26) - self:DisableUnitIntel('Enhancement', 'Sonar') - if self.Layer == 'Seabed' then - self:GetWeaponByLabel('DummyWeapon'):ChangeMaxRadius(self.normalRange) - end + end + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementMicrowaveLaserGenerator = function(self, bp) + self:SetWeaponEnabledByLabel('MLG', true) + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementMicrowaveLaserGeneratorRemove = function(self, bp) + self:SetWeaponEnabledByLabel('MLG', false) + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementNaniteTorpedoTube = function(self, bp) + self:SetWeaponEnabledByLabel('Torpedo', true) + self:SetIntelRadius('Sonar', bp.NewSonarRadius or 60) + self:EnableUnitIntel('Enhancement', 'Sonar') + if self.Layer == 'Seabed' then + self:GetWeaponByLabel('DummyWeapon'):ChangeMaxRadius(self.torpRange) + end + end, + + ---@param self URL0001 + ---@param bp Blueprint + ProcessEnhancementNaniteTorpedoTubeRemove = function(self, bp) + local bpIntel = self.Blueprint.Intel + self:SetWeaponEnabledByLabel('Torpedo', false) + self:SetIntelRadius('Sonar', bpIntel.SonarRadius or 26) + self:DisableUnitIntel('Enhancement', 'Sonar') + if self.Layer == 'Seabed' then + self:GetWeaponByLabel('DummyWeapon'):ChangeMaxRadius(self.normalRange) + end + end, + + ---@param self URL0001 + ---@param enh CybranACUEnhancementBuffType + CreateEnhancement = function(self, enh) + ACUUnit.CreateEnhancement(self, enh) + + local bp = self.Blueprint.Enhancements[enh] + + if not bp then return end + + local ref = 'ProcessEnhancement' .. enh + local handler = self[ref] + if handler then + handler(self, bp) + else + WARN("Missing enhancement: ", enh, " for unit: ", self:GetUnitId(), " note that the function name should be called: ", ref) end end, @@ -424,6 +526,8 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { }, }, + ---@param self URL0001 + ---@param intel string OnIntelEnabled = function(self, intel) ACUUnit.OnIntelEnabled(self, intel) if self.CloakEnh and self:IsIntelEnabled('Cloak') then @@ -445,6 +549,8 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end end, + ---@param self URL0001 + ---@param intel string OnIntelDisabled = function(self, intel) ACUUnit.OnIntelDisabled(self, intel) if self.IntelEffectsBag then @@ -458,6 +564,9 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end end, + ---@param self URL0001 + ---@param new any + ---@param old any OnLayerChange = function(self, new, old) ACUUnit.OnLayerChange(self, new, old) if self:GetWeaponByLabel('DummyWeapon') == nil then return end From ecc85e776fbec964b3bb39e08007f48788bb1be9 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Wed, 6 Nov 2024 02:47:46 -0800 Subject: [PATCH 02/13] Condense snippet into 6498's snippet --- changelog/snippets/other.6498.md | 2 +- changelog/snippets/other.6503.md | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 changelog/snippets/other.6503.md diff --git a/changelog/snippets/other.6498.md b/changelog/snippets/other.6498.md index 237a2857b1..ff37651b8c 100644 --- a/changelog/snippets/other.6498.md +++ b/changelog/snippets/other.6498.md @@ -1 +1 @@ -- (#6498, #6502) Refactor the Enhancements section in the ACU/SACU scripts to replace the long if/else chain with a more modular design that is easier to maintain and hook. Each enhancement has its own dedicated function, named with the format `ProcessEnhancement[EnhancementName]`. The CreateEnhancement function now calls the appropriate enhancement function automatically by that name format. +- (#6498, #6502, #6503) Refactor the Enhancements section in the ACU/SACU scripts to replace the long if/else chain with a more modular design that is easier to maintain and hook. Each enhancement has its own dedicated function, named with the format `ProcessEnhancement[EnhancementName]`. The CreateEnhancement function now calls the appropriate enhancement function automatically by that name format. diff --git a/changelog/snippets/other.6503.md b/changelog/snippets/other.6503.md deleted file mode 100644 index 4f8b4e9002..0000000000 --- a/changelog/snippets/other.6503.md +++ /dev/null @@ -1 +0,0 @@ -- (#6503) Refactor the Enhancement section in the Cybran unit script file to replace the long if/else chain with a more modular design. Each enhancement should have its own dedicated function, enabling cleaner code organization and easier maintenance. The CreateEnhancement function will then call the appropriate enhancement function based on specific enhancement criteria. From a888de068eec50c241fcc72aa7fd98d5242760c1 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Wed, 6 Nov 2024 02:49:44 -0800 Subject: [PATCH 03/13] Apply formatter (fix whitespace) --- units/URL0001/URL0001_script.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/units/URL0001/URL0001_script.lua b/units/URL0001/URL0001_script.lua index c8908137bf..f4211ecd4d 100644 --- a/units/URL0001/URL0001_script.lua +++ b/units/URL0001/URL0001_script.lua @@ -42,7 +42,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { SetOnTransport = function(self, transportstate) CDFHeavyMicrowaveLaserGeneratorCom.SetOnTransport(self, transportstate) - self.Trash:Add(ForkThread(self.OnTransportWatch,self)) + self.Trash:Add(ForkThread(self.OnTransportWatch, self)) end, OnTransportWatch = function(self) @@ -104,7 +104,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { self:DisableUnitIntel('Enhancement', 'Sonar') self:HideBone('Back_Upgrade', true) self:HideBone('Right_Upgrade', true) - self.Trash:Add(ForkThread(self.GiveInitialResources,self)) + self.Trash:Add(ForkThread(self.GiveInitialResources, self)) end, ---@param self URL0001 @@ -309,7 +309,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { Duration = -1, Affects = { BuildRate = { - Add = bp.NewBuildRate - self.Blueprint.Economy.BuildRate, + Add = bp.NewBuildRate - self.Blueprint.Economy.BuildRate, Mult = 1.0, }, MaxHealth = { @@ -356,7 +356,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { Duration = -1, Affects = { BuildRate = { - Add = bp.NewBuildRate - self.Blueprint.Economy.BuildRate, + Add = bp.NewBuildRate - self.Blueprint.Economy.BuildRate, Mult = 1.0, }, MaxHealth = { From 4171503d012fa09bfdcf3b256b3ee8a211635ddb Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Wed, 6 Nov 2024 02:52:13 -0800 Subject: [PATCH 04/13] Change `Blueprint` to `UnitBlueprintEnhancement` --- units/URL0001/URL0001_script.lua | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/units/URL0001/URL0001_script.lua b/units/URL0001/URL0001_script.lua index f4211ecd4d..6670945aa6 100644 --- a/units/URL0001/URL0001_script.lua +++ b/units/URL0001/URL0001_script.lua @@ -122,13 +122,13 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { -- Enhancements ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementTeleporter = function(self, bp) self:AddCommandCap('RULEUCC_Teleport') end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementTeleporterRemove = function(self, bp) RemoveUnitEnhancement(self, 'Teleporter') RemoveUnitEnhancement(self, 'TeleporterRemove') @@ -136,7 +136,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementStealthGenerator = function(self, bp) self:AddToggleCap('RULEUTC_StealthToggle') self.StealthEnh = true @@ -167,7 +167,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementStealthGeneratorRemove = function(self, bp) self:RemoveToggleCap('RULEUTC_StealthToggle') self:DisableUnitIntel('Enhancement', 'RadarStealth') @@ -179,7 +179,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementFAF_SelfRepairSystem = function(self, bp) if not Buffs['CybranACURegenerateBonus'] then BuffBlueprint { @@ -206,7 +206,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementFAF_SelfRepairSystemRemove = function(self, bp) -- remove prerequisites self:RemoveToggleCap('RULEUTC_StealthToggle') @@ -224,7 +224,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementCloakingGenerator = function(self, bp) if not bp then return end self:RemoveToggleCap('RULEUTC_StealthToggle') @@ -253,7 +253,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementCloakingGeneratorRemove = function(self, bp) -- remove prerequisites self:RemoveToggleCap('RULEUTC_CloakToggle') @@ -277,7 +277,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementResourceAllocation = function(self, bp) local bpEcon = self.Blueprint.Economy if not bp then return end @@ -286,7 +286,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementResourceAllocationRemove = function(self, bp) local bpEcon = self.Blueprint.Economy self:SetProductionPerSecondEnergy(bpEcon.ProductionPerSecondEnergy or 0) @@ -294,7 +294,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementAdvancedEngineering = function(self, bp) self.BuildBotTotal = 3 if not bp then return end @@ -327,7 +327,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementAdvancedEngineeringRemove = function(self, bp) self.BuildBotTotal = 2 local buildRate = self.Blueprint.Economy.BuildRate @@ -341,7 +341,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementT3Engineering = function(self, bp) self.BuildBotTotal = 4 if not bp then return end @@ -374,7 +374,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementT3EngineeringRemove = function(self, bp) self.BuildBotTotal = 2 local buildRate = self.Blueprint.Economy.BuildRate @@ -387,7 +387,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementCoolingUpgrade = function(self, bp) local wep = self:GetWeaponByLabel('RightRipper') wep:ChangeMaxRadius(bp.NewMaxRadius or 30) @@ -405,7 +405,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementCoolingUpgradeRemove = function(self, bp) local wep = self:GetWeaponByLabel('RightRipper') local wepBp = self.Blueprint.Weapon @@ -428,19 +428,19 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementMicrowaveLaserGenerator = function(self, bp) self:SetWeaponEnabledByLabel('MLG', true) end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementMicrowaveLaserGeneratorRemove = function(self, bp) self:SetWeaponEnabledByLabel('MLG', false) end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementNaniteTorpedoTube = function(self, bp) self:SetWeaponEnabledByLabel('Torpedo', true) self:SetIntelRadius('Sonar', bp.NewSonarRadius or 60) @@ -451,7 +451,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param bp Blueprint + ---@param bp UnitBlueprintEnhancement ProcessEnhancementNaniteTorpedoTubeRemove = function(self, bp) local bpIntel = self.Blueprint.Intel self:SetWeaponEnabledByLabel('Torpedo', false) From 02079428744c442ecb8092f40231c85faa68920f Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Wed, 6 Nov 2024 02:53:09 -0800 Subject: [PATCH 05/13] Clean up empty comment --- units/URL0001/URL0001_script.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/units/URL0001/URL0001_script.lua b/units/URL0001/URL0001_script.lua index 6670945aa6..eb2ca3c8e1 100644 --- a/units/URL0001/URL0001_script.lua +++ b/units/URL0001/URL0001_script.lua @@ -63,7 +63,6 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { ACUUnit.__init(self, 'RightRipper') end, - --- ---@param self URL0001 OnCreate = function(self) ACUUnit.OnCreate(self) From d9d665b4029ef07be733256e5b5827864b143c3e Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Wed, 6 Nov 2024 02:55:10 -0800 Subject: [PATCH 06/13] Move down unused import --- units/URL0001/URL0001_script.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/units/URL0001/URL0001_script.lua b/units/URL0001/URL0001_script.lua index eb2ca3c8e1..0bb994387e 100644 --- a/units/URL0001/URL0001_script.lua +++ b/units/URL0001/URL0001_script.lua @@ -29,7 +29,6 @@ local ACUDeathWeapon = import("/lua/sim/defaultweapons.lua").ACUDeathWeapon local CDFHeavyMicrowaveLaserGeneratorCom = CWeapons.CDFHeavyMicrowaveLaserGeneratorCom local CDFOverchargeWeapon = CWeapons.CDFOverchargeWeapon local CANTorpedoLauncherWeapon = CWeapons.CANTorpedoLauncherWeapon -local Entity = import("/lua/sim/entity.lua").Entity ---@class URL0001 : ACUUnit, CCommandUnit URL0001 = ClassUnit(ACUUnit, CCommandUnit) { @@ -578,3 +577,9 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { } TypeClass = URL0001 + +--#region backwards compatibility + +local Entity = import("/lua/sim/entity.lua").Entity + +--#endregion From e4a0e780f3910137e55ba2e068f2afbe64e26037 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Wed, 6 Nov 2024 02:58:17 -0800 Subject: [PATCH 07/13] Fix "undefined field" with cloak/stealth enhancements Update URL0001_script.lua --- units/URL0001/URL0001_script.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/units/URL0001/URL0001_script.lua b/units/URL0001/URL0001_script.lua index 0bb994387e..9f982859a7 100644 --- a/units/URL0001/URL0001_script.lua +++ b/units/URL0001/URL0001_script.lua @@ -31,6 +31,8 @@ local CDFOverchargeWeapon = CWeapons.CDFOverchargeWeapon local CANTorpedoLauncherWeapon = CWeapons.CANTorpedoLauncherWeapon ---@class URL0001 : ACUUnit, CCommandUnit +---@field StealthEnh? true +---@field CloakEnh? true URL0001 = ClassUnit(ACUUnit, CCommandUnit) { Weapons = { DeathWeapon = ClassWeapon(ACUDeathWeapon) {}, From 020b2c0286b1bf1498d0ff65d92d00528644cac1 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Wed, 6 Nov 2024 02:58:35 -0800 Subject: [PATCH 08/13] Make the cloak/stealth variable name clearer --- units/URL0001/URL0001_script.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/units/URL0001/URL0001_script.lua b/units/URL0001/URL0001_script.lua index 9f982859a7..98046cf0fb 100644 --- a/units/URL0001/URL0001_script.lua +++ b/units/URL0001/URL0001_script.lua @@ -31,8 +31,8 @@ local CDFOverchargeWeapon = CWeapons.CDFOverchargeWeapon local CANTorpedoLauncherWeapon = CWeapons.CANTorpedoLauncherWeapon ---@class URL0001 : ACUUnit, CCommandUnit ----@field StealthEnh? true ----@field CloakEnh? true +---@field HasStealthEnh? true +---@field HasCloakEnh? true URL0001 = ClassUnit(ACUUnit, CCommandUnit) { Weapons = { DeathWeapon = ClassWeapon(ACUDeathWeapon) {}, @@ -139,7 +139,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { ---@param bp UnitBlueprintEnhancement ProcessEnhancementStealthGenerator = function(self, bp) self:AddToggleCap('RULEUTC_StealthToggle') - self.StealthEnh = true + self.HasStealthEnh = true self:EnableUnitIntel('Enhancement', 'RadarStealth') self:EnableUnitIntel('Enhancement', 'SonarStealth') if not Buffs['CybranACUStealthBonus'] then @@ -172,7 +172,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { self:RemoveToggleCap('RULEUTC_StealthToggle') self:DisableUnitIntel('Enhancement', 'RadarStealth') self:DisableUnitIntel('Enhancement', 'SonarStealth') - self.StealthEnh = nil + self.HasStealthEnh = nil if Buff.HasBuff(self, 'CybranACUStealthBonus') then Buff.RemoveBuff(self, 'CybranACUStealthBonus') end @@ -212,7 +212,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { self:RemoveToggleCap('RULEUTC_StealthToggle') self:DisableUnitIntel('Enhancement', 'RadarStealth') self:DisableUnitIntel('Enhancement', 'SonarStealth') - self.StealthEnh = nil + self.HasStealthEnh = nil if Buff.HasBuff(self, 'CybranACUStealthBonus') then Buff.RemoveBuff(self, 'CybranACUStealthBonus') end @@ -229,8 +229,8 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { if not bp then return end self:RemoveToggleCap('RULEUTC_StealthToggle') self:AddToggleCap('RULEUTC_CloakToggle') - self.StealthEnh = nil - self.CloakEnh = true + self.HasStealthEnh = nil + self.HasCloakEnh = true self:EnableUnitIntel('Enhancement', 'Cloak') if not Buffs['CybranACUCloakBonus'] then BuffBlueprint { @@ -259,7 +259,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { self:RemoveToggleCap('RULEUTC_CloakToggle') self:DisableUnitIntel('Enhancement', 'RadarStealth') self:DisableUnitIntel('Enhancement', 'SonarStealth') - self.StealthEnh = nil + self.HasStealthEnh = nil if Buff.HasBuff(self, 'CybranACUStealthBonus') then Buff.RemoveBuff(self, 'CybranACUStealthBonus') end @@ -270,7 +270,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { -- remove cloak self:RemoveToggleCap('RULEUTC_CloakToggle') self:DisableUnitIntel('Enhancement', 'Cloak') - self.CloakEnh = nil + self.HasCloakEnh = nil if Buff.HasBuff(self, 'CybranACUCloakBonus') then Buff.RemoveBuff(self, 'CybranACUCloakBonus') end @@ -530,7 +530,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { ---@param intel string OnIntelEnabled = function(self, intel) ACUUnit.OnIntelEnabled(self, intel) - if self.CloakEnh and self:IsIntelEnabled('Cloak') then + if self.HasCloakEnh and self:IsIntelEnabled('Cloak') then self:SetEnergyMaintenanceConsumptionOverride(self.Blueprint.Enhancements['CloakingGenerator'].MaintenanceConsumptionPerSecondEnergy or 0) self:SetMaintenanceConsumptionActive() @@ -538,7 +538,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { self.IntelEffectsBag = {} self:CreateTerrainTypeEffects(self.IntelEffects.Cloak, 'FXIdle', self.Layer, nil, self.IntelEffectsBag) end - elseif self.StealthEnh and self:IsIntelEnabled('RadarStealth') and self:IsIntelEnabled('SonarStealth') then + elseif self.HasStealthEnh and self:IsIntelEnabled('RadarStealth') and self:IsIntelEnabled('SonarStealth') then self:SetEnergyMaintenanceConsumptionOverride(self.Blueprint.Enhancements['StealthGenerator'].MaintenanceConsumptionPerSecondEnergy or 0) self:SetMaintenanceConsumptionActive() @@ -557,9 +557,9 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { EffectUtil.CleanupEffectBag(self, 'IntelEffectsBag') self.IntelEffectsBag = nil end - if self.CloakEnh and not self:IsIntelEnabled('Cloak') then + if self.HasCloakEnh and not self:IsIntelEnabled('Cloak') then self:SetMaintenanceConsumptionInactive() - elseif self.StealthEnh and not self:IsIntelEnabled('RadarStealth') and not self:IsIntelEnabled('SonarStealth') then + elseif self.HasStealthEnh and not self:IsIntelEnabled('RadarStealth') and not self:IsIntelEnabled('SonarStealth') then self:SetMaintenanceConsumptionInactive() end end, From f3b7b358ee93ae80ada86df3a32ce9d289621da4 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Wed, 6 Nov 2024 03:07:28 -0800 Subject: [PATCH 09/13] Annotate `normalRange` and `torpRange` --- units/URL0001/URL0001_script.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/units/URL0001/URL0001_script.lua b/units/URL0001/URL0001_script.lua index 98046cf0fb..cae8a544d9 100644 --- a/units/URL0001/URL0001_script.lua +++ b/units/URL0001/URL0001_script.lua @@ -33,6 +33,8 @@ local CANTorpedoLauncherWeapon = CWeapons.CANTorpedoLauncherWeapon ---@class URL0001 : ACUUnit, CCommandUnit ---@field HasStealthEnh? true ---@field HasCloakEnh? true +---@field normalRange number # caches gun range to adjust the unit AI controller dummy weapon's range on layer change depending on active enhancements +---@field torpRange number # caches torpedo range to adjust the unit AI controller dummy weapon's range on layer change depending on active enhancements URL0001 = ClassUnit(ACUUnit, CCommandUnit) { Weapons = { DeathWeapon = ClassWeapon(ACUDeathWeapon) {}, @@ -564,6 +566,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end end, + --- Makes sure the ACU walks into the correct range for the target when it has/doesn't have the torpedo enhancement. ---@param self URL0001 ---@param new any ---@param old any From 1e1e90ce6deebbe41c8bd5dc33e4e1dce0c03d13 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Wed, 6 Nov 2024 03:11:56 -0800 Subject: [PATCH 10/13] Use `IntelType?` instead of `string` --- units/URL0001/URL0001_script.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/units/URL0001/URL0001_script.lua b/units/URL0001/URL0001_script.lua index cae8a544d9..8d993cc856 100644 --- a/units/URL0001/URL0001_script.lua +++ b/units/URL0001/URL0001_script.lua @@ -529,7 +529,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { }, ---@param self URL0001 - ---@param intel string + ---@param intel? IntelType OnIntelEnabled = function(self, intel) ACUUnit.OnIntelEnabled(self, intel) if self.HasCloakEnh and self:IsIntelEnabled('Cloak') then @@ -552,7 +552,7 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, ---@param self URL0001 - ---@param intel string + ---@param intel? IntelType OnIntelDisabled = function(self, intel) ACUUnit.OnIntelDisabled(self, intel) if self.IntelEffectsBag then From f51fcce5d155740ad1d6e9171c864c8a793db620 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Wed, 6 Nov 2024 03:21:49 -0800 Subject: [PATCH 11/13] Annotate the laser weapon in the unit script --- units/URL0001/URL0001_script.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/units/URL0001/URL0001_script.lua b/units/URL0001/URL0001_script.lua index 8d993cc856..543bd0babe 100644 --- a/units/URL0001/URL0001_script.lua +++ b/units/URL0001/URL0001_script.lua @@ -40,14 +40,18 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { DeathWeapon = ClassWeapon(ACUDeathWeapon) {}, RightRipper = ClassWeapon(CCannonMolecularWeapon) {}, Torpedo = ClassWeapon(CANTorpedoLauncherWeapon) {}, + ---@class MLG : CDFHeavyMicrowaveLaserGeneratorCom MLG = ClassWeapon(CDFHeavyMicrowaveLaserGeneratorCom) { DisabledFiringBones = { 'Turret_Muzzle_03' }, + ---@param self MLG + ---@param transportstate boolean SetOnTransport = function(self, transportstate) CDFHeavyMicrowaveLaserGeneratorCom.SetOnTransport(self, transportstate) self.Trash:Add(ForkThread(self.OnTransportWatch, self)) end, + ---@param self MLG OnTransportWatch = function(self) while self:GetOnTransport() do self:PlayFxBeamEnd() From bfc6dfde66da12839e92d233b539353ae7df5d46 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Wed, 6 Nov 2024 03:28:17 -0800 Subject: [PATCH 12/13] Remove redundant check for bp It is checked for in CreateEnhancement --- units/URL0001/URL0001_script.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/units/URL0001/URL0001_script.lua b/units/URL0001/URL0001_script.lua index 543bd0babe..8d1971720f 100644 --- a/units/URL0001/URL0001_script.lua +++ b/units/URL0001/URL0001_script.lua @@ -232,7 +232,6 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { ---@param self URL0001 ---@param bp UnitBlueprintEnhancement ProcessEnhancementCloakingGenerator = function(self, bp) - if not bp then return end self:RemoveToggleCap('RULEUTC_StealthToggle') self:AddToggleCap('RULEUTC_CloakToggle') self.HasStealthEnh = nil @@ -286,7 +285,6 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { ---@param bp UnitBlueprintEnhancement ProcessEnhancementResourceAllocation = function(self, bp) local bpEcon = self.Blueprint.Economy - if not bp then return end self:SetProductionPerSecondEnergy((bp.ProductionPerSecondEnergy + bpEcon.ProductionPerSecondEnergy) or 0) self:SetProductionPerSecondMass((bp.ProductionPerSecondMass + bpEcon.ProductionPerSecondMass) or 0) end, @@ -303,7 +301,6 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { ---@param bp UnitBlueprintEnhancement ProcessEnhancementAdvancedEngineering = function(self, bp) self.BuildBotTotal = 3 - if not bp then return end local cat = ParseEntityCategory(bp.BuildableCategoryAdds) self:RemoveBuildRestriction(cat) if not Buffs['CybranACUT2BuildRate'] then @@ -350,7 +347,6 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { ---@param bp UnitBlueprintEnhancement ProcessEnhancementT3Engineering = function(self, bp) self.BuildBotTotal = 4 - if not bp then return end local cat = ParseEntityCategory(bp.BuildableCategoryAdds) self:RemoveBuildRestriction(cat) if not Buffs['CybranACUT3BuildRate'] then From a59fb79d1bd3d189c93ce3e44f56ccfe71ca48b8 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Wed, 6 Nov 2024 03:33:07 -0800 Subject: [PATCH 13/13] Use a region for enhancements --- units/URL0001/URL0001_script.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/units/URL0001/URL0001_script.lua b/units/URL0001/URL0001_script.lua index 8d1971720f..e07206f936 100644 --- a/units/URL0001/URL0001_script.lua +++ b/units/URL0001/URL0001_script.lua @@ -124,8 +124,8 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end, - --====================================================================================================== - -- Enhancements + --------------------------------------------------------------------------- + --#region Enhancements ---@param self URL0001 ---@param bp UnitBlueprintEnhancement @@ -482,6 +482,8 @@ URL0001 = ClassUnit(ACUUnit, CCommandUnit) { end end, + --#endregion + -- Intel IntelEffects = { Cloak = {