-- Fixing respawning of CargoGroups after dead event.

This commit is contained in:
FlightControl_Master 2018-03-29 12:48:24 +02:00
parent 93640b1d8e
commit 35f18d0d1f

View File

@ -535,8 +535,7 @@ function CARGO:SetWeight( Weight )
return self return self
end end
end end -- CARGO
do -- CARGO_REPRESENTABLE do -- CARGO_REPRESENTABLE
@ -989,7 +988,6 @@ do -- CARGO_UNIT
end -- CARGO_UNIT end -- CARGO_UNIT
do -- CARGO_CRATE do -- CARGO_CRATE
--- Models the behaviour of cargo crates, which can be slingloaded and boarded on helicopters using the DCS menus. --- Models the behaviour of cargo crates, which can be slingloaded and boarded on helicopters using the DCS menus.
@ -1127,16 +1125,17 @@ function CARGO_GROUP:New( CargoGroup, Type, Name, ReportRadius )
self:SetDeployed( false ) self:SetDeployed( false )
local WeightGroup = 0 local WeightGroup = 0
local GroupName = CargoGroup:GetName()
self.GroupName = CargoGroup:GetName()
self.CargoTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplate( self.GroupName ) )
CargoGroup:Destroy() CargoGroup:Destroy()
-- We iterate through the group template and for each unit in the template, we create a new group with one unit. -- We iterate through the group template and for each unit in the template, we create a new group with one unit.
for UnitID, UnitTemplate in pairs( _DATABASE:GetGroupTemplate(GroupName).units ) do for UnitID, UnitTemplate in pairs( self.CargoTemplate.units ) do
local GroupTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplate(GroupName) ) local GroupTemplate = UTILS.DeepCopy( self.CargoTemplate )
local GroupName = env.getValueDictByKey( GroupTemplate.name ) local GroupName = env.getValueDictByKey( GroupTemplate.name )
self:E( GroupName )
-- We create a new group object with one unit... -- We create a new group object with one unit...
-- First we prepare the template... -- First we prepare the template...
@ -1565,15 +1564,38 @@ function CARGO_GROUP:OnEventCargoDead( EventData )
Cargo:SetStartState( "UnLoaded" ) Cargo:SetStartState( "UnLoaded" )
end end
local CargoObject = self.CargoObject -- Wrapper.Group#GROUP
CargoObject:Destroy() -- We iterate through the group template and for each unit in the template, we create a new group with one unit.
local Template = CargoObject:GetTemplate() for UnitID, UnitTemplate in pairs( self.CargoTemplate.units ) do
CargoObject:Respawn( Template )
local GroupTemplate = UTILS.DeepCopy( self.CargoTemplate )
local GroupName = env.getValueDictByKey( GroupTemplate.name )
-- We create a new group object with one unit...
-- First we prepare the template...
GroupTemplate.name = GroupName .. "#CARGO#" .. UnitID
GroupTemplate.groupId = nil
GroupTemplate.units = {}
GroupTemplate.units[1] = UnitTemplate
local UnitName = UnitTemplate.name .. "#CARGO"
GroupTemplate.units[1].name = UnitTemplate.name .. "#CARGO"
-- Then we register the new group in the database
local CargoGroup = GROUP:NewTemplate( GroupTemplate, GroupTemplate.CoalitionID, GroupTemplate.CategoryID, GroupTemplate.CountryID)
-- Now we spawn the new group based on the template created.
_DATABASE:Spawn( GroupTemplate )
-- And we register the spawned unit as part of the CargoSet.
local Unit = UNIT:FindByName( UnitName )
--local WeightUnit = Unit:GetDesc().massEmpty
--WeightGroup = WeightGroup + WeightUnit
local CargoUnit = CARGO_UNIT:New( Unit, Type, UnitName, 10 )
self.CargoSet:Add( UnitName, CargoUnit )
end
self:SetDeployed( false ) self:SetDeployed( false )
local WeightGroup = 0
self:SetStartState( "UnLoaded" ) self:SetStartState( "UnLoaded" )
end end