diff --git a/Moose Development/Moose/AI/AI_Cargo.lua b/Moose Development/Moose/AI/AI_Cargo.lua index d51149fbc..ed76eca7b 100644 --- a/Moose Development/Moose/AI/AI_Cargo.lua +++ b/Moose Development/Moose/AI/AI_Cargo.lua @@ -293,6 +293,80 @@ function AI_CARGO:onbeforeLoad( Carrier, From, Event, To, PickupZone ) end + +--- On before Reload event. +-- @param #AI_CARGO self +-- @param Wrapper.Group#GROUP Carrier +-- @param #string From From state. +-- @param #string Event Event. +-- @param #string To To state. +-- @param Core.Zone#ZONE PickupZone (optional) The zone where the cargo will be picked up. The PickupZone can be nil, if there wasn't any PickupZoneSet provided. +function AI_CARGO:onbeforeReload( Carrier, From, Event, To ) + self:F( { Carrier, From, Event, To } ) + + local Boarding = false + + local LoadInterval = 2 + local LoadDelay = 1 + local Carrier_List = {} + local Carrier_Weight = {} + + if Carrier and Carrier:IsAlive() then + for _, CarrierUnit in pairs( Carrier:GetUnits() ) do + local CarrierUnit = CarrierUnit -- Wrapper.Unit#UNIT + + Carrier_List[#Carrier_List+1] = CarrierUnit + end + + local Carrier_Count = #Carrier_List + local Carrier_Index = 1 + + local Loaded = false + + for Cargo, CarrierUnit in pairs( self.Carrier_Cargo ) do + local Cargo = Cargo -- Cargo.Cargo#CARGO + + self:F( { IsUnLoaded = Cargo:IsUnLoaded(), IsDeployed = Cargo:IsDeployed(), Cargo:GetName(), Carrier:GetName() } ) + + -- Try all Carriers, but start from the one according the Carrier_Index + for Carrier_Loop = 1, #Carrier_List do + + local CarrierUnit = Carrier_List[Carrier_Index] -- Wrapper.Unit#UNIT + + -- This counters loop through the available Carriers. + Carrier_Index = Carrier_Index + 1 + if Carrier_Index > Carrier_Count then + Carrier_Index = 1 + end + + if Cargo:IsUnLoaded() and not Cargo:IsDeployed() then + Carrier:RouteStop() + Cargo:__Board( -LoadDelay, CarrierUnit ) + self:__Board( LoadDelay, Cargo, CarrierUnit ) + + LoadDelay = LoadDelay + Cargo:GetCount() * LoadInterval + + -- So now this CarrierUnit has Cargo that is being loaded. + -- This will be used further in the logic to follow and to check cargo status. + self.Carrier_Cargo[Cargo] = CarrierUnit + Boarding = true + Loaded = true + end + + end + + end + + if not Loaded == true then + -- No loading happened, so we need to pickup something else. + self.Relocating = false + end + end + + return Boarding + +end + --- On after Board event. -- @param #AI_CARGO self -- @param Wrapper.Group#GROUP Carrier diff --git a/Moose Development/Moose/AI/AI_Cargo_APC.lua b/Moose Development/Moose/AI/AI_Cargo_APC.lua index 0f76bdda1..4929f2d46 100644 --- a/Moose Development/Moose/AI/AI_Cargo_APC.lua +++ b/Moose Development/Moose/AI/AI_Cargo_APC.lua @@ -97,6 +97,7 @@ function AI_CARGO_APC:New( APC, CargoSet, CombatRadius ) self:AddTransition( "*", "Follow", "Following" ) self:AddTransition( "*", "Guard", "Unloaded" ) self:AddTransition( "*", "Home", "*" ) + self:AddTransition( "*", "Reload", "Boarding" ) self:AddTransition( "*", "Destroyed", "Destroyed" ) @@ -280,8 +281,8 @@ function AI_CARGO_APC:onafterMonitor( APC, From, Event, To ) self.Zone:Scan( { Object.Category.UNIT } ) if self.Zone:IsAllInZoneOfCoalition( self.Coalition ) then if self:Is( "Unloaded" ) then - -- There are no enemies within combat radius. Load the CargoCarrier. - self:Load() + -- There are no enemies within combat radius. Reload the CargoCarrier. + self:Reload() end else if self:Is( "Loaded" ) then diff --git a/Moose Development/Moose/Cargo/CargoGroup.lua b/Moose Development/Moose/Cargo/CargoGroup.lua index 7e4a524d7..b64d205c2 100644 --- a/Moose Development/Moose/Cargo/CargoGroup.lua +++ b/Moose Development/Moose/Cargo/CargoGroup.lua @@ -307,6 +307,8 @@ do -- CARGO_GROUP self.CargoSet:ForEach( function( Cargo, ... ) self:F( { "Board Unit", Cargo:GetName( ), Cargo:IsDestroyed(), Cargo.CargoObject:IsAlive() } ) + local CargoGroup = Cargo.CargoObject --Wrapper.Group#GROUP + CargoGroup:OptionAlarmStateGreen() Cargo:__Board( 1, CargoCarrier, NearRadius, ... ) end, ... )