This commit is contained in:
FlightControl 2017-07-06 08:51:08 +02:00
parent f76ac1e03a
commit 9f5b9ab04c
3 changed files with 85 additions and 39 deletions

View File

@ -210,8 +210,7 @@ do -- CARGO
-- The state transition method needs to start with the name **OnEnter + the name of the state**. -- The state transition method needs to start with the name **OnEnter + the name of the state**.
-- These state transition methods need to provide a return value, which is specified at the function description. -- These state transition methods need to provide a return value, which is specified at the function description.
-- --
-- @field #CARGO CARGO -- @field #CARGO
--
CARGO = { CARGO = {
ClassName = "CARGO", ClassName = "CARGO",
Type = nil, Type = nil,
@ -265,6 +264,8 @@ function CARGO:New( Type, Name, Weight ) --R2.1
self.Slingloadable = false self.Slingloadable = false
self.Moveable = false self.Moveable = false
self.Containable = false self.Containable = false
self:SetDeployed( false )
self.CargoScheduler = SCHEDULER:New() self.CargoScheduler = SCHEDULER:New()
@ -276,6 +277,15 @@ function CARGO:New( Type, Name, Weight ) --R2.1
return self return self
end end
--- Destroy the cargo.
-- @param #CARGO self
function CARGO:Destroy()
if self.CargoObject then
self.CargoObject:Destroy()
end
self:Destroyed()
end
--- Get the name of the Cargo. --- Get the name of the Cargo.
-- @param #CARGO self -- @param #CARGO self
-- @return #string The name of the Cargo. -- @return #string The name of the Cargo.
@ -335,6 +345,19 @@ function CARGO:IsAlive()
end end
end end
--- Set the cargo as deployed
-- @param #CARGO self
function CARGO:SetDeployed( Deployed )
self.Deployed = Deployed
end
--- Is the cargo deployed
-- @param #CARGO self
-- @return #boolean
function CARGO:IsDeployed()
return self.Deployed
end
@ -486,6 +509,8 @@ end -- CARGO_REPRESENTABLE
local self = BASE:Inherit( self, CARGO:New( Type, Name, Weight ) ) -- #CARGO_REPORTABLE local self = BASE:Inherit( self, CARGO:New( Type, Name, Weight ) ) -- #CARGO_REPORTABLE
self:F( { Type, Name, Weight, ReportRadius } ) self:F( { Type, Name, Weight, ReportRadius } )
self.CargoSet = SET_CARGO:New() -- Core.Set#SET_CARGO
self.ReportRadius = ReportRadius or 1000 self.ReportRadius = ReportRadius or 1000
self.CargoObject = CargoObject self.CargoObject = CargoObject
@ -517,7 +542,7 @@ end -- CARGO_REPRESENTABLE
end end
--- Send a CC message to a GROUP. --- Send a CC message to a GROUP.
-- @param #COMMANDCENTER self -- @param #CARGO_REPORTABLE self
-- @param #string Message -- @param #string Message
-- @param Wrapper.Group#GROUP TaskGroup -- @param Wrapper.Group#GROUP TaskGroup
-- @param #sring Name (optional) The name of the Group used as a prefix for the message to the Group. If not provided, there will be nothing shown. -- @param #sring Name (optional) The name of the Group used as a prefix for the message to the Group. If not provided, there will be nothing shown.
@ -530,11 +555,44 @@ end -- CARGO_REPRESENTABLE
end end
--- Get the range till cargo will board. --- Get the range till cargo will board.
-- @param #CARGO self -- @param #CARGO_REPORTABLE self
-- @return #number The range till cargo will board. -- @return #number The range till cargo will board.
function CARGO_REPORTABLE:GetBoardingRange() function CARGO_REPORTABLE:GetBoardingRange()
return self.ReportRadius return self.ReportRadius
end end
--- Respawn the cargo.
-- @param #CARGO_REPORTABLE self
function CARGO_REPORTABLE:Respawn()
for CargoID, CargoData in pairs( self.CargoSet:GetSet() ) do
local Cargo = CargoData -- #CARGO
Cargo:Destroy()
end
local CargoObject = self.CargoObject -- Wrapper.Group#GROUP
local Template = CargoObject:GetTemplate()
CargoObject:Respawn( Template )
self:SetDeployed( false )
local WeightGroup = 0
for UnitID, UnitData in pairs( CargoObject:GetUnits() ) do
local Unit = UnitData -- Wrapper.Unit#UNIT
local WeightUnit = Unit:GetDesc().massEmpty
WeightGroup = WeightGroup + WeightUnit
local CargoUnit = CARGO_UNIT:New( Unit, self.Type, Unit:GetName(), WeightUnit )
self.CargoSet:Add( CargoUnit:GetName(), CargoUnit )
end
self:SetWeight( WeightGroup )
self:T( { "Weight Cargo", WeightGroup } )
self:SetStartState( "UnLoaded" )
end
end end
@ -922,8 +980,6 @@ 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( CargoGroup, Type, Name, 0, ReportRadius ) ) -- #CARGO_GROUP
self:F( { Type, Name, ReportRadius } ) self:F( { Type, Name, ReportRadius } )
self.CargoSet = SET_CARGO:New()
self.CargoObject = CargoGroup self.CargoObject = CargoGroup
self:SetDeployed( false ) self:SetDeployed( false )
@ -1051,19 +1107,6 @@ function CARGO_GROUP:GetCount()
return self.CargoSet:Count() return self.CargoSet:Count()
end end
--- Set the cargo as deployed
-- @param #CARGO_GROUP self
function CARGO_GROUP:SetDeployed( Deployed )
self.Deployed = Deployed
end
--- Is the cargo deployed
-- @param #CARGO_GROUP self
-- @return #boolean
function CARGO_GROUP:IsDeployed()
return self.Deployed
end
--- Enter UnBoarding State. --- Enter UnBoarding State.
-- @param #CARGO_GROUP self -- @param #CARGO_GROUP self

View File

@ -2748,13 +2748,13 @@ SET_CARGO = {
--- (R2.1) Creates a new SET_CARGO object, building a set of cargos belonging to a coalitions and categories. --- (R2.1) Creates a new SET_CARGO object, building a set of cargos belonging to a coalitions and categories.
-- @param #SET_CARGO self -- @param #SET_CARGO self
-- @return #SET_CARGO self -- @return #SET_CARGO
-- @usage -- @usage
-- -- Define a new SET_CARGO Object. The DatabaseSet will contain a reference to all Cargos. -- -- Define a new SET_CARGO Object. The DatabaseSet will contain a reference to all Cargos.
-- DatabaseSet = SET_CARGO:New() -- DatabaseSet = SET_CARGO:New()
function SET_CARGO:New() --R2.1 function SET_CARGO:New() --R2.1
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, SET_BASE:New( _DATABASE.CARGOS ) ) local self = BASE:Inherit( self, SET_BASE:New( _DATABASE.CARGOS ) ) -- #SET_CARGO
return self return self
end end

View File

@ -869,25 +869,28 @@ end
-- @param #table Template The template of the Group retrieved with GROUP:GetTemplate() -- @param #table Template The template of the Group retrieved with GROUP:GetTemplate()
function GROUP:Respawn( Template ) function GROUP:Respawn( Template )
local Vec3 = self:GetVec3() if self:IsAlive() then
Template.x = Vec3.x local Vec3 = self:GetVec3()
Template.y = Vec3.z Template.x = Vec3.x
--Template.x = nil Template.y = Vec3.z
--Template.y = nil --Template.x = nil
--Template.y = nil
self:E( #Template.units )
for UnitID, UnitData in pairs( self:GetUnits() ) do self:E( #Template.units )
local GroupUnit = UnitData -- Wrapper.Unit#UNIT for UnitID, UnitData in pairs( self:GetUnits() ) do
self:E( GroupUnit:GetName() ) local GroupUnit = UnitData -- Wrapper.Unit#UNIT
if GroupUnit:IsAlive() then self:E( GroupUnit:GetName() )
local GroupUnitVec3 = GroupUnit:GetVec3() if GroupUnit:IsAlive() then
local GroupUnitHeading = GroupUnit:GetHeading() local GroupUnitVec3 = GroupUnit:GetVec3()
Template.units[UnitID].alt = GroupUnitVec3.y local GroupUnitHeading = GroupUnit:GetHeading()
Template.units[UnitID].x = GroupUnitVec3.x Template.units[UnitID].alt = GroupUnitVec3.y
Template.units[UnitID].y = GroupUnitVec3.z Template.units[UnitID].x = GroupUnitVec3.x
Template.units[UnitID].heading = GroupUnitHeading Template.units[UnitID].y = GroupUnitVec3.z
self:E( { UnitID, Template.units[UnitID], Template.units[UnitID] } ) Template.units[UnitID].heading = GroupUnitHeading
self:E( { UnitID, Template.units[UnitID], Template.units[UnitID] } )
end
end end
end end
self:Destroy() self:Destroy()