A working escort function for helicopters, first version

This commit is contained in:
FlightControl 2016-04-01 17:27:28 +02:00
parent 10fbaa07f5
commit b8c10c2f41
10 changed files with 881 additions and 402 deletions

View File

@ -3683,7 +3683,7 @@ end
--- Holding weapons.
-- @param self
-- @return #GROUP self
function GROUP:HoldFire()
function GROUP:OptionROEHoldFire()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -3695,7 +3695,7 @@ end
--- Return fire.
-- @param self
-- @return #GROUP self
function GROUP:ReturnFire()
function GROUP:OptionROEReturnFire()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -3707,7 +3707,7 @@ end
--- Openfire.
-- @param self
-- @return #GROUP self
function GROUP:OpenFire()
function GROUP:OptionROEOpenFire()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -3719,7 +3719,7 @@ end
--- Weapon free.
-- @param self
-- @return #GROUP self
function GROUP:WeaponFree()
function GROUP:OptionROEWeaponFree()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -3731,7 +3731,7 @@ end
--- No evasion on enemy threats.
-- @param self
-- @return #GROUP self
function GROUP:EvasionNoReaction()
function GROUP:OptionEvasionNoReaction()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -3743,7 +3743,7 @@ end
--- Evasion passive defense.
-- @param self
-- @return #GROUP self
function GROUP:EvasionPassiveDefense()
function GROUP:OptionROTPassiveDefense()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -3755,7 +3755,7 @@ end
--- Evade fire.
-- @param self
-- @return #GROUP self
function GROUP:EvasionEvadeFire()
function GROUP:OptionROTEvadeFire()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -3767,7 +3767,7 @@ end
--- Vertical manoeuvres.
-- @param self
-- @return #GROUP self
function GROUP:EvasionVertical()
function GROUP:OptionROTVertical()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -11167,7 +11167,7 @@ function ESCORT:New( EscortClient, EscortGroup, EscortName )
self.EscortMenuEvasionNoReaction = MENU_CLIENT_COMMAND:New( self.EscortClient, "Fight until death", self.EscortMenuEvasion, ESCORT._EvasionNoReaction, { ParamSelf = self, } )
self.EscortMenuEvasionPassiveDefense = MENU_CLIENT_COMMAND:New( self.EscortClient, "Use flares, chaff and jammers", self.EscortMenuEvasion, ESCORT._EvasionPassiveDefense, { ParamSelf = self, } )
self.EscortMenuEvasionEvadeFire = MENU_CLIENT_COMMAND:New( self.EscortClient, "Evade enemy fire", self.EscortMenuEvasion, ESCORT._EvasionEvadeFire, { ParamSelf = self, } )
self.EscortMenuEvasionVertical = MENU_CLIENT_COMMAND:New( self.EscortClient, "Go below radar and evade fire", self.EscortMenuEvasion, ESCORT._EvasionVertical, { ParamSelf = self, } )
self.EscortMenuOptionEvasionVertical = MENU_CLIENT_COMMAND:New( self.EscortClient, "Go below radar and evade fire", self.EscortMenuEvasion, ESCORT._OptionEvasionVertical, { ParamSelf = self, } )
self.ScanForTargetsFunction = routines.scheduleFunction( self._ScanForTargets, { self }, timer.getTime() + 1, 30 )
@ -11194,49 +11194,49 @@ end
function ESCORT._ROEHoldFire( MenuParam )
MenuParam.ParamSelf.EscortGroup:HoldFire()
MenuParam.ParamSelf.EscortGroup:OptionROEHoldFire()
MESSAGE:New( "Holding weapons.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/AttackUnit" ):ToClient( MenuParam.ParamSelf.EscortClient )
end
function ESCORT._ROEReturnFire( MenuParam )
MenuParam.ParamSelf.EscortGroup:ReturnFire()
MenuParam.ParamSelf.EscortGroup:OptionROEReturnFire()
MESSAGE:New( "Returning enemy fire.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/AttackUnit" ):ToClient( MenuParam.ParamSelf.EscortClient )
end
function ESCORT._ROEOpenFire( MenuParam )
MenuParam.ParamSelf.EscortGroup:OpenFire()
MenuParam.ParamSelf.EscortGroup:OptionROEOpenFire()
MESSAGE:New( "Open fire on ordered targets.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/AttackUnit" ):ToClient( MenuParam.ParamSelf.EscortClient )
end
function ESCORT._ROEWeaponFree( MenuParam )
MenuParam.ParamSelf.EscortGroup:WeaponFree()
MenuParam.ParamSelf.EscortGroup:OptionROEWeaponFree()
MESSAGE:New( "Engaging targets.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/AttackUnit" ):ToClient( MenuParam.ParamSelf.EscortClient )
end
function ESCORT._EvasionNoReaction( MenuParam )
MenuParam.ParamSelf.EscortGroup:EvasionNoReaction()
MenuParam.ParamSelf.EscortGroup:OptionEvasionNoReaction()
MESSAGE:New( "We'll fight until death.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/AttackUnit" ):ToClient( MenuParam.ParamSelf.EscortClient )
end
function ESCORT._EvasionPassiveDefense( MenuParam )
MenuParam.ParamSelf.EscortGroup:EvasionPassiveDefense()
MenuParam.ParamSelf.EscortGroup:OptionROTPassiveDefense()
MESSAGE:New( "We will use flares, chaff and jammers.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/AttackUnit" ):ToClient( MenuParam.ParamSelf.EscortClient )
end
function ESCORT._EvasionEvadeFire( MenuParam )
MenuParam.ParamSelf.EscortGroup:EvasionEvadeFire()
MenuParam.ParamSelf.EscortGroup:OptionROTEvadeFire()
MESSAGE:New( "We'll evade enemy fire.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/AttackUnit" ):ToClient( MenuParam.ParamSelf.EscortClient )
end
function ESCORT._EvasionVertical( MenuParam )
function ESCORT._OptionEvasionVertical( MenuParam )
MenuParam.ParamSelf.EscortGroup:EvasionVertical()
MenuParam.ParamSelf.EscortGroup:OptionROTVertical()
MESSAGE:New( "We'll perform vertical evasive manoeuvres.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/AttackUnit" ):ToClient( MenuParam.ParamSelf.EscortClient )
end

View File

@ -16,7 +16,7 @@ local _TraceClass = {
--ZONE = true,
--GROUP = true,
--UNIT = true,
--CLIENT = true,
--CLIENT = true,
--CARGO = true,
--CARGO_GROUP = true,
--CARGO_PACKAGE = true,
@ -25,7 +25,7 @@ local _TraceClass = {
--CLEANUP = true,
--MENU_CLIENT = true,
--MENU_CLIENT_COMMAND = true,
ESCORT = true,
--ESCORT = true,
}
--- The BASE Class
@ -256,6 +256,7 @@ end
-- Trace section
-- Log a trace (only shown when trace is on)
-- TODO: Make trace function using variable parameters.
function BASE:F( Arguments )

View File

@ -71,35 +71,44 @@ end
function CLIENT:Alive( CallBack )
self:F()
self.ClientAlive = false
self.ClientAlive2 = false
self.ClientCallBack = CallBack
self.AliveCheckFunction = routines.scheduleFunction( self._AliveCheckCallBack, { self }, timer.getTime() + 1, 1 )
self.AliveCheckFunction = routines.scheduleFunction( self._AliveCheckCallBack, { self }, timer.getTime() + 1, 5 )
return self
end
--- Checks if client is alive and returns true or false.
-- @param #CLIENT self
-- @param #boolean Returns true if client is alive.
function CLIENT:IsAlive()
self:F()
self:F( self.ClientName )
local ClientDCSGroup = self:GetDCSGroup()
if ClientDCSGroup then
self:T("true")
return true
end
self:T( "false" )
return false
end
--- @param #CLIENT self
function CLIENT:_AliveCheckCallBack()
self:F( { self.ClientName, self.ClientAlive2 } )
if self:IsAlive() then
if self.ClientAlive == false then
if self.ClientAlive2 == false then
self:T("Calling Callback function")
self.ClientCallBack( self )
self.ClientAlive = true
routines.removeFunction( self.AliveCheckFunction )
self.ClientAlive2 = true
end
else
if self.ClientAlive2 == true then
self.ClientAlive2 = false
end
end
end

View File

@ -8,7 +8,7 @@
-- * Report identified targets
-- * Perform tasks per identified target: Report vector to target, paint target, kill target
--
-- @module ESCORT
-- @module Escort
-- @author FlightControl
Include.File( "Routines" )
@ -24,6 +24,9 @@ Include.File( "Zone" )
-- @field Group#GROUP EscortGroup
-- @field #string EscortName
-- @field #number FollowScheduler The id of the _FollowScheduler function.
-- @field #boolean ReportTargets If true, nearby targets are reported.
-- @Field DCSTypes#AI.Option.Air.val.ROE OptionROE Which ROE is set to the EscortGroup.
-- @field DCSTypes#AI.Option.Air.val.REACTION_ON_THREAT OptionReactionOnThreat Which REACTION_ON_THREAT is set to the EscortGroup.
ESCORT = {
ClassName = "ESCORT",
EscortName = nil, -- The Escort Name
@ -31,6 +34,9 @@ ESCORT = {
EscortGroup = nil,
Targets = {}, -- The identified targets
FollowScheduler = nil,
ReportTargets = true,
OptionROE = AI.Option.Air.val.ROE.OPEN_FIRE,
OptionReactionOnThreat = AI.Option.Air.val.REACTION_ON_THREAT.ALLOW_ABORT_MISSION
}
--- MENUPARAM type
@ -48,10 +54,9 @@ function ESCORT:New( EscortClient, EscortGroup, EscortName )
local self = BASE:Inherit( self, BASE:New() )
self:F( { EscortClient, EscortGroup, EscortName } )
self.EscortClient = EscortClient
self.EscortGroup = EscortGroup
self.EscortClient = EscortClient -- Client#CLIENT
self.EscortGroup = EscortGroup -- Group#GROUP
self.EscortName = EscortName
self.ReportTargets = true
self.EscortMenu = MENU_CLIENT:New( self.EscortClient, "Escort" .. self.EscortName )
@ -88,24 +93,38 @@ function ESCORT:New( EscortClient, EscortGroup, EscortName )
-- Reaction to Threats
self.EscortMenuEvasion = MENU_CLIENT:New( self.EscortClient, "Evasion", self.EscortMenu )
self.EscortMenuEvasionNoReaction = MENU_CLIENT_COMMAND:New( self.EscortClient, "Fight until death", self.EscortMenuEvasion, ESCORT._EvasionNoReaction, { ParamSelf = self, } )
self.EscortMenuEvasionPassiveDefense = MENU_CLIENT_COMMAND:New( self.EscortClient, "Use flares, chaff and jammers", self.EscortMenuEvasion, ESCORT._EvasionPassiveDefense, { ParamSelf = self, } )
self.EscortMenuEvasionEvadeFire = MENU_CLIENT_COMMAND:New( self.EscortClient, "Evade enemy fire", self.EscortMenuEvasion, ESCORT._EvasionEvadeFire, { ParamSelf = self, } )
self.EscortMenuEvasionVertical = MENU_CLIENT_COMMAND:New( self.EscortClient, "Go below radar and evade fire", self.EscortMenuEvasion, ESCORT._EvasionVertical, { ParamSelf = self, } )
self.EscortMenuEvasionNoReaction = MENU_CLIENT_COMMAND:New( self.EscortClient, "Fight until death", self.EscortMenuEvasion, ESCORT._OptionROTNoReaction, { ParamSelf = self, } )
self.EscortMenuEvasionPassiveDefense = MENU_CLIENT_COMMAND:New( self.EscortClient, "Use flares, chaff and jammers", self.EscortMenuEvasion, ESCORT._OptionROTPassiveDefense, { ParamSelf = self, } )
self.EscortMenuEvasionEvadeFire = MENU_CLIENT_COMMAND:New( self.EscortClient, "Evade enemy fire", self.EscortMenuEvasion, ESCORT._OptionROTEvadeFire, { ParamSelf = self, } )
self.EscortMenuOptionEvasionVertical = MENU_CLIENT_COMMAND:New( self.EscortClient, "Go below radar and evade fire", self.EscortMenuEvasion, ESCORT._OptionROTVertical, { ParamSelf = self, } )
-- Cancel current Task
self.EscortMenuCancelTask = MENU_CLIENT_COMMAND:New( self.EscortClient, "Cancel current task", self.EscortMenu, ESCORT._CancelCurrentTask, { ParamSelf = self, } )
self.EscortMenuResumeMission = MENU_CLIENT:New( self.EscortClient, "Resume Mission", self.EscortMenu )
self.EscortMenuResumeWayPoints = {}
local TaskPoints = self:RegisterRoute()
for WayPointID, WayPoint in pairs( TaskPoints ) do
self.EscortMenuResumeWayPoints[WayPointID] = MENU_CLIENT_COMMAND:New( self.EscortClient, "Resume from waypoint " .. WayPointID, self.EscortMenuResumeMission, ESCORT._ResumeMission, { ParamSelf = self, ParamWayPoint = WayPointID } )
end
-- Initialize the EscortGroup
self.ScanForTargetsScheduler = routines.scheduleFunction( self._ScanForTargets, { self }, timer.getTime() + 1, 30 )
self.EscortGroup:OptionROTVertical()
self.EscortGroup:OptionROEOpenFire()
self.EscortGroup:PushTask( EscortGroup:TaskRoute( TaskPoints ) )
self.ReportTargetsScheduler = routines.scheduleFunction( self._ReportTargetsScheduler, { self }, timer.getTime() + 1, 30 )
end
--- @param #MENUPARAM MenuParam
function ESCORT._HoldPosition( MenuParam )
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
routines.removeFunction( self.FollowScheduler )
EscortGroup:PushTask( EscortGroup:TaskHoldPosition( 300 ) )
MESSAGE:New( "Holding Position at ... for 5 minutes.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/TaskHoldPosition" ):ToClient( EscortClient )
@ -114,11 +133,14 @@ end
--- @param #MENUPARAM MenuParam
function ESCORT._HoldPositionNearBy( MenuParam )
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
--MenuParam.ParamSelf.EscortGroup:TaskOrbitCircleAtVec2( MenuParam.ParamSelf.EscortClient:GetPointVec2(), 300, 30, 0 )
routines.removeFunction( self.FollowScheduler )
local PointFrom = {}
local GroupPoint = EscortGroup:GetPointVec2()
PointFrom = {}
@ -141,8 +163,7 @@ function ESCORT._HoldPositionNearBy( MenuParam )
local Points = { PointFrom, PointTo }
EscortGroup:PushTask( EscortGroup:TaskMission( Points ) )
EscortGroup:PushTask( EscortGroup:TaskRoute( Points ) )
MESSAGE:New( "Rejoining to your location. Please hold at your location.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/HoldPositionNearBy" ):ToClient( EscortClient )
end
@ -150,8 +171,8 @@ end
function ESCORT._JoinUpAndFollow( MenuParam )
local self = MenuParam.ParamSelf
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
local Distance = MenuParam.ParamDistance
@ -167,18 +188,32 @@ end
function ESCORT._ReportNearbyTargets( MenuParam )
MenuParam.ParamSelf:T()
MenuParam.ParamSelf.ReportTargets = MenuParam.ParamReportTargets
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
self.ReportTargets = MenuParam.ParamReportTargets
if self.ReportTargets then
if not self.ReportTargetsScheduler then
self.ReportTargetsScheduler = routines.scheduleFunction( self._ReportTargetsScheduler, { self }, timer.getTime() + 1, 30 )
end
else
routines.removeFunction( self.ReportTargetsScheduler )
self.ReportTargetsScheduler = nil
end
end
--- @param #MENUPARAM MenuParam
function ESCORT._ScanTargets30Seconds( MenuParam )
MenuParam.ParamSelf:T()
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
routines.removeFunction( self.FollowScheduler )
EscortGroup:PushTask(
EscortGroup:TaskControlled(
@ -193,8 +228,11 @@ end
function ESCORT._ScanTargets60Seconds( MenuParam )
MenuParam.ParamSelf:T()
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
routines.removeFunction( self.FollowScheduler )
EscortGroup:PushTask(
EscortGroup:TaskControlled(
@ -208,12 +246,16 @@ end
--- @param #MENUPARAM MenuParam
function ESCORT._AttackTarget( MenuParam )
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
local AttackUnit = MenuParam.ParamUnit
EscortGroup:OpenFire()
EscortGroup:EvasionVertical()
routines.removeFunction( self.FollowScheduler )
self.FollowScheduler = nil
EscortGroup:OptionROEOpenFire()
EscortGroup:OptionROTVertical()
EscortGroup:PushTask( EscortGroup:TaskAttackUnit( AttackUnit ) )
MESSAGE:New( "Attacking Unit", MenuParam.ParamSelf.EscortName, 10, "ESCORT/AttackTarget" ):ToClient( EscortClient )
end
@ -221,91 +263,131 @@ end
--- @param #MENUPARAM MenuParam
function ESCORT._ROEHoldFire( MenuParam )
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
EscortGroup:HoldFire()
EscortGroup:OptionROEHoldFire()
MESSAGE:New( "Holding weapons.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/ROEHoldFire" ):ToClient( EscortClient )
end
--- @param #MENUPARAM MenuParam
function ESCORT._ROEReturnFire( MenuParam )
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
EscortGroup:ReturnFire()
EscortGroup:OptionROEReturnFire()
MESSAGE:New( "Returning enemy fire.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/ROEReturnFire" ):ToClient( EscortClient )
end
--- @param #MENUPARAM MenuParam
function ESCORT._ROEOpenFire( MenuParam )
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
EscortGroup:OpenFire()
EscortGroup:OptionROEOpenFire()
MESSAGE:New( "Open fire on ordered targets.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/ROEOpenFire" ):ToClient( EscortClient )
end
--- @param #MENUPARAM MenuParam
function ESCORT._ROEWeaponFree( MenuParam )
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
EscortGroup:WeaponFree()
EscortGroup:OptionROEWeaponFree()
MESSAGE:New( "Engaging targets.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/ROEWeaponFree" ):ToClient( EscortClient )
end
--- @param #MENUPARAM MenuParam
function ESCORT._EvasionNoReaction( MenuParam )
function ESCORT._OptionROTNoReaction( MenuParam )
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
EscortGroup:EvasionNoReaction()
MESSAGE:New( "We'll fight until death.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/EvasionNoReaction" ):ToClient( EscortClient )
EscortGroup:OptionEvasionNoReaction()
MESSAGE:New( "We'll fight until death.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/OptionEvasionNoReaction" ):ToClient( EscortClient )
end
--- @param #MENUPARAM MenuParam
function ESCORT._EvasionPassiveDefense( MenuParam )
function ESCORT._OptionROTPassiveDefense( MenuParam )
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
EscortGroup:EvasionPassiveDefense()
MESSAGE:New( "We will use flares, chaff and jammers.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/EvasionPassiveDefense" ):ToClient( EscortClient )
EscortGroup:OptionROTPassiveDefense()
MESSAGE:New( "We will use flares, chaff and jammers.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/OptionROTPassiveDefense" ):ToClient( EscortClient )
end
--- @param #MENUPARAM MenuParam
function ESCORT._EvasionEvadeFire( MenuParam )
function ESCORT._OptionROTEvadeFire( MenuParam )
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
EscortGroup:EvasionEvadeFire()
MESSAGE:New( "We'll evade enemy fire.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/EvasionEvadeFire" ):ToClient( EscortClient )
EscortGroup:OptionROTEvadeFire()
MESSAGE:New( "We'll evade enemy fire.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/OptionROTEvadeFire" ):ToClient( EscortClient )
end
--- @param #MENUPARAM MenuParam
function ESCORT._EvasionVertical( MenuParam )
function ESCORT._OptionROTVertical( MenuParam )
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
EscortGroup:EvasionVertical()
MESSAGE:New( "We'll perform vertical evasive manoeuvres.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/EvasionVertical" ):ToClient( EscortClient )
EscortGroup:OptionROTVertical()
MESSAGE:New( "We'll perform vertical evasive manoeuvres.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/OptionROTVertical" ):ToClient( EscortClient )
end
--- @param #MENUPARAM MenuParam
function ESCORT._CancelCurrentTask( MenuParam )
function ESCORT._ResumeMission( MenuParam )
local EscortGroup = MenuParam.ParamSelf.EscortGroup
local EscortClient = MenuParam.ParamSelf.EscortClient
local self = MenuParam.ParamSelf
local EscortGroup = self.EscortGroup
local EscortClient = self.EscortClient
local WayPoint = MenuParam.ParamWayPoint
routines.removeFunction( self.FollowScheduler )
self.FollowScheduler = nil
local WayPoints = EscortGroup:GetTaskRoute()
self:T( WayPoint, WayPoints )
for WayPointIgnore = 1, WayPoint do
table.remove( WayPoints, 1 )
end
EscortGroup:PopCurrentTask()
MESSAGE:New( "Cancelling with current orders, continuing our mission.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/CancelCurrentTask" ):ToClient( EscortClient )
EscortGroup:PushTask( EscortGroup:TaskRoute( WayPoints ) )
MESSAGE:New( "Resuming mission.", MenuParam.ParamSelf.EscortName, 10, "ESCORT/ResumeMission" ):ToClient( EscortClient )
end
function ESCORT:RegisterRoute()
local EscortGroup = self.EscortGroup -- Group#GROUP
local TaskPoints = EscortGroup:GetTaskRoute()
self:T( TaskPoints )
for TaskPointID, TaskPoint in pairs( TaskPoints ) do
self:T( TaskPointID )
TaskPoint.task.params.tasks[#TaskPoint.task.params.tasks+1] = EscortGroup:TaskRegisterWayPoint( TaskPointID )
self:T( TaskPoint.task.params.tasks[#TaskPoint.task.params.tasks] )
end
self:T( TaskPoints )
return TaskPoints
end
--- @param Escort#ESCORT self
@ -355,46 +437,49 @@ function ESCORT:_FollowScheduler( FollowDistance )
local GV = { x = GV2.x - CV2.x, y = GV2.y - CV2.y, z = GV2.z - CV2.z }
-- Calculate GH2, GH2 with the same height as CV2.
local GH2 = { x = GV2.x, y = GV2.y, z = CV2.z }
local GH2 = { x = GV2.x, y = CV2.y, z = GV2.z }
-- Calculate the angle of GV to the orthonormal plane
local alpha = math.atan2( GV.y, GV.x )
local alpha = math.atan2( GV.z, GV.x )
-- Now we calculate the intersecting vector between the circle around CV2 with radius FollowDistance and GH2.
-- From the GeoGebra model: CVI = (x(CV2) + FollowDistance cos(alpha), y(CV2) + FollowDistance sin(alpha), z(GH2))
-- From the GeoGebra model: CVI = (x(CV2) + FollowDistance cos(alpha), y(GH2) + FollowDistance sin(alpha), z(CV2))
local CVI = { x = CV2.x + FollowDistance * math.cos(alpha),
y = CV2.y + FollowDistance * math.sin(alpha),
z = GH2.z
y = GH2.y,
z = CV2.z + FollowDistance * math.sin(alpha),
}
-- Calculate the direction vector DV of the escort group. We use CVI as the base and CV2 as the direction.
local DV = { x = CV2.x - CVI.x, y = CV2.y - CVI.y, z = CV2.z - CVI.z }
-- We now calculate the unary direction vector DVu, so that we can multiply DVu with the speed, which is expressed in meters / s.
-- We need to calculate this vector to predict the point the escort group needs to fly to according its speed.
-- The distance of the destination point should be far enough not to have the aircraft starting to swipe left to right...
local DVu = { x = DV.x / FollowDistance, y = DV.y / FollowDistance, z = DV.z / FollowDistance }
-- Now we can calculate the group destination vector GDV.
local GDV = { x = DVu.x * CS * 2 + CVI.x, y = CVI.y, z = DVu.z * CS * 2 + CVI.z }
self:T2( { "CV2:", CV2 } )
self:T2( { "CVI:", CVI } )
self:T2( { "GDV:", GDV } )
-- Measure distance between client and group
local CatchUpDistance = ( ( CVI.x - GV2.x )^2 + ( CVI.y - GV2.y )^2 + ( CVI.z - GV2.z )^2 ) ^ 0.5
local Distance = CatchUpDistance - FollowDistance
local CatchUpDistance = ( ( GDV.x - GV2.x )^2 + ( GDV.y - GV2.y )^2 + ( GDV.z - GV2.z )^2 ) ^ 0.5
-- The calculation of the Speed would simulate that the group would take 30 seconds to overcome
-- the requested Distance).
local Time = 1600 / FollowDistance
local CatchUpSpeed = ( Distance / Time ) * ( CatchUpDistance / 1000 )
local Time = 30
local CatchUpSpeed = ( CatchUpDistance - ( CS * 2 ) ) / Time
-- Follow speed required = Client Speed - Group Speed + Speed to overcome distance.
local BreakSpeed = ( GS * ( ( 1 ) / Distance ) )
if BreakSpeed < 0 then
BreakSpeed = 0
end
if BreakSpeed > CS then
BreakSpeed = CS
end
local Speed = CS + CatchUpSpeed --- - BreakSpeed
local Speed = CS + CatchUpSpeed
if Speed < 0 then
Speed = 0
end
self:T( { "Client Speed, Client Time, Escort Speed, Speed, CatchUpSpeed, BreakSpeed, Distance, Time:", CS, CT, GS, Speed, CatchUpSpeed, BreakSpeed, Distance, Time } )
self:T( { "Client Speed, Escort Speed, Speed, FlyDistance, Time:", CS, GS, Speed, Distance, Time } )
-- Now route the escort to the desired point with the desired speed.
self.EscortGroup:TaskRouteToVec3( CVI, Speed / 3.6 ) -- DCS models speed in Mps (Miles per second)
self.EscortGroup:TaskRouteToVec3( GDV, Speed / 3.6 ) -- DCS models speed in Mps (Miles per second)
end
else
routines.removeFunction( self.FollowScheduler )
@ -403,7 +488,7 @@ function ESCORT:_FollowScheduler( FollowDistance )
end
function ESCORT:_ScanForTargets()
function ESCORT:_ReportTargetsScheduler()
self:F()
self.Targets = {}
@ -511,6 +596,7 @@ function ESCORT:_ScanForTargets()
end
else
routines.removeFunction( self.ScanForTargetsScheduler )
routines.removeFunction( self.ReportTargetsScheduler )
self.ReportTargetsScheduler = nil
end
end

View File

@ -26,7 +26,8 @@ GROUP = {
-- @type DCSGroup
-- @field id_ The ID of the group in DCS
GROUPS = {}
--- The GROUPS structure contains references to all the created GROUP instances.
local GROUPS = {}
--- Create a new GROUP from a DCSGroup
-- @param self
@ -45,6 +46,8 @@ function GROUP:New( DCSGroup )
self:E( { "DCSGroup is nil or does not exist, cannot initialize GROUP!", self.DCSGroup } )
end
GROUPS[self.GroupID] = self
return self
end
@ -64,6 +67,8 @@ function GROUP:NewFromName( GroupName )
self.Controller = self.DCSGroup:getController()
end
GROUPS[self.GroupID] = self
return self
end
@ -82,6 +87,8 @@ function GROUP:NewFromDCSUnit( DCSUnit )
self.Controller = self.DCSGroup:getController()
end
GROUPS[self.GroupID] = self
return self
end
@ -556,13 +563,27 @@ function GROUP:TaskEmbarkToTransportAtVec2( Point, Radius )
return DCSTask
end
--- Return a Misson task to follow a given route.
--- Return a Misson task from a mission template.
-- @param #GROUP self
-- @param #table Points A table of Route Points.
-- @param #table TaskMission A table containing the mission task.
-- @return #DCSTask
function GROUP:TaskMission( Points )
function GROUP:TaskMission( TaskMission )
self:F( Points )
local DCSTask
DCSTask = { id = 'Mission', params = { TaskMission, }, }
self:T( { DCSTask } )
return DCSTask
end
--- Return a Misson task to follow a given route defined by Points.
-- @param #GROUP self
-- @param #table Points A table of route points.
-- @return #DCSTask
function GROUP:TaskRoute( Points )
self:F( Points )
local DCSTask
DCSTask = { id = 'Mission', params = { route = { points = Points, }, }, }
@ -622,6 +643,33 @@ function GROUP:Route( GoPoints )
return self
end
function GROUP:TaskRegisterWayPoint( WayPoint )
local DCSTask
DCSTask = { id = "WrappedAction",
enabled = true,
auto = false,
number = 1,
params =
{
action =
{
id = "Script",
params =
{
command = "local MissionGroup = GROUP.FindGroup( ... ) " ..
"env.info( MissionGroup:GetName() ) " ..
"MissionGroup:RegisterWayPoint ( " .. WayPoint .. " )",
}, -- end of ["params"]
}, -- end of ["action"]
}, -- end of ["params"]
}
self:T( DCSTask )
return DCSTask
end
--- Route the group to a given zone.
-- The group final destination point can be randomized.
-- A speed can be given in km/h.
@ -678,6 +726,24 @@ function GROUP:TaskRouteToZone( Zone, Randomize, Speed, Formation )
return self
end
--- Return the mission template of the group.
-- @param #GROUP self
-- @return #table The MissionTemplate
function GROUP:GetTaskMission()
self:F( self.GroupName )
return _Database.Groups[self.GroupName].Template
end
--- Return the mission route of the group.
-- @param #GROUP self
-- @return #table The mission route defined by points.
function GROUP:GetTaskRoute()
self:F( self.GroupName )
return _Database.Groups[self.GroupName].Template.route.points
end
--- Return the route of a group by using the @{Database#DATABASE} class.
-- @param #GROUP self
-- @param #number Begin The route point from where the copy will start. The base route point is 0.
@ -757,7 +823,7 @@ end
--- Holding weapons.
-- @param #GROUP self
-- @return #GROUP self
function GROUP:HoldFire()
function GROUP:OptionROEHoldFire()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -769,7 +835,7 @@ end
--- Return fire.
-- @param #GROUP self
-- @return #GROUP self
function GROUP:ReturnFire()
function GROUP:OptionROEReturnFire()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -781,7 +847,7 @@ end
--- Openfire.
-- @param #GROUP self
-- @return #GROUP self
function GROUP:OpenFire()
function GROUP:OptionROEOpenFire()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -793,7 +859,7 @@ end
--- Weapon free.
-- @param #GROUP self
-- @return #GROUP self
function GROUP:WeaponFree()
function GROUP:OptionROEWeaponFree()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -805,7 +871,7 @@ end
--- No evasion on enemy threats.
-- @param #GROUP self
-- @return #GROUP self
function GROUP:EvasionNoReaction()
function GROUP:OptionEvasionNoReaction()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -817,7 +883,7 @@ end
--- Evasion passive defense.
-- @param #GROUP self
-- @return #GROUP self
function GROUP:EvasionPassiveDefense()
function GROUP:OptionROTPassiveDefense()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -829,7 +895,7 @@ end
--- Evade fire.
-- @param #GROUP self
-- @return #GROUP self
function GROUP:EvasionEvadeFire()
function GROUP:OptionROTEvadeFire()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -841,7 +907,7 @@ end
--- Vertical manoeuvres.
-- @param #GROUP self
-- @return #GROUP self
function GROUP:EvasionVertical()
function GROUP:OptionROTVertical()
self:F( { self.GroupName } )
local Controller = self:_GetController()
@ -908,3 +974,25 @@ function GROUP:MessageToClient( Message, Duration, Client )
self:Message( Message, Duration ):ToClient( Client )
end
function GROUP:RegisterWayPoint( WayPoint )
self:Message( "Moving over wayPoint " .. WayPoint, 20 ):ToAll()
self.WayPoint = WayPoint
end
--- Find the created GROUP using the DCSGroup ID. If a GROUP was created with the DCSGroupID, the the GROUP instance will be returned.
-- Otherwise nil will be returned.
-- @param DCSGroup#Group Group
-- @return #GROUP
function GROUP.FindGroup( DCSGroup )
local self = GROUPS[DCSGroup:getID()] -- Group#GROUP
self:T( self:GetClassNameAndID() )
return self
end

View File

@ -1,18 +1,27 @@
Include.File( "Mission" )
Include.File( "Client" )
Include.File( "Spawn" )
Include.File( "Escort" )
do
local function EventAliveHelicopter( Client )
local EscortGroupHeli = GROUP:NewFromName( "Escort Helicopter" )
local EscortHeli = ESCORT:New( Client, EscortGroupHeli, "Escort Test Helicopter" )
local SpawnEscortHeli = SPAWN:New( "Escort Helicopter" )
local EscortGroupHeli1 = SpawnEscortHeli:Spawn()
local EscortGroupHeli2 = SpawnEscortHeli:Spawn()
local EscortGroupHeli3 = SpawnEscortHeli:Spawn()
local EscortGroupHeli4 = SpawnEscortHeli:Spawn()
local EscortHeli1 = ESCORT:New( Client, EscortGroupHeli1, "Escort Alpha" )
local EscortHeli2 = ESCORT:New( Client, EscortGroupHeli2, "Escort Bravo" )
local EscortHeli3 = ESCORT:New( Client, EscortGroupHeli3, "Escort Delta" )
local EscortHeli4 = ESCORT:New( Client, EscortGroupHeli4, "Escort Gamma" )
end
local function EventAlivePlane( Client )
local EscortGroupPlane = GROUP:NewFromName( "Escort Plane" )
local EscortPlane = ESCORT:New( EscortClientPlane, EscortGroupPlane, "Escort Test Plane" )
local SpawnEscortPlane = SPAWN:New( "Escort Plane" )
local EscortGroupPlane = SpawnEscortPlane:Spawn()
local EscortPlane = ESCORT:New( Client, EscortGroupPlane, "Escort Test Plane" )
end
local EscortClientHeli = CLIENT:New( "Lead Helicopter", "Fly around and observe the behaviour of the escort helicopter" ):Alive( EventAliveHelicopter )

View File

@ -3,23 +3,31 @@ dictionary =
["DictKey_GroupName_19"] = "Escort Plane",
["DictKey_WptName_11"] = "",
["DictKey_UnitName_20"] = "Escort Plane",
["DictKey_GroupName_15"] = "Lead Plane",
["DictKey_GroupName_12"] = "Escort Helicopter",
["DictKey_WptName_30"] = "",
["DictKey_sortie_4"] = "",
["DictKey_WptName_28"] = "",
["DictKey_WptName_14"] = "",
["DictKey_WptName_29"] = "",
["DictKey_WptName_23"] = "",
["DictKey_GroupName_15"] = "Lead Plane",
["DictKey_descriptionRedTask_2"] = "",
["DictKey_descriptionBlueTask_3"] = "",
["DictKey_GroupName_9"] = "Lead Helicopter",
["DictKey_GroupName_31"] = "Test Attack",
["DictKey_descriptionText_1"] = "",
["DictKey_UnitName_10"] = "Lead Helicopter",
["DictKey_UnitName_13"] = "Escort Helicopter",
["DictKey_UnitName_32"] = "Unit #1",
["DictKey_WptName_21"] = "",
["DictKey_descriptionBlueTask_3"] = "",
["DictKey_WptName_22"] = "",
["DictKey_WptName_18"] = "",
["DictKey_WptName_14"] = "",
["DictKey_UnitName_10"] = "Lead Helicopter",
["DictKey_WptName_17"] = "",
["DictKey_UnitName_13"] = "Escort Helicopter",
["DictKey_WptName_33"] = "",
["DictKey_WptName_26"] = "",
["DictKey_WptName_25"] = "",
["DictKey_UnitName_16"] = "Lead Plane",
["DictKey_WptName_21"] = "",
["DictKey_WptName_24"] = "",
["DictKey_GroupName_12"] = "Escort Helicopter",
["DictKey_WptName_34"] = "",
["DictKey_WptName_27"] = "",
} -- end of dictionary

File diff suppressed because it is too large Load Diff

View File

@ -442,7 +442,7 @@ warehouses =
["suppliers"] =
{
}, -- end of ["suppliers"]
["coalition"] = "NEUTRAL",
["coalition"] = "BLUE",
["jet_fuel"] =
{
["InitFuel"] = 100,