Fixed AI_CAS_ZONE

-- Added separate detection loop during engagement
-- Detection during patrolling is off.
-- Engage now has several parameters that specify how to engage within
the zone.
-- Created several additional test missions, more to come.
This commit is contained in:
FlightControl 2017-02-06 14:58:19 +01:00
parent 9f63184a5e
commit 93e7fab116
94 changed files with 814 additions and 169 deletions

View File

@ -148,7 +148,7 @@ function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude
self.Accomplished = false
self:SetDetectionZone( self.EngageZone )
self:AddTransition( { "Patrolling", "Engaging" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnBefore Transition Handler for Event Engage.
@ -158,6 +158,12 @@ function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
-- @param #number EngageSpeed (optional) The speed the Group will hold when engaging to the target zone.
-- @param Dcs.DCSTypes#AI.Task.WeaponExpend EngageWeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param Dcs.DCSTypes#Distance EngageAltitude (optional) Desired altitude to perform the unit engagement.
-- @param #number EngageAttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo.
-- @param Dcs.DCSTypes#Azimuth EngageDirection (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
-- @return #boolean Return false to cancel Transition.
--- OnAfter Transition Handler for Event Engage.
@ -167,6 +173,11 @@ function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
-- @param #number EngageSpeed (optional) The speed the Group will hold when engaging to the target zone.
-- @param Dcs.DCSTypes#AI.Task.WeaponExpend EngageWeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param Dcs.DCSTypes#Distance EngageAltitude (optional) Desired altitude to perform the unit engagement.
-- @param #number EngageAttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo.
-- @param Dcs.DCSTypes#Azimuth EngageDirection (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
--- Synchronous Event Trigger for Event Engage.
-- @function [parent=#AI_CAS_ZONE] Engage
@ -194,6 +205,8 @@ function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude
-- @param #string Event The Event string.
-- @param #string To The To State string.
self:AddTransition( "Engaging", "Target", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnBefore Transition Handler for Event Fired.
@ -339,6 +352,7 @@ function AI_CAS_ZONE:onafterStart( Controllable, From, Event, To )
self:GetParent(self).onafterStart( self, Controllable, From, Event, To )
self:EventOnDead( self.OnDead )
self:SetDetectionDeactivated() -- When not engaging, set the detection off.
end
--- @param Wrapper.Controllable#CONTROLLABLE AIControllable
@ -361,15 +375,62 @@ function AI_CAS_ZONE:onbeforeEngage( Controllable, From, Event, To )
end
end
--- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
function AI_CAS_ZONE:onafterTarget( Controllable, From, Event, To )
self:E("onafterTarget")
if Controllable:IsAlive() then
local AttackTasks = {}
for DetectedUnit, Detected in pairs( self.DetectedUnits ) do
local DetectedUnit = DetectedUnit -- Wrapper.Unit#UNIT
if DetectedUnit:IsAlive() then
if DetectedUnit:IsInZone( self.EngageZone ) then
if Detected == true then
self:E( {"Target: ", DetectedUnit } )
self.DetectedUnits[DetectedUnit] = false
local AttackTask = Controllable:EnRouteTaskEngageUnit( DetectedUnit, 1, true, self.EngageWeaponExpend, self.EngageAttackQty, self.EngageDirection, self.EngageAltitude, nil )
self.Controllable:PushTask( AttackTask, 1 )
end
end
else
self.DetectedUnits[DetectedUnit] = nil
end
end
self:__Target( -10 )
end
end
--- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
-- @param #number EngageSpeed (optional) The speed the Group will hold when engaging to the target zone.
-- @param Dcs.DCSTypes#AI.Task.WeaponExpend EngageWeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param Dcs.DCSTypes#Distance EngageAltitude (optional) Desired altitude to perform the unit engagement.
-- @param #number EngageAttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo.
-- @param Dcs.DCSTypes#Azimuth EngageDirection (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To, EngageSpeed, EngageAltitude, EngageWeaponExpend, EngageAttackQty, EngageDirection )
self:E("onafterEngage")
self.EngageSpeed = EngageSpeed or 400
self.EngageAltitude = EngageAltitude or 2000
self.EngageWeaponExpend = EngageWeaponExpend
self.EngageAttackQty = EngageAttackQty
self.EngageDirection = EngageDirection
if Controllable:IsAlive() then
local EngageRoute = {}
@ -384,7 +445,7 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
self.PatrolAltType,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToEngageZoneSpeed,
self.EngageSpeed,
true
)
@ -397,20 +458,15 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
local ToEngageZoneVec2 = self.EngageZone:GetRandomVec2()
self:T2( ToEngageZoneVec2 )
-- Define Speed and Altitude.
local ToEngageZoneAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
local ToEngageZoneSpeed = self.PatrolMaxSpeed
self:T2( ToEngageZoneSpeed )
-- Obtain a 3D @{Point} from the 2D point + altitude.
local ToEngageZonePointVec3 = POINT_VEC3:New( ToEngageZoneVec2.x, ToEngageZoneAltitude, ToEngageZoneVec2.y )
local ToEngageZonePointVec3 = POINT_VEC3:New( ToEngageZoneVec2.x, self.EngageAltitude, ToEngageZoneVec2.y )
-- Create a route point of type air.
local ToEngageZoneRoutePoint = ToEngageZonePointVec3:RoutePointAir(
self.PatrolAltType,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToEngageZoneSpeed,
self.EngageSpeed,
true
)
@ -424,20 +480,15 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
local ToTargetVec2 = self.EngageZone:GetRandomVec2()
self:T2( ToTargetVec2 )
--- Define Speed and Altitude.
local ToTargetAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
local ToTargetSpeed = math.random( self.PatrolMinSpeed, self.PatrolMaxSpeed )
self:T2( { self.PatrolMinSpeed, self.PatrolMaxSpeed, ToTargetSpeed } )
--- Obtain a 3D @{Point} from the 2D point + altitude.
local ToTargetPointVec3 = POINT_VEC3:New( ToTargetVec2.x, ToTargetAltitude, ToTargetVec2.y )
local ToTargetPointVec3 = POINT_VEC3:New( ToTargetVec2.x, self.EngageAltitude, ToTargetVec2.y )
--- Create a route point of type air.
local ToTargetRoutePoint = ToTargetPointVec3:RoutePointAir(
self.PatrolAltType,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed,
self.EngageSpeed,
true
)
@ -447,24 +498,24 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
Controllable:OptionROEOpenFire()
Controllable:OptionROTPassiveDefense()
Controllable:OptionROTVertical()
local AttackTasks = {}
for DetectedUnitID, DetectedUnit in pairs( self.DetectedUnits ) do
local DetectedUnit = DetectedUnit -- Wrapper.Unit#UNIT
self:T( DetectedUnit )
if DetectedUnit:IsAlive() then
if DetectedUnit:IsInZone( self.EngageZone ) then
self:E( {"Engaging ", DetectedUnit } )
AttackTasks[#AttackTasks+1] = Controllable:TaskAttackUnit( DetectedUnit )
end
else
self.DetectedUnits[DetectedUnit] = nil
end
end
EngageRoute[1].task = Controllable:TaskCombo( AttackTasks )
-- local AttackTasks = {}
--
-- for DetectedUnitID, DetectedUnit in pairs( self.DetectedUnits ) do
-- local DetectedUnit = DetectedUnit -- Wrapper.Unit#UNIT
-- self:T( DetectedUnit )
-- if DetectedUnit:IsAlive() then
-- if DetectedUnit:IsInZone( self.EngageZone ) then
-- self:E( {"Engaging ", DetectedUnit } )
-- AttackTasks[#AttackTasks+1] = Controllable:TaskAttackUnit( DetectedUnit )
-- end
-- else
-- self.DetectedUnits[DetectedUnit] = nil
-- end
-- end
--
-- EngageRoute[1].task = Controllable:TaskCombo( AttackTasks )
--- Now we're going to do something special, we're going to call a function from a waypoint action at the AIControllable...
self.Controllable:WayPointInitialize( EngageRoute )
@ -475,7 +526,11 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
self.Controllable:WayPointFunction( #EngageRoute, 1, "_NewEngageRoute" )
--- NOW ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1, 2 )
self.Controllable:WayPointExecute( 1 )
self:SetDetectionInterval( 10 )
self:SetDetectionActivated()
self:__Target( -10 ) -- Start Targetting
end
end
@ -501,7 +556,7 @@ end
-- @param #string To The To State string.
function AI_CAS_ZONE:onafterAccomplish( Controllable, From, Event, To )
self.Accomplished = true
self:SetDetectionOff()
self:SetDetectionDeactivated()
end
--- @param #AI_CAS_ZONE self

View File

@ -478,6 +478,7 @@ end
function AI_PATROL_ZONE:SetDetectionActivated()
self:F2()
self:ClearDetectedUnits()
self.DetectActivated = true
self:__Detect( -self.DetectInterval )
end
@ -488,6 +489,7 @@ end
function AI_PATROL_ZONE:SetDetectionDeactivated()
self:F2()
self:ClearDetectedUnits()
self.DetectActivated = false
end
@ -534,6 +536,12 @@ function AI_PATROL_ZONE:GetDetectedUnits()
return self.DetectedUnits
end
--- Clears the list of @{Unit#UNIT}s that were detected by the AI.
-- @param #AI_PATROL_ZONE self
function AI_PATROL_ZONE:ClearDetectedUnits()
self:F2()
self.DetectedUnits = {}
end
--- When the AI is out of fuel, it is required that a new AI is started, before the old AI can return to the home base.
-- Therefore, with a parameter and a calculation of the distance to the home base, the fuel treshold is calculated.
@ -628,11 +636,15 @@ function AI_PATROL_ZONE:onafterDetect( Controllable, From, Event, To )
if self.DetectionZone then
if TargetUnit:IsInZone( self.DetectionZone ) then
self:T( {"Detected ", TargetUnit } )
self.DetectedUnits[TargetUnit] = TargetUnit
if self.DetectedUnits[TargetUnit] == nil then
self.DetectedUnits[TargetUnit] = true
end
Detected = true
end
else
self.DetectedUnits[TargetUnit] = TargetUnit
if self.DetectedUnits[TargetUnit] == nil then
self.DetectedUnits[TargetUnit] = true
end
Detected = true
end
end

View File

@ -83,12 +83,13 @@ function DATABASE:New()
-- Inherits from BASE
local self = BASE:Inherit( self, BASE:New() )
self:SetEventPriority( 1 )
_EVENTDISPATCHER:OnBirth( self._EventOnBirth, self )
_EVENTDISPATCHER:OnDead( self._EventOnDeadOrCrash, self )
_EVENTDISPATCHER:OnCrash( self._EventOnDeadOrCrash, self )
-- Follow alive players and clients
_EVENTDISPATCHER:OnPlayerEnterUnit( self._EventOnPlayerEnterUnit, self )
_EVENTDISPATCHER:OnPlayerLeaveUnit( self._EventOnPlayerLeaveUnit, self )
@ -100,8 +101,6 @@ function DATABASE:New()
self:_RegisterPlayers()
self:_RegisterAirbases()
self:SetEventPriority( 1 )
return self
end

View File

@ -1,3 +1,12 @@
--- This module contains the **EVENT** class, which models the dispatching of DCS Events to subscribed MOOSE classes,
-- following a given priority.
--
-- ##
--
-- ![Banner Image](..\Presentations\FSM\Dia1.JPG)
--
-- ===
--
--- This module contains the EVENT class.
--
-- ===
@ -122,7 +131,6 @@ end
--- Initializes the Events structure for the event
-- @param #EVENT self
-- @param Dcs.DCSWorld#world.event EventID
-- @param #number EventPriority The priority of the EventClass.
-- @param Core.Base#BASE EventClass
-- @return #EVENT.Events
function EVENT:Init( EventID, EventClass )

View File

@ -1175,17 +1175,18 @@ end
--- (AIR) Attack the Unit.
-- @param #CONTROLLABLE self
-- @param Wrapper.Unit#UNIT AttackUnit The UNIT.
-- @param #number Priority All en-route tasks have the priority parameter. This is a number (less value - higher priority) that determines actions related to what task will be performed first.
-- @param #number WeaponType (optional) Bitmask of weapon types those allowed to use. If parameter is not defined that means no limits on weapon usage.
-- @param Wrapper.Unit#UNIT EngageUnit The UNIT.
-- @param #number Priority (optional) All en-route tasks have the priority parameter. This is a number (less value - higher priority) that determines actions related to what task will be performed first.
-- @param #boolean GroupAttack (optional) If true, all units in the group will attack the Unit when found.
-- @param Dcs.DCSTypes#AI.Task.WeaponExpend WeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param #number AttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo.
-- @param Dcs.DCSTypes#Azimuth Direction (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
-- @param #boolean AttackQtyLimit (optional) The flag determines how to interpret attackQty parameter. If the flag is true then attackQty is a limit on maximal attack quantity for "AttackControllable" and "AttackUnit" tasks. If the flag is false then attackQty is a desired attack quantity for "Bombing" and "BombingRunway" tasks.
-- @param Dcs.DCSTypes#Distance Altitude (optional) Desired altitude to perform the unit engagement.
-- @param #boolean Visible (optional) Unit must be visible.
-- @param #boolean ControllableAttack (optional) Flag indicates that the target must be engaged by all aircrafts of the controllable. Has effect only if the task is assigned to a controllable, not to a single aircraft.
-- @return Dcs.DCSTasking.Task#Task The DCS task structure.
function CONTROLLABLE:EnRouteTaskEngageUnit( AttackUnit, Priority, WeaponType, WeaponExpend, AttackQty, Direction, AttackQtyLimit, ControllableAttack )
self:F2( { self.ControllableName, AttackUnit, Priority, WeaponType, WeaponExpend, AttackQty, Direction, AttackQtyLimit, ControllableAttack } )
function CONTROLLABLE:EnRouteTaskEngageUnit( EngageUnit, Priority, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, Visible, ControllableAttack )
self:F2( { self.ControllableName, EngageUnit, Priority, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, Visible, ControllableAttack } )
-- EngageUnit = {
-- id = 'EngageUnit',
@ -1204,14 +1205,18 @@ function CONTROLLABLE:EnRouteTaskEngageUnit( AttackUnit, Priority, WeaponType, W
local DCSTask
DCSTask = { id = 'EngageUnit',
params = {
unitId = AttackUnit:GetID(),
weaponType = WeaponType,
expend = WeaponExpend,
attackQty = AttackQty,
unitId = EngageUnit:GetID(),
priority = Priority or 1,
groupAttack = GroupAttack or false,
visible = Visible or false,
expend = WeaponExpend or "Auto",
directionEnabled = Direction and true or false,
direction = Direction,
attackQtyLimit = AttackQtyLimit,
altitudeEnabled = Altitude and true or false,
altitude = Altitude,
attackQtyLimit = AttackQty and true or false,
attackQty = AttackQty,
controllableAttack = ControllableAttack,
priority = Priority,
},
},

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170205_1705' )
env.info( 'Moose Generation Timestamp: 20170206_1456' )
local base = _G
Include = {}
@ -4209,6 +4209,15 @@ end
--- This module contains the **EVENT** class, which models the dispatching of DCS Events to subscribed MOOSE classes,
-- following a given priority.
--
-- ##
--
-- ![Banner Image](..\Presentations\FSM\Dia1.JPG)
--
-- ===
--
--- This module contains the EVENT class.
--
-- ===
@ -4333,7 +4342,6 @@ end
--- Initializes the Events structure for the event
-- @param #EVENT self
-- @param Dcs.DCSWorld#world.event EventID
-- @param #number EventPriority The priority of the EventClass.
-- @param Core.Base#BASE EventClass
-- @return #EVENT.Events
function EVENT:Init( EventID, EventClass )
@ -6862,12 +6870,13 @@ function DATABASE:New()
-- Inherits from BASE
local self = BASE:Inherit( self, BASE:New() )
self:SetEventPriority( 1 )
_EVENTDISPATCHER:OnBirth( self._EventOnBirth, self )
_EVENTDISPATCHER:OnDead( self._EventOnDeadOrCrash, self )
_EVENTDISPATCHER:OnCrash( self._EventOnDeadOrCrash, self )
-- Follow alive players and clients
_EVENTDISPATCHER:OnPlayerEnterUnit( self._EventOnPlayerEnterUnit, self )
_EVENTDISPATCHER:OnPlayerLeaveUnit( self._EventOnPlayerLeaveUnit, self )
@ -6879,8 +6888,6 @@ function DATABASE:New()
self:_RegisterPlayers()
self:_RegisterAirbases()
self:SetEventPriority( 1 )
return self
end
@ -13818,17 +13825,18 @@ end
--- (AIR) Attack the Unit.
-- @param #CONTROLLABLE self
-- @param Wrapper.Unit#UNIT AttackUnit The UNIT.
-- @param #number Priority All en-route tasks have the priority parameter. This is a number (less value - higher priority) that determines actions related to what task will be performed first.
-- @param #number WeaponType (optional) Bitmask of weapon types those allowed to use. If parameter is not defined that means no limits on weapon usage.
-- @param Wrapper.Unit#UNIT EngageUnit The UNIT.
-- @param #number Priority (optional) All en-route tasks have the priority parameter. This is a number (less value - higher priority) that determines actions related to what task will be performed first.
-- @param #boolean GroupAttack (optional) If true, all units in the group will attack the Unit when found.
-- @param Dcs.DCSTypes#AI.Task.WeaponExpend WeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param #number AttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo.
-- @param Dcs.DCSTypes#Azimuth Direction (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
-- @param #boolean AttackQtyLimit (optional) The flag determines how to interpret attackQty parameter. If the flag is true then attackQty is a limit on maximal attack quantity for "AttackControllable" and "AttackUnit" tasks. If the flag is false then attackQty is a desired attack quantity for "Bombing" and "BombingRunway" tasks.
-- @param Dcs.DCSTypes#Distance Altitude (optional) Desired altitude to perform the unit engagement.
-- @param #boolean Visible (optional) Unit must be visible.
-- @param #boolean ControllableAttack (optional) Flag indicates that the target must be engaged by all aircrafts of the controllable. Has effect only if the task is assigned to a controllable, not to a single aircraft.
-- @return Dcs.DCSTasking.Task#Task The DCS task structure.
function CONTROLLABLE:EnRouteTaskEngageUnit( AttackUnit, Priority, WeaponType, WeaponExpend, AttackQty, Direction, AttackQtyLimit, ControllableAttack )
self:F2( { self.ControllableName, AttackUnit, Priority, WeaponType, WeaponExpend, AttackQty, Direction, AttackQtyLimit, ControllableAttack } )
function CONTROLLABLE:EnRouteTaskEngageUnit( EngageUnit, Priority, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, Visible, ControllableAttack )
self:F2( { self.ControllableName, EngageUnit, Priority, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, Visible, ControllableAttack } )
-- EngageUnit = {
-- id = 'EngageUnit',
@ -13847,14 +13855,18 @@ function CONTROLLABLE:EnRouteTaskEngageUnit( AttackUnit, Priority, WeaponType, W
local DCSTask
DCSTask = { id = 'EngageUnit',
params = {
unitId = AttackUnit:GetID(),
weaponType = WeaponType,
expend = WeaponExpend,
attackQty = AttackQty,
unitId = EngageUnit:GetID(),
priority = Priority or 1,
groupAttack = GroupAttack or false,
visible = Visible or false,
expend = WeaponExpend or "Auto",
directionEnabled = Direction and true or false,
direction = Direction,
attackQtyLimit = AttackQtyLimit,
altitudeEnabled = Altitude and true or false,
altitude = Altitude,
attackQtyLimit = AttackQty and true or false,
attackQty = AttackQty,
controllableAttack = ControllableAttack,
priority = Priority,
},
},
@ -25300,6 +25312,7 @@ end
function AI_PATROL_ZONE:SetDetectionActivated()
self:F2()
self:ClearDetectedUnits()
self.DetectActivated = true
self:__Detect( -self.DetectInterval )
end
@ -25310,6 +25323,7 @@ end
function AI_PATROL_ZONE:SetDetectionDeactivated()
self:F2()
self:ClearDetectedUnits()
self.DetectActivated = false
end
@ -25356,6 +25370,12 @@ function AI_PATROL_ZONE:GetDetectedUnits()
return self.DetectedUnits
end
--- Clears the list of @{Unit#UNIT}s that were detected by the AI.
-- @param #AI_PATROL_ZONE self
function AI_PATROL_ZONE:ClearDetectedUnits()
self:F2()
self.DetectedUnits = {}
end
--- When the AI is out of fuel, it is required that a new AI is started, before the old AI can return to the home base.
-- Therefore, with a parameter and a calculation of the distance to the home base, the fuel treshold is calculated.
@ -25450,11 +25470,15 @@ function AI_PATROL_ZONE:onafterDetect( Controllable, From, Event, To )
if self.DetectionZone then
if TargetUnit:IsInZone( self.DetectionZone ) then
self:T( {"Detected ", TargetUnit } )
self.DetectedUnits[TargetUnit] = TargetUnit
if self.DetectedUnits[TargetUnit] == nil then
self.DetectedUnits[TargetUnit] = true
end
Detected = true
end
else
self.DetectedUnits[TargetUnit] = TargetUnit
if self.DetectedUnits[TargetUnit] == nil then
self.DetectedUnits[TargetUnit] = true
end
Detected = true
end
end
@ -25846,7 +25870,7 @@ function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude
self.Accomplished = false
self:SetDetectionZone( self.EngageZone )
self:AddTransition( { "Patrolling", "Engaging" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnBefore Transition Handler for Event Engage.
@ -25856,6 +25880,12 @@ function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
-- @param #number EngageSpeed (optional) The speed the Group will hold when engaging to the target zone.
-- @param Dcs.DCSTypes#AI.Task.WeaponExpend EngageWeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param Dcs.DCSTypes#Distance EngageAltitude (optional) Desired altitude to perform the unit engagement.
-- @param #number EngageAttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo.
-- @param Dcs.DCSTypes#Azimuth EngageDirection (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
-- @return #boolean Return false to cancel Transition.
--- OnAfter Transition Handler for Event Engage.
@ -25865,6 +25895,11 @@ function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
-- @param #number EngageSpeed (optional) The speed the Group will hold when engaging to the target zone.
-- @param Dcs.DCSTypes#AI.Task.WeaponExpend EngageWeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param Dcs.DCSTypes#Distance EngageAltitude (optional) Desired altitude to perform the unit engagement.
-- @param #number EngageAttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo.
-- @param Dcs.DCSTypes#Azimuth EngageDirection (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
--- Synchronous Event Trigger for Event Engage.
-- @function [parent=#AI_CAS_ZONE] Engage
@ -25892,6 +25927,8 @@ function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude
-- @param #string Event The Event string.
-- @param #string To The To State string.
self:AddTransition( "Engaging", "Target", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnBefore Transition Handler for Event Fired.
@ -26037,6 +26074,7 @@ function AI_CAS_ZONE:onafterStart( Controllable, From, Event, To )
self:GetParent(self).onafterStart( self, Controllable, From, Event, To )
self:EventOnDead( self.OnDead )
self:SetDetectionDeactivated() -- When not engaging, set the detection off.
end
--- @param Wrapper.Controllable#CONTROLLABLE AIControllable
@ -26059,15 +26097,62 @@ function AI_CAS_ZONE:onbeforeEngage( Controllable, From, Event, To )
end
end
--- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
function AI_CAS_ZONE:onafterTarget( Controllable, From, Event, To )
self:E("onafterTarget")
if Controllable:IsAlive() then
local AttackTasks = {}
for DetectedUnit, Detected in pairs( self.DetectedUnits ) do
local DetectedUnit = DetectedUnit -- Wrapper.Unit#UNIT
if DetectedUnit:IsAlive() then
if DetectedUnit:IsInZone( self.EngageZone ) then
if Detected == true then
self:E( {"Target: ", DetectedUnit } )
self.DetectedUnits[DetectedUnit] = false
local AttackTask = Controllable:EnRouteTaskEngageUnit( DetectedUnit, 1, true, self.EngageWeaponExpend, self.EngageAttackQty, self.EngageDirection, self.EngageAltitude, nil )
self.Controllable:PushTask( AttackTask, 1 )
end
end
else
self.DetectedUnits[DetectedUnit] = nil
end
end
self:__Target( -10 )
end
end
--- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
-- @param #number EngageSpeed (optional) The speed the Group will hold when engaging to the target zone.
-- @param Dcs.DCSTypes#AI.Task.WeaponExpend EngageWeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param Dcs.DCSTypes#Distance EngageAltitude (optional) Desired altitude to perform the unit engagement.
-- @param #number EngageAttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo.
-- @param Dcs.DCSTypes#Azimuth EngageDirection (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To, EngageSpeed, EngageAltitude, EngageWeaponExpend, EngageAttackQty, EngageDirection )
self:E("onafterEngage")
self.EngageSpeed = EngageSpeed or 400
self.EngageAltitude = EngageAltitude or 2000
self.EngageWeaponExpend = EngageWeaponExpend
self.EngageAttackQty = EngageAttackQty
self.EngageDirection = EngageDirection
if Controllable:IsAlive() then
local EngageRoute = {}
@ -26082,7 +26167,7 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
self.PatrolAltType,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToEngageZoneSpeed,
self.EngageSpeed,
true
)
@ -26095,20 +26180,15 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
local ToEngageZoneVec2 = self.EngageZone:GetRandomVec2()
self:T2( ToEngageZoneVec2 )
-- Define Speed and Altitude.
local ToEngageZoneAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
local ToEngageZoneSpeed = self.PatrolMaxSpeed
self:T2( ToEngageZoneSpeed )
-- Obtain a 3D @{Point} from the 2D point + altitude.
local ToEngageZonePointVec3 = POINT_VEC3:New( ToEngageZoneVec2.x, ToEngageZoneAltitude, ToEngageZoneVec2.y )
local ToEngageZonePointVec3 = POINT_VEC3:New( ToEngageZoneVec2.x, self.EngageAltitude, ToEngageZoneVec2.y )
-- Create a route point of type air.
local ToEngageZoneRoutePoint = ToEngageZonePointVec3:RoutePointAir(
self.PatrolAltType,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToEngageZoneSpeed,
self.EngageSpeed,
true
)
@ -26122,20 +26202,15 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
local ToTargetVec2 = self.EngageZone:GetRandomVec2()
self:T2( ToTargetVec2 )
--- Define Speed and Altitude.
local ToTargetAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
local ToTargetSpeed = math.random( self.PatrolMinSpeed, self.PatrolMaxSpeed )
self:T2( { self.PatrolMinSpeed, self.PatrolMaxSpeed, ToTargetSpeed } )
--- Obtain a 3D @{Point} from the 2D point + altitude.
local ToTargetPointVec3 = POINT_VEC3:New( ToTargetVec2.x, ToTargetAltitude, ToTargetVec2.y )
local ToTargetPointVec3 = POINT_VEC3:New( ToTargetVec2.x, self.EngageAltitude, ToTargetVec2.y )
--- Create a route point of type air.
local ToTargetRoutePoint = ToTargetPointVec3:RoutePointAir(
self.PatrolAltType,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed,
self.EngageSpeed,
true
)
@ -26145,24 +26220,24 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
Controllable:OptionROEOpenFire()
Controllable:OptionROTPassiveDefense()
Controllable:OptionROTVertical()
local AttackTasks = {}
for DetectedUnitID, DetectedUnit in pairs( self.DetectedUnits ) do
local DetectedUnit = DetectedUnit -- Wrapper.Unit#UNIT
self:T( DetectedUnit )
if DetectedUnit:IsAlive() then
if DetectedUnit:IsInZone( self.EngageZone ) then
self:E( {"Engaging ", DetectedUnit } )
AttackTasks[#AttackTasks+1] = Controllable:TaskAttackUnit( DetectedUnit )
end
else
self.DetectedUnits[DetectedUnit] = nil
end
end
EngageRoute[1].task = Controllable:TaskCombo( AttackTasks )
-- local AttackTasks = {}
--
-- for DetectedUnitID, DetectedUnit in pairs( self.DetectedUnits ) do
-- local DetectedUnit = DetectedUnit -- Wrapper.Unit#UNIT
-- self:T( DetectedUnit )
-- if DetectedUnit:IsAlive() then
-- if DetectedUnit:IsInZone( self.EngageZone ) then
-- self:E( {"Engaging ", DetectedUnit } )
-- AttackTasks[#AttackTasks+1] = Controllable:TaskAttackUnit( DetectedUnit )
-- end
-- else
-- self.DetectedUnits[DetectedUnit] = nil
-- end
-- end
--
-- EngageRoute[1].task = Controllable:TaskCombo( AttackTasks )
--- Now we're going to do something special, we're going to call a function from a waypoint action at the AIControllable...
self.Controllable:WayPointInitialize( EngageRoute )
@ -26173,7 +26248,11 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
self.Controllable:WayPointFunction( #EngageRoute, 1, "_NewEngageRoute" )
--- NOW ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1, 2 )
self.Controllable:WayPointExecute( 1 )
self:SetDetectionInterval( 10 )
self:SetDetectionActivated()
self:__Target( -10 ) -- Start Targetting
end
end
@ -26199,7 +26278,7 @@ end
-- @param #string To The To State string.
function AI_CAS_ZONE:onafterAccomplish( Controllable, From, Event, To )
self.Accomplished = true
self:SetDetectionOff()
self:SetDetectionDeactivated()
end
--- @param #AI_CAS_ZONE self

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170205_1705' )
env.info( 'Moose Generation Timestamp: 20170206_1456' )
local base = _G
Include = {}
@ -4209,6 +4209,15 @@ end
--- This module contains the **EVENT** class, which models the dispatching of DCS Events to subscribed MOOSE classes,
-- following a given priority.
--
-- ##
--
-- ![Banner Image](..\Presentations\FSM\Dia1.JPG)
--
-- ===
--
--- This module contains the EVENT class.
--
-- ===
@ -4333,7 +4342,6 @@ end
--- Initializes the Events structure for the event
-- @param #EVENT self
-- @param Dcs.DCSWorld#world.event EventID
-- @param #number EventPriority The priority of the EventClass.
-- @param Core.Base#BASE EventClass
-- @return #EVENT.Events
function EVENT:Init( EventID, EventClass )
@ -6862,12 +6870,13 @@ function DATABASE:New()
-- Inherits from BASE
local self = BASE:Inherit( self, BASE:New() )
self:SetEventPriority( 1 )
_EVENTDISPATCHER:OnBirth( self._EventOnBirth, self )
_EVENTDISPATCHER:OnDead( self._EventOnDeadOrCrash, self )
_EVENTDISPATCHER:OnCrash( self._EventOnDeadOrCrash, self )
-- Follow alive players and clients
_EVENTDISPATCHER:OnPlayerEnterUnit( self._EventOnPlayerEnterUnit, self )
_EVENTDISPATCHER:OnPlayerLeaveUnit( self._EventOnPlayerLeaveUnit, self )
@ -6879,8 +6888,6 @@ function DATABASE:New()
self:_RegisterPlayers()
self:_RegisterAirbases()
self:SetEventPriority( 1 )
return self
end
@ -13818,17 +13825,18 @@ end
--- (AIR) Attack the Unit.
-- @param #CONTROLLABLE self
-- @param Wrapper.Unit#UNIT AttackUnit The UNIT.
-- @param #number Priority All en-route tasks have the priority parameter. This is a number (less value - higher priority) that determines actions related to what task will be performed first.
-- @param #number WeaponType (optional) Bitmask of weapon types those allowed to use. If parameter is not defined that means no limits on weapon usage.
-- @param Wrapper.Unit#UNIT EngageUnit The UNIT.
-- @param #number Priority (optional) All en-route tasks have the priority parameter. This is a number (less value - higher priority) that determines actions related to what task will be performed first.
-- @param #boolean GroupAttack (optional) If true, all units in the group will attack the Unit when found.
-- @param Dcs.DCSTypes#AI.Task.WeaponExpend WeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param #number AttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo.
-- @param Dcs.DCSTypes#Azimuth Direction (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
-- @param #boolean AttackQtyLimit (optional) The flag determines how to interpret attackQty parameter. If the flag is true then attackQty is a limit on maximal attack quantity for "AttackControllable" and "AttackUnit" tasks. If the flag is false then attackQty is a desired attack quantity for "Bombing" and "BombingRunway" tasks.
-- @param Dcs.DCSTypes#Distance Altitude (optional) Desired altitude to perform the unit engagement.
-- @param #boolean Visible (optional) Unit must be visible.
-- @param #boolean ControllableAttack (optional) Flag indicates that the target must be engaged by all aircrafts of the controllable. Has effect only if the task is assigned to a controllable, not to a single aircraft.
-- @return Dcs.DCSTasking.Task#Task The DCS task structure.
function CONTROLLABLE:EnRouteTaskEngageUnit( AttackUnit, Priority, WeaponType, WeaponExpend, AttackQty, Direction, AttackQtyLimit, ControllableAttack )
self:F2( { self.ControllableName, AttackUnit, Priority, WeaponType, WeaponExpend, AttackQty, Direction, AttackQtyLimit, ControllableAttack } )
function CONTROLLABLE:EnRouteTaskEngageUnit( EngageUnit, Priority, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, Visible, ControllableAttack )
self:F2( { self.ControllableName, EngageUnit, Priority, GroupAttack, WeaponExpend, AttackQty, Direction, Altitude, Visible, ControllableAttack } )
-- EngageUnit = {
-- id = 'EngageUnit',
@ -13847,14 +13855,18 @@ function CONTROLLABLE:EnRouteTaskEngageUnit( AttackUnit, Priority, WeaponType, W
local DCSTask
DCSTask = { id = 'EngageUnit',
params = {
unitId = AttackUnit:GetID(),
weaponType = WeaponType,
expend = WeaponExpend,
attackQty = AttackQty,
unitId = EngageUnit:GetID(),
priority = Priority or 1,
groupAttack = GroupAttack or false,
visible = Visible or false,
expend = WeaponExpend or "Auto",
directionEnabled = Direction and true or false,
direction = Direction,
attackQtyLimit = AttackQtyLimit,
altitudeEnabled = Altitude and true or false,
altitude = Altitude,
attackQtyLimit = AttackQty and true or false,
attackQty = AttackQty,
controllableAttack = ControllableAttack,
priority = Priority,
},
},
@ -25300,6 +25312,7 @@ end
function AI_PATROL_ZONE:SetDetectionActivated()
self:F2()
self:ClearDetectedUnits()
self.DetectActivated = true
self:__Detect( -self.DetectInterval )
end
@ -25310,6 +25323,7 @@ end
function AI_PATROL_ZONE:SetDetectionDeactivated()
self:F2()
self:ClearDetectedUnits()
self.DetectActivated = false
end
@ -25356,6 +25370,12 @@ function AI_PATROL_ZONE:GetDetectedUnits()
return self.DetectedUnits
end
--- Clears the list of @{Unit#UNIT}s that were detected by the AI.
-- @param #AI_PATROL_ZONE self
function AI_PATROL_ZONE:ClearDetectedUnits()
self:F2()
self.DetectedUnits = {}
end
--- When the AI is out of fuel, it is required that a new AI is started, before the old AI can return to the home base.
-- Therefore, with a parameter and a calculation of the distance to the home base, the fuel treshold is calculated.
@ -25450,11 +25470,15 @@ function AI_PATROL_ZONE:onafterDetect( Controllable, From, Event, To )
if self.DetectionZone then
if TargetUnit:IsInZone( self.DetectionZone ) then
self:T( {"Detected ", TargetUnit } )
self.DetectedUnits[TargetUnit] = TargetUnit
if self.DetectedUnits[TargetUnit] == nil then
self.DetectedUnits[TargetUnit] = true
end
Detected = true
end
else
self.DetectedUnits[TargetUnit] = TargetUnit
if self.DetectedUnits[TargetUnit] == nil then
self.DetectedUnits[TargetUnit] = true
end
Detected = true
end
end
@ -25846,7 +25870,7 @@ function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude
self.Accomplished = false
self:SetDetectionZone( self.EngageZone )
self:AddTransition( { "Patrolling", "Engaging" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnBefore Transition Handler for Event Engage.
@ -25856,6 +25880,12 @@ function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
-- @param #number EngageSpeed (optional) The speed the Group will hold when engaging to the target zone.
-- @param Dcs.DCSTypes#AI.Task.WeaponExpend EngageWeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param Dcs.DCSTypes#Distance EngageAltitude (optional) Desired altitude to perform the unit engagement.
-- @param #number EngageAttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo.
-- @param Dcs.DCSTypes#Azimuth EngageDirection (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
-- @return #boolean Return false to cancel Transition.
--- OnAfter Transition Handler for Event Engage.
@ -25865,6 +25895,11 @@ function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
-- @param #number EngageSpeed (optional) The speed the Group will hold when engaging to the target zone.
-- @param Dcs.DCSTypes#AI.Task.WeaponExpend EngageWeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param Dcs.DCSTypes#Distance EngageAltitude (optional) Desired altitude to perform the unit engagement.
-- @param #number EngageAttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo.
-- @param Dcs.DCSTypes#Azimuth EngageDirection (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
--- Synchronous Event Trigger for Event Engage.
-- @function [parent=#AI_CAS_ZONE] Engage
@ -25892,6 +25927,8 @@ function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude
-- @param #string Event The Event string.
-- @param #string To The To State string.
self:AddTransition( "Engaging", "Target", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnBefore Transition Handler for Event Fired.
@ -26037,6 +26074,7 @@ function AI_CAS_ZONE:onafterStart( Controllable, From, Event, To )
self:GetParent(self).onafterStart( self, Controllable, From, Event, To )
self:EventOnDead( self.OnDead )
self:SetDetectionDeactivated() -- When not engaging, set the detection off.
end
--- @param Wrapper.Controllable#CONTROLLABLE AIControllable
@ -26059,15 +26097,62 @@ function AI_CAS_ZONE:onbeforeEngage( Controllable, From, Event, To )
end
end
--- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
function AI_CAS_ZONE:onafterTarget( Controllable, From, Event, To )
self:E("onafterTarget")
if Controllable:IsAlive() then
local AttackTasks = {}
for DetectedUnit, Detected in pairs( self.DetectedUnits ) do
local DetectedUnit = DetectedUnit -- Wrapper.Unit#UNIT
if DetectedUnit:IsAlive() then
if DetectedUnit:IsInZone( self.EngageZone ) then
if Detected == true then
self:E( {"Target: ", DetectedUnit } )
self.DetectedUnits[DetectedUnit] = false
local AttackTask = Controllable:EnRouteTaskEngageUnit( DetectedUnit, 1, true, self.EngageWeaponExpend, self.EngageAttackQty, self.EngageDirection, self.EngageAltitude, nil )
self.Controllable:PushTask( AttackTask, 1 )
end
end
else
self.DetectedUnits[DetectedUnit] = nil
end
end
self:__Target( -10 )
end
end
--- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
-- @param #number EngageSpeed (optional) The speed the Group will hold when engaging to the target zone.
-- @param Dcs.DCSTypes#AI.Task.WeaponExpend EngageWeaponExpend (optional) Determines how much weapon will be released at each attack. If parameter is not defined the unit / controllable will choose expend on its own discretion.
-- @param Dcs.DCSTypes#Distance EngageAltitude (optional) Desired altitude to perform the unit engagement.
-- @param #number EngageAttackQty (optional) This parameter limits maximal quantity of attack. The aicraft/controllable will not make more attack than allowed even if the target controllable not destroyed and the aicraft/controllable still have ammo. If not defined the aircraft/controllable will attack target until it will be destroyed or until the aircraft/controllable will run out of ammo.
-- @param Dcs.DCSTypes#Azimuth EngageDirection (optional) Desired ingress direction from the target to the attacking aircraft. Controllable/aircraft will make its attacks from the direction. Of course if there is no way to attack from the direction due the terrain controllable/aircraft will choose another direction.
function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To, EngageSpeed, EngageAltitude, EngageWeaponExpend, EngageAttackQty, EngageDirection )
self:E("onafterEngage")
self.EngageSpeed = EngageSpeed or 400
self.EngageAltitude = EngageAltitude or 2000
self.EngageWeaponExpend = EngageWeaponExpend
self.EngageAttackQty = EngageAttackQty
self.EngageDirection = EngageDirection
if Controllable:IsAlive() then
local EngageRoute = {}
@ -26082,7 +26167,7 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
self.PatrolAltType,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToEngageZoneSpeed,
self.EngageSpeed,
true
)
@ -26095,20 +26180,15 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
local ToEngageZoneVec2 = self.EngageZone:GetRandomVec2()
self:T2( ToEngageZoneVec2 )
-- Define Speed and Altitude.
local ToEngageZoneAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
local ToEngageZoneSpeed = self.PatrolMaxSpeed
self:T2( ToEngageZoneSpeed )
-- Obtain a 3D @{Point} from the 2D point + altitude.
local ToEngageZonePointVec3 = POINT_VEC3:New( ToEngageZoneVec2.x, ToEngageZoneAltitude, ToEngageZoneVec2.y )
local ToEngageZonePointVec3 = POINT_VEC3:New( ToEngageZoneVec2.x, self.EngageAltitude, ToEngageZoneVec2.y )
-- Create a route point of type air.
local ToEngageZoneRoutePoint = ToEngageZonePointVec3:RoutePointAir(
self.PatrolAltType,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToEngageZoneSpeed,
self.EngageSpeed,
true
)
@ -26122,20 +26202,15 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
local ToTargetVec2 = self.EngageZone:GetRandomVec2()
self:T2( ToTargetVec2 )
--- Define Speed and Altitude.
local ToTargetAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
local ToTargetSpeed = math.random( self.PatrolMinSpeed, self.PatrolMaxSpeed )
self:T2( { self.PatrolMinSpeed, self.PatrolMaxSpeed, ToTargetSpeed } )
--- Obtain a 3D @{Point} from the 2D point + altitude.
local ToTargetPointVec3 = POINT_VEC3:New( ToTargetVec2.x, ToTargetAltitude, ToTargetVec2.y )
local ToTargetPointVec3 = POINT_VEC3:New( ToTargetVec2.x, self.EngageAltitude, ToTargetVec2.y )
--- Create a route point of type air.
local ToTargetRoutePoint = ToTargetPointVec3:RoutePointAir(
self.PatrolAltType,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed,
self.EngageSpeed,
true
)
@ -26145,24 +26220,24 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
Controllable:OptionROEOpenFire()
Controllable:OptionROTPassiveDefense()
Controllable:OptionROTVertical()
local AttackTasks = {}
for DetectedUnitID, DetectedUnit in pairs( self.DetectedUnits ) do
local DetectedUnit = DetectedUnit -- Wrapper.Unit#UNIT
self:T( DetectedUnit )
if DetectedUnit:IsAlive() then
if DetectedUnit:IsInZone( self.EngageZone ) then
self:E( {"Engaging ", DetectedUnit } )
AttackTasks[#AttackTasks+1] = Controllable:TaskAttackUnit( DetectedUnit )
end
else
self.DetectedUnits[DetectedUnit] = nil
end
end
EngageRoute[1].task = Controllable:TaskCombo( AttackTasks )
-- local AttackTasks = {}
--
-- for DetectedUnitID, DetectedUnit in pairs( self.DetectedUnits ) do
-- local DetectedUnit = DetectedUnit -- Wrapper.Unit#UNIT
-- self:T( DetectedUnit )
-- if DetectedUnit:IsAlive() then
-- if DetectedUnit:IsInZone( self.EngageZone ) then
-- self:E( {"Engaging ", DetectedUnit } )
-- AttackTasks[#AttackTasks+1] = Controllable:TaskAttackUnit( DetectedUnit )
-- end
-- else
-- self.DetectedUnits[DetectedUnit] = nil
-- end
-- end
--
-- EngageRoute[1].task = Controllable:TaskCombo( AttackTasks )
--- Now we're going to do something special, we're going to call a function from a waypoint action at the AIControllable...
self.Controllable:WayPointInitialize( EngageRoute )
@ -26173,7 +26248,11 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
self.Controllable:WayPointFunction( #EngageRoute, 1, "_NewEngageRoute" )
--- NOW ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1, 2 )
self.Controllable:WayPointExecute( 1 )
self:SetDetectionInterval( 10 )
self:SetDetectionActivated()
self:__Target( -10 ) -- Start Targetting
end
end
@ -26199,7 +26278,7 @@ end
-- @param #string To The To State string.
function AI_CAS_ZONE:onafterAccomplish( Controllable, From, Event, To )
self.Accomplished = true
self:SetDetectionOff()
self:SetDetectionDeactivated()
end
--- @param #AI_CAS_ZONE self

View File

@ -1,11 +1,26 @@
-- Name: CAS in a ZONE
---
-- Name: CAS-001 - CAS in a Zone by Airplane Group
-- Author: FlightControl
-- Date Created: 13 January 2017
--
-- # Situation:
--
-- A group of 4 Su-25T at patrolling north of an engage zone for 10 minutes.
-- After 10 minutes, the command center orders the Su-25T to engage the zone and execute a CAS.
--
-- # Test cases:
--
-- 1. Observe that the Su-25T is patrolling in the patrol zone, until the engage command is given.
-- 2. The Su-25T are not detecting any target during the patrol.
-- 3. When the Su-25T is commanded to engage, the group will fly to the engage zone.
-- 4. Detection is activated and detected targets within the engage zone are assigned for CAS.
-- 5. Observe the Su-25T eliminating the targets.
-- 6. Observe the Su-25T defenses.
-- 7. When all targets within the engage zone are destroyed, the Su-25T CAS task is set to Accomplished.
-- 8. The Su-25T will return to base.
-- Create a local variable (in this case called CASEngagementZone) and
-- using the ZONE function find the pre-defined zone called "Engagement Zone"
-- currently on the map and assign it to this variable
@ -42,18 +57,18 @@ AICasZone:__Engage( 600 )
-- When the trigger completed has been fired, the Plane will go back to the Patrol Zone.
Check, CheckScheduleID = SCHEDULER:New(nil,
function()
BASE:E( { "In Scheduler: ", Targets:GetSize() } )
if Targets:IsAlive() and Targets:GetSize() > 5 then
BASE:E("Still alive")
BASE:E( "Test Mission: " .. Targets:GetSize() .. " targets left to be destroyed.")
else
BASE:E("Destroyed")
BASE:E( "Test Mission: The required targets are destroyed." )
AICasZone:__Accomplish( 1 ) -- Now they should fly back to teh patrolzone and patrol.
Check:Stop(CheckScheduleID)
end
end, {}, 20, 60, 0.2 )
-- When the targets in the zone are destroyed, (see scheduled function), the planes will return home ...
function AICasZone:OnAfterAccomplish( Controllable, From, Event, To )
BASE:E( "Test Mission: Sending the Su-25T back to base." )
Check:Stop( CheckScheduleID )
AICasZone:__RTB( 1 )
end

View File

@ -0,0 +1,75 @@
---
-- Name: CAS-002 - CAS in a Zone by Airplane Group - Engage with Speed
-- Author: FlightControl
-- Date Created: 06 February 2017
--
-- # Situation:
--
-- A group of 4 Su-25T at patrolling north of an engage zone for 1 minute.
-- After 1 minute, the command center orders the Su-25T to engage the zone and execute a CAS.
--
-- # Test cases:
--
-- 1. Observe that the Su-25T is patrolling in the patrol zone, until the engage command is given.
-- 2. The Su-25T are not detecting any target during the patrol.
-- 3. When the Su-25T is commanded to engage, the group will fly to the engage zone.
-- 3.1. The approach speed to the engage zone is set to 400 km/h.
-- 4. Detection is activated and detected targets within the engage zone are assigned for CAS.
-- 5. Observe the Su-25T eliminating the targets.
-- 6. Observe the Su-25T defenses.
-- 7. When all targets within the engage zone are destroyed, the Su-25T CAS task is set to Accomplished.
-- 8. The Su-25T will return to base.
-- Create a local variable (in this case called CASEngagementZone) and
-- using the ZONE function find the pre-defined zone called "Engagement Zone"
-- currently on the map and assign it to this variable
local CASEngagementZone = ZONE:New( "Engagement Zone" )
-- Create a local variable (in this case called CASPlane) and
-- using the GROUP function find the aircraft group called "Plane" and assign to this variable
local CASPlane = GROUP:FindByName( "Plane" )
-- Create a local Variable (in this cased called PatrolZone and
-- using the ZONE function find the pre-defined zone called "Patrol Zone" and assign it to this variable
local PatrolZone = ZONE:New( "Patrol Zone" )
-- Create and object (in this case called AICasZone) and
-- using the functions AI_CAS_ZONE assign the parameters that define this object
-- (in this case PatrolZone, 500, 1000, 500, 600, CASEngagementZone)
local AICasZone = AI_CAS_ZONE:New( PatrolZone, 500, 1000, 500, 600, CASEngagementZone )
-- Create an object (in this case called Targets) and
-- using the GROUP function find the group labeled "Targets" and assign it to this object
local Targets = GROUP:FindByName("Targets")
-- Tell the program to use the object (in this case called CASPlane) as the group to use in the CAS function
AICasZone:SetControllable( CASPlane )
-- Tell the group CASPlane to start the mission in 1 second.
AICasZone:__Start( 1 ) -- They should statup, and start patrolling in the PatrolZone.
-- After 10 minutes, tell the group CASPlane to engage the targets located in the engagement zone called CASEngagement Zone. (600 is 600 seconds)
AICasZone:__Engage( 60, 400 ) -- Engage after one minute with a speed of 400 km/h.
-- Check every 60 seconds whether the Targets have been eliminated.
-- When the trigger completed has been fired, the Plane will go back to the Patrol Zone.
Check, CheckScheduleID = SCHEDULER:New(nil,
function()
if Targets:IsAlive() and Targets:GetSize() > 5 then
BASE:E( "Test Mission: " .. Targets:GetSize() .. " targets left to be destroyed.")
else
BASE:E( "Test Mission: The required targets are destroyed." )
AICasZone:__Accomplish( 1 ) -- Now they should fly back to teh patrolzone and patrol.
end
end, {}, 20, 60, 0.2 )
-- When the targets in the zone are destroyed, (see scheduled function), the planes will return home ...
function AICasZone:OnAfterAccomplish( Controllable, From, Event, To )
BASE:E( "Test Mission: Sending the Su-25T back to base." )
Check:Stop( CheckScheduleID )
AICasZone:__RTB( 1 )
end

View File

@ -0,0 +1,76 @@
---
-- Name: CAS-003 - CAS in a Zone by Airplane Group - Engage with Speed and Altitude
-- Author: FlightControl
-- Date Created: 6 February 2017
--
-- # Situation:
--
-- A group of 4 Su-25T at patrolling north of an engage zone for 1 minute.
-- After 1 minute, the command center orders the Su-25T to engage the zone and execute a CAS.
--
-- # Test cases:
--
-- 1. Observe that the Su-25T is patrolling in the patrol zone, until the engage command is given.
-- 2. The Su-25T are not detecting any target during the patrol.
-- 3. When the Su-25T is commanded to engage, the group will fly to the engage zone
-- 3.1. The approach speed to the engage zone is set to 400 km/h.
-- 3.2. The altitude to the engage zone and CAS execution is set to 500 meters.
-- 4. Detection is activated and detected targets within the engage zone are assigned for CAS.
-- 5. Observe the Su-25T eliminating the targets.
-- 6. Observe the Su-25T defenses.
-- 7. When all targets within the engage zone are destroyed, the Su-25T CAS task is set to Accomplished.
-- 8. The Su-25T will return to base.
-- Create a local variable (in this case called CASEngagementZone) and
-- using the ZONE function find the pre-defined zone called "Engagement Zone"
-- currently on the map and assign it to this variable
local CASEngagementZone = ZONE:New( "Engagement Zone" )
-- Create a local variable (in this case called CASPlane) and
-- using the GROUP function find the aircraft group called "Plane" and assign to this variable
local CASPlane = GROUP:FindByName( "Plane" )
-- Create a local Variable (in this cased called PatrolZone and
-- using the ZONE function find the pre-defined zone called "Patrol Zone" and assign it to this variable
local PatrolZone = ZONE:New( "Patrol Zone" )
-- Create and object (in this case called AICasZone) and
-- using the functions AI_CAS_ZONE assign the parameters that define this object
-- (in this case PatrolZone, 500, 1000, 500, 600, CASEngagementZone)
local AICasZone = AI_CAS_ZONE:New( PatrolZone, 500, 1000, 500, 600, CASEngagementZone )
-- Create an object (in this case called Targets) and
-- using the GROUP function find the group labeled "Targets" and assign it to this object
local Targets = GROUP:FindByName("Targets")
-- Tell the program to use the object (in this case called CASPlane) as the group to use in the CAS function
AICasZone:SetControllable( CASPlane )
-- Tell the group CASPlane to start the mission in 1 second.
AICasZone:__Start( 1 ) -- They should statup, and start patrolling in the PatrolZone.
-- After 10 minutes, tell the group CASPlane to engage the targets located in the engagement zone called CASEngagement Zone. (600 is 600 seconds)
AICasZone:__Engage( 60, 400, 500 ) -- Engage after one minute with a speed of 400 km/h and an altitude of 500 meters.
-- Check every 60 seconds whether the Targets have been eliminated.
-- When the trigger completed has been fired, the Plane will go back to the Patrol Zone.
Check, CheckScheduleID = SCHEDULER:New(nil,
function()
if Targets:IsAlive() and Targets:GetSize() > 5 then
BASE:E( "Test Mission: " .. Targets:GetSize() .. " targets left to be destroyed.")
else
BASE:E( "Test Mission: The required targets are destroyed." )
AICasZone:__Accomplish( 1 ) -- Now they should fly back to teh patrolzone and patrol.
end
end, {}, 20, 60, 0.2 )
-- When the targets in the zone are destroyed, (see scheduled function), the planes will return home ...
function AICasZone:OnAfterAccomplish( Controllable, From, Event, To )
BASE:E( "Test Mission: Sending the Su-25T back to base." )
Check:Stop( CheckScheduleID )
AICasZone:__RTB( 1 )
end

View File

@ -0,0 +1,76 @@
---
-- Name: CAS-010 - CAS in a Zone by Helicopter
-- Author: FlightControl
-- Date Created: 6 February 2017
--
-- # Situation:
--
-- A group of 1 Ka-50 patrolling north of an engage zone for 1 minute.
-- After 1 minute, the command center orders the Ka-50 to engage the zone and execute a CAS.
--
-- # Test cases:
--
-- 1. Observe that the Ka-50 is patrolling in the patrol zone, until the engage command is given.
-- 2. The Ka-50 are not detecting any target during the patrol.
-- 3. When the Ka-50 is commanded to engage, the group will fly to the engage zone.
-- 3.1. Engage Speed is set to 100 km/h.
-- 3.2. Engage Altitude is set to 150 meters.
-- 4. Detection is activated and detected targets within the engage zone are assigned for CAS.
-- 5. Observe the Ka-50 eliminating the targets.
-- 6. Observe the Ka-50 defenses.
-- 7. When all targets within the engage zone are destroyed, the Ka-50 CAS task is set to Accomplished.
-- 8. The Ka-50 will return to base.
-- Create a local variable (in this case called CASEngagementZone) and
-- using the ZONE function find the pre-defined zone called "Engagement Zone"
-- currently on the map and assign it to this variable
local CASEngagementZone = ZONE:New( "Engagement Zone" )
-- Create a local variable (in this case called CASPlane) and
-- using the GROUP function find the aircraft group called "Plane" and assign to this variable
local CASPlane = GROUP:FindByName( "Helicopter" )
-- Create a local Variable (in this cased called PatrolZone and
-- using the ZONE function find the pre-defined zone called "Patrol Zone" and assign it to this variable
local PatrolZone = ZONE:New( "Patrol Zone" )
-- Create and object (in this case called AICasZone) and
-- using the functions AI_CAS_ZONE assign the parameters that define this object
-- (in this case PatrolZone, 500, 1000, 500, 600, CASEngagementZone)
local AICasZone = AI_CAS_ZONE:New( PatrolZone, 500, 1000, 500, 600, CASEngagementZone )
-- Create an object (in this case called Targets) and
-- using the GROUP function find the group labeled "Targets" and assign it to this object
local Targets = GROUP:FindByName("Targets")
-- Tell the program to use the object (in this case called CASPlane) as the group to use in the CAS function
AICasZone:SetControllable( CASPlane )
-- Tell the group CASPlane to start the mission in 1 second.
AICasZone:__Start( 1 ) -- They should statup, and start patrolling in the PatrolZone.
-- After 10 minutes, tell the group CASPlane to engage the targets located in the engagement zone called CASEngagement Zone. (600 is 600 seconds)
AICasZone:__Engage( 60, 100, 150 )
-- Check every 60 seconds whether the Targets have been eliminated.
-- When the trigger completed has been fired, the Plane will go back to the Patrol Zone.
Check, CheckScheduleID = SCHEDULER:New(nil,
function()
if Targets:IsAlive() and Targets:GetSize() > 5 then
BASE:E( "Test Mission: " .. Targets:GetSize() .. " targets left to be destroyed.")
else
BASE:E( "Test Mission: The required targets are destroyed." )
AICasZone:__Accomplish( 1 ) -- Now they should fly back to teh patrolzone and patrol.
end
end, {}, 20, 60, 0.2 )
-- When the targets in the zone are destroyed, (see scheduled function), the planes will return home ...
function AICasZone:OnAfterAccomplish( Controllable, From, Event, To )
BASE:E( "Test Mission: Sending the Su-25T back to base." )
Check:Stop( CheckScheduleID )
AICasZone:__RTB( 1 )
end

View File

@ -0,0 +1,75 @@
---
-- Name: CAS-011 - CAS in a Zone by Helicopter Group
-- Author: FlightControl
-- Date Created: 6 February 2017
--
-- # Situation:
--
-- A group of 4 Ka-50 patrolling north of an engage zone for 1 minute.
-- After 1 minute, the command center orders the Ka-50 to engage the zone and execute a CAS.
--
-- # Test cases:
--
-- 1. Observe that the Ka-50 is patrolling in the patrol zone, until the engage command is given.
-- 2. The Ka-50 are not detecting any target during the patrol.
-- 3. When the Ka-50 is commanded to engage, the group will fly to the engage zone.
-- 3.1. Engage Speed is set to 100 km/h.
-- 3.2. Engage Altitude is set to 150 meters.
-- 4. Detection is activated and detected targets within the engage zone are assigned for CAS.
-- 5. Observe the Ka-50 eliminating the targets.
-- 6. Observe the Ka-50 defenses.
-- 7. When all targets within the engage zone are destroyed, the Ka-50 CAS task is set to Accomplished.
-- 8. The Ka-50 will return to base.
-- Create a local variable (in this case called CASEngagementZone) and
-- using the ZONE function find the pre-defined zone called "Engagement Zone"
-- currently on the map and assign it to this variable
local CASEngagementZone = ZONE:New( "Engagement Zone" )
-- Create a local variable (in this case called CASPlane) and
-- using the GROUP function find the aircraft group called "Plane" and assign to this variable
local CASPlane = GROUP:FindByName( "Helicopter" )
-- Create a local Variable (in this cased called PatrolZone and
-- using the ZONE function find the pre-defined zone called "Patrol Zone" and assign it to this variable
local PatrolZone = ZONE:New( "Patrol Zone" )
-- Create and object (in this case called AICasZone) and
-- using the functions AI_CAS_ZONE assign the parameters that define this object
-- (in this case PatrolZone, 500, 1000, 500, 600, CASEngagementZone)
local AICasZone = AI_CAS_ZONE:New( PatrolZone, 500, 1000, 500, 600, CASEngagementZone )
-- Create an object (in this case called Targets) and
-- using the GROUP function find the group labeled "Targets" and assign it to this object
local Targets = GROUP:FindByName("Targets")
-- Tell the program to use the object (in this case called CASPlane) as the group to use in the CAS function
AICasZone:SetControllable( CASPlane )
-- Tell the group CASPlane to start the mission in 1 second.
AICasZone:__Start( 1 ) -- They should statup, and start patrolling in the PatrolZone.
-- After 10 minutes, tell the group CASPlane to engage the targets located in the engagement zone called CASEngagement Zone. (600 is 600 seconds)
AICasZone:__Engage( 60, 100, 150 )
-- Check every 60 seconds whether the Targets have been eliminated.
-- When the trigger completed has been fired, the Plane will go back to the Patrol Zone.
Check, CheckScheduleID = SCHEDULER:New(nil,
function()
if Targets:IsAlive() and Targets:GetSize() > 5 then
BASE:E( "Test Mission: " .. Targets:GetSize() .. " targets left to be destroyed.")
else
BASE:E( "Test Mission: The required targets are destroyed." )
AICasZone:__Accomplish( 1 ) -- Now they should fly back to teh patrolzone and patrol.
end
end, {}, 20, 60, 0.2 )
-- When the targets in the zone are destroyed, (see scheduled function), the planes will return home ...
function AICasZone:OnAfterAccomplish( Controllable, From, Event, To )
BASE:E( "Test Mission: Sending the Su-25T back to base." )
Check:Stop( CheckScheduleID )
AICasZone:__RTB( 1 )
end

View File

@ -0,0 +1,91 @@
---
-- Name: CAS-111 - Multiple CAS in 1 Radius Zone by Helicopter and AirPlane Groups
-- Author: FlightControl
-- Date Created: 6 February 2017
--
-- # Situation:
--
-- A group of 4 Ka-50 and 5 Su-25T are patrolling north in two engage zone for 5 minutes.
-- After 5 minutes, the command center orders the groups to engage the zone and execute a CAS.
--
-- # Test cases:
--
-- 1. Observe that the groups is patrolling in the patrol zone, until the engage command is given.
-- 2. The groups are not detecting any target during the patrol.
-- 3. When the groups is commanded to engage, the group will fly to the engage zone.
-- 3.1. Engage Speed for the Su-25T is set to 350 km/h.
-- 3.2. Engage Altitude for the Su-25T is set to 1500 meters.
-- 3.3. Engage Speed for the Ka-50 is set to 100 km/h.
-- 3.4. Engage Altitude for the Ka-50 is set to 150 meters.
-- 4. Detection is activated and detected targets within the engage zone are assigned for CAS.
-- 5. Observe the groups eliminating the targets.
-- 6. Observe the groups defenses.
-- 7. When all targets within the engage zone are destroyed, the groups CAS task is set to Accomplished.
-- 8. The groups will return to base.
-- Create a local variable (in this case called CASEngagementZone) and
-- using the ZONE function find the pre-defined zone called "Engagement Zone"
-- currently on the map and assign it to this variable
local CASEngagementZone = ZONE:New( "Engagement Zone" )
-- Create a local variables (in this case called CASPlane and CASHelicopters) and
-- using the GROUP function find the aircraft group called "Plane" and "Helicopter" and assign to these variables
local CASPlane = GROUP:FindByName( "Plane" )
local CASHelicopter = GROUP:FindByName( "Helicopter" )
-- Create two patrol zones, one for the Planes and one for the Helicopters.
local PatrolZonePlanes = ZONE:New( "Patrol Zone Planes" )
local PatrolZoneHelicopters = ZONE:New( "Patrol Zone Helicopters" )
-- Create and object (in this case called AICasZone) and
-- using the functions AI_CAS_ZONE assign the parameters that define this object
-- (in this case PatrolZone, 500, 1000, 500, 600, CASEngagementZone)
local AICasZonePlanes = AI_CAS_ZONE:New( PatrolZonePlanes, 400, 500, 500, 2500, CASEngagementZone )
local AICasZoneHelicopters = AI_CAS_ZONE:New( PatrolZoneHelicopters, 100, 250, 300, 1000, CASEngagementZone )
-- Create an object (in this case called Targets) and
-- using the GROUP function find the group labeled "Targets" and assign it to this object
local Targets = GROUP:FindByName("Targets")
-- Tell the program to use the object (in this case called CASPlane) as the group to use in the CAS function
AICasZonePlanes:SetControllable( CASPlane )
AICasZoneHelicopters:SetControllable( CASHelicopter )
-- Tell the group CASPlane to start the mission in 1 second.
AICasZonePlanes:__Start( 1 ) -- They should startup, and start patrolling in the PatrolZone.
AICasZoneHelicopters:__Start( 1 ) -- They should startup, and start patrolling in the PatrolZone.
-- After 10 minutes, tell the group CASPlanes and CASHelicopters to engage the targets located in the engagement zone called CASEngagement Zone.
AICasZonePlanes:__Engage( 300, 350, 1500 ) -- Engage with a speed of 350 km/h and 1500 meter altitude.
AICasZoneHelicopters:__Engage( 300, 100, 150 ) -- Engage with a speed of 100 km/h and 150 meter altitude.
-- Check every 60 seconds whether the Targets have been eliminated.
-- When the trigger completed has been fired, the Planes and Helicopters will go back to the Patrol Zone.
Check, CheckScheduleID = SCHEDULER:New(nil,
function()
if Targets:IsAlive() and Targets:GetSize() > 5 then
BASE:E( "Test Mission: " .. Targets:GetSize() .. " targets left to be destroyed.")
else
BASE:E( "Test Mission: The required targets are destroyed." )
Check:Stop( CheckScheduleID )
AICasZonePlanes:__Accomplish( 1 ) -- Now they should fly back to teh patrolzone and patrol.
AICasZoneHelicopters:__Accomplish( 1 ) -- Now they should fly back to teh patrolzone and patrol.
end
end, {}, 20, 60, 0.2 )
-- When the targets in the zone are destroyed, (see scheduled function), the planes will return home ...
function AICasZonePlanes:OnAfterAccomplish( Controllable, From, Event, To )
BASE:E( "Test Mission: Sending the Su-25T back to base." )
AICasZonePlanes:__RTB( 1 )
end
-- When the targets in the zone are destroyed, (see scheduled function), the helicpters will return home ...
function AICasZoneHelicopters:OnAfterAccomplish( Controllable, From, Event, To )
BASE:E( "Test Mission: Sending the Ka-50 back to base." )
AICasZoneHelicopters:__RTB( 1 )
end