Skip to content

Commit

Permalink
Fix free intel not being toggleable (FAForever#6207)
Browse files Browse the repository at this point in the history
also fix Cybran ACU/SACU stealth not being toggleable
  • Loading branch information
lL1l1 authored May 31, 2024
1 parent 74c486a commit 145ea06
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 99 deletions.
3 changes: 3 additions & 0 deletions changelog/snippets/fix.6207.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 0 additions & 1 deletion engine/Core/Blueprints/UnitBlueprint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,6 @@
---@field AllIntel table<IntelType, boolean>
---@field AllIntelRecharging table<IntelType, boolean>
---@field AllIntelMaintenanceFree table<IntelType, boolean>
---@field AllIntelFromEnhancements table<IntelType, boolean>
---@field AllIntelDisabledByEvent table<IntelType, table<string, boolean>>

---@class UnitBlueprintIntel
Expand Down
126 changes: 59 additions & 67 deletions lua/defaultcomponents.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 0 additions & 8 deletions lua/sim/Unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lua/sim/units/cybran/CCommandUnit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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,
}
36 changes: 17 additions & 19 deletions lua/system/blueprints-units.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {}
Expand Down
10 changes: 6 additions & 4 deletions units/URL0301/URL0301_script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ URL0301 = ClassUnit(CCommandUnit) {
if self.Blueprint.General.BuildBones then
self:SetupBuildBones()
end
self.IntelButtonSet = true
end,

__init = function(self)
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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)
Expand Down

0 comments on commit 145ea06

Please sign in to comment.