From 65c28d66280aa81dfe6306c81853f45807a98418 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Thu, 18 Oct 2018 18:24:25 +0200 Subject: [PATCH] Optimized the boarding and unboarding of cargo. fixed bug when in defence of APC, cargo would not be loaded. The boarding and unboarding has become much more stable now. --- Moose Development/Moose/AI/AI_Cargo_APC.lua | 63 +++++++++++++-------- Moose Development/Moose/Cargo/CargoUnit.lua | 20 ------- 2 files changed, 39 insertions(+), 44 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Cargo_APC.lua b/Moose Development/Moose/AI/AI_Cargo_APC.lua index 21fa5d3ba..0f76bdda1 100644 --- a/Moose Development/Moose/AI/AI_Cargo_APC.lua +++ b/Moose Development/Moose/AI/AI_Cargo_APC.lua @@ -444,6 +444,45 @@ function AI_CARGO_APC:onafterDeploy( APC, From, Event, To, Coordinate, Speed, He end +--- On after Unloaded event. +-- @param #AI_CARGO_APC self +-- @param Wrapper.Group#GROUP Carrier +-- @param #string From From state. +-- @param #string Event Event. +-- @param #string To To state. +-- @param #string Cargo.Cargo#CARGO Cargo Cargo object. +-- @param #boolean Deployed Cargo is deployed. +-- @param Core.Zone#ZONE DeployZone The zone wherein the cargo is deployed. This can be any zone type, like a ZONE, ZONE_GROUP, ZONE_AIRBASE. +function AI_CARGO_APC:onafterUnloaded( Carrier, From, Event, To, Cargo, CarrierUnit, DeployZone, Defend ) + self:F( { Carrier, From, Event, To, DeployZone = DeployZone, Defend = Defend } ) + + + self:GetParent( self, AI_CARGO_APC ).onafterUnloaded( self, Carrier, From, Event, To, Cargo, CarrierUnit, DeployZone, Defend ) + + -- If Defend == true then we need to scan for possible enemies within combat zone and engage only ground forces. + if Defend == true then + self.Zone:Scan( { Object.Category.UNIT } ) + if not self.Zone:IsAllInZoneOfCoalition( self.Coalition ) then + -- OK, enemies nearby, now find the enemies and attack them. + local AttackUnits = self.Zone:GetScannedUnits() -- #list + local Move = {} + local CargoGroup = Cargo.CargoObject -- Wrapper.Group#GROUP + Move[#Move+1] = CargoGroup:GetCoordinate():WaypointGround( 70, "Custom" ) + for UnitId, AttackUnit in pairs( AttackUnits ) do + local MooseUnit = UNIT:Find( AttackUnit ) + if MooseUnit:GetCoalition() ~= CargoGroup:GetCoalition() then + Move[#Move+1] = MooseUnit:GetCoordinate():WaypointGround( 70, "Line abreast" ) + --MoveTo.Task = CargoGroup:TaskCombo( CargoGroup:TaskAttackUnit( MooseUnit, true ) ) + self:F( { MooseUnit = MooseUnit:GetName(), CargoGroup = CargoGroup:GetName() } ) + end + end + CargoGroup:RoutePush( Move, 0.1 ) + end + + end + +end + --- On after Deployed event. -- @param #AI_CARGO_APC self -- @param Wrapper.Group#GROUP Carrier @@ -457,30 +496,6 @@ function AI_CARGO_APC:onafterDeployed( APC, From, Event, To, DeployZone, Defend self:__Guard( 0.1 ) self:GetParent( self, AI_CARGO_APC ).onafterDeployed( self, APC, From, Event, To, DeployZone, Defend ) - - -- If Defend == true then we need to scan for possible enemies within combat zone and engage only ground forces. - if Defend == true then - self.Zone:Scan( { Object.Category.UNIT } ) - if not self.Zone:IsAllInZoneOfCoalition( self.Coalition ) then - -- OK, enemies nearby, now find the enemies and attack them. - local AttackUnits = self.Zone:GetScannedUnits() -- #list - local Move = {} - for CargoId, CargoData in pairs( self.CargoSet:GetSet() ) do - local CargoGroup = CargoData.CargoObject -- Wrapper.Group#GROUP - Move[#Move+1] = CargoGroup:GetCoordinate():WaypointGround( 70, "Custom" ) - for UnitId, AttackUnit in pairs( AttackUnits ) do - local MooseUnit = UNIT:Find( AttackUnit ) - if MooseUnit:GetCoalition() ~= CargoGroup:GetCoalition() then - Move[#Move+1] = MooseUnit:GetCoordinate():WaypointGround( 70, "Line abreast" ) - --MoveTo.Task = CargoGroup:TaskCombo( CargoGroup:TaskAttackUnit( MooseUnit, true ) ) - self:F( { MooseUnit = MooseUnit:GetName(), CargoGroup = CargoGroup:GetName() } ) - end - end - CargoGroup:RoutePush( Move, 0.1 ) - end - end - - end end diff --git a/Moose Development/Moose/Cargo/CargoUnit.lua b/Moose Development/Moose/Cargo/CargoUnit.lua index a3714c443..61319476d 100644 --- a/Moose Development/Moose/Cargo/CargoUnit.lua +++ b/Moose Development/Moose/Cargo/CargoUnit.lua @@ -341,26 +341,6 @@ do -- CARGO_UNIT end - --- Enter Boarding State. - -- @param #CARGO_UNIT self - -- @param #string Event - -- @param #string From - -- @param #string To - -- @param Wrapper.Unit#UNIT CargoCarrier - -- @param #number NearRadius Default 25 m. - function CARGO_UNIT:onenterBoarding( From, Event, To, CargoCarrier, NearRadius, ... ) - --self:F( { From, Event, To, CargoCarrier.UnitName, NearRadius } ) - - local Speed = 90 - local Angle = 180 - local Distance = 5 - - if From == "UnLoaded" or From == "Boarding" then - - end - - end - --- Loaded State. -- @param #CARGO_UNIT self -- @param #string Event