This commit is contained in:
Frank 2020-04-08 00:09:47 +02:00
parent 861f2da4d6
commit 53fbec9c15
2 changed files with 46 additions and 11 deletions

View File

@ -771,6 +771,8 @@ end
function BASE:onEvent(event) function BASE:onEvent(event)
--self:F( { BaseEventCodes[event.id], event } ) --self:F( { BaseEventCodes[event.id], event } )
env.info("FF BASE:onEvent id="..event.id)
if self then if self then
for EventID, EventObject in pairs( self.Events ) do for EventID, EventObject in pairs( self.Events ) do
if EventObject.EventEnabled then if EventObject.EventEnabled then

View File

@ -555,6 +555,8 @@ function EVENT:Init( EventID, EventClass )
if not self.Events[EventID][EventPriority][EventClass] then if not self.Events[EventID][EventPriority][EventClass] then
self.Events[EventID][EventPriority][EventClass] = {} self.Events[EventID][EventPriority][EventClass] = {}
end end
return self.Events[EventID][EventPriority][EventClass] return self.Events[EventID][EventPriority][EventClass]
end end
@ -641,7 +643,7 @@ end
-- @param EventID -- @param EventID
-- @return #EVENT -- @return #EVENT
function EVENT:OnEventGeneric( EventFunction, EventClass, EventID ) function EVENT:OnEventGeneric( EventFunction, EventClass, EventID )
self:F2( { EventID } ) self:F2( { EventID, EventClass, EventFunction } )
local EventData = self:Init( EventID, EventClass ) local EventData = self:Init( EventID, EventClass )
EventData.EventFunction = EventFunction EventData.EventFunction = EventFunction
@ -960,13 +962,26 @@ function EVENT:onEvent( Event )
end end
if Event.IniObjectCategory == Object.Category.STATIC then if Event.IniObjectCategory == Object.Category.STATIC then
Event.IniDCSUnit = Event.initiator if Event.id==31 then
Event.IniDCSUnitName = Event.IniDCSUnit:getName() env.info("FF event 31")
Event.IniUnitName = Event.IniDCSUnitName -- Event.initiator is a Static object representing the pilot. But getName() error due to DCS bug.
Event.IniUnit = STATIC:FindByName( Event.IniDCSUnitName, false ) Event.IniDCSUnit = Event.initiator
Event.IniCoalition = Event.IniDCSUnit:getCoalition() local ID=Event.initiator.id_
Event.IniCategory = Event.IniDCSUnit:getDesc().category Event.IniDCSUnitName = string.format("Ejected Pilot ID %s", tostring(ID))
Event.IniTypeName = Event.IniDCSUnit:getTypeName() Event.IniUnitName = Event.IniDCSUnitName
Event.IniCoalition = 0
Event.IniCategory = 0
Event.IniUnit=STATIC:Register(Event.IniUnitName)
Event.IniTypeName = "Ejected Pilot"
else
Event.IniDCSUnit = Event.initiator
Event.IniDCSUnitName = Event.IniDCSUnit:getName()
Event.IniUnitName = Event.IniDCSUnitName
Event.IniUnit = STATIC:FindByName( Event.IniDCSUnitName, false )
Event.IniCoalition = Event.IniDCSUnit:getCoalition()
Event.IniCategory = Event.IniDCSUnit:getDesc().category
Event.IniTypeName = Event.IniDCSUnit:getTypeName()
end
end end
if Event.IniObjectCategory == Object.Category.CARGO then if Event.IniObjectCategory == Object.Category.CARGO then
@ -1048,7 +1063,7 @@ function EVENT:onEvent( Event )
if Event.place then if Event.place then
if Event.id==EVENTS.LandingAfterEjection then if Event.id==EVENTS.LandingAfterEjection then
-- Place is here the UNIT of which the pilot ejected. -- Place is here the UNIT of which the pilot ejected.
Event.Place=UNIT:Find(Event.place) --Event.Place=UNIT:Find(Event.place)
else else
Event.Place=AIRBASE:Find(Event.place) Event.Place=AIRBASE:Find(Event.place)
Event.PlaceName=Event.Place:GetName() Event.PlaceName=Event.Place:GetName()
@ -1083,13 +1098,30 @@ function EVENT:onEvent( Event )
self:F( { EventMeta.Text, Event, Event.IniDCSUnitName, Event.TgtDCSUnitName, PriorityOrder } ) self:F( { EventMeta.Text, Event, Event.IniDCSUnitName, Event.TgtDCSUnitName, PriorityOrder } )
end end
--self:E({Events=self.Events})
--self:E({Events31=self.Events[31]})
env.info(string.format("FF %s all events:", EventMeta.Text))
for id,data in pairs(self.Events) do
self:E({id=id, data=data})
end
for EventPriority = PriorityBegin, PriorityEnd, PriorityOrder do for EventPriority = PriorityBegin, PriorityEnd, PriorityOrder do
env.info("hallo 100 EventPriority="..EventPriority)
if self.Events[Event.id][EventPriority] then if self.Events[Event.id][EventPriority] then
env.info("hallo 200")
self:E({blub=EventMeta.Text, bla=self.Events[Event.id][EventPriority]})
-- 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. -- 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 for EventClass, EventData in pairs( self.Events[Event.id][EventPriority] ) do
env.info("hallo 300")
self:E({eventclass=EventClass})
self:E({eventdata=EventData})
--if Event.IniObjectCategory ~= Object.Category.STATIC then --if Event.IniObjectCategory ~= Object.Category.STATIC then
-- self:E( { "Evaluating: ", EventClass:GetClassNameAndID() } ) -- self:E( { "Evaluating: ", EventClass:GetClassNameAndID() } )
--end --end
@ -1145,10 +1177,11 @@ function EVENT:onEvent( Event )
else else
-- The EventClass is not alive anymore, we remove it from the EventHandlers... -- The EventClass is not alive anymore, we remove it from the EventHandlers...
self:RemoveEvent( EventClass, Event.id ) self:RemoveEvent( EventClass, Event.id )
end end
else else
-- If the EventData is for a GROUP, the call directly the EventClass EventFunction for the UNIT in that GROUP. --- If the EventData is for a GROUP, the call directly the EventClass EventFunction for the UNIT in that GROUP.
if EventData.EventGroup then if EventData.EventGroup then
-- So now the EventClass must be a GROUP class!!! We check if it is still "Alive". -- So now the EventClass must be a GROUP class!!! We check if it is still "Alive".