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:
parent
a02d3c1950
commit
7a2dee4162
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user