From 115743263b872f8692fa9a1971a501210f66e076 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Thu, 1 Aug 2019 21:16:01 +0300 Subject: [PATCH] Fixed nasty bug where the same plane would be chosen all the time for request spawns. Root cause was the inherit. self variables were also copied during inherit of the chile object, resulting in a bad bad bad behaviour. --- Moose Development/Moose/AI/AI_Escort.lua | 1 + .../Moose/AI/AI_Escort_Dispatcher_Request.lua | 27 ++++++++++++++++- .../Moose/AI/AI_Escort_Request.lua | 29 +++++++++++++++++-- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Escort.lua b/Moose Development/Moose/AI/AI_Escort.lua index d64732c8e..dc9e699b4 100644 --- a/Moose Development/Moose/AI/AI_Escort.lua +++ b/Moose Development/Moose/AI/AI_Escort.lua @@ -391,6 +391,7 @@ function AI_ESCORT:onafterStop( EscortGroupSet ) self.MainMenu:Remove() end + --- Set a Detection method for the EscortUnit to be reported upon. -- Detection methods are based on the derived classes from DETECTION_BASE. -- @param #AI_ESCORT self diff --git a/Moose Development/Moose/AI/AI_Escort_Dispatcher_Request.lua b/Moose Development/Moose/AI/AI_Escort_Dispatcher_Request.lua index 546f2baf9..0bf3d1a6b 100644 --- a/Moose Development/Moose/AI/AI_Escort_Dispatcher_Request.lua +++ b/Moose Development/Moose/AI/AI_Escort_Dispatcher_Request.lua @@ -69,10 +69,35 @@ function AI_ESCORT_DISPATCHER_REQUEST:onafterStart( From, Event, To ) self:HandleEvent( EVENTS.Birth ) - self:HandleEvent( EVENTS.PlayerLeaveUnit ) + self:HandleEvent( EVENTS.PlayerLeaveUnit, self.OnEventExit ) + self:HandleEvent( EVENTS.Crash, self.OnEventExit ) + self:HandleEvent( EVENTS.Dead, self.OnEventExit ) end +--- @param #AI_ESCORT_DISPATCHER_REQUEST self +-- @param Core.Event#EVENTDATA EventData +function AI_ESCORT_DISPATCHER_REQUEST:OnEventExit( EventData ) + + local PlayerGroupName = EventData.IniGroupName + local PlayerGroup = EventData.IniGroup + local PlayerUnit = EventData.IniUnit + + self.CarrierSet:Flush(self) + self:I({EscortAirbase= self.EscortAirbase } ) + self:I({PlayerGroupName = PlayerGroupName } ) + self:I({PlayerGroup = PlayerGroup}) + self:I({FirstGroup = self.CarrierSet:GetFirst()}) + self:I({FindGroup = self.CarrierSet:FindGroup( PlayerGroupName )}) + + if self.CarrierSet:FindGroup( PlayerGroupName ) then + if self.AI_Escorts[PlayerGroupName] then + self.AI_Escorts[PlayerGroupName]:Stop() + self.AI_Escorts[PlayerGroupName] = nil + end + end + +end --- @param #AI_ESCORT_DISPATCHER_REQUEST self -- @param Core.Event#EVENTDATA EventData diff --git a/Moose Development/Moose/AI/AI_Escort_Request.lua b/Moose Development/Moose/AI/AI_Escort_Request.lua index 5eb274278..0994a143c 100644 --- a/Moose Development/Moose/AI/AI_Escort_Request.lua +++ b/Moose Development/Moose/AI/AI_Escort_Request.lua @@ -206,12 +206,13 @@ AI_ESCORT_REQUEST = { -- Escort:__Start( 5 ) function AI_ESCORT_REQUEST:New( EscortUnit, EscortSpawn, EscortAirbase, EscortName, EscortBriefing ) - self.EscortGroupSet = SET_GROUP:New():FilterDeads():FilterCrashes() + local EscortGroupSet = SET_GROUP:New():FilterDeads():FilterCrashes() + local self = BASE:Inherit( self, AI_ESCORT:New( EscortUnit, EscortGroupSet, EscortName, EscortBriefing ) ) -- #AI_ESCORT_REQUEST + + self.EscortGroupSet = EscortGroupSet self.EscortSpawn = EscortSpawn self.EscortAirbase = EscortAirbase - local self = BASE:Inherit( self, AI_ESCORT:New( EscortUnit, self.EscortGroupSet, EscortName, EscortBriefing ) ) -- #AI_ESCORT_REQUEST - self.LeaderGroup = self.PlayerUnit:GetGroup() self.Detection = DETECTION_AREAS:New( self.EscortGroupSet, 5000 ) @@ -284,6 +285,28 @@ function AI_ESCORT_REQUEST:onafterStart( EscortGroupSet ) end +--- @param #AI_ESCORT_REQUEST self +-- @param Core.Set#SET_GROUP EscortGroupSet +function AI_ESCORT_REQUEST:onafterStop( EscortGroupSet ) + + self:F() + + EscortGroupSet:ForEachGroup( + --- @param Core.Group#GROUP EscortGroup + function( EscortGroup ) + EscortGroup:WayPointInitialize() + + EscortGroup:OptionROTVertical() + EscortGroup:OptionROEOpenFire() + end + ) + + self.Detection:Stop() + + self.MainMenu:Remove() + +end + --- Set the spawn mode to be mission execution. -- @param #AI_ESCORT_REQUEST self function AI_ESCORT_REQUEST:SetEscortSpawnMission()