From ca32c57c52b83aa4e20fd3c17a0d8d0c06c9df27 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Sat, 24 Mar 2018 07:32:04 +0100 Subject: [PATCH 1/5] Progress on the new cargo group movements --- Moose Development/Moose/Core/Cargo.lua | 57 ++++++++++++++++------- Moose Development/Moose/Wrapper/Group.lua | 2 +- Moose Development/Moose/Wrapper/Unit.lua | 6 ++- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/Moose Development/Moose/Core/Cargo.lua b/Moose Development/Moose/Core/Cargo.lua index 991669931..495938e77 100644 --- a/Moose Development/Moose/Core/Cargo.lua +++ b/Moose Development/Moose/Core/Cargo.lua @@ -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 } ) diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index f46c2701b..0606b14a0 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -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() diff --git a/Moose Development/Moose/Wrapper/Unit.lua b/Moose Development/Moose/Wrapper/Unit.lua index 26d30ed91..695774052 100644 --- a/Moose Development/Moose/Wrapper/Unit.lua +++ b/Moose Development/Moose/Wrapper/Unit.lua @@ -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 From 7963f04bdc41576227ea29c6e2cc0bba7ca665a8 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Sat, 24 Mar 2018 08:01:49 +0100 Subject: [PATCH 2/5] progress --- Moose Development/Moose/Core/Cargo.lua | 11 +++++++---- Moose Development/Moose/Core/Point.lua | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Moose Development/Moose/Core/Cargo.lua b/Moose Development/Moose/Core/Cargo.lua index 495938e77..7a1949fbc 100644 --- a/Moose Development/Moose/Core/Cargo.lua +++ b/Moose Development/Moose/Core/Cargo.lua @@ -261,7 +261,7 @@ function CARGO:New( Type, Name, Weight ) --R2.1 self.Name = Name self.Weight = Weight self.CargoObject = nil - self.CargoCarrier = nil + self.CargoCarrier = nil -- Wrapper.Client#CLIENT self.Representable = false self.Slingloadable = false self.Moveable = false @@ -753,7 +753,7 @@ do -- CARGO_UNIT if From == "Loaded" then - local CargoCarrier = self.CargoCarrier -- Wrapper.Controllable#CONTROLLABLE + local CargoCarrier = self.CargoCarrier -- Wrapper.Client#CLIENT local CargoCarrierPointVec2 = CargoCarrier:GetPointVec2() local CargoCarrierHeading = self.CargoCarrier:GetHeading() -- Get Heading of object in degrees. @@ -764,11 +764,12 @@ do -- CARGO_UNIT -- if there is no ToPointVec2 given, then use the CargoRoutePointVec2 - ToPointVec2 = ToPointVec2 or CargoRoutePointVec2 + ToPointVec2 = ToPointVec2 or CargoCarrierPointVec2:GetRandomCoordinateInRadius( NearRadius, 5 ) local DirectionVec3 = CargoCarrierPointVec2:GetDirectionVec3(ToPointVec2) local Angle = CargoCarrierPointVec2:GetAngleDegrees(DirectionVec3) local CargoDeployPointVec2 = CargoCarrierPointVec2:Translate( DeployDistance, Angle ) + local CargoDeployPointVec2 = CargoCarrierPointVec2:GetRandomCoordinateInRadius( NearRadius, 5 ) local FromPointVec2 = CargoCarrierPointVec2 @@ -937,7 +938,7 @@ do -- CARGO_UNIT -- @param #string Event -- @param #string From -- @param #string To - -- @param Wrapper.Unit#UNIT CargoCarrier + -- @param Wrapper.Client#CLIENT CargoCarrier -- @param #number NearRadius function CARGO_UNIT:onafterBoarding( From, Event, To, CargoCarrier, NearRadius, ... ) self:F( { From, Event, To, CargoCarrier.UnitName, NearRadius } ) @@ -1366,6 +1367,8 @@ function CARGO_GROUP:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius self:F( {From, Event, To, ToPointVec2, NearRadius } ) NearRadius = NearRadius or 25 + + local CargoCarrier = self.CargoCarrier -- Wrapper.Client#CLIENT local Timer = 1 diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index b5556abea..f3eb0b5b7 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -303,6 +303,18 @@ do -- COORDINATE end + --- Return a random Coordinate within an Outer Radius and optionally NOT within an Inner Radius of the COORDINATE. + -- @param #COORDINATE self + -- @param Dcs.DCSTypes#Distance OuterRadius + -- @param Dcs.DCSTypes#Distance InnerRadius + -- @return #COORDINATE + function COORDINATE:GetRandomCoordinateInRadius( OuterRadius, InnerRadius ) + self:F2( { OuterRadius, InnerRadius } ) + + return COORDINATE:NewFromVec2( self:GetRandomVec2InRadius( OuterRadius, InnerRadius ) ) + end + + --- Return a random Vec3 within an Outer Radius and optionally NOT within an Inner Radius of the COORDINATE. -- @param #COORDINATE self -- @param Dcs.DCSTypes#Distance OuterRadius From 7a8881974caa8b340eb235954b36892739e5fb77 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Wed, 28 Mar 2018 16:42:37 +0200 Subject: [PATCH 3/5] Optimizations of cargo deployment. --- .../Moose/AI/AI_Cargo_Troops.lua | 10 +++---- Moose Development/Moose/Core/Cargo.lua | 27 ++++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Cargo_Troops.lua b/Moose Development/Moose/AI/AI_Cargo_Troops.lua index defb6bd81..f0d524be3 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Troops.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Troops.lua @@ -148,7 +148,7 @@ function AI_CARGO_TROOPS:onafterLoad( CargoCarrier, From, Event, To ) if CargoCarrier and CargoCarrier:IsAlive() then CargoCarrier:RouteStop() - self:Board() + self:__Board( 10 ) self.CargoGroup:Board( CargoCarrier, 25 ) end @@ -162,7 +162,7 @@ function AI_CARGO_TROOPS:onafterBoard( CargoCarrier, From, Event, To ) if CargoCarrier and CargoCarrier:IsAlive() then self:F({ IsLoaded = self.CargoGroup:IsLoaded() } ) if not self.CargoGroup:IsLoaded() then - self:__Board( 1 ) + self:__Board( 10 ) else self:__Loaded( 1 ) end @@ -190,7 +190,7 @@ function AI_CARGO_TROOPS:onafterUnload( CargoCarrier, From, Event, To ) if CargoCarrier and CargoCarrier:IsAlive() then CargoCarrier:RouteStop() self.CargoGroup:UnBoard( ) - self:__Unboard( 1 ) + self:__Unboard( 10 ) end end @@ -202,9 +202,9 @@ function AI_CARGO_TROOPS:onafterUnboard( CargoCarrier, From, Event, To ) if CargoCarrier and CargoCarrier:IsAlive() then if not self.CargoGroup:IsUnLoaded() then - self:__Unboard( 1 ) + self:__Unboard( 10 ) else - self:Unloaded() + self:__Unloaded( 1 ) end end diff --git a/Moose Development/Moose/Core/Cargo.lua b/Moose Development/Moose/Core/Cargo.lua index 8cfa3037f..e0a42c690 100644 --- a/Moose Development/Moose/Core/Cargo.lua +++ b/Moose Development/Moose/Core/Cargo.lua @@ -771,25 +771,26 @@ do -- CARGO_UNIT -- if there is no ToPointVec2 given, then use the CargoRoutePointVec2 - ToPointVec2 = ToPointVec2 or CargoCarrierPointVec2:GetRandomCoordinateInRadius( NearRadius, 5 ) - local DirectionVec3 = CargoCarrierPointVec2:GetDirectionVec3(ToPointVec2) - local Angle = CargoCarrierPointVec2:GetAngleDegrees(DirectionVec3) - - local CargoDeployPointVec2 = CargoCarrierPointVec2:Translate( DeployDistance, Angle ) - local CargoDeployPointVec2 = CargoCarrierPointVec2:GetRandomCoordinateInRadius( NearRadius, 5 ) + local FromDirectionVec3 = CargoCarrierPointVec2:GetDirectionVec3( ToPointVec2 or CargoRoutePointVec2 ) + local FromAngle = CargoCarrierPointVec2:GetAngleDegrees(FromDirectionVec3) + local FromPointVec2 = CargoCarrierPointVec2:Translate( DeployDistance, FromAngle ) + --local CargoDeployPointVec2 = CargoCarrierPointVec2:GetRandomCoordinateInRadius( 10, 5 ) + + ToPointVec2 = ToPointVec2 or CargoCarrierPointVec2:GetRandomCoordinateInRadius( NearRadius, DeployDistance ) - local FromPointVec2 = CargoCarrierPointVec2 - -- Respawn the group... if self.CargoObject then - self.CargoObject:ReSpawn( CargoDeployPointVec2:GetVec3(), CargoDeployHeading ) + self.CargoObject:ReSpawn( FromPointVec2:GetVec3(), CargoDeployHeading ) self:F( { "CargoUnits:", self.CargoObject:GetGroup():GetName() } ) self.CargoCarrier = nil local Points = {} - Points[#Points+1] = CargoCarrierPointVec2:WaypointGround( Speed ) - Points[#Points+1] = ToPointVec2:WaypointGround( Speed ) + -- From + Points[#Points+1] = FromPointVec2:WaypointGround( Speed, "Vee" ) + + -- To + Points[#Points+1] = ToPointVec2:WaypointGround( Speed, "Vee" ) local TaskRoute = self.CargoObject:TaskRoute( Points ) self.CargoObject:SetTask( TaskRoute, 1 ) @@ -1375,7 +1376,7 @@ function CARGO_GROUP:OnEventCargoDead( EventData ) function CARGO_GROUP:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius, ... ) self:F( {From, Event, To, ToPointVec2, NearRadius } ) - NearRadius = NearRadius or 100 + NearRadius = NearRadius or 25 local Timer = 1 @@ -1390,7 +1391,7 @@ function CARGO_GROUP:OnEventCargoDead( EventData ) function( Cargo, NearRadius ) Cargo:__UnBoard( Timer, ToPointVec2, NearRadius ) - Timer = Timer + 10 + Timer = Timer + 3 end, { NearRadius } ) From 31a7a4e9935a54156a432c24b11b5620235a08b0 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Wed, 28 Mar 2018 16:48:03 +0200 Subject: [PATCH 4/5] Default of near radius is 25 meters. --- Moose Development/Moose/Core/Cargo.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moose Development/Moose/Core/Cargo.lua b/Moose Development/Moose/Core/Cargo.lua index e0a42c690..4a88b528b 100644 --- a/Moose Development/Moose/Core/Cargo.lua +++ b/Moose Development/Moose/Core/Cargo.lua @@ -749,7 +749,7 @@ do -- CARGO_UNIT function CARGO_UNIT:onenterUnBoarding( From, Event, To, ToPointVec2, NearRadius ) self:F( { From, Event, To, ToPointVec2, NearRadius } ) - NearRadius = NearRadius or 100 + NearRadius = NearRadius or 25 local Angle = 180 local Speed = 60 From b29ce9b45eca5ea5676a121d8f13828be943b0fb Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Wed, 28 Mar 2018 18:00:17 +0200 Subject: [PATCH 5/5] Boarding of troops --- Moose Development/Moose/AI/AI_Cargo_Troops.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moose Development/Moose/AI/AI_Cargo_Troops.lua b/Moose Development/Moose/AI/AI_Cargo_Troops.lua index f0d524be3..754409aeb 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Troops.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Troops.lua @@ -149,7 +149,7 @@ function AI_CARGO_TROOPS:onafterLoad( CargoCarrier, From, Event, To ) if CargoCarrier and CargoCarrier:IsAlive() then CargoCarrier:RouteStop() self:__Board( 10 ) - self.CargoGroup:Board( CargoCarrier, 25 ) + self.CargoGroup:Board( CargoCarrier, 100 ) end end