mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
fix cleanup of crates on load or build.
This commit is contained in:
parent
3e5926f706
commit
8d3910ea4c
@ -2145,24 +2145,39 @@ function CTLD:_LoadCratesNearby(Group, Unit)
|
|||||||
self.Loaded_Cargo[unitname] = loaded
|
self.Loaded_Cargo[unitname] = loaded
|
||||||
self:_UpdateUnitCargoMass(Unit)
|
self:_UpdateUnitCargoMass(Unit)
|
||||||
-- clean up real world crates
|
-- clean up real world crates
|
||||||
local existingcrates = self.Spawned_Cargo -- #table
|
self:_CleanupTrackedCrates(crateidsloaded)
|
||||||
local newexcrates = {}
|
|
||||||
for _,_crate in pairs(existingcrates) do
|
|
||||||
local excrate = _crate -- #CTLD_CARGO
|
|
||||||
local ID = excrate:GetID()
|
|
||||||
for _,_ID in pairs(crateidsloaded) do
|
|
||||||
if ID ~= _ID then
|
|
||||||
table.insert(newexcrates,_crate)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.Spawned_Cargo = nil
|
|
||||||
self.Spawned_Cargo = newexcrates
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- (Internal) Function to clean up tracked cargo crates
|
||||||
|
function CTLD:_CleanupTrackedCrates(crateIdsToRemove)
|
||||||
|
local existingcrates = self.Spawned_Cargo -- #table
|
||||||
|
local newexcrates = {}
|
||||||
|
for _,_crate in pairs(existingcrates) do
|
||||||
|
local excrate = _crate -- #CTLD_CARGO
|
||||||
|
local ID = excrate:GetID()
|
||||||
|
local keep = true
|
||||||
|
for _,_ID in pairs(crateIdsToRemove) do
|
||||||
|
if ID == _ID then
|
||||||
|
keep = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- remove destroyed crates here too
|
||||||
|
local static = _crate:GetPositionable() -- Wrapper.Static#STATIC -- crates
|
||||||
|
if not static or not static:IsAlive() then
|
||||||
|
keep = false
|
||||||
|
end
|
||||||
|
if keep then
|
||||||
|
table.insert(newexcrates,_crate)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.Spawned_Cargo = nil
|
||||||
|
self.Spawned_Cargo = newexcrates
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
--- (Internal) Function to get current loaded mass
|
--- (Internal) Function to get current loaded mass
|
||||||
-- @param #CTLD self
|
-- @param #CTLD self
|
||||||
-- @param Wrapper.Unit#UNIT Unit
|
-- @param Wrapper.Unit#UNIT Unit
|
||||||
@ -2849,19 +2864,7 @@ function CTLD:_CleanUpCrates(Crates,Build,Number)
|
|||||||
if found == numberdest then break end -- got enough
|
if found == numberdest then break end -- got enough
|
||||||
end
|
end
|
||||||
-- loop and remove from real world representation
|
-- loop and remove from real world representation
|
||||||
for _,_crate in pairs(existingcrates) do
|
self:_CleanupTrackedCrates(destIDs)
|
||||||
local excrate = _crate -- #CTLD_CARGO
|
|
||||||
local ID = excrate:GetID()
|
|
||||||
for _,_ID in pairs(destIDs) do
|
|
||||||
if ID ~= _ID then
|
|
||||||
table.insert(newexcrates,_crate)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- reset Spawned_Cargo
|
|
||||||
self.Spawned_Cargo = nil
|
|
||||||
self.Spawned_Cargo = newexcrates
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user