Skip to content

Commit

Permalink
Fix AI factory manager not removing factories after upgrade (FAForeve…
Browse files Browse the repository at this point in the history
  • Loading branch information
relent0r authored Oct 27, 2022
1 parent 4cec93c commit 9cde3ee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
17 changes: 17 additions & 0 deletions lua/sim/BuilderManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,23 @@ BuilderManager = ClassSimple {
end
end
end,

---@param self, BuilderManager
---@param oldtable, Table
---@return tempTable, Table
RebuildTable = function(self, oldtable)
local temptable = {}
for k, v in oldtable do
if v ~= nil then
if type(k) == 'string' then
temptable[k] = v
else
table.insert(temptable, v)
end
end
end
return temptable
end,
}


Expand Down
20 changes: 15 additions & 5 deletions lua/sim/FactoryBuilderManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ FactoryBuilderManager = Class(BuilderManager) {
---@param factory Unit
FactoryDestroyed = function(self, factory)
local guards = factory:GetGuards()
local factoryDestroyed = false
for k,v in guards do
if not v.Dead and v.AssistPlatoon then
if self.Brain:PlatoonExists(v.AssistPlatoon) then
Expand All @@ -288,10 +289,14 @@ FactoryBuilderManager = Class(BuilderManager) {
end
end
for k,v in self.FactoryList do
if v == factory then
if IsDestroyed(v) then
self.FactoryList[k] = nil
factoryDestroyed = true
end
end
if factoryDestroyed then
self.FactoryList = self:RebuildTable(self.FactoryList)
end
for k,v in self.FactoryList do
if not v.Dead then
return
Expand Down Expand Up @@ -465,13 +470,18 @@ FactoryBuilderManager = Class(BuilderManager) {

---@param self FactoryBuilderManager
---@param factory Unit
---@param finishedUnit boolean
---@param finishedUnit Unit
FactoryFinishBuilding = function(self,factory,finishedUnit)
if EntityCategoryContains(categories.ENGINEER, finishedUnit) then
self.Brain.BuilderManagers[self.LocationType].EngineerManager:AddUnit(finishedUnit)
elseif EntityCategoryContains(categories.FACTORY, finishedUnit) then
self:AddFactory(finishedUnit)
end
elseif EntityCategoryContains(categories.FACTORY * categories.STRUCTURE, finishedUnit ) then
if finishedUnit:GetFractionComplete() == 1 then
self:AddFactory(finishedUnit )
factory.Dead = true
factory.Trash:Destroy()
return self:FactoryDestroyed(factory)
end
end
self:AssignBuildOrder(factory, factory.BuilderManagerData.BuilderType)
end,

Expand Down

0 comments on commit 9cde3ee

Please sign in to comment.