mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Fixed AI_CAP
-- ROE fine tuned. -- Detection events cross firing and exploding... -- Crash, Ejected, PilotDead is detected, makes the FSM stop. -- FSM bug fixed. There was an issue with the onbefore and onleave events returning false, which did not stop the transition! Fixed now. -- Event calling can return errors, and these must be logged correctly -> xpcall implemented. -- Added help from moose club members as a reference in the documentation. -> delta99 en whisper. -- ...
This commit is contained in:
@@ -717,6 +717,16 @@ end
|
||||
-- @param #EVENTDATA Event
|
||||
function EVENT:onEvent( Event )
|
||||
|
||||
local ErrorHandler = function( errmsg )
|
||||
|
||||
env.info( "Error in SCHEDULER function:" .. errmsg )
|
||||
if debug ~= nil then
|
||||
env.info( debug.traceback() )
|
||||
end
|
||||
|
||||
return errmsg
|
||||
end
|
||||
|
||||
if self and self.Events and self.Events[Event.id] then
|
||||
if Event.initiator and Event.initiator:getCategory() == Object.Category.UNIT then
|
||||
Event.IniDCSUnit = Event.initiator
|
||||
@@ -758,14 +768,16 @@ function EVENT:onEvent( Event )
|
||||
-- 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
|
||||
self:T( { "Calling EventFunction for Class ", EventClass:GetClassNameAndID(), ", Unit ", Event.IniUnitName } )
|
||||
EventData.IniUnit[Event.IniDCSUnitName].EventFunction( EventData.IniUnit[Event.IniDCSUnitName].EventClass, Event )
|
||||
local Result, Value = xpcall( function() return EventData.IniUnit[Event.IniDCSUnitName].EventFunction( EventData.IniUnit[Event.IniDCSUnitName].EventClass, Event ) end, ErrorHandler )
|
||||
--EventData.IniUnit[Event.IniDCSUnitName].EventFunction( EventData.IniUnit[Event.IniDCSUnitName].EventClass, Event )
|
||||
else
|
||||
-- If the EventData is not bound to a specific unit, then call the EventClass EventFunction.
|
||||
-- Note that here the EventFunction will need to implement and determine the logic for the relevant source- or target unit, or weapon.
|
||||
if Event.IniDCSUnit and not EventData.IniUnit then
|
||||
if EventClass == EventData.EventClass then
|
||||
self:T( { "Calling EventFunction for Class ", EventClass:GetClassNameAndID() } )
|
||||
EventData.EventFunction( EventData.EventClass, Event )
|
||||
local Result, Value = xpcall( function() return EventData.EventFunction( EventData.EventClass, Event ) end, ErrorHandler )
|
||||
--EventData.EventFunction( EventData.EventClass, Event )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -529,7 +529,8 @@ do -- FSM
|
||||
function FSM:_call_handler(handler, params)
|
||||
if self[handler] then
|
||||
self:E( "Calling " .. handler )
|
||||
return self[handler]( self, unpack(params) )
|
||||
local Value = self[handler]( self, unpack(params) )
|
||||
return Value
|
||||
end
|
||||
end
|
||||
|
||||
@@ -551,10 +552,11 @@ do -- FSM
|
||||
self:E( "FSM Transition:" .. self.current .. " --> " .. EventName .. " --> " .. to )
|
||||
end
|
||||
|
||||
if 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 then
|
||||
if ( 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 ) then
|
||||
self:E( "Cancel Transition" )
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -746,7 +748,8 @@ do -- FSM_CONTROLLABLE
|
||||
|
||||
if self[handler] then
|
||||
self:F3( "Calling " .. handler )
|
||||
return xpcall( function() return self[handler]( self, self.Controllable, unpack( params ) ) end, ErrorHandler )
|
||||
local Result, Value = xpcall( function() return self[handler]( self, self.Controllable, unpack( params ) ) end, ErrorHandler )
|
||||
return Value
|
||||
--return self[handler]( self, self.Controllable, unpack( params ) )
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user