Merge pull request #288 from FlightControl-Master/master-adding

Master Bugfix
This commit is contained in:
Sven Van de Velde 2017-03-07 09:44:00 +01:00 committed by GitHub
commit ad90a08ec0
27 changed files with 1062 additions and 149 deletions

View File

@ -50,11 +50,14 @@
--
-- * **None** ( Group ): The process is not started yet.
-- * **Patrolling** ( Group ): The AI is patrolling the Patrol Zone.
-- * **Returning** ( Group ): The AI is returning to Base..
-- * **Returning** ( Group ): The AI is returning to Base.
-- * **Stopped** ( Group ): The process is stopped.
-- * **Crashed** ( Group ): The AI has crashed or is dead.
--
-- ### 1.2.2) AI_PATROL_ZONE Events
--
-- * **Start** ( Group ): Start the process.
-- * **Stop** ( Group ): Stop the process.
-- * **Route** ( Group ): Route the AI to a new random 3D point within the Patrol Zone.
-- * **RTB** ( Group ): Route the AI to the home base.
-- * **Detect** ( Group ): The AI is detecting targets.
@ -201,6 +204,51 @@ function AI_PATROL_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltit
self:SetStartState( "None" )
self:AddTransition( "*", "Stop", "Stopped" )
--- OnLeave Transition Handler for State Stopped.
-- @function [parent=#AI_PATROL_ZONE] OnLeaveStopped
-- @param #AI_PATROL_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 Stopped.
-- @function [parent=#AI_PATROL_ZONE] OnEnterStopped
-- @param #AI_PATROL_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 Transition Handler for Event Stop.
-- @function [parent=#AI_PATROL_ZONE] OnBeforeStop
-- @param #AI_PATROL_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 Stop.
-- @function [parent=#AI_PATROL_ZONE] OnAfterStop
-- @param #AI_PATROL_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 Stop.
-- @function [parent=#AI_PATROL_ZONE] Stop
-- @param #AI_PATROL_ZONE self
--- Asynchronous Event Trigger for Event Stop.
-- @function [parent=#AI_PATROL_ZONE] __Stop
-- @param #AI_PATROL_ZONE self
-- @param #number Delay The delay in seconds.
self:AddTransition( "None", "Start", "Patrolling" )
--- OnBefore Transition Handler for Event Start.

View File

@ -65,6 +65,13 @@
-- * @{Base#BASE.HandleEvent}(): Subscribe to a DCS Event.
-- * @{Base#BASE.UnHandleEvent}(): Unsubscribe from a DCS Event.
--
-- Note that for a UNIT, the event will be handled **for that UNIT only**!
-- Note that for a GROUP, the event will be handled **for all the UNITs in that GROUP only**!
--
-- For all objects of other classes, the subscribed events will be handled for **all UNITs within the Mission**!
-- So if a UNIT within the mission has the subscribed event for that object,
-- then the object event handler will receive the event for that UNIT!
--
-- ### 1.3.2 Event Handling of DCS Events
--
-- Once the class is subscribed to the event, an **Event Handling** method on the object or class needs to be written that will be called
@ -165,7 +172,9 @@
--
-- Hereby the change log:
--
-- * 2016-02-07: Did a complete revision of the Event Handing API and underlying mechanisms.
-- * 2017-03-07: Added the correct event dispatching in case the event is subscribed by a GROUP.
--
-- * 2017-02-07: Did a complete revision of the Event Handing API and underlying mechanisms.
--
-- ===
--
@ -179,10 +188,6 @@
--
-- @module Event
-- TODO: Need to update the EVENTDATA documentation with IniPlayerName and TgtPlayerName
-- TODO: Need to update the EVENTDATA documentation with IniObjectCategory and TgtObjectCategory
--- The EVENT structure
-- @type EVENT
@ -443,8 +448,9 @@ function EVENT:Remove( EventClass, EventID )
self.Events[EventID][EventPriority][EventClass] = nil
end
--- Removes an Events entry for a Unit
--- Removes an Events entry for a UNIT.
-- @param #EVENT self
-- @param #string UnitName The name of the UNIT.
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param Dcs.DCSWorld#world.event EventID
-- @return #EVENT.Events
@ -457,6 +463,21 @@ function EVENT:RemoveForUnit( UnitName, EventClass, EventID )
Event.IniUnit[UnitName] = nil
end
--- Removes an Events entry for a GROUP.
-- @param #EVENT self
-- @param #string GroupName The name of the GROUP.
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param Dcs.DCSWorld#world.event EventID
-- @return #EVENT.Events
function EVENT:RemoveForGroup( GroupName, EventClass, EventID )
self:F3( { EventClass, _EVENTMETA[EventID].Text } )
local EventClass = EventClass
local EventPriority = EventClass:GetEventPriority()
local Event = self.Events[EventID][EventPriority][EventClass]
Event.IniGroup[GroupName] = nil
end
--- Clears all event subscriptions for a @{Base#BASE} derived object.
-- @param #EVENT self
-- @param Core.Base#BASE EventObject
@ -505,23 +526,43 @@ function EVENT:OnEventGeneric( EventFunction, EventClass, EventID )
end
--- Set a new listener for an S_EVENT_X event
--- Set a new listener for an S_EVENT_X event for a UNIT.
-- @param #EVENT self
-- @param #string EventDCSUnitName
-- @param #function EventFunction The function to be called when the event occurs for the unit.
-- @param #string UnitName The name of the UNIT.
-- @param #function EventFunction The function to be called when the event occurs for the GROUP.
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param EventID
-- @return #EVENT
function EVENT:OnEventForUnit( EventDCSUnitName, EventFunction, EventClass, EventID )
self:F2( EventDCSUnitName )
function EVENT:OnEventForUnit( UnitName, EventFunction, EventClass, EventID )
self:F2( UnitName )
local Event = self:Init( EventID, EventClass )
if not Event.IniUnit then
Event.IniUnit = {}
end
Event.IniUnit[EventDCSUnitName] = {}
Event.IniUnit[EventDCSUnitName].EventFunction = EventFunction
Event.IniUnit[EventDCSUnitName].EventClass = EventClass
Event.IniUnit[UnitName] = {}
Event.IniUnit[UnitName].EventFunction = EventFunction
Event.IniUnit[UnitName].EventClass = EventClass
return self
end
--- Set a new listener for an S_EVENT_X event for a GROUP.
-- @param #EVENT self
-- @param #string GroupName The name of the GROUP.
-- @param #function EventFunction The function to be called when the event occurs for the GROUP.
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param EventID
-- @return #EVENT
function EVENT:OnEventForGroup( GroupName, EventFunction, EventClass, EventID )
self:F2( GroupName )
local Event = self:Init( EventID, EventClass )
if not Event.IniGroup then
Event.IniGroup = {}
end
Event.IniGroup[GroupName] = {}
Event.IniGroup[GroupName].EventFunction = EventFunction
Event.IniGroup[GroupName].EventClass = EventClass
return self
end
@ -1084,7 +1125,9 @@ function EVENT:onEvent( Event )
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
Event.IniDCSGroupName = Event.IniDCSGroup:getName()
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
self:E( { IniGroup = Event.IniGroup } )
if Event.IniGroup then
Event.IniGroupName = Event.IniDCSGroupName
end
end
Event.IniPlayerName = Event.IniDCSUnit:getPlayerName()
Event.IniCoalition = Event.IniDCSUnit:getCoalition()
@ -1125,6 +1168,10 @@ function EVENT:onEvent( Event )
Event.TgtDCSGroupName = ""
if Event.TgtDCSGroup and Event.TgtDCSGroup:isExist() then
Event.TgtDCSGroupName = Event.TgtDCSGroup:getName()
Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName )
if Event.TgtGroup then
Event.TgtGroupName = Event.TgtDCSGroupName
end
end
Event.TgtPlayerName = Event.TgtDCSUnit:getPlayerName()
Event.TgtCoalition = Event.TgtDCSUnit:getCoalition()
@ -1171,14 +1218,15 @@ function EVENT:onEvent( Event )
-- Okay, we got the event from DCS. Now loop the SORTED self.EventSorted[] table for the received Event.id, and for each EventData registered, check if a function needs to be called.
for EventClass, EventData in pairs( self.Events[Event.id][EventPriority] ) do
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
-- If the EventData is for a UNIT, the call directly the EventClass EventFunction for that UNIT.
if Event.IniDCSUnitName and EventData.IniUnit and EventData.IniUnit[Event.IniDCSUnitName] then
-- First test if a EventFunction is Set, otherwise search for the default function
if EventData.IniUnit[Event.IniDCSUnitName].EventFunction then
self:E( { "Calling EventFunction for Class ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
self:E( { "Calling EventFunction for UNIT ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
local Result, Value = xpcall(
function()
@ -1193,7 +1241,38 @@ function EVENT:onEvent( Event )
-- Now call the default event function.
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
local Result, Value = xpcall(
function()
return EventFunction( EventClass, Event )
end, ErrorHandler )
end
end
else
-- If the EventData is for a GROUP, the call directly the EventClass EventFunction for the UNIT in that GROUP.
if Event.IniDCSUnitName and Event.IniDCSGroupName and Event.IniGroupName and EventData.IniGroup and EventData.IniGroup[Event.IniGroupName] then
-- First test if a EventFunction is Set, otherwise search for the default function
if EventData.IniGroup[Event.IniGroupName].EventFunction then
self:E( { "Calling EventFunction for GROUP ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
local Result, Value = xpcall(
function()
return EventData.IniGroup[Event.IniGroupName].EventFunction( EventClass, Event )
end, ErrorHandler )
else
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
local EventFunction = EventClass[ _EVENTMETA[Event.id].Event ]
if EventFunction and type( EventFunction ) == "function" then
-- Now call the default event function.
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for GROUP ", EventClass:GetClassNameAndID(), EventPriority } )
local Result, Value = xpcall(
function()
@ -1216,7 +1295,6 @@ function EVENT:onEvent( Event )
-- There is an EventFunction defined, so call the EventFunction.
self:E( { "Calling EventFunction for Class ", EventClass:GetClassNameAndID(), EventPriority } )
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
local Result, Value = xpcall(
function()
@ -1230,7 +1308,6 @@ function EVENT:onEvent( Event )
-- Now call the default event function.
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
local Result, Value = xpcall(
function()
@ -1244,6 +1321,7 @@ function EVENT:onEvent( Event )
end
end
end
end
else
self:E( { _EVENTMETA[Event.id].Text, Event } )
end

View File

@ -76,6 +76,9 @@
--
-- Hereby the change log:
--
-- 2017-03-07: GROUP:**HandleEvent( Event, EventFunction )** added.
-- 2017-03-07: GROUP:**UnHandleEvent( Event )** added.
--
-- 2017-01-24: GROUP:**SetAIOnOff( AIOnOff )** added.
--
-- 2017-01-24: GROUP:**SetAIOn()** added.
@ -897,4 +900,29 @@ function GROUP:OnReSpawn( ReSpawnFunction )
self.ReSpawnFunction = ReSpawnFunction
end
do -- Event Handling
--- Subscribe to a DCS Event.
-- @param #GROUP self
-- @param Core.Event#EVENTS Event
-- @param #function EventFunction (optional) The function to be called when the event occurs for the GROUP.
-- @return #GROUP
function GROUP:HandleEvent( Event, EventFunction )
self:EventDispatcher():OnEventForGroup( self:GetName(), EventFunction, self, Event )
return self
end
--- UnSubscribe to a DCS event.
-- @param #GROUP self
-- @param Core.Event#EVENTS Event
-- @return #GROUP
function GROUP:UnHandleEvent( Event )
self:EventDispatcher():RemoveForGroup( self:GetName(), self, Event )
return self
end
end

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170306_1631' )
env.info( 'Moose Generation Timestamp: 20170307_0923' )
local base = _G
Include = {}
@ -4086,6 +4086,13 @@ end
-- * @{Base#BASE.HandleEvent}(): Subscribe to a DCS Event.
-- * @{Base#BASE.UnHandleEvent}(): Unsubscribe from a DCS Event.
--
-- Note that for a UNIT, the event will be handled **for that UNIT only**!
-- Note that for a GROUP, the event will be handled **for all the UNITs in that GROUP only**!
--
-- For all objects of other classes, the subscribed events will be handled for **all UNITs within the Mission**!
-- So if a UNIT within the mission has the subscribed event for that object,
-- then the object event handler will receive the event for that UNIT!
--
-- ### 1.3.2 Event Handling of DCS Events
--
-- Once the class is subscribed to the event, an **Event Handling** method on the object or class needs to be written that will be called
@ -4186,7 +4193,9 @@ end
--
-- Hereby the change log:
--
-- * 2016-02-07: Did a complete revision of the Event Handing API and underlying mechanisms.
-- * 2017-03-07: Added the correct event dispatching in case the event is subscribed by a GROUP.
--
-- * 2017-02-07: Did a complete revision of the Event Handing API and underlying mechanisms.
--
-- ===
--
@ -4200,10 +4209,6 @@ end
--
-- @module Event
-- TODO: Need to update the EVENTDATA documentation with IniPlayerName and TgtPlayerName
-- TODO: Need to update the EVENTDATA documentation with IniObjectCategory and TgtObjectCategory
--- The EVENT structure
-- @type EVENT
@ -4464,8 +4469,9 @@ function EVENT:Remove( EventClass, EventID )
self.Events[EventID][EventPriority][EventClass] = nil
end
--- Removes an Events entry for a Unit
--- Removes an Events entry for a UNIT.
-- @param #EVENT self
-- @param #string UnitName The name of the UNIT.
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param Dcs.DCSWorld#world.event EventID
-- @return #EVENT.Events
@ -4478,6 +4484,21 @@ function EVENT:RemoveForUnit( UnitName, EventClass, EventID )
Event.IniUnit[UnitName] = nil
end
--- Removes an Events entry for a GROUP.
-- @param #EVENT self
-- @param #string GroupName The name of the GROUP.
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param Dcs.DCSWorld#world.event EventID
-- @return #EVENT.Events
function EVENT:RemoveForGroup( GroupName, EventClass, EventID )
self:F3( { EventClass, _EVENTMETA[EventID].Text } )
local EventClass = EventClass
local EventPriority = EventClass:GetEventPriority()
local Event = self.Events[EventID][EventPriority][EventClass]
Event.IniGroup[GroupName] = nil
end
--- Clears all event subscriptions for a @{Base#BASE} derived object.
-- @param #EVENT self
-- @param Core.Base#BASE EventObject
@ -4526,23 +4547,43 @@ function EVENT:OnEventGeneric( EventFunction, EventClass, EventID )
end
--- Set a new listener for an S_EVENT_X event
--- Set a new listener for an S_EVENT_X event for a UNIT.
-- @param #EVENT self
-- @param #string EventDCSUnitName
-- @param #function EventFunction The function to be called when the event occurs for the unit.
-- @param #string UnitName The name of the UNIT.
-- @param #function EventFunction The function to be called when the event occurs for the GROUP.
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param EventID
-- @return #EVENT
function EVENT:OnEventForUnit( EventDCSUnitName, EventFunction, EventClass, EventID )
self:F2( EventDCSUnitName )
function EVENT:OnEventForUnit( UnitName, EventFunction, EventClass, EventID )
self:F2( UnitName )
local Event = self:Init( EventID, EventClass )
if not Event.IniUnit then
Event.IniUnit = {}
end
Event.IniUnit[EventDCSUnitName] = {}
Event.IniUnit[EventDCSUnitName].EventFunction = EventFunction
Event.IniUnit[EventDCSUnitName].EventClass = EventClass
Event.IniUnit[UnitName] = {}
Event.IniUnit[UnitName].EventFunction = EventFunction
Event.IniUnit[UnitName].EventClass = EventClass
return self
end
--- Set a new listener for an S_EVENT_X event for a GROUP.
-- @param #EVENT self
-- @param #string GroupName The name of the GROUP.
-- @param #function EventFunction The function to be called when the event occurs for the GROUP.
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param EventID
-- @return #EVENT
function EVENT:OnEventForGroup( GroupName, EventFunction, EventClass, EventID )
self:F2( GroupName )
local Event = self:Init( EventID, EventClass )
if not Event.IniGroup then
Event.IniGroup = {}
end
Event.IniGroup[GroupName] = {}
Event.IniGroup[GroupName].EventFunction = EventFunction
Event.IniGroup[GroupName].EventClass = EventClass
return self
end
@ -5105,7 +5146,9 @@ function EVENT:onEvent( Event )
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
Event.IniDCSGroupName = Event.IniDCSGroup:getName()
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
self:E( { IniGroup = Event.IniGroup } )
if Event.IniGroup then
Event.IniGroupName = Event.IniDCSGroupName
end
end
Event.IniPlayerName = Event.IniDCSUnit:getPlayerName()
Event.IniCoalition = Event.IniDCSUnit:getCoalition()
@ -5146,6 +5189,10 @@ function EVENT:onEvent( Event )
Event.TgtDCSGroupName = ""
if Event.TgtDCSGroup and Event.TgtDCSGroup:isExist() then
Event.TgtDCSGroupName = Event.TgtDCSGroup:getName()
Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName )
if Event.TgtGroup then
Event.TgtGroupName = Event.TgtDCSGroupName
end
end
Event.TgtPlayerName = Event.TgtDCSUnit:getPlayerName()
Event.TgtCoalition = Event.TgtDCSUnit:getCoalition()
@ -5192,14 +5239,15 @@ function EVENT:onEvent( Event )
-- Okay, we got the event from DCS. Now loop the SORTED self.EventSorted[] table for the received Event.id, and for each EventData registered, check if a function needs to be called.
for EventClass, EventData in pairs( self.Events[Event.id][EventPriority] ) do
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
-- If the EventData is for a UNIT, the call directly the EventClass EventFunction for that UNIT.
if Event.IniDCSUnitName and EventData.IniUnit and EventData.IniUnit[Event.IniDCSUnitName] then
-- First test if a EventFunction is Set, otherwise search for the default function
if EventData.IniUnit[Event.IniDCSUnitName].EventFunction then
self:E( { "Calling EventFunction for Class ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
self:E( { "Calling EventFunction for UNIT ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
local Result, Value = xpcall(
function()
@ -5214,7 +5262,38 @@ function EVENT:onEvent( Event )
-- Now call the default event function.
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
local Result, Value = xpcall(
function()
return EventFunction( EventClass, Event )
end, ErrorHandler )
end
end
else
-- If the EventData is for a GROUP, the call directly the EventClass EventFunction for the UNIT in that GROUP.
if Event.IniDCSUnitName and Event.IniDCSGroupName and Event.IniGroupName and EventData.IniGroup and EventData.IniGroup[Event.IniGroupName] then
-- First test if a EventFunction is Set, otherwise search for the default function
if EventData.IniGroup[Event.IniGroupName].EventFunction then
self:E( { "Calling EventFunction for GROUP ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
local Result, Value = xpcall(
function()
return EventData.IniGroup[Event.IniGroupName].EventFunction( EventClass, Event )
end, ErrorHandler )
else
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
local EventFunction = EventClass[ _EVENTMETA[Event.id].Event ]
if EventFunction and type( EventFunction ) == "function" then
-- Now call the default event function.
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for GROUP ", EventClass:GetClassNameAndID(), EventPriority } )
local Result, Value = xpcall(
function()
@ -5237,7 +5316,6 @@ function EVENT:onEvent( Event )
-- There is an EventFunction defined, so call the EventFunction.
self:E( { "Calling EventFunction for Class ", EventClass:GetClassNameAndID(), EventPriority } )
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
local Result, Value = xpcall(
function()
@ -5251,7 +5329,6 @@ function EVENT:onEvent( Event )
-- Now call the default event function.
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
local Result, Value = xpcall(
function()
@ -5265,6 +5342,7 @@ function EVENT:onEvent( Event )
end
end
end
end
else
self:E( { _EVENTMETA[Event.id].Text, Event } )
end
@ -15657,6 +15735,9 @@ end
--
-- Hereby the change log:
--
-- 2017-03-07: GROUP:**HandleEvent( Event, EventFunction )** added.
-- 2017-03-07: GROUP:**UnHandleEvent( Event )** added.
--
-- 2017-01-24: GROUP:**SetAIOnOff( AIOnOff )** added.
--
-- 2017-01-24: GROUP:**SetAIOn()** added.
@ -16478,7 +16559,32 @@ function GROUP:OnReSpawn( ReSpawnFunction )
self.ReSpawnFunction = ReSpawnFunction
end
do -- Event Handling
--- Subscribe to a DCS Event.
-- @param #GROUP self
-- @param Core.Event#EVENTS Event
-- @param #function EventFunction (optional) The function to be called when the event occurs for the GROUP.
-- @return #GROUP
function GROUP:HandleEvent( Event, EventFunction )
self:EventDispatcher():OnEventForGroup( self:GetName(), EventFunction, self, Event )
return self
end
--- UnSubscribe to a DCS event.
-- @param #GROUP self
-- @param Core.Event#EVENTS Event
-- @return #GROUP
function GROUP:UnHandleEvent( Event )
self:EventDispatcher():RemoveForGroup( self:GetName(), self, Event )
return self
end
end
--- This module contains the UNIT class.
--
-- 1) @{#UNIT} class, extends @{Controllable#CONTROLLABLE}
@ -26484,11 +26590,14 @@ end
--
-- * **None** ( Group ): The process is not started yet.
-- * **Patrolling** ( Group ): The AI is patrolling the Patrol Zone.
-- * **Returning** ( Group ): The AI is returning to Base..
-- * **Returning** ( Group ): The AI is returning to Base.
-- * **Stopped** ( Group ): The process is stopped.
-- * **Crashed** ( Group ): The AI has crashed or is dead.
--
-- ### 1.2.2) AI_PATROL_ZONE Events
--
-- * **Start** ( Group ): Start the process.
-- * **Stop** ( Group ): Stop the process.
-- * **Route** ( Group ): Route the AI to a new random 3D point within the Patrol Zone.
-- * **RTB** ( Group ): Route the AI to the home base.
-- * **Detect** ( Group ): The AI is detecting targets.
@ -26635,6 +26744,51 @@ function AI_PATROL_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltit
self:SetStartState( "None" )
self:AddTransition( "*", "Stop", "Stopped" )
--- OnLeave Transition Handler for State Stopped.
-- @function [parent=#AI_PATROL_ZONE] OnLeaveStopped
-- @param #AI_PATROL_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 Stopped.
-- @function [parent=#AI_PATROL_ZONE] OnEnterStopped
-- @param #AI_PATROL_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 Transition Handler for Event Stop.
-- @function [parent=#AI_PATROL_ZONE] OnBeforeStop
-- @param #AI_PATROL_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 Stop.
-- @function [parent=#AI_PATROL_ZONE] OnAfterStop
-- @param #AI_PATROL_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 Stop.
-- @function [parent=#AI_PATROL_ZONE] Stop
-- @param #AI_PATROL_ZONE self
--- Asynchronous Event Trigger for Event Stop.
-- @function [parent=#AI_PATROL_ZONE] __Stop
-- @param #AI_PATROL_ZONE self
-- @param #number Delay The delay in seconds.
self:AddTransition( "None", "Start", "Patrolling" )
--- OnBefore Transition Handler for Event Start.

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170306_1631' )
env.info( 'Moose Generation Timestamp: 20170307_0923' )
local base = _G
Include = {}
@ -4086,6 +4086,13 @@ end
-- * @{Base#BASE.HandleEvent}(): Subscribe to a DCS Event.
-- * @{Base#BASE.UnHandleEvent}(): Unsubscribe from a DCS Event.
--
-- Note that for a UNIT, the event will be handled **for that UNIT only**!
-- Note that for a GROUP, the event will be handled **for all the UNITs in that GROUP only**!
--
-- For all objects of other classes, the subscribed events will be handled for **all UNITs within the Mission**!
-- So if a UNIT within the mission has the subscribed event for that object,
-- then the object event handler will receive the event for that UNIT!
--
-- ### 1.3.2 Event Handling of DCS Events
--
-- Once the class is subscribed to the event, an **Event Handling** method on the object or class needs to be written that will be called
@ -4186,7 +4193,9 @@ end
--
-- Hereby the change log:
--
-- * 2016-02-07: Did a complete revision of the Event Handing API and underlying mechanisms.
-- * 2017-03-07: Added the correct event dispatching in case the event is subscribed by a GROUP.
--
-- * 2017-02-07: Did a complete revision of the Event Handing API and underlying mechanisms.
--
-- ===
--
@ -4200,10 +4209,6 @@ end
--
-- @module Event
-- TODO: Need to update the EVENTDATA documentation with IniPlayerName and TgtPlayerName
-- TODO: Need to update the EVENTDATA documentation with IniObjectCategory and TgtObjectCategory
--- The EVENT structure
-- @type EVENT
@ -4464,8 +4469,9 @@ function EVENT:Remove( EventClass, EventID )
self.Events[EventID][EventPriority][EventClass] = nil
end
--- Removes an Events entry for a Unit
--- Removes an Events entry for a UNIT.
-- @param #EVENT self
-- @param #string UnitName The name of the UNIT.
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param Dcs.DCSWorld#world.event EventID
-- @return #EVENT.Events
@ -4478,6 +4484,21 @@ function EVENT:RemoveForUnit( UnitName, EventClass, EventID )
Event.IniUnit[UnitName] = nil
end
--- Removes an Events entry for a GROUP.
-- @param #EVENT self
-- @param #string GroupName The name of the GROUP.
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param Dcs.DCSWorld#world.event EventID
-- @return #EVENT.Events
function EVENT:RemoveForGroup( GroupName, EventClass, EventID )
self:F3( { EventClass, _EVENTMETA[EventID].Text } )
local EventClass = EventClass
local EventPriority = EventClass:GetEventPriority()
local Event = self.Events[EventID][EventPriority][EventClass]
Event.IniGroup[GroupName] = nil
end
--- Clears all event subscriptions for a @{Base#BASE} derived object.
-- @param #EVENT self
-- @param Core.Base#BASE EventObject
@ -4526,23 +4547,43 @@ function EVENT:OnEventGeneric( EventFunction, EventClass, EventID )
end
--- Set a new listener for an S_EVENT_X event
--- Set a new listener for an S_EVENT_X event for a UNIT.
-- @param #EVENT self
-- @param #string EventDCSUnitName
-- @param #function EventFunction The function to be called when the event occurs for the unit.
-- @param #string UnitName The name of the UNIT.
-- @param #function EventFunction The function to be called when the event occurs for the GROUP.
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param EventID
-- @return #EVENT
function EVENT:OnEventForUnit( EventDCSUnitName, EventFunction, EventClass, EventID )
self:F2( EventDCSUnitName )
function EVENT:OnEventForUnit( UnitName, EventFunction, EventClass, EventID )
self:F2( UnitName )
local Event = self:Init( EventID, EventClass )
if not Event.IniUnit then
Event.IniUnit = {}
end
Event.IniUnit[EventDCSUnitName] = {}
Event.IniUnit[EventDCSUnitName].EventFunction = EventFunction
Event.IniUnit[EventDCSUnitName].EventClass = EventClass
Event.IniUnit[UnitName] = {}
Event.IniUnit[UnitName].EventFunction = EventFunction
Event.IniUnit[UnitName].EventClass = EventClass
return self
end
--- Set a new listener for an S_EVENT_X event for a GROUP.
-- @param #EVENT self
-- @param #string GroupName The name of the GROUP.
-- @param #function EventFunction The function to be called when the event occurs for the GROUP.
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param EventID
-- @return #EVENT
function EVENT:OnEventForGroup( GroupName, EventFunction, EventClass, EventID )
self:F2( GroupName )
local Event = self:Init( EventID, EventClass )
if not Event.IniGroup then
Event.IniGroup = {}
end
Event.IniGroup[GroupName] = {}
Event.IniGroup[GroupName].EventFunction = EventFunction
Event.IniGroup[GroupName].EventClass = EventClass
return self
end
@ -5105,7 +5146,9 @@ function EVENT:onEvent( Event )
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
Event.IniDCSGroupName = Event.IniDCSGroup:getName()
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
self:E( { IniGroup = Event.IniGroup } )
if Event.IniGroup then
Event.IniGroupName = Event.IniDCSGroupName
end
end
Event.IniPlayerName = Event.IniDCSUnit:getPlayerName()
Event.IniCoalition = Event.IniDCSUnit:getCoalition()
@ -5146,6 +5189,10 @@ function EVENT:onEvent( Event )
Event.TgtDCSGroupName = ""
if Event.TgtDCSGroup and Event.TgtDCSGroup:isExist() then
Event.TgtDCSGroupName = Event.TgtDCSGroup:getName()
Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName )
if Event.TgtGroup then
Event.TgtGroupName = Event.TgtDCSGroupName
end
end
Event.TgtPlayerName = Event.TgtDCSUnit:getPlayerName()
Event.TgtCoalition = Event.TgtDCSUnit:getCoalition()
@ -5192,14 +5239,15 @@ function EVENT:onEvent( Event )
-- Okay, we got the event from DCS. Now loop the SORTED self.EventSorted[] table for the received Event.id, and for each EventData registered, check if a function needs to be called.
for EventClass, EventData in pairs( self.Events[Event.id][EventPriority] ) do
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
-- If the EventData is for a UNIT, the call directly the EventClass EventFunction for that UNIT.
if Event.IniDCSUnitName and EventData.IniUnit and EventData.IniUnit[Event.IniDCSUnitName] then
-- First test if a EventFunction is Set, otherwise search for the default function
if EventData.IniUnit[Event.IniDCSUnitName].EventFunction then
self:E( { "Calling EventFunction for Class ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
self:E( { "Calling EventFunction for UNIT ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
local Result, Value = xpcall(
function()
@ -5214,7 +5262,38 @@ function EVENT:onEvent( Event )
-- Now call the default event function.
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
local Result, Value = xpcall(
function()
return EventFunction( EventClass, Event )
end, ErrorHandler )
end
end
else
-- If the EventData is for a GROUP, the call directly the EventClass EventFunction for the UNIT in that GROUP.
if Event.IniDCSUnitName and Event.IniDCSGroupName and Event.IniGroupName and EventData.IniGroup and EventData.IniGroup[Event.IniGroupName] then
-- First test if a EventFunction is Set, otherwise search for the default function
if EventData.IniGroup[Event.IniGroupName].EventFunction then
self:E( { "Calling EventFunction for GROUP ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName, EventPriority } )
local Result, Value = xpcall(
function()
return EventData.IniGroup[Event.IniGroupName].EventFunction( EventClass, Event )
end, ErrorHandler )
else
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
local EventFunction = EventClass[ _EVENTMETA[Event.id].Event ]
if EventFunction and type( EventFunction ) == "function" then
-- Now call the default event function.
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for GROUP ", EventClass:GetClassNameAndID(), EventPriority } )
local Result, Value = xpcall(
function()
@ -5237,7 +5316,6 @@ function EVENT:onEvent( Event )
-- There is an EventFunction defined, so call the EventFunction.
self:E( { "Calling EventFunction for Class ", EventClass:GetClassNameAndID(), EventPriority } )
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
local Result, Value = xpcall(
function()
@ -5251,7 +5329,6 @@ function EVENT:onEvent( Event )
-- Now call the default event function.
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName )
local Result, Value = xpcall(
function()
@ -5265,6 +5342,7 @@ function EVENT:onEvent( Event )
end
end
end
end
else
self:E( { _EVENTMETA[Event.id].Text, Event } )
end
@ -15657,6 +15735,9 @@ end
--
-- Hereby the change log:
--
-- 2017-03-07: GROUP:**HandleEvent( Event, EventFunction )** added.
-- 2017-03-07: GROUP:**UnHandleEvent( Event )** added.
--
-- 2017-01-24: GROUP:**SetAIOnOff( AIOnOff )** added.
--
-- 2017-01-24: GROUP:**SetAIOn()** added.
@ -16478,7 +16559,32 @@ function GROUP:OnReSpawn( ReSpawnFunction )
self.ReSpawnFunction = ReSpawnFunction
end
do -- Event Handling
--- Subscribe to a DCS Event.
-- @param #GROUP self
-- @param Core.Event#EVENTS Event
-- @param #function EventFunction (optional) The function to be called when the event occurs for the GROUP.
-- @return #GROUP
function GROUP:HandleEvent( Event, EventFunction )
self:EventDispatcher():OnEventForGroup( self:GetName(), EventFunction, self, Event )
return self
end
--- UnSubscribe to a DCS event.
-- @param #GROUP self
-- @param Core.Event#EVENTS Event
-- @return #GROUP
function GROUP:UnHandleEvent( Event )
self:EventDispatcher():RemoveForGroup( self:GetName(), self, Event )
return self
end
end
--- This module contains the UNIT class.
--
-- 1) @{#UNIT} class, extends @{Controllable#CONTROLLABLE}
@ -26484,11 +26590,14 @@ end
--
-- * **None** ( Group ): The process is not started yet.
-- * **Patrolling** ( Group ): The AI is patrolling the Patrol Zone.
-- * **Returning** ( Group ): The AI is returning to Base..
-- * **Returning** ( Group ): The AI is returning to Base.
-- * **Stopped** ( Group ): The process is stopped.
-- * **Crashed** ( Group ): The AI has crashed or is dead.
--
-- ### 1.2.2) AI_PATROL_ZONE Events
--
-- * **Start** ( Group ): Start the process.
-- * **Stop** ( Group ): Stop the process.
-- * **Route** ( Group ): Route the AI to a new random 3D point within the Patrol Zone.
-- * **RTB** ( Group ): Route the AI to the home base.
-- * **Detect** ( Group ): The AI is detecting targets.
@ -26635,6 +26744,51 @@ function AI_PATROL_ZONE:New( PatrolZone, PatrolFloorAltitude, PatrolCeilingAltit
self:SetStartState( "None" )
self:AddTransition( "*", "Stop", "Stopped" )
--- OnLeave Transition Handler for State Stopped.
-- @function [parent=#AI_PATROL_ZONE] OnLeaveStopped
-- @param #AI_PATROL_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 Stopped.
-- @function [parent=#AI_PATROL_ZONE] OnEnterStopped
-- @param #AI_PATROL_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 Transition Handler for Event Stop.
-- @function [parent=#AI_PATROL_ZONE] OnBeforeStop
-- @param #AI_PATROL_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 Stop.
-- @function [parent=#AI_PATROL_ZONE] OnAfterStop
-- @param #AI_PATROL_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 Stop.
-- @function [parent=#AI_PATROL_ZONE] Stop
-- @param #AI_PATROL_ZONE self
--- Asynchronous Event Trigger for Event Stop.
-- @function [parent=#AI_PATROL_ZONE] __Stop
-- @param #AI_PATROL_ZONE self
-- @param #number Delay The delay in seconds.
self:AddTransition( "None", "Start", "Patrolling" )
--- OnBefore Transition Handler for Event Start.

View File

@ -1,7 +1,7 @@
---
-- Name: EVT-100 - OnEventShot Example
-- Name: EVT-100 - UNIT OnEventShot Example
-- Author: FlightControl
-- Date Created: 7 February 2017
-- Date Created: 7 Feb 2017
--
-- # Situation:
--

View File

@ -1,7 +1,7 @@
---
-- Name: EVT-101 - OnEventHit Example
-- Name: EVT-101 - UNIT OnEventHit Example
-- Author: FlightControl
-- Date Created: 7 February 2017
-- Date Created: 7 Feb 2017
--
-- # Situation:
--

View File

@ -1,7 +1,7 @@
---
-- Name: EVT-102 - OnEventTakeoff Example
-- Name: EVT-102 - UNIT OnEventTakeoff Example
-- Author: FlightControl
-- Date Created: 7 February 2017
-- Date Created: 7 Feb 2017
--
-- # Situation:
--

View File

@ -1,7 +1,7 @@
---
-- Name: EVT-103 - OnEventLand Example
-- Name: EVT-103 - UNIT OnEventLand Example
-- Author: FlightControl
-- Date Created: 7 February 2017
-- Date Created: 7 Feb 2017
--
-- # Situation:
--

View File

@ -1,7 +1,7 @@
---
-- Name: EVT-104 - OnEventCrash Example
-- Name: EVT-104 - UNIT OnEventCrash Example
-- Author: FlightControl
-- Date Created: 7 February 2017
-- Date Created: 7 Feb 2017
--
-- # Situation:
--

View File

@ -0,0 +1,28 @@
---
-- Name: EVT-200 - GROUP OnEventShot Example
-- Author: FlightControl
-- Date Created: 07 Mar 2017
--
-- # Situation:
--
-- Two groups of planes are flying in the air and shoot an missile to a multitude of ground targets.
--
-- # Test cases:
--
-- 1. Observe the planes shooting the missile.
-- 2. Observe when the planes shoots the missile, a dcs.log entry is written in the logging.
-- 3. Check the contents of the fields of the S_EVENT_SHOT entry.
-- 4. The planes of GROUP "Group Plane A", should only send a message when they shoot a missile.
-- 5. The planes of GROUP "Group Plane B", should NOT send a message when they shoot a missile.
local PlaneGroup = GROUP:FindByName( "Group Plane A" )
PlaneGroup:HandleEvent( EVENTS.Shot )
function PlaneGroup:OnEventShot( EventData )
self:E( "I just fired a missile and I am part of " .. EventData.IniGroupName )
EventData.IniUnit:MessageToAll( "I just fired a missile and I am part of " .. EventData.IniGroupName, 15, "Alert!" )
end

View File

@ -129,13 +129,16 @@ When the fuel treshold has been reached, the airplane will fly towards the neare
<ul>
<li><strong>None</strong> ( Group ): The process is not started yet.</li>
<li><strong>Patrolling</strong> ( Group ): The AI is patrolling the Patrol Zone.</li>
<li><strong>Returning</strong> ( Group ): The AI is returning to Base..</li>
<li><strong>Returning</strong> ( Group ): The AI is returning to Base.</li>
<li><strong>Stopped</strong> ( Group ): The process is stopped.</li>
<li><strong>Crashed</strong> ( Group ): The AI has crashed or is dead.</li>
</ul>
<h3>1.2.2) AI<em>PATROL</em>ZONE Events</h3>
<ul>
<li><strong>Start</strong> ( Group ): Start the process.</li>
<li><strong>Stop</strong> ( Group ): Stop the process.</li>
<li><strong>Route</strong> ( Group ): Route the AI to a new random 3D point within the Patrol Zone.</li>
<li><strong>RTB</strong> ( Group ): Route the AI to the home base.</li>
<li><strong>Detect</strong> ( Group ): The AI is detecting targets.</li>
@ -380,6 +383,12 @@ Use the method <a href="##(AI_PATROL_ZONE).ManageDamage">AI<em>PATROL</em>ZONE.M
<td class="name" nowrap="nowrap"><a href="##(AI_PATROL_ZONE).OnAfterStatus">AI_PATROL_ZONE:OnAfterStatus(Controllable, From, Event, To)</a></td>
<td class="summary">
<p>OnAfter Transition Handler for Event Status.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(AI_PATROL_ZONE).OnAfterStop">AI_PATROL_ZONE:OnAfterStop(Controllable, From, Event, To)</a></td>
<td class="summary">
<p>OnAfter Transition Handler for Event Stop.</p>
</td>
</tr>
<tr>
@ -416,6 +425,12 @@ Use the method <a href="##(AI_PATROL_ZONE).ManageDamage">AI<em>PATROL</em>ZONE.M
<td class="name" nowrap="nowrap"><a href="##(AI_PATROL_ZONE).OnBeforeStatus">AI_PATROL_ZONE:OnBeforeStatus(Controllable, From, Event, To)</a></td>
<td class="summary">
<p>OnBefore Transition Handler for Event Status.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(AI_PATROL_ZONE).OnBeforeStop">AI_PATROL_ZONE:OnBeforeStop(Controllable, From, Event, To)</a></td>
<td class="summary">
<p>OnBefore Transition Handler for Event Stop.</p>
</td>
</tr>
<tr>
@ -440,6 +455,12 @@ Use the method <a href="##(AI_PATROL_ZONE).ManageDamage">AI<em>PATROL</em>ZONE.M
<td class="name" nowrap="nowrap"><a href="##(AI_PATROL_ZONE).OnEnterReturning">AI_PATROL_ZONE:OnEnterReturning(Controllable, From, Event, To)</a></td>
<td class="summary">
<p>OnEnter Transition Handler for State Returning.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(AI_PATROL_ZONE).OnEnterStopped">AI_PATROL_ZONE:OnEnterStopped(Controllable, From, Event, To)</a></td>
<td class="summary">
<p>OnEnter Transition Handler for State Stopped.</p>
</td>
</tr>
<tr>
@ -452,6 +473,12 @@ Use the method <a href="##(AI_PATROL_ZONE).ManageDamage">AI<em>PATROL</em>ZONE.M
<td class="name" nowrap="nowrap"><a href="##(AI_PATROL_ZONE).OnLeaveReturning">AI_PATROL_ZONE:OnLeaveReturning(Controllable, From, Event, To)</a></td>
<td class="summary">
<p>OnLeave Transition Handler for State Returning.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(AI_PATROL_ZONE).OnLeaveStopped">AI_PATROL_ZONE:OnLeaveStopped(Controllable, From, Event, To)</a></td>
<td class="summary">
<p>OnLeave Transition Handler for State Stopped.</p>
</td>
</tr>
<tr>
@ -602,6 +629,12 @@ Use the method <a href="##(AI_PATROL_ZONE).ManageDamage">AI<em>PATROL</em>ZONE.M
<td class="name" nowrap="nowrap"><a href="##(AI_PATROL_ZONE).Status">AI_PATROL_ZONE:Status()</a></td>
<td class="summary">
<p>Synchronous Event Trigger for Event Status.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(AI_PATROL_ZONE).Stop">AI_PATROL_ZONE:Stop()</a></td>
<td class="summary">
<p>Synchronous Event Trigger for Event Stop.</p>
</td>
</tr>
<tr>
@ -644,6 +677,12 @@ Use the method <a href="##(AI_PATROL_ZONE).ManageDamage">AI<em>PATROL</em>ZONE.M
<td class="name" nowrap="nowrap"><a href="##(AI_PATROL_ZONE).__Status">AI_PATROL_ZONE:__Status(Delay)</a></td>
<td class="summary">
<p>Asynchronous Event Trigger for Event Status.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(AI_PATROL_ZONE).__Stop">AI_PATROL_ZONE:__Stop(Delay)</a></td>
<td class="summary">
<p>Asynchronous Event Trigger for Event Stop.</p>
</td>
</tr>
<tr>
@ -1286,6 +1325,46 @@ The To State string.</p>
<dl class="function">
<dt>
<a id="#(AI_PATROL_ZONE).OnAfterStop" >
<strong>AI_PATROL_ZONE:OnAfterStop(Controllable, From, Event, To)</strong>
</a>
</dt>
<dd>
<p>OnAfter Transition Handler for Event Stop.</p>
<h3>Parameters</h3>
<ul>
<li>
<p><code><em><a href="Wrapper.Controllable.html##(CONTROLLABLE)">Wrapper.Controllable#CONTROLLABLE</a> Controllable </em></code>:
The Controllable Object managed by the FSM.</p>
</li>
<li>
<p><code><em>#string From </em></code>:
The From State string.</p>
</li>
<li>
<p><code><em>#string Event </em></code>:
The Event string.</p>
</li>
<li>
<p><code><em>#string To </em></code>:
The To State string.</p>
</li>
</ul>
</dd>
</dl>
<dl class="function">
<dt>
<a id="#(AI_PATROL_ZONE).OnBeforeDetect" >
<strong>AI_PATROL_ZONE:OnBeforeDetect(Controllable, From, Event, To)</strong>
</a>
@ -1556,6 +1635,51 @@ Return false to cancel Transition.</p>
<dl class="function">
<dt>
<a id="#(AI_PATROL_ZONE).OnBeforeStop" >
<strong>AI_PATROL_ZONE:OnBeforeStop(Controllable, From, Event, To)</strong>
</a>
</dt>
<dd>
<p>OnBefore Transition Handler for Event Stop.</p>
<h3>Parameters</h3>
<ul>
<li>
<p><code><em><a href="Wrapper.Controllable.html##(CONTROLLABLE)">Wrapper.Controllable#CONTROLLABLE</a> Controllable </em></code>:
The Controllable Object managed by the FSM.</p>
</li>
<li>
<p><code><em>#string From </em></code>:
The From State string.</p>
</li>
<li>
<p><code><em>#string Event </em></code>:
The Event string.</p>
</li>
<li>
<p><code><em>#string To </em></code>:
The To State string.</p>
</li>
</ul>
<h3>Return value</h3>
<p><em>#boolean:</em>
Return false to cancel Transition.</p>
</dd>
</dl>
<dl class="function">
<dt>
<a id="#(AI_PATROL_ZONE).OnCrash" >
<strong>AI_PATROL_ZONE:OnCrash(EventData)</strong>
</a>
@ -1678,6 +1802,46 @@ The To State string.</p>
<dl class="function">
<dt>
<a id="#(AI_PATROL_ZONE).OnEnterStopped" >
<strong>AI_PATROL_ZONE:OnEnterStopped(Controllable, From, Event, To)</strong>
</a>
</dt>
<dd>
<p>OnEnter Transition Handler for State Stopped.</p>
<h3>Parameters</h3>
<ul>
<li>
<p><code><em><a href="Wrapper.Controllable.html##(CONTROLLABLE)">Wrapper.Controllable#CONTROLLABLE</a> Controllable </em></code>:
The Controllable Object managed by the FSM.</p>
</li>
<li>
<p><code><em>#string From </em></code>:
The From State string.</p>
</li>
<li>
<p><code><em>#string Event </em></code>:
The Event string.</p>
</li>
<li>
<p><code><em>#string To </em></code>:
The To State string.</p>
</li>
</ul>
</dd>
</dl>
<dl class="function">
<dt>
<a id="#(AI_PATROL_ZONE).OnLeavePatrolling" >
<strong>AI_PATROL_ZONE:OnLeavePatrolling(Controllable, From, Event, To)</strong>
</a>
@ -1768,6 +1932,51 @@ Return false to cancel Transition.</p>
<dl class="function">
<dt>
<a id="#(AI_PATROL_ZONE).OnLeaveStopped" >
<strong>AI_PATROL_ZONE:OnLeaveStopped(Controllable, From, Event, To)</strong>
</a>
</dt>
<dd>
<p>OnLeave Transition Handler for State Stopped.</p>
<h3>Parameters</h3>
<ul>
<li>
<p><code><em><a href="Wrapper.Controllable.html##(CONTROLLABLE)">Wrapper.Controllable#CONTROLLABLE</a> Controllable </em></code>:
The Controllable Object managed by the FSM.</p>
</li>
<li>
<p><code><em>#string From </em></code>:
The From State string.</p>
</li>
<li>
<p><code><em>#string Event </em></code>:
The Event string.</p>
</li>
<li>
<p><code><em>#string To </em></code>:
The To State string.</p>
</li>
</ul>
<h3>Return value</h3>
<p><em>#boolean:</em>
Return false to cancel Transition.</p>
</dd>
</dl>
<dl class="function">
<dt>
<a id="#(AI_PATROL_ZONE).OnPilotDead" >
<strong>AI_PATROL_ZONE:OnPilotDead(EventData)</strong>
</a>
@ -2226,6 +2435,19 @@ self</p>
<dl class="function">
<dt>
<a id="#(AI_PATROL_ZONE).Stop" >
<strong>AI_PATROL_ZONE:Stop()</strong>
</a>
</dt>
<dd>
<p>Synchronous Event Trigger for Event Stop.</p>
</dd>
</dl>
<dl class="function">
<dt>
<a id="#(AI_PATROL_ZONE)._NewPatrolRoute" >
<strong>AI_PATROL_ZONE._NewPatrolRoute(AIControllable, self)</strong>
</a>
@ -2386,6 +2608,28 @@ The delay in seconds.</p>
<dl class="function">
<dt>
<a id="#(AI_PATROL_ZONE).__Stop" >
<strong>AI_PATROL_ZONE:__Stop(Delay)</strong>
</a>
</dt>
<dd>
<p>Asynchronous Event Trigger for Event Stop.</p>
<h3>Parameter</h3>
<ul>
<li>
<p><code><em>#number Delay </em></code>:
The delay in seconds.</p>
</li>
</ul>
</dd>
</dl>
<dl class="function">
<dt>
<a id="#(AI_PATROL_ZONE).onafterDead" >
<strong>AI_PATROL_ZONE:onafterDead()</strong>
</a>

View File

@ -2425,7 +2425,6 @@ The UNIT carrying the package.</p>
<dl class="function">
<dt>
<em></em>
<a id="#(AI_CARGO_UNIT).CargoCarrier" >
<strong>AI_CARGO_UNIT.CargoCarrier</strong>
</a>

View File

@ -145,6 +145,13 @@ There are two functions which you use to subscribe to or unsubscribe from an eve
<li><a href="Base.html##(BASE).UnHandleEvent">Base#BASE.UnHandleEvent</a>(): Unsubscribe from a DCS Event.</li>
</ul>
<p>Note that for a UNIT, the event will be handled <strong>for that UNIT only</strong>!
Note that for a GROUP, the event will be handled <strong>for all the UNITs in that GROUP only</strong>!</p>
<p>For all objects of other classes, the subscribed events will be handled for <strong>all UNITs within the Mission</strong>!
So if a UNIT within the mission has the subscribed event for that object,
then the object event handler will receive the event for that UNIT!</p>
<h3>1.3.2 Event Handling of DCS Events</h3>
<p>Once the class is subscribed to the event, an <strong>Event Handling</strong> method on the object or class needs to be written that will be called
@ -252,7 +259,8 @@ YYYY-MM-DD: CLASS:<strong>NewFunction( Params )</strong> added</p>
<p>Hereby the change log:</p>
<ul>
<li>2016-02-07: Did a complete revision of the Event Handing API and underlying mechanisms.</li>
<li><p>2017-03-07: Added the correct event dispatching in case the event is subscribed by a GROUP.</p></li>
<li><p>2017-02-07: Did a complete revision of the Event Handing API and underlying mechanisms.</p></li>
</ul>
<hr/>
@ -427,6 +435,12 @@ YYYY-MM-DD: CLASS:<strong>NewFunction( Params )</strong> added</p>
<td class="name" nowrap="nowrap"><a href="##(EVENT).OnEngineStartUpRemove">EVENT:OnEngineStartUpRemove(EventClass)</a></td>
<td class="summary">
<p>Stop listening to S<em>EVENT</em>ENGINE_STARTUP event.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(EVENT).OnEventForGroup">EVENT:OnEventForGroup(GroupName, EventFunction, EventClass, EventID)</a></td>
<td class="summary">
<p>Set a new listener for an S<em>EVENT</em>X event for a GROUP.</p>
</td>
</tr>
<tr>
@ -436,9 +450,9 @@ YYYY-MM-DD: CLASS:<strong>NewFunction( Params )</strong> added</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(EVENT).OnEventForUnit">EVENT:OnEventForUnit(EventDCSUnitName, EventFunction, EventClass, EventID)</a></td>
<td class="name" nowrap="nowrap"><a href="##(EVENT).OnEventForUnit">EVENT:OnEventForUnit(UnitName, EventFunction, EventClass, EventID)</a></td>
<td class="summary">
<p>Set a new listener for an S<em>EVENT</em>X event</p>
<p>Set a new listener for an S<em>EVENT</em>X event for a UNIT.</p>
</td>
</tr>
<tr>
@ -574,9 +588,15 @@ YYYY-MM-DD: CLASS:<strong>NewFunction( Params )</strong> added</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(EVENT).RemoveForUnit">EVENT:RemoveForUnit(EventClass, EventID, UnitName)</a></td>
<td class="name" nowrap="nowrap"><a href="##(EVENT).RemoveForGroup">EVENT:RemoveForGroup(GroupName, EventClass, EventID)</a></td>
<td class="summary">
<p>Removes an Events entry for a Unit</p>
<p>Removes an Events entry for a GROUP.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(EVENT).RemoveForUnit">EVENT:RemoveForUnit(UnitName, EventClass, EventID)</a></td>
<td class="summary">
<p>Removes an Events entry for a UNIT.</p>
</td>
</tr>
<tr>
@ -1704,6 +1724,50 @@ The self instance of the class for which the event is.</p>
<p><em><a href="##(EVENT)">#EVENT</a>:</em></p>
</dd>
</dl>
<dl class="function">
<dt>
<a id="#(EVENT).OnEventForGroup" >
<strong>EVENT:OnEventForGroup(GroupName, EventFunction, EventClass, EventID)</strong>
</a>
</dt>
<dd>
<p>Set a new listener for an S<em>EVENT</em>X event for a GROUP.</p>
<h3>Parameters</h3>
<ul>
<li>
<p><code><em>#string GroupName </em></code>:
The name of the GROUP.</p>
</li>
<li>
<p><code><em>#function EventFunction </em></code>:
The function to be called when the event occurs for the GROUP.</p>
</li>
<li>
<p><code><em><a href="Core.Base.html##(BASE)">Core.Base#BASE</a> EventClass </em></code>:
The self instance of the class for which the event is.</p>
</li>
<li>
<p><code><em> EventID </em></code>: </p>
</li>
</ul>
<h3>Return value</h3>
<p><em><a href="##(EVENT)">#EVENT</a>:</em></p>
</dd>
</dl>
<dl class="function">
@ -1753,24 +1817,25 @@ The instance of the class for which the event is.</p>
<dt>
<a id="#(EVENT).OnEventForUnit" >
<strong>EVENT:OnEventForUnit(EventDCSUnitName, EventFunction, EventClass, EventID)</strong>
<strong>EVENT:OnEventForUnit(UnitName, EventFunction, EventClass, EventID)</strong>
</a>
</dt>
<dd>
<p>Set a new listener for an S<em>EVENT</em>X event</p>
<p>Set a new listener for an S<em>EVENT</em>X event for a UNIT.</p>
<h3>Parameters</h3>
<ul>
<li>
<p><code><em>#string EventDCSUnitName </em></code>: </p>
<p><code><em>#string UnitName </em></code>:
The name of the UNIT.</p>
</li>
<li>
<p><code><em>#function EventFunction </em></code>:
The function to be called when the event occurs for the unit.</p>
The function to be called when the event occurs for the GROUP.</p>
</li>
<li>
@ -2470,18 +2535,24 @@ The self instance of the class for which the event is.</p>
<dl class="function">
<dt>
<a id="#(EVENT).RemoveForUnit" >
<strong>EVENT:RemoveForUnit(EventClass, EventID, UnitName)</strong>
<a id="#(EVENT).RemoveForGroup" >
<strong>EVENT:RemoveForGroup(GroupName, EventClass, EventID)</strong>
</a>
</dt>
<dd>
<p>Removes an Events entry for a Unit</p>
<p>Removes an Events entry for a GROUP.</p>
<h3>Parameters</h3>
<ul>
<li>
<p><code><em>#string GroupName </em></code>:
The name of the GROUP.</p>
</li>
<li>
<p><code><em><a href="Core.Base.html##(BASE)">Core.Base#BASE</a> EventClass </em></code>:
The self instance of the class for which the event is.</p>
@ -2491,9 +2562,42 @@ The self instance of the class for which the event is.</p>
<p><code><em><a href="Dcs.DCSWorld.html##(world.event)">Dcs.DCSWorld#world.event</a> EventID </em></code>: </p>
</li>
</ul>
<h3>Return value</h3>
<p><em><a href="##(EVENT.Events)">#EVENT.Events</a>:</em></p>
</dd>
</dl>
<dl class="function">
<dt>
<a id="#(EVENT).RemoveForUnit" >
<strong>EVENT:RemoveForUnit(UnitName, EventClass, EventID)</strong>
</a>
</dt>
<dd>
<p>Removes an Events entry for a UNIT.</p>
<h3>Parameters</h3>
<ul>
<li>
<p><code><em> UnitName </em></code>: </p>
<p><code><em>#string UnitName </em></code>:
The name of the UNIT.</p>
</li>
<li>
<p><code><em><a href="Core.Base.html##(BASE)">Core.Base#BASE</a> EventClass </em></code>:
The self instance of the class for which the event is.</p>
</li>
<li>
<p><code><em><a href="Dcs.DCSWorld.html##(world.event)">Dcs.DCSWorld#world.event</a> EventID </em></code>: </p>
</li>
</ul>

View File

@ -162,6 +162,9 @@ Use the following Zone validation methods on the group:</p>
<p>Hereby the change log:</p>
<p>2017-03-07: GROUP:<strong>HandleEvent( Event, EventFunction )</strong> added. <br/>
2017-03-07: GROUP:<strong>UnHandleEvent( Event )</strong> added.</p>
<p>2017-01-24: GROUP:<strong>SetAIOnOff( AIOnOff )</strong> added. </p>
<p>2017-01-24: GROUP:<strong>SetAIOn()</strong> added. </p>
@ -376,6 +379,12 @@ Use the following Zone validation methods on the group:</p>
<td class="name" nowrap="nowrap"><a href="##(GROUP).GroupName">GROUP.GroupName</a></td>
<td class="summary">
<p>The name of the group.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(GROUP).HandleEvent">GROUP:HandleEvent(Event, EventFunction)</a></td>
<td class="summary">
<p>Subscribe to a DCS Event.</p>
</td>
</tr>
<tr>
@ -490,6 +499,12 @@ Use the following Zone validation methods on the group:</p>
<td class="name" nowrap="nowrap"><a href="##(GROUP).SetTemplateCountry">GROUP:SetTemplateCountry(CountryID, Template)</a></td>
<td class="summary">
<p>Sets the CountryID of the group in a Template.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(GROUP).UnHandleEvent">GROUP:UnHandleEvent(Event)</a></td>
<td class="summary">
<p>UnSubscribe to a DCS event.</p>
</td>
</tr>
</table>
@ -1139,6 +1154,38 @@ Current Vec3 of the first DCS Unit of the GROUP.</p>
<p>The name of the group.</p>
</dd>
</dl>
<dl class="function">
<dt>
<a id="#(GROUP).HandleEvent" >
<strong>GROUP:HandleEvent(Event, EventFunction)</strong>
</a>
</dt>
<dd>
<p>Subscribe to a DCS Event.</p>
<h3>Parameters</h3>
<ul>
<li>
<p><code><em><a href="Core.Event.html##(EVENTS)">Core.Event#EVENTS</a> Event </em></code>: </p>
</li>
<li>
<p><code><em>#function EventFunction </em></code>:
(optional) The function to be called when the event occurs for the GROUP.</p>
</li>
</ul>
<h3>Return value</h3>
<p><em><a href="##(GROUP)">#GROUP</a>:</em></p>
</dd>
</dl>
<dl class="function">
@ -1613,6 +1660,32 @@ The country ID.</p>
<p><em>#table:</em></p>
</dd>
</dl>
<dl class="function">
<dt>
<a id="#(GROUP).UnHandleEvent" >
<strong>GROUP:UnHandleEvent(Event)</strong>
</a>
</dt>
<dd>
<p>UnSubscribe to a DCS event.</p>
<h3>Parameter</h3>
<ul>
<li>
<p><code><em><a href="Core.Event.html##(EVENTS)">Core.Event#EVENTS</a> Event </em></code>: </p>
</li>
</ul>
<h3>Return value</h3>
<p><em><a href="##(GROUP)">#GROUP</a>:</em></p>
</dd>
</dl>

View File

@ -1759,6 +1759,9 @@ The group that was spawned. You can use this group for further actions.</p>
<p> Don't repeat the group from Take-Off till Landing and back Take-Off by ReSpawning.</p>
</dd>
</dl>
<dl class="function">
@ -2233,7 +2236,7 @@ when nothing was spawned.</p>
<dl class="function">
<dt>
<em>#number</em>
<em></em>
<a id="#(SPAWN).SpawnMaxGroups" >
<strong>SPAWN.SpawnMaxGroups</strong>
</a>
@ -2250,7 +2253,7 @@ when nothing was spawned.</p>
<dl class="function">
<dt>
<em>#number</em>
<em></em>
<a id="#(SPAWN).SpawnMaxUnitsAlive" >
<strong>SPAWN.SpawnMaxUnitsAlive</strong>
</a>