After a rapid look, since i don't have your unit bp and i can't test changes, you may check theses parts :
- Code: Select all
DroneSetup2 = function(self)
-- Drone handle table, used to issue orders to all drones at once
self.DroneTable = {}
When you call your code part at the enhancement, you clear the current DroneTable to be replaced with your own. But what about the 2 existing BO drones ?
You call again some maintenance existing thread, and that not quite good for code stability.
Here is the tread that orders drone repairs then rebuild. If your drones don't rebuild, there is something that should be wrong in the rebuild conditions.
- Code: Select all
DroneMaintenanceState = State {
Main = function(self)
self.DroneMaintenance = true
-- Resume any interrupted drone rebuilds
if self.BuildingDrone then
ChangeState(self, self.DroneRebuildingState)
end
-- Check for dead or damaged drones
while self and not self:IsDead() and not self.BuildingDrone do
for droneName, droneData in self.DroneData do
if not droneData.Active or (droneData.Active and droneData.Damaged and droneData.Docked) then
self.BuildingDrone = droneName
ChangeState(self, self.DroneRebuildingState)
end
end
WaitTicks(2)
end
end,
OnPaused = function(self)
ChangeState(self, self.PausedState)
end,
},
So Im not sure that theses conditions are valid after your setup2 :
- Code: Select all
if not droneData.Active or (droneData.Active and droneData.Damaged and droneData.Docked) then
So a simple fix maybe use the table.insert function instead a clear and deepcopy
So your setup2 (you should change the name of setup2 by a more reco name) should be modified
So your setup2 code part :
- Code: Select all
-- Initial drone setup - loads globals, DroneData table, and creates drones
DroneSetup2 = function(self)
-- Drone handle table, used to issue orders to all drones at once
self.DroneTable = {}
-- Drone construction globals
self.BuildingDrone = false
self.ControlRange = self:GetBlueprint().AI.DroneControlRange or 70
self.ReturnRange = self:GetBlueprint().AI.DroneReturnRange or (ControlRange / 2)
self.AssistRange = self.ControlRange + 10
self.AirMonitorRange = self:GetBlueprint().AI.AirMonitorRange or (self.AssistRange / 2)
self.HeartBeatInterval = self:GetBlueprint().AI.AssistHeartbeatInterval or 1
self.DroneData = table.deepcopy(self:GetBlueprint().DroneData2)
-- Load other data from drone BP and spawn drones
for droneName, droneData in self.DroneData do
-- Set drone name variable
if not droneData.Name then
droneData.Name = droneName
end
droneData.Blueprint = table.deepcopy(GetUnitBlueprintByName(droneData.UnitID))
droneData.Economy = droneData.Blueprint.Economy
droneData.BuildProgress = 1
-- Create this drone
self:ForkThread(self.CreateDrone, droneName)
end
-- Assist/monitor heartbeat thread
self.HeartBeatThread = self:ForkThread(self.AssistHeartBeat)
-- Begin drone maintenance monitoring
ChangeState(self, self.DroneMaintenanceState)
end,
Should be more like this one :
- Code: Select all
-- Enh new drone setup - creates 2 new drones from enh
AddingEnhDronesSetup = function(self)
local NewdronesFromEnh = table.deepcopy(self:GetBlueprint().DroneData2)
table.insert(self.DroneTable, NewdronesFromEnh)
-- Load other data from drone BP and spawn drones from enh
for droneName, droneData in NewdronesFromEnh do
-- Set drone name variable
if not droneData.Name then
droneData.Name = droneName
end
droneData.Blueprint = table.deepcopy(GetUnitBlueprintByName(droneData.UnitID))
droneData.Economy = droneData.Blueprint.Economy
droneData.BuildProgress = 1
-- Create this drone
self:ForkThread(self.CreateDrone, droneName)
end
end,
I can't test this code, but it should give you some help and direction for fixing your code.