Progress on AI_CAS_ZONE and AI_PATROL_ZONE rework.

This commit is contained in:
FlightControl 2017-01-15 11:11:58 +01:00
parent e552e70e2a
commit 6d5655e56a
19 changed files with 536 additions and 61600 deletions

View File

@ -95,161 +95,13 @@ function AI_CAS_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed ) ) -- #AI_CAS_ZONE local self = BASE:Inherit( self, AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitude, PatrolMinSpeed, PatrolMaxSpeed ) ) -- #AI_CAS_ZONE
self.PatrolZone = PatrolZone
self.PatrolFloorAltitude = PatrolFloorAltitude
self.PatrolCeilingAltitude = PatrolCeilingAltitude
self.PatrolMinSpeed = PatrolMinSpeed
self.PatrolMaxSpeed = PatrolMaxSpeed
self.EngageZone = EngageZone self.EngageZone = EngageZone
self.Accomplished = false
do self:AddTransition( { "Patrol", "Route", "Engaging" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE. self:AddTransition( { "Patrolling", "Engaging" }, "Engage", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Holding. --- OnBefore Transition Handler for Event Engage.
-- @function [parent=#AI_CAS_ZONE] OnLeaveHolding -- @function [parent=#AI_CAS_ZONE] OnBeforeEngage
-- @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.
-- @return #boolean Return false to cancel Transition.
--- OnEnter State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnEnterEngaging
-- @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.
--- OnBefore State Transition for Engage.
-- @function [parent=#AI_CAS_ZONE] OnBeforeEngage
-- @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.
-- @return #boolean Return false to cancel Transition.
--- OnAfter State Transition for Engage.
-- @function [parent=#AI_CAS_ZONE] OnAfterEngage
-- @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.
--- Embedded Event Trigger for Engage.
-- @function [parent=#AI_CAS_ZONE] Engage
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Engage
-- @function [parent=#AI_CAS_ZONE] __Engage
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @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.
-- @return #boolean Return false to cancel Transition.
--- OnEnter State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnEnterEngaging
-- @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.
--- OnBefore State Transition for Fired.
-- @function [parent=#AI_CAS_ZONE] OnBeforeFired
-- @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.
-- @return #boolean Return false to cancel Transition.
--- OnAfter State Transition for Fired.
-- @function [parent=#AI_CAS_ZONE] OnAfterFired
-- @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.
-- @return #boolean
--- Embedded Event Trigger for Fired.
-- @function [parent=#AI_CAS_ZONE] Fired
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Fired
-- @function [parent=#AI_CAS_ZONE] __Fired
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Destroy", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @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.
-- @return #boolean Return false to cancel Transition.
--- OnEnter State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnEnterEngaging
-- @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.
--- OnBefore State Transition for Destroy.
-- @function [parent=#AI_CAS_ZONE] OnBeforeDestroy
-- @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.
-- @return #boolean Return false to cancel Transition.
--- OnAfter State Transition for Destroy.
-- @function [parent=#AI_CAS_ZONE] OnAfterDestroy
-- @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.
--- Embedded Event Trigger for Destroy.
-- @function [parent=#AI_CAS_ZONE] Destroy
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Destroy
-- @function [parent=#AI_CAS_ZONE] __Destroy
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
do self:AddTransition( "Engaging", "Abort", "Patrol" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnLeave State Transition for Engaging.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @param #AI_CAS_ZONE self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
@ -257,15 +109,100 @@ do self:AddTransition( "Engaging", "Abort", "Patrol" ) -- FSM_CONTROLLABLE Trans
-- @param #string To The To State string. -- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnEnter State Transition for Patrol. --- OnAfter Transition Handler for Event Engage.
-- @function [parent=#AI_CAS_ZONE] OnEnterPatrol -- @function [parent=#AI_CAS_ZONE] OnAfterEngage
-- @param #AI_CAS_ZONE self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
--- OnBefore State Transition for Abort. --- Synchronous Event Trigger for Event Engage.
-- @function [parent=#AI_CAS_ZONE] Engage
-- @param #AI_CAS_ZONE self
--- Asynchronous Event Trigger for Event Engage.
-- @function [parent=#AI_CAS_ZONE] __Engage
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
--- OnLeave Transition Handler for State Engaging.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging
-- @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.
-- @return #boolean Return false to cancel Transition.
--- OnEnter Transition Handler for State Engaging.
-- @function [parent=#AI_CAS_ZONE] OnEnterEngaging
-- @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.
self:AddTransition( "Engaging", "Fired", "Engaging" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnBefore Transition Handler for Event Fired.
-- @function [parent=#AI_CAS_ZONE] OnBeforeFired
-- @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.
-- @return #boolean Return false to cancel Transition.
--- OnAfter Transition Handler for Event Fired.
-- @function [parent=#AI_CAS_ZONE] OnAfterFired
-- @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.
--- Synchronous Event Trigger for Event Fired.
-- @function [parent=#AI_CAS_ZONE] Fired
-- @param #AI_CAS_ZONE self
--- Asynchronous Event Trigger for Event Fired.
-- @function [parent=#AI_CAS_ZONE] __Fired
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
self:AddTransition( "*", "Destroy", "*" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnBefore Transition Handler for Event Destroy.
-- @function [parent=#AI_CAS_ZONE] OnBeforeDestroy
-- @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.
-- @return #boolean Return false to cancel Transition.
--- OnAfter Transition Handler for Event Destroy.
-- @function [parent=#AI_CAS_ZONE] OnAfterDestroy
-- @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.
--- Synchronous Event Trigger for Event Destroy.
-- @function [parent=#AI_CAS_ZONE] Destroy
-- @param #AI_CAS_ZONE self
--- Asynchronous Event Trigger for Event Destroy.
-- @function [parent=#AI_CAS_ZONE] __Destroy
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
self:AddTransition( "Engaging", "Abort", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnBefore Transition Handler for Event Abort.
-- @function [parent=#AI_CAS_ZONE] OnBeforeAbort -- @function [parent=#AI_CAS_ZONE] OnBeforeAbort
-- @param #AI_CAS_ZONE self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
@ -274,7 +211,7 @@ do self:AddTransition( "Engaging", "Abort", "Patrol" ) -- FSM_CONTROLLABLE Trans
-- @param #string To The To State string. -- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnAfter State Transition for Abort. --- OnAfter Transition Handler for Event Abort.
-- @function [parent=#AI_CAS_ZONE] OnAfterAbort -- @function [parent=#AI_CAS_ZONE] OnAfterAbort
-- @param #AI_CAS_ZONE self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
@ -282,64 +219,42 @@ do self:AddTransition( "Engaging", "Abort", "Patrol" ) -- FSM_CONTROLLABLE Trans
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
--- Embedded Event Trigger for Abort. --- Synchronous Event Trigger for Event Abort.
-- @function [parent=#AI_CAS_ZONE] Abort -- @function [parent=#AI_CAS_ZONE] Abort
-- @param #AI_CAS_ZONE self -- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Abort --- Asynchronous Event Trigger for Event Abort.
-- @function [parent=#AI_CAS_ZONE] __Abort -- @function [parent=#AI_CAS_ZONE] __Abort
-- @param #AI_CAS_ZONE self -- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds. -- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE self:AddTransition( "Engaging", "Accomplish", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE.
--- OnBefore Transition Handler for Event Accomplish.
-- @function [parent=#AI_CAS_ZONE] OnBeforeAccomplish
-- @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.
-- @return #boolean Return false to cancel Transition.
do self:AddTransition( "Engaging", "Completed", "Patrol" ) -- FSM_CONTROLLABLE Transition for type #AI_CAS_ZONE. --- OnAfter Transition Handler for Event Accomplish.
-- @function [parent=#AI_CAS_ZONE] OnAfterAccomplish
-- @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.
--- OnLeave State Transition for Engaging. --- Synchronous Event Trigger for Event Accomplish.
-- @function [parent=#AI_CAS_ZONE] OnLeaveEngaging -- @function [parent=#AI_CAS_ZONE] Accomplish
-- @param #AI_CAS_ZONE self -- @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.
-- @return #boolean Return false to cancel Transition.
--- OnEnter State Transition for Patrol. --- Asynchronous Event Trigger for Event Accomplish.
-- @function [parent=#AI_CAS_ZONE] OnEnterPatrol -- @function [parent=#AI_CAS_ZONE] __Accomplish
-- @param #AI_CAS_ZONE self -- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param #number Delay The delay in seconds.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
--- OnBefore State Transition for Completed.
-- @function [parent=#AI_CAS_ZONE] OnBeforeCompleted
-- @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.
-- @return #boolean Return false to cancel Transition.
--- OnAfter State Transition for Completed.
-- @function [parent=#AI_CAS_ZONE] OnAfterCompleted
-- @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.
--- Embedded Event Trigger for Completed.
-- @function [parent=#AI_CAS_ZONE] Completed
-- @param #AI_CAS_ZONE self
--- Delayed Event Trigger for Completed
-- @function [parent=#AI_CAS_ZONE] __Completed
-- @param #AI_CAS_ZONE self
-- @param #number Delay The delay in seconds.
end -- AI_CAS_ZONE
return self return self
end end
@ -354,15 +269,14 @@ end
function AI_CAS_ZONE:onafterStart( Controllable, From, Event, To ) function AI_CAS_ZONE:onafterStart( Controllable, From, Event, To )
if Controllable:IsAlive() then self:Route()
self:__Route( 1 ) self:__Status( 30 ) -- Check status status every 30 seconds.
end self:__Detect( 30, self.EngageZone ) -- Detect for new targets every 30 seconds in the EngageZone.
self:EventOnDead( self.OnDead ) self:EventOnDead( self.OnDead )
Controllable:OptionROEHoldFire() Controllable:OptionROEHoldFire()
Controllable:OptionROTVertical() Controllable:OptionROTVertical()
end end
--- @param Wrapper.Controllable#CONTROLLABLE AIControllable --- @param Wrapper.Controllable#CONTROLLABLE AIControllable
@ -373,6 +287,18 @@ function _NewEngageRoute( AIControllable )
EngageZone:__Engage( 1 ) EngageZone:__Engage( 1 )
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:onbeforeEngage( Controllable, From, Event, To )
if self.Accomplished == true then
return false
end
end
--- @param #AI_CAS_ZONE self --- @param #AI_CAS_ZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
@ -383,8 +309,28 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
if Controllable:IsAlive() then if Controllable:IsAlive() then
self:Detect( self.EngageZone )
local EngageRoute = {} local EngageRoute = {}
--- Calculate the current route point.
local CurrentVec2 = self.Controllable:GetVec2()
--TODO: Create GetAltitude function for GROUP, and delete GetUnit(1).
local CurrentAltitude = self.Controllable:GetUnit(1):GetAltitude()
local CurrentPointVec3 = POINT_VEC3:New( CurrentVec2.x, CurrentAltitude, CurrentVec2.y )
local ToEngageZoneSpeed = self.PatrolMaxSpeed
local CurrentRoutePoint = CurrentPointVec3:RoutePointAir(
POINT_VEC3.RoutePointAltType.BARO,
POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint,
ToEngageZoneSpeed,
true
)
EngageRoute[#EngageRoute+1] = CurrentRoutePoint
if self.Controllable:IsNotInZone( self.EngageZone ) then if self.Controllable:IsNotInZone( self.EngageZone ) then
-- Find a random 2D point in EngageZone. -- Find a random 2D point in EngageZone.
@ -435,7 +381,7 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
true true
) )
ToTargetPointVec3:SmokeRed() ToTargetPointVec3:SmokeBlue()
EngageRoute[#EngageRoute+1] = ToTargetRoutePoint EngageRoute[#EngageRoute+1] = ToTargetRoutePoint
@ -445,21 +391,16 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
local AttackTasks = {} local AttackTasks = {}
local DetectedTargets = Controllable:GetDetectedTargets() for DetectedUnitID, DetectedUnit in pairs( self.DetectedUnits ) do
for TargetID, Target in pairs( DetectedTargets ) do local DetectedUnit = DetectedUnit -- Wrapper.Unit#UNIT
local TargetObject = Target.object self:T( DetectedUnit )
self:T( TargetObject ) if DetectedUnit:IsAlive() then
if TargetObject and TargetObject:isExist() and TargetObject.id_ < 50000000 then if DetectedUnit:IsInZone( self.EngageZone ) then
self:E( {"Engaging ", DetectedUnit } )
local TargetUnit = UNIT:Find( TargetObject ) AttackTasks[#AttackTasks+1] = Controllable:TaskAttackUnit( DetectedUnit )
local TargetUnitName = TargetUnit:GetName()
if TargetUnit:IsInZone( self.EngageZone ) then
self:E( {"Engaging ", TargetUnit } )
--local EngageTask = Controllable:EnRouteTaskEngageUnit( TargetUnit, 1 )
AttackTasks[#AttackTasks+1] = Controllable:TaskAttackUnit( TargetUnit )
end end
else
self.DetectedUnits[DetectedUnit] = nil
end end
end end
@ -474,7 +415,7 @@ function AI_CAS_ZONE:onafterEngage( Controllable, From, Event, To )
self.Controllable:WayPointFunction( #EngageRoute, 1, "_NewEngageRoute" ) self.Controllable:WayPointFunction( #EngageRoute, 1, "_NewEngageRoute" )
--- NOW ROUTE THE GROUP! --- NOW ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1, 5 ) self.Controllable:WayPointExecute( 1, 2 )
end end
end end
@ -483,11 +424,35 @@ end
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
function AI_CAS_ZONE:onafterDestroy( Controllable, From, Event, To ) -- @param Core.Event#EVENTDATA EventData
function AI_CAS_ZONE:onafterDestroy( Controllable, From, Event, To, EventData )
if EventData.IniUnit then
self.DetectedUnits[EventData.IniUnit] = nil
end
Controllable:MessageToAll( "Destroyed a target", 15 , "Destroyed!" ) Controllable:MessageToAll( "Destroyed a target", 15 , "Destroyed!" )
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:onafterRTB( Controllable, From, Event, To, EventData )
self.CheckStatus = false
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:onafterAccomplish( Controllable, From, Event, To )
self.Accomplished = true
self.DetectUnits = false
end
--- @param #AI_CAS_ZONE self --- @param #AI_CAS_ZONE self
-- @param Core.Event#EVENTDATA EventData -- @param Core.Event#EVENTDATA EventData
function AI_CAS_ZONE:OnDead( EventData ) function AI_CAS_ZONE:OnDead( EventData )

View File

@ -140,6 +140,7 @@
-- @field Dcs.DCSTypes#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol. -- @field Dcs.DCSTypes#Altitude PatrolCeilingAltitude The highest altitude in meters where to execute the patrol.
-- @field Dcs.DCSTypes#Speed PatrolMinSpeed The minimum speed of the @{Controllable} in km/h. -- @field Dcs.DCSTypes#Speed PatrolMinSpeed The minimum speed of the @{Controllable} in km/h.
-- @field Dcs.DCSTypes#Speed PatrolMaxSpeed The maximum speed of the @{Controllable} in km/h. -- @field Dcs.DCSTypes#Speed PatrolMaxSpeed The maximum speed of the @{Controllable} in km/h.
-- @field Functional.Spawn#SPAWN CoordTest
-- @extends Core.Fsm#FSM_CONTROLLABLE -- @extends Core.Fsm#FSM_CONTROLLABLE
AI_PATROLZONE = { AI_PATROLZONE = {
ClassName = "AI_PATROLZONE", ClassName = "AI_PATROLZONE",
@ -166,204 +167,194 @@ function AI_PATROLZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltitu
local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- Core.Fsm#FSM_CONTROLLABLE local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- Core.Fsm#FSM_CONTROLLABLE
self.PatrolZone = PatrolZone self.PatrolZone = PatrolZone
self.PatrolFloorAltitude = PatrolFloorAltitude self.PatrolFloorAltitude = PatrolFloorAltitude
self.PatrolCeilingAltitude = PatrolCeilingAltitude self.PatrolCeilingAltitude = PatrolCeilingAltitude
self.PatrolMinSpeed = PatrolMinSpeed self.PatrolMinSpeed = PatrolMinSpeed
self.PatrolMaxSpeed = PatrolMaxSpeed self.PatrolMaxSpeed = PatrolMaxSpeed
self.PatrolFuelTresholdPercentage = 0.2 self.DetectUnits = true
self.CheckStatus = true
self.DetectedUnits = {} -- This table contains the targets detected during patrol.
self.PatrolFuelTresholdPercentage = 0.2
self:SetStartState( "None" ) self:SetStartState( "None" )
do self:AddTransition( "*", "Start", "Route" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE. self:AddTransition( "None", "Start", "Patrolling" )
--- OnLeave State Transition for Route. --- OnBefore Transition Handler for Event Start.
-- @function [parent=#AI_PATROLZONE] OnLeaveRoute -- @function [parent=#AI_PATROLZONE] OnBeforeStart
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnEnter State Transition for Route. --- OnAfter Transition Handler for Event Start.
-- @function [parent=#AI_PATROLZONE] OnEnterRoute -- @function [parent=#AI_PATROLZONE] OnAfterStart
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
--- OnBefore State Transition for Start. --- Synchronous Event Trigger for Event Start.
-- @function [parent=#AI_PATROLZONE] OnBeforeStart -- @function [parent=#AI_PATROLZONE] Start
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE 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.
-- @return #boolean Return false to cancel Transition.
--- OnAfter State Transition for Start. --- Asynchronous Event Trigger for Event Start.
-- @function [parent=#AI_PATROLZONE] OnAfterStart -- @function [parent=#AI_PATROLZONE] __Start
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param #number Delay The delay in seconds.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
--- Embedded Event Trigger for Start. --- OnLeave Transition Handler for State Patrolling.
-- @function [parent=#AI_PATROLZONE] Start -- @function [parent=#AI_PATROLZONE] OnLeavePatrolling
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE 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.
-- @return #boolean Return false to cancel Transition.
--- Delayed Event Trigger for Start --- OnEnter Transition Handler for State Patrolling.
-- @function [parent=#AI_PATROLZONE] __Start -- @function [parent=#AI_PATROLZONE] OnEnterPatrolling
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds. -- @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.
end -- AI_PATROLZONE self:AddTransition( "Patrolling", "Route", "Patrolling" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
do self:AddTransition( "*", "Route", "Route" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE. --- OnBefore Transition Handler for Event Route.
-- @function [parent=#AI_PATROLZONE] OnBeforeRoute
-- @param #AI_PATROLZONE 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.
-- @return #boolean Return false to cancel Transition.
--- OnLeave State Transition for Route. --- OnAfter Transition Handler for Event Route.
-- @function [parent=#AI_PATROLZONE] OnLeaveRoute -- @function [parent=#AI_PATROLZONE] OnAfterRoute
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition.
--- OnEnter State Transition for Route. --- Synchronous Event Trigger for Event Route.
-- @function [parent=#AI_PATROLZONE] OnEnterRoute -- @function [parent=#AI_PATROLZONE] Route
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE 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.
--- OnBefore State Transition for Route. --- Asynchronous Event Trigger for Event Route.
-- @function [parent=#AI_PATROLZONE] OnBeforeRoute -- @function [parent=#AI_PATROLZONE] __Route
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param #number Delay The delay in seconds.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition.
--- OnAfter State Transition for Route. self:AddTransition( "*", "Status", "*" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
-- @function [parent=#AI_PATROLZONE] OnAfterRoute
-- @param #AI_PATROLZONE 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.
--- Embedded Event Trigger for Route. --- OnBefore Transition Handler for Event Status.
-- @function [parent=#AI_PATROLZONE] Route -- @function [parent=#AI_PATROLZONE] OnBeforeStatus
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE 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.
-- @return #boolean Return false to cancel Transition.
--- Delayed Event Trigger for Route --- OnAfter Transition Handler for Event Status.
-- @function [parent=#AI_PATROLZONE] __Route -- @function [parent=#AI_PATROLZONE] OnAfterStatus
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds. -- @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.
end -- AI_PATROLZONE --- Synchronous Event Trigger for Event Status.
-- @function [parent=#AI_PATROLZONE] Status
-- @param #AI_PATROLZONE self
do self:AddTransition( "*", "Patrol", "Patrol" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE. --- Asynchronous Event Trigger for Event Status.
-- @function [parent=#AI_PATROLZONE] __Status
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
--- OnLeave State Transition for Patrol. self:AddTransition( "*", "Detect", "*" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
-- @function [parent=#AI_PATROLZONE] OnLeavePatrol
-- @param #AI_PATROLZONE 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.
-- @return #boolean Return false to cancel Transition.
--- OnEnter State Transition for Patrol. --- OnBefore Transition Handler for Event Detect.
-- @function [parent=#AI_PATROLZONE] OnEnterPatrol -- @function [parent=#AI_PATROLZONE] OnBeforeDetect
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition.
--- OnBefore State Transition for Patrol. --- OnAfter Transition Handler for Event Detect.
-- @function [parent=#AI_PATROLZONE] OnBeforePatrol -- @function [parent=#AI_PATROLZONE] OnAfterDetect
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition.
--- OnAfter State Transition for Patrol. --- Synchronous Event Trigger for Event Detect.
-- @function [parent=#AI_PATROLZONE] OnAfterPatrol -- @function [parent=#AI_PATROLZONE] Detect
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE 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.
--- Embedded Event Trigger for Patrol. --- Asynchronous Event Trigger for Event Detect.
-- @function [parent=#AI_PATROLZONE] Patrol -- @function [parent=#AI_PATROLZONE] __Detect
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
--- Delayed Event Trigger for Patrol self:AddTransition( "*", "RTB", "RTB" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE.
-- @function [parent=#AI_PATROLZONE] __Patrol
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE --- OnBefore Transition Handler for Event RTB.
-- @function [parent=#AI_PATROLZONE] OnBeforeRTB
-- @param #AI_PATROLZONE 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.
-- @return #boolean Return false to cancel Transition.
do self:AddTransition( "Patrol", "RTB", "RTB" ) -- FSM_CONTROLLABLE Transition for type #AI_PATROLZONE. --- OnAfter Transition Handler for Event RTB.
-- @function [parent=#AI_PATROLZONE] OnAfterRTB
-- @param #AI_PATROLZONE 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.
--- OnLeave State Transition for Patrol. --- Synchronous Event Trigger for Event RTB.
-- @function [parent=#AI_PATROLZONE] OnLeavePatrol -- @function [parent=#AI_PATROLZONE] RTB
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE 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.
-- @return #boolean Return false to cancel Transition.
--- OnEnter State Transition for RTB. --- Asynchronous Event Trigger for Event RTB.
-- @function [parent=#AI_PATROLZONE] OnEnterRTB -- @function [parent=#AI_PATROLZONE] __RTB
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param #number Delay The delay in seconds.
-- @param #string From The From State string.
-- @param #string Event The Event string.
-- @param #string To The To State string.
--- OnBefore State Transition for RTB. --- OnLeave Transition Handler for State Returning.
-- @function [parent=#AI_PATROLZONE] OnBeforeRTB -- @function [parent=#AI_PATROLZONE] OnLeaveReturning
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
-- @return #boolean Return false to cancel Transition. -- @return #boolean Return false to cancel Transition.
--- OnAfter State Transition for RTB. --- OnEnter Transition Handler for State Returning.
-- @function [parent=#AI_PATROLZONE] OnAfterRTB -- @function [parent=#AI_PATROLZONE] OnEnterReturning
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM. -- @param Wrapper.Controllable#CONTROLLABLE Controllable The Controllable Object managed by the FSM.
-- @param #string From The From State string. -- @param #string From The From State string.
-- @param #string Event The Event string. -- @param #string Event The Event string.
-- @param #string To The To State string. -- @param #string To The To State string.
--- Embedded Event Trigger for RTB.
-- @function [parent=#AI_PATROLZONE] RTB
-- @param #AI_PATROLZONE self
--- Delayed Event Trigger for RTB
-- @function [parent=#AI_PATROLZONE] __RTB
-- @param #AI_PATROLZONE self
-- @param #number Delay The delay in seconds.
end -- AI_PATROLZONE
return self return self
end end
@ -399,14 +390,6 @@ end
--- @param Wrapper.Controllable#CONTROLLABLE AIControllable
function _NewPatrolRoute( AIControllable )
AIControllable:T( "NewPatrolRoute" )
local PatrolZone = AIControllable:GetState( AIControllable, "PatrolZone" ) -- PatrolCore.Zone#AI_PATROLZONE
PatrolZone:__Route( 1 )
end
@ -430,29 +413,102 @@ end
--- Defines a new patrol route using the @{Process_PatrolZone} parameters and settings. --- Defines a new patrol route using the @{Process_PatrolZone} parameters and settings.
-- @param #AI_PATROLZONE self -- @param #AI_PATROLZONE self
-- @return #AI_PATROLZONE self -- @return #AI_PATROLZONE self
function AI_PATROLZONE:onenterRoute() -- @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_PATROLZONE:onafterStart( Controllable, From, Event, To )
self:F2()
self:Route() -- Route to the patrol point.
self:__Status( 30 ) -- Check status status every 30 seconds.
self:__Detect( 30 ) -- Detect for new targets every 30 seconds.
Controllable:OptionROEHoldFire()
Controllable:OptionROTVertical()
end
--- @param #AI_PATROLZONE self
--- @param Wrapper.Controllable#CONTROLLABLE Controllable
function AI_PATROLZONE:onbeforeDetect( Controllable, From, Event, To, DetectZone )
return self.DetectUnits
end
--- @param #AI_PATROLZONE self
--- @param Wrapper.Controllable#CONTROLLABLE Controllable
function AI_PATROLZONE:onafterDetect( Controllable, From, Event, To, DetectZone )
local DetectedTargets = Controllable:GetDetectedTargets()
for TargetID, Target in pairs( DetectedTargets ) do
local TargetObject = Target.object
self:T( TargetObject )
if TargetObject and TargetObject:isExist() and TargetObject.id_ < 50000000 then
local TargetUnit = UNIT:Find( TargetObject )
local TargetUnitName = TargetUnit:GetName()
if DetectZone then
if TargetUnit:IsInZone( DetectZone ) then
self:T( {"Detected ", TargetUnit } )
self.DetectedUnits[TargetUnit] = TargetUnit
end
else
self.DetectedUnits[TargetUnit] = TargetUnit
end
end
end
end
--- @param Wrapper.Controllable#CONTROLLABLE AIControllable
function _NewPatrolRoute( AIControllable )
AIControllable:T( "NewPatrolRoute" )
local PatrolZone = AIControllable:GetState( AIControllable, "PatrolZone" ) -- PatrolCore.Zone#AI_PATROLZONE
PatrolZone:Route()
end
--- Defines a new patrol route using the @{Process_PatrolZone} parameters and settings.
-- @param #AI_PATROLZONE 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_PATROLZONE:onafterRoute( Controllable, From, Event, To )
self:F2() self:F2()
-- When RTB, don't allow anymore the routing.
if From == "RTB" then
return
end
local PatrolRoute = {} local PatrolRoute = {}
if self.Controllable:IsAlive() then if self.Controllable:IsAlive() then
--- Determine if the AIControllable is within the PatrolZone. --- Determine if the AIControllable is within the PatrolZone.
-- If not, make a waypoint within the to that the AIControllable will fly at maximum speed to that point. -- If not, make a waypoint within the to that the AIControllable will fly at maximum speed to that point.
-- --- Calculate the current route point. --- Calculate the current route point.
-- local CurrentVec2 = self.Controllable:GetVec2() local CurrentVec2 = self.Controllable:GetVec2()
-- local CurrentAltitude = self.Controllable:GetUnit(1):GetAltitude()
-- local CurrentPointVec3 = POINT_VEC3:New( CurrentVec2.x, CurrentAltitude, CurrentVec2.y ) --TODO: Create GetAltitude function for GROUP, and delete GetUnit(1).
-- local CurrentRoutePoint = CurrentPointVec3:RoutePointAir( local CurrentAltitude = self.Controllable:GetUnit(1):GetAltitude()
-- POINT_VEC3.RoutePointAltType.BARO, local CurrentPointVec3 = POINT_VEC3:New( CurrentVec2.x, CurrentAltitude, CurrentVec2.y )
-- POINT_VEC3.RoutePointType.TurningPoint, local ToPatrolZoneSpeed = self.PatrolMaxSpeed
-- POINT_VEC3.RoutePointAction.TurningPoint, local CurrentRoutePoint = CurrentPointVec3:RoutePointAir(
-- ToPatrolZoneSpeed, POINT_VEC3.RoutePointAltType.BARO,
-- true POINT_VEC3.RoutePointType.TurningPoint,
-- ) POINT_VEC3.RoutePointAction.TurningPoint,
-- ToPatrolZoneSpeed,
-- PatrolRoute[#PatrolRoute+1] = CurrentRoutePoint true
)
PatrolRoute[#PatrolRoute+1] = CurrentRoutePoint
self:T2( PatrolRoute ) self:T2( PatrolRoute )
@ -505,7 +561,9 @@ function AI_PATROLZONE:onenterRoute()
true true
) )
--ToTargetPointVec3:SmokeRed() --self.CoordTest:SpawnFromVec3( ToTargetPointVec3:GetVec3() )
ToTargetPointVec3:SmokeRed()
PatrolRoute[#PatrolRoute+1] = ToTargetRoutePoint PatrolRoute[#PatrolRoute+1] = ToTargetRoutePoint
@ -517,16 +575,19 @@ function AI_PATROLZONE:onenterRoute()
self.Controllable:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" ) self.Controllable:WayPointFunction( #PatrolRoute, 1, "_NewPatrolRoute" )
--- NOW ROUTE THE GROUP! --- NOW ROUTE THE GROUP!
self.Controllable:WayPointExecute( 1, 5 ) self.Controllable:WayPointExecute( 1, 2 )
self:__Patrol( 30 )
end end
end end
--- @param #AI_PATROLZONE self
function AI_PATROLZONE:onbeforeStatus()
return self.CheckStatus
end
--- @param #AI_PATROLZONE self --- @param #AI_PATROLZONE self
function AI_PATROLZONE:onenterPatrol() function AI_PATROLZONE:onafterStatus()
self:F2() self:F2()
if self.Controllable and self.Controllable:IsAlive() then if self.Controllable and self.Controllable:IsAlive() then
@ -542,8 +603,10 @@ function AI_PATROLZONE:onenterPatrol()
self:RTB() self:RTB()
else else
self:__Patrol( 30 ) -- Execute the Patrol event after 30 seconds. self:__Status( 30 ) -- Execute the Patrol event after 30 seconds.
end end
self:__Detect( 30 ) -- Detect for new targets every 30 seconds.
end end
end end

View File

@ -535,15 +535,18 @@ do -- FSM
function FSM._handler( self, EventName, ... ) function FSM._handler( self, EventName, ... )
self:E( { EventName, ... } )
local Can, to = self:can( EventName ) local Can, to = self:can( EventName )
self:E( { From = self.current, Event = EventName, To = to, Can = Can } )
if to == "*" then
to = self.current
end
if Can then if Can then
local from = self.current local from = self.current
local params = { from, EventName, to, ... } local params = { from, EventName, to, ... }
self:E( "FSM Transition:" .. self.current .. " --> " .. EventName .. " --> " .. to )
if self:_call_handler("onbefore" .. EventName, params) == false if self:_call_handler("onbefore" .. EventName, params) == false
or self:_call_handler("OnBefore" .. EventName, params) == false or self:_call_handler("OnBefore" .. EventName, params) == false
or self:_call_handler("onleave" .. from, params) == false or self:_call_handler("onleave" .. from, params) == false
@ -592,6 +595,9 @@ do -- FSM
self:_call_handler("onstatechange", params) self:_call_handler("onstatechange", params)
end end
else
self:E( "Cannot execute transition." )
self:E( { From = self.current, Event = EventName, To = to, Can = Can } )
end end
return nil return nil
@ -667,7 +673,6 @@ do -- FSM
end end
function FSM:can(e) function FSM:can(e)
self:E( { e, self.Events, self.Events[e] } )
local Event = self.Events[e] local Event = self.Events[e]
self:F3( { self.current, Event } ) self:F3( { self.current, Event } )
local To = Event and Event.map[self.current] or Event.map['*'] local To = Event and Event.map[self.current] or Event.map['*']
@ -736,7 +741,7 @@ do -- FSM_CONTROLLABLE
end end
if self[handler] then if self[handler] then
self:E( "Calling " .. handler ) self:F3( "Calling " .. handler )
return xpcall( function() return self[handler]( self, self.Controllable, unpack( params ) ) end, ErrorHandler ) return xpcall( function() return self[handler]( self, self.Controllable, unpack( params ) ) end, ErrorHandler )
--return self[handler]( self, self.Controllable, unpack( params ) ) --return self[handler]( self, self.Controllable, unpack( params ) )
end end

View File

@ -68,10 +68,10 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
if Scheduler.MasterObject then if Scheduler.MasterObject then
self.ObjectSchedulers[self.CallID] = Scheduler self.ObjectSchedulers[self.CallID] = Scheduler
self:E( { CallID = self.CallID, ObjectScheduler = tostring(self.ObjectSchedulers[self.CallID]), MasterObject = tostring(Scheduler.MasterObject) } ) self:F3( { CallID = self.CallID, ObjectScheduler = tostring(self.ObjectSchedulers[self.CallID]), MasterObject = tostring(Scheduler.MasterObject) } )
else else
self.PersistentSchedulers[self.CallID] = Scheduler self.PersistentSchedulers[self.CallID] = Scheduler
self:E( { CallID = self.CallID, PersistentScheduler = self.PersistentSchedulers[self.CallID] } ) self:F3( { CallID = self.CallID, PersistentScheduler = self.PersistentSchedulers[self.CallID] } )
end end
self.Schedule = self.Schedule or setmetatable( {}, { __mode = "k" } ) self.Schedule = self.Schedule or setmetatable( {}, { __mode = "k" } )

View File

@ -102,7 +102,7 @@ function SCHEDULER:Schedule( SchedulerObject, SchedulerFunction, SchedulerArgume
if SchedulerObject and SchedulerObject.ClassName and SchedulerObject.ClassID then if SchedulerObject and SchedulerObject.ClassName and SchedulerObject.ClassID then
ObjectName = SchedulerObject.ClassName .. SchedulerObject.ClassID ObjectName = SchedulerObject.ClassName .. SchedulerObject.ClassID
end end
self:E( { "Schedule :", ObjectName, tostring( SchedulerObject ), Start, Repeat, RandomizeFactor, Stop } ) self:F3( { "Schedule :", ObjectName, tostring( SchedulerObject ), Start, Repeat, RandomizeFactor, Stop } )
self.SchedulerObject = SchedulerObject self.SchedulerObject = SchedulerObject
local ScheduleID = _SCHEDULEDISPATCHER:AddSchedule( local ScheduleID = _SCHEDULEDISPATCHER:AddSchedule(

View File

@ -306,6 +306,10 @@ function CONTROLLABLE:TaskCombo( DCSTasks )
} }
} }
for TaskID, Task in ipairs( DCSTasks ) do
self:E( Task )
end
self:T3( { DCSTaskCombo } ) self:T3( { DCSTaskCombo } )
return DCSTaskCombo return DCSTaskCombo
end end
@ -490,22 +494,24 @@ function CONTROLLABLE:TaskAttackUnit( AttackUnit, WeaponType, WeaponExpend, Atta
-- } -- }
local DCSTask local DCSTask
DCSTask = { id = 'AttackUnit', DCSTask = {
id = 'AttackUnit',
params = { params = {
altitudeEnabled = false, altitudeEnabled = true,
unitId = AttackUnit:GetID(), unitId = AttackUnit:GetID(),
attackQtyLimit = AttackQtyLimit or false, attackQtyLimit = AttackQtyLimit or false,
attackQty = AttackQty or 1, attackQty = AttackQty or 2,
expend = WeaponExpend or "Auto", expend = WeaponExpend or "Auto",
altitude = 2000, altitude = 2000,
directionEnabled = false, directionEnabled = true,
groupAttack = false, groupAttack = true,
weaponType = WeaponType or 1073741822, --weaponType = WeaponType or 1073741822,
direction = Direction or 0, direction = Direction or 0,
}, }
}, }
self:E( DCSTask )
self:E( { DCSTask } )
return DCSTask return DCSTask
end end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -13,25 +13,36 @@ local CASPlane = GROUP:FindByName( "Plane" )
local PatrolZone = ZONE:New( "Patrol Zone" ) local PatrolZone = ZONE:New( "Patrol Zone" )
local AICasZone = AI_CAS_ZONE:New( PatrolZone, 500, 1000, 350, 600, CASEngagementZone ) local AICasZone = AI_CAS_ZONE:New( PatrolZone, 500, 1000, 500, 600, CASEngagementZone )
local Targets = GROUP:FindByName("Targets") local Targets = GROUP:FindByName("Targets")
AICasZone:SetControllable(CASPlane) AICasZone:SetControllable(CASPlane)
AICasZone:__Start(1)
AICasZone:__Engage(10) AICasZone:__Start( 1 ) -- They should statup, and start patrolling in the PatrolZone.
-- After 5 minutes, engage
AICasZone:__Engage( 600 )
-- Check every 60 seconds whether the Targets have been eliminated. -- 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. -- When the trigger completed has been fired, the Plane will go back to the Patrol Zone.
Check = SCHEDULER:New(nil, Check, CheckScheduleID = SCHEDULER:New(nil,
function() function()
BASE:E( { "In Scheduler: ", Targets:GetSize() } ) BASE:E( { "In Scheduler: ", Targets:GetSize() } )
if Targets:IsAlive() and Targets:GetSize() ~= 0 then if Targets:IsAlive() and Targets:GetSize() > 5 then
BASE:E("Still alive") BASE:E("Still alive")
else else
BASE:E("Destroyed") BASE:E("Destroyed")
AICasZone:__Completed(1) AICasZone:__Accomplish( 1 ) -- Now they should fly back to teh patrolzone and patrol.
Check:Stop(CheckScheduleID)
end end
end, {}, 20, 60, 0.2 ) end, {}, 20, 60, 0.2 )
-- When the targets in the zone are destroyed, (see scheduled function), the planes will return homs...
function AICasZone:OnAfterAccomplish( Controllable, From, Event, To )
AICasZone:__RTB( 1 )
end

Binary file not shown.

Binary file not shown.