OSPTRANSPORT

This commit is contained in:
Frank 2023-02-09 01:06:36 +01:00
parent 2c24e56aa5
commit 709fccd96c
2 changed files with 56 additions and 14 deletions

View File

@ -7955,7 +7955,7 @@ function OPSGROUP:_CheckCargoTransport()
end end
-- Boarding finished ==> Transport cargo. -- Boarding finished ==> Transport cargo.
if gotcargo and self.cargoTransport:_CheckRequiredCargos(self.cargoTZC) and not boarding then if gotcargo and self.cargoTransport:_CheckRequiredCargos(self.cargoTZC, self) and not boarding then
self:T(self.lid.."Boarding finished ==> Loaded") self:T(self.lid.."Boarding finished ==> Loaded")
self:LoadingDone() self:LoadingDone()
else else
@ -9330,6 +9330,8 @@ function OPSGROUP:onafterUnloading(From, Event, To)
-- Set carrier status to UNLOADING. -- Set carrier status to UNLOADING.
self:_NewCarrierStatus(OPSGROUP.CarrierStatus.UNLOADING) self:_NewCarrierStatus(OPSGROUP.CarrierStatus.UNLOADING)
self:I(self.lid.."FF Unloading..")
-- Deploy zone. -- Deploy zone.
local zone=self.cargoTZC.DisembarkZone or self.cargoTZC.DeployZone --Core.Zone#ZONE local zone=self.cargoTZC.DisembarkZone or self.cargoTZC.DeployZone --Core.Zone#ZONE
@ -9341,7 +9343,6 @@ function OPSGROUP:onafterUnloading(From, Event, To)
if cargo.opsgroup:IsLoaded(self.groupname) and not cargo.opsgroup:IsDead() then if cargo.opsgroup:IsLoaded(self.groupname) and not cargo.opsgroup:IsDead() then
-- Disembark to carrier. -- Disembark to carrier.
local needscarrier=false --#boolean
local carrier=nil --Ops.OpsGroup#OPSGROUP.Element local carrier=nil --Ops.OpsGroup#OPSGROUP.Element
local carrierGroup=nil --Ops.OpsGroup#OPSGROUP local carrierGroup=nil --Ops.OpsGroup#OPSGROUP
@ -9354,17 +9355,21 @@ function OPSGROUP:onafterUnloading(From, Event, To)
carrier=carrierGroup:GetElementByName(shipname) carrier=carrierGroup:GetElementByName(shipname)
end end
if self.cargoTZC.DisembarkCarriers and #self.cargoTZC.DisembarkCarriers>0 then if self.cargoTZC.disembarkToCarriers then
needscarrier=true self:I(self.lid.."FF Unloading 100")
self:I(zone:GetName())
-- Try to find a carrier that can take the cargo.
carrier, carrierGroup=self.cargoTransport:FindTransferCarrierForCargo(cargo.opsgroup, zone, self.cargoTZC) carrier, carrierGroup=self.cargoTransport:FindTransferCarrierForCargo(cargo.opsgroup, zone, self.cargoTZC)
--TODO: max unloading time if transfer carrier does not arrive in the zone. --TODO: max unloading time if transfer carrier does not arrive in the zone.
end end
if needscarrier==false or (needscarrier and carrier and carrierGroup) then if (self.cargoTZC.disembarkToCarriers and carrier and carrierGroup) or (not self.cargoTZC.disembarkToCarriers) then
self:I(self.lid.."FF Unloading 200")
-- Cargo was delivered (somehow). -- Cargo was delivered (somehow).
cargo.delivered=true cargo.delivered=true
@ -9383,7 +9388,7 @@ function OPSGROUP:onafterUnloading(From, Event, To)
elseif zone and zone:IsInstanceOf("ZONE_AIRBASE") and zone:GetAirbase():IsShip() then elseif zone and zone:IsInstanceOf("ZONE_AIRBASE") and zone:GetAirbase():IsShip() then
--- ---
-- Delivered to a ship via helo or VTOL -- Delivered to a ship via helo that landed on its platform
--- ---
-- Issue warning. -- Issue warning.
@ -9398,6 +9403,8 @@ function OPSGROUP:onafterUnloading(From, Event, To)
-- Delivered to deploy zone -- Delivered to deploy zone
--- ---
self:I(self.lid.."FF Unloading 400")
if self.cargoTransport:GetDisembarkInUtero(self.cargoTZC) then if self.cargoTransport:GetDisembarkInUtero(self.cargoTZC) then
-- Unload but keep "in utero" (no coordinate provided). -- Unload but keep "in utero" (no coordinate provided).

View File

@ -172,6 +172,7 @@ OPSTRANSPORT.Status={
-- @field #table TransportPaths Path for Transport. Each elment of the table is of type `#OPSTRANSPORT.Path`. -- @field #table TransportPaths Path for Transport. Each elment of the table is of type `#OPSTRANSPORT.Path`.
-- @field #table RequiredCargos Required cargos. -- @field #table RequiredCargos Required cargos.
-- @field #table DisembarkCarriers Carriers where the cargo is directly disembarked to. -- @field #table DisembarkCarriers Carriers where the cargo is directly disembarked to.
-- @field #boolean disembarkToCarriers If `true`, cargo is supposed to embark to another carrier.
-- @field #boolean disembarkActivation If true, troops are spawned in late activated state when disembarked from carrier. -- @field #boolean disembarkActivation If true, troops are spawned in late activated state when disembarked from carrier.
-- @field #boolean disembarkInUtero If true, troops are disembarked "in utero". -- @field #boolean disembarkInUtero If true, troops are disembarked "in utero".
-- @field #boolean assets Cargo assets. -- @field #boolean assets Cargo assets.
@ -722,7 +723,7 @@ function OPSTRANSPORT:GetDisembarkActivation(TransportZoneCombo)
return TransportZoneCombo.disembarkActivation return TransportZoneCombo.disembarkActivation
end end
--- Set transfer carrier(s). These are carrier groups, where the cargo is directly loaded into when disembarked. --- Set/add transfer carrier(s). These are carrier groups, where the cargo is directly loaded into when disembarked.
-- @param #OPSTRANSPORT self -- @param #OPSTRANSPORT self
-- @param Core.Set#SET_GROUP Carriers Carrier set. Can also be passed as a #GROUP, #OPSGROUP or #SET_OPSGROUP object. -- @param Core.Set#SET_GROUP Carriers Carrier set. Can also be passed as a #GROUP, #OPSGROUP or #SET_OPSGROUP object.
-- @param #OPSTRANSPORT.TransportZoneCombo TransportZoneCombo Transport zone combo. -- @param #OPSTRANSPORT.TransportZoneCombo TransportZoneCombo Transport zone combo.
@ -735,6 +736,9 @@ function OPSTRANSPORT:SetDisembarkCarriers(Carriers, TransportZoneCombo)
-- Use default TZC if no transport zone combo is provided. -- Use default TZC if no transport zone combo is provided.
TransportZoneCombo=TransportZoneCombo or self.tzcDefault TransportZoneCombo=TransportZoneCombo or self.tzcDefault
-- Set that we want to disembark to carriers.
TransportZoneCombo.disembarkToCarriers=true
if Carriers:IsInstanceOf("GROUP") or Carriers:IsInstanceOf("OPSGROUP") then if Carriers:IsInstanceOf("GROUP") or Carriers:IsInstanceOf("OPSGROUP") then
local carrier=self:_GetOpsGroupFromObject(Carriers) local carrier=self:_GetOpsGroupFromObject(Carriers)
@ -1928,31 +1932,61 @@ end
--- Check if all required cargos are loaded. --- Check if all required cargos are loaded.
-- @param #OPSTRANSPORT self -- @param #OPSTRANSPORT self
-- @param #OPSTRANSPORT.TransportZoneCombo TransportZoneCombo Transport zone combo. -- @param #OPSTRANSPORT.TransportZoneCombo TransportZoneCombo Transport zone combo.
-- @return #boolean If true, all required cargos are loaded or there is no required cargo. -- @param Ops.OpsGroup#OPSGROUP CarrierGroup The carrier group asking.
function OPSTRANSPORT:_CheckRequiredCargos(TransportZoneCombo) -- @return #boolean If true, all required cargos are loaded or there is no required cargo or asking carrier is full.
function OPSTRANSPORT:_CheckRequiredCargos(TransportZoneCombo, CarrierGroup)
-- Use default TZC if no transport zone combo is provided. -- Use default TZC if no transport zone combo is provided.
TransportZoneCombo=TransportZoneCombo or self.tzcDefault TransportZoneCombo=TransportZoneCombo or self.tzcDefault
local requiredCargos=TransportZoneCombo.RequiredCargos -- Use input or take all cargos.
local requiredCargos=TransportZoneCombo.RequiredCargos or TransportZoneCombo.Cargos
if requiredCargos==nil or #requiredCargos==0 then if requiredCargos==nil or #requiredCargos==0 then
return true return true
end end
-- All carrier names.
local carrierNames=self:_GetCarrierNames() local carrierNames=self:_GetCarrierNames()
local gotit=true -- Cargo groups not loaded yet.
local weightmin=nil
for _,_cargo in pairs(requiredCargos) do for _,_cargo in pairs(requiredCargos) do
local cargo=_cargo --Ops.OpsGroup#OPSGROUP local cargo=_cargo --Ops.OpsGroup#OPSGROUP
-- Is this cargo loaded into any carrier?
local isLoaded=cargo:IsLoaded(carrierNames)
if not cargo:IsLoaded(carrierNames) then if not isLoaded then
return false local weight=cargo:GetWeightTotal()
if weightmin==nil or weight<weightmin then
weightmin=weight
end
end end
end end
if weightmin then
-- Free space of carrier.
local freeSpace=CarrierGroup:GetFreeCargobayMax(true)
-- Debug info.
self:T(self.lid..string.format("Check required cargos for carrier=%s free=%.1f, weight=%.1f", CarrierGroup:GetName(), freeSpace, weightmin))
if weightmin<freeSpace then
-- This group can still take cargo.
return false
else
-- This group is full! Even if there is cargo left, we cannot transport it.
return true
end
end
-- No cargo left.
return true return true
end end
@ -2021,6 +2055,7 @@ function OPSTRANSPORT:FindTransferCarrierForCargo(CargoGroup, Zone, TransportZon
end end
end end
self:T2(self.lid.."Could NOT find any carrier that is ALIVE and LOADING (or DELOYAIRBASE))!")
return nil, nil return nil, nil
end end