diff --git a/Moose Development/Moose/AI/AI_Escort.lua b/Moose Development/Moose/AI/AI_Escort.lua index 8d94b39ae..6a7517dd9 100644 --- a/Moose Development/Moose/AI/AI_Escort.lua +++ b/Moose Development/Moose/AI/AI_Escort.lua @@ -176,10 +176,6 @@ AI_ESCORT = { EscortUnit = nil, EscortGroup = nil, EscortMode = 1, - MODE = { - FOLLOW = 1, - MISSION = 2, - }, Targets = {}, -- The identified targets FollowScheduler = nil, ReportTargets = true, @@ -192,11 +188,6 @@ AI_ESCORT = { --- @field Functional.Detection#DETECTION_AREAS AI_ESCORT.Detection = nil ---- AI_ESCORT.Mode class --- @type AI_ESCORT.MODE --- @field #number FOLLOW --- @field #number MISSION - --- MENUPARAM type -- @type MENUPARAM -- @field #AI_ESCORT ParamSelf @@ -225,8 +216,6 @@ function AI_ESCORT:New( EscortUnit, EscortGroupSet, EscortName, EscortBriefing ) local self = BASE:Inherit( self, AI_FORMATION:New( EscortUnit, EscortGroupSet, EscortName, EscortBriefing ) ) -- #AI_ESCORT self:F( { EscortUnit, EscortGroupSet } ) - self.EscortUnit = self.FollowUnit -- Wrapper.Unit#UNIT - self.PlayerUnit = self.FollowUnit -- Wrapper.Unit#UNIT self.PlayerGroup = self.FollowUnit:GetGroup() -- Wrapper.Group#GROUP @@ -261,18 +250,16 @@ function AI_ESCORT:New( EscortUnit, EscortGroupSet, EscortName, EscortBriefing ) --- @param Core.Group#GROUP EscortGroup function( EscortGroup ) -- Set EscortGroup known at EscortUnit. - if not self.EscortUnit._EscortGroups then - self.EscortUnit._EscortGroups = {} + if not self.PlayerUnit._EscortGroups then + self.PlayerUnit._EscortGroups = {} end - if not self.EscortUnit._EscortGroups[EscortGroup:GetName()] then - self.EscortUnit._EscortGroups[EscortGroup:GetName()] = {} - self.EscortUnit._EscortGroups[EscortGroup:GetName()].EscortGroup = EscortGroup - self.EscortUnit._EscortGroups[EscortGroup:GetName()].EscortName = self.EscortName - self.EscortUnit._EscortGroups[EscortGroup:GetName()].Detection = self.Detection + if not self.PlayerUnit._EscortGroups[EscortGroup:GetName()] then + self.PlayerUnit._EscortGroups[EscortGroup:GetName()] = {} + self.PlayerUnit._EscortGroups[EscortGroup:GetName()].EscortGroup = EscortGroup + self.PlayerUnit._EscortGroups[EscortGroup:GetName()].EscortName = self.EscortName + self.PlayerUnit._EscortGroups[EscortGroup:GetName()].Detection = self.Detection end - - EscortGroup.EscortMode = AI_ESCORT.MODE.FOLLOW end ) @@ -297,11 +284,9 @@ function AI_ESCORT:onafterStart( EscortGroupSet ) local LeaderEscort = EscortGroupSet:GetFirst() -- Wrapper.Group#GROUP local Report = REPORT:New( "Escort reporting:" ) - Report:Add( "Current coordinate: " .. LeaderEscort:GetCoordinate():ToString( self.EscortUnit ) ) - Report:Add( "Configuration: " .. EscortGroupSet:GetUnitTypeNames():Text( ", " ) ) - Report:Add( "Joining Up ..." ) + Report:Add( "Joining Up " .. EscortGroupSet:GetUnitTypeNames():Text( ", " ) .. " from " .. LeaderEscort:GetCoordinate():ToString( self.PlayerUnit ) ) - LeaderEscort:MessageTypeToGroup( Report:Text(), MESSAGE.Type.Information, self.EscortUnit ) + LeaderEscort:MessageTypeToGroup( Report:Text(), MESSAGE.Type.Information, self.PlayerUnit ) self.Detection = DETECTION_AREAS:New( EscortGroupSet, 5000 ) @@ -317,7 +302,7 @@ function AI_ESCORT:SetDetection( Detection ) self.Detection = Detection self.EscortGroup.Detection = self.Detection - self.EscortUnit._EscortGroups[self.EscortGroup:GetName()].Detection = self.EscortGroup.Detection + self.PlayerUnit._EscortGroups[self.EscortGroup:GetName()].Detection = self.EscortGroup.Detection Detection:__Start( 1 ) @@ -935,7 +920,7 @@ function AI_ESCORT:MenuReportTargets( Seconds ) -- Attack Targets local EscortMenuAttackTargets = MENU_GROUP:New( self.PlayerGroup, "Attack targets", EscortMenu ) - --EscortGroup.ReportTargetsScheduler = SCHEDULER:New( self, self._ReportTargetsScheduler, { EscortGroup }, timer, Seconds ) + EscortGroup.ReportTargetsScheduler = SCHEDULER:New( self, self._ReportTargetsScheduler, { EscortGroup }, timer, Seconds ) timer=timer+1 end end @@ -1078,7 +1063,7 @@ end -- @param #number OrbitSeconds function AI_ESCORT:_HoldPosition( OrbitGroup, EscortGroup, OrbitHeight, OrbitSeconds ) - local EscortUnit = self.EscortUnit + local EscortUnit = self.PlayerUnit local OrbitUnit = OrbitGroup:GetUnit(1) -- Wrapper.Unit#UNIT @@ -1121,7 +1106,7 @@ end -- @param #number OrbitSeconds function AI_ESCORT:_FlightHoldPosition( OrbitGroup, OrbitHeight, OrbitSeconds ) - local EscortUnit = self.EscortUnit + local EscortUnit = self.PlayerUnit self.EscortGroupSet:ForSomeGroupAlive( --- @param Core.Group#GROUP EscortGroup @@ -1141,10 +1126,11 @@ end function AI_ESCORT:_JoinUp( EscortGroup ) - local EscortUnit = self.EscortUnit + local EscortUnit = self.PlayerUnit self:JoinFormation( EscortGroup ) - EscortGroup.EscortMode = AI_ESCORT.MODE.FOLLOW + + EscortGroup:SetState( self, "Mode", self.__Enum.Mode.Follow ) end @@ -1218,7 +1204,7 @@ end function AI_ESCORT:_Flare( EscortGroup, Color, Message ) - local EscortUnit = self.EscortUnit + local EscortUnit = self.PlayerUnit EscortGroup:GetUnit(1):Flare( Color ) EscortGroup:MessageTypeToGroup( Message, MESSAGE.Type.Information, EscortUnit:GetGroup() ) @@ -1242,7 +1228,7 @@ end function AI_ESCORT:_Smoke( EscortGroup, Color, Message ) - local EscortUnit = self.EscortUnit + local EscortUnit = self.PlayerUnit EscortGroup:GetUnit(1):Smoke( Color ) EscortGroup:MessageTypeToGroup( Message, MESSAGE.Type.Information, EscortUnit:GetGroup() ) @@ -1264,7 +1250,7 @@ end function AI_ESCORT:_ReportNearbyTargetsNow( EscortGroup ) - local EscortUnit = self.EscortUnit + local EscortUnit = self.PlayerUnit self:_ReportTargetsScheduler( EscortGroup ) @@ -1280,7 +1266,7 @@ end function AI_ESCORT:_SwitchReportNearbyTargets( EscortGroup, ReportTargets ) - local EscortUnit = self.EscortUnit + local EscortUnit = self.PlayerUnit self.ReportTargets = ReportTargets @@ -1312,7 +1298,7 @@ end function AI_ESCORT:_ScanTargets( ScanDuration ) local EscortGroup = self.EscortGroup -- Wrapper.Group#GROUP - local EscortUnit = self.EscortUnit + local EscortUnit = self.PlayerUnit self.FollowScheduler:Stop( self.FollowSchedule ) @@ -1344,10 +1330,8 @@ function AI_ESCORT.___Resume( EscortGroup, self ) local PlayerGroup = self.PlayerGroup - if EscortGroup.EscortMode == AI_ESCORT.MODE.FOLLOW then - self:JoinFormation( EscortGroup ) - EscortGroup:MessageTypeToClient( "Destroyed all targets. Rejoining.", MESSAGE.Type.Information, PlayerGroup ) - end + self:JoinFormation( EscortGroup ) + EscortGroup:MessageTypeToClient( "Destroyed all targets. Rejoining.", MESSAGE.Type.Information, PlayerGroup ) end @@ -1359,7 +1343,7 @@ function AI_ESCORT:_AttackTarget( EscortGroup, DetectedItem ) self:F( EscortGroup ) - local EscortUnit = self.EscortUnit + local EscortUnit = self.PlayerUnit self:ReleaseFormation( EscortGroup ) @@ -1383,7 +1367,7 @@ function AI_ESCORT:_AttackTarget( EscortGroup, DetectedItem ) ) Tasks[#Tasks+1] = EscortGroup:TaskCombo( AttackUnitTasks ) - Tasks[#Tasks+1] = EscortGroup:TaskFunction( "AI_ESCORT.___Resume", self, EscortGroup ) + Tasks[#Tasks+1] = EscortGroup:TaskFunction( "AI_ESCORT.___Resume", EscortGroup, self ) EscortGroup:SetTask( EscortGroup:TaskCombo( @@ -1439,7 +1423,7 @@ end -- @param Functional.Detection#DETECTION_BASE.DetectedItem DetectedItem function AI_ESCORT:_AssistTarget( EscortGroup, DetectedItem ) - local EscortUnit = self.EscortUnit + local EscortUnit = self.PlayerUnit local DetectedSet = self.Detection:GetDetectedItemSet( DetectedItem ) @@ -1500,7 +1484,7 @@ end function AI_ESCORT:_ResumeMission( WayPoint ) local EscortGroup = self.EscortGroup - local EscortUnit = self.EscortUnit + local EscortUnit = self.PlayerUnit self.FollowScheduler:Stop( self.FollowSchedule ) @@ -1540,7 +1524,7 @@ end function AI_ESCORT:_ReportTargetsScheduler( EscortGroup ) self:F( EscortGroup:GetName() ) - if EscortGroup:IsAlive() and self.EscortUnit:IsAlive() then + if EscortGroup:IsAlive() and self.PlayerUnit:IsAlive() then if true then @@ -1563,7 +1547,7 @@ function AI_ESCORT:_ReportTargetsScheduler( EscortGroup ) for DetectedItemIndex, DetectedItem in pairs( DetectedItems ) do - local DetectedItemReportSummary = self.Detection:DetectedItemReportMenu( DetectedItem, EscortGroup, _DATABASE:GetPlayerSettings( self.EscortUnit:GetPlayerName() ) ) + local DetectedItemReportSummary = self.Detection:DetectedItemReportMenu( DetectedItem, EscortGroup, _DATABASE:GetPlayerSettings( self.PlayerUnit:GetPlayerName() ) ) local DetectedMenu = DetectedItemReportSummary:Text("\n") @@ -1615,7 +1599,7 @@ function AI_ESCORT:_FlightReportTargetsScheduler() local DetectedTargetsReport = REPORT:New( "Reporting detected targets:\n" ) -- A new report to display the detected targets as a message to the player. - if EscortGroup and ( self.EscortUnit:IsAlive() and EscortGroup:IsAlive() ) then + if EscortGroup and ( self.PlayerUnit:IsAlive() and EscortGroup:IsAlive() ) then local ClientGroup = self.PlayerGroup @@ -1637,7 +1621,7 @@ function AI_ESCORT:_FlightReportTargetsScheduler() DetectedTargets = true -- There are detected targets, when the content of the for loop is executed. We use it to display a message. - local DetectedItemReportMenu = self.Detection:DetectedItemReportMenu( DetectedItem, ClientGroup, _DATABASE:GetPlayerSettings( self.EscortUnit:GetPlayerName() ) ) + local DetectedItemReportMenu = self.Detection:DetectedItemReportMenu( DetectedItem, ClientGroup, _DATABASE:GetPlayerSettings( self.PlayerUnit:GetPlayerName() ) ) local ReportMenuText = DetectedItemReportMenu:Text(", ") MENU_GROUP_COMMAND:New( self.PlayerGroup, @@ -1648,7 +1632,7 @@ function AI_ESCORT:_FlightReportTargetsScheduler() DetectedItem ):SetTag( "Flight" ):SetTime( TimeUpdate ) - local DetectedItemReportSummary = self.Detection:DetectedItemReportSummary( DetectedItem, ClientGroup, _DATABASE:GetPlayerSettings( self.EscortUnit:GetPlayerName() ) ) + local DetectedItemReportSummary = self.Detection:DetectedItemReportSummary( DetectedItem, ClientGroup, _DATABASE:GetPlayerSettings( self.PlayerUnit:GetPlayerName() ) ) local ReportSummary = DetectedItemReportSummary:Text(", ") DetectedTargetsReport:AddIndent( ReportSummary, "-" ) end diff --git a/Moose Development/Moose/AI/AI_Escort_Request.lua b/Moose Development/Moose/AI/AI_Escort_Request.lua index 372f09d22..8d17d2657 100644 --- a/Moose Development/Moose/AI/AI_Escort_Request.lua +++ b/Moose Development/Moose/AI/AI_Escort_Request.lua @@ -212,7 +212,7 @@ function AI_ESCORT_REQUEST:New( EscortUnit, EscortSpawn, EscortAirbase, EscortNa local self = BASE:Inherit( self, AI_ESCORT:New( EscortUnit, self.EscortGroupSet, EscortName, EscortBriefing ) ) -- #AI_ESCORT_REQUEST - self.LeaderGroup = self.EscortUnit:GetGroup() + self.LeaderGroup = self.PlayerUnit:GetGroup() self.Detection = DETECTION_AREAS:New( self.EscortGroupSet, 5000 ) self.Detection:__Start( 30 ) @@ -235,15 +235,14 @@ function AI_ESCORT_REQUEST:SpawnEscort() function() local LeaderEscort = self.EscortGroupSet:GetFirst() -- Wrapper.Group#GROUP - local Report = REPORT:New( "Escorts Reporting." ) - Report:Add( "Current coordinate: " .. LeaderEscort:GetCoordinate():ToString( self.EscortUnit ) ) - Report:Add( "Configuration: " .. self.EscortGroupSet:GetUnitTypeNames():Text( ", " ) ) - Report:Add( "Joining Up ..." ) - - LeaderEscort:MessageTypeToGroup( Report:Text(), MESSAGE.Type.Information, self.EscortUnit ) + local Report = REPORT:New() + + Report:Add( "Joining Up " .. self.EscortGroupSet:GetUnitTypeNames():Text( ", " ) .. " from " .. LeaderEscort:GetCoordinate():ToString( self.EscortUnit ) ) + + LeaderEscort:MessageTypeToGroup( Report:Text(), MESSAGE.Type.Information, self.PlayerUnit ) self:FormationTrail( 50, 50, 50 ) self:JoinFormation( EscortGroup ) - self:Menus() + self:Menus( self.XStart, self.XSpace, self.YStart, self.YSpace, self.ZStart, self.ZSpace, self.ZLevels ) end ) @@ -254,7 +253,7 @@ end function AI_ESCORT_REQUEST:onafterStart( EscortGroupSet ) if not self.MenuRequestEscort then - self.MenuRequestEscort = MENU_GROUP_COMMAND:New( self.LeaderGroup, "Request A2G Escort", self.FlightMenu, + self.MenuRequestEscort = MENU_GROUP_COMMAND:New( self.LeaderGroup, "Request A2G Escort", self.MainMenu, function() self:SpawnEscort() end diff --git a/Moose Development/Moose/AI/AI_Formation.lua b/Moose Development/Moose/AI/AI_Formation.lua index 5eae434e2..5eb5d0e90 100644 --- a/Moose Development/Moose/AI/AI_Formation.lua +++ b/Moose Development/Moose/AI/AI_Formation.lua @@ -110,10 +110,43 @@ AI_FORMATION = { dtFollow = 0.5, } ---- AI_FORMATION.Mode class --- @type AI_FORMATION.MODE --- @field #number FOLLOW --- @field #number MISSION +AI_FORMATION.__Enum = {} + +--- @type AI_FORMATION.__Enum.Formation +-- @field #number None +-- @field #number Line +-- @field #number Trail +-- @field #number Stack +-- @field #number LeftLine +-- @field #number RightLine +-- @field #number LeftWing +-- @field #number RightWing +-- @field #number Vic +-- @field #number Box +AI_FORMATION.__Enum.Formation = { + None = 0, + Mission = 1, + Line = 2, + Trail = 3, + Stack = 4, + LeftLine = 5, + RightLine = 6, + LeftWing = 7, + RightWing = 8, + Vic = 9, + Box = 10, +} + +--- @type AI_FORMATION.__Enum.Mode +-- @field #number Mission +-- @field #number Formation +AI_FORMATION.__Enum.Mode = { + Mission = 0, + Formation = 1, +} + + + --- MENUPARAM type -- @type MENUPARAM @@ -139,7 +172,7 @@ function AI_FORMATION:New( FollowUnit, FollowGroupSet, FollowName, FollowBriefin self.FollowGroupSet:ForEachGroup( function( FollowGroup ) self:E("Following") - FollowGroup.Following = true + FollowGroup:SetState( self, "Mode", self.__Enum.Mode.Formation ) end ) @@ -663,8 +696,8 @@ end -- @param #nubmer ZStart The start position on the Z-axis in meters for the first group. -- @param #number ZSpace The space between groups on the Z-axis in meters for each sequent group. -- @return #AI_FORMATION -function AI_FORMATION:onafterFormationLine( FollowGroupSet, From , Event , To, XStart, XSpace, YStart, YSpace, ZStart, ZSpace ) --R2.1 - self:F( { FollowGroupSet, From , Event ,To, XStart, XSpace, YStart, YSpace, ZStart, ZSpace } ) +function AI_FORMATION:onafterFormationLine( FollowGroupSet, From , Event , To, XStart, XSpace, YStart, YSpace, ZStart, ZSpace, Formation ) --R2.1 + self:F( { FollowGroupSet, From , Event ,To, XStart, XSpace, YStart, YSpace, ZStart, ZSpace, Formation } ) FollowGroupSet:Flush( self ) @@ -682,6 +715,9 @@ function AI_FORMATION:onafterFormationLine( FollowGroupSet, From , Event , To, X local Vec3 = PointVec3:GetVec3() FollowGroup:SetState( self, "FormationVec3", Vec3 ) i = i + 1 + + FollowGroup:SetState( FollowGroup, "Formation", Formation ) + FollowGroup:SetState( FollowGroup, "Mode", self.__Enum.Mode.Formation ) end return self @@ -700,7 +736,7 @@ end -- @return #AI_FORMATION function AI_FORMATION:onafterFormationTrail( FollowGroupSet, From , Event , To, XStart, XSpace, YStart ) --R2.1 - self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,0,0,0) + self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,0,0,0, self.__Enum.Formation.Trail ) return self end @@ -719,7 +755,7 @@ end -- @return #AI_FORMATION function AI_FORMATION:onafterFormationStack( FollowGroupSet, From , Event , To, XStart, XSpace, YStart, YSpace ) --R2.1 - self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,YSpace,0,0) + self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,YSpace,0,0, self.__Enum.Formation.Stack ) return self end @@ -740,7 +776,7 @@ end -- @return #AI_FORMATION function AI_FORMATION:onafterFormationLeftLine( FollowGroupSet, From , Event , To, XStart, YStart, ZStart, ZSpace ) --R2.1 - self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,0,YStart,0,-ZStart,-ZSpace) + self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,0,YStart,0,-ZStart,-ZSpace, self.__Enum.Formation.LeftLine ) return self end @@ -759,7 +795,7 @@ end -- @return #AI_FORMATION function AI_FORMATION:onafterFormationRightLine( FollowGroupSet, From , Event , To, XStart, YStart, ZStart, ZSpace ) --R2.1 - self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,0,YStart,0,ZStart,ZSpace) + self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,0,YStart,0,ZStart,ZSpace,self.__Enum.Formation.RightLine) return self end @@ -778,7 +814,7 @@ end -- @param #number ZSpace The space between groups on the Z-axis in meters for each sequent group. function AI_FORMATION:onafterFormationLeftWing( FollowGroupSet, From , Event , To, XStart, XSpace, YStart, ZStart, ZSpace ) --R2.1 - self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,0,-ZStart,-ZSpace) + self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,0,-ZStart,-ZSpace,self.__Enum.Formation.LeftWing) return self end @@ -798,7 +834,7 @@ end -- @param #number ZSpace The space between groups on the Z-axis in meters for each sequent group. function AI_FORMATION:onafterFormationRightWing( FollowGroupSet, From , Event , To, XStart, XSpace, YStart, ZStart, ZSpace ) --R2.1 - self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,0,ZStart,ZSpace) + self:onafterFormationLine(FollowGroupSet,From,Event,To,XStart,XSpace,YStart,0,ZStart,ZSpace,self.__Enum.Formation.RightWing) return self end @@ -836,6 +872,8 @@ function AI_FORMATION:onafterFormationCenterWing( FollowGroupSet, From , Event , local Vec3 = PointVec3:GetVec3() FollowGroup:SetState( self, "FormationVec3", Vec3 ) i = i + 1 + FollowGroup:SetState( FollowGroup, "Formation", self.__Enum.Formation.Vic ) + FollowGroup:SetState( FollowGroup, "Mode", self.__Enum.Mode.Formation ) end return self @@ -895,6 +933,8 @@ function AI_FORMATION:onafterFormationBox( FollowGroupSet, From , Event , To, XS local Vec3 = PointVec3:GetVec3() FollowGroup:SetState( self, "FormationVec3", Vec3 ) i = i + 1 + FollowGroup:SetState( FollowGroup, "Formation", self.__Enum.Formation.Box ) + FollowGroup:SetState( FollowGroup, "Mode", self.__Enum.Mode.Formation ) end return self @@ -919,7 +959,7 @@ end -- @return #AI_FORMATION function AI_FORMATION:ReleaseFormation( FollowGroup ) - FollowGroup.Following = false + FollowGroup:SetState( FollowGroup, "Mode", self.__Enum.Mode.Mission ) return self end @@ -931,7 +971,9 @@ end -- @return #AI_FORMATION function AI_FORMATION:JoinFormation( FollowGroup ) - FollowGroup.Following = true + -- If a formation type was defined for the AI_FORMATION object, then we can joinup. + + FollowGroup:SetState( FollowGroup, "Mode", self.__Enum.Mode.Formation ) return self end @@ -989,7 +1031,7 @@ function AI_FORMATION:onenterFollowing( FollowGroupSet ) --R2.1 -- @param Wrapper.Unit#UNIT ClientUnit function( FollowGroup, Formation, ClientUnit, CT1, CV1, CT2, CV2 ) - if FollowGroup.Following == true then + if FollowGroup:GetState( FollowGroup, "Mode" ) == self.__Enum.Mode.Formation then FollowGroup:OptionROTEvadeFire() FollowGroup:OptionROEReturnFire()