Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update UEF SACU Enhancement Script #6515

Merged
merged 7 commits into from
Nov 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 129 additions & 87 deletions units/UEL0301/UEL0301_script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,105 +171,147 @@ UEL0301 = ClassUnit(CommandUnit) {
attachee:SetDoNotTarget(false)
end,


-- ============================================================================================================================================================
-- ENHANCEMENTS

ProcessEnhancementPod = function(self, bp)
MrRowey marked this conversation as resolved.
Show resolved Hide resolved
local location = self:GetPosition('AttachSpecial01')
local pod = CreateUnitHPR('UEA0003', self.Army, location[1], location[2], location[3], 0, 0, 0)
pod:SetParent(self, 'Pod')
pod:SetCreator(self)
self.Trash:Add(pod)
self.HasPod = true
self.Pod = pod
end,

ProcessEnhancementPodRemove = function(self, bp)
if self.HasPod == true then
self.HasPod = false
if self.Pod and not self.Pod:BeenDestroyed() then
self.Pod:Kill()
self.Pod = nil
end
if self.RebuildingPod ~= nil then
RemoveEconomyEvent(self, self.RebuildingPod)
self.RebuildingPod = nil
end
end
KillThread(self.RebuildThread)
end,

ProcessEnhancementShield = function (self, bp)
self:AddToggleCap('RULEUTC_ShieldToggle')
self:SetEnergyMaintenanceConsumptionOverride(bp.MaintenanceConsumptionPerSecondEnergy or 0)
self:SetMaintenanceConsumptionActive()
self:CreateShield(bp)
end,

ProcessEnhancementShieldRemove = function (self, bp)
RemoveUnitEnhancement(self, 'Shield')
self:DestroyShield()
self:SetMaintenanceConsumptionInactive()
self:RemoveToggleCap('RULEUTC_ShieldToggle')
end,

ProcessEnhancementShieldGeneratorField = function(self, bp)
self:DestroyShield()
self:ForkThread(function()
WaitTicks(1)
self:CreateShield(bp)
self:SetEnergyMaintenanceConsumptionOverride(bp.MaintenanceConsumptionPerSecondEnergy or 0)
self:SetMaintenanceConsumptionActive()
end)
end,

ProcessEnhancementShieldGeneratorFieldRemove = function(self, bp)
self:DestroyShield()
self:SetMaintenanceConsumptionInactive()
self:RemoveToggleCap('RULEUTC_ShieldToggle')
end,

ProcessEnhancementResourceAllocation = function(self, bp)
local bpEcon = self:GetBlueprint().Economy
if not bp then return end
self:SetProductionPerSecondEnergy((bp.ProductionPerSecondEnergy + bpEcon.ProductionPerSecondEnergy) or 0)
self:SetProductionPerSecondMass((bp.ProductionPerSecondMass + bpEcon.ProductionPerSecondMass) or 0)
end,

ProcessEnhancementResourceAllocationRemove = function(self, bp)
local bpEcon = self:GetBlueprint().Economy
self:SetProductionPerSecondEnergy(bpEcon.ProductionPerSecondEnergy or 0)
self:SetProductionPerSecondMass(bpEcon.ProductionPerSecondMass or 0)
end,

ProcessEnhancementSensorRangeEnhancer = function(self, bp)
self:SetIntelRadius('Vision', bp.NewVisionRadius or 104)
self:SetIntelRadius('Omni', bp.NewOmniRadius or 104)
end,

ProcessEnhancementSensorRangeEnhancerRemove = function(self, bp)
local bpIntel = self:GetBlueprint().Intel
self:SetIntelRadius('Vision', bpIntel.VisionRadius or 26)
self:SetIntelRadius('Omni', bpIntel.OmniRadius or 26)
end,

ProcessEnhancementRadarJammer = function(self, bp)
self:SetIntelRadius('Jammer', bp.NewJammerRadius or 26)
self.RadarJammerEnh = true
self:EnableUnitIntel('Enhancement', 'Jammer')
self:AddToggleCap('RULEUTC_JammingToggle')
end,

ProcessEnhancementRadarJammerRemove = function(self, bp)
local bpIntel = self:GetBlueprint().Intel
self:SetIntelRadius('Jammer', 0)
self:DisableUnitIntel('Enhancement', 'Jammer')
self.RadarJammerEnh = false
self:RemoveToggleCap('RULEUTC_JammingToggle')
end,

ProcessEnhancementAdvancedCoolingUpgrade = function(self, bp)
local wep = self:GetWeaponByLabel('RightHeavyPlasmaCannon')
wep:ChangeRateOfFire(bp.NewRateOfFire)
end,

ProcessEnhancementAdvancedCoolingUpgradeRemove = function(self, bp)
local wep = self:GetWeaponByLabel('RightHeavyPlasmaCannon')
wep:ChangeRateOfFire(self:GetBlueprint().Weapon[1].RateOfFire or 1)
end,

ProcessEnhancementHighExplosiveOrdnance = function(self, bp)
local wep = self:GetWeaponByLabel('RightHeavyPlasmaCannon')
wep:AddDamageRadiusMod(bp.NewDamageRadius)
wep:ChangeMaxRadius(bp.NewMaxRadius or 35)
end,

ProcessEnhancementHighExplosiveOrdnanceRemove = function(self, bp)
local wep = self:GetWeaponByLabel('RightHeavyPlasmaCannon')
wep:AddDamageRadiusMod(bp.NewDamageRadius)
wep:ChangeMaxRadius(bp.NewMaxRadius or 25)
end,

---@param self UEL0301
---@param enh string
CreateEnhancement = function(self, enh)
CommandUnit.CreateEnhancement(self, enh)
local bp = self:GetBlueprint().Enhancements[enh]
if not bp then return end
if enh == 'Pod' then
local location = self:GetPosition('AttachSpecial01')
local pod = CreateUnitHPR('UEA0003', self.Army, location[1], location[2], location[3], 0, 0, 0)
pod:SetParent(self, 'Pod')
pod:SetCreator(self)
self.Trash:Add(pod)
self.HasPod = true
self.Pod = pod
elseif enh == 'PodRemove' then
if self.HasPod == true then
self.HasPod = false
if self.Pod and not self.Pod:BeenDestroyed() then
self.Pod:Kill()
self.Pod = nil
end
if self.RebuildingPod ~= nil then
RemoveEconomyEvent(self, self.RebuildingPod)
self.RebuildingPod = nil
end
end
KillThread(self.RebuildThread)
elseif enh == 'Shield' then
self:AddToggleCap('RULEUTC_ShieldToggle')
self:SetEnergyMaintenanceConsumptionOverride(bp.MaintenanceConsumptionPerSecondEnergy or 0)
self:SetMaintenanceConsumptionActive()
self:CreateShield(bp)
elseif enh == 'ShieldRemove' then
RemoveUnitEnhancement(self, 'Shield')
self:DestroyShield()
self:SetMaintenanceConsumptionInactive()
self:RemoveToggleCap('RULEUTC_ShieldToggle')
elseif enh == 'ShieldGeneratorField' then
self:DestroyShield()
self:ForkThread(function()
WaitTicks(1)
self:CreateShield(bp)
self:SetEnergyMaintenanceConsumptionOverride(bp.MaintenanceConsumptionPerSecondEnergy or 0)
self:SetMaintenanceConsumptionActive()
end)
elseif enh == 'ShieldGeneratorFieldRemove' then
self:DestroyShield()
self:SetMaintenanceConsumptionInactive()
self:RemoveToggleCap('RULEUTC_ShieldToggle')
elseif enh =='ResourceAllocation' then
local bp = self:GetBlueprint().Enhancements[enh]
local bpEcon = self:GetBlueprint().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:GetBlueprint().Economy
self:SetProductionPerSecondEnergy(bpEcon.ProductionPerSecondEnergy or 0)
self:SetProductionPerSecondMass(bpEcon.ProductionPerSecondMass or 0)
elseif enh == 'SensorRangeEnhancer' then
self:SetIntelRadius('Vision', bp.NewVisionRadius or 104)
self:SetIntelRadius('Omni', bp.NewOmniRadius or 104)
elseif enh == 'SensorRangeEnhancerRemove' then
local bpIntel = self:GetBlueprint().Intel
self:SetIntelRadius('Vision', bpIntel.VisionRadius or 26)
self:SetIntelRadius('Omni', bpIntel.OmniRadius or 26)
elseif enh == 'RadarJammer' then
self:SetIntelRadius('Jammer', bp.NewJammerRadius or 26)
self.RadarJammerEnh = true
self:EnableUnitIntel('Enhancement', 'Jammer')
self:AddToggleCap('RULEUTC_JammingToggle')
elseif enh == 'RadarJammerRemove' then
local bpIntel = self:GetBlueprint().Intel
self:SetIntelRadius('Jammer', 0)
self:DisableUnitIntel('Enhancement', 'Jammer')
self.RadarJammerEnh = false
self:RemoveToggleCap('RULEUTC_JammingToggle')
elseif enh =='AdvancedCoolingUpgrade' then
local wep = self:GetWeaponByLabel('RightHeavyPlasmaCannon')
wep:ChangeRateOfFire(bp.NewRateOfFire)
elseif enh =='AdvancedCoolingUpgradeRemove' then
local wep = self:GetWeaponByLabel('RightHeavyPlasmaCannon')
wep:ChangeRateOfFire(self:GetBlueprint().Weapon[1].RateOfFire or 1)
elseif enh =='HighExplosiveOrdnance' then
local wep = self:GetWeaponByLabel('RightHeavyPlasmaCannon')
wep:AddDamageRadiusMod(bp.NewDamageRadius)
wep:ChangeMaxRadius(bp.NewMaxRadius or 35)
elseif enh =='HighExplosiveOrdnanceRemove' then
local wep = self:GetWeaponByLabel('RightHeavyPlasmaCannon')
wep:AddDamageRadiusMod(bp.NewDamageRadius)
wep:ChangeMaxRadius(bp.NewMaxRadius or 25)

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,

---@param self UEL0301
---@param intel IntelType
OnIntelEnabled = function(self, intel)
CommandUnit.OnIntelEnabled(self, intel)
if self.RadarJammerEnh and self:IsIntelEnabled('Jammer') then
if self.ProcessEnhancementRadarJammer and self:IsIntelEnabled('Jammer') then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unintentional change - it would always be true. See also the RadarJammerEnh field that is set to true/false depending on whether the enhancement exists.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking at this can't this just be a part of the 2 Functions for the enhancements now?

Copy link
Member Author

@MrRowey MrRowey Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So something like

    ---@param self UEL0301
    ---@param bp UnitBlueprintEnhancement
    ProcessEnhancementRadarJammer = function(self, bp)
        self:SetIntelRadius('Jammer', bp.NewJammerRadius or 26)
        self:EnableUnitIntel('Enhancement', 'Jammer')
        self:AddToggleCap('RULEUTC_JammingToggle')
        self:SetEnergyMaintenanceConsumptionOverride(bp.MaintenanceConsumptionPerSecondEnergy or 0)
        self:SetMaintenanceConsumptionActive()

        if self.IntelEffects then
            self.IntelEffectsBag = {}
            self:CreateTerrainTypeEffects(self.IntelEffects, 'FXIdle',  self.Layer, nil, self.IntelEffectsBag)
        end

    end,
    ```

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but then do you even need the self.RadarJammerEnh = true if the part its setting ti for can now be apart of the same function as it wasn't before ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't inline OnIntelEnabled because that function is called when the jamming toggle is pressed (or whenever else the jammer is enabled), while the enhancement function is called only once when the enhancement is built. Same for OnIntelDisabled.

If you did inline it, then the jammer's FX and and energy consumption would remain permanently on until the enhancement is removed.

if self.IntelEffects then
self.IntelEffectsBag = {}
self:CreateTerrainTypeEffects(self.IntelEffects, 'FXIdle', self.Layer, nil, self.IntelEffectsBag)
Expand All @@ -283,7 +325,7 @@ UEL0301 = ClassUnit(CommandUnit) {
---@param intel IntelType
OnIntelDisabled = function(self, intel)
CommandUnit.OnIntelDisabled(self, intel)
if self.RadarJammerEnh and not self:IsIntelEnabled('Jammer') then
if self.ProcessEnhancementRadarJammer and not self:IsIntelEnabled('Jammer') then
self:SetMaintenanceConsumptionInactive()
if self.IntelEffectsBag then
EffectUtil.CleanupEffectBag(self, 'IntelEffectsBag')
Expand Down
Loading