mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
OK. Revised cargo for AI is working.
This commit is contained in:
@@ -198,14 +198,41 @@ function AI_CARGO_APC:New( APC, CargoSet, CombatRadius )
|
|||||||
|
|
||||||
for _, APCUnit in pairs( APC:GetUnits() ) do
|
for _, APCUnit in pairs( APC:GetUnits() ) do
|
||||||
local Desc = APCUnit:GetDesc()
|
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 )
|
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 )
|
APCUnit:SetCargoBayWeightLimit( CargoBayWeightLimit )
|
||||||
self:F({CargoBayWeightLimit=CargoBayWeightLimit})
|
|
||||||
--Airplane:SetCargoBayVolumeLimit( 15 )
|
--Airplane:SetCargoBayVolumeLimit( 15 )
|
||||||
|
|
||||||
|
self:F( {TypeName = Desc.typeName, Desc = Desc, WeightLimit = CargoBayWeightLimit } )
|
||||||
end
|
end
|
||||||
|
|
||||||
self.Transporting = false
|
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:IsUnLoaded() and not Cargo:IsDeployed() then
|
||||||
if Cargo:IsInLoadRadius( APCUnit:GetCoordinate() ) then
|
if Cargo:IsInLoadRadius( APCUnit:GetCoordinate() ) then
|
||||||
self:F( { "In radius", APCUnit:GetName() } )
|
self:F( { "In radius", APCUnit:GetName() } )
|
||||||
APC:RouteStop()
|
|
||||||
--Cargo:Ungroup()
|
local CargoBayFreeWeight = APCUnit:GetCargoBayFreeWeight()
|
||||||
Cargo:Board( APCUnit, 25 )
|
local CargoWeight = Cargo:GetWeight()
|
||||||
self:__Board( 1, Cargo )
|
|
||||||
|
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
||||||
|
|
||||||
-- So now this APCUnit has Cargo that is being loaded.
|
-- Only when there is space within the bay to load the next cargo item!
|
||||||
-- This will be used further in the logic to follow and to check cargo status.
|
if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then
|
||||||
self.APC_Cargo[APCUnit] = Cargo
|
APC:RouteStop()
|
||||||
Boarding = true
|
--Cargo:Ungroup()
|
||||||
break
|
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
|
end
|
||||||
end
|
end
|
||||||
@@ -548,10 +584,12 @@ function AI_CARGO_APC:onafterUnload( APC, From, Event, To, Deployed )
|
|||||||
local APCUnit = APCUnit -- Wrapper.Unit#UNIT
|
local APCUnit = APCUnit -- Wrapper.Unit#UNIT
|
||||||
APC:RouteStop()
|
APC:RouteStop()
|
||||||
for _, Cargo in pairs( APCUnit:GetCargo() ) do
|
for _, Cargo in pairs( APCUnit:GetCargo() ) do
|
||||||
Cargo:UnBoard()
|
if Cargo:IsLoaded() then
|
||||||
Cargo:SetDeployed( true )
|
Cargo:UnBoard()
|
||||||
self:__Unboard( 10, Cargo, Deployed )
|
Cargo:SetDeployed( true )
|
||||||
end
|
self:__Unboard( 10, Cargo, Deployed )
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -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 } )
|
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
|
if Cargo:IsUnLoaded() == true and Cargo:IsDeployed() == false then
|
||||||
local CargoCoordinate = Cargo:GetCoordinate()
|
local CargoCoordinate = Cargo:GetCoordinate()
|
||||||
self:F({CargoCoordinate = CargoCoordinate })
|
|
||||||
local CoordinateFree = true
|
local CoordinateFree = true
|
||||||
for CarrierPickup, Coordinate in pairs( self.PickupCargo ) do
|
for CarrierPickup, Coordinate in pairs( self.PickupCargo ) do
|
||||||
if CarrierPickup:IsAlive() == true then
|
if CarrierPickup:IsAlive() == true then
|
||||||
@@ -428,7 +427,6 @@ function AI_CARGO_DISPATCHER:onafterMonitor()
|
|||||||
self.PickupCargo[CarrierPickup] = nil
|
self.PickupCargo[CarrierPickup] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self:F({CoordinateFree = CoordinateFree})
|
|
||||||
if CoordinateFree == true then
|
if CoordinateFree == true then
|
||||||
self.PickupCargo[Carrier] = CargoCoordinate
|
self.PickupCargo[Carrier] = CargoCoordinate
|
||||||
PickupCargo = Cargo
|
PickupCargo = Cargo
|
||||||
@@ -437,8 +435,6 @@ function AI_CARGO_DISPATCHER:onafterMonitor()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self:F( { PickupCargo = PickupCargo} )
|
|
||||||
|
|
||||||
if PickupCargo then
|
if PickupCargo then
|
||||||
self.CarrierHome[Carrier] = nil
|
self.CarrierHome[Carrier] = nil
|
||||||
local PickupCoordinate = PickupCargo:GetCoordinate():GetRandomCoordinateInRadius( self.PickupOuterRadius, self.PickupInnerRadius )
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
self:F({Carrier=Carrier})
|
|
||||||
self.PickupCargo[Carrier] = nil
|
self.PickupCargo[Carrier] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,8 @@
|
|||||||
-- @field #AI_CARGO_HELICOPTER
|
-- @field #AI_CARGO_HELICOPTER
|
||||||
AI_CARGO_HELICOPTER = {
|
AI_CARGO_HELICOPTER = {
|
||||||
ClassName = "AI_CARGO_HELICOPTER",
|
ClassName = "AI_CARGO_HELICOPTER",
|
||||||
Coordinate = nil -- Core.Point#COORDINATE,
|
Coordinate = nil, -- Core.Point#COORDINATE,
|
||||||
|
Helicopter_Cargo = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
AI_CARGO_QUEUE = {}
|
AI_CARGO_QUEUE = {}
|
||||||
@@ -148,7 +149,6 @@ function AI_CARGO_HELICOPTER:New( Helicopter, CargoSet )
|
|||||||
local Desc = HelicopterUnit:GetDesc()
|
local Desc = HelicopterUnit:GetDesc()
|
||||||
self:F({Desc=Desc})
|
self:F({Desc=Desc})
|
||||||
HelicopterUnit:SetCargoBayWeightLimit( Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) )
|
HelicopterUnit:SetCargoBayWeightLimit( Desc.massMax - ( Desc.massEmpty + Desc.fuelMassMax ) )
|
||||||
--Airplane:SetCargoBayVolumeLimit( 15 )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.Relocating = false
|
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:IsUnLoaded() and not Cargo:IsDeployed() then
|
||||||
if Cargo:IsInLoadRadius( HelicopterUnit:GetCoordinate() ) then
|
if Cargo:IsInLoadRadius( HelicopterUnit:GetCoordinate() ) then
|
||||||
self:F( { "In radius", HelicopterUnit:GetName() } )
|
self:F( { "In radius", HelicopterUnit:GetName() } )
|
||||||
--Cargo:Ungroup()
|
|
||||||
Cargo:Board( HelicopterUnit, 25 )
|
local CargoBayFreeWeight = HelicopterUnit:GetCargoBayFreeWeight()
|
||||||
self:__Board( 1, Cargo )
|
local CargoWeight = Cargo:GetWeight()
|
||||||
Boarding = true
|
|
||||||
break
|
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
|
end
|
||||||
end
|
end
|
||||||
@@ -438,10 +449,13 @@ function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To, Cargo )
|
|||||||
local CargoBayFreeWeight = HelicopterUnit:GetCargoBayFreeWeight()
|
local CargoBayFreeWeight = HelicopterUnit:GetCargoBayFreeWeight()
|
||||||
local CargoWeight = Cargo:GetWeight()
|
local CargoWeight = Cargo:GetWeight()
|
||||||
|
|
||||||
|
self:F({CargoBayFreeWeight=CargoBayFreeWeight})
|
||||||
|
|
||||||
-- Only when there is space within the bay to load the next cargo item!
|
-- Only when there is space within the bay to load the next cargo item!
|
||||||
if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then
|
if CargoBayFreeWeight > CargoWeight then --and CargoBayFreeVolume > CargoVolume then
|
||||||
Cargo:Board( HelicopterUnit, 25 )
|
Cargo:Board( HelicopterUnit, 25 )
|
||||||
self:__Board( 10, Cargo )
|
self:__Board( 10, Cargo )
|
||||||
|
self.Helicopter_Cargo[HelicopterUnit] = Cargo
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -454,6 +468,36 @@ function AI_CARGO_HELICOPTER:onafterBoard( Helicopter, From, Event, To, Cargo )
|
|||||||
|
|
||||||
end
|
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.
|
--- On after Loaded event. Check if cargo is loaded.
|
||||||
-- @param #AI_CARGO_HELICOPTER self
|
-- @param #AI_CARGO_HELICOPTER self
|
||||||
-- @param Wrapper.Group#GROUP Helicopter
|
-- @param Wrapper.Group#GROUP Helicopter
|
||||||
|
|||||||
Reference in New Issue
Block a user