WIP, need to make a new class next week, AI_ESCORT_REQUEST. Need to solve the issue with the formation flying uof multiple escort classes working together. Planes may not crash into each other.

This commit is contained in:
FlightControl
2019-04-25 08:59:07 +03:00
parent 315d6bf82a
commit b4d6f78e42
5 changed files with 78 additions and 249 deletions

View File

@@ -250,7 +250,7 @@ function AI_ESCORT:New( EscortUnit, EscortGroupSet, EscortName, EscortBriefing )
self.GT1 = 0
self.FlightMenu = MENU_GROUP:New( self.EscortUnit:GetGroup(), "Flight" )
self.FlightMenu = MENU_GROUP:New( self.EscortUnit:GetGroup(), EscortName )
EscortGroupSet:ForEachGroup(
--- @param Core.Group#GROUP EscortGroup
@@ -271,17 +271,6 @@ function AI_ESCORT:New( EscortUnit, EscortGroupSet, EscortName, EscortBriefing )
end
)
EscortGroupSet:ForSomeGroup(
--- @param Core.Group#GROUP EscortGroup
function( EscortGroup )
EscortGroup.EscortMenu = MENU_GROUP:New( self.EscortUnit:GetGroup(), EscortGroup:GetName() )
end
)
self.Detection = DETECTION_AREAS:New( EscortGroupSet, 5000 )
self.Detection:Start()
return self
end
@@ -295,7 +284,7 @@ function AI_ESCORT:onafterStart( EscortGroupSet )
EscortGroupSet:ForEachGroup(
--- @param Core.Group#GROUP EscortGroup
function( EscortGroup )
EscortGroup.EscortMenu = MENU_GROUP:New( self.EscortUnit:GetGroup(), EscortGroup:GetName() )
--EscortGroup.EscortMenu = MENU_GROUP:New( self.EscortUnit:GetGroup(), EscortGroup:GetName() )
EscortGroup:WayPointInitialize( 1 )
EscortGroup:OptionROTVertical()
@@ -311,6 +300,10 @@ function AI_ESCORT:onafterStart( EscortGroupSet )
Report:Add( "Joining Up ..." )
LeaderEscort:MessageTypeToGroup( Report:Text(), MESSAGE.Type.Information, self.EscortUnit )
self.Detection = DETECTION_AREAS:New( EscortGroupSet, 5000 )
self.Detection:__Start( 30 )
end
@@ -364,7 +357,7 @@ function AI_ESCORT:Menus()
self:MenuReportTargets( 60 )
self:MenuAssistedAttack()
self:MenuROE()
self:MenuEvasion()
-- self:MenuEvasion()
-- self:MenuResumeMission()
@@ -396,21 +389,6 @@ function AI_ESCORT:MenuFormation( Formation, ... )
)
end
-- self.EscortGroupSet:ForSomeGroupAlive(
-- --- @param Core.Group#GROUP EscortGroup
-- function( EscortGroup )
-- if EscortGroup:IsAir() then
-- if not EscortGroup.EscortMenuReportNavigation then
-- EscortGroup.EscortMenuReportNavigation = MENU_GROUP:New( self.EscortUnit:GetGroup(), "Navigation", EscortGroup.EscortMenu )
-- end
--
-- if not EscortGroup["EscortMenuFormation"..Formation] then
-- EscortGroup["EscortMenuFormation"..Formation] = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), Formation, EscortGroup.EscortMenuReportNavigation, AI_ESCORT["_EscortFormation"..Formation], self, EscortGroup, ... )
-- end
-- end
-- end
-- )
end
@@ -428,22 +406,6 @@ function AI_ESCORT:MenuJoinUp()
self.FlightMenuJoinUp = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Join Up", self.FlightMenuReportNavigation, AI_ESCORT._FlightJoinUp, self )
end
self.EscortGroupSet:ForSomeGroupAlive(
--- @param Core.Group#GROUP EscortGroup
function( EscortGroup )
if EscortGroup:IsAir() then
if not EscortGroup.EscortMenuReportNavigation then
EscortGroup.EscortMenuReportNavigation = MENU_GROUP:New( self.EscortUnit:GetGroup(), "Navigation", EscortGroup.EscortMenu )
end
if not EscortGroup.EscortMenuJoinUpAndFollow then
EscortGroup.EscortMenuJoinUpAndFollow = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Join-Up", EscortGroup.EscortMenuReportNavigation, ESCORT._JoinUp, self, EscortGroup )
end
end
end
)
return self
end
@@ -652,36 +614,6 @@ function AI_ESCORT:MenuHoldAtEscortPosition( Height, Speed, MenuTextFormat )
Speed
)
self.EscortGroupSet:ForSomeGroupAlive(
--- @param Core.Group#GROUP EscortGroup
function( EscortGroup )
if EscortGroup:IsAir() then
if not EscortGroup.EscortMenuHold then
EscortGroup.EscortMenuHold = MENU_GROUP:New( self.EscortUnit:GetGroup(), "Hold position", EscortGroup.EscortMenu )
end
if not EscortGroup.EscortMenuHoldPosition then
EscortGroup.EscortMenuHoldPosition = {}
end
EscortGroup.EscortMenuHoldPosition[#EscortGroup.EscortMenuHoldPosition+1] = MENU_GROUP_COMMAND
:New(
self.EscortUnit:GetGroup(),
MenuText,
EscortGroup.EscortMenuHold,
AI_ESCORT._HoldPosition,
self,
EscortGroup,
EscortGroup,
Height,
Speed
)
end
end
)
return self
end
@@ -739,58 +671,6 @@ function AI_ESCORT:MenuHoldAtLeaderPosition( Height, Speed, MenuTextFormat )
Speed
)
self.EscortGroupSet:ForSomeGroupAlive(
--- @param Core.Group#GROUP EscortGroup
function( EscortGroup )
if EscortGroup:IsAir() then
if not EscortGroup.EscortMenuHold then
EscortGroup.EscortMenuHold = MENU_GROUP:New( self.EscortUnit:GetGroup(), "Hold position", EscortGroup.EscortMenu )
end
if not Height then
Height = 30
end
if not Speed then
Speed = 0
end
local MenuText = ""
if not MenuTextFormat then
if Speed == 0 then
MenuText = string.format( "Rejoin and hold at %d meter", Height )
else
MenuText = string.format( "Rejoin and hold at %d meter at %d", Height, Speed )
end
else
if Speed == 0 then
MenuText = string.format( MenuTextFormat, Height )
else
MenuText = string.format( MenuTextFormat, Height, Speed )
end
end
if not self.EscortMenuHoldAtLeaderPosition then
self.EscortMenuHoldAtLeaderPosition = {}
end
self.EscortMenuHoldAtLeaderPosition[#self.EscortMenuHoldAtLeaderPosition+1] = MENU_GROUP_COMMAND
:New(
self.EscortUnit:GetGroup(),
MenuText,
EscortGroup.EscortMenuHold,
AI_ESCORT._HoldPosition,
self,
self.EscortUnit:GetGroup(),
EscortGroup,
Height,
Speed
)
end
end
)
return self
end
@@ -880,30 +760,6 @@ function AI_ESCORT:MenuFlare( MenuTextFormat )
self.FlightMenuFlareYellow = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Release yellow flare", self.FlightMenuFlare, AI_ESCORT._FlightFlare, self, FLARECOLOR.Yellow, "Released a yellow flare!" )
end
self.EscortGroupSet:ForSomeGroupAlive(
--- @param Core.Group#GROUP EscortGroup
function( EscortGroup )
if not EscortGroup.EscortMenuReportNavigation then
EscortGroup.EscortMenuReportNavigation = MENU_GROUP:New( self.EscortUnit:GetGroup(), "Navigation", EscortGroup.EscortMenu )
end
local MenuText = ""
if not MenuTextFormat then
MenuText = "Flare"
else
MenuText = MenuTextFormat
end
if not EscortGroup.EscortMenuFlare then
EscortGroup.EscortMenuFlare = MENU_GROUP:New( self.EscortUnit:GetGroup(), MenuText, EscortGroup.EscortMenuReportNavigation )
EscortGroup.EscortMenuFlareGreen = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Release green flare", EscortGroup.EscortMenuFlare, AI_ESCORT._Flare, self, EscortGroup, FLARECOLOR.Green, "Released a green flare!" )
EscortGroup.EscortMenuFlareRed = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Release red flare", EscortGroup.EscortMenuFlare, AI_ESCORT._Flare, self, EscortGroup, FLARECOLOR.Red, "Released a red flare!" )
EscortGroup.EscortMenuFlareWhite = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Release white flare", EscortGroup.EscortMenuFlare, AI_ESCORT._Flare, self, EscortGroup, FLARECOLOR.White, "Released a white flare!" )
EscortGroup.EscortMenuFlareYellow = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Release yellow flare", EscortGroup.EscortMenuFlare, AI_ESCORT._Flare, self, EscortGroup, FLARECOLOR.Yellow, "Released a yellow flare!" )
end
end
)
return self
end
@@ -937,33 +793,6 @@ function AI_ESCORT:MenuSmoke( MenuTextFormat )
self.FlightMenuSmokeBlue = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Release blue smoke", self.FlightMenuSmoke, AI_ESCORT._FlightSmoke, self, SMOKECOLOR.Blue, "Releasing blue smoke!" )
end
self.EscortGroupSet:ForSomeGroupAlive(
--- @param Core.Group#GROUP EscortGroup
function( EscortGroup )
if not EscortGroup:IsAir() then
if not EscortGroup.EscortMenuReportNavigation then
EscortGroup.EscortMenuReportNavigation = MENU_GROUP:New( self.EscortUnit:GetGroup(), "Navigation", EscortGroup.EscortMenu )
end
local MenuText = ""
if not MenuTextFormat then
MenuText = "Smoke"
else
MenuText = MenuTextFormat
end
if not EscortGroup.EscortMenuSmoke then
EscortGroup.EscortMenuSmoke = MENU_GROUP:New( self.EscortUnit:GetGroup(), "Smoke", EscortGroup.EscortMenuReportNavigation )
EscortGroup.EscortMenuSmokeGreen = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Release green smoke", EscortGroup.EscortMenuSmoke, AI_ESCORT._Smoke, self, EscortGroup, SMOKECOLOR.Green, "Releasing green smoke!" )
EscortGroup.EscortMenuSmokeRed = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Release red smoke", EscortGroup.EscortMenuSmoke, AI_ESCORT._Smoke, self, EscortGroup, SMOKECOLOR.Red, "Releasing red smoke!" )
EscortGroup.EscortMenuSmokeWhite = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Release white smoke", EscortGroup.EscortMenuSmoke, AI_ESCORT._Smoke, self, EscortGroup, SMOKECOLOR.White, "Releasing white smoke!" )
EscortGroup.EscortMenuSmokeOrange = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Release orange smoke", EscortGroup.EscortMenuSmoke, AI_ESCORT._Smoke, self, EscortGroup, SMOKECOLOR.Orange, "Releasing orange smoke!" )
EscortGroup.EscortMenuSmokeBlue = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Release blue smoke", EscortGroup.EscortMenuSmoke, AI_ESCORT._Smoke, self, EscortGroup, SMOKECOLOR.Blue, "Releasing blue smoke!" )
end
end
end
)
return self
end
@@ -996,29 +825,6 @@ function AI_ESCORT:MenuReportTargets( Seconds )
self.FlightReportTargetsScheduler = SCHEDULER:New( self, self._FlightReportTargetsScheduler, {}, 5, Seconds )
self.EscortGroupSet:ForSomeGroupAlive(
--- @param Core.Group#GROUP EscortGroup
function( EscortGroup )
if EscortGroup:IsAir() then
if not EscortGroup.EscortMenuReportNearbyTargets then
EscortGroup.EscortMenuReportNearbyTargets = MENU_GROUP:New( self.EscortUnit:GetGroup(), "Report targets", EscortGroup.EscortMenu )
end
-- Report Targets
EscortGroup.EscortMenuReportNearbyTargetsNow = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Report targets now!", EscortGroup.EscortMenuReportNearbyTargets, AI_ESCORT._ReportNearbyTargetsNow, self, EscortGroup, true )
EscortGroup.EscortMenuReportNearbyTargetsOn = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Report targets on", EscortGroup.EscortMenuReportNearbyTargets, AI_ESCORT._SwitchReportNearbyTargets, self, EscortGroup, true )
EscortGroup.EscortMenuReportNearbyTargetsOff = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Report targets off", EscortGroup.EscortMenuReportNearbyTargets, AI_ESCORT._SwitchReportNearbyTargets, self, EscortGroup, false )
-- Attack Targets
EscortGroup.EscortMenuAttackNearbyTargets = MENU_GROUP:New( self.EscortUnit:GetGroup(), "Attack targets", EscortGroup.EscortMenu )
EscortGroup.ReportTargetsScheduler = SCHEDULER:New( self, self._ReportTargetsScheduler, { EscortGroup }, timer, Seconds )
timer=timer+1
end
end
)
return self
end
@@ -1051,28 +857,23 @@ end
function AI_ESCORT:MenuROE( MenuTextFormat )
self:F( MenuTextFormat )
self.EscortGroupSet:ForSomeGroupAlive(
--- @param Core.Group#GROUP EscortGroup
function( EscortGroup )
if not EscortGroup.EscortMenuROE then
-- Rules of Engagement
EscortGroup.EscortMenuROE = MENU_GROUP:New( self.EscortUnit:GetGroup(), "ROE", EscortGroup.EscortMenu )
if EscortGroup:OptionROEHoldFirePossible() then
EscortGroup.EscortMenuROEHoldFire = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Hold Fire", EscortGroup.EscortMenuROE, AI_ESCORT._ROE, self, EscortGroup, EscortGroup:OptionROEHoldFire(), "Holding weapons!" )
end
if EscortGroup:OptionROEReturnFirePossible() then
EscortGroup.EscortMenuROEReturnFire = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Return Fire", EscortGroup.EscortMenuROE, AI_ESCORT._ROE, self, EscortGroup, EscortGroup:OptionROEReturnFire(), "Returning fire!" )
end
if EscortGroup:OptionROEOpenFirePossible() then
EscortGroup.EscortMenuROEOpenFire = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Open Fire", EscortGroup.EscortMenuROE, AI_ESCORT._ROE, self, EscortGroup, EscortGroup:OptionROEOpenFire(), "Opening fire on designated targets!!" )
end
if EscortGroup:OptionROEWeaponFreePossible() then
EscortGroup.EscortMenuROEWeaponFree = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Weapon Free", EscortGroup.EscortMenuROE, AI_ESCORT._ROE, self, EscortGroup, EscortGroup:OptionROEWeaponFree(), "Opening fire on targets of opportunity!" )
end
end
end
)
if not self.FlightMenuROE then
self.FlightMenuROE = MENU_GROUP:New( self.EscortUnit:GetGroup(), "ROE", self.FlightMenu )
end
if not self.FlightMenuROEHoldFire then
self.FlightMenuROEHoldFire = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Hold fire", self.FlightMenuROE, AI_ESCORT._ROE, self, ENUMS.ROE.HoldFire, "Holding weapons!" )
end
if not self.FlightMenuROEReturnFire then
self.FlightMenuROEReturnFire = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Return fire", self.FlightMenuROE, AI_ESCORT._ROE, self, ENUMS.ROE.ReturnFire, "Returning fire!" )
end
if not self.FlightMenuROEOpenFire then
self.FlightMenuROEOpenFire = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Open fire", self.FlightMenuROE, AI_ESCORT._ROE, self, ENUMS.ROE.OpenFire, "Open fire at designated targets!" )
end
if not self.FlightMenuROEWeaponFree then
self.FlightMenuROEWeaponFree = MENU_GROUP_COMMAND:New( self.EscortUnit:GetGroup(), "Engage all targets", self.FlightMenuROE, AI_ESCORT._ROE, self, ENUMS.ROE.WeaponFree, "Engaging all targets!" )
end
return self
end
@@ -1318,15 +1119,6 @@ function AI_ESCORT:_FlightSmoke( Color, Message )
end
function AI_ESCORT:_ReportNearbyTargetsNow( EscortGroup )
local EscortUnit = self.EscortUnit
self:_ReportTargetsScheduler( EscortGroup )
end
function AI_ESCORT:_FlightReportNearbyTargetsNow()
self:_FlightReportTargetsScheduler()
@@ -1522,12 +1314,27 @@ function AI_ESCORT:_AssistTarget( EscortGroup, DetectedItem )
end
function AI_ESCORT:_ROE( EscortGroup, EscortROEFunction, EscortROEMessage )
function AI_ESCORT:_ROE( EscortAction, EscortROEMessage )
self:F({EscortAction=EscortAction,EscortROEMessage=EscortROEMessage})
local EscortUnit = self.EscortUnit
pcall( function() EscortROEFunction() end )
EscortGroup:MessageTypeToGroup( EscortROEMessage, MESSAGE.Type.Information, EscortUnit:GetGroup() )
self.EscortGroupSet:ForSomeGroupAlive(
--- @param Wrapper.Group#GROUP EscortGroup
function( EscortGroup )
if EscortAction == ENUMS.ROE.HoldFire then
EscortGroup:OptionROEHoldFire()
elseif EscortAction == ENUMS.ROE.ReturnFire then
EscortGroup:OptionROEReturnFire()
elseif EscortAction == ENUMS.ROE.OpenFire then
EscortGroup:OptionROEOpenFire()
elseif EscortAction == ENUMS.ROE.WeaponFree then
EscortGroup:OptionROEWeaponFree()
end
EscortGroup:MessageTypeToGroup( EscortROEMessage, MESSAGE.Type.Information, EscortUnit:GetGroup() )
end
)
end