diff --git a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua index 08cda3bbe..63d466b10 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Airplane.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Airplane.lua @@ -235,11 +235,12 @@ function AI_CARGO_AIRPLANE:onafterLanded( Airplane, From, Event, To ) self:F({IsAlive=Airplane:IsAlive()}) self:F({RoutePickup=self.RoutePickup}) - if Airplane and Airplane:IsAlive() then + if Airplane and Airplane:IsAlive()~=nil then -- Aircraft was sent to this airbase to pickup troops. Initiate loadling. if self.RoutePickup == true then - self:Load( Airplane:GetPointVec2() ) + env.info("FF load airplane "..Airplane:GetName()) + self:Load( Airplane:GetCoordinate() ) self.RoutePickup = false end @@ -264,10 +265,13 @@ end -- @param #number Speed in km/h for travelling to pickup base. function AI_CARGO_AIRPLANE:onafterPickup( Airplane, From, Event, To, Airbase, Speed ) - if Airplane and Airplane:IsAlive() then + if Airplane and Airplane:IsAlive()~=nil then + env.info("FF onafterpick aircraft alive") -- Get closest airbase of current position. local ClosestAirbase, DistToAirbase=Airplane:GetCoordinate():GetClosestAirbase() + + env.info("FF onafterpickup closest airbase "..ClosestAirbase:GetName()) -- Two cases. Aircraft spawned in air or at an airbase. if Airplane:InAir() then @@ -276,7 +280,13 @@ function AI_CARGO_AIRPLANE:onafterPickup( Airplane, From, Event, To, Airbase, Sp self.Airbase=ClosestAirbase end - if Airplane:InAir() or Airbase:GetCoordinate():Get2DDistance(ClosestAirbase:GetCoordinate())>100 then + -- Distance from closest to pickup airbase ==> we need to know if we are already at the pickup airbase. + local Dist=Airbase:GetCoordinate():Get2DDistance(ClosestAirbase:GetCoordinate()) + env.info("Distance closest to pickup airbase = "..Dist) + + if Airplane:InAir() or Dist>500 then + + env.info("FF onafterpickup routing to airbase "..ClosestAirbase:GetName()) -- Route aircraft to pickup airbase. self:Route( Airplane, Airbase, Speed ) @@ -291,11 +301,15 @@ function AI_CARGO_AIRPLANE:onafterPickup( Airplane, From, Event, To, Airbase, Sp self.Transporting = true self.Relocating = false else + env.info("FF onafterpick calling landed") -- We are already at the right airbase ==> Landed ==> triggers loading of troops. Is usually called at engine shutdown event. + self.RoutePickup=true self:Landed() end + else + env.info("FF onafterpick aircraft not alive") end end @@ -345,8 +359,9 @@ function AI_CARGO_AIRPLANE:onafterLoad( Airplane, From, Event, To, Coordinate ) if Airplane and Airplane:IsAlive()~=nil then - for _, Cargo in pairs( self.CargoSet:GetSet() ) do - self:F({Cargo:GetName()}) + 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 ) diff --git a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua index 6b3732121..7ac009283 100644 --- a/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_Cargo_Dispatcher.lua @@ -216,6 +216,31 @@ function AI_CARGO_DISPATCHER:SetHomeZone( HomeZone ) return self end +--- Set the home airbase. This is for air units, i.e. helicopters and airplanes. +-- When there is nothing anymore to pickup, the carriers will go back to their home base. They will await here new orders. +-- @param #AI_CARGO_DISPATCHER self +-- @param Wrapper.Airbase#AIRBASE HomeBase Airbase where the carriers will go after all pickup assignments are done. +-- @return #AI_CARGO_DISPATCHER self +function AI_CARGO_DISPATCHER:SetHomeBase( HomeBase ) + + self.HomeBase = HomeBase + + return self +end + + +--- Set the home base. +-- When there is nothing anymore to pickup, the carriers will return to their home airbase. There they will await new orders. +-- @param #AI_CARGO_DISPATCHER self +-- @param Wrapper.Airbase#AIRBASE HomeBase The airbase where the carrier will go to, once they completed all pending assignments. +-- @return #AI_CARGO_DISPATCHER self +function AI_CARGO_DISPATCHER:SetHomeBase( HomeBase ) + + self.HomeBase = HomeBase + + return self +end + --- Sets or randomizes the pickup location for the carrier around the cargo coordinate in a radius defined an outer and optional inner radius. -- This radius is influencing the location where the carrier will land to pickup the cargo. @@ -408,6 +433,7 @@ function AI_CARGO_DISPATCHER:onafterMonitor() end end end + if PickupCargo then self.CarrierHome[Carrier] = nil local PickupCoordinate = PickupCargo:GetCoordinate():GetRandomCoordinateInRadius( self.PickupOuterRadius, self.PickupInnerRadius ) diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 4385cfaa3..7c801f4fb 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -535,6 +535,9 @@ function WAREHOUSE:onafterRequest(From, Event, To, Airbase, AssetDescriptor, Ass local DeployZoneSet = SET_ZONE:New():AddZonesByName(Airbase:GetZone():GetName()) local CargoTransport --AI.AI_Cargo_Dispatcher#AI_CARGO_DISPATCHER + + -- Filter the requested transport assets. + local _assetstock=self:_FilterStock(self.stock, WAREHOUSE.Descriptor.ATTRIBUTE, TransportType) -- Dependent on transport type, spawn the transports and set up the dispatchers. if TransportType==WAREHOUSE.TransportType.AIRPLANE then