From 9f5b9ab04ccf7bf273e3b1544a1f2433aea9c63b Mon Sep 17 00:00:00 2001 From: FlightControl Date: Thu, 6 Jul 2017 08:51:08 +0200 Subject: [PATCH] Progress --- Moose Development/Moose/Core/Cargo.lua | 81 +++++++++++++++++------ Moose Development/Moose/Core/Set.lua | 4 +- Moose Development/Moose/Wrapper/Group.lua | 39 ++++++----- 3 files changed, 85 insertions(+), 39 deletions(-) diff --git a/Moose Development/Moose/Core/Cargo.lua b/Moose Development/Moose/Core/Cargo.lua index 1ce873dcb..0741e867a 100644 --- a/Moose Development/Moose/Core/Cargo.lua +++ b/Moose Development/Moose/Core/Cargo.lua @@ -210,8 +210,7 @@ do -- CARGO -- 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. -- - -- @field #CARGO CARGO - -- + -- @field #CARGO CARGO = { ClassName = "CARGO", Type = nil, @@ -265,6 +264,8 @@ function CARGO:New( Type, Name, Weight ) --R2.1 self.Slingloadable = false self.Moveable = false self.Containable = false + + self:SetDeployed( false ) self.CargoScheduler = SCHEDULER:New() @@ -276,6 +277,15 @@ function CARGO:New( Type, Name, Weight ) --R2.1 return self 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. -- @param #CARGO self -- @return #string The name of the Cargo. @@ -335,6 +345,19 @@ function CARGO:IsAlive() 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 self:F( { Type, Name, Weight, ReportRadius } ) + self.CargoSet = SET_CARGO:New() -- Core.Set#SET_CARGO + self.ReportRadius = ReportRadius or 1000 self.CargoObject = CargoObject @@ -517,7 +542,7 @@ end -- CARGO_REPRESENTABLE end --- Send a CC message to a GROUP. - -- @param #COMMANDCENTER self + -- @param #CARGO_REPORTABLE self -- @param #string Message -- @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. @@ -530,11 +555,44 @@ end -- CARGO_REPRESENTABLE end --- Get the range till cargo will board. - -- @param #CARGO self + -- @param #CARGO_REPORTABLE self -- @return #number The range till cargo will board. function CARGO_REPORTABLE:GetBoardingRange() return self.ReportRadius 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 @@ -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 self:F( { Type, Name, ReportRadius } ) - self.CargoSet = SET_CARGO:New() - self.CargoObject = CargoGroup self:SetDeployed( false ) @@ -1051,19 +1107,6 @@ function CARGO_GROUP:GetCount() return self.CargoSet:Count() 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. -- @param #CARGO_GROUP self diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index 0152e5cb8..3b8ece2df 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -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. -- @param #SET_CARGO self --- @return #SET_CARGO self +-- @return #SET_CARGO -- @usage -- -- Define a new SET_CARGO Object. The DatabaseSet will contain a reference to all Cargos. -- DatabaseSet = SET_CARGO:New() function SET_CARGO:New() --R2.1 -- 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 end diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 8e1deed6e..652e13c7e 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -869,25 +869,28 @@ end -- @param #table Template The template of the Group retrieved with GROUP:GetTemplate() function GROUP:Respawn( Template ) - local Vec3 = self:GetVec3() - Template.x = Vec3.x - Template.y = Vec3.z - --Template.x = nil - --Template.y = nil - - self:E( #Template.units ) - for UnitID, UnitData in pairs( self:GetUnits() ) do - local GroupUnit = UnitData -- Wrapper.Unit#UNIT - self:E( GroupUnit:GetName() ) - if GroupUnit:IsAlive() then - local GroupUnitVec3 = GroupUnit:GetVec3() - local GroupUnitHeading = GroupUnit:GetHeading() - Template.units[UnitID].alt = GroupUnitVec3.y - Template.units[UnitID].x = GroupUnitVec3.x - Template.units[UnitID].y = GroupUnitVec3.z - Template.units[UnitID].heading = GroupUnitHeading - self:E( { UnitID, Template.units[UnitID], Template.units[UnitID] } ) + if self:IsAlive() then + local Vec3 = self:GetVec3() + Template.x = Vec3.x + Template.y = Vec3.z + --Template.x = nil + --Template.y = nil + + self:E( #Template.units ) + for UnitID, UnitData in pairs( self:GetUnits() ) do + local GroupUnit = UnitData -- Wrapper.Unit#UNIT + self:E( GroupUnit:GetName() ) + if GroupUnit:IsAlive() then + local GroupUnitVec3 = GroupUnit:GetVec3() + local GroupUnitHeading = GroupUnit:GetHeading() + Template.units[UnitID].alt = GroupUnitVec3.y + Template.units[UnitID].x = GroupUnitVec3.x + Template.units[UnitID].y = GroupUnitVec3.z + Template.units[UnitID].heading = GroupUnitHeading + self:E( { UnitID, Template.units[UnitID], Template.units[UnitID] } ) + end end + end self:Destroy()