Skip to content

Commit

Permalink
Restore HQ status after removing restrictions (FAForever#4623)
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas authored Jan 24, 2023
1 parent 03fcd3f commit 5ee7162
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lua/ScenarioFramework.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,12 @@ function RemoveRestriction(army, categories, isSilent)
-- Remove scenario restriction from game restrictions
Game.RemoveRestriction(categories, army)
Sync.Restrictions = Game.GetRestrictions()

---@type AIBrain
local brain = ArmyBrains[army]
if brain then
brain:ReEvaluateHQSupportFactoryRestrictions()
end
end
end

Expand Down
21 changes: 19 additions & 2 deletions lua/aibrain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,23 @@ AIBrain = Class(moho.aibrain_methods) {
self.HQs[faction][layer][tech] = math.max(0, self.HQs[faction][layer][tech] - 1)
end,

--- Completely re evaluates the support factory restrictions of the engi mod
---@param self AIBrain
ReEvaluateHQSupportFactoryRestrictions = function (self)
local layers = { "AIR", "LAND", "NAVAL" }
local factions = { "UEF", "AEON", "CYBRAN", "SERAPHIM" }

if categories.NOMADS then
table.insert(factions, 'NOMADS')
end

for _, faction in factions do
for _, layer in layers do
self:SetHQSupportFactoryRestrictions(faction, layer)
end
end
end,

--- Manages the support factory restrictions of the engi mod
---@param self AIBrain
---@param faction HqFaction
Expand All @@ -260,13 +277,13 @@ AIBrain = Class(moho.aibrain_methods) {
AddBuildRestriction(army, categories[faction] * categories[layer] * categories["TECH3"] * categories.SUPPORTFACTORY)

-- lift t2 / t3 support factory restrictions
if self.HQs[faction][layer]["TECH3"] > 0 then
if self.HQs[faction][layer]["TECH3"] > 0 then
RemoveBuildRestriction(army, categories[faction] * categories[layer] * categories["TECH2"] * categories.SUPPORTFACTORY)
RemoveBuildRestriction(army, categories[faction] * categories[layer] * categories["TECH3"] * categories.SUPPORTFACTORY)
end

-- lift t2 support factory restrictions
if self.HQs[faction][layer]["TECH2"] > 0 then
if self.HQs[faction][layer]["TECH2"] > 0 then
RemoveBuildRestriction(army, categories[faction] * categories[layer] * categories["TECH2"] * categories.SUPPORTFACTORY)
end
end,
Expand Down

0 comments on commit 5ee7162

Please sign in to comment.