From 145ea06732a838f6d0fc210eb016b919d8f494da Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 30 May 2024 23:15:49 -0700 Subject: [PATCH] Fix free intel not being toggleable (#6207) also fix Cybran ACU/SACU stealth not being toggleable --- changelog/snippets/fix.6207.md | 3 + engine/Core/Blueprints/UnitBlueprint.lua | 1 - lua/defaultcomponents.lua | 126 +++++++++++------------ lua/sim/Unit.lua | 8 -- lua/sim/units/cybran/CCommandUnit.lua | 6 ++ lua/system/blueprints-units.lua | 36 +++---- units/URL0301/URL0301_script.lua | 10 +- 7 files changed, 91 insertions(+), 99 deletions(-) create mode 100644 changelog/snippets/fix.6207.md diff --git a/changelog/snippets/fix.6207.md b/changelog/snippets/fix.6207.md new file mode 100644 index 0000000000..0499ad7d9c --- /dev/null +++ b/changelog/snippets/fix.6207.md @@ -0,0 +1,3 @@ +- (#6207) Fix free intel not being toggleable, which lead to UEF spy plane's jammer blips never reappearing after being seen. + +- (#6207) Fix Cybran ACU and SACU stealth not being toggleable. diff --git a/engine/Core/Blueprints/UnitBlueprint.lua b/engine/Core/Blueprints/UnitBlueprint.lua index dd357614a5..b6f65b2b90 100644 --- a/engine/Core/Blueprints/UnitBlueprint.lua +++ b/engine/Core/Blueprints/UnitBlueprint.lua @@ -992,7 +992,6 @@ ---@field AllIntel table ---@field AllIntelRecharging table ---@field AllIntelMaintenanceFree table ----@field AllIntelFromEnhancements table ---@field AllIntelDisabledByEvent table> ---@class UnitBlueprintIntel diff --git a/lua/defaultcomponents.lua b/lua/defaultcomponents.lua index 77590a99e8..f57677a799 100644 --- a/lua/defaultcomponents.lua +++ b/lua/defaultcomponents.lua @@ -74,7 +74,7 @@ IntelComponent = ClassSimple { end, ---@param self IntelComponent | Unit - ---@param disabler string + ---@param disabler string The reason the intel is disabled. If it's 'Energy', then free intel does not get disabled. ---@param intel? IntelType DisableUnitIntel = function(self, disabler, intel) local status = self.IntelStatus @@ -84,67 +84,68 @@ IntelComponent = ClassSimple { -- prevent recharging from occuring self:OnIntelRechargeFailed() - -- disable all intel + -- upvalue for performance local allIntel = status.AllIntel local allIntelDisabledByEvent = status.AllIntelDisabledByEvent local allIntelMaintenanceFree = status.AllIntelMaintenanceFree - local allIntelFromEnhancements = status.AllIntelFromEnhancements + + -- disable all intel if not intel then - for i, _ in allIntel do - if not (disabler == 'Energy' and allIntelMaintenanceFree and allIntelMaintenanceFree[i]) then - allIntelDisabledByEvent[i] = allIntelDisabledByEvent[i] or {} - if not allIntelDisabledByEvent[i][disabler] then - allIntelDisabledByEvent[i][disabler] = true - self:DisableIntel(i) - self:OnIntelDisabled(i) - end + for intel, _ in allIntel do + local allIntelDisablers = allIntelDisabledByEvent[intel] + if not allIntelDisablers then + allIntelDisabledByEvent[intel] = {} + end + if not allIntelDisablers[disabler] then + allIntelDisabledByEvent[intel][disabler] = true + self:DisableIntel(intel) + self:OnIntelDisabled(intel) end end - if allIntelMaintenanceFree then - for i, _ in allIntelMaintenanceFree do - if not (disabler == 'Energy' and allIntelMaintenanceFree and allIntelMaintenanceFree[i]) then - allIntelDisabledByEvent[i] = allIntelDisabledByEvent[i] or {} - if not allIntelDisabledByEvent[i][disabler] then - allIntelDisabledByEvent[i][disabler] = true - self:DisableIntel(i) - self:OnIntelDisabled(i) - end + if disabler ~= 'Energy' and allIntelMaintenanceFree then + for intel, _ in allIntelMaintenanceFree do + local allIntelDisablers = allIntelDisabledByEvent[intel] + if not allIntelDisablers then + allIntelDisabledByEvent[intel] = {} + end + if not allIntelDisablers[disabler] then + allIntelDisabledByEvent[intel][disabler] = true + self:DisableIntel(intel) + self:OnIntelDisabled(intel) end end end - -- disable one intel - elseif allIntel[intel] or (allIntelFromEnhancements and allIntelFromEnhancements[intel]) then - -- special case that requires additional book keeping - if disabler == 'Enhancement' then - allIntelFromEnhancements[intel] = true + -- disable one intel + elseif allIntel[intel] + or (disabler ~= 'Energy' and allIntelMaintenanceFree[intel]) + then + local allIntelDisablers = allIntelDisabledByEvent[intel] + if not allIntelDisablers then + allIntelDisabledByEvent[intel] = {} end - - if not (disabler == 'Energy' and allIntelMaintenanceFree and allIntelMaintenanceFree[intel]) then - allIntelDisabledByEvent[intel] = allIntelDisabledByEvent[intel] or {} - if not allIntelDisabledByEvent[intel][disabler] then - allIntelDisabledByEvent[intel][disabler] = true - self:DisableIntel(intel) - self:OnIntelDisabled(intel) - end + if not allIntelDisablers[disabler] then + allIntelDisabledByEvent[intel][disabler] = true + self:DisableIntel(intel) + self:OnIntelDisabled(intel) end end end end, ---@param self IntelComponent | Unit - ---@param disabler string + ---@param disabler string The reason the intel is disabled. Intel will not enable if some other disabler is disabling it. ---@param intel? IntelType EnableUnitIntel = function(self, disabler, intel) local status = self.IntelStatus if status then -- LOG("EnableUnitIntel: " .. tostring(disabler) .. " for " .. tostring(intel)) + -- upvalue for performance local allIntel = status.AllIntel local allIntelDisabledByEvent = status.AllIntelDisabledByEvent local allIntelMaintenanceFree = status.AllIntelMaintenanceFree - local allIntelFromEnhancements = status.AllIntelFromEnhancements -- special case when unit is finished building if disabler == 'NotInitialized' then @@ -166,48 +167,39 @@ IntelComponent = ClassSimple { return end - -- disable all intel + -- enable all intel if not intel then - for i, _ in allIntel do - if not (disabler == 'Energy' and allIntelMaintenanceFree and allIntelMaintenanceFree[i]) then - allIntelDisabledByEvent[i] = allIntelDisabledByEvent[i] or {} - if allIntelDisabledByEvent[i][disabler] then - allIntelDisabledByEvent[i][disabler] = nil - if table.empty(allIntelDisabledByEvent[i]) then - self:OnIntelRecharge(i) - end + for intel, _ in allIntel do + local allIntelDisablers = allIntelDisabledByEvent[intel] + if allIntelDisablers[disabler] then + allIntelDisablers[disabler] = nil + if table.empty(allIntelDisablers) then + self:OnIntelRecharge(intel) end end end - if allIntelFromEnhancements then - for i, _ in allIntelFromEnhancements do - if not (disabler == 'Energy' and allIntelMaintenanceFree and allIntelMaintenanceFree[i]) then - allIntelDisabledByEvent[i] = allIntelDisabledByEvent[i] or {} - if allIntelDisabledByEvent[i][disabler] then - allIntelDisabledByEvent[i][disabler] = nil - if table.empty(allIntelDisabledByEvent[i]) then - self:OnIntelRecharge(i) - end + if disabler ~= 'Energy' and allIntelMaintenanceFree then + for intel, _ in allIntelMaintenanceFree do + local allIntelDisablers = allIntelDisabledByEvent[intel] + if allIntelDisablers[disabler] then + allIntelDisablers[disabler] = nil + if table.empty(allIntelDisablers) then + self:OnIntelRecharge(intel) end end end end - -- disable one intel - elseif allIntel[intel] or (allIntelFromEnhancements and allIntelFromEnhancements[intel]) then - -- special case that requires additional book keeping - if disabler == 'Enhancement' then - allIntelFromEnhancements[intel] = true - end - - if not (disabler == 'Energy' and allIntelMaintenanceFree and allIntelMaintenanceFree[intel]) then - allIntelDisabledByEvent[intel] = allIntelDisabledByEvent[intel] or {} - if allIntelDisabledByEvent[intel][disabler] then - allIntelDisabledByEvent[intel][disabler] = nil - if table.empty(allIntelDisabledByEvent[intel]) then - self:OnIntelRecharge(intel) - end + -- enable one intel + elseif allIntel[intel] + or (disabler ~= 'Energy' and allIntelMaintenanceFree[intel]) + then + local allIntelDisablers = allIntelDisabledByEvent[intel] + if allIntelDisablers[disabler] then + allIntelDisablers[disabler] = nil + if table.empty(allIntelDisablers) then + self:OnIntelRecharge(intel) end end end diff --git a/lua/sim/Unit.lua b/lua/sim/Unit.lua index c33ccdb02e..1a343d1dbe 100644 --- a/lua/sim/Unit.lua +++ b/lua/sim/Unit.lua @@ -487,10 +487,6 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent) { self:SetMaintenanceConsumptionInactive() self:DisableUnitIntel('ToggleBit8', 'Cloak') end - - if not self.MaintenanceConsumption then - self.ToggledOff = true - end end, ---@param self Unit @@ -536,10 +532,6 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent) { self:SetMaintenanceConsumptionActive() self:EnableUnitIntel('ToggleBit8', 'Cloak') end - - if self.MaintenanceConsumption then - self.ToggledOff = false - end end, ---@param self Unit diff --git a/lua/sim/units/cybran/CCommandUnit.lua b/lua/sim/units/cybran/CCommandUnit.lua index 5755f8ebe5..9289ec5394 100644 --- a/lua/sim/units/cybran/CCommandUnit.lua +++ b/lua/sim/units/cybran/CCommandUnit.lua @@ -79,6 +79,7 @@ CCommandUnit = ClassUnit(CommandUnit, CConstructionTemplate) { CConstructionTemplateOnDestroy(self) end, + --- changes cloak toggle behavior to also toggle stealth ---@param self CCommandUnit ---@param bit number OnScriptBitSet = function(self, bit) @@ -90,9 +91,12 @@ CCommandUnit = ClassUnit(CommandUnit, CConstructionTemplate) { self:DisableUnitIntel('ToggleBit8', 'RadarStealthField') self:DisableUnitIntel('ToggleBit8', 'SonarStealth') self:DisableUnitIntel('ToggleBit8', 'SonarStealthField') + else + CommandUnit.OnScriptBitSet(self, bit) end end, + --- changes cloak toggle behavior to also toggle stealth ---@param self CCommandUnit ---@param bit number OnScriptBitClear = function(self, bit) @@ -104,6 +108,8 @@ CCommandUnit = ClassUnit(CommandUnit, CConstructionTemplate) { self:EnableUnitIntel('ToggleBit8', 'RadarStealthField') self:EnableUnitIntel('ToggleBit8', 'SonarStealth') self:EnableUnitIntel('ToggleBit8', 'SonarStealthField') + else + CommandUnit.OnScriptBitClear(self, bit) end end, } diff --git a/lua/system/blueprints-units.lua b/lua/system/blueprints-units.lua index e65fea4c50..3413d75d2e 100644 --- a/lua/system/blueprints-units.lua +++ b/lua/system/blueprints-units.lua @@ -338,40 +338,38 @@ local function PostProcessUnit(unit) ---@type UnitIntelStatus local status = {} - -- life is good, intel is funded by the government + -- all of the unit's intel is free due to a bp flag or 0 maintenance cost local allIntelIsFree = false - if intelBlueprint.FreeIntel or ( - not enhancementBlueprints and - ( - (not economyBlueprint) or - (not economyBlueprint.MaintenanceConsumptionPerSecondEnergy) or - economyBlueprint.MaintenanceConsumptionPerSecondEnergy == 0 + if intelBlueprint.FreeIntel + or ( + not enhancementBlueprints + and ( + not economyBlueprint + or not economyBlueprint.MaintenanceConsumptionPerSecondEnergy + or economyBlueprint.MaintenanceConsumptionPerSecondEnergy == 0 ) - ) then + ) + then allIntelIsFree = true status.AllIntelMaintenanceFree = {} end - -- special case: unit has intel that is considered free - if intelBlueprint.ActiveIntel then - status.AllIntelMaintenanceFree = status.AllIntelMaintenanceFree or {} - for intel, _ in intelBlueprint.ActiveIntel do + -- special case: unit has specific intel types that are considered free + local activeIntel = intelBlueprint.ActiveIntel + if activeIntel then + status.AllIntelMaintenanceFree = {} + for intel, _ in activeIntel do status.AllIntelMaintenanceFree[intel] = true end end - -- special case: unit has enhancements and therefore can have any intel type - if enhancementBlueprints then - status.AllIntelFromEnhancements = {} - end - -- usual case: find all remaining intel status.AllIntel = {} for name, value in intelBlueprint do if value == true or value > 0 then local intel = BlueprintNameToIntel[name] - if intel then + if intel and not activeIntel[intel] then if allIntelIsFree then status.AllIntelMaintenanceFree[intel] = true else @@ -382,7 +380,7 @@ local function PostProcessUnit(unit) end -- check if we have any intel - if not (table.empty(status.AllIntel) and table.empty(status.AllIntelMaintenanceFree) and not enhancementBlueprints) then + if not ( table.empty(status.AllIntel) and table.empty(status.AllIntelMaintenanceFree) ) then -- cache it status.AllIntelDisabledByEvent = {} status.AllIntelRecharging = {} diff --git a/units/URL0301/URL0301_script.lua b/units/URL0301/URL0301_script.lua index 6bbfb17741..50723218c0 100644 --- a/units/URL0301/URL0301_script.lua +++ b/units/URL0301/URL0301_script.lua @@ -54,7 +54,6 @@ URL0301 = ClassUnit(CCommandUnit) { if self.Blueprint.General.BuildBones then self:SetupBuildBones() end - self.IntelButtonSet = true end, __init = function(self) @@ -103,8 +102,13 @@ URL0301 = ClassUnit(CCommandUnit) { end Buff.ApplyBuff(self, 'CybranSCUCloakBonus') elseif enh == 'CloakingGeneratorRemove' then + -- remove prerequisites + self:RemoveToggleCap('RULEUTC_StealthToggle') + self:DisableUnitIntel('Enhancement', 'RadarStealth') + self:DisableUnitIntel('Enhancement', 'SonarStealth') + + -- remove cloak self:DisableUnitIntel('Enhancement', 'Cloak') - self.StealthEnh = false self.CloakEnh = false self:RemoveToggleCap('RULEUTC_CloakToggle') if Buff.HasBuff(self, 'CybranSCUCloakBonus') then @@ -116,7 +120,6 @@ URL0301 = ClassUnit(CCommandUnit) { EffectUtil.CleanupEffectBag(self, 'IntelEffectsBag') self.IntelEffectsBag = nil end - self.CloakEnh = false self.StealthEnh = true self:EnableUnitIntel('Enhancement', 'RadarStealth') self:EnableUnitIntel('Enhancement', 'SonarStealth') @@ -125,7 +128,6 @@ URL0301 = ClassUnit(CCommandUnit) { self:DisableUnitIntel('Enhancement', 'RadarStealth') self:DisableUnitIntel('Enhancement', 'SonarStealth') self.StealthEnh = false - self.CloakEnh = false elseif enh == 'NaniteMissileSystem' then self:ShowBone('AA_Gun', true) self:SetWeaponEnabledByLabel('NMissile', true)