Progress on the new cargo group movements

This commit is contained in:
FlightControl_Master 2018-03-24 07:32:04 +01:00
parent 25659647a6
commit ca32c57c52
3 changed files with 47 additions and 18 deletions

View File

@ -1,5 +1,7 @@
--- **Core** -- Management of CARGO logistics, that can be transported from and to transportation carriers.
--
-- ===
--
-- ![Banner Image](..\Presentations\CARGO\Dia1.JPG)
--
-- ===
@ -602,23 +604,19 @@ end -- CARGO_REPRESENTABLE
--- CARGO_REPORTABLE Constructor.
-- @param #CARGO_REPORTABLE self
-- @param Wrapper.Controllable#Controllable CargoObject
-- @param #string Type
-- @param #string Name
-- @param #number Weight
-- @param #number ReportRadius (optional)
-- @param #number NearRadius (optional)
-- @return #CARGO_REPORTABLE
function CARGO_REPORTABLE:New( CargoObject, Type, Name, Weight, ReportRadius )
function CARGO_REPORTABLE:New( Type, Name, Weight, ReportRadius )
local self = BASE:Inherit( self, CARGO:New( Type, Name, Weight ) ) -- #CARGO_REPORTABLE
self:F( { Type, Name, Weight, ReportRadius } )
self.CargoSet = SET_CARGO:New() -- Core.Set#SET_CARGO
self.ReportRadius = ReportRadius or 1000
self.CargoObject = CargoObject
return self
end
@ -776,8 +774,9 @@ do -- CARGO_UNIT
-- Respawn the group...
if self.CargoObject then
self:F( { CargoObject = self.CargoObject } )
self.CargoObject:ReSpawn( CargoDeployPointVec2:GetVec3(), CargoDeployHeading )
self:F( { "CargoUnits:", self.CargoObject:GetGroup():GetName() } )
--self:F( { "CargoUnits:", self.CargoObject:GetGroup():GetName() } )
self.CargoCarrier = nil
local Points = {}
@ -1150,6 +1149,8 @@ do -- CARGO_GROUP
}
--- CARGO_GROUP constructor.
-- This make a new CARGO_GROUP from a @{Group} object.
-- It will "ungroup" the group object within the sim, and will create a @{Set} of individual Unit objects.
-- @param #CARGO_GROUP self
-- @param Wrapper.Group#GROUP CargoGroup
-- @param #string Type
@ -1158,23 +1159,47 @@ do -- CARGO_GROUP
-- @param #number NearRadius (optional)
-- @return #CARGO_GROUP
function CARGO_GROUP:New( CargoGroup, Type, Name, ReportRadius )
local self = BASE:Inherit( self, CARGO_REPORTABLE:New( CargoGroup, Type, Name, 0, ReportRadius ) ) -- #CARGO_GROUP
local self = BASE:Inherit( self, CARGO_REPORTABLE:New( Type, Name, 0, ReportRadius ) ) -- #CARGO_GROUP
self:F( { Type, Name, ReportRadius } )
self.CargoObject = CargoGroup
self:SetDeployed( false )
self.CargoGroup = CargoGroup
local WeightGroup = 0
local GroupName = CargoGroup:GetName()
for UnitID, UnitData in pairs( CargoGroup:GetUnits() ) do
local Unit = UnitData -- Wrapper.Unit#UNIT
local WeightUnit = Unit:GetDesc().massEmpty
WeightGroup = WeightGroup + WeightUnit
local CargoUnit = CARGO_UNIT:New( Unit, Type, Unit:GetName(), WeightUnit )
self.CargoSet:Add( CargoUnit:GetName(), CargoUnit )
CargoGroup:Destroy()
-- 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
local GroupTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplate(GroupName) )
local GroupName = env.getValueDictByKey( GroupTemplate.name )
self:E( GroupName )
-- We create a new group object with one unit...
-- First we prepare the template...
GroupTemplate.name = GroupName .. "#CARGO#" .. UnitID
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:SetWeight( WeightGroup )
self:T( { "Weight Cargo", WeightGroup } )
@ -1355,7 +1380,7 @@ function CARGO_GROUP:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius
function( Cargo, NearRadius )
Cargo:__UnBoard( Timer, ToPointVec2, NearRadius )
Timer = Timer + 10
Timer = Timer + 1
end, { NearRadius }
)

View File

@ -336,7 +336,7 @@ end
-- @param #number UnitNumber The number of the UNIT wrapper class to be returned.
-- @return Wrapper.Unit#UNIT The UNIT wrapper class.
function GROUP:GetUnit( UnitNumber )
self:F2( { self.GroupName, UnitNumber } )
self:E( { self.GroupName, UnitNumber } )
local DCSGroup = self:GetDCSObject()

View File

@ -193,10 +193,12 @@ end
-- @param #number Heading The heading of the unit respawn.
function UNIT:ReSpawn( SpawnVec3, Heading )
self:T( self:Name() )
local SpawnGroupTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplateFromUnitName( self:Name() ) )
self:T( SpawnGroupTemplate )
local SpawnGroup = self:GetGroup()
self:T( { SpawnGroup = SpawnGroup } )
if SpawnGroup then
@ -221,7 +223,7 @@ function UNIT:ReSpawn( SpawnVec3, Heading )
end
for UnitTemplateID, UnitTemplateData in pairs( SpawnGroupTemplate.units ) do
self:T( UnitTemplateData.name )
self:T( { UnitTemplateData.name, self:Name() } )
if UnitTemplateData.name == self:Name() then
self:T("Adjusting")
SpawnGroupTemplate.units[UnitTemplateID].alt = SpawnVec3.y
@ -261,6 +263,8 @@ function UNIT:ReSpawn( SpawnVec3, Heading )
i = i + 1
end
end
self:T( SpawnGroupTemplate )
_DATABASE:Spawn( SpawnGroupTemplate )
end