Cargo is now respawning correctly when:

The cargo is destroyed
The carrier crashes with cargo on board
The player exits the carrier with cargo on board.
This commit is contained in:
FlightControl 2017-07-06 17:00:53 +02:00
parent 71da9933d7
commit 532a311db6

View File

@ -581,6 +581,7 @@ end -- CARGO_REPRESENTABLE
end end
local CargoObject = self.CargoObject -- Wrapper.Group#GROUP local CargoObject = self.CargoObject -- Wrapper.Group#GROUP
CargoObject:Destroy()
local Template = CargoObject:GetTemplate() local Template = CargoObject:GetTemplate()
CargoObject:Respawn( Template ) CargoObject:Respawn( Template )
@ -632,16 +633,16 @@ function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, NearRadius )
self:T( self.ClassName ) self:T( self.ClassName )
self:HandleEvent( EVENTS.Dead, -- self:HandleEvent( EVENTS.Dead,
--- @param #CARGO Cargo -- --- @param #CARGO Cargo
-- @param Core.Event#EVENTDATA EventData -- -- @param Core.Event#EVENTDATA EventData
function( Cargo, EventData ) -- function( Cargo, EventData )
if Cargo:GetObjectName() == EventData.IniUnit:GetName() then -- if Cargo:GetObjectName() == EventData.IniUnit:GetName() then
self:E( { "Cargo destroyed", Cargo } ) -- self:E( { "Cargo destroyed", Cargo } )
Cargo:Destroyed() -- Cargo:Destroyed()
end -- end
end -- end
) -- )
self:SetEventPriority( 5 ) self:SetEventPriority( 5 )
@ -984,6 +985,7 @@ function CARGO_GROUP:New( CargoGroup, Type, Name, ReportRadius )
self.CargoObject = CargoGroup self.CargoObject = CargoGroup
self:SetDeployed( false ) self:SetDeployed( false )
self.CargoGroup = CargoGroup
local WeightGroup = 0 local WeightGroup = 0
@ -1002,12 +1004,23 @@ function CARGO_GROUP:New( CargoGroup, Type, Name, ReportRadius )
-- Cargo objects are added to the _DATABASE and SET_CARGO objects. -- Cargo objects are added to the _DATABASE and SET_CARGO objects.
_EVENTDISPATCHER:CreateEventNewCargo( self ) _EVENTDISPATCHER:CreateEventNewCargo( self )
self:HandleEvent( EVENTS.Dead, self:HandleEvent( EVENTS.Dead, self.OnEventCargoDead )
--- @param #CARGO Cargo self:HandleEvent( EVENTS.Crash, self.OnEventCargoDead )
-- @param Core.Event#EVENTDATA EventData self:HandleEvent( EVENTS.PlayerLeaveUnit, self.OnEventCargoDead )
function( Cargo, EventData )
local Destroyed = true self:SetEventPriority( 4 )
return self
end
--- @param #CARGO Cargo
-- @param Core.Event#EVENTDATA EventData
function CARGO_GROUP:OnEventCargoDead( EventData )
local Destroyed = false
if self:IsDestroyed() or self:IsUnLoaded() then
Destroyed = true
for CargoID, CargoData in pairs( self.CargoSet:GetSet() ) do for CargoID, CargoData in pairs( self.CargoSet:GetSet() ) do
local Cargo = CargoData -- #CARGO local Cargo = CargoData -- #CARGO
if Cargo:IsAlive() then if Cargo:IsAlive() then
@ -1016,17 +1029,17 @@ function CARGO_GROUP:New( CargoGroup, Type, Name, ReportRadius )
Cargo:Destroyed() Cargo:Destroyed()
end end
end end
else
if self.CargoCarrier:GetName() == EventData.IniUnitName then
Destroyed = true
end
end
if Destroyed then if Destroyed then
self:Destroyed() self:Destroyed()
self:E( { "Cargo destroyed", Cargo } ) self:E( { "Cargo group destroyed" } )
end end
end
)
self:SetEventPriority( 4 )
return self
end end
--- Enter Boarding State. --- Enter Boarding State.
@ -1070,7 +1083,7 @@ function CARGO_GROUP:onenterLoaded( From, Event, To, CargoCarrier, ... )
end end
end end
self.CargoObject:Destroy() --self.CargoObject:Destroy()
self.CargoCarrier = CargoCarrier self.CargoCarrier = CargoCarrier
end end