From a14c2ef58977d9dab3460dd4df37133675bf750d Mon Sep 17 00:00:00 2001 From: FlightControl Date: Wed, 8 Aug 2018 22:41:02 +0200 Subject: [PATCH 1/9] Work in progress. Limit functions for POSITIONABLE. --- .../Moose/AI/AI_Cargo_Airplane.lua | 4 +- .../Moose/AI/AI_Cargo_Dispatcher.lua | 1 + .../Moose/Wrapper/Positionable.lua | 139 ++++++++++++------ 3 files changed, 93 insertions(+), 51 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua index 003100967..54f8b0cdd 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua @@ -188,7 +188,6 @@ function AI_CARGO_AIRPLANE:SetCarrier( Airplane ) function Airplane:OnEventEngineShutdown( EventData ) - self:F("Calling") AICargo:Landed( self.Airplane ) end @@ -233,8 +232,6 @@ end function AI_CARGO_AIRPLANE:onafterLanded( Airplane, From, Event, To ) self:F({Airplane, From, Event, To}) - self:F({IsAlive=Airplane:IsAlive()}) - self:F({RoutePickup=self.RoutePickup}) if Airplane and Airplane:IsAlive()~=nil then @@ -406,6 +403,7 @@ function AI_CARGO_AIRPLANE:onafterLoaded( Airplane, From, Event, To ) env.info("FF troops loaded into cargo plane") if Airplane and Airplane:IsAlive() then + -- Check if another cargo can be loaded into the airplane. end end diff --git a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua index 7ac009283..ea76ec694 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua @@ -403,6 +403,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor() -- The Pickup sequence ... -- Check if this Carrier need to go and Pickup something... + -- So, if the cargo bay is not full yet with cargo to be loaded ... self:I( { IsTransporting = AI_Cargo:IsTransporting() } ) if AI_Cargo:IsTransporting() == false then -- ok, so there is a free Carrier diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index 23b85806a..888cf3232 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -798,56 +798,99 @@ function POSITIONABLE:GetLaserCode() --R2.1 return self.LaserCode end ---- Add cargo. --- @param #POSITIONABLE self --- @param Core.Cargo#CARGO Cargo --- @return #POSITIONABLE -function POSITIONABLE:AddCargo( Cargo ) - self.__.Cargo[Cargo] = Cargo - return self -end +do -- Cargo ---- Get all contained cargo. --- @param #POSITIONABLE self --- @return #POSITIONABLE -function POSITIONABLE:GetCargo() - return self.__.Cargo -end - - - ---- Remove cargo. --- @param #POSITIONABLE self --- @param Core.Cargo#CARGO Cargo --- @return #POSITIONABLE -function POSITIONABLE:RemoveCargo( Cargo ) - self.__.Cargo[Cargo] = nil - return self -end - ---- Returns if carrier has given cargo. --- @param #POSITIONABLE self --- @return Core.Cargo#CARGO Cargo -function POSITIONABLE:HasCargo( Cargo ) - return self.__.Cargo[Cargo] -end - ---- Clear all cargo. --- @param #POSITIONABLE self -function POSITIONABLE:ClearCargo() - self.__.Cargo = {} -end - ---- Get cargo item count. --- @param #POSITIONABLE self --- @return Core.Cargo#CARGO Cargo -function POSITIONABLE:CargoItemCount() - local ItemCount = 0 - for CargoName, Cargo in pairs( self.__.Cargo ) do - ItemCount = ItemCount + Cargo:GetCount() + --- Add cargo. + -- @param #POSITIONABLE self + -- @param Core.Cargo#CARGO Cargo + -- @return #POSITIONABLE + function POSITIONABLE:AddCargo( Cargo ) + self.__.Cargo[Cargo] = Cargo + return self end - return ItemCount -end + + --- Get all contained cargo. + -- @param #POSITIONABLE self + -- @return #POSITIONABLE + function POSITIONABLE:GetCargo() + return self.__.Cargo + end + + + + --- Remove cargo. + -- @param #POSITIONABLE self + -- @param Core.Cargo#CARGO Cargo + -- @return #POSITIONABLE + function POSITIONABLE:RemoveCargo( Cargo ) + self.__.Cargo[Cargo] = nil + return self + end + + --- Returns if carrier has given cargo. + -- @param #POSITIONABLE self + -- @return Core.Cargo#CARGO Cargo + function POSITIONABLE:HasCargo( Cargo ) + return self.__.Cargo[Cargo] + end + + --- Clear all cargo. + -- @param #POSITIONABLE self + function POSITIONABLE:ClearCargo() + self.__.Cargo = {} + end + + --- Get cargo item count. + -- @param #POSITIONABLE self + -- @return Core.Cargo#CARGO Cargo + function POSITIONABLE:CargoItemCount() + local ItemCount = 0 + for CargoName, Cargo in pairs( self.__.Cargo ) do + ItemCount = ItemCount + Cargo:GetCount() + end + return ItemCount + end + + --- Get Cargo Bay Free Volume in m3. + -- @param #POSITIONABLE self + -- @return #number CargoBayFreeVolume + function POSITIONABLE:GetCargoBayFreeVolume() + local CargoVolume = 0 + for CargoName, Cargo in pairs( self.__.Cargo ) do + CargoVolume = CargoVolume + Cargo:GetVolume() + end + return self.__.CargoBayVolumeLimit - CargoVolume + end + + --- Get Cargo Bay Free Weight in kg. + -- @param #POSITIONABLE self + -- @return #number CargoBayFreeWeight + function POSITIONABLE:GetCargoBayFreeWeight() + local CargoWeight = 0 + for CargoName, Cargo in pairs( self.__.Cargo ) do + CargoWeight = CargoWeight + Cargo:GetWeight() + end + return self.__.CargoBayWeightLimit - CargoWeight + end + + --- Get Cargo Bay Volume Limit in m3. + -- @param #POSITIONABLE self + -- @param #number VolumeLimit + function POSITIONABLE:SetCargoBayVolumeLimit( VolumeLimit ) + self.__.CargoBayVolumeLimit = VolumeLimit + end + + --- Get Cargo Bay Weight Limit in kg. + -- @param #POSITIONABLE self + -- @param #number WeightLimit + function POSITIONABLE:GetCargoBayFreeWeightLimit( WeightLimit ) + self.__.CargoBayWeightLimit = WeightLimit + end + + + + +end --- Cargo --- Signal a flare at the position of the POSITIONABLE. -- @param #POSITIONABLE self From 7f9f9b33fd4b1f64040c911e810ade946a28493d Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sat, 11 Aug 2018 11:33:43 +0200 Subject: [PATCH 2/9] - Have added cargo bay limits based on volume and weight. - AI Cargo Dispatcher works with cargo bay limits for carrier. (i still need to add options to set the parameters for this). - Carriers load now multiple cargo. - Added weight and volume attached to cargo objects for units. I reworked the respawning of cargo units, so that these volumes and weights are collected from the unit Descriptor properties! - There are still bugs, which I need to resolve, but it is going in the right direction. --- .../Moose/AI/AI_Cargo_Airplane.lua | 89 ++++++++++++++----- .../Moose/AI/AI_Cargo_Dispatcher.lua | 12 +-- Moose Development/Moose/Cargo/Cargo.lua | 23 +++++ Moose Development/Moose/Cargo/CargoGroup.lua | 31 ++++++- .../Moose/Wrapper/Identifiable.lua | 2 +- .../Moose/Wrapper/Positionable.lua | 3 +- 6 files changed, 129 insertions(+), 31 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua index 54f8b0cdd..28a71989f 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua @@ -34,10 +34,10 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) self:SetStartState( "Unloaded" ) - self:AddTransition( "Unloaded", "Pickup", "*" ) + self:AddTransition( { "Unloaded", "Loaded" }, "Pickup", "*" ) self:AddTransition( "Loaded", "Deploy", "*" ) - self:AddTransition( "Unloaded", "Load", "Boarding" ) + self:AddTransition( { "Unloaded", "Loaded" }, "Load", "Boarding" ) self:AddTransition( "Boarding", "Board", "Boarding" ) self:AddTransition( "Boarding", "Loaded", "Loaded" ) self:AddTransition( "Loaded", "Unload", "Unboarding" ) @@ -128,6 +128,11 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) -- Set carrier. self:SetCarrier( Airplane ) + Airplane:SetCargoBayWeightLimit( 5000 ) + Airplane:SetCargoBayVolumeLimit( 15 ) + + self.Relocating = true + return self end @@ -188,6 +193,7 @@ function AI_CARGO_AIRPLANE:SetCarrier( Airplane ) function Airplane:OnEventEngineShutdown( EventData ) + AICargo.Relocating = false AICargo:Landed( self.Airplane ) end @@ -355,17 +361,21 @@ end -- @param Wrapper.Point#COORDINATE Coordinate Place where the cargo is guided to if it is inside the load radius. function AI_CARGO_AIRPLANE:onafterLoad( Airplane, From, Event, To, Coordinate ) - if Airplane and Airplane:IsAlive()~=nil then + if Airplane and Airplane:IsAlive() ~= nil then for _,_Cargo in pairs( self.CargoSet:GetSet() ) do self:F({_Cargo:GetName()}) local Cargo=_Cargo --Cargo.Cargo#CARGO local InRadius = Cargo:IsInLoadRadius( Coordinate ) if InRadius then - self:__Board( 5 ) - Cargo:Board( Airplane, 25 ) - self.Cargo = Cargo - break + + -- Is there a cargo still unloaded? + if Cargo:IsUnLoaded() == true then + + self:__Board( 5, Cargo ) + Cargo:Board( Airplane, 25 ) + break + end end end @@ -379,14 +389,16 @@ end -- @param #string From From state. -- @param #string Event Event. -- @param #string To To state. -function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To ) +function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To, Cargo ) if Airplane and Airplane:IsAlive() then - self:F({ IsLoaded = self.Cargo:IsLoaded() } ) - if not self.Cargo:IsLoaded() then - self:__Board( 10 ) + + self:F({ IsLoaded = Cargo:IsLoaded() } ) + + if not Cargo:IsLoaded() then + self:__Board( 10, Cargo ) else - self:__Loaded( 1 ) + self:__Loaded( 1, Cargo ) end end @@ -398,12 +410,46 @@ end -- @param #string From From state. -- @param #string Event Event. -- @param #string To To state. -function AI_CARGO_AIRPLANE:onafterLoaded( Airplane, From, Event, To ) +function AI_CARGO_AIRPLANE:onafterLoaded( Airplane, From, Event, To, Cargo ) env.info("FF troops loaded into cargo plane") if Airplane and Airplane:IsAlive() then + -- Check if another cargo can be loaded into the airplane. + for _,_Cargo in pairs( self.CargoSet:GetSet() ) do + + self:F({_Cargo:GetName()}) + local Cargo =_Cargo --Cargo.Cargo#CARGO + + -- Is there a cargo still unloaded? + if Cargo:IsUnLoaded() == true then + + -- Only when the cargo is within load radius. + local InRadius = Cargo:IsInLoadRadius( Airplane:GetCoordinate() ) + if InRadius then + + local CargoBayFreeWeight = Airplane:GetCargoBayFreeWeight() + local CargoBayFreeVolume = Airplane:GetCargoBayFreeVolume() + + local CargoWeight = Cargo:GetWeight() + local CargoVolume = Cargo:GetVolume() + + -- Only when there is space within the bay to load the next cargo item! + if CargoBayFreeWeight > CargoWeight and CargoBayFreeVolume > CargoVolume then + + -- ok, board. + self:__Load( 5, Airplane:GetCoordinate() ) + + -- And start the boarding loop for the AI_CARGO_AIRPLANE object until the cargo is boarded. + --Cargo:Board( Airplane, 25 ) + return + end + end + end + end + self:F( { "Transporting" } ) + self.Transporting = true -- This will only be executed when there is no cargo boarded anymore. The dispatcher will then kick-off the deploy cycle! end end @@ -418,8 +464,11 @@ end function AI_CARGO_AIRPLANE:onafterUnload( Airplane, From, Event, To ) if Airplane and Airplane:IsAlive() then - self.Cargo:UnBoard() - self:__Unboard( 10 ) + local Cargos = Airplane:GetCargo() + for CargoID, Cargo in pairs( Cargos ) do + Cargo:UnBoard() + self:__Unboard( 10, Cargo ) + end end end @@ -430,13 +479,13 @@ end -- @param #string From From state. -- @param #string Event Event. -- @param #string To To state. -function AI_CARGO_AIRPLANE:onafterUnboard( Airplane, From, Event, To ) +function AI_CARGO_AIRPLANE:onafterUnboard( Airplane, From, Event, To, Cargo ) if Airplane and Airplane:IsAlive() then - if not self.Cargo:IsUnLoaded() then - self:__Unboard( 10 ) + if not Cargo:IsUnLoaded() then + self:__Unboard( 10, Cargo ) else - self:__Unloaded( 1 ) + self:__Unloaded( 1, Cargo ) end end @@ -448,7 +497,7 @@ end -- @param #string From From state. -- @param #string Event Event. -- @param #string To To state. -function AI_CARGO_AIRPLANE:onafterUnloaded( Airplane, From, Event, To ) +function AI_CARGO_AIRPLANE:onafterUnloaded( Airplane, From, Event, To, Cargo ) if Airplane and Airplane:IsAlive() then self.Airplane = Airplane diff --git a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua index ea76ec694..9a5082f52 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua @@ -404,8 +404,8 @@ function AI_CARGO_DISPATCHER:onafterMonitor() -- The Pickup sequence ... -- Check if this Carrier need to go and Pickup something... -- So, if the cargo bay is not full yet with cargo to be loaded ... - self:I( { IsTransporting = AI_Cargo:IsTransporting() } ) - if AI_Cargo:IsTransporting() == false then + self:I( { IsRelocating = AI_Cargo:IsRelocating() } ) + if AI_Cargo:IsRelocating() == false then -- ok, so there is a free Carrier -- now find the first cargo that is Unloaded @@ -560,9 +560,11 @@ function AI_CARGO_DISPATCHER:OnAfterLoaded( From, Event, To, Carrier, Cargo ) end if self.DeployAirbasesSet then - - local DeployAirbase = self.DeployAirbasesSet:GetRandomAirbase() - self.AI_Cargo[Carrier]:Deploy( DeployAirbase, math.random( self.DeployMinSpeed, self.DeployMaxSpeed ) ) + + if self.AI_Cargo[Carrier]:IsTransporting() == true then + local DeployAirbase = self.DeployAirbasesSet:GetRandomAirbase() + self.AI_Cargo[Carrier]:Deploy( DeployAirbase, math.random( self.DeployMinSpeed, self.DeployMaxSpeed ) ) + end end self.PickupCargo[Carrier] = nil diff --git a/Moose Development/Moose/Cargo/Cargo.lua b/Moose Development/Moose/Cargo/Cargo.lua index 5c2526919..e0b6f4d4a 100644 --- a/Moose Development/Moose/Cargo/Cargo.lua +++ b/Moose Development/Moose/Cargo/Cargo.lua @@ -875,6 +875,13 @@ do -- CARGO return self.CargoObject:GetCoordinate() end + --- Get the weight of the cargo. + -- @param #CARGO self + -- @return #number Weight The weight in kg. + function CARGO:GetWeight() + return self.Weight + end + --- Set the weight of the cargo. -- @param #CARGO self -- @param #number Weight The weight in kg. @@ -884,6 +891,22 @@ do -- CARGO return self end + --- Get the volume of the cargo. + -- @param #CARGO self + -- @return #number Volume The volume in kg. + function CARGO:GetVolume() + return self.Volume + end + + --- Set the volume of the cargo. + -- @param #CARGO self + -- @param #number Volume The volume in kg. + -- @return #CARGO + function CARGO:SetVolume( Volume ) + self.Volume = Volume + return self + end + --- Send a CC message to a @{Wrapper.Group}. -- @param #CARGO self -- @param #string Message diff --git a/Moose Development/Moose/Cargo/CargoGroup.lua b/Moose Development/Moose/Cargo/CargoGroup.lua index c2d45f142..b7c78a713 100644 --- a/Moose Development/Moose/Cargo/CargoGroup.lua +++ b/Moose Development/Moose/Cargo/CargoGroup.lua @@ -73,6 +73,7 @@ do -- CARGO_GROUP self:SetDeployed( false ) local WeightGroup = 0 + local VolumeGroup = 0 self.CargoGroup:Destroy() @@ -96,10 +97,7 @@ do -- CARGO_GROUP -- And we register the spawned unit as part of the CargoSet. local Unit = UNIT:Register( CargoUnitName ) - --local WeightUnit = Unit:GetDesc().massEmpty - --WeightGroup = WeightGroup + WeightUnit - local CargoUnit = CARGO_UNIT:New( Unit, Type, CargoUnitName, 10, LoadRadius, NearRadius ) - self.CargoSet:Add( CargoUnitName, CargoUnit ) + end -- Then we register the new group in the database @@ -107,6 +105,31 @@ do -- CARGO_GROUP -- Now we spawn the new group based on the template created. self.CargoObject = _DATABASE:Spawn( GroupTemplate ) + + for CargoUnitID, CargoUnit in pairs( self.CargoObject:GetUnits() ) do + local Desc = CargoUnit:GetDesc() + self:I( { Desc = Desc } ) + local WeightUnit = math.random( 80, 120 ) + if Desc then + WeightUnit = Desc.massEmpty + end + + local Box = CargoUnit:GetBoundingBox() + local VolumeUnit = ( Box.max.x - Box.min.x ) * ( Box.max.y - Box.min.y ) * ( Box.max.z - Box.min.z ) + self:I( { VolumeUnit = VolumeUnit, WeightUnit = WeightUnit } ) + + + local CargoUnitName = CargoUnit:GetName() + + local Cargo = CARGO_UNIT:New( CargoUnit, Type, CargoUnitName, 0, LoadRadius, NearRadius ) + Cargo:SetWeight( WeightUnit ) + Cargo:SetVolume( VolumeUnit ) + self.CargoSet:Add( CargoUnitName, Cargo ) + + WeightGroup = WeightGroup + WeightUnit + VolumeGroup = VolumeGroup + VolumeUnit + + end self:SetWeight( WeightGroup ) self.CargoLimit = 10 diff --git a/Moose Development/Moose/Wrapper/Identifiable.lua b/Moose Development/Moose/Wrapper/Identifiable.lua index 6e226a466..0f6e14f06 100644 --- a/Moose Development/Moose/Wrapper/Identifiable.lua +++ b/Moose Development/Moose/Wrapper/Identifiable.lua @@ -216,7 +216,7 @@ end function IDENTIFIABLE:GetDesc() self:F2( self.IdentifiableName ) - local DCSIdentifiable = self:GetDCSObject() + local DCSIdentifiable = self:GetDCSObject() -- DCS#Object if DCSIdentifiable then local IdentifiableDesc = DCSIdentifiable:getDesc() diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index 888cf3232..44fa06d52 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -868,6 +868,7 @@ do -- Cargo function POSITIONABLE:GetCargoBayFreeWeight() local CargoWeight = 0 for CargoName, Cargo in pairs( self.__.Cargo ) do + self:F( { Cargo = Cargo } ) CargoWeight = CargoWeight + Cargo:GetWeight() end return self.__.CargoBayWeightLimit - CargoWeight @@ -883,7 +884,7 @@ do -- Cargo --- Get Cargo Bay Weight Limit in kg. -- @param #POSITIONABLE self -- @param #number WeightLimit - function POSITIONABLE:GetCargoBayFreeWeightLimit( WeightLimit ) + function POSITIONABLE:SetCargoBayWeightLimit( WeightLimit ) self.__.CargoBayWeightLimit = WeightLimit end From 74e9599df942c142f3d2dec278715e2f069940fa Mon Sep 17 00:00:00 2001 From: FlightControl Date: Mon, 13 Aug 2018 07:38:18 +0200 Subject: [PATCH 3/9] Got the airplanes finally to load together ... --- .../Moose/AI/AI_Cargo_Airplane.lua | 83 ++++++++++--------- .../Moose/AI/AI_Cargo_Dispatcher.lua | 2 +- Moose Development/Moose/Cargo/Cargo.lua | 22 ++++- Moose Development/Moose/Cargo/CargoGroup.lua | 19 +---- Moose Development/Moose/Cargo/CargoUnit.lua | 6 +- .../Moose/Wrapper/Positionable.lua | 36 ++++---- 6 files changed, 86 insertions(+), 82 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua index 28a71989f..75f3f2873 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua @@ -37,7 +37,7 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) self:AddTransition( { "Unloaded", "Loaded" }, "Pickup", "*" ) self:AddTransition( "Loaded", "Deploy", "*" ) - self:AddTransition( { "Unloaded", "Loaded" }, "Load", "Boarding" ) + self:AddTransition( { "Unloaded", "Boarding" }, "Load", "Boarding" ) self:AddTransition( "Boarding", "Board", "Boarding" ) self:AddTransition( "Boarding", "Loaded", "Loaded" ) self:AddTransition( "Loaded", "Unload", "Unboarding" ) @@ -128,8 +128,13 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) -- Set carrier. self:SetCarrier( Airplane ) - Airplane:SetCargoBayWeightLimit( 5000 ) - Airplane:SetCargoBayVolumeLimit( 15 ) + local Desc = Airplane:GetUnit(1):GetDesc() + + self:F({Desc=Desc}) + + + Airplane:SetCargoBayWeightLimit( Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) ) + --Airplane:SetCargoBayVolumeLimit( 15 ) self.Relocating = true @@ -344,8 +349,7 @@ function AI_CARGO_AIRPLANE:onafterDeploy( Airplane, From, Event, To, Airbase, Sp -- Set destination airbase for next :Route() command. self.Airbase = Airbase - -- Unclear?! - self.Transporting = false + self.Transporting = true self.Relocating = false end @@ -398,6 +402,38 @@ function AI_CARGO_AIRPLANE:onafterBoard( Airplane, From, Event, To, Cargo ) if not Cargo:IsLoaded() then self:__Board( 10, Cargo ) else + -- Check if another cargo can be loaded into the airplane. + for _,_Cargo in pairs( self.CargoSet:GetSet() ) do + + self:F({_Cargo:GetName()}) + local Cargo =_Cargo --Cargo.Cargo#CARGO + + -- Is there a cargo still unloaded? + if Cargo:IsUnLoaded() == true then + + -- Only when the cargo is within load radius. + local InRadius = Cargo:IsInLoadRadius( Airplane:GetCoordinate() ) + if InRadius then + + local CargoBayFreeWeight = Airplane:GetCargoBayFreeWeight() + --local CargoBayFreeVolume = Airplane:GetCargoBayFreeVolume() + + local CargoWeight = Cargo:GetWeight() + --local CargoVolume = Cargo:GetVolume() + + -- Only when there is space within the bay to load the next cargo item! + if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then + + -- ok, board. + self:__Load( 5, Airplane:GetCoordinate() ) + + -- And start the boarding loop for the AI_CARGO_AIRPLANE object until the cargo is boarded. + --Cargo:Board( Airplane, 25 ) + return + end + end + end + end self:__Loaded( 1, Cargo ) end end @@ -415,41 +451,8 @@ function AI_CARGO_AIRPLANE:onafterLoaded( Airplane, From, Event, To, Cargo ) env.info("FF troops loaded into cargo plane") if Airplane and Airplane:IsAlive() then - - -- Check if another cargo can be loaded into the airplane. - for _,_Cargo in pairs( self.CargoSet:GetSet() ) do - - self:F({_Cargo:GetName()}) - local Cargo =_Cargo --Cargo.Cargo#CARGO - - -- Is there a cargo still unloaded? - if Cargo:IsUnLoaded() == true then - - -- Only when the cargo is within load radius. - local InRadius = Cargo:IsInLoadRadius( Airplane:GetCoordinate() ) - if InRadius then - - local CargoBayFreeWeight = Airplane:GetCargoBayFreeWeight() - local CargoBayFreeVolume = Airplane:GetCargoBayFreeVolume() - - local CargoWeight = Cargo:GetWeight() - local CargoVolume = Cargo:GetVolume() - - -- Only when there is space within the bay to load the next cargo item! - if CargoBayFreeWeight > CargoWeight and CargoBayFreeVolume > CargoVolume then - - -- ok, board. - self:__Load( 5, Airplane:GetCoordinate() ) - - -- And start the boarding loop for the AI_CARGO_AIRPLANE object until the cargo is boarded. - --Cargo:Board( Airplane, 25 ) - return - end - end - end - end - self:F( { "Transporting" } ) - self.Transporting = true -- This will only be executed when there is no cargo boarded anymore. The dispatcher will then kick-off the deploy cycle! + self:F( { "Transporting" } ) + self.Transporting = true -- This will only be executed when there is no cargo boarded anymore. The dispatcher will then kick-off the deploy cycle! end end diff --git a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua index 9a5082f52..c7a0ea4b9 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua @@ -405,7 +405,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor() -- Check if this Carrier need to go and Pickup something... -- So, if the cargo bay is not full yet with cargo to be loaded ... self:I( { IsRelocating = AI_Cargo:IsRelocating() } ) - if AI_Cargo:IsRelocating() == false then + if AI_Cargo:IsRelocating() == false and AI_Cargo:IsTransporting() == false then -- ok, so there is a free Carrier -- now find the first cargo that is Unloaded diff --git a/Moose Development/Moose/Cargo/Cargo.lua b/Moose Development/Moose/Cargo/Cargo.lua index e0b6f4d4a..50cade298 100644 --- a/Moose Development/Moose/Cargo/Cargo.lua +++ b/Moose Development/Moose/Cargo/Cargo.lua @@ -1020,13 +1020,27 @@ do -- CARGO_REPRESENTABLE -- @param #CARGO_REPRESENTABLE self -- @param #string Type -- @param #string Name - -- @param #number Weight -- @param #number LoadRadius (optional) -- @param #number NearRadius (optional) -- @return #CARGO_REPRESENTABLE - function CARGO_REPRESENTABLE:New( CargoObject, Type, Name, Weight, LoadRadius, NearRadius ) - local self = BASE:Inherit( self, CARGO:New( Type, Name, Weight, LoadRadius, NearRadius ) ) -- #CARGO_REPRESENTABLE - self:F( { Type, Name, Weight, LoadRadius, NearRadius } ) + function CARGO_REPRESENTABLE:New( CargoObject, Type, Name, LoadRadius, NearRadius ) + local self = BASE:Inherit( self, CARGO:New( Type, Name, 0, LoadRadius, NearRadius ) ) -- #CARGO_REPRESENTABLE + self:F( { Type, Name, LoadRadius, NearRadius } ) + + local Desc = CargoObject:GetDesc() + self:I( { Desc = Desc } ) + local Weight = math.random( 80, 120 ) + if Desc then + Weight = Desc.massEmpty + end + + self:SetWeight( Weight ) + +-- local Box = CargoUnit:GetBoundingBox() +-- local VolumeUnit = ( Box.max.x - Box.min.x ) * ( Box.max.y - Box.min.y ) * ( Box.max.z - Box.min.z ) +-- self:I( { VolumeUnit = VolumeUnit, WeightUnit = WeightUnit } ) + --self:SetVolume( VolumeUnit ) + return self end diff --git a/Moose Development/Moose/Cargo/CargoGroup.lua b/Moose Development/Moose/Cargo/CargoGroup.lua index b7c78a713..72a3430cf 100644 --- a/Moose Development/Moose/Cargo/CargoGroup.lua +++ b/Moose Development/Moose/Cargo/CargoGroup.lua @@ -107,32 +107,19 @@ do -- CARGO_GROUP self.CargoObject = _DATABASE:Spawn( GroupTemplate ) for CargoUnitID, CargoUnit in pairs( self.CargoObject:GetUnits() ) do - local Desc = CargoUnit:GetDesc() - self:I( { Desc = Desc } ) - local WeightUnit = math.random( 80, 120 ) - if Desc then - WeightUnit = Desc.massEmpty - end - - local Box = CargoUnit:GetBoundingBox() - local VolumeUnit = ( Box.max.x - Box.min.x ) * ( Box.max.y - Box.min.y ) * ( Box.max.z - Box.min.z ) - self:I( { VolumeUnit = VolumeUnit, WeightUnit = WeightUnit } ) local CargoUnitName = CargoUnit:GetName() - local Cargo = CARGO_UNIT:New( CargoUnit, Type, CargoUnitName, 0, LoadRadius, NearRadius ) - Cargo:SetWeight( WeightUnit ) - Cargo:SetVolume( VolumeUnit ) + local Cargo = CARGO_UNIT:New( CargoUnit, Type, CargoUnitName, LoadRadius, NearRadius ) self.CargoSet:Add( CargoUnitName, Cargo ) - WeightGroup = WeightGroup + WeightUnit - VolumeGroup = VolumeGroup + VolumeUnit + WeightGroup = WeightGroup + Cargo:GetWeight() + --VolumeGroup = VolumeGroup + VolumeUnit end self:SetWeight( WeightGroup ) - self.CargoLimit = 10 self:T( { "Weight Cargo", WeightGroup } ) diff --git a/Moose Development/Moose/Cargo/CargoUnit.lua b/Moose Development/Moose/Cargo/CargoUnit.lua index c7992256c..90eceeda9 100644 --- a/Moose Development/Moose/Cargo/CargoUnit.lua +++ b/Moose Development/Moose/Cargo/CargoUnit.lua @@ -42,9 +42,9 @@ do -- CARGO_UNIT -- @param #number LoadRadius (optional) -- @param #number NearRadius (optional) -- @return #CARGO_UNIT - function CARGO_UNIT:New( CargoUnit, Type, Name, Weight, LoadRadius, NearRadius ) - local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoUnit, Type, Name, Weight, LoadRadius, NearRadius ) ) -- #CARGO_UNIT - self:I( { Type, Name, Weight, LoadRadius, NearRadius } ) + function CARGO_UNIT:New( CargoUnit, Type, Name, LoadRadius, NearRadius ) + local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoUnit, Type, Name, LoadRadius, NearRadius ) ) -- #CARGO_UNIT + self:I( { Type, Name, LoadRadius, NearRadius } ) self:T( CargoUnit ) self.CargoObject = CargoUnit diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index 44fa06d52..1de5c21fe 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -851,17 +851,17 @@ do -- Cargo return ItemCount end - --- Get Cargo Bay Free Volume in m3. - -- @param #POSITIONABLE self - -- @return #number CargoBayFreeVolume - function POSITIONABLE:GetCargoBayFreeVolume() - local CargoVolume = 0 - for CargoName, Cargo in pairs( self.__.Cargo ) do - CargoVolume = CargoVolume + Cargo:GetVolume() - end - return self.__.CargoBayVolumeLimit - CargoVolume - end - +-- --- Get Cargo Bay Free Volume in m3. +-- -- @param #POSITIONABLE self +-- -- @return #number CargoBayFreeVolume +-- function POSITIONABLE:GetCargoBayFreeVolume() +-- local CargoVolume = 0 +-- for CargoName, Cargo in pairs( self.__.Cargo ) do +-- CargoVolume = CargoVolume + Cargo:GetVolume() +-- end +-- return self.__.CargoBayVolumeLimit - CargoVolume +-- end +-- --- Get Cargo Bay Free Weight in kg. -- @param #POSITIONABLE self -- @return #number CargoBayFreeWeight @@ -874,13 +874,13 @@ do -- Cargo return self.__.CargoBayWeightLimit - CargoWeight end - --- Get Cargo Bay Volume Limit in m3. - -- @param #POSITIONABLE self - -- @param #number VolumeLimit - function POSITIONABLE:SetCargoBayVolumeLimit( VolumeLimit ) - self.__.CargoBayVolumeLimit = VolumeLimit - end - +-- --- Get Cargo Bay Volume Limit in m3. +-- -- @param #POSITIONABLE self +-- -- @param #number VolumeLimit +-- function POSITIONABLE:SetCargoBayVolumeLimit( VolumeLimit ) +-- self.__.CargoBayVolumeLimit = VolumeLimit +-- end + --- Get Cargo Bay Weight Limit in kg. -- @param #POSITIONABLE self -- @param #number WeightLimit From 4d7812b368eaf7453c951a7a4a8bfb5fe7bdd891 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Mon, 13 Aug 2018 21:42:44 +0200 Subject: [PATCH 4/9] Working version for airplanes, now need to debug to make it also happen for helicopters and apcs --- .../Moose/AI/AI_Cargo_Airplane.lua | 35 ++++++++++++++++--- .../Moose/AI/AI_Cargo_Dispatcher.lua | 2 +- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua index 75f3f2873..8cacb48ea 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua @@ -42,7 +42,7 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) self:AddTransition( "Boarding", "Loaded", "Loaded" ) self:AddTransition( "Loaded", "Unload", "Unboarding" ) self:AddTransition( "Unboarding", "Unboard", "Unboarding" ) - self:AddTransition( "Unboarding", "Unloaded", "Unloaded" ) + self:AddTransition( "Unboarding" , "Unloaded", "Unloaded" ) self:AddTransition( "*", "Landed", "*" ) self:AddTransition( "*", "Home" , "*" ) @@ -469,7 +469,15 @@ function AI_CARGO_AIRPLANE:onafterUnload( Airplane, From, Event, To ) if Airplane and Airplane:IsAlive() then local Cargos = Airplane:GetCargo() for CargoID, Cargo in pairs( Cargos ) do - Cargo:UnBoard() + + local Angle = 180 + local CargoCarrierHeading = Airplane:GetHeading() -- Get Heading of object in degrees. + local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle ) + self:T( { CargoCarrierHeading, CargoDeployHeading } ) + local CargoDeployCoordinate = Airplane:GetPointVec2():Translate( 150, CargoDeployHeading ) + + Cargo:UnBoard( CargoDeployCoordinate ) + Cargo:SetDeployed( true ) self:__Unboard( 10, Cargo ) end end @@ -484,14 +492,30 @@ end -- @param #string To To state. function AI_CARGO_AIRPLANE:onafterUnboard( Airplane, From, Event, To, Cargo ) + self:E( { "Unboard", Cargo } ) + if Airplane and Airplane:IsAlive() then if not Cargo:IsUnLoaded() then self:__Unboard( 10, Cargo ) else + local Cargos = Airplane:GetCargo() + for CargoID, Cargo in pairs( Cargos ) do + if Cargo:IsLoaded() then + local Angle = 180 + local CargoCarrierHeading = Airplane:GetHeading() -- Get Heading of object in degrees. + local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle ) + self:T( { CargoCarrierHeading, CargoDeployHeading } ) + local CargoDeployCoordinate = Airplane:GetPointVec2():Translate( 150, CargoDeployHeading ) + Cargo:UnBoard( CargoDeployCoordinate ) + Cargo:SetDeployed( true ) + + self:__Unboard( 10, Cargo ) + return + end + end self:__Unloaded( 1, Cargo ) end end - end --- On after Unloaded event. Cargo has been unloaded, i.e. the unboarding process is finished. @@ -500,12 +524,15 @@ end -- @param #string From From state. -- @param #string Event Event. -- @param #string To To state. +-- @param Cargo.Cargo#CARGO Cargo function AI_CARGO_AIRPLANE:onafterUnloaded( Airplane, From, Event, To, Cargo ) + self:E( { "Unloaded", Cargo } ) + if Airplane and Airplane:IsAlive() then self.Airplane = Airplane + self.Transporting = false -- This will only be executed when there is no cargo onboard anymore. The dispatcher will then kick-off the pickup cycle! end - end --- Route the airplane from one airport or it's current position to another airbase. diff --git a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua index c7a0ea4b9..c19d760a8 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua @@ -414,7 +414,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor() for CargoName, Cargo in pairs( self.SetCargo:GetSet() ) do local Cargo = Cargo -- Cargo.Cargo#CARGO self:F( { Cargo = Cargo:GetName(), UnLoaded = Cargo:IsUnLoaded(), Deployed = Cargo:IsDeployed(), PickupCargo = self.PickupCargo[Carrier] ~= nil } ) - if Cargo:IsUnLoaded() and not Cargo:IsDeployed() then + if Cargo:IsUnLoaded() == true and Cargo:IsDeployed() == false then local CargoCoordinate = Cargo:GetCoordinate() local CoordinateFree = true for CarrierPickup, Coordinate in pairs( self.PickupCargo ) do From e4f8b5afc3586e3c8b2b69159e75ac510a5e2355 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Tue, 14 Aug 2018 21:04:11 +0200 Subject: [PATCH 5/9] Working plane cargo AI dispatcher, but still need to work on the collisions on the runway etc of moving vehicles with planes... --- Moose Development/Moose/Cargo/CargoGroup.lua | 4 +-- Moose Development/Moose/Core/Database.lua | 35 +++++++++++--------- Moose Development/Moose/Core/Event.lua | 2 +- Moose Development/Moose/Wrapper/Group.lua | 14 ++++---- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/Moose Development/Moose/Cargo/CargoGroup.lua b/Moose Development/Moose/Cargo/CargoGroup.lua index 72a3430cf..b51e5502c 100644 --- a/Moose Development/Moose/Cargo/CargoGroup.lua +++ b/Moose Development/Moose/Cargo/CargoGroup.lua @@ -89,7 +89,7 @@ do -- CARGO_GROUP for UnitID, UnitTemplate in pairs( self.CargoTemplate.units ) do UnitTemplate.name = UnitTemplate.name .. "#CARGO" - local CargoUnitName = UnitTemplate.name + local CargoUnitName = UnitTemplate.name self.CargoUnitTemplate[CargoUnitName] = UnitTemplate GroupTemplate.units[#GroupTemplate.units+1] = self.CargoUnitTemplate[CargoUnitName] @@ -101,7 +101,7 @@ do -- CARGO_GROUP end -- Then we register the new group in the database - self.CargoGroup = GROUP:NewTemplate( GroupTemplate, GroupTemplate.CoalitionID, GroupTemplate.CategoryID, GroupTemplate.CountryID) + GROUP:NewTemplate( GroupTemplate, GroupTemplate.CoalitionID, GroupTemplate.CategoryID, GroupTemplate.CountryID ) -- Now we spawn the new group based on the template created. self.CargoObject = _DATABASE:Spawn( GroupTemplate ) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index 3b0fb0337..59e4676e4 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -374,14 +374,15 @@ do -- cargo -- @return #DATABASE self function DATABASE:_RegisterCargos() + local Groups = UTILS.DeepCopy( self.GROUPS ) -- This is a very important statement. CARGO_GROUP:New creates a new _DATABASE.GROUP entry, which will confuse the loop. I searched 4 hours on this to find the bug! - for CargoGroupName, CargoGroup in pairs( self.GROUPS ) do + for CargoGroupName, CargoGroup in pairs( Groups ) do + self:I( { Cargo = CargoGroupName } ) if self:IsCargo( CargoGroupName ) then local CargoInfo = CargoGroupName:match("~CARGO(.*)") local CargoParam = CargoInfo and CargoInfo:match( "%((.*)%)") local CargoName1 = CargoGroupName:match("(.*)~CARGO%(.*%)") local CargoName2 = CargoGroupName:match(".*~CARGO%(.*%)(.*)") - self:E({CargoName1 = CargoName1, CargoName2 = CargoName2 }) local CargoName = CargoName1 .. ( CargoName2 or "" ) local Type = CargoParam and CargoParam:match( "T=([%a%d ]+),?") local Name = CargoParam and CargoParam:match( "N=([%a%d]+),?") or CargoName @@ -459,7 +460,7 @@ end function DATABASE:AddGroup( GroupName ) if not self.GROUPS[GroupName] then - self:E( { "Add GROUP:", GroupName } ) + self:I( { "Add GROUP:", GroupName } ) self.GROUPS[GroupName] = GROUP:Register( GroupName ) end @@ -471,7 +472,7 @@ end function DATABASE:AddPlayer( UnitName, PlayerName ) if PlayerName then - self:E( { "Add player for unit:", UnitName, PlayerName } ) + self:I( { "Add player for unit:", UnitName, PlayerName } ) self.PLAYERS[PlayerName] = UnitName self.PLAYERUNITS[PlayerName] = self:FindUnit( UnitName ) self.PLAYERSJOINED[PlayerName] = PlayerName @@ -483,7 +484,7 @@ end function DATABASE:DeletePlayer( UnitName, PlayerName ) if PlayerName then - self:E( { "Clean player:", PlayerName } ) + self:I( { "Clean player:", PlayerName } ) self.PLAYERS[PlayerName] = nil self.PLAYERUNITS[PlayerName] = nil end @@ -750,7 +751,7 @@ function DATABASE:_RegisterPlayers() local UnitName = UnitData:getName() local PlayerName = UnitData:getPlayerName() if not self.PLAYERS[PlayerName] then - self:E( { "Add player for unit:", UnitName, PlayerName } ) + self:I( { "Add player for unit:", UnitName, PlayerName } ) self:AddPlayer( UnitName, PlayerName ) end end @@ -773,13 +774,13 @@ function DATABASE:_RegisterGroupsAndUnits() if DCSGroup:isExist() then local DCSGroupName = DCSGroup:getName() - self:E( { "Register Group:", DCSGroupName } ) + self:I( { "Register Group:", DCSGroupName } ) self:AddGroup( DCSGroupName ) for DCSUnitId, DCSUnit in pairs( DCSGroup:getUnits() ) do local DCSUnitName = DCSUnit:getName() - self:E( { "Register Unit:", DCSUnitName } ) + self:I( { "Register Unit:", DCSUnitName } ) self:AddUnit( DCSUnitName ) end else @@ -788,6 +789,11 @@ function DATABASE:_RegisterGroupsAndUnits() end end + + self:I("Groups:") + for GroupName, Group in pairs( self.GROUPS ) do + self:I( { "Group:", GroupName } ) + end return self end @@ -798,7 +804,7 @@ end function DATABASE:_RegisterClients() for ClientName, ClientTemplate in pairs( self.Templates.ClientsByName ) do - self:E( { "Register Client:", ClientName } ) + self:I( { "Register Client:", ClientName } ) self:AddClient( ClientName ) end @@ -809,14 +815,14 @@ end function DATABASE:_RegisterStatics() local CoalitionsData = { GroupsRed = coalition.getStaticObjects( coalition.side.RED ), GroupsBlue = coalition.getStaticObjects( coalition.side.BLUE ) } - self:E( { Statics = CoalitionsData } ) + self:I( { Statics = CoalitionsData } ) for CoalitionId, CoalitionData in pairs( CoalitionsData ) do for DCSStaticId, DCSStatic in pairs( CoalitionData ) do if DCSStatic:isExist() then local DCSStaticName = DCSStatic:getName() - self:E( { "Register Static:", DCSStaticName } ) + self:I( { "Register Static:", DCSStaticName } ) self:AddStatic( DCSStaticName ) else self:E( { "Static does not exist: ", DCSStatic } ) @@ -836,7 +842,7 @@ function DATABASE:_RegisterAirbases() local DCSAirbaseName = DCSAirbase:getName() - self:E( { "Register Airbase:", DCSAirbaseName, DCSAirbase:getID() } ) + self:I( { "Register Airbase:", DCSAirbaseName, DCSAirbase:getID() } ) self:AddAirbase( DCSAirbaseName ) end end @@ -866,9 +872,8 @@ function DATABASE:_EventOnBirth( Event ) Event.IniUnit = self:FindUnit( Event.IniDCSUnitName ) Event.IniGroup = self:FindGroup( Event.IniDCSGroupName ) local PlayerName = Event.IniUnit:GetPlayerName() - self:E( { "PlayerName:", PlayerName } ) if PlayerName then - self:E( { "Player Joined:", PlayerName } ) + self:I( { "Player Joined:", PlayerName } ) if not self.PLAYERS[PlayerName] then self:AddPlayer( Event.IniUnitName, PlayerName ) end @@ -937,7 +942,7 @@ function DATABASE:_EventOnPlayerLeaveUnit( Event ) if Event.IniObjectCategory == 1 then local PlayerName = Event.IniUnit:GetPlayerName() if PlayerName and self.PLAYERS[PlayerName] then - self:E( { "Player Left:", PlayerName } ) + self:I( { "Player Left:", PlayerName } ) local Settings = SETTINGS:Set( PlayerName ) Settings:RemovePlayerMenu( Event.IniUnit ) self:DeletePlayer( Event.IniUnit, PlayerName ) diff --git a/Moose Development/Moose/Core/Event.lua b/Moose Development/Moose/Core/Event.lua index a1be00587..c7f937c8b 100644 --- a/Moose Development/Moose/Core/Event.lua +++ b/Moose Development/Moose/Core/Event.lua @@ -719,7 +719,7 @@ do -- Event Creation -- @param #EVENT self -- @param AI.AI_Cargo#AI_CARGO Cargo The Cargo created. function EVENT:CreateEventNewCargo( Cargo ) - self:F( { Cargo } ) + self:I( { Cargo } ) local Event = { id = EVENTS.NewCargo, diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 1cf57eb77..81d26911e 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -121,13 +121,16 @@ GROUPTEMPLATE.Takeoff = { -- @return #GROUP self function GROUP:NewTemplate( GroupTemplate, CoalitionSide, CategoryID, CountryID ) local GroupName = GroupTemplate.name + _DATABASE:_RegisterGroupTemplate( GroupTemplate, CoalitionSide, CategoryID, CountryID, GroupName ) - self = BASE:Inherit( self, CONTROLLABLE:New( GroupName ) ) - self:F2( GroupName ) + + local self = BASE:Inherit( self, CONTROLLABLE:New( GroupName ) ) self.GroupName = GroupName - - _DATABASE:AddGroup( GroupName ) - + + if not _DATABASE.GROUPS[GroupName] then + _DATABASE.GROUPS[GroupName] = self + end + self:SetEventPriority( 4 ) return self end @@ -140,7 +143,6 @@ end -- @return #GROUP self function GROUP:Register( GroupName ) local self = BASE:Inherit( self, CONTROLLABLE:New( GroupName ) ) -- #GROUP - self:F( GroupName ) self.GroupName = GroupName self:SetEventPriority( 4 ) From 965012976933c4f0aa7856fb7bdf724c43c532fa Mon Sep 17 00:00:00 2001 From: FlightControl Date: Tue, 14 Aug 2018 22:40:28 +0200 Subject: [PATCH 6/9] AI helicopter dispatcher working to load multiple infantry groups ! --- .../Moose/AI/AI_Cargo_Airplane.lua | 11 ++- .../Moose/AI/AI_Cargo_Dispatcher.lua | 2 +- .../Moose/AI/AI_Cargo_Helicopter.lua | 85 ++++++++++++------- Moose Development/Moose/Cargo/CargoGroup.lua | 2 +- .../Moose/Wrapper/Positionable.lua | 11 +++ 5 files changed, 71 insertions(+), 40 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua index 8cacb48ea..638211643 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua @@ -129,10 +129,7 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) self:SetCarrier( Airplane ) local Desc = Airplane:GetUnit(1):GetDesc() - self:F({Desc=Desc}) - - Airplane:SetCargoBayWeightLimit( Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) ) --Airplane:SetCargoBayVolumeLimit( 15 ) @@ -251,12 +248,15 @@ function AI_CARGO_AIRPLANE:onafterLanded( Airplane, From, Event, To ) env.info("FF load airplane "..Airplane:GetName()) self:Load( Airplane:GetCoordinate() ) self.RoutePickup = false + self.Relocating = true end -- Aircraft was send to this airbase to deploy troops. Initiate unloading. if self.RouteDeploy == true then self:Unload() self.RouteDeploy = false + self.Transporting = false + self.Relocating = false end end @@ -451,10 +451,9 @@ function AI_CARGO_AIRPLANE:onafterLoaded( Airplane, From, Event, To, Cargo ) env.info("FF troops loaded into cargo plane") if Airplane and Airplane:IsAlive() then - self:F( { "Transporting" } ) - self.Transporting = true -- This will only be executed when there is no cargo boarded anymore. The dispatcher will then kick-off the deploy cycle! + self:F( { "Transporting" } ) + self.Transporting = true -- This will only be executed when there is no cargo boarded anymore. The dispatcher will then kick-off the deploy cycle! end - end diff --git a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua index c19d760a8..933556713 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua @@ -404,7 +404,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor() -- The Pickup sequence ... -- Check if this Carrier need to go and Pickup something... -- So, if the cargo bay is not full yet with cargo to be loaded ... - self:I( { IsRelocating = AI_Cargo:IsRelocating() } ) + self:I( { IsRelocating = AI_Cargo:IsRelocating(), IsTransporting = AI_Cargo:IsTransporting() } ) if AI_Cargo:IsRelocating() == false and AI_Cargo:IsTransporting() == false then -- ok, so there is a free Carrier -- now find the first cargo that is Unloaded diff --git a/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua b/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua index 1e3141649..faa85affc 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua @@ -43,7 +43,7 @@ function AI_CARGO_HELICOPTER:New( Helicopter, CargoSet ) self:AddTransition( "Unloaded", "Pickup", "*" ) self:AddTransition( "Loaded", "Deploy", "*" ) - self:AddTransition( "Unloaded", "Load", "Boarding" ) + self:AddTransition( { "Unloaded", "Loading" }, "Load", "Boarding" ) self:AddTransition( "Boarding", "Board", "Boarding" ) self:AddTransition( "Boarding", "Loaded", "Loaded" ) self:AddTransition( "Loaded", "Unload", "Unboarding" ) @@ -144,6 +144,16 @@ function AI_CARGO_HELICOPTER:New( Helicopter, CargoSet ) end ) + for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do + local Desc = HelicopterUnit:GetDesc() + self:F({Desc=Desc}) + HelicopterUnit:SetCargoBayWeightLimit( Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) ) + --Airplane:SetCargoBayVolumeLimit( 15 ) + end + + self.Relocating = false + self.Transporting = false + self:SetCarrier( Helicopter ) return self @@ -380,7 +390,6 @@ function AI_CARGO_HELICOPTER:onbeforeLoad( Helicopter, From, Event, To) self.BoardingCount = 0 if Helicopter and Helicopter:IsAlive() then - self.Helicopter_Cargo = {} for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do local HelicopterUnit = HelicopterUnit -- Wrapper.Unit#UNIT for _, Cargo in pairs( self.CargoSet:GetSet() ) do @@ -393,10 +402,6 @@ function AI_CARGO_HELICOPTER:onbeforeLoad( Helicopter, From, Event, To) Cargo:Board( HelicopterUnit, 25 ) self:__Board( 1, Cargo ) Boarding = true - - -- So now this APCUnit has Cargo that is being loaded. - -- This will be used further in the logic to follow and to check cargo status. - self.Helicopter_Cargo[HelicopterUnit] = Cargo break end end @@ -424,7 +429,27 @@ function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To, Cargo ) if not Cargo:IsLoaded() then self:__Board( 10, Cargo ) else - self:__Loaded( 1, Cargo ) + for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do + local HelicopterUnit = HelicopterUnit -- Wrapper.Unit#UNIT + for _, Cargo in pairs( self.CargoSet:GetSet() ) do + local Cargo = Cargo -- Cargo.Cargo#CARGO + if Cargo:IsUnLoaded() then + if Cargo:IsInLoadRadius( HelicopterUnit:GetCoordinate() ) then + local CargoBayFreeWeight = HelicopterUnit:GetCargoBayFreeWeight() + local CargoWeight = Cargo:GetWeight() + + -- Only when there is space within the bay to load the next cargo item! + if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then + + Cargo:Board( HelicopterUnit, 25 ) + self:__Board( 10, Cargo ) + return + end + end + end + end + end + self:__Loaded( 1, Cargo ) -- Will only be executed when no more cargo is boarded. end end @@ -438,24 +463,12 @@ end -- @param #string To To state. -- @param Cargo.Cargo#CARGO Cargo Cargo object. -- @return #boolean Cargo is loaded. -function AI_CARGO_HELICOPTER:onbeforeLoaded( Helicopter, From, Event, To, Cargo ) +function AI_CARGO_HELICOPTER:onafterLoaded( Helicopter, From, Event, To, Cargo ) self:F( { Helicopter, From, Event, To, Cargo } ) - local Loaded = true - if Helicopter and Helicopter:IsAlive() then - for HelicopterUnit, Cargo in pairs( self.Helicopter_Cargo ) do - local Cargo = Cargo -- Cargo.Cargo#CARGO - self:F( { IsLoaded = Cargo:IsLoaded(), IsDestroyed = Cargo:IsDestroyed() } ) - if not Cargo:IsLoaded() and not Cargo:IsDestroyed() then - Loaded = false - end - end - + self.Transporting = true end - - return Loaded - end @@ -471,9 +484,11 @@ function AI_CARGO_HELICOPTER:onafterUnload( Helicopter, From, Event, To, Deploye for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do local HelicopterUnit = HelicopterUnit -- Wrapper.Unit#UNIT for _, Cargo in pairs( HelicopterUnit:GetCargo() ) do - Cargo:UnBoard() - Cargo:SetDeployed( true ) - self:__Unboard( 10, Cargo, Deployed ) + if Cargo:IsLoaded() then + Cargo:UnBoard() + Cargo:SetDeployed( true ) + self:__Unboard( 10, Cargo, Deployed ) + end end end end @@ -495,6 +510,17 @@ function AI_CARGO_HELICOPTER:onafterUnboard( Helicopter, From, Event, To, Cargo, if not Cargo:IsUnLoaded() then self:__Unboard( 10, Cargo, Deployed ) else + for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do + local HelicopterUnit = HelicopterUnit -- Wrapper.Unit#UNIT + for _, Cargo in pairs( HelicopterUnit:GetCargo() ) do + if Cargo:IsLoaded() then + Cargo:UnBoard() + Cargo:SetDeployed( true ) + self:__Unboard( 10, Cargo, Deployed ) + return + end + end + end self:__Unloaded( 1, Cargo, Deployed ) end end @@ -519,21 +545,16 @@ function AI_CARGO_HELICOPTER:onbeforeUnloaded( Helicopter, From, Event, To, Carg if Helicopter and Helicopter:IsAlive() then for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do - local CargoCheck = self.Helicopter_Cargo[HelicopterUnit] -- Cargo.Cargo#CARGO - if CargoCheck then - self:F( { CargoCheck:GetName(), IsUnLoaded = CargoCheck:IsUnLoaded() } ) - if CargoCheck:IsUnLoaded() == false then + local IsEmpty = HelicopterUnit:IsCargoEmpty() + self:I({ IsEmpty = IsEmpty }) + if not IsEmpty then AllUnloaded = false break - end end end if AllUnloaded == true then if Deployed == true then - for HelicopterUnit, Cargo in pairs( self.Helicopter_Cargo ) do - local Cargo = Cargo -- Cargo.Cargo#CARGO - end self.Helicopter_Cargo = {} end self.Helicopter = Helicopter diff --git a/Moose Development/Moose/Cargo/CargoGroup.lua b/Moose Development/Moose/Cargo/CargoGroup.lua index b51e5502c..9a0294855 100644 --- a/Moose Development/Moose/Cargo/CargoGroup.lua +++ b/Moose Development/Moose/Cargo/CargoGroup.lua @@ -101,7 +101,7 @@ do -- CARGO_GROUP end -- Then we register the new group in the database - GROUP:NewTemplate( GroupTemplate, GroupTemplate.CoalitionID, GroupTemplate.CategoryID, GroupTemplate.CountryID ) + self.CargoGroup = GROUP:NewTemplate( GroupTemplate, GroupTemplate.CoalitionID, GroupTemplate.CategoryID, GroupTemplate.CountryID ) -- Now we spawn the new group based on the template created. self.CargoObject = _DATABASE:Spawn( GroupTemplate ) diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index 1de5c21fe..017c5f70f 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -840,6 +840,17 @@ do -- Cargo self.__.Cargo = {} end + --- Is cargo bay empty. + -- @param #POSITIONABLE self + function POSITIONABLE:IsCargoEmpty() + local IsEmpty = true + for _, Cargo in pairs( self.__.Cargo ) do + IsEmpty = false + break + end + return IsEmpty + end + --- Get cargo item count. -- @param #POSITIONABLE self -- @return Core.Cargo#CARGO Cargo From a02d3c195013fff3f79d87a22db46f768b8605e5 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Fri, 17 Aug 2018 07:59:53 +0200 Subject: [PATCH 7/9] Cargo Dispatcher APC - Multiple Cargo Groups and Weight in APC --- Moose Development/Moose/AI/AI_Cargo_APC.lua | 97 +++++++++++++++---- .../Moose/AI/AI_Cargo_Dispatcher.lua | 5 + .../Moose/AI/AI_Cargo_Dispatcher_APC.lua | 4 +- .../Moose/AI/AI_Cargo_Helicopter.lua | 5 +- Moose Development/Moose/Cargo/Cargo.lua | 3 +- Moose Development/Moose/Cargo/CargoGroup.lua | 13 ++- .../Moose/Wrapper/Positionable.lua | 1 - 7 files changed, 97 insertions(+), 31 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Cargo_APC.lua b/Moose Development/Moose/AI/AI_Cargo_APC.lua index 13f88324e..fbe2dd1f4 100644 --- a/Moose Development/Moose/AI/AI_Cargo_APC.lua +++ b/Moose Development/Moose/AI/AI_Cargo_APC.lua @@ -96,7 +96,7 @@ function AI_CARGO_APC:New( APC, CargoSet, CombatRadius ) self:AddTransition( "Loaded", "Deploy", "*" ) self:AddTransition( "*", "Load", "Boarding" ) - self:AddTransition( "Boarding", "Board", "Boarding" ) + self:AddTransition( { "Boarding", "Loaded" }, "Board", "Boarding" ) self:AddTransition( "Boarding", "Loaded", "Loaded" ) self:AddTransition( "Loaded", "Unload", "Unboarding" ) self:AddTransition( "Unboarding", "Unboard", "Unboarding" ) @@ -194,8 +194,20 @@ function AI_CARGO_APC:New( APC, CargoSet, CombatRadius ) self:__Monitor( 1 ) - self:SetCarrier( APC ) + + for _, APCUnit in pairs( APC:GetUnits() ) do + local Desc = APCUnit:GetDesc() + self:F({Desc=Desc}) +-- local Box = CargoUnit:GetBoundingBox() + local VolumeUnit = ( Desc.box.max.x - Desc.box.min.x ) * ( Desc.box.max.y - Desc.box.min.y ) * ( Desc.box.max.z - Desc.box.min.z ) + self:F({VolumeUnit=VolumeUnit}) + local CargoBayWeightLimit = 1250 + APCUnit:SetCargoBayWeightLimit( CargoBayWeightLimit ) + self:F({CargoBayWeightLimit=CargoBayWeightLimit}) + --Airplane:SetCargoBayVolumeLimit( 15 ) + end + self.Transporting = false self.Relocating = false @@ -411,7 +423,6 @@ function AI_CARGO_APC:onbeforeLoad( APC, From, Event, To ) self:F( { APC, From, Event, To } ) local Boarding = false - self.BoardingCount = 0 if APC and APC:IsAlive() then self.APC_Cargo = {} @@ -427,11 +438,11 @@ function AI_CARGO_APC:onbeforeLoad( APC, From, Event, To ) --Cargo:Ungroup() Cargo:Board( APCUnit, 25 ) self:__Board( 1, Cargo ) - Boarding = true - + -- So now this APCUnit has Cargo that is being loaded. -- This will be used further in the logic to follow and to check cargo status. self.APC_Cargo[APCUnit] = Cargo + Boarding = true break end end @@ -458,7 +469,31 @@ function AI_CARGO_APC:onafterBoard( APC, From, Event, To, Cargo ) if not Cargo:IsLoaded() then self:__Board( 10, Cargo ) else - self:__Loaded( 1 ) + for _, APCUnit in pairs( APC:GetUnits() ) do + local APCUnit = APCUnit -- Wrapper.Unit#UNIT + for _, Cargo in pairs( self.CargoSet:GetSet() ) do + local Cargo = Cargo -- Cargo.Cargo#CARGO + if Cargo:IsUnLoaded() then + if Cargo:IsInLoadRadius( APCUnit:GetCoordinate() ) then + local CargoBayFreeWeight = APCUnit:GetCargoBayFreeWeight() + local CargoWeight = Cargo:GetWeight() + + self:F({CargoBayFreeWeight=CargoBayFreeWeight}) + + -- Only when there is space within the bay to load the next cargo item! + if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then + Cargo:Board( APCUnit, 25 ) + self:__Board( 10, Cargo ) + -- So now this APCUnit has Cargo that is being loaded. + -- This will be used further in the logic to follow and to check cargo status. + self.APC_Cargo[APCUnit] = Cargo + return + end + end + end + end + end + self:__Loaded( 5, Cargo ) end end @@ -471,7 +506,7 @@ end -- @param #string Event Event. -- @param #string To To state. -- @return #boolean Cargo loaded. -function AI_CARGO_APC:onbeforeLoaded( APC, From, Event, To ) +function AI_CARGO_APC:onbeforeLoaded( APC, From, Event, To, Cargo ) self:F( { APC, From, Event, To } ) local Loaded = true @@ -484,7 +519,6 @@ function AI_CARGO_APC:onbeforeLoaded( APC, From, Event, To ) Loaded = false end end - end if Loaded == true then @@ -496,6 +530,9 @@ function AI_CARGO_APC:onbeforeLoaded( APC, From, Event, To ) end + + + --- On after Unload event. -- @param #AI_CARGO_APC self -- @param Wrapper.Group#GROUP APC @@ -512,6 +549,7 @@ function AI_CARGO_APC:onafterUnload( APC, From, Event, To, Deployed ) APC:RouteStop() for _, Cargo in pairs( APCUnit:GetCargo() ) do Cargo:UnBoard() + Cargo:SetDeployed( true ) self:__Unboard( 10, Cargo, Deployed ) end end @@ -534,6 +572,17 @@ function AI_CARGO_APC:onafterUnboard( APC, From, Event, To, Cargo, Deployed ) if not Cargo:IsUnLoaded() then self:__Unboard( 10, Cargo, Deployed ) else + for _, APCUnit in pairs( APC:GetUnits() ) do + local APCUnit = APCUnit -- Wrapper.Unit#UNIT + for _, Cargo in pairs( APCUnit:GetCargo() ) do + if Cargo:IsLoaded() then + Cargo:UnBoard() + Cargo:SetDeployed( true ) + self:__Unboard( 10, Cargo, Deployed ) + return + end + end + end self:__Unloaded( 1, Cargo, Deployed ) end end @@ -559,22 +608,16 @@ function AI_CARGO_APC:onbeforeUnloaded( APC, From, Event, To, Cargo, Deployed ) if APC and APC:IsAlive() then for _, APCUnit in pairs( APC:GetUnits() ) do local APCUnit = APCUnit -- Wrapper.Unit#UNIT - local CargoCheck = self.APC_Cargo[APCUnit] - if CargoCheck then - self:F( { CargoCheck:GetName(), IsUnLoaded = CargoCheck:IsUnLoaded() } ) - if CargoCheck:IsUnLoaded() == false then - AllUnloaded = false - break - end + local IsEmpty = APCUnit:IsCargoEmpty() + self:I({ IsEmpty = IsEmpty }) + if not IsEmpty then + AllUnloaded = false + break end end if AllUnloaded == true then if Deployed == true then - for APCUnit, Cargo in pairs( self.APC_Cargo ) do - local Cargo = Cargo -- Cargo.Cargo#CARGO - Cargo:SetDeployed( true ) - end self.APC_Cargo = {} end self:Guard() @@ -587,6 +630,21 @@ function AI_CARGO_APC:onbeforeUnloaded( APC, From, Event, To, Cargo, Deployed ) end +--- On after Unloaded event. +-- @param #AI_CARGO_APC self +-- @param Wrapper.Group#GROUP APC +-- @param #string From From state. +-- @param #string Event Event. +-- @param #string To To state. +-- @param #string Cargo.Cargo#CARGO Cargo Cargo object. +-- @param #boolean Deployed Cargo is deployed. +-- @return #boolean All cargo unloaded. +function AI_CARGO_APC:onafterUnloaded( APC, From, Event, To, Cargo, Deployed ) + self:F( { APC, From, Event, To, Cargo:GetName(), Deployed = Deployed } ) + + self.Transporting = false + +end --- On after Follow event. -- @param #AI_CARGO_APC self @@ -632,7 +690,6 @@ function AI_CARGO_APC._Deploy( APC, self ) if APC:IsAlive() then self:Unload( true ) - self.Transporting = false self.Relocating = false end end diff --git a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua index 933556713..9bbfe26a8 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua @@ -416,6 +416,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor() self:F( { Cargo = Cargo:GetName(), UnLoaded = Cargo:IsUnLoaded(), Deployed = Cargo:IsDeployed(), PickupCargo = self.PickupCargo[Carrier] ~= nil } ) if Cargo:IsUnLoaded() == true and Cargo:IsDeployed() == false then local CargoCoordinate = Cargo:GetCoordinate() + self:F({CargoCoordinate = CargoCoordinate }) local CoordinateFree = true for CarrierPickup, Coordinate in pairs( self.PickupCargo ) do if CarrierPickup:IsAlive() == true then @@ -427,6 +428,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor() self.PickupCargo[CarrierPickup] = nil end end + self:F({CoordinateFree = CoordinateFree}) if CoordinateFree == true then self.PickupCargo[Carrier] = CargoCoordinate PickupCargo = Cargo @@ -435,6 +437,8 @@ function AI_CARGO_DISPATCHER:onafterMonitor() end end + self:F( { PickupCargo = PickupCargo} ) + if PickupCargo then self.CarrierHome[Carrier] = nil local PickupCoordinate = PickupCargo:GetCoordinate():GetRandomCoordinateInRadius( self.PickupOuterRadius, self.PickupInnerRadius ) @@ -567,6 +571,7 @@ function AI_CARGO_DISPATCHER:OnAfterLoaded( From, Event, To, Carrier, Cargo ) end end + self:F({Carrier=Carrier}) self.PickupCargo[Carrier] = nil end diff --git a/Moose Development/Moose/AI/AI_Cargo_Dispatcher_APC.lua b/Moose Development/Moose/AI/AI_Cargo_Dispatcher_APC.lua index 413ca7c26..1612ce2c7 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Dispatcher_APC.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Dispatcher_APC.lua @@ -101,9 +101,9 @@ AI_CARGO_DISPATCHER_APC = { -- SetDeployZone = SET_ZONE:New():FilterPrefixes( "Deploy" ):FilterStart() -- AICargoDispatcher = AI_CARGO_DISPATCHER_APC:New( SetAPC, SetCargo, SetDeployZone, 500 ) -- -function AI_CARGO_DISPATCHER_APC:NewWithZones( SetAPC, SetCargo, SetDeployZone, CombatRadius ) +function AI_CARGO_DISPATCHER_APC:New( SetAPC, SetCargo, SetDeployZone, CombatRadius ) - local self = BASE:Inherit( self, AI_CARGO_DISPATCHER:New( SetAPC, SetCargo, SetDeployZone ) ) -- #AI_CARGO_DISPATCHER_APC + local self = BASE:Inherit( self, AI_CARGO_DISPATCHER:NewWithZones( SetAPC, SetCargo, SetDeployZone ) ) -- #AI_CARGO_DISPATCHER_APC self.CombatRadius = CombatRadius or 500 diff --git a/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua b/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua index faa85affc..df6865545 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua @@ -395,7 +395,7 @@ function AI_CARGO_HELICOPTER:onbeforeLoad( Helicopter, From, Event, To) for _, Cargo in pairs( self.CargoSet:GetSet() ) do local Cargo = Cargo -- Cargo.Cargo#CARGO self:F( { IsUnLoaded = Cargo:IsUnLoaded() } ) - if Cargo:IsUnLoaded() then + if Cargo:IsUnLoaded() and not Cargo:IsDeployed() then if Cargo:IsInLoadRadius( HelicopterUnit:GetCoordinate() ) then self:F( { "In radius", HelicopterUnit:GetName() } ) --Cargo:Ungroup() @@ -440,7 +440,6 @@ function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To, Cargo ) -- Only when there is space within the bay to load the next cargo item! if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then - Cargo:Board( HelicopterUnit, 25 ) self:__Board( 10, Cargo ) return @@ -455,7 +454,7 @@ function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To, Cargo ) end ---- On before Loaded event. Check if cargo is loaded. +--- On after Loaded event. Check if cargo is loaded. -- @param #AI_CARGO_HELICOPTER self -- @param Wrapper.Group#GROUP Helicopter -- @param #string From From state. diff --git a/Moose Development/Moose/Cargo/Cargo.lua b/Moose Development/Moose/Cargo/Cargo.lua index 50cade298..3311a1bff 100644 --- a/Moose Development/Moose/Cargo/Cargo.lua +++ b/Moose Development/Moose/Cargo/Cargo.lua @@ -779,7 +779,8 @@ do -- CARGO local Distance = 0 if self:IsUnLoaded() then - Distance = Coordinate:Get2DDistance( self.CargoObject:GetCoordinate() ) + local CargoCoordinate = self.CargoObject:GetCoordinate() + Distance = Coordinate:Get2DDistance( CargoCoordinate ) self:T( Distance ) if Distance <= self.LoadRadius then return true diff --git a/Moose Development/Moose/Cargo/CargoGroup.lua b/Moose Development/Moose/Cargo/CargoGroup.lua index 9a0294855..63f9203d1 100644 --- a/Moose Development/Moose/Cargo/CargoGroup.lua +++ b/Moose Development/Moose/Cargo/CargoGroup.lua @@ -500,8 +500,6 @@ do -- CARGO_GROUP -- @return Core.Point#COORDINATE The current Coordinate of the first Cargo of the CargoGroup. -- @return #nil There is no valid Cargo in the CargoGroup. function CARGO_GROUP:GetCoordinate() - self:F() - local Cargo = self:GetFirstAlive() -- Cargo.Cargo#CARGO if Cargo then @@ -635,12 +633,19 @@ do -- CARGO_GROUP if Cargo then local Distance = 0 + local CargoCoordinate if Cargo:IsLoaded() then - Distance = Coordinate:Get2DDistance( Cargo.CargoCarrier:GetCoordinate() ) + CargoCoordinate = Cargo.CargoCarrier:GetCoordinate() else - Distance = Coordinate:Get2DDistance( Cargo.CargoObject:GetCoordinate() ) + CargoCoordinate = Cargo.CargoObject:GetCoordinate() end +-- if CargoCoordinate then + Distance = Coordinate:Get2DDistance( CargoCoordinate ) +-- else +-- return false +-- end + self:F( { Distance = Distance, LoadRadius = self.LoadRadius } ) if Distance <= self.LoadRadius then return true diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index 017c5f70f..287338c2b 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -879,7 +879,6 @@ do -- Cargo function POSITIONABLE:GetCargoBayFreeWeight() local CargoWeight = 0 for CargoName, Cargo in pairs( self.__.Cargo ) do - self:F( { Cargo = Cargo } ) CargoWeight = CargoWeight + Cargo:GetWeight() end return self.__.CargoBayWeightLimit - CargoWeight From 7a2dee41624ea9d4e7690455c2bac9624d2b639f Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sun, 19 Aug 2018 07:26:50 +0200 Subject: [PATCH 8/9] OK. Revised cargo for AI is working. --- Moose Development/Moose/AI/AI_Cargo_APC.lua | 74 ++++++++++++++----- .../Moose/AI/AI_Cargo_Dispatcher.lua | 8 -- .../Moose/AI/AI_Cargo_Helicopter.lua | 58 +++++++++++++-- 3 files changed, 107 insertions(+), 33 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Cargo_APC.lua b/Moose Development/Moose/AI/AI_Cargo_APC.lua index fbe2dd1f4..acf565f81 100644 --- a/Moose Development/Moose/AI/AI_Cargo_APC.lua +++ b/Moose Development/Moose/AI/AI_Cargo_APC.lua @@ -198,14 +198,41 @@ function AI_CARGO_APC:New( APC, CargoSet, CombatRadius ) for _, APCUnit in pairs( APC:GetUnits() ) do local Desc = APCUnit:GetDesc() - self:F({Desc=Desc}) --- local Box = CargoUnit:GetBoundingBox() + local VolumeUnit = ( Desc.box.max.x - Desc.box.min.x ) * ( Desc.box.max.y - Desc.box.min.y ) * ( Desc.box.max.z - Desc.box.min.z ) - self:F({VolumeUnit=VolumeUnit}) - local CargoBayWeightLimit = 1250 + + local Weights = { + ["M1126 Stryker ICV"] = 9, + ["M-113"] = 9, + ["AAV7"] = 25, + ["M2A1_halftrack"] = 9, + ["BMD-1"] = 9, + ["BMP-1"] = 8, + ["BMP-2"] = 7, + ["BMP-3"] = 8, + ["Boman"] = 25, + ["BTR-80"] = 9, + ["BTR_D"] = 12, + ["Cobra"] = 8, + ["LAV-25"] = 6, + ["M-2 Bradley"] = 6, + ["M1043 HMMWV Armament"] = 4, + ["M1045 HMMWV TOW"] = 4, + ["M1126 Stryker ICV"] = 9, + ["M1134 Stryker ATGM"] = 9, + ["Marder"] = 6, + ["MCV-80"] = 9, + ["MLRS FDDM"] = 4, + ["MTLB"] = 25, + ["TPZ"] = 10, + } + + local CargoBayWeightLimit = ( Weights[Desc.typeName] or 0 ) * 70 + APCUnit:SetCargoBayWeightLimit( CargoBayWeightLimit ) - self:F({CargoBayWeightLimit=CargoBayWeightLimit}) --Airplane:SetCargoBayVolumeLimit( 15 ) + + self:F( {TypeName = Desc.typeName, Desc = Desc, WeightLimit = CargoBayWeightLimit } ) end self.Transporting = false @@ -434,16 +461,25 @@ function AI_CARGO_APC:onbeforeLoad( APC, From, Event, To ) if Cargo:IsUnLoaded() and not Cargo:IsDeployed() then if Cargo:IsInLoadRadius( APCUnit:GetCoordinate() ) then self:F( { "In radius", APCUnit:GetName() } ) - APC:RouteStop() - --Cargo:Ungroup() - Cargo:Board( APCUnit, 25 ) - self:__Board( 1, Cargo ) + + local CargoBayFreeWeight = APCUnit:GetCargoBayFreeWeight() + local CargoWeight = Cargo:GetWeight() + + self:F({CargoBayFreeWeight=CargoBayFreeWeight}) - -- So now this APCUnit has Cargo that is being loaded. - -- This will be used further in the logic to follow and to check cargo status. - self.APC_Cargo[APCUnit] = Cargo - Boarding = true - break + -- Only when there is space within the bay to load the next cargo item! + if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then + APC:RouteStop() + --Cargo:Ungroup() + Cargo:Board( APCUnit, 25 ) + self:__Board( 1, Cargo ) + + -- So now this APCUnit has Cargo that is being loaded. + -- This will be used further in the logic to follow and to check cargo status. + self.APC_Cargo[APCUnit] = Cargo + Boarding = true + break + end end end end @@ -548,10 +584,12 @@ function AI_CARGO_APC:onafterUnload( APC, From, Event, To, Deployed ) local APCUnit = APCUnit -- Wrapper.Unit#UNIT APC:RouteStop() for _, Cargo in pairs( APCUnit:GetCargo() ) do - Cargo:UnBoard() - Cargo:SetDeployed( true ) - self:__Unboard( 10, Cargo, Deployed ) - end + if Cargo:IsLoaded() then + Cargo:UnBoard() + Cargo:SetDeployed( true ) + self:__Unboard( 10, Cargo, Deployed ) + end + end end end diff --git a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua index 9bbfe26a8..602868607 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua @@ -416,7 +416,6 @@ function AI_CARGO_DISPATCHER:onafterMonitor() self:F( { Cargo = Cargo:GetName(), UnLoaded = Cargo:IsUnLoaded(), Deployed = Cargo:IsDeployed(), PickupCargo = self.PickupCargo[Carrier] ~= nil } ) if Cargo:IsUnLoaded() == true and Cargo:IsDeployed() == false then local CargoCoordinate = Cargo:GetCoordinate() - self:F({CargoCoordinate = CargoCoordinate }) local CoordinateFree = true for CarrierPickup, Coordinate in pairs( self.PickupCargo ) do if CarrierPickup:IsAlive() == true then @@ -428,7 +427,6 @@ function AI_CARGO_DISPATCHER:onafterMonitor() self.PickupCargo[CarrierPickup] = nil end end - self:F({CoordinateFree = CoordinateFree}) if CoordinateFree == true then self.PickupCargo[Carrier] = CargoCoordinate PickupCargo = Cargo @@ -437,8 +435,6 @@ function AI_CARGO_DISPATCHER:onafterMonitor() end end - self:F( { PickupCargo = PickupCargo} ) - if PickupCargo then self.CarrierHome[Carrier] = nil local PickupCoordinate = PickupCargo:GetCoordinate():GetRandomCoordinateInRadius( self.PickupOuterRadius, self.PickupInnerRadius ) @@ -571,10 +567,6 @@ function AI_CARGO_DISPATCHER:OnAfterLoaded( From, Event, To, Carrier, Cargo ) end end - self:F({Carrier=Carrier}) self.PickupCargo[Carrier] = nil end - - - diff --git a/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua b/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua index df6865545..1341129f6 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua @@ -20,7 +20,8 @@ -- @field #AI_CARGO_HELICOPTER AI_CARGO_HELICOPTER = { ClassName = "AI_CARGO_HELICOPTER", - Coordinate = nil -- Core.Point#COORDINATE, + Coordinate = nil, -- Core.Point#COORDINATE, + Helicopter_Cargo = {}, } AI_CARGO_QUEUE = {} @@ -148,7 +149,6 @@ function AI_CARGO_HELICOPTER:New( Helicopter, CargoSet ) local Desc = HelicopterUnit:GetDesc() self:F({Desc=Desc}) HelicopterUnit:SetCargoBayWeightLimit( Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) ) - --Airplane:SetCargoBayVolumeLimit( 15 ) end self.Relocating = false @@ -398,11 +398,22 @@ function AI_CARGO_HELICOPTER:onbeforeLoad( Helicopter, From, Event, To) if Cargo:IsUnLoaded() and not Cargo:IsDeployed() then if Cargo:IsInLoadRadius( HelicopterUnit:GetCoordinate() ) then self:F( { "In radius", HelicopterUnit:GetName() } ) - --Cargo:Ungroup() - Cargo:Board( HelicopterUnit, 25 ) - self:__Board( 1, Cargo ) - Boarding = true - break + + local CargoBayFreeWeight = HelicopterUnit:GetCargoBayFreeWeight() + local CargoWeight = Cargo:GetWeight() + + self:F({CargoBayFreeWeight=CargoBayFreeWeight}) + + -- Only when there is space within the bay to load the next cargo item! + if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then + + --Cargo:Ungroup() + Cargo:Board( HelicopterUnit, 25 ) + self:__Board( 1, Cargo ) + self.Helicopter_Cargo[HelicopterUnit] = Cargo + Boarding = true + break + end end end end @@ -438,10 +449,13 @@ function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To, Cargo ) local CargoBayFreeWeight = HelicopterUnit:GetCargoBayFreeWeight() local CargoWeight = Cargo:GetWeight() + self:F({CargoBayFreeWeight=CargoBayFreeWeight}) + -- Only when there is space within the bay to load the next cargo item! if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then Cargo:Board( HelicopterUnit, 25 ) self:__Board( 10, Cargo ) + self.Helicopter_Cargo[HelicopterUnit] = Cargo return end end @@ -454,6 +468,36 @@ function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To, Cargo ) end + +--- On before Loaded event. +-- @param #AI_CARGO_HELICOPTER self +-- @param Wrapper.Group#GROUP Helicopter +-- @param #string From From state. +-- @param #string Event Event. +-- @param #string To To state. +-- @return #boolean Cargo loaded. +function AI_CARGO_HELICOPTER:onbeforeLoaded( Helicopter, From, Event, To, Cargo ) + self:F( { Helicopter, From, Event, To } ) + + local Loaded = true + + if Helicopter and Helicopter:IsAlive() then + for HelicopterUnit, Cargo in pairs( self.Helicopter_Cargo ) do + local Cargo = Cargo -- Cargo.Cargo#CARGO + self:F( { IsLoaded = Cargo:IsLoaded(), IsDestroyed = Cargo:IsDestroyed(), Cargo:GetName(), Helicopter:GetName() } ) + if not Cargo:IsLoaded() and not Cargo:IsDestroyed() then + Loaded = false + end + end + end + + return Loaded + +end + + + + --- On after Loaded event. Check if cargo is loaded. -- @param #AI_CARGO_HELICOPTER self -- @param Wrapper.Group#GROUP Helicopter From bf903c0cc71eade75171e20d3b35183199cc8ad6 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Wed, 22 Aug 2018 20:41:37 +0200 Subject: [PATCH 9/9] New weight driven limits logic for cargo to load multiple cargo. Fixed near range issue for carriers. now the infantry disappearance range for boarding is calculated by the carrier bounding range, which is derived from the bounding rectangle on the Y-axis. The near range parameter can still be provided and will be interpreted as the loading range for static cargo objects! --- Moose Development/Moose/AI/AI_Cargo_APC.lua | 37 +----- .../Moose/AI/AI_Cargo_Airplane.lua | 5 +- .../Moose/AI/AI_Cargo_Helicopter.lua | 4 +- Moose Development/Moose/Cargo/Cargo.lua | 2 +- Moose Development/Moose/Cargo/CargoUnit.lua | 11 +- .../Moose/Tasking/Task_CARGO.lua | 15 ++- .../Moose/Wrapper/Positionable.lua | 121 +++++++++++++++++- Moose Development/Moose/Wrapper/Unit.lua | 44 ------- 8 files changed, 134 insertions(+), 105 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Cargo_APC.lua b/Moose Development/Moose/AI/AI_Cargo_APC.lua index acf565f81..c1c871cdd 100644 --- a/Moose Development/Moose/AI/AI_Cargo_APC.lua +++ b/Moose Development/Moose/AI/AI_Cargo_APC.lua @@ -197,42 +197,7 @@ function AI_CARGO_APC:New( APC, CargoSet, CombatRadius ) self:SetCarrier( APC ) for _, APCUnit in pairs( APC:GetUnits() ) do - local Desc = APCUnit:GetDesc() - - local VolumeUnit = ( Desc.box.max.x - Desc.box.min.x ) * ( Desc.box.max.y - Desc.box.min.y ) * ( Desc.box.max.z - Desc.box.min.z ) - - local Weights = { - ["M1126 Stryker ICV"] = 9, - ["M-113"] = 9, - ["AAV7"] = 25, - ["M2A1_halftrack"] = 9, - ["BMD-1"] = 9, - ["BMP-1"] = 8, - ["BMP-2"] = 7, - ["BMP-3"] = 8, - ["Boman"] = 25, - ["BTR-80"] = 9, - ["BTR_D"] = 12, - ["Cobra"] = 8, - ["LAV-25"] = 6, - ["M-2 Bradley"] = 6, - ["M1043 HMMWV Armament"] = 4, - ["M1045 HMMWV TOW"] = 4, - ["M1126 Stryker ICV"] = 9, - ["M1134 Stryker ATGM"] = 9, - ["Marder"] = 6, - ["MCV-80"] = 9, - ["MLRS FDDM"] = 4, - ["MTLB"] = 25, - ["TPZ"] = 10, - } - - local CargoBayWeightLimit = ( Weights[Desc.typeName] or 0 ) * 70 - - APCUnit:SetCargoBayWeightLimit( CargoBayWeightLimit ) - --Airplane:SetCargoBayVolumeLimit( 15 ) - - self:F( {TypeName = Desc.typeName, Desc = Desc, WeightLimit = CargoBayWeightLimit } ) + APCUnit:SetCargoBayWeightLimit() end self.Transporting = false diff --git a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua index 638211643..1d5d1e398 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua @@ -128,10 +128,7 @@ function AI_CARGO_AIRPLANE:New( Airplane, CargoSet ) -- Set carrier. self:SetCarrier( Airplane ) - local Desc = Airplane:GetUnit(1):GetDesc() - self:F({Desc=Desc}) - Airplane:SetCargoBayWeightLimit( Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) ) - --Airplane:SetCargoBayVolumeLimit( 15 ) + Airplane:SetCargoBayWeightLimit() self.Relocating = true diff --git a/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua b/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua index 1341129f6..0148e9c79 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Helicopter.lua @@ -146,9 +146,7 @@ function AI_CARGO_HELICOPTER:New( Helicopter, CargoSet ) ) for _, HelicopterUnit in pairs( Helicopter:GetUnits() ) do - local Desc = HelicopterUnit:GetDesc() - self:F({Desc=Desc}) - HelicopterUnit:SetCargoBayWeightLimit( Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) ) + HelicopterUnit:SetCargoBayWeightLimit() end self.Relocating = false diff --git a/Moose Development/Moose/Cargo/Cargo.lua b/Moose Development/Moose/Cargo/Cargo.lua index 3311a1bff..82015511e 100644 --- a/Moose Development/Moose/Cargo/Cargo.lua +++ b/Moose Development/Moose/Cargo/Cargo.lua @@ -811,7 +811,7 @@ do -- CARGO end - --- Check if CargoCarrier is near the Cargo to be Loaded. + --- Check if CargoCarrier is near the coordinate within NearRadius. -- @param #CARGO self -- @param Core.Point#COORDINATE Coordinate -- @param #number NearRadius The radius when the cargo will board the Carrier (to avoid collision). diff --git a/Moose Development/Moose/Cargo/CargoUnit.lua b/Moose Development/Moose/Cargo/CargoUnit.lua index 90eceeda9..da9c73f2b 100644 --- a/Moose Development/Moose/Cargo/CargoUnit.lua +++ b/Moose Development/Moose/Cargo/CargoUnit.lua @@ -226,8 +226,6 @@ do -- CARGO_UNIT function CARGO_UNIT:onafterBoard( From, Event, To, CargoCarrier, NearRadius, ... ) self:F( { From, Event, To, CargoCarrier, NearRadius } ) - local NearRadius = NearRadius or 25 - self.CargoInAir = self.CargoObject:InAir() local Desc = self.CargoObject:GetDesc() @@ -239,6 +237,9 @@ do -- CARGO_UNIT -- Only move the group to the carrier when the cargo is not in the air -- (eg. cargo can be on a oil derrick, moving the cargo on the oil derrick will drop the cargo on the sea). if not self.CargoInAir then + -- If NearRadius is given, then use the given NearRadius, otherwise calculate the NearRadius + -- based upon the Carrier bounding radius, which is calculated from the bounding rectangle on the Y axis. + local NearRadius = CargoCarrier:GetBoundingRadius( NearRadius ) if self:IsNear( CargoCarrier:GetPointVec2(), NearRadius ) then self:Load( CargoCarrier, NearRadius, ... ) else @@ -250,8 +251,6 @@ do -- CARGO_UNIT local Angle = 180 local Distance = 5 - NearRadius = NearRadius or 25 - local CargoCarrierPointVec2 = CargoCarrier:GetPointVec2() local CargoCarrierHeading = CargoCarrier:GetHeading() -- Get Heading of object in degrees. local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle ) @@ -302,8 +301,6 @@ do -- CARGO_UNIT local Angle = 180 local Distance = 5 - NearRadius = NearRadius or 25 - local CargoCarrierPointVec2 = CargoCarrier:GetPointVec2() local CargoCarrierHeading = CargoCarrier:GetHeading() -- Get Heading of object in degrees. local CargoDeployHeading = ( ( CargoCarrierHeading + Angle ) >= 360 ) and ( CargoCarrierHeading + Angle - 360 ) or ( CargoCarrierHeading + Angle ) @@ -349,8 +346,6 @@ do -- CARGO_UNIT local Angle = 180 local Distance = 5 - local NearRadius = NearRadius or 25 - if From == "UnLoaded" or From == "Boarding" then end diff --git a/Moose Development/Moose/Tasking/Task_CARGO.lua b/Moose Development/Moose/Tasking/Task_CARGO.lua index fd1d60ef7..ae4ebc7b8 100644 --- a/Moose Development/Moose/Tasking/Task_CARGO.lua +++ b/Moose Development/Moose/Tasking/Task_CARGO.lua @@ -589,6 +589,12 @@ do -- TASK_CARGO Fsm:AddTransition( "Rejected", "Reject", "Aborted" ) Fsm:AddTransition( "Failed", "Fail", "Failed" ) + for _, Group in pairs( SetGroup:GetSet() ) do + for __, Unit in pairs( Group:GetUnits() ) do + local Unit = Unit -- Wrapper.Unit#UNIT + Unit:SetCargoBayWeightLimit() + end + end ---- @param #FSM_PROCESS self -- @param Wrapper.Unit#UNIT TaskUnit @@ -610,7 +616,6 @@ do -- TASK_CARGO local TaskUnitName = TaskUnit:GetName() local MenuTime = Task:InitTaskControlMenu( TaskUnit ) local MenuControl = Task:GetTaskControlMenu( TaskUnit ) - local CargoItemCount = TaskUnit:CargoItemCount() Task.SetCargo:ForEachCargo( @@ -635,7 +640,13 @@ do -- TASK_CARGO local TaskGroup = TaskUnit:GetGroup() if Cargo:IsUnLoaded() then - if CargoItemCount < 1 then + local CargoBayFreeWeight = TaskUnit:GetCargoBayFreeWeight() + local CargoWeight = Cargo:GetWeight() + + self:F({CargoBayFreeWeight=CargoBayFreeWeight}) + + -- Only when there is space within the bay to load the next cargo item! + if CargoBayFreeWeight > CargoWeight then if Cargo:IsInReportRadius( TaskUnit:GetPointVec2() ) then local NotInDeployZones = true for DeployZoneName, DeployZone in pairs( Task.DeployZones ) do diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index 287338c2b..b0200fd24 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -243,7 +243,7 @@ end --- Get the bounding box of the underlying POSITIONABLE DCS Object. -- @param #POSITIONABLE self --- @return DCS#Distance The bounding box of the POSITIONABLE. +-- @return DCS#Box3 The bounding box of the POSITIONABLE. -- @return #nil The POSITIONABLE is not existing or alive. function POSITIONABLE:GetBoundingBox() --R2.1 self:F2() @@ -264,6 +264,29 @@ function POSITIONABLE:GetBoundingBox() --R2.1 end +--- Get the bounding radius of the underlying POSITIONABLE DCS Object. +-- @param #POSITIONABLE self +-- @return DCS#Distance The bounding radius of the POSITIONABLE. +-- @return #nil The POSITIONABLE is not existing or alive. +function POSITIONABLE:GetBoundingRadius() + self:F2() + + local Box = self:GetBoundingBox() + + + if Box then + local X = Box.max.x - Box.min.x + local Z = Box.max.z - Box.min.z + local CX = X / 2 + local CZ = Z / 2 + return math.max( CX, CZ ) + end + + BASE:E( { "Cannot GetBoundingRadius", Positionable = self, Alive = self:IsAlive() } ) + + return nil +end + --- Returns the altitude of the POSITIONABLE. -- @param Wrapper.Positionable#POSITIONABLE self -- @return DCS#Distance The altitude of the POSITIONABLE. @@ -323,7 +346,7 @@ end --- Returns the POSITIONABLE heading in degrees. -- @param Wrapper.Positionable#POSITIONABLE self --- @return #number The POSTIONABLE heading +-- @return #number The POSITIONABLE heading -- @return #nil The POSITIONABLE is not existing or alive. function POSITIONABLE:GetHeading() local DCSPositionable = self:GetDCSObject() @@ -347,6 +370,52 @@ function POSITIONABLE:GetHeading() return nil end +-- Is Methods + +--- Returns if the unit is of an air category. +-- If the unit is a helicopter or a plane, then this method will return true, otherwise false. +-- @param #POSITIONABLE self +-- @return #boolean Air category evaluation result. +function POSITIONABLE:IsAir() + self:F2() + + local DCSUnit = self:GetDCSObject() + + if DCSUnit then + local UnitDescriptor = DCSUnit:getDesc() + self:T3( { UnitDescriptor.category, Unit.Category.AIRPLANE, Unit.Category.HELICOPTER } ) + + local IsAirResult = ( UnitDescriptor.category == Unit.Category.AIRPLANE ) or ( UnitDescriptor.category == Unit.Category.HELICOPTER ) + + self:T3( IsAirResult ) + return IsAirResult + end + + return nil +end + +--- Returns if the unit is of an ground category. +-- If the unit is a ground vehicle or infantry, this method will return true, otherwise false. +-- @param #POSITIONABLE self +-- @return #boolean Ground category evaluation result. +function POSITIONABLE:IsGround() + self:F2() + + local DCSUnit = self:GetDCSObject() + + if DCSUnit then + local UnitDescriptor = DCSUnit:getDesc() + self:T3( { UnitDescriptor.category, Unit.Category.GROUND_UNIT } ) + + local IsGroundResult = ( UnitDescriptor.category == Unit.Category.GROUND_UNIT ) + + self:T3( IsGroundResult ) + return IsGroundResult + end + + return nil +end + --- Returns true if the POSITIONABLE is in the air. -- Polymorphic, is overridden in GROUP and UNIT. @@ -895,12 +964,50 @@ do -- Cargo -- @param #POSITIONABLE self -- @param #number WeightLimit function POSITIONABLE:SetCargoBayWeightLimit( WeightLimit ) - self.__.CargoBayWeightLimit = WeightLimit - end - - - + if WeightLimit then + self.__.CargoBayWeightLimit = WeightLimit + else + -- If weightlimit is not provided, we will calculate it depending on the type of unit. + + -- When an airplane or helicopter, we calculate the weightlimit based on the descriptor. + if self:IsAir() then + local Desc = self:GetDesc() + self:F({Desc=Desc}) + self.__.CargoBayWeightLimit = Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) + else + local Desc = self:GetDesc() + local Weights = { + ["M1126 Stryker ICV"] = 9, + ["M-113"] = 9, + ["AAV7"] = 25, + ["M2A1_halftrack"] = 9, + ["BMD-1"] = 9, + ["BMP-1"] = 8, + ["BMP-2"] = 7, + ["BMP-3"] = 8, + ["Boman"] = 25, + ["BTR-80"] = 9, + ["BTR_D"] = 12, + ["Cobra"] = 8, + ["LAV-25"] = 6, + ["M-2 Bradley"] = 6, + ["M1043 HMMWV Armament"] = 4, + ["M1045 HMMWV TOW"] = 4, + ["M1126 Stryker ICV"] = 9, + ["M1134 Stryker ATGM"] = 9, + ["Marder"] = 6, + ["MCV-80"] = 9, + ["MLRS FDDM"] = 4, + ["MTLB"] = 25, + ["TPZ"] = 10, + } + + local CargoBayWeightLimit = ( Weights[Desc.typeName] or 0 ) * 70 + self.__.CargoBayWeightLimit = CargoBayWeightLimit + end + end + end end --- Cargo --- Signal a flare at the position of the POSITIONABLE. diff --git a/Moose Development/Moose/Wrapper/Unit.lua b/Moose Development/Moose/Wrapper/Unit.lua index 753b842f4..059a0266c 100644 --- a/Moose Development/Moose/Wrapper/Unit.lua +++ b/Moose Development/Moose/Wrapper/Unit.lua @@ -854,51 +854,7 @@ end --- Is methods ---- Returns if the unit is of an air category. --- If the unit is a helicopter or a plane, then this method will return true, otherwise false. --- @param #UNIT self --- @return #boolean Air category evaluation result. -function UNIT:IsAir() - self:F2() - - local DCSUnit = self:GetDCSObject() - - if DCSUnit then - local UnitDescriptor = DCSUnit:getDesc() - self:T3( { UnitDescriptor.category, Unit.Category.AIRPLANE, Unit.Category.HELICOPTER } ) - - local IsAirResult = ( UnitDescriptor.category == Unit.Category.AIRPLANE ) or ( UnitDescriptor.category == Unit.Category.HELICOPTER ) - - self:T3( IsAirResult ) - return IsAirResult - end - - return nil -end - ---- Returns if the unit is of an ground category. --- If the unit is a ground vehicle or infantry, this method will return true, otherwise false. --- @param #UNIT self --- @return #boolean Ground category evaluation result. -function UNIT:IsGround() - self:F2() - - local DCSUnit = self:GetDCSObject() - - if DCSUnit then - local UnitDescriptor = DCSUnit:getDesc() - self:T3( { UnitDescriptor.category, Unit.Category.GROUND_UNIT } ) - - local IsGroundResult = ( UnitDescriptor.category == Unit.Category.GROUND_UNIT ) - - self:T3( IsGroundResult ) - return IsGroundResult - end - - return nil -end --- Returns if the unit is a friendly unit. -- @param #UNIT self